From 3a51b473af7ba748eb671696eab26eee47ad5787 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sat, 11 May 2019 23:15:57 -0700 Subject: [PATCH 001/165] remove some key usage from core, refactor Operations.apply --- packages/slate/src/commands/at-range.js | 90 ++-- packages/slate/src/commands/by-path.js | 10 + packages/slate/src/commands/with-intent.js | 5 +- packages/slate/src/controllers/editor.js | 110 +++-- packages/slate/src/interfaces/element.js | 44 +- packages/slate/src/interfaces/range.js | 14 +- packages/slate/src/models/point.js | 65 ++- packages/slate/src/models/value.js | 546 ++++++++++----------- packages/slate/src/operations/apply.js | 344 +++++++++++-- packages/slate/src/plugins/schema.js | 11 +- packages/slate/src/utils/path-utils.js | 14 + 11 files changed, 813 insertions(+), 440 deletions(-) diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 04d3e95e09..083d46a198 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -4,6 +4,7 @@ import Inline from '../models/inline' import Mark from '../models/mark' import Node from '../models/node' import TextUtils from '../utils/text-utils' +import PathUtils from '../utils/path-utils' /** * Ensure that an expanded selection is deleted first, and return the updated @@ -47,26 +48,33 @@ const Commands = {} */ Commands.addMarkAtRange = (editor, range, mark) => { - if (range.isCollapsed) return + if (range.isCollapsed) { + return + } const { value } = editor const { document } = value const { start, end } = range - const texts = document.getTextsAtRange(range) editor.withoutNormalizing(() => { - texts.forEach(node => { - const { key } = node + for (const [node, path] of document.texts({ range })) { let index = 0 let length = node.text.length - if (key === start.key) index = start.offset - if (key === end.key) length = end.offset - if (key === start.key && key === end.key) + if (path.equals(start.path)) { + index = start.offset + } + + if (path.equals(end.path)) { + length = end.offset + } + + if (path.equals(start.path) && path.equals(end.path)) { length = end.offset - start.offset + } - editor.addMarkByKey(key, index, length, mark) - }) + editor.addMarkByPath(path, index, length, mark) + } }) } @@ -869,16 +877,19 @@ Commands.insertInlineAtRange = (editor, range, inline) => { const { value } = editor const { document } = value const { start } = range - const parent = document.getParent(start.path) - const startText = document.assertDescendant(start.path) - const index = parent.nodes.indexOf(startText) + + document.assertDescendant(start.path) + + const parentPath = PathUtils.lift(start.path) + const index = start.path.last() + const parent = document.getNode(parentPath) if (editor.isVoid(parent)) { return } editor.splitNodeByPath(start.path, start.offset) - editor.insertNodeByKey(parent.key, index + 1, inline) + editor.insertNodeByPath(parentPath, index + 1, inline) }) } @@ -918,26 +929,37 @@ Commands.insertTextAtRange = (editor, range, text, marks) => { */ Commands.removeMarkAtRange = (editor, range, mark) => { - if (range.isCollapsed) return + if (range.isCollapsed) { + return + } const { value } = editor const { document } = value - const texts = document.getTextsAtRange(range) const { start, end } = range editor.withoutNormalizing(() => { - texts.forEach(node => { - const { key } = node - let index = 0 - let length = node.text.length - - if (key === start.key) index = start.offset - if (key === end.key) length = end.offset - if (key === start.key && key === end.key) + for (const [node, path] of document.texts({ range })) { + const isStart = path.equals(start.path) + const isEnd = path.equals(end.path) + let index + let length + + if (isStart && isEnd) { + index = start.offset length = end.offset - start.offset + } else if (isStart) { + index = start.offset + length = node.text.length - start.offset + } else if (isEnd) { + index = 0 + length = end.offset + } else { + index = 0 + length = node.text.length + } - editor.removeMarkByKey(key, index, length, mark) - }) + editor.removeMarkByPath(path, index, length, mark) + } }) } @@ -957,7 +979,7 @@ Commands.setBlocksAtRange = (editor, range, properties) => { const { start, end, isCollapsed } = range const isStartVoid = document.hasVoidParent(start.path, editor) const startBlock = document.getClosestBlock(start.path) - const endBlock = document.getClosestBlock(end.key) + const endBlock = document.getClosestBlock(end.path) // Check if we have a "hanging" selection case where the even though the // selection extends into the start of the end node, we actually want to @@ -991,12 +1013,11 @@ Commands.setBlocksAtRange = (editor, range, properties) => { Commands.setInlinesAtRange = (editor, range, properties) => { const { value } = editor const { document } = value - const inlines = document.getLeafInlinesAtRange(range) editor.withoutNormalizing(() => { - inlines.forEach(inline => { - editor.setNodeByKey(inline.key, properties) - }) + for (const [, path] of document.inlines({ range, onlyLeaves: true })) { + editor.setNodeByPath(path, properties) + } }) } @@ -1031,7 +1052,10 @@ Commands.splitBlockAtRange = (editor, range, height = 1) => { document = value.document if (range.isExpanded) { - if (range.isBackward) range = range.flip() + if (range.isBackward) { + range = range.flip() + } + const nextBlock = document.getNextBlock(node.key) range = range.moveAnchorToStartOfNode(nextBlock) range = range.setFocus(range.focus.setPath(null)) @@ -1256,7 +1280,9 @@ Commands.wrapBlockAtRange = (editor, range, block) => { } // If no shared parent could be found then the parent is the document. - if (parent == null) parent = document + if (parent == null) { + parent = document + } // Create a list of direct children siblings of parent that fall in the // selection. diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index 56ddfaacc8..dfed0c4472 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -38,6 +38,11 @@ Commands.addMarksByPath = (editor, path, offset, length, marks) => { const { value } = editor const { document } = value const node = document.assertNode(path) + marks = marks.subtract(node.marks) + + if (!marks.size) { + return + } editor.withoutNormalizing(() => { // If it ends before the end of the node, we'll need to split to create a new @@ -236,6 +241,11 @@ Commands.removeMarksByPath = (editor, path, offset, length, marks) => { const { value } = editor const { document } = value const node = document.assertNode(path) + marks = marks.intersect(node.marks) + + if (!marks.size) { + return + } editor.withoutNormalizing(() => { // If it ends before the end of the node, we'll need to split to create a new diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js index 977a101de0..14f64335b8 100644 --- a/packages/slate/src/commands/with-intent.js +++ b/packages/slate/src/commands/with-intent.js @@ -235,7 +235,10 @@ Commands.insertBlock = (editor, block) => { // If the node was successfully inserted, update the selection. const node = editor.value.document.getNode(block.key) - if (node) editor.moveToEndOfNode(node) + + if (node) { + editor.moveToEndOfNode(node) + } } /** diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index 9ad88d624f..07faac674f 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -195,8 +195,11 @@ class Editor { normalize() { const { value, controller } = this let { document } = value - const table = document.getKeysToPathsTable() - const paths = Object.values(table).map(PathUtils.create) + const paths = Array.from( + document.descendants({ includeTarget: true, includeRoot: true }), + ([, path]) => path + ) + this.tmp.dirty = this.tmp.dirty.concat(paths) normalizeDirtyPaths(this) @@ -505,8 +508,14 @@ function getDirtyPaths(operation) { } case 'insert_node': { - const table = node.getKeysToPathsTable() - const paths = Object.values(table).map(p => path.concat(p)) + const paths = + node.object === 'text' + ? [] + : Array.from( + node.descendants({ includeTarget: true, includeRoot: true }), + ([, p]) => path.concat(p) + ) + const ancestors = PathUtils.getAncestors(path).toArray() return [...ancestors, path, ...paths] } @@ -580,58 +589,67 @@ function normalizeDirtyPaths(editor) { * * @param {Editor} editor * @param {Array} path + * @param {Number} iteration */ -function normalizeNodeByPath(editor, path) { +function normalizeNodeByPath( + editor, + path, + iteration = 0, + maxIterations = null +) { const { controller } = editor - let { value } = editor - let { document } = value - let node = document.assertNode(path) - let iterations = 0 - const max = 100 + (node.object === 'text' ? 1 : node.nodes.size) + const { value } = editor + const { document } = value + const node = document.assertNode(path) - while (node) { - const fn = node.normalize(controller) + // Set a best estimate for maximum iterations. + if (!maxIterations) { + maxIterations = 100 + (node.object === 'text' ? 1 : node.nodes.size) + } - if (!fn) { - break - } + // Check to make sure that we haven't exceeded the max. Without this check, + // it's easy for a `normalize` function of a schema rule to be written + // incorrectly and for an infinite invalid loop to occur. + if (iteration > maxIterations) { + throw new Error( + 'A schema rule could not be normalized after sufficient iterations. This is usually due to a `rule.normalize` or `plugin.normalizeNode` function of a schema being incorrectly written, causing an infinite loop.' + ) + } - // Run the normalize `fn` to fix the node. - fn(controller) + const fn = node.normalize(controller) - // Attempt to re-find the node by path, or by key if it has changed - // locations in the tree continue iterating. - value = editor.value - document = value.document - const { key } = node - let found = document.getDescendant(path) - - if (found && found.key === key) { - node = found - } else { - found = document.getDescendant(key) - - if (found) { - node = found - path = document.getPath(key) - } else { - // If it no longer exists by key, it was removed, so we're done. - break - } - } + // A normalizing function is only returned when the node is invalid. + if (!fn) { + return + } + + // Run the normalize `fn` to fix the node. + const opCount = editor.operations.size + fn(controller) - // Increment the iterations counter, and check to make sure that we haven't - // exceeded the max. Without this check, it's easy for the `normalize` - // function of a schema rule to be written incorrectly and for an infinite - // invalid loop to occur. - iterations++ + // Now that normalizing operations have been applied, we need to refind the + // path, transformed by all the new operations. + const newOps = editor.operations.slice(opCount) + let paths = [path] - if (iterations > max) { - throw new Error( - 'A schema rule could not be normalized after sufficient iterations. This is usually due to a `rule.normalize` or `plugin.normalizeNode` function of a schema being incorrectly written, causing an infinite loop.' - ) + for (const op of newOps) { + let next = [] + + // Transforming paths can sometimes result in multiple new paths, so we + // have to accoutn for that by collecting an array. + for (const p of paths) { + const transformed = PathUtils.transform(p, op) + next = next.concat(transformed.toArray()) } + + paths = next + } + + // For every updated path, we want to continue iterating to ensure that the + // node is fully normalized by all rules. + for (const p of paths) { + normalizeNodeByPath(editor, p, iteration + 1, maxIterations) } } diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js index f1a501d7dd..529bd2b5f5 100644 --- a/packages/slate/src/interfaces/element.js +++ b/packages/slate/src/interfaces/element.js @@ -1483,7 +1483,7 @@ class ElementInterface { nodes.forEach((node, i) => { const ret = predicate(node, i, this.nodes) - if (ret !== node) nodes = nodes.set(ret.key, ret) + if (ret !== node) nodes = nodes.set(i, ret) }) const ret = this.set('nodes', nodes) @@ -1882,6 +1882,48 @@ class ElementInterface { return iterable } + previousText(path) { + const node = this.assertNode(path) + + if (node.object !== 'text') { + const entry = node.firstText() + + if (entry) { + const [, entryPath] = entry + path = path.concat(entryPath) + } + } + + const [prev] = this.texts({ path, direction: 'backward' }) + return prev + } + + nextText(path) { + const node = this.assertNode(path) + + if (node.object !== 'text') { + const entry = node.lastText() + + if (entry) { + const [, entryPath] = entry + path = path.concat(entryPath) + } + } + + const [next] = this.texts({ path }) + return next + } + + firstText() { + const [first] = this.texts() + return first + } + + lastText() { + const [last] = this.texts({ direction: 'backward' }) + return last + } + /** * Deprecated. */ diff --git a/packages/slate/src/interfaces/range.js b/packages/slate/src/interfaces/range.js index fa290872d3..0242d43e6d 100644 --- a/packages/slate/src/interfaces/range.js +++ b/packages/slate/src/interfaces/range.js @@ -21,10 +21,16 @@ class RangeInterface { */ get isCollapsed() { + const { anchor, focus } = this + + // PERF: If the points are actually equal we can abort faster. + if (anchor === focus) { + return true + } + return ( - this.anchor === this.focus || - (this.anchor.key === this.focus.key && - this.anchor.offset === this.focus.offset) + anchor.offset === focus.offset && + PathUtils.isEqual(anchor.path, focus.path) ) } @@ -51,7 +57,7 @@ class RangeInterface { return null } - if (anchor.key === focus.key) { + if (anchor.path.equals(focus.path)) { return anchor.offset > focus.offset } diff --git a/packages/slate/src/models/point.js b/packages/slate/src/models/point.js index 029c938255..9dcb6ff3c9 100644 --- a/packages/slate/src/models/point.js +++ b/packages/slate/src/models/point.js @@ -127,11 +127,13 @@ class Point extends Record(DEFAULTS) { */ isAfterPoint(point) { - if (this.isUnset) return false - const is = - (this.key === point.key && this.offset > point.offset) || - PathUtils.compare(this.path, point.path) === 1 - return is + if (this.isUnset || point.isUnset) { + return false + } + + const result = PathUtils.compare(this.path, point.path) + const isAfter = (result === 0 && this.offset > point.offset) || result === 1 + return isAfter } /** @@ -141,9 +143,7 @@ class Point extends Record(DEFAULTS) { */ isAfterRange(range) { - if (this.isUnset) return false - const is = this.isAfterPoint(range.end) - return is + return this.isAfterPoint(range.end) } /** @@ -153,7 +153,10 @@ class Point extends Record(DEFAULTS) { */ isAtEndOfRange(range) { - if (this.isUnset) return false + if (this.isUnset) { + return false + } + const is = this.equals(range.end) return is } @@ -165,7 +168,10 @@ class Point extends Record(DEFAULTS) { */ isAtStartOfRange(range) { - if (this.isUnset) return false + if (this.isUnset) { + return false + } + const is = this.equals(range.start) return is } @@ -177,11 +183,15 @@ class Point extends Record(DEFAULTS) { */ isBeforePoint(point) { - if (this.isUnset) return false - const is = - (this.key === point.key && this.offset < point.offset) || - PathUtils.compare(this.path, point.path) === -1 - return is + if (this.isUnset) { + return false + } + + const result = PathUtils.compare(this.path, point.path) + const isBefore = + (result === 0 && this.offset < point.offset) || result === -1 + + return isBefore } /** @@ -191,7 +201,10 @@ class Point extends Record(DEFAULTS) { */ isBeforeRange(range) { - if (this.isUnset) return false + if (this.isUnset) { + return false + } + const is = this.isBeforePoint(range.start) return is } @@ -203,7 +216,10 @@ class Point extends Record(DEFAULTS) { */ isInRange(range) { - if (this.isUnset) return false + if (this.isUnset) { + return false + } + const is = this.equals(range.start) || this.equals(range.end) || @@ -219,7 +235,10 @@ class Point extends Record(DEFAULTS) { */ isAtEndOfNode(node) { - if (this.isUnset) return false + if (this.isUnset) { + return false + } + const last = node.getLastText() const is = this.key === last.key && this.offset === last.text.length return is @@ -233,7 +252,9 @@ class Point extends Record(DEFAULTS) { */ isAtStartOfNode(node) { - if (this.isUnset) return false + if (this.isUnset) { + return false + } // PERF: Do a check for a `0` offset first since it's quickest. if (this.offset !== 0) return false @@ -251,7 +272,10 @@ class Point extends Record(DEFAULTS) { */ isInNode(node) { - if (this.isUnset) return false + if (this.isUnset) { + return false + } + if (node.object === 'text' && node.key === this.key) return true if (node.hasNode(this.key)) return true return false @@ -374,6 +398,7 @@ class Point extends Record(DEFAULTS) { } if (!target) { + debugger warning(false, "A point's `path` or `key` invalid and was reset!") const text = node.getFirstText() diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index 8a999969f5..873a1b8d92 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -1,5 +1,6 @@ import isPlainObject from 'is-plain-object' import invariant from 'tiny-invariant' +import warning from 'tiny-warning' import { Record, Set, List } from 'immutable' import Annotation from './annotation' @@ -119,8 +120,8 @@ class Value extends Record(DEFAULTS) { get startBlock() { return ( - this.selection.start.key && - this.document.getClosestBlock(this.selection.start.key) + this.selection.start.path && + this.document.getClosestBlock(this.selection.start.path) ) } @@ -132,8 +133,8 @@ class Value extends Record(DEFAULTS) { get endBlock() { return ( - this.selection.end.key && - this.document.getClosestBlock(this.selection.end.key) + this.selection.end.path && + this.document.getClosestBlock(this.selection.end.path) ) } @@ -145,8 +146,8 @@ class Value extends Record(DEFAULTS) { get anchorBlock() { return ( - this.selection.anchor.key && - this.document.getClosestBlock(this.selection.anchor.key) + this.selection.anchor.path && + this.document.getClosestBlock(this.selection.anchor.path) ) } @@ -158,8 +159,8 @@ class Value extends Record(DEFAULTS) { get focusBlock() { return ( - this.selection.focus.key && - this.document.getClosestBlock(this.selection.focus.key) + this.selection.focus.path && + this.document.getClosestBlock(this.selection.focus.path) ) } @@ -171,8 +172,8 @@ class Value extends Record(DEFAULTS) { get startInline() { return ( - this.selection.start.key && - this.document.getClosestInline(this.selection.start.key) + this.selection.start.path && + this.document.getClosestInline(this.selection.start.path) ) } @@ -184,8 +185,8 @@ class Value extends Record(DEFAULTS) { get endInline() { return ( - this.selection.end.key && - this.document.getClosestInline(this.selection.end.key) + this.selection.end.path && + this.document.getClosestInline(this.selection.end.path) ) } @@ -197,8 +198,8 @@ class Value extends Record(DEFAULTS) { get anchorInline() { return ( - this.selection.anchor.key && - this.document.getClosestInline(this.selection.anchor.key) + this.selection.anchor.path && + this.document.getClosestInline(this.selection.anchor.path) ) } @@ -210,8 +211,8 @@ class Value extends Record(DEFAULTS) { get focusInline() { return ( - this.selection.focus.key && - this.document.getClosestInline(this.selection.focus.key) + this.selection.focus.path && + this.document.getClosestInline(this.selection.focus.path) ) } @@ -223,8 +224,8 @@ class Value extends Record(DEFAULTS) { get startText() { return ( - this.selection.start.key && - this.document.getDescendant(this.selection.start.key) + this.selection.start.path && + this.document.getDescendant(this.selection.start.path) ) } @@ -236,8 +237,8 @@ class Value extends Record(DEFAULTS) { get endText() { return ( - this.selection.end.key && - this.document.getDescendant(this.selection.end.key) + this.selection.end.path && + this.document.getDescendant(this.selection.end.path) ) } @@ -249,8 +250,8 @@ class Value extends Record(DEFAULTS) { get anchorText() { return ( - this.selection.anchor.key && - this.document.getDescendant(this.selection.anchor.key) + this.selection.anchor.path && + this.document.getDescendant(this.selection.anchor.path) ) } @@ -262,8 +263,8 @@ class Value extends Record(DEFAULTS) { get focusText() { return ( - this.selection.focus.key && - this.document.getDescendant(this.selection.focus.key) + this.selection.focus.path && + this.document.getDescendant(this.selection.focus.path) ) } @@ -275,8 +276,8 @@ class Value extends Record(DEFAULTS) { get nextBlock() { return ( - this.selection.end.key && - this.document.getNextBlock(this.selection.end.key) + this.selection.end.path && + this.document.getNextBlock(this.selection.end.path) ) } @@ -288,8 +289,8 @@ class Value extends Record(DEFAULTS) { get previousBlock() { return ( - this.selection.start.key && - this.document.getPreviousBlock(this.selection.start.key) + this.selection.start.path && + this.document.getPreviousBlock(this.selection.start.path) ) } @@ -301,8 +302,8 @@ class Value extends Record(DEFAULTS) { get nextInline() { return ( - this.selection.end.key && - this.document.getNextInline(this.selection.end.key) + this.selection.end.path && + this.document.getNextInline(this.selection.end.path) ) } @@ -314,8 +315,8 @@ class Value extends Record(DEFAULTS) { get previousInline() { return ( - this.selection.start.key && - this.document.getPreviousInline(this.selection.start.key) + this.selection.start.path && + this.document.getPreviousInline(this.selection.start.path) ) } @@ -327,8 +328,8 @@ class Value extends Record(DEFAULTS) { get nextText() { return ( - this.selection.end.key && - this.document.getNextText(this.selection.end.key) + this.selection.end.path && + this.document.getNextText(this.selection.end.path) ) } @@ -340,8 +341,8 @@ class Value extends Record(DEFAULTS) { get previousText() { return ( - this.selection.start.key && - this.document.getPreviousText(this.selection.start.key) + this.selection.start.path && + this.document.getPreviousText(this.selection.start.path) ) } @@ -419,97 +420,79 @@ class Value extends Record(DEFAULTS) { } /** - * Add an `annotation` to the value. - * - * @param {Annotation} annotation - * @param {Mark} mark - * @return {Value} - */ - - addAnnotation(annotation) { - annotation = Annotation.create(annotation) - let value = this - let { annotations } = value - const { key } = annotation - annotations = annotations.set(key, annotation) - value = value.set('annotations', annotations) - return value - } - - /** - * Add `mark` to text at `path`. + * Return a JSON representation of the value. * - * @param {List|String} path - * @param {Mark} mark - * @return {Value} + * @param {Object} options + * @return {Object} */ - addMark(path, mark) { - mark = Mark.create(mark) - let value = this - let { document } = value - document = document.addMark(path, mark) - value = value.set('document', document) - return value - } + toJSON(options = {}) { + const object = { + object: this.object, + document: this.document.toJSON(options), + } - /** - * Insert a `node`. - * - * @param {List|String} path - * @param {Node} node - * @return {Value} - */ + if (options.preserveData) { + object.data = this.data.toJSON(options) + } - insertNode(path, node) { - let value = this - let { document } = value - document = document.insertNode(path, node) - value = value.set('document', document) + if (options.preserveAnnotations) { + object.annotations = this.annotations + .map(a => a.toJSON(options)) + .toObject() + } - value = value.mapRanges(range => - range.updatePoints(point => point.setPath(null)) - ) + if (options.preserveSelection) { + object.selection = this.selection.toJSON(options) + } - return value + return object } /** - * Insert `text` at `offset` in node by `path`. - * - * @param {List|String} path - * @param {Number} offset - * @param {String} text - * @return {Value} + * Deprecated. */ - insertText(path, offset, text) { + mapRanges(iterator) { + warning( + false, + 'As of slate@0.48 the `value.mapRanges` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + let value = this - let { document } = value - let node = document.assertNode(path) - document = document.insertText(path, offset, text) - node = document.assertNode(path) - value = value.set('document', document) + const { document, selection, annotations } = value - value = value.mapPoints(point => { - if (point.key === node.key && point.offset >= offset) { - return point.setOffset(point.offset + text.length) - } else { - return point - } + let sel = selection.isSet ? iterator(selection) : selection + if (!sel) sel = selection.unset() + if (sel !== selection) sel = document.createSelection(sel) + value = value.set('selection', sel) + + let anns = annotations.map(annotation => { + let n = annotation.isSet ? iterator(annotation) : annotation + if (n && n !== annotation) n = document.createAnnotation(n) + return n }) + anns = anns.filter(annotation => !!annotation) + value = value.set('annotations', anns) return value } - /** - * Merge a node backwards its previous sibling. - * - * @param {List|Key} path - * @return {Value} - */ + mapPoints(iterator) { + warning( + false, + 'As of slate@0.48 the `value.mapPoints` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + + return this.mapRanges(range => range.updatePoints(iterator)) + } mergeNode(path) { + warning( + false, + 'As of slate@0.48 the `value.mergeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + let value = this const { document } = value const newDocument = document.mergeNode(path) @@ -540,75 +523,46 @@ class Value extends Record(DEFAULTS) { return value } - /** - * Move a node by `path` to `newPath`. - * - * A `newIndex` can be provided when move nodes by `key`, to account for not - * being able to have a key for a location in the tree that doesn't exist yet. - * - * @param {List|Key} path - * @param {List|Key} newPath - * @param {Number} newIndex - * @return {Value} - */ + splitNode(path, position, properties) { + warning( + false, + 'As of slate@0.48 the `value.splitNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) - moveNode(path, newPath, newIndex = 0) { let value = this - let { document } = value + const { document } = value + const newDocument = document.splitNode(path, position, properties) + const node = document.assertNode(path) + value = value.set('document', newDocument) - if (PathUtils.isEqual(path, newPath)) { - return value - } + value = value.mapRanges(range => { + const next = newDocument.getNextText(node.key) + const { start, end } = range - document = document.moveNode(path, newPath, newIndex) - value = value.set('document', document) - value = value.mapPoints(point => point.setPath(null)) - return value - } + // If the start was after the split, move it to the next node. + if (node.key === start.key && position <= start.offset) { + range = range.moveStartTo(next.key, start.offset - position) + } - /** - * Remove an `annotation` from the value. - * - * @param {Annotation} annotation - * @param {Mark} mark - * @return {Value} - */ + // If the end was after the split, move it to the next node. + if (node.key === end.key && position <= end.offset) { + range = range.moveEndTo(next.key, end.offset - position) + } - removeAnnotation(annotation) { - annotation = Annotation.create(annotation) - let value = this - let { annotations } = value - const { key } = annotation - annotations = annotations.delete(key) - value = value.set('annotations', annotations) - return value - } + range = range.updatePoints(point => point.setPath(null)) - /** - * Remove `mark` at `path`. - * - * @param {List|String} path - * @param {Mark} mark - * @return {Value} - */ + return range + }) - removeMark(path, mark) { - mark = Mark.create(mark) - let value = this - let { document } = value - document = document.removeMark(path, mark) - value = value.set('document', document) return value } - /** - * Remove a node by `path`. - * - * @param {List|String} path - * @return {Value} - */ - removeNode(path) { + warning( + false, + 'As of slate@0.48 the `value.removeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + let value = this let { document } = value const node = document.assertNode(path) @@ -643,16 +597,31 @@ class Value extends Record(DEFAULTS) { return value } - /** - * Remove `text` at `offset` in node by `path`. - * - * @param {List|Key} path - * @param {Number} offset - * @param {String} text - * @return {Value} - */ + moveNode(path, newPath, newIndex = 0) { + warning( + false, + 'As of slate@0.48 the `value.moveNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + + let value = this + let { document } = value + + if (PathUtils.isEqual(path, newPath)) { + return value + } + + document = document.moveNode(path, newPath, newIndex) + value = value.set('document', document) + value = value.mapPoints(point => point.setPath(null)) + return value + } removeText(path, offset, text) { + warning( + false, + 'As of slate@0.48 the `value.removeText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + let value = this let { document } = value const node = document.assertNode(path) @@ -682,15 +651,25 @@ class Value extends Record(DEFAULTS) { return value } - /** - * Add an `annotation` to the value. - * - * @param {Annotation} annotation - * @param {Mark} mark - * @return {Value} - */ + setNode(path, properties) { + warning( + false, + 'As of slate@0.48 the `value.setNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + + let value = this + let { document } = value + document = document.setNode(path, properties) + value = value.set('document', document) + return value + } setAnnotation(properties, newProperties) { + warning( + false, + 'As of slate@0.48 the `value.setAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + newProperties = Annotation.createProperties(newProperties) const annotation = Annotation.create(properties) const next = annotation.merge(newProperties) @@ -702,32 +681,12 @@ class Value extends Record(DEFAULTS) { return value } - /** - * Set `properties` on a node. - * - * @param {List|String} path - * @param {Object} properties - * @return {Value} - */ - - setNode(path, properties) { - let value = this - let { document } = value - document = document.setNode(path, properties) - value = value.set('document', document) - return value - } - - /** - * Set `properties` on `mark` on text at `offset` and `length` in node. - * - * @param {List|String} path - * @param {Mark} mark - * @param {Object} properties - * @return {Value} - */ - setMark(path, mark, properties) { + warning( + false, + 'As of slate@0.48 the `value.setMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + let value = this let { document } = value document = document.setMark(path, mark, properties) @@ -735,14 +694,12 @@ class Value extends Record(DEFAULTS) { return value } - /** - * Set `properties` on the value. - * - * @param {Object} properties - * @return {Value} - */ - setProperties(properties) { + warning( + false, + 'As of slate@0.48 the `value.setProperties` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + let value = this const { document } = value const { data, annotations } = properties @@ -762,15 +719,12 @@ class Value extends Record(DEFAULTS) { return value } - /** - * Set `properties` on the selection. - * - * @param {Value} value - * @param {Operation} operation - * @return {Value} - */ - setSelection(properties) { + warning( + false, + 'As of slate@0.48 the `value.setSelection` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + let value = this let { document, selection } = value const next = selection.setProperties(properties) @@ -779,110 +733,104 @@ class Value extends Record(DEFAULTS) { return value } - /** - * Split a node by `path` at `position` with optional `properties` to apply - * to the newly split node. - * - * @param {List|String} path - * @param {Number} position - * @param {Object} properties - * @return {Value} - */ + removeAnnotation(annotation) { + warning( + false, + 'As of slate@0.48 the `value.removeAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) - splitNode(path, position, properties) { + annotation = Annotation.create(annotation) let value = this - const { document } = value - const newDocument = document.splitNode(path, position, properties) - const node = document.assertNode(path) - value = value.set('document', newDocument) + let { annotations } = value + const { key } = annotation + annotations = annotations.delete(key) + value = value.set('annotations', annotations) + return value + } - value = value.mapRanges(range => { - const next = newDocument.getNextText(node.key) - const { start, end } = range + removeMark(path, mark) { + warning( + false, + 'As of slate@0.48 the `value.removeMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) - // If the start was after the split, move it to the next node. - if (node.key === start.key && position <= start.offset) { - range = range.moveStartTo(next.key, start.offset - position) - } + mark = Mark.create(mark) + let value = this + let { document } = value + document = document.removeMark(path, mark) + value = value.set('document', document) + return value + } - // If the end was after the split, move it to the next node. - if (node.key === end.key && position <= end.offset) { - range = range.moveEndTo(next.key, end.offset - position) - } + addAnnotation(annotation) { + warning( + false, + 'As of slate@0.48 the `value.addAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) - range = range.updatePoints(point => point.setPath(null)) + annotation = Annotation.create(annotation) + let value = this + let { annotations } = value + const { key } = annotation + annotations = annotations.set(key, annotation) + value = value.set('annotations', annotations) + return value + } - return range - }) + addMark(path, mark) { + warning( + false, + 'As of slate@0.48 the `value.addMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) + mark = Mark.create(mark) + let value = this + let { document } = value + document = document.addMark(path, mark) + value = value.set('document', document) return value } - /** - * Map all range objects to apply adjustments with an `iterator`. - * - * @param {Function} iterator - * @return {Value} - */ + insertNode(path, node) { + warning( + false, + 'As of slate@0.48 the `value.insertNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) - mapRanges(iterator) { let value = this - const { document, selection, annotations } = value - - let sel = selection.isSet ? iterator(selection) : selection - if (!sel) sel = selection.unset() - if (sel !== selection) sel = document.createSelection(sel) - value = value.set('selection', sel) + let { document } = value + document = document.insertNode(path, node) + value = value.set('document', document) - let anns = annotations.map(annotation => { - let n = annotation.isSet ? iterator(annotation) : annotation - if (n && n !== annotation) n = document.createAnnotation(n) - return n - }) + value = value.mapRanges(range => + range.updatePoints(point => point.setPath(null)) + ) - anns = anns.filter(annotation => !!annotation) - value = value.set('annotations', anns) return value } - mapPoints(iterator) { - return this.mapRanges(range => range.updatePoints(iterator)) - } - - /** - * Return a JSON representation of the value. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - document: this.document.toJSON(options), - } - - if (options.preserveData) { - object.data = this.data.toJSON(options) - } + insertText(path, offset, text) { + warning( + false, + 'As of slate@0.48 the `value.insertText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + ) - if (options.preserveAnnotations) { - object.annotations = this.annotations - .map(a => a.toJSON(options)) - .toObject() - } + let value = this + let { document } = value + document = document.insertText(path, offset, text) + value = value.set('document', document) - if (options.preserveSelection) { - object.selection = this.selection.toJSON(options) - } + value = value.mapPoints(point => { + if (point.path.equals(path) && point.offset >= offset) { + return point.setOffset(point.offset + text.length) + } else { + return point + } + }) - return object + return value } - /** - * Deprecated. - */ - get history() { invariant( false, diff --git a/packages/slate/src/operations/apply.js b/packages/slate/src/operations/apply.js index 252746f041..76ae39d7ca 100644 --- a/packages/slate/src/operations/apply.js +++ b/packages/slate/src/operations/apply.js @@ -1,6 +1,10 @@ import Debug from 'debug' +import Annotation from '../models/annotation' +import Node from '../models/node' import Operation from '../models/operation' +import Mark from '../models/mark' +import PathUtils from '../utils/path-utils' /** * Debug. @@ -26,98 +30,345 @@ function applyOperation(value, op) { switch (type) { case 'add_annotation': { const { annotation } = op - const next = value.addAnnotation(annotation) - return next + const { key } = annotation + const { annotations } = value + const newAnnotations = annotations.set(key, annotation) + const newValue = value.set('annotations', newAnnotations) + return newValue } case 'add_mark': { const { path, mark } = op - const next = value.addMark(path, mark) - return next + const { document } = value + const node = document.assertNode(path) + const { marks } = node + const newMarks = marks.add(mark) + const newNode = node.set('marks', newMarks) + const newDocument = document.replaceNode(path, newNode) + const newValue = value.set('document', newDocument) + return newValue } case 'insert_node': { const { path, node } = op - const next = value.insertNode(path, node) - return next + const { document } = value + const index = path.last() + const parentPath = PathUtils.lift(path) + const parentNode = document.assertNode(parentPath) + const newParentNodes = parentNode.nodes.splice(index, 0, node) + const newParentNode = parentNode.set('nodes', newParentNodes) + const newDocument = document.replaceNode(parentPath, newParentNode) + + const newValue = mapPoints(value.set('document', newDocument), point => { + const newPaths = PathUtils.transform(point.path, op) + const newPath = newPaths.first() + const newPoint = point.setPath(newPath).setKey(null) + return newPoint + }) + + return newValue } case 'insert_text': { - const { path, offset, text, marks } = op - const next = value.insertText(path, offset, text, marks) - return next + const { path, offset, text } = op + const { document } = value + const node = document.assertNode(path) + const newText = + node.text.slice(0, offset) + text + node.text.slice(offset) + const newNode = node.set('text', newText) + const newDocument = document.replaceNode(path, newNode) + + const newValue = mapPoints(value.set('document', newDocument), point => { + if (point.path.equals(path) && point.offset >= offset) { + return point.setOffset(point.offset + text.length) + } else { + return point + } + }) + + return newValue } case 'merge_node': { - const { path } = op - const next = value.mergeNode(path) - return next + const { path, position } = op + const { document } = value + const withPath = PathUtils.decrement(path) + const parentPath = PathUtils.lift(path) + const index = withPath.last() + const parent = document.assertNode(parentPath) + const a = document.assertNode(withPath) + const b = document.assertNode(path) + + const newNode = + a.object === 'text' + ? a.mergeText(b) + : a.set('nodes', a.nodes.concat(b.nodes)) + + const newParentNodes = parent.nodes.splice(index, 2, newNode) + const newParent = parent.set('nodes', newParentNodes) + const newDocument = document.replaceNode(parentPath, newParent) + + const newValue = mapPoints(value.set('document', newDocument), point => { + if (point.path.equals(path)) { + const newPath = PathUtils.decrement(point.path) + const newOffset = point.offset + position + return point.moveTo(newPath, newOffset).setKey(null) + } else if (PathUtils.isAbove(path, point.path)) { + let newPath = PathUtils.decrement(point.path, 1, path.size - 1) + newPath = PathUtils.increment(newPath, position, path.size) + return point.setPath(newPath).setKey(null) + } else if (PathUtils.isYounger(path, point.path)) { + const newPath = PathUtils.decrement(point.path, 1, path.size - 1) + return point.setPath(newPath).setKey(null) + } else { + return point + } + }) + + return newValue } case 'move_node': { - const { path, newPath } = op - const next = value.moveNode(path, newPath) - return next + const { path } = op + const { document } = value + const index = path.last() + const parentPath = PathUtils.lift(path) + const node = document.assertNode(path) + const parent = document.assertNode(parentPath) + const nextParentNodes = parent.nodes.splice(index, 1) + const nextParent = parent.set('nodes', nextParentNodes) + let nextDocument = document.replaceNode(parentPath, nextParent) + + // This is a bit tricky, but since the `path` and `newPath` both refer to + // the same snapshot in time, after either inserting or removing as the + // first step, the second step's path can be out of date. So instead of + // using the `op.newPath` directly, we transform `op.path` to ascertain + // what the `newPath` would be after the operation was applied. + const newPath = PathUtils.transform(path, op).first() + + const newIndex = newPath.last() + const newParentPath = PathUtils.lift(newPath) + const newParent = nextDocument.assertNode(newParentPath) + const nextNewParentNodes = newParent.nodes.splice(newIndex, 0, node) + const nextNewParent = newParent.set('nodes', nextNewParentNodes) + nextDocument = nextDocument.replaceNode(newParentPath, nextNewParent) + + const nextValue = mapPoints( + value.set('document', nextDocument), + point => { + const nextPath = PathUtils.transform(point.path, op).first() + return point.setPath(nextPath).setKey(null) + } + ) + + return nextValue } case 'remove_annotation': { const { annotation } = op - const next = value.removeAnnotation(annotation) - return next + const { key } = annotation + const { annotations } = value + const newAnnotations = annotations.delete(key) + const newValue = value.set('annotations', newAnnotations) + return newValue } case 'remove_mark': { const { path, mark } = op - const next = value.removeMark(path, mark) - return next + const { document } = value + const node = document.assertNode(path) + const { marks } = node + const newMarks = marks.remove(mark) + const newNode = node.set('marks', newMarks) + const newDocument = document.replaceNode(path, newNode) + const newValue = value.set('document', newDocument) + return newValue } case 'remove_node': { const { path } = op - const next = value.removeNode(path) - return next + const { document } = value + const index = path.last() + const parentPath = PathUtils.lift(path) + const parentNode = document.assertNode(parentPath) + const newParentNodes = parentNode.nodes.splice(index, 1) + const newParentNode = parentNode.set('nodes', newParentNodes) + const newDocument = document.replaceNode(parentPath, newParentNode) + + const prev = document.previousText(path) + const next = document.nextText(path) + + const newValue = mapPoints(value.set('document', newDocument), point => { + const newPath = PathUtils.transform(point.path, op).first() + + if (newPath) { + return point.setPath(newPath).setKey(null) + } else if (prev) { + const [prevNode, prevPath] = prev + return point.moveTo(prevPath, prevNode.text.length).setKey(null) + } else if (next) { + let [, nextPath] = next + nextPath = PathUtils.transform(nextPath, op).first() + return point.moveTo(nextPath, 0).setKey(null) + } else { + return point.unset() + } + }) + + return newValue } case 'remove_text': { const { path, offset, text } = op - const next = value.removeText(path, offset, text) - return next + const { length } = text + const { document } = value + const node = document.assertNode(path) + const newText = + node.text.slice(0, offset) + node.text.slice(offset + length) + const newNode = node.set('text', newText) + const newDocument = document.replaceNode(path, newNode) + + const newValue = mapPoints(value.set('document', newDocument), point => { + const isEqual = point.path.equals(path) + const isEnd = point.offset >= offset + length + const isStart = point.offset > offset + + if (isEqual && isEnd) { + return point.setOffset(point.offset - length) + } else if (isEqual && isStart) { + return point.setOffset(offset) + } else { + return point + } + }) + + return newValue } case 'set_annotation': { const { properties, newProperties } = op - const next = value.setAnnotation(properties, newProperties) - return next + const { annotations } = value + const newAnnotation = Annotation.create({ + ...properties, + ...newProperties, + }) + + const { key } = newAnnotation + const newAnnotations = annotations.set(key, newAnnotation) + const newValue = value.set('annotations', newAnnotations) + return newValue } case 'set_mark': { const { path, properties, newProperties } = op - const next = value.setMark(path, properties, newProperties) - return next + const { document } = value + const mark = Mark.create(properties) + const newMark = Mark.create({ ...properties, ...newProperties }) + const node = document.assertNode(path) + const { marks } = node + const newMarks = marks.remove(mark).add(newMark) + const newNode = node.set('marks', newMarks) + const newDocument = document.replaceNode(path, newNode) + const newValue = value.set('document', newDocument) + return newValue } case 'set_node': { const { path, newProperties } = op - const next = value.setNode(path, newProperties) - return next + const { document } = value + const node = document.assertNode(path) + const newNode = node.merge(newProperties) + const newDocument = document.replaceNode(path, newNode) + const newValue = value.set('document', newDocument) + return newValue } case 'set_selection': { const { newProperties } = op - const next = value.setSelection(newProperties) - return next + const { document, selection } = value + let newSelection = selection.setProperties(newProperties) + + // TODO: this should not be required, and seems actively bad. The op + // should come in with correct properties already, so they shouldn't need + // to be resolved again. + newSelection = document.resolveSelection(newSelection) + + const newValue = value.set('selection', newSelection) + return newValue } case 'set_value': { const { newProperties } = op - const next = value.setProperties(newProperties) - return next + const { document } = value + let { data, annotations } = newProperties + let newValue = value + + if (data) { + newValue = newValue.set('data', data) + } + + if (annotations) { + // TODO: this should not happen, because again the ranges should already + // be resolved relative to the document when the operation is created. + annotations = annotations.map( + a => (a.isSet ? a : document.resolveAnnotation(a)) + ) + + newValue = newValue.set('annotations', annotations) + } + + return newValue } case 'split_node': { const { path, position, properties } = op - const next = value.splitNode(path, position, properties) - return next + const { document } = value + const node = document.assertNode(path) + let a + let b + + if (node.object === 'text') { + ;[a, b] = node.splitText(position) + } else { + const befores = node.nodes.take(position) + const afters = node.nodes.skip(position) + a = node.set('nodes', befores) + b = node.set('nodes', afters).regenerateKey() + + // TODO: remove this conditional, and always merge these + if (properties) { + b = b.merge(properties) + } + } + + const parentPath = PathUtils.lift(path) + const parent = document.assertNode(parentPath) + const index = path.last() + const newParentNodes = parent.nodes.splice(index, 1, a, b) + const newParent = parent.set('nodes', newParentNodes) + const newDocument = document.replaceNode(parentPath, newParent) + + const newValue = mapPoints(value.set('document', newDocument), point => { + if (point.path.equals(path) && position <= point.offset) { + const newPath = PathUtils.increment(point.path, 1, path.size - 1) + const newOffset = point.offset - position + return point.moveTo(newPath, newOffset).setKey(null) + } else if ( + PathUtils.isAbove(path, point.path) && + position <= point.path.get(path.size) + ) { + let newPath = PathUtils.increment(point.path, 1, path.size - 1) + newPath = PathUtils.decrement(newPath, position, path.size) + return point.setPath(newPath).setKey(null) + } else if (PathUtils.isYounger(path, point.path)) { + const newPath = PathUtils.increment(point.path, 1, path.size - 1) + return point.setPath(newPath).setKey(null) + } else { + return point + } + }) + + return newValue } default: { @@ -126,6 +377,29 @@ function applyOperation(value, op) { } } +function mapRanges(value, iterator) { + const { document, selection, annotations } = value + + let sel = selection.isSet ? iterator(selection) : selection + if (!sel) sel = selection.unset() + if (sel !== selection) sel = document.createSelection(sel) + value = value.set('selection', sel) + + let anns = annotations.map(annotation => { + let n = annotation.isSet ? iterator(annotation) : annotation + if (n && n !== annotation) n = document.createAnnotation(n) + return n + }) + + anns = anns.filter(annotation => !!annotation) + value = value.set('annotations', anns) + return value +} + +function mapPoints(value, iterator) { + return mapRanges(value, range => range.updatePoints(iterator)) +} + /** * Export. * diff --git a/packages/slate/src/plugins/schema.js b/packages/slate/src/plugins/schema.js index ad3338ba4f..a29881df77 100644 --- a/packages/slate/src/plugins/schema.js +++ b/packages/slate/src/plugins/schema.js @@ -120,7 +120,10 @@ function SchemaPlugin(schema) { function normalizeNode(node, editor, next) { const error = validateNode(node, editor, () => {}) - if (!error) return next() + + if (!error) { + return next() + } return () => { const { rule } = error @@ -152,7 +155,11 @@ function SchemaPlugin(schema) { function validateNode(node, editor, next) { const matches = schemaRules.filter(r => testRules(node, r.match)) const failure = validateRules(node, matches, schemaRules, { every: true }) - if (!failure) return next() + + if (!failure) { + return next() + } + const error = new SlateError(failure.code, failure) return error } diff --git a/packages/slate/src/utils/path-utils.js b/packages/slate/src/utils/path-utils.js index aa51213a96..471f944201 100644 --- a/packages/slate/src/utils/path-utils.js +++ b/packages/slate/src/utils/path-utils.js @@ -26,6 +26,19 @@ function compare(path, target) { return path.size === target.size ? 0 : null } +/** + * Does path `a` contain path `b`? + * + * @param {List} a + * @param {List} b + * @return {Boolean} + */ + +function contains(a, b) { + ;[a, b] = crop(a, b) + return isEqual(a, b) +} + /** * Create a path from `attrs`. * @@ -405,6 +418,7 @@ function transform(path, operation) { export default { compare, + contains, create, crop, decrement, From 9d6b2a7cce711a5ce5010026a36bcc1645e7b4e4 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sat, 11 May 2019 23:58:34 -0700 Subject: [PATCH 002/165] undeprecate some methods --- packages/slate/src/interfaces/element.js | 487 +++++++++++------------ 1 file changed, 230 insertions(+), 257 deletions(-) diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js index 529bd2b5f5..7d42cd8683 100644 --- a/packages/slate/src/interfaces/element.js +++ b/packages/slate/src/interfaces/element.js @@ -36,22 +36,6 @@ class ElementInterface { return this.getText() } - /** - * Add `mark` to text at `path`. - * - * @param {List|String} path - * @param {Mark} mark - * @return {Node} - */ - - addMark(path, mark) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.addMark(mark) - const ret = this.replaceNode(path, node) - return ret - } - /** * Create an iteratable for all of the ancestors of the node. * @@ -732,20 +716,37 @@ class ElementInterface { const { start, end } = range let node = this - let targetPath = end.path - let targetPosition = end.offset - let side = 'end' - - while (targetPath.size) { - const index = targetPath.last() - node = node.splitNode(targetPath, targetPosition) - targetPosition = index + 1 - targetPath = PathUtils.lift(targetPath) - - if (!targetPath.size && side === 'end') { - targetPath = start.path - targetPosition = start.offset - side = 'start' + let target = end + let path = target.path + let position = target.offset + + while (path.size) { + const index = path.last() + const child = node.assertNode(path) + const parentPath = PathUtils.lift(path) + const parent = node.assertNode(parentPath) + let a + let b + + if (child.object === 'text') { + ;[a, b] = child.splitText(position) + } else { + const befores = child.nodes.take(position) + const afters = child.nodes.skip(position) + a = child.set('nodes', befores) + b = child.set('nodes', afters).regenerateKey() + } + + const newParentNodes = parent.nodes.splice(index, 1, a, b) + const newParent = parent.set('nodes', newParentNodes) + node = node.replaceNode(parentPath, newParent) + position = index + 1 + path = PathUtils.lift(path) + + if (!path.size && target === end) { + target = start + path = target.path + position = target.offset } } @@ -1376,42 +1377,6 @@ class ElementInterface { return iterable } - /** - * Insert a `node`. - * - * @param {List|String} path - * @param {Node} node - * @return {Node} - */ - - insertNode(path, node) { - path = this.resolvePath(path) - const index = path.last() - const parentPath = PathUtils.lift(path) - let parent = this.assertNode(parentPath) - const nodes = parent.nodes.splice(index, 0, node) - parent = parent.set('nodes', nodes) - const ret = this.replaceNode(parentPath, parent) - return ret - } - - /** - * Insert `text` at `offset` in node by `path`. - * - * @param {List|String} path - * @param {Number} offset - * @param {String} text - * @return {Node} - */ - - insertText(path, offset, text) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.insertText(offset, text) - const ret = this.replaceNode(path, node) - return ret - } - /** * Check whether the node is a leaf block. * @@ -1561,127 +1526,6 @@ class ElementInterface { } } - /** - * Merge a node backwards its previous sibling. - * - * @param {List|Key} path - * @return {Node} - */ - - mergeNode(path) { - const b = this.assertNode(path) - path = this.resolvePath(path) - - if (path.last() === 0) { - throw new Error( - `Unable to merge node because it has no previous sibling: ${b}` - ) - } - - const withPath = PathUtils.decrement(path) - const a = this.assertNode(withPath) - - if (a.object !== b.object) { - throw new Error( - `Unable to merge two different kinds of nodes: ${a} and ${b}` - ) - } - - const newNode = - a.object === 'text' - ? a.mergeText(b) - : a.set('nodes', a.nodes.concat(b.nodes)) - - let ret = this - ret = ret.removeNode(path) - ret = ret.removeNode(withPath) - ret = ret.insertNode(withPath, newNode) - return ret - } - - /** - * Move a node by `path` to `newPath`. - * - * A `newIndex` can be provided when move nodes by `key`, to account for not - * being able to have a key for a location in the tree that doesn't exist yet. - * - * @param {List|Key} path - * @param {List|Key} newPath - * @param {Number} newIndex - * @return {Node} - */ - - moveNode(path, newPath, newIndex = 0) { - const node = this.assertNode(path) - path = this.resolvePath(path) - newPath = this.resolvePath(newPath, newIndex) - - const newParentPath = PathUtils.lift(newPath) - this.assertNode(newParentPath) - - // TODO: this is a bit hacky, re-creating the operation that led to this method being called - // Alternative 1: pass the operation through from apply -> value.moveNode - // Alternative 2: add a third property to the operation called "transformedNewPath", pass that through - const op = Operation.create({ - type: 'move_node', - path, - newPath, - }) - newPath = PathUtils.transform(path, op).first() - - let ret = this - ret = ret.removeNode(path) - ret = ret.insertNode(newPath, node) - return ret - } - - /** - * Remove `mark` from text at `path`. - * - * @param {List} path - * @param {Mark} mark - * @return {Node} - */ - - removeMark(path, mark) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.removeMark(mark) - const ret = this.replaceNode(path, node) - return ret - } - - /** - * Remove a node. - * - * @param {List|String} path - * @return {Node} - */ - - removeNode(path) { - this.assertDescendant(path) - path = this.resolvePath(path) - const deep = path.flatMap(x => ['nodes', x]) - const ret = this.deleteIn(deep) - return ret - } - - /** - * Remove `text` at `offset` in node. - * - * @param {List|Key} path - * @param {Number} offset - * @param {String} text - * @return {Node} - */ - - removeText(path, offset, text) { - let node = this.assertDescendant(path) - node = node.removeText(offset, text.length) - const ret = this.replaceNode(path, node) - return ret - } - /** * Replace a `node` in the tree. * @@ -1776,40 +1620,6 @@ class ElementInterface { return selection } - /** - * Set `properties` on a node. - * - * @param {List|String} path - * @param {Object} properties - * @return {Node} - */ - - setNode(path, properties) { - let node = this.assertNode(path) - node = node.merge(properties) - const ret = this.replaceNode(path, node) - return ret - } - - /** - * Set `properties` on `mark` on text at `offset` and `length` in node. - * - * @param {List|String} path - * @param {Number} offset - * @param {Number} length - * @param {Mark} mark - * @param {Object} properties - * @return {Node} - */ - - setMark(path, properties, newProperties) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.setMark(properties, newProperties) - const ret = this.replaceNode(path, node) - return ret - } - /** * Create an iteratable for the siblings in the tree at `path`. * @@ -1828,42 +1638,6 @@ class ElementInterface { return iterable } - /** - * Split a node by `path` at `position` with optional `properties` to apply - * to the newly split node. - * - * @param {List|String} path - * @param {Number} position - * @param {Object} properties - * @return {Node} - */ - - splitNode(path, position, properties) { - const child = this.assertNode(path) - path = this.resolvePath(path) - let a - let b - - if (child.object === 'text') { - ;[a, b] = child.splitText(position) - } else { - const befores = child.nodes.take(position) - const afters = child.nodes.skip(position) - a = child.set('nodes', befores) - b = child.set('nodes', afters).regenerateKey() - } - - if (properties && child.object !== 'text') { - b = b.merge(properties) - } - - let ret = this - ret = ret.removeNode(path) - ret = ret.insertNode(path, b) - ret = ret.insertNode(path, a) - return ret - } - /** * Create an iteratable for all the text node descendants. * @@ -1919,11 +1693,210 @@ class ElementInterface { return first } + firstBlock(options) { + const [first] = this.blocks(options) + return first + } + lastText() { const [last] = this.texts({ direction: 'backward' }) return last } + closest(path, predicate) { + for (const [n, p] of this.ancestors(path)) { + if (predicate(n, p)) { + return [n, p] + } + } + + return null + } + + closestBlock(path) { + const closest = this.closest(path, n => n.object === 'block') + return closest + } + + closestInline(path) { + const closest = this.closest(path, n => n.object === 'inline') + return closest + } + + closestVoid(path, editor) { + const closest = this.closest(path, n => editor.isVoid(n)) + return closest + } + + furthest(path, predicate = identity) { + const iterable = this.ancestors(path) + const results = Array.from(iterable).reverse() + + for (const [n, p] of results) { + if (predicate(n, p)) { + return [n, p] + } + } + + return null + } + + furthestBlock(path) { + const furthest = this.furthest(path, n => n.object === 'block') + return furthest + } + + furthestInline(path) { + const furthest = this.furthest(path, n => n.object === 'inline') + return furthest + } + + addMark(path, mark) { + path = this.resolvePath(path) + let node = this.assertDescendant(path) + node = node.addMark(mark) + const ret = this.replaceNode(path, node) + return ret + } + + setNode(path, properties) { + let node = this.assertNode(path) + node = node.merge(properties) + const ret = this.replaceNode(path, node) + return ret + } + + setMark(path, properties, newProperties) { + path = this.resolvePath(path) + let node = this.assertDescendant(path) + node = node.setMark(properties, newProperties) + const ret = this.replaceNode(path, node) + return ret + } + + splitNode(path, position, properties) { + const child = this.assertNode(path) + path = this.resolvePath(path) + let a + let b + + if (child.object === 'text') { + ;[a, b] = child.splitText(position) + } else { + const befores = child.nodes.take(position) + const afters = child.nodes.skip(position) + a = child.set('nodes', befores) + b = child.set('nodes', afters).regenerateKey() + } + + if (properties && child.object !== 'text') { + b = b.merge(properties) + } + + let ret = this + ret = ret.removeNode(path) + ret = ret.insertNode(path, b) + ret = ret.insertNode(path, a) + return ret + } + + insertNode(path, node) { + path = this.resolvePath(path) + const index = path.last() + const parentPath = PathUtils.lift(path) + let parent = this.assertNode(parentPath) + const nodes = parent.nodes.splice(index, 0, node) + parent = parent.set('nodes', nodes) + const ret = this.replaceNode(parentPath, parent) + return ret + } + + insertText(path, offset, text) { + path = this.resolvePath(path) + let node = this.assertDescendant(path) + node = node.insertText(offset, text) + const ret = this.replaceNode(path, node) + return ret + } + + mergeNode(path) { + const b = this.assertNode(path) + path = this.resolvePath(path) + + if (path.last() === 0) { + throw new Error( + `Unable to merge node because it has no previous sibling: ${b}` + ) + } + + const withPath = PathUtils.decrement(path) + const a = this.assertNode(withPath) + + if (a.object !== b.object) { + throw new Error( + `Unable to merge two different kinds of nodes: ${a} and ${b}` + ) + } + + const newNode = + a.object === 'text' + ? a.mergeText(b) + : a.set('nodes', a.nodes.concat(b.nodes)) + + let ret = this + ret = ret.removeNode(path) + ret = ret.removeNode(withPath) + ret = ret.insertNode(withPath, newNode) + return ret + } + + moveNode(path, newPath, newIndex = 0) { + const node = this.assertNode(path) + path = this.resolvePath(path) + newPath = this.resolvePath(newPath, newIndex) + + const newParentPath = PathUtils.lift(newPath) + this.assertNode(newParentPath) + + // TODO: this is a bit hacky, re-creating the operation that led to this method being called + // Alternative 1: pass the operation through from apply -> value.moveNode + // Alternative 2: add a third property to the operation called "transformedNewPath", pass that through + const op = Operation.create({ + type: 'move_node', + path, + newPath, + }) + newPath = PathUtils.transform(path, op).first() + + let ret = this + ret = ret.removeNode(path) + ret = ret.insertNode(newPath, node) + return ret + } + + removeMark(path, mark) { + path = this.resolvePath(path) + let node = this.assertDescendant(path) + node = node.removeMark(mark) + const ret = this.replaceNode(path, node) + return ret + } + + removeNode(path) { + this.assertDescendant(path) + path = this.resolvePath(path) + const deep = path.flatMap(x => ['nodes', x]) + const ret = this.deleteIn(deep) + return ret + } + + removeText(path, offset, text) { + let node = this.assertDescendant(path) + node = node.removeText(offset, text.length) + const ret = this.replaceNode(path, node) + return ret + } + /** * Deprecated. */ From 5368064419e01ee65e7f8a3d1017dac437c1cdbb Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 12 May 2019 09:36:32 -0400 Subject: [PATCH 003/165] convert more key usage to paths --- packages/slate/src/commands/at-range.js | 66 ++++++++++++++----------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 083d46a198..a27c92671c 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -417,11 +417,11 @@ Commands.deleteCharBackwardAtRange = (editor, range) => { const { value } = editor const { document } = value const { start } = range - const startBlock = document.getClosestBlock(start.path) - const offset = startBlock.getOffset(start.key) + const [block, path] = document.closestBlock(start.path) + const relativePath = start.path.slice(path.size) + const offset = block.getOffset(relativePath) const o = offset + start.offset - const { text } = startBlock - const n = TextUtils.getCharOffsetBackward(text, o) + const n = TextUtils.getCharOffsetBackward(block.text, o) editor.deleteBackwardAtRange(range, n) } @@ -441,11 +441,11 @@ Commands.deleteCharForwardAtRange = (editor, range) => { const { value } = editor const { document } = value const { start } = range - const startBlock = document.getClosestBlock(start.path) - const offset = startBlock.getOffset(start.key) + const [block, path] = document.closestBlock(start.path) + const relativePath = start.path.slice(path.size) + const offset = block.getOffset(relativePath) const o = offset + start.offset - const { text } = startBlock - const n = TextUtils.getCharOffsetForward(text, o) + const n = TextUtils.getCharOffsetForward(block.text, o) editor.deleteForwardAtRange(range, n) } @@ -458,7 +458,10 @@ Commands.deleteCharForwardAtRange = (editor, range) => { */ Commands.deleteForwardAtRange = (editor, range, n = 1) => { - if (n === 0) return + if (n === 0) { + return + } + const { value } = editor const { document } = value const { start, focus } = range @@ -571,8 +574,9 @@ Commands.deleteLineBackwardAtRange = (editor, range) => { const { value } = editor const { document } = value const { start } = range - const startBlock = document.getClosestBlock(start.path) - const offset = startBlock.getOffset(start.key) + const [block, path] = document.closestBlock(start.path) + const relativePath = start.path.slice(path.size) + const offset = block.getOffset(relativePath) const o = offset + start.offset editor.deleteBackwardAtRange(range, o) } @@ -593,10 +597,11 @@ Commands.deleteLineForwardAtRange = (editor, range) => { const { value } = editor const { document } = value const { start } = range - const startBlock = document.getClosestBlock(start.path) - const offset = startBlock.getOffset(start.key) + const [block, path] = document.closestBlock(start.path) + const relativePath = start.path.slice(path.size) + const offset = block.getOffset(relativePath) const o = offset + start.offset - editor.deleteForwardAtRange(range, startBlock.text.length - o) + editor.deleteForwardAtRange(range, block.text.length - o) } /** @@ -615,11 +620,11 @@ Commands.deleteWordBackwardAtRange = (editor, range) => { const { value } = editor const { document } = value const { start } = range - const startBlock = document.getClosestBlock(start.path) - const offset = startBlock.getOffset(start.key) + const [block, path] = document.closestBlock(start.path) + const relativePath = start.path.slice(path.size) + const offset = block.getOffset(relativePath) const o = offset + start.offset - const { text } = startBlock - const n = o === 0 ? 1 : TextUtils.getWordOffsetBackward(text, o) + const n = o === 0 ? 1 : TextUtils.getWordOffsetBackward(block.text, o) editor.deleteBackwardAtRange(range, n) } @@ -639,11 +644,11 @@ Commands.deleteWordForwardAtRange = (editor, range) => { const { value } = editor const { document } = value const { start } = range - const startBlock = document.getClosestBlock(start.path) - const offset = startBlock.getOffset(start.key) + const [block, path] = document.closestBlock(start.path) + const relativePath = start.path.slice(path.size) + const offset = block.getOffset(relativePath) const o = offset + start.offset - const { text } = startBlock - const wordOffset = TextUtils.getWordOffsetForward(text, o) + const wordOffset = TextUtils.getWordOffsetForward(block.text, o) const n = wordOffset === 0 ? 1 : wordOffset editor.deleteForwardAtRange(range, n) } @@ -1080,21 +1085,22 @@ Commands.splitBlockAtRange = (editor, range, height = 1) => { Commands.splitInlineAtRange = (editor, range, height = Infinity) => { range = deleteExpandedAtRange(editor, range) - const { start } = range const { value } = editor const { document } = value - let node = document.assertDescendant(start.path) - let parent = document.getClosestInline(node.key) let h = 0 + let targetPath - while (parent && parent.object === 'inline' && h < height) { - node = parent - parent = document.getClosestInline(parent.key) - h++ + for (const [node, path] of document.ancestors(start.path)) { + if (node.object === 'inline' && h < height) { + targetPath = path + h++ + } else { + break + } } - editor.splitDescendantsByKey(node.key, start.path, start.offset) + editor.splitDescendantsByPath(targetPath, start.path, start.offset) } /** From 24105bfbefdfa0e31e2d2916be7a7a044ec67f34 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 21 May 2019 13:22:30 -0700 Subject: [PATCH 004/165] update deprecations --- packages/slate/src/models/value.js | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index 873a1b8d92..9e9b647c73 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -456,7 +456,7 @@ class Value extends Record(DEFAULTS) { mapRanges(iterator) { warning( false, - 'As of slate@0.48 the `value.mapRanges` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.mapRanges` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -481,7 +481,7 @@ class Value extends Record(DEFAULTS) { mapPoints(iterator) { warning( false, - 'As of slate@0.48 the `value.mapPoints` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.mapPoints` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) return this.mapRanges(range => range.updatePoints(iterator)) @@ -490,7 +490,7 @@ class Value extends Record(DEFAULTS) { mergeNode(path) { warning( false, - 'As of slate@0.48 the `value.mergeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.mergeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -526,7 +526,7 @@ class Value extends Record(DEFAULTS) { splitNode(path, position, properties) { warning( false, - 'As of slate@0.48 the `value.splitNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.splitNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -560,7 +560,7 @@ class Value extends Record(DEFAULTS) { removeNode(path) { warning( false, - 'As of slate@0.48 the `value.removeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.removeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -600,7 +600,7 @@ class Value extends Record(DEFAULTS) { moveNode(path, newPath, newIndex = 0) { warning( false, - 'As of slate@0.48 the `value.moveNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.moveNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -619,7 +619,7 @@ class Value extends Record(DEFAULTS) { removeText(path, offset, text) { warning( false, - 'As of slate@0.48 the `value.removeText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.removeText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -654,7 +654,7 @@ class Value extends Record(DEFAULTS) { setNode(path, properties) { warning( false, - 'As of slate@0.48 the `value.setNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.setNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -667,7 +667,7 @@ class Value extends Record(DEFAULTS) { setAnnotation(properties, newProperties) { warning( false, - 'As of slate@0.48 the `value.setAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.setAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) newProperties = Annotation.createProperties(newProperties) @@ -684,7 +684,7 @@ class Value extends Record(DEFAULTS) { setMark(path, mark, properties) { warning( false, - 'As of slate@0.48 the `value.setMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.setMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -697,7 +697,7 @@ class Value extends Record(DEFAULTS) { setProperties(properties) { warning( false, - 'As of slate@0.48 the `value.setProperties` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.setProperties` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -722,7 +722,7 @@ class Value extends Record(DEFAULTS) { setSelection(properties) { warning( false, - 'As of slate@0.48 the `value.setSelection` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.setSelection` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -736,7 +736,7 @@ class Value extends Record(DEFAULTS) { removeAnnotation(annotation) { warning( false, - 'As of slate@0.48 the `value.removeAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.removeAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) annotation = Annotation.create(annotation) @@ -751,7 +751,7 @@ class Value extends Record(DEFAULTS) { removeMark(path, mark) { warning( false, - 'As of slate@0.48 the `value.removeMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.removeMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) mark = Mark.create(mark) @@ -765,7 +765,7 @@ class Value extends Record(DEFAULTS) { addAnnotation(annotation) { warning( false, - 'As of slate@0.48 the `value.addAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.addAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) annotation = Annotation.create(annotation) @@ -780,7 +780,7 @@ class Value extends Record(DEFAULTS) { addMark(path, mark) { warning( false, - 'As of slate@0.48 the `value.addMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.addMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) mark = Mark.create(mark) @@ -794,7 +794,7 @@ class Value extends Record(DEFAULTS) { insertNode(path, node) { warning( false, - 'As of slate@0.48 the `value.insertNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.insertNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this @@ -812,7 +812,7 @@ class Value extends Record(DEFAULTS) { insertText(path, offset, text) { warning( false, - 'As of slate@0.48 the `value.insertText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' + 'As of slate@0.47 the `value.insertText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' ) let value = this From 8dfa9ef09cc60727095b8920f6545d659fdb9c88 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 22 May 2019 11:58:48 -0700 Subject: [PATCH 005/165] convert selection commands to use all paths --- packages/slate/src/commands/on-selection.js | 2181 ++++++++++++++--- packages/slate/src/interfaces/element.js | 87 +- .../{commands.js => commands/index.js} | 0 .../slate/src/plugins/core/core-commands.js | 32 + .../slate/src/plugins/core/core-queries.js | 139 ++ .../plugins/{core.js => core/core-schema.js} | 62 +- packages/slate/src/plugins/core/index.js | 26 + .../plugins/{queries.js => queries/index.js} | 0 .../plugins/{schema.js => schema/index.js} | 4 +- .../move-word-backward/expanded.js | 3 +- .../move-word-backward/reversed.js | 3 +- .../move-word-forward/expanded.js | 2 +- .../move-word-forward/reversed.js | 2 +- 13 files changed, 2169 insertions(+), 372 deletions(-) rename packages/slate/src/plugins/{commands.js => commands/index.js} (100%) create mode 100644 packages/slate/src/plugins/core/core-commands.js create mode 100644 packages/slate/src/plugins/core/core-queries.js rename packages/slate/src/plugins/{core.js => core/core-schema.js} (78%) create mode 100644 packages/slate/src/plugins/core/index.js rename packages/slate/src/plugins/{queries.js => queries/index.js} (100%) rename packages/slate/src/plugins/{schema.js => schema/index.js} (99%) diff --git a/packages/slate/src/commands/on-selection.js b/packages/slate/src/commands/on-selection.js index fd1bea7607..3484637878 100644 --- a/packages/slate/src/commands/on-selection.js +++ b/packages/slate/src/commands/on-selection.js @@ -1,4 +1,5 @@ import { is } from 'immutable' +import warning from 'tiny-warning' import pick from 'lodash/pick' import Selection from '../models/selection' @@ -6,587 +7,2123 @@ import TextUtils from '../utils/text-utils' const Commands = {} +/** + * Get the next point by `n`. + * + * @param {Editor} editor + * @param {Point} point + * @param {Number} n + * @return {Point} + */ + +function getNextPoint(editor, point, n) { + for (let i = 0; i < n; i++) { + point = editor.getNextPoint(point) + } + + return point +} + +/** + * Get the previous point by `n`. + * + * @param {Editor} editor + * @param {Point} point + * @param {Number} n + * @return {Point} + */ + +function getPreviousPoint(editor, point, n) { + for (let i = 0; i < n; i++) { + point = editor.getPreviousPoint(point) + } + + return point +} + +/** + * Get word offset backward from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Number} + */ + +function getWordOffsetBackward(editor, point) { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + const o = blockOffset + offset + return TextUtils.getWordOffsetBackward(block.text, o) +} + +/** + * Get word offset forward from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Number} + */ + +function getWordOffsetForward(editor, point) { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + const o = blockOffset + offset + return TextUtils.getWordOffsetForward(block.text, o) +} + +/** + * Blur the selection. + * + * @param {Editor} editor + */ + Commands.blur = editor => { editor.select({ isFocused: false }) } +/** + * Deselect the selection. + * + * @param {Editor} editor + */ + Commands.deselect = editor => { - const range = Selection.create() - editor.select(range) + editor.select(Selection.create()) } +/** + * Focus the selection. + * + * @param {Editor} editor + */ + Commands.focus = editor => { editor.select({ isFocused: true }) } +/** + * Flip the selection's anchor and focus points. + * + * @param {Editor} editor + */ + Commands.flip = editor => { - editor.command(proxy, 'flip') + const { value: { selection } } = editor + const range = selection.flip() + editor.select(range) } -Commands.moveAnchorBackward = (editor, ...args) => { - editor.command(pointBackward, 'anchor', ...args) -} +/** + * Move the selection's anchor point backwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ -Commands.moveAnchorWordBackward = (editor, ...args) => { - editor.command(pointWordBackward, 'anchor', ...args) +Commands.moveAnchorBackward = (editor, n = 1) => { + const { value: { selection } } = editor + const point = getPreviousPoint(editor, selection.anchor, n) + editor.moveAnchorTo(point.path, point.offset) } -Commands.moveAnchorForward = (editor, ...args) => { - editor.command(pointForward, 'anchor', ...args) -} +/** + * Move the selection's anchor point forwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ -Commands.moveAnchorWordForward = (editor, ...args) => { - editor.command(pointWordForward, 'anchor', ...args) +Commands.moveAnchorForward = (editor, n = 1) => { + const { value: { selection } } = editor + const point = getNextPoint(editor, selection.anchor, n) + editor.moveAnchorTo(point.path, point.offset) } -Commands.moveAnchorTo = (editor, ...args) => { - editor.command(proxy, 'moveAnchorTo', ...args) +/** + * Move the selection's anchor point to a specific `path` and `offset`. + * + * @param {Editor} editor + * @param {Path} path + * @param {Number} offset + */ + +Commands.moveAnchorTo = (editor, path, offset) => { + const { value: { selection } } = editor + const range = selection.moveAnchorTo(path, offset) + editor.select(range) } +/** + * Move the selection's anchor point to the end of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfBlock = editor => { - editor.command(pointEdgeObject, 'anchor', 'end', 'block') + const { value: { document, selection } } = editor + const entry = document.closestBlock(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveAnchorToEndOfPath = (editor, path) => { + const { value: { document } } = editor + const entry = document.lastText({ path }) + + if (entry) { + const [targetNode, targetPath] = entry + editor.moveAnchorTo(targetPath, targetNode.text.length) + } +} + +/** + * Move the selection's anchor point to the end of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfInline = editor => { - editor.command(pointEdgeObject, 'anchor', 'end', 'inline') + const { value: { document, selection } } = editor + const entry = document.closestInline(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the document. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfDocument = editor => { - editor.moveAnchorToEndOfNode(editor.value.document).moveToAnchor() + const { value: { document } } = editor + const entry = document.lastText() + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the next block. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'end', 'next', 'block') + const { value: { document, selection } } = editor + const entry = document.nextBlock(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the next inline. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'end', 'next', 'inline') + const { value: { document, selection } } = editor + const entry = document.nextInline(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the next text node. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfNextText = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'end', 'next', 'text') -} + const { value: { document, selection } } = editor + const entry = document.nextText(selection.anchor.path) -Commands.moveAnchorToEndOfNode = (editor, ...args) => { - editor.command(proxy, 'moveAnchorToEndOfNode', ...args) + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the previous block. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'end', 'previous', 'block') + const { value: { document, selection } } = editor + const entry = document.previousBlock(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'end', 'previous', 'inline') + const { value: { document, selection } } = editor + const entry = document.previousInline(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'end', 'previous', 'text') + const { value: { document, selection } } = editor + const entry = document.previousText(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's anchor point to the end of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveAnchorToEndOfText = editor => { - editor.command(pointEdgeObject, 'anchor', 'end', 'text') + const { value: { selection } } = editor + editor.moveAnchorToEndOfPath(selection.anchor.path) } +/** + * Move the selection's anchor point to the start of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfBlock = editor => { - editor.command(pointEdgeObject, 'anchor', 'start', 'block') + const { value: { document, selection } } = editor + const entry = document.closestBlock(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } -Commands.moveAnchorToStartOfDocument = editor => { - editor.moveAnchorToStartOfNode(editor.value.document).moveToAnchor() +/** + * Move the selection's anchor point to the start of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveAnchorToStartOfPath = (editor, path) => { + const { value: { document } } = editor + const entry = document.lastText({ path }) + + if (entry) { + const [, targetPath] = entry + editor.moveAnchorTo(targetPath, 0) + } } +/** + * Move the selection's anchor point to the start of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfInline = editor => { - editor.command(pointEdgeObject, 'anchor', 'start', 'inline') + const { value: { document, selection } } = editor + const entry = document.closestInline(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's anchor point to the start of the document. + * + * @param {Editor} editor + */ + +Commands.moveAnchorToStartOfDocument = editor => { + const { value: { document } } = editor + const entry = document.firstText() + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } +} + +/** + * Move the selection's anchor point to the start of the next block. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'start', 'next', 'block') + const { value: { document, selection } } = editor + const entry = document.nextBlock(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's anchor point to the start of the next inline. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'start', 'next', 'inline') + const { value: { document, selection } } = editor + const entry = document.nextInline(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's anchor point to the start of the next text node. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfNextText = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'start', 'next', 'text') -} + const { value: { document, selection } } = editor + const entry = document.nextText(selection.anchor.path) -Commands.moveAnchorToStartOfNode = (editor, ...args) => { - editor.command(proxy, 'moveAnchorToStartOfNode', ...args) + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's anchor point to the start of the previous block. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'start', 'previous', 'block') + const { value: { document, selection } } = editor + const entry = document.previousBlock(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's anchor point to the start of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'start', 'previous', 'inline') + const { value: { document, selection } } = editor + const entry = document.previousInline(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's anchor point to the start of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'anchor', 'start', 'previous', 'text') + const { value: { document, selection } } = editor + const entry = document.previousText(selection.anchor.path) + + if (entry) { + const [, path] = entry + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's anchor point to the start of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveAnchorToStartOfText = editor => { - editor.command(pointEdgeObject, 'anchor', 'start', 'text') + const { value: { selection } } = editor + editor.moveAnchorToStartOfPath(selection.anchor.path) } -Commands.moveBackward = (editor, ...args) => { - editor.moveAnchorBackward(...args).moveFocusBackward(...args) +/** + * Move the selection's anchor point backward to the edge of the nearest word. + * + * @param {Editor} editor + */ + +Commands.moveAnchorWordBackward = editor => { + const { value: { selection } } = editor + const n = getWordOffsetBackward(editor, selection.anchor) + editor.moveAnchorBackward(n) } -Commands.moveWordBackward = (editor, ...args) => { - editor.moveFocusWordBackward(...args).moveToFocus() +/** + * Move the selection's anchor point forward to the edge of the nearest word. + * + * @param {Editor} editor + */ + +Commands.moveAnchorWordForward = editor => { + const { value: { selection } } = editor + const n = getWordOffsetForward(editor, selection.anchor) + editor.moveAnchorForward(n) } -Commands.moveEndBackward = (editor, ...args) => { - editor.command(pointBackward, 'end', ...args) +/** + * Move the selection backward by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveBackward = (editor, n) => { + editor.moveAnchorBackward(n).moveFocusBackward(n) } -Commands.moveEndWordBackward = (editor, ...args) => { - editor.command(pointWordBackward, 'end', ...args) +/** + * Move the selection backward by `n` words. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveWordBackward = (editor, n) => { + editor.moveAnchorWordBackward(n).moveFocusWordBackward(n) } -Commands.moveEndForward = (editor, ...args) => { - editor.command(pointForward, 'end', ...args) +/** + * Move the selection's end point backwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveEndBackward = (editor, n = 1) => { + if (editor.value.selection.isForward) { + editor.moveFocusBackward(n) + } else { + editor.moveAnchorBackward(n) + } } -Commands.moveEndWordForward = (editor, ...args) => { - editor.command(pointWordForward, 'end', ...args) +/** + * Move the selection's end point forwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveEndForward = (editor, n = 1) => { + if (editor.value.selection.isForward) { + editor.moveFocusForward(n) + } else { + editor.moveAnchorForward() + } } -Commands.moveEndTo = (editor, ...args) => { - editor.command(proxy, 'moveEndTo', ...args) +/** + * Move the selection's end point to a specific `path` and `offset`. + * + * @param {Editor} editor + * @param {Array} path + * @param {Number} offset + */ + +Commands.moveEndTo = (editor, path, offset) => { + const { value: { selection } } = editor + const range = selection.moveEndTo(path, offset) + editor.select(range) } +/** + * Move the selection's end point to the end of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfBlock = editor => { - editor.command(pointEdgeObject, 'end', 'end', 'block') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfBlock() + } else { + editor.moveAnchorToEndOfBlock() + } } +/** + * Move the selection's end point to the end of the document. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfDocument = editor => { - editor.moveEndToEndOfNode(editor.value.document).moveToEnd() + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfDocument() + } else { + editor.moveAnchorToEndOfDocument() + } } +/** + * Move the selection's end point to the end of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfInline = editor => { - editor.command(pointEdgeObject, 'end', 'end', 'inline') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfInline() + } else { + editor.moveAnchorToEndOfInline() + } } +/** + * Move the selection's end point to the end of the next block. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'end', 'end', 'next', 'block') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfNextBlock() + } else { + editor.moveAnchorToEndOfNextBlock() + } } +/** + * Move the selection's end point to the end of the next inline. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'end', 'end', 'next', 'inline') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfNextInline() + } else { + editor.moveAnchorToEndOfNextInline() + } } +/** + * Move the selection's end point to the end of the next text node. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfNextText = editor => { - editor.command(pointEdgeSideObject, 'end', 'end', 'next', 'text') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfNextText() + } else { + editor.moveAnchorToEndOfNextText() + } } -Commands.moveEndToEndOfNode = (editor, ...args) => { - editor.command(proxy, 'moveEndToEndOfNode', ...args) +/** + * Move the selection's end point to the end of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveEndToEndOfPath = (editor, path) => { + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfPath(path) + } else { + editor.moveAnchorToEndOfPath(path) + } } +/** + * Move the selection's end point to the end of the previous block. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'end', 'end', 'previous', 'block') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfPreviousBlock() + } else { + editor.moveAnchorToEndOfPreviousBlock() + } } +/** + * Move the selection's end point to the end of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'end', 'end', 'previous', 'inline') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfPreviousInline() + } else { + editor.moveAnchorToEndOfPreviousInline() + } } +/** + * Move the selection's end point to the end of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'end', 'end', 'previous', 'text') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfPreviousText() + } else { + editor.moveAnchorToEndOfPreviousText() + } } +/** + * Move the selection's end point to the end of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveEndToEndOfText = editor => { - editor.command(pointEdgeObject, 'end', 'end', 'text') + if (editor.value.selection.isForward) { + editor.moveFocusToEndOfText() + } else { + editor.moveAnchorToEndOfText() + } } +/** + * Move the selection's end point to the start of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfBlock = editor => { - editor.command(pointEdgeObject, 'end', 'start', 'block') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfBlock() + } else { + editor.moveAnchorToStartOfBlock() + } } +/** + * Move the selection's end point to the start of the document. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfDocument = editor => { - editor.moveEndToStartOfNode(editor.value.document).moveToEnd() + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfDocument() + } else { + editor.moveAnchorToStartOfDocument() + } } +/** + * Move the selection's end point to the start of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfInline = editor => { - editor.command(pointEdgeObject, 'end', 'start', 'inline') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfInline() + } else { + editor.moveAnchorToStartOfInline() + } } +/** + * Move the selection's end point to the start of the next block. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'end', 'start', 'next', 'block') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfNextBlock() + } else { + editor.moveAnchorToStartOfNextBlock() + } } +/** + * Move the selection's end point to the start of the next inline. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'end', 'start', 'next', 'inline') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfNextInline() + } else { + editor.moveAnchorToStartOfNextInline() + } } +/** + * Move the selection's end point to the start of the next text node. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfNextText = editor => { - editor.command(pointEdgeSideObject, 'end', 'start', 'next', 'text') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfNextText() + } else { + editor.moveAnchorToStartOfNextText() + } } -Commands.moveEndToStartOfNode = (editor, ...args) => { - editor.command(proxy, 'moveEndToStartOfNode', ...args) +/** + * Move the selection's end point to the start of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveEndToStartOfPath = (editor, path) => { + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfPath(path) + } else { + editor.moveAnchorToStartOfPath(path) + } } +/** + * Move the selection's end point to the start of the previous block. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'end', 'start', 'previous', 'block') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfPreviousBlock() + } else { + editor.moveAnchorToStartOfPreviousBlock() + } } +/** + * Move the selection's end point to the start of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'end', 'start', 'previous', 'inline') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfPreviousInline() + } else { + editor.moveAnchorToStartOfPreviousInline() + } } +/** + * Move the selection's end point to the start of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'end', 'start', 'previous', 'text') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfPreviousText() + } else { + editor.moveAnchorToStartOfPreviousText() + } } +/** + * Move the selection's end point to the start of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveEndToStartOfText = editor => { - editor.command(pointEdgeObject, 'end', 'start', 'text') + if (editor.value.selection.isForward) { + editor.moveFocusToStartOfText() + } else { + editor.moveAnchorToStartOfText() + } } -Commands.moveFocusBackward = (editor, ...args) => { - editor.command(pointBackward, 'focus', ...args) +/** + * Move the selection's end point backward to the edge of the nearest word. + * + * @param {Editor} editor + */ + +Commands.moveEndWordBackward = (editor, ...args) => { + if (editor.value.selection.isForward) { + editor.moveFocusWordBackward() + } else { + editor.moveAnchorWordBackward() + } } -Commands.moveFocusWordBackward = (editor, ...args) => { - editor.command(pointWordBackward, 'focus', ...args) +/** + * Move the selection's end point forward to the edge of the nearest word. + * + * @param {Editor} editor + */ + +Commands.moveEndWordForward = (editor, ...args) => { + if (editor.value.selection.isForward) { + editor.moveFocusWordForward() + } else { + editor.moveAnchorWordForward() + } } -Commands.moveFocusForward = (editor, ...args) => { - editor.command(pointForward, 'focus', ...args) +/** + * Move the selection's focus point backwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveFocusBackward = (editor, n = 1) => { + const { value: { selection } } = editor + const point = getPreviousPoint(editor, selection.focus, n) + editor.moveFocusTo(point.path, point.offset) } -Commands.moveFocusWordForward = (editor, ...args) => { - editor.command(pointWordForward, 'focus', ...args) +/** + * Move the selection's focus point forwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveFocusForward = (editor, n = 1) => { + const { value: { selection } } = editor + const point = getNextPoint(editor, selection.focus, n) + editor.moveFocusTo(point.path, point.offset) } -Commands.moveFocusTo = (editor, ...args) => { - editor.command(proxy, 'moveFocusTo', ...args) +/** + * Move the selection's focus point to a specific `path` and `offset`. + * + * @param {Path} path + * @param {Number} offset + * @param {Editor} editor + */ + +Commands.moveFocusTo = (editor, path, offset) => { + const { value: { selection } } = editor + const range = selection.moveFocusTo(path, offset) + editor.select(range) } +/** + * Move the selection's focus point to the end of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfBlock = editor => { - editor.command(pointEdgeObject, 'focus', 'end', 'block') + const { value: { document, selection } } = editor + const entry = document.closestBlock(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } -Commands.moveFocusToEndOfDocument = editor => { - editor.moveFocusToEndOfNode(editor.value.document).moveToFocus() +/** + * Move the selection's focus point to the end of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveFocusToEndOfPath = (editor, path) => { + const { value: { document } } = editor + const entry = document.lastText({ path }) + + if (entry) { + const [targetNode, targetPath] = entry + editor.moveFocusTo(targetPath, targetNode.text.length) + } } +/** + * Move the selection's focus point to the end of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfInline = editor => { - editor.command(pointEdgeObject, 'focus', 'end', 'inline') + const { value: { document, selection } } = editor + const entry = document.closestInline(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } +} + +/** + * Move the selection's focus point to the end of the document. + * + * @param {Editor} editor + */ + +Commands.moveFocusToEndOfDocument = editor => { + const { value: { document } } = editor + const entry = document.lastText() + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's focus point to the end of the next block. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'focus', 'end', 'next', 'block') + const { value: { document, selection } } = editor + const entry = document.nextBlock(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's focus point to the end of the next inline. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'focus', 'end', 'next', 'inline') + const { value: { document, selection } } = editor + const entry = document.nextInline(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's focus point to the end of the next text node. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfNextText = editor => { - editor.command(pointEdgeSideObject, 'focus', 'end', 'next', 'text') -} + const { value: { document, selection } } = editor + const entry = document.nextText(selection.focus.path) -Commands.moveFocusToEndOfNode = (editor, ...args) => { - editor.command(proxy, 'moveFocusToEndOfNode', ...args) + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's focus point to the end of the previous block. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'focus', 'end', 'previous', 'block') + const { value: { document, selection } } = editor + const entry = document.previousBlock(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's focus point to the end of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'focus', 'end', 'previous', 'inline') + const { value: { document, selection } } = editor + const entry = document.previousInline(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's focus point to the end of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'focus', 'end', 'previous', 'text') + const { value: { document, selection } } = editor + const entry = document.previousText(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's focus point to the end of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveFocusToEndOfText = editor => { - editor.command(pointEdgeObject, 'focus', 'end', 'text') + const { value: { selection } } = editor + editor.moveFocusToEndOfPath(selection.focus.path) } +/** + * Move the selection's focus point to the start of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfBlock = editor => { - editor.command(pointEdgeObject, 'focus', 'start', 'block') + const { value: { document, selection } } = editor + const entry = document.closestBlock(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } -Commands.moveFocusToStartOfDocument = editor => { - editor.moveFocusToStartOfNode(editor.value.document).moveToFocus() +/** + * Move the selection's focus point to the start of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveFocusToStartOfPath = (editor, path) => { + const { value: { document } } = editor + const entry = document.lastText({ path }) + + if (entry) { + const [, targetPath] = entry + editor.moveFocusTo(targetPath, 0) + } } +/** + * Move the selection's focus point to the start of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfInline = editor => { - editor.command(pointEdgeObject, 'focus', 'start', 'inline') + const { value: { document, selection } } = editor + const entry = document.closestInline(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } +} + +/** + * Move the selection's focus point to the start of the document. + * + * @param {Editor} editor + */ + +Commands.moveFocusToStartOfDocument = editor => { + const { value: { document } } = editor + const entry = document.firstText() + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's focus point to the start of the next block. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'focus', 'start', 'next', 'block') + const { value: { document, selection } } = editor + const entry = document.nextBlock(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's focus point to the start of the next inline. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'focus', 'start', 'next', 'inline') + const { value: { document, selection } } = editor + const entry = document.nextInline(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's focus point to the start of the next text node. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfNextText = editor => { - editor.command(pointEdgeSideObject, 'focus', 'start', 'next', 'text') -} + const { value: { document, selection } } = editor + const entry = document.nextText(selection.focus.path) -Commands.moveFocusToStartOfNode = (editor, ...args) => { - editor.command(proxy, 'moveFocusToStartOfNode', ...args) + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's focus point to the start of the previous block. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'focus', 'start', 'previous', 'block') + const { value: { document, selection } } = editor + const entry = document.previousBlock(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's focus point to the start of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'focus', 'start', 'previous', 'inline') + const { value: { document, selection } } = editor + const entry = document.previousInline(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's focus point to the start of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'focus', 'start', 'previous', 'text') + const { value: { document, selection } } = editor + const entry = document.previousText(selection.focus.path) + + if (entry) { + const [, path] = entry + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's focus point to the start of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveFocusToStartOfText = editor => { - editor.command(pointEdgeObject, 'focus', 'start', 'text') + const { value: { selection } } = editor + editor.moveFocusToStartOfPath(selection.focus.path) } -Commands.moveForward = (editor, ...args) => { - editor.moveAnchorForward(...args).moveFocusForward(...args) -} +/** + * Move the selection's focus point backward to the edge of the nearest word. + * + * @param {Editor} editor + */ -Commands.moveWordForward = (editor, ...args) => { - editor.moveFocusWordForward(...args).moveToFocus(...args) +Commands.moveFocusWordBackward = editor => { + const { value: { selection } } = editor + const n = getWordOffsetBackward(editor, selection.focus) + editor.moveFocusBackward(n) } -Commands.moveStartBackward = (editor, ...args) => { - editor.command(pointBackward, 'start', ...args) +/** + * Move the selection's focus point forward to the edge of the nearest word. + * + * @param {Editor} editor + */ + +Commands.moveFocusWordForward = editor => { + const { value: { selection } } = editor + const n = getWordOffsetForward(editor, selection.focus) + editor.moveFocusForward(n) } -Commands.moveStartWordBackward = (editor, ...args) => { - editor.command(pointWordBackward, 'start', ...args) +/** + * Move the selection's points each forward by one character. + * + * @param {Editor} editor + */ + +Commands.moveForward = (editor, ...args) => { + editor.moveAnchorForward(...args).moveFocusForward(...args) } -Commands.moveStartForward = (editor, ...args) => { - editor.command(pointForward, 'start', ...args) +/** + * Move the selection's start point backwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveStartBackward = (editor, n = 1) => { + if (editor.value.selection.isForward) { + editor.moveAnchorBackward(n) + } else { + editor.moveFocusBackward(n) + } } -Commands.moveStartWordForward = (editor, ...args) => { - editor.command(pointWordForward, 'start', ...args) +/** + * Move the selection's start point forwards by `n`. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveStartForward = (editor, n = 1) => { + if (editor.value.selection.isForward) { + editor.moveAnchorForward(n) + } else { + editor.moveFocusForward(n) + } } -Commands.moveStartTo = (editor, ...args) => { - editor.command(proxy, 'moveStartTo', ...args) +/** + * Move the selection's start point to a specific `path` and `offset`. + * + * @param {Editor} editor + * @param {Array} path + * @param {Number} offset + */ + +Commands.moveStartTo = (editor, path, offset) => { + const { value: { selection } } = editor + const range = selection.moveStartTo(path, offset) + editor.select(range) } +/** + * Move the selection's start point to the end of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfBlock = editor => { - editor.command(pointEdgeObject, 'start', 'end', 'block') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfBlock() + } else { + editor.moveFocusToEndOfBlock() + } } +/** + * Move the selection's start point to the end of the document. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfDocument = editor => { - editor.moveStartToEndOfNode(editor.value.document).moveToStart() + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfDocument() + } else { + editor.moveFocusToEndOfDocument() + } } +/** + * Move the selection's start point to the end of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfInline = editor => { - editor.command(pointEdgeObject, 'start', 'end', 'inline') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfInline() + } else { + editor.moveFocusToEndOfInline() + } } +/** + * Move the selection's start point to the end of the next block. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'start', 'end', 'next', 'block') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfNextBlock() + } else { + editor.moveFocusToEndOfNextBlock() + } } +/** + * Move the selection's start point to the end of the next inline. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'start', 'end', 'next', 'inline') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfNextInline() + } else { + editor.moveFocusToEndOfNextInline() + } } +/** + * Move the selection's start point to the end of the next text node. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfNextText = editor => { - editor.command(pointEdgeSideObject, 'start', 'end', 'next', 'text') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfNextText() + } else { + editor.moveFocusToEndOfNextText() + } } -Commands.moveStartToEndOfNode = (editor, ...args) => { - editor.command(proxy, 'moveStartToEndOfNode', ...args) +/** + * Move the selection's start point to the end of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveStartToEndOfPath = (editor, path) => { + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfPath(path) + } else { + editor.moveFocusToEndOfPath(path) + } } +/** + * Move the selection's start point to the end of the previous block. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'start', 'end', 'previous', 'block') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfPreviousBlock() + } else { + editor.moveFocusToEndOfPreviousBlock() + } } +/** + * Move the selection's start point to the end of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'start', 'end', 'previous', 'inline') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfPreviousInline() + } else { + editor.moveFocusToEndOfPreviousInline() + } } +/** + * Move the selection's start point to the end of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'start', 'end', 'previous', 'text') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfPreviousText() + } else { + editor.moveFocusToEndOfPreviousText() + } } +/** + * Move the selection's start point to the end of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveStartToEndOfText = editor => { - editor.command(pointEdgeObject, 'start', 'end', 'text') + if (editor.value.selection.isForward) { + editor.moveAnchorToEndOfText() + } else { + editor.moveFocusToEndOfText() + } } +/** + * Move the selection's start point to the start of the block it's in. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfBlock = editor => { - editor.command(pointEdgeObject, 'start', 'start', 'block') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfBlock() + } else { + editor.moveFocusToStartOfBlock() + } } +/** + * Move the selection's start point to the start of the document. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfDocument = editor => { - editor.moveStartToStartOfNode(editor.value.document).moveToStart() + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfDocument() + } else { + editor.moveFocusToStartOfDocument() + } } +/** + * Move the selection's start point to the start of the nearest inline. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfInline = editor => { - editor.command(pointEdgeObject, 'start', 'start', 'inline') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfInline() + } else { + editor.moveFocusToStartOfInline() + } } +/** + * Move the selection's start point to the start of the next block. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfNextBlock = editor => { - editor.command(pointEdgeSideObject, 'start', 'start', 'next', 'block') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfNextBlock() + } else { + editor.moveFocusToStartOfNextBlock() + } } +/** + * Move the selection's start point to the start of the next inline. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfNextInline = editor => { - editor.command(pointEdgeSideObject, 'start', 'start', 'next', 'inline') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfNextInline() + } else { + editor.moveFocusToStartOfNextInline() + } } +/** + * Move the selection's start point to the start of the next text node. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfNextText = editor => { - editor.command(pointEdgeSideObject, 'start', 'start', 'next', 'text') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfNextText() + } else { + editor.moveFocusToStartOfNextText() + } } -Commands.moveStartToStartOfNode = (editor, ...args) => { - editor.command(proxy, 'moveStartToStartOfNode', ...args) +/** + * Move the selection's start point to the start of the node at `path`. + * + * @param {Editor} editor + */ + +Commands.moveStartToStartOfPath = (editor, path) => { + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfPath(path) + } else { + editor.moveFocusToStartOfPath(path) + } } +/** + * Move the selection's start point to the start of the previous block. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfPreviousBlock = editor => { - editor.command(pointEdgeSideObject, 'start', 'start', 'previous', 'block') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfPreviousBlock() + } else { + editor.moveFocusToStartOfPreviousBlock() + } } +/** + * Move the selection's start point to the start of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfPreviousInline = editor => { - editor.command(pointEdgeSideObject, 'start', 'start', 'previous', 'inline') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfPreviousInline() + } else { + editor.moveFocusToStartOfPreviousInline() + } } +/** + * Move the selection's start point to the start of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfPreviousText = editor => { - editor.command(pointEdgeSideObject, 'start', 'start', 'previous', 'text') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfPreviousText() + } else { + editor.moveFocusToStartOfPreviousText() + } } +/** + * Move the selection's start point to the start of the text node it's in. + * + * @param {Editor} editor + */ + Commands.moveStartToStartOfText = editor => { - editor.command(pointEdgeObject, 'start', 'start', 'text') + if (editor.value.selection.isForward) { + editor.moveAnchorToStartOfText() + } else { + editor.moveFocusToStartOfText() + } +} + +/** + * Move the selection's start point backward to the edge of the nearest word. + * + * @param {Editor} editor + */ + +Commands.moveStartWordBackward = (editor, ...args) => { + if (editor.value.selection.isForward) { + editor.moveAnchorWordBackward() + } else { + editor.moveFocusWordBackward() + } +} + +/** + * Move the selection's start point forward to the edge of the nearest word. + * + * @param {Editor} editor + */ + +Commands.moveStartWordForward = (editor, ...args) => { + if (editor.value.selection.isForward) { + editor.moveAnchorWordForward() + } else { + editor.moveFocusWordForward() + } } -Commands.moveTo = (editor, ...args) => { - editor.command(proxy, 'moveTo', ...args) +/** + * Move the cursor to a specific `path` and `offset`. + * + * @param {Editor} editor + * @param {Array} path + * @param {Number} offset + */ + +Commands.moveTo = (editor, path, offset) => { + const { value: { selection } } = editor + const range = selection.moveTo(path, offset) + editor.select(range) } +/** + * Collapse the cursor to the selection's anchor point. + * + * @param {Editor} editor + */ + Commands.moveToAnchor = editor => { - editor.command(proxy, 'moveToAnchor') + const { value: { selection } } = editor + const range = selection.moveToAnchor() + editor.select(range) } +/** + * Collapse the cursor to the selection's end point. + * + * @param {Editor} editor + */ + Commands.moveToEnd = editor => { - editor.command(proxy, 'moveToEnd') + const { value: { selection } } = editor + const range = selection.moveToEnd() + editor.select(range) } +/** + * Collapse the cursor to the end of the current block. + * + * @param {Editor} editor + */ + Commands.moveToEndOfBlock = editor => { - editor.moveEndToEndOfBlock().moveToEnd() + editor.moveEndToEndOfBlock() + editor.moveToEnd() } +/** + * Collapse the cursor to the end of the document. + * + * @param {Editor} editor + */ + Commands.moveToEndOfDocument = editor => { - editor.moveEndToEndOfNode(editor.value.document).moveToEnd() + editor.moveEndToEndOfDocument() + editor.moveToEnd() } +/** + * Collapse the cursor to the end of the current inline. + * + * @param {Editor} editor + */ + Commands.moveToEndOfInline = editor => { - editor.moveEndToEndOfInline().moveToEnd() + editor.moveEndToEndOfInline() + editor.moveToEnd() } +/** + * Collapse the cursor to the end of the next block. + * + * @param {Editor} editor + */ + Commands.moveToEndOfNextBlock = editor => { - editor.moveEndToEndOfNextBlock().moveToEnd() + editor.moveEndToEndOfNextBlock() + editor.moveToEnd() } +/** + * Collapse the cursor to the end of the next inline. + * + * @param {Editor} editor + */ + Commands.moveToEndOfNextInline = editor => { - editor.moveEndToEndOfNextInline().moveToEnd() + editor.moveEndToEndOfNextInline() + editor.moveToEnd() } +/** + * Collapse the cursor to the end of the next text node. + * + * @param {Editor} editor + */ + Commands.moveToEndOfNextText = editor => { - editor.moveEndToEndOfNextText().moveToEnd() + editor.moveEndToEndOfNextText() + editor.moveToEnd() } -Commands.moveToEndOfNode = (editor, ...args) => { - editor.command(proxy, 'moveToEndOfNode', ...args) +/** + * Collapse the cursor to the end of the node at `path`. + * + * @param {Editor} + * @param {Array} path + */ + +Commands.moveToEndOfPath = (editor, path) => { + editor.moveAnchorToEndOfPath(path) + editor.moveToAnchor() } +/** + * Collapse the cursor to the end of the previous block. + * + * @param {Editor} editor + */ + Commands.moveToEndOfPreviousBlock = editor => { - editor.moveStartToEndOfPreviousBlock().moveToStart() + editor.moveStartToEndOfPreviousBlock() + editor.moveToStart() } +/** + * Collapse the cursor to the end of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveToEndOfPreviousInline = editor => { - editor.moveStartToEndOfPreviousInline().moveToStart() + editor.moveStartToEndOfPreviousInline() + editor.moveToStart() } +/** + * Collapse the cursor to the end of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveToEndOfPreviousText = editor => { - editor.moveStartToEndOfPreviousText().moveToStart() + editor.moveStartToEndOfPreviousText() + editor.moveToStart() } +/** + * Collapse the cursor to the end of the current text node. + * + * @param {Editor} editor + */ + Commands.moveToEndOfText = editor => { - editor.moveEndToEndOfText().moveToEnd() + editor.moveEndToEndOfText() + editor.moveToEnd() } +/** + * Collapse the cursor to the selection's focus point. + * + * @param {Editor} editor + */ + Commands.moveToFocus = editor => { - editor.command(proxy, 'moveToFocus') + const { value: { selection } } = editor + const range = selection.moveToFocus() + editor.select(range) } +/** + * Move the selection's anchor and focus points to the start and end of the + * document, respectively. + * + * @param {Editor} editor + */ + Commands.moveToRangeOfDocument = editor => { - editor.moveToRangeOfNode(editor.value.document) + editor.moveAnchorToStartOfDocument() + editor.moveFocusToEndOfDocument() } -Commands.moveToRangeOfNode = (editor, ...args) => { - editor.command(proxy, 'moveToRangeOfNode', ...args) +/** + * Move the selection's anchor and focus points to the start and end of the + * current block, respectively. + * + * @param {Editor} editor + */ + +Commands.moveToRangeOfBlock = editor => { + editor.moveToStart() + editor.moveAnchorToStartOfBlock() + editor.moveFocusToEndOfBlock() +} + +/** + * Move the selection's anchor and focus points to the start and end of the + * current inline, respectively. + * + * @param {Editor} editor + */ + +Commands.moveToRangeOfInline = editor => { + editor.moveToStart() + editor.moveAnchorToStartOfBlock() + editor.moveFocusToEndOfBlock() +} + +/** + * Move the selection's anchor and focus points to the start and end of the + * current text node, respectively. + * + * @param {Editor} editor + */ + +Commands.moveToRangeOfInline = editor => { + editor.moveToStart() + editor.moveAnchorToStartOfText() + editor.moveFocusToEndOfText() +} + +/** + * Collapse the cursor to the end of the node at `path`. + * + * @param {Editor} + * @param {Array} path + */ + +Commands.moveToRangeOfPath = (editor, path) => { + editor.moveAnchorToStartOfPath(path) + editor.moveFocusToEndOfPath(path) } +/** + * Collapse the cursor to the selection's start point. + * + * @param {Editor} editor + */ + Commands.moveToStart = editor => { - editor.command(proxy, 'moveToStart') + const { value: { selection } } = editor + const range = selection.moveToStart() + editor.select(range) } +/** + * Collapse the cursor to the start of the current block. + * + * @param {Editor} editor + */ + Commands.moveToStartOfBlock = editor => { - editor.moveStartToStartOfBlock().moveToStart() + editor.moveStartToStartOfBlock() + editor.moveToStart() } +/** + * Collapse the cursor to the start of the document. + * + * @param {Editor} editor + */ + Commands.moveToStartOfDocument = editor => { - editor.moveStartToStartOfNode(editor.value.document).moveToStart() + editor.moveStartToStartOfDocument() + editor.moveToStart() } +/** + * Collapse the cursor to the start of the current inline. + * + * @param {Editor} editor + */ + Commands.moveToStartOfInline = editor => { - editor.moveStartToStartOfInline().moveToStart() + editor.moveStartToStartOfInline() + editor.moveToStart() } +/** + * Collapse the cursor to the start of the next block. + * + * @param {Editor} editor + */ + Commands.moveToStartOfNextBlock = editor => { - editor.moveEndToStartOfNextBlock().moveToEnd() + editor.moveEndToStartOfNextBlock() + editor.moveToEnd() } +/** + * Collapse the cursor to the start of the next inline. + * + * @param {Editor} editor + */ + Commands.moveToStartOfNextInline = editor => { - editor.moveEndToStartOfNextInline().moveToEnd() + editor.moveEndToStartOfNextInline() + editor.moveToEnd() } +/** + * Collapse the cursor to the start of the next text node. + * + * @param {Editor} editor + */ + Commands.moveToStartOfNextText = editor => { - editor.moveEndToStartOfNextText().moveToEnd() + editor.moveEndToStartOfNextText() + editor.moveToEnd() } -Commands.moveToStartOfNode = (editor, ...args) => { - editor.command(proxy, 'moveToStartOfNode', ...args) +/** + * Collapse the cursor to the start of the node at `path`. + * + * @param {Editor} editor + * @param {Array} path + */ + +Commands.moveToStartOfPath = (editor, path) => { + editor.moveAnchorToStartOfPath(path) + editor.moveToAnchor() } +/** + * Collapse the cursor to the start of the previous block. + * + * @param {Editor} editor + */ + Commands.moveToStartOfPreviousBlock = editor => { - editor.moveStartToStartOfPreviousBlock().moveToStart() + editor.moveStartToStartOfPreviousBlock() + editor.moveToStart() } +/** + * Collapse the cursor to the start of the previous inline. + * + * @param {Editor} editor + */ + Commands.moveToStartOfPreviousInline = editor => { - editor.moveStartToStartOfPreviousInline().moveToStart() + editor.moveStartToStartOfPreviousInline() + editor.moveToStart() } +/** + * Collapse the cursor to the start of the previous text node. + * + * @param {Editor} editor + */ + Commands.moveToStartOfPreviousText = editor => { - editor.moveStartToStartOfPreviousText().moveToStart() + editor.moveStartToStartOfPreviousText() + editor.moveToStart() } +/** + * Collapse the cursor to the start of the current text node. + * + * @param {Editor} editor + */ + Commands.moveToStartOfText = editor => { - editor.moveStartToStartOfText().moveToStart() + editor.moveStartToStartOfText() + editor.moveToStart() +} + +/** + * Move the selection's points each backward by `n` words. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveWordBackward = (editor, n) => { + editor.moveAnchorWordBackward(n) + editor.moveFocusWordBackward(n) +} + +/** + * Move the selection's points each forward by `n` words. + * + * @param {Editor} editor + * @param {Number} n + */ + +Commands.moveWordForward = (editor, n) => { + editor.moveAnchorWordForward(n) + editor.moveFocusWordForward(n) } +/** + * Set new `properties` on the selection. + * + * @param {Editor} editor + * @param {Object} properties + * @param {Object} options + */ + Commands.select = (editor, properties, options = {}) => { properties = Selection.createProperties(properties) const { snapshot = false } = options @@ -637,22 +2174,64 @@ Commands.select = (editor, properties, options = {}) => { ) } -Commands.setAnchor = (editor, ...args) => { - editor.command(proxy, 'setAnchor', ...args) +/** + * Set the selection's anchor point to the return value of `fn`. + * + * @param {Editor} editor + * @param {Function} fn + */ + +Commands.setAnchor = (editor, fn) => { + const { value: { selection } } = editor + const range = selection.setAnchor(fn) + editor.select(range) } -Commands.setEnd = (editor, ...args) => { - editor.command(proxy, 'setEnd', ...args) +/** + * Set the selection's end point to the return value of `fn`. + * + * @param {Editor} editor + * @param {Function} fn + */ + +Commands.setEnd = (editor, fn) => { + const { value: { selection } } = editor + const range = selection.setEnd(fn) + editor.select(range) } -Commands.setFocus = (editor, ...args) => { - editor.command(proxy, 'setFocus', ...args) +/** + * Set the selection's focus point to the return value of `fn`. + * + * @param {Editor} editor + * @param {Function} fn + */ + +Commands.setFocus = (editor, fn) => { + const { value: { selection } } = editor + const range = selection.setFocus(fn) + editor.select(range) } -Commands.setStart = (editor, ...args) => { - editor.command(proxy, 'setStart', ...args) +/** + * Set the selection's start point to the return value of `fn`. + * + * @param {Editor} editor + * @param {Function} fn + */ + +Commands.setStart = (editor, fn) => { + const { value: { selection } } = editor + const range = selection.setStart(fn) + editor.select(range) } +/** + * HACK: Snapshot the selection, saving an entry in the history. + * + * @param {Editor} editor + */ + Commands.snapshotSelection = editor => { editor.withoutMerging(() => { editor.select(editor.value.selection, { snapshot: true }) @@ -660,134 +2239,128 @@ Commands.snapshotSelection = editor => { } /** - * Helpers. + * Deprecated. */ -function proxy(editor, method, ...args) { - const range = editor.value.selection[method](...args) +Commands.moveAnchorToEndOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveAnchorToEndOfNode(node) command is deprecated. Use the `editor.moveAnchorToEndOfPath(path)` command instead.' + ) + + const { value: { selection } } = editor + const range = selection.moveAnchorToEndOfNode(...args) editor.select(range) } -function pointEdgeObject(editor, point, edge, object) { - const Point = point.slice(0, 1).toUpperCase() + point.slice(1) - const Edge = edge.slice(0, 1).toUpperCase() + edge.slice(1) - const Object = object.slice(0, 1).toUpperCase() + object.slice(1) - const method = `move${Point}To${Edge}OfNode` - const getNode = object === 'text' ? 'getNode' : `getClosest${Object}` - const { value } = editor - const { document, selection } = value - const p = selection[point] - const node = document[getNode](p.key) - if (!node) return - editor[method](node) -} - -function pointEdgeSideObject(editor, point, edge, side, object) { - const Point = point.slice(0, 1).toUpperCase() + point.slice(1) - const Edge = edge.slice(0, 1).toUpperCase() + edge.slice(1) - const Side = side.slice(0, 1).toUpperCase() + side.slice(1) - const Object = object.slice(0, 1).toUpperCase() + object.slice(1) - const method = `move${Point}To${Edge}OfNode` - const getNode = object === 'text' ? 'getNode' : `getClosest${Object}` - const getDirectionNode = `get${Side}${Object}` - const { value } = editor - const { document, selection } = value - const p = selection[point] - const node = document[getNode](p.key) - if (!node) return - const target = document[getDirectionNode](node.key) - if (!target) return - editor[method](target) +Commands.moveAnchorToStartOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveAnchorToStartOfNode(node) command is deprecated. Use the `editor.moveAnchorToStartOfPath(path)` command instead.' + ) + + const { value: { selection } } = editor + const range = selection.moveAnchorToStartOfNode(...args) + editor.select(range) } -function pointBackward(editor, point, n = 1) { - if (n === 0) return - if (n < 0) return pointForward(editor, point, -n) +Commands.moveEndToEndOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveEndToEndOfNode(node) command is deprecated. Use the `editor.moveEndToEndOfPath(path)` command instead.' + ) - const Point = point.slice(0, 1).toUpperCase() + point.slice(1) - const { value } = editor - const { document, selection } = value - const p = selection[point] - const hasVoidParent = document.hasVoidParent(p.path, editor) + const { value: { selection } } = editor + const range = selection.moveEndToEndOfNode(...args) + editor.select(range) +} - // what is this? - if (!hasVoidParent && p.offset - n >= 0) { - const range = selection[`move${Point}Backward`](n) - editor.select(range) - return - } +Commands.moveEndToStartOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveEndToStartOfNode(node) command is deprecated. Use the `editor.moveEndToStartOfPath(path)` command instead.' + ) - const previous = document.getPreviousText(p.path) - if (!previous) return + const { value: { selection } } = editor + const range = selection.moveEndToStartOfNode(...args) + editor.select(range) +} - const block = document.getClosestBlock(p.path) - const isInBlock = block.hasNode(previous.key) - const isPreviousInVoid = - previous && document.hasVoidParent(previous.key, editor) - editor[`move${Point}ToEndOfNode`](previous) +Commands.moveFocusToEndOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveFocusToEndOfNode(node) command is deprecated. Use the `editor.moveFocusToEndOfPath(path)` command instead.' + ) - // when is this called? - if (!hasVoidParent && !isPreviousInVoid && isInBlock) { - const range = editor.value.selection[`move${Point}Backward`](n) - editor.select(range) - } + const { value: { selection } } = editor + const range = selection.moveFocusToEndOfNode(...args) + editor.select(range) } -function pointForward(editor, point, n = 1) { - if (n === 0) return - if (n < 0) return pointBackward(editor, point, -n) +Commands.moveFocusToStartOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveFocusToStartOfNode(node) command is deprecated. Use the `editor.moveFocusToStartOfPath(path)` command instead.' + ) - const Point = point.slice(0, 1).toUpperCase() + point.slice(1) - const { value } = editor - const { document, selection } = value - const p = selection[point] - const text = document.getNode(p.path) - const hasVoidParent = document.hasVoidParent(p.path, editor) - - // what is this? - if (!hasVoidParent && p.offset + n <= text.text.length) { - const range = selection[`move${Point}Forward`](n) - editor.select(range) - return - } + const { value: { selection } } = editor + const range = selection.moveFocusToStartOfNode(...args) + editor.select(range) +} + +Commands.moveStartToEndOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveStartToEndOfNode(node) command is deprecated. Use the `editor.moveStartToEndOfPath(path)` command instead.' + ) - const next = document.getNextText(p.path) - if (!next) return + const { value: { selection } } = editor + const range = selection.moveStartToEndOfNode(...args) + editor.select(range) +} - const block = document.getClosestBlock(p.path) - const isInBlock = block.hasNode(next.key) - const isNextInVoid = document.hasVoidParent(next.key, editor) - editor[`move${Point}ToStartOfNode`](next) +Commands.moveStartToStartOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveStartToStartOfNode(node) command is deprecated. Use the `editor.moveStartToStartOfPath(path)` command instead.' + ) - // when is this called? - if (!hasVoidParent && !isNextInVoid && isInBlock) { - const range = editor.value.selection[`move${Point}Forward`](n) - editor.select(range) - } + const { value: { selection } } = editor + const range = selection.moveStartToStartOfNode(...args) + editor.select(range) } -function pointWordBackward(editor, pointName) { - const { value } = editor - const { document, selection } = value - const point = selection[pointName] - const block = document.getClosestBlock(point.key) - const offset = block.getOffset(point.key) - const o = offset + point.offset - const { text } = block - const n = TextUtils.getWordOffsetBackward(text, o) - editor.command(pointBackward, pointName, n > 0 ? n : 1) +Commands.moveToEndOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveToEndOfNode(node) command is deprecated. Use the `editor.moveToEndOfPath(path)` command instead.' + ) + + const { value: { selection } } = editor + const range = selection.moveToEndOfNode(...args) + editor.select(range) } -function pointWordForward(editor, pointName) { - const { value } = editor - const { document, selection } = value - const point = selection[pointName] - const block = document.getClosestBlock(point.key) - const offset = block.getOffset(point.key) - const o = offset + point.offset - const { text } = block - const n = TextUtils.getWordOffsetForward(text, o) - editor.command(pointForward, pointName, n > 0 ? n : 1) +Commands.moveToRangeOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveToRangeOfNode(node) command is deprecated. Use the `editor.moveToRangeOfPath(path)` command instead.' + ) + + const { value: { selection } } = editor + const range = selection.moveToRangeOfNode(...args) + editor.select(range) +} + +Commands.moveToStartOfNode = (editor, ...args) => { + warning( + false, + 'As of slate@0.48 the `editor.moveToStartOfNode(node) command is deprecated. Use the `editor.moveToStartOfPath(path)` command instead.' + ) + + const { value: { selection } } = editor + const range = selection.moveToStartOfNode(...args) + editor.select(range) } export default Commands diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js index 7d42cd8683..b38df873e5 100644 --- a/packages/slate/src/interfaces/element.js +++ b/packages/slate/src/interfaces/element.js @@ -1656,6 +1656,48 @@ class ElementInterface { return iterable } + previousBlock(path) { + const node = this.assertNode(path) + + if (node.object !== 'text') { + const entry = node.firstText() + + if (entry) { + const [, entryPath] = entry + path = path.concat(entryPath) + } + } + + const [prev] = this.blocks({ + path, + direction: 'backward', + onlyLeaves: true, + }) + + return prev + } + + previousInline(path) { + const node = this.assertNode(path) + + if (node.object !== 'text') { + const entry = node.firstText() + + if (entry) { + const [, entryPath] = entry + path = path.concat(entryPath) + } + } + + const [prev] = this.inlines({ + path, + direction: 'backward', + onlyLeaves: true, + }) + + return prev + } + previousText(path) { const node = this.assertNode(path) @@ -1672,6 +1714,38 @@ class ElementInterface { return prev } + nextBlock(path) { + const node = this.assertNode(path) + + if (node.object !== 'text') { + const entry = node.lastText() + + if (entry) { + const [, entryPath] = entry + path = path.concat(entryPath) + } + } + + const [next] = this.blocks({ path, onlyLeaves: true }) + return next + } + + nextInline(path) { + const node = this.assertNode(path) + + if (node.object !== 'text') { + const entry = node.lastText() + + if (entry) { + const [, entryPath] = entry + path = path.concat(entryPath) + } + } + + const [next] = this.inlines({ path, onlyLeaves: true }) + return next + } + nextText(path) { const node = this.assertNode(path) @@ -1688,8 +1762,8 @@ class ElementInterface { return next } - firstText() { - const [first] = this.texts() + firstText(options) { + const [first] = this.texts({ includeTarget: true, ...options }) return first } @@ -1698,8 +1772,13 @@ class ElementInterface { return first } - lastText() { - const [last] = this.texts({ direction: 'backward' }) + lastText(options) { + const [last] = this.texts({ + direction: 'backward', + includeTarget: true, + ...options, + }) + return last } diff --git a/packages/slate/src/plugins/commands.js b/packages/slate/src/plugins/commands/index.js similarity index 100% rename from packages/slate/src/plugins/commands.js rename to packages/slate/src/plugins/commands/index.js diff --git a/packages/slate/src/plugins/core/core-commands.js b/packages/slate/src/plugins/core/core-commands.js new file mode 100644 index 0000000000..bbe9b92bd6 --- /dev/null +++ b/packages/slate/src/plugins/core/core-commands.js @@ -0,0 +1,32 @@ +import AtRange from '../../commands/at-range' +import ByPath from '../../commands/by-path' +import Commands from '../commands' +import OnHistory from '../../commands/on-history' +import OnSelection from '../../commands/on-selection' +import OnValue from '../../commands/on-value' +import WithIntent from '../../commands/with-intent' + +/** + * A plugin that defines the core Slate commands. + * + * @return {Object} + */ + +function CoreCommandsPlugin() { + return Commands({ + ...AtRange, + ...ByPath, + ...OnHistory, + ...OnSelection, + ...OnValue, + ...WithIntent, + }) +} + +/** + * Export. + * + * @type {Object} + */ + +export default CoreCommandsPlugin diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js new file mode 100644 index 0000000000..a0d91f6975 --- /dev/null +++ b/packages/slate/src/plugins/core/core-queries.js @@ -0,0 +1,139 @@ +import PathUtils from '../../utils/path-utils' +import Queries from '../queries' + +/** + * A plugin that defines the core Slate query logic. + * + * @return {Object} + */ + +function CoreQueriesPlugin() { + return Queries({ + /** + * By default, no formats are atomic in Slate. + * + * @param {Editor} editor + * @param {Annotation|Decoration|Mark} object + * @return {Boolean} + */ + + isAtomic() { + return false + }, + + /** + * By default, no nodes are void in Slate. + * + * @param {Editor} editor + * @param {Node} node + * @return {Boolean} + */ + + isVoid() { + return false + }, + + /** + * Calculate the next point forward from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point|Null} + */ + + getNextPoint(editor, point) { + const { value } = editor + const { document } = value + const { path, offset } = point + const closestBlock = document.closestBlock(path) + const closestVoid = document.closest(path, editor.isVoid) + const node = document.getNode(path) + + // PERF: if we're not in a void and we have offset to gain, do it easily. + if (!closestVoid && offset < node.text.length) { + return point.setOffset(offset + 1) + } + + for (const [, nextPath] of document.nextTexts({ path })) { + // If we're still inside the void node, keep going until we exit it. + if (closestVoid) { + const [, voidPath] = closestVoid + + if (!PathUtils.isAfter(nextPath, voidPath)) { + continue + } + } + + // If we're no longer inside the original block node, we don't want to + // add an extra `1` to the offset, since we've changed blocks. Instead + // we move right to the start of the block. + if (closestBlock) { + const [, blockPath] = closestBlock + + if (PathUtils.isAfter(nextPath, blockPath)) { + return point.moveTo(nextPath, 0) + } + } + + return point.moveTo(nextPath, 1) + } + + return null + }, + + /** + * Calculate the previous point backward from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point|Null} + */ + + getPreviousPoint(editor, point) { + const { value } = editor + const { document } = value + const { path, offset } = point + const closestBlock = document.closestBlock(path) + const closestVoid = document.closest(path, editor.isVoid) + + // PERF: if we're not in a void and we have offset to lose, do it easily. + if (!closestVoid && offset > 0) { + return point.setOffset(offset - 1) + } + + for (const [prevNode, prevPath] of document.previousTexts({ path })) { + // If we're still inside the void node, keep going until we exit it. + if (closestVoid) { + const [, voidPath] = closestVoid + + if (!PathUtils.isBefore(prevPath, voidPath)) { + continue + } + } + + // If we're no longer inside the original block node, we don't want to + // remove an extra `1` from the offset, since we've changed blocks. + // Instead we move right to the end of the block. + if (closestBlock) { + const [, blockPath] = closestBlock + + if (PathUtils.isBefore(prevPath, blockPath)) { + return point.moveTo(prevPath, prevNode.text.length) + } + } + + return point.moveTo(prevPath, prevNode.text.length - 1) + } + + return null + }, + }) +} + +/** + * Export. + * + * @type {Object} + */ + +export default CoreQueriesPlugin diff --git a/packages/slate/src/plugins/core.js b/packages/slate/src/plugins/core/core-schema.js similarity index 78% rename from packages/slate/src/plugins/core.js rename to packages/slate/src/plugins/core/core-schema.js index c5a65a4aa9..340c1aa376 100644 --- a/packages/slate/src/plugins/core.js +++ b/packages/slate/src/plugins/core/core-schema.js @@ -1,57 +1,15 @@ -import AtRange from '../commands/at-range' -import ByPath from '../commands/by-path' -import Commands from './commands' -import OnHistory from '../commands/on-history' -import OnSelection from '../commands/on-selection' -import OnValue from '../commands/on-value' -import Queries from './queries' -import Schema from './schema' -import Text from '../models/text' -import WithIntent from '../commands/with-intent' +import Schema from '../schema' +import Text from '../../models/text' /** - * A plugin that defines the core Slate logic. + * A plugin that defines the core Slate schema. * * @param {Object} options * @return {Object} */ -function CorePlugin(options = {}) { - const { plugins = [] } = options - - /** - * The core Slate commands. - * - * @type {Object} - */ - - const commands = Commands({ - ...AtRange, - ...ByPath, - ...OnHistory, - ...OnSelection, - ...OnValue, - ...WithIntent, - }) - - /** - * The core Slate queries. - * - * @type {Object} - */ - - const queries = Queries({ - isAtomic: () => false, - isVoid: () => false, - }) - - /** - * The core Slate schema. - * - * @type {Object} - */ - - const schema = Schema({ +function CoreSchemaPlugin(options = {}) { + return Schema({ rules: [ // Only allow block nodes in documents. { @@ -190,14 +148,6 @@ function CorePlugin(options = {}) { }, ], }) - - /** - * Return the plugins. - * - * @type {Array} - */ - - return [schema, ...plugins, commands, queries] } /** @@ -206,4 +156,4 @@ function CorePlugin(options = {}) { * @type {Object} */ -export default CorePlugin +export default CoreSchemaPlugin diff --git a/packages/slate/src/plugins/core/index.js b/packages/slate/src/plugins/core/index.js new file mode 100644 index 0000000000..6c60082361 --- /dev/null +++ b/packages/slate/src/plugins/core/index.js @@ -0,0 +1,26 @@ +import CoreQueries from './core-queries' +import CoreCommands from './core-commands' +import CoreSchema from './core-schema' + +/** + * A plugin that defines the core Slate logic. + * + * @param {Object} options + * @return {Object} + */ + +function CorePlugin(options = {}) { + const { plugins = [] } = options + const schema = CoreSchema(options) + const queries = CoreQueries(options) + const commands = CoreCommands(options) + return [schema, ...plugins, commands, queries] +} + +/** + * Export. + * + * @type {Object} + */ + +export default CorePlugin diff --git a/packages/slate/src/plugins/queries.js b/packages/slate/src/plugins/queries/index.js similarity index 100% rename from packages/slate/src/plugins/queries.js rename to packages/slate/src/plugins/queries/index.js diff --git a/packages/slate/src/plugins/schema.js b/packages/slate/src/plugins/schema/index.js similarity index 99% rename from packages/slate/src/plugins/schema.js rename to packages/slate/src/plugins/schema/index.js index a29881df77..6f08129dcf 100644 --- a/packages/slate/src/plugins/schema.js +++ b/packages/slate/src/plugins/schema/index.js @@ -1,5 +1,5 @@ -import SlateError from '../utils/slate-error' -import Queries from './queries' +import SlateError from '../../utils/slate-error' +import Queries from '../queries' /** * Create a plugin from a `schema` definition. diff --git a/packages/slate/test/commands/on-selection/move-word-backward/expanded.js b/packages/slate/test/commands/on-selection/move-word-backward/expanded.js index f76559fe03..d66413fecd 100644 --- a/packages/slate/test/commands/on-selection/move-word-backward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-word-backward/expanded.js @@ -16,12 +16,11 @@ export const input = ( ) -// Should move to next word after focus and collapse export const output = ( - one two three four five six + one two three four five six diff --git a/packages/slate/test/commands/on-selection/move-word-backward/reversed.js b/packages/slate/test/commands/on-selection/move-word-backward/reversed.js index 78aba90d16..6893f04e6c 100644 --- a/packages/slate/test/commands/on-selection/move-word-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-word-backward/reversed.js @@ -16,12 +16,11 @@ export const input = ( ) -// Should move to next word after focus and collapse export const output = ( - one two three four five six + one two three four five six diff --git a/packages/slate/test/commands/on-selection/move-word-forward/expanded.js b/packages/slate/test/commands/on-selection/move-word-forward/expanded.js index 3c3ab8fc94..e8e918e1c4 100644 --- a/packages/slate/test/commands/on-selection/move-word-forward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-word-forward/expanded.js @@ -21,7 +21,7 @@ export const output = ( - one two three four five six + one two three four five six diff --git a/packages/slate/test/commands/on-selection/move-word-forward/reversed.js b/packages/slate/test/commands/on-selection/move-word-forward/reversed.js index b8c0a3d692..45465dacf2 100644 --- a/packages/slate/test/commands/on-selection/move-word-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-word-forward/reversed.js @@ -21,7 +21,7 @@ export const output = ( - one two three four five six + one two three four five six From b93b8a962e945b945c8a3f57fe437bf6e53b207a Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 22 May 2019 12:40:36 -0700 Subject: [PATCH 006/165] refactor word boundary selection logic --- packages/slate-react/src/plugins/dom/after.js | 4 +- packages/slate/src/commands/on-selection.js | 61 ++++-------------- .../slate/src/plugins/core/core-queries.js | 63 +++++++++++++++++++ 3 files changed, 78 insertions(+), 50 deletions(-) diff --git a/packages/slate-react/src/plugins/dom/after.js b/packages/slate-react/src/plugins/dom/after.js index 479fd879a4..8eb86536ef 100644 --- a/packages/slate-react/src/plugins/dom/after.js +++ b/packages/slate-react/src/plugins/dom/after.js @@ -351,7 +351,9 @@ function AfterPlugin(options = {}) { hasVoidParent = document.hasVoidParent(p, editor) } - if (n) editor.moveToStartOfNode(n) + if (p) { + editor.moveToStartOfPath(p) + } } if (text) { diff --git a/packages/slate/src/commands/on-selection.js b/packages/slate/src/commands/on-selection.js index 3484637878..57de7cf51c 100644 --- a/packages/slate/src/commands/on-selection.js +++ b/packages/slate/src/commands/on-selection.js @@ -3,7 +3,6 @@ import warning from 'tiny-warning' import pick from 'lodash/pick' import Selection from '../models/selection' -import TextUtils from '../utils/text-utils' const Commands = {} @@ -41,42 +40,6 @@ function getPreviousPoint(editor, point, n) { return point } -/** - * Get word offset backward from a `point`. - * - * @param {Editor} editor - * @param {Point} point - * @return {Number} - */ - -function getWordOffsetBackward(editor, point) { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - const o = blockOffset + offset - return TextUtils.getWordOffsetBackward(block.text, o) -} - -/** - * Get word offset forward from a `point`. - * - * @param {Editor} editor - * @param {Point} point - * @return {Number} - */ - -function getWordOffsetForward(editor, point) { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - const o = blockOffset + offset - return TextUtils.getWordOffsetForward(block.text, o) -} - /** * Blur the selection. * @@ -129,7 +92,7 @@ Commands.flip = editor => { Commands.moveAnchorBackward = (editor, n = 1) => { const { value: { selection } } = editor const point = getPreviousPoint(editor, selection.anchor, n) - editor.moveAnchorTo(point.path, point.offset) + editor.setAnchor(point) } /** @@ -142,7 +105,7 @@ Commands.moveAnchorBackward = (editor, n = 1) => { Commands.moveAnchorForward = (editor, n = 1) => { const { value: { selection } } = editor const point = getNextPoint(editor, selection.anchor, n) - editor.moveAnchorTo(point.path, point.offset) + editor.setAnchor(point) } /** @@ -509,8 +472,8 @@ Commands.moveAnchorToStartOfText = editor => { Commands.moveAnchorWordBackward = editor => { const { value: { selection } } = editor - const n = getWordOffsetBackward(editor, selection.anchor) - editor.moveAnchorBackward(n) + const point = editor.getPreviousWordPoint(selection.anchor) + editor.setAnchor(point) } /** @@ -521,8 +484,8 @@ Commands.moveAnchorWordBackward = editor => { Commands.moveAnchorWordForward = editor => { const { value: { selection } } = editor - const n = getWordOffsetForward(editor, selection.anchor) - editor.moveAnchorForward(n) + const point = editor.getNextWordPoint(selection.anchor) + editor.setAnchor(point) } /** @@ -937,7 +900,7 @@ Commands.moveEndWordForward = (editor, ...args) => { Commands.moveFocusBackward = (editor, n = 1) => { const { value: { selection } } = editor const point = getPreviousPoint(editor, selection.focus, n) - editor.moveFocusTo(point.path, point.offset) + editor.setFocus(point) } /** @@ -950,7 +913,7 @@ Commands.moveFocusBackward = (editor, n = 1) => { Commands.moveFocusForward = (editor, n = 1) => { const { value: { selection } } = editor const point = getNextPoint(editor, selection.focus, n) - editor.moveFocusTo(point.path, point.offset) + editor.setFocus(point) } /** @@ -1317,8 +1280,8 @@ Commands.moveFocusToStartOfText = editor => { Commands.moveFocusWordBackward = editor => { const { value: { selection } } = editor - const n = getWordOffsetBackward(editor, selection.focus) - editor.moveFocusBackward(n) + const point = editor.getPreviousWordPoint(selection.focus) + editor.setFocus(point) } /** @@ -1329,8 +1292,8 @@ Commands.moveFocusWordBackward = editor => { Commands.moveFocusWordForward = editor => { const { value: { selection } } = editor - const n = getWordOffsetForward(editor, selection.focus) - editor.moveFocusForward(n) + const point = editor.getNextWordPoint(selection.focus) + editor.setFocus(point) } /** diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index a0d91f6975..bff0420019 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -1,4 +1,5 @@ import PathUtils from '../../utils/path-utils' +import TextUtils from '../../utils/text-utils' import Queries from '../queries' /** @@ -81,6 +82,37 @@ function CoreQueriesPlugin() { return null }, + /** + * Calculate the next word boundary from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point} + */ + + getNextWordPoint(editor, point) { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + const blockText = block.getText() + + if (blockOffset + offset === blockText.length) { + return editor.getNextPoint(point) + } + + const o = blockOffset + offset + const n = TextUtils.getWordOffsetForward(blockText, o) + let next = point + + for (let i = 0; i < n; i++) { + next = editor.getNextPoint(next) + } + + return next + }, + /** * Calculate the previous point backward from a `point`. * @@ -127,6 +159,37 @@ function CoreQueriesPlugin() { return null }, + + /** + * Calculate the previous word boundary from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point} + */ + + getPreviousWordPoint(editor, point) { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + + if (blockOffset + offset === 0) { + return editor.getPreviousPoint(point) + } + + const blockText = block.getText() + const o = blockOffset + offset + const n = TextUtils.getWordOffsetBackward(blockText, o) + let prev = point + + for (let i = 0; i < n; i++) { + prev = editor.getPreviousPoint(prev) + } + + return prev + }, }) } From 1e8074d994589836af299e4fa2895478af461980 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 6 Jun 2019 21:14:10 +0100 Subject: [PATCH 007/165] convert many at-range commands to use paths --- packages/slate/src/commands/at-range.js | 480 +++++++----------- packages/slate/src/interfaces/element.js | 49 ++ .../slate/src/plugins/core/core-queries.js | 182 ++++++- .../join-blocks-from-inline.js | 3 + .../insert-block/is-inline-void.js | 4 + .../set-block/across-inlines.js | 4 +- .../hanging-selection-across-inlines.js | 41 ++ .../split-inline/{depth.js => height.js} | 9 + 8 files changed, 450 insertions(+), 322 deletions(-) create mode 100644 packages/slate/test/commands/at-current-range/set-block/hanging-selection-across-inlines.js rename packages/slate/test/commands/at-current-range/split-inline/{depth.js => height.js} (77%) diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 657a27ad3c..536f83d493 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -302,22 +302,23 @@ Commands.deleteAtRange = (editor, range) => { */ Commands.deleteBackwardAtRange = (editor, range, n = 1) => { - if (n === 0) return - const { value } = editor - const { document } = value - const { start, focus } = range - - // If the range is expanded, perform a regular delete instead. if (range.isExpanded) { editor.deleteAtRange(range) return } - const voidParent = document.getClosestVoid(start.path, editor) + if (n === 0) { + return + } - // If there is a void parent, delete it. - if (voidParent) { - editor.removeNodeByKey(voidParent.key) + const { value } = editor + const { document } = value + const { start } = range + const closestVoid = document.closest(start.path, editor.isVoid) + + if (closestVoid) { + const [, voidPath] = closestVoid + editor.removeNodeByPath(voidPath) return } @@ -355,7 +356,6 @@ Commands.deleteBackwardAtRange = (editor, range, n = 1) => { prev = document.getPreviousText(prev.key) } - const prevBlock = document.getClosestBlock(prev.key) const prevVoid = document.getClosestVoid(prev.key, editor) // If the previous text node has a void parent, remove it. @@ -363,45 +363,46 @@ Commands.deleteBackwardAtRange = (editor, range, n = 1) => { editor.removeNodeByKey(prevVoid.key) return } - - // If we're deleting by one character and the previous text node is not - // inside the current block, we need to merge the two blocks together. - if (n === 1 && prevBlock !== block) { - range = range.moveAnchorTo(prev.key, prev.text.length) - editor.deleteAtRange(range) - return - } - } - - // If the focus offset is farther than the number of characters to delete, - // just remove the characters backwards inside the current node. - if (n < focus.offset) { - range = range.moveFocusBackward(n) - editor.deleteAtRange(range) - return } - // Otherwise, we need to see how many nodes backwards to go. - let node = text - let offset = 0 - let traversed = focus.offset + let point = range.start - while (n > traversed) { - node = document.getPreviousText(node.key) - const next = traversed + node.text.length + for (let i = 0; i < n; i++) { + const next = editor.getPreviousPoint(point) - if (n <= next) { - offset = next - n + if (!next) { break } else { - traversed = next + point = next } } - range = range.moveAnchorTo(node.key, offset) + range = range.setStart(point) editor.deleteAtRange(range) + return } +// Commands.deleteBackwardAtRange = (editor, range, n = 1) => { +// if (range.isExpanded) { +// editor.deleteAtRange(range) +// } else { +// let point = range.start + +// for (let i = 0; i < n; i++) { +// const next = editor.getPreviousPoint(point) + +// if (!next) { +// break +// } else { +// point = next +// } +// } + +// range = range.setStart(point) +// editor.deleteAtRange(range) +// } +// } + /** * Delete backward until the character boundary at a `range`. * @@ -412,18 +413,14 @@ Commands.deleteBackwardAtRange = (editor, range, n = 1) => { Commands.deleteCharBackwardAtRange = (editor, range) => { if (range.isExpanded) { editor.deleteAtRange(range) - return - } + } else { + const prev = editor.getPreviousCharacterPoint(range.end) - const { value } = editor - const { document } = value - const { start } = range - const [block, path] = document.closestBlock(start.path) - const relativePath = start.path.slice(path.size) - const offset = block.getOffset(relativePath) - const o = offset + start.offset - const n = TextUtils.getCharOffsetBackward(block.text, o) - editor.deleteBackwardAtRange(range, n) + if (prev) { + range = range.setStart(prev) + editor.deleteAtRange(range) + } + } } /** @@ -436,18 +433,14 @@ Commands.deleteCharBackwardAtRange = (editor, range) => { Commands.deleteCharForwardAtRange = (editor, range) => { if (range.isExpanded) { editor.deleteAtRange(range) - return - } + } else { + const next = editor.getNextCharacterPoint(range.end) - const { value } = editor - const { document } = value - const { start } = range - const [block, path] = document.closestBlock(start.path) - const relativePath = start.path.slice(path.size) - const offset = block.getOffset(relativePath) - const o = offset + start.offset - const n = TextUtils.getCharOffsetForward(block.text, o) - editor.deleteForwardAtRange(range, n) + if (next) { + range = range.setStart(next) + editor.deleteAtRange(range) + } + } } /** @@ -459,6 +452,11 @@ Commands.deleteCharForwardAtRange = (editor, range) => { */ Commands.deleteForwardAtRange = (editor, range, n = 1) => { + if (range.isExpanded) { + editor.deleteAtRange(range) + return + } + if (n === 0) { return } @@ -466,13 +464,6 @@ Commands.deleteForwardAtRange = (editor, range, n = 1) => { const { value } = editor const { document } = value const { start, focus } = range - - // If the range is expanded, perform a regular delete instead. - if (range.isExpanded) { - editor.deleteAtRange(range) - return - } - const voidParent = document.getClosestVoid(start.path, editor) // If the node has a void parent, delete it. @@ -615,18 +606,14 @@ Commands.deleteLineForwardAtRange = (editor, range) => { Commands.deleteWordBackwardAtRange = (editor, range) => { if (range.isExpanded) { editor.deleteAtRange(range) - return - } + } else { + const previous = editor.getPreviousWordPoint(range.end) - const { value } = editor - const { document } = value - const { start } = range - const [block, path] = document.closestBlock(start.path) - const relativePath = start.path.slice(path.size) - const offset = block.getOffset(relativePath) - const o = offset + start.offset - const n = o === 0 ? 1 : TextUtils.getWordOffsetBackward(block.text, o) - editor.deleteBackwardAtRange(range, n) + if (previous) { + range = range.setStart(previous) + editor.deleteAtRange(range) + } + } } /** @@ -639,19 +626,14 @@ Commands.deleteWordBackwardAtRange = (editor, range) => { Commands.deleteWordForwardAtRange = (editor, range) => { if (range.isExpanded) { editor.deleteAtRange(range) - return - } + } else { + const next = editor.getNextWordPoint(range.start) - const { value } = editor - const { document } = value - const { start } = range - const [block, path] = document.closestBlock(start.path) - const relativePath = start.path.slice(path.size) - const offset = block.getOffset(relativePath) - const o = offset + start.offset - const wordOffset = TextUtils.getWordOffsetForward(block.text, o) - const n = wordOffset === 0 ? 1 : wordOffset - editor.deleteForwardAtRange(range, n) + if (next) { + range = range.setEnd(next) + editor.deleteAtRange(range) + } + } } /** @@ -669,36 +651,22 @@ Commands.insertBlockAtRange = (editor, range, block) => { const { value } = editor const { document } = value const { start } = range - let startKey = start.key - let startOffset = start.offset - const startBlock = document.getClosestBlock(startKey) - const startInline = document.getClosestInline(startKey) - const parent = document.getParent(startBlock.key) - const index = parent.nodes.indexOf(startBlock) + const [, blockPath] = document.closestBlock(start.path) + const parentPath = PathUtils.lift(blockPath) + const index = blockPath.last() const insertionMode = getInsertionMode(editor, range) if (insertionMode === 'before') { - editor.insertNodeByKey(parent.key, index, block) - } else if (insertionMode === 'behind') { - editor.insertNodeByKey(parent.key, index + 1, block) + editor.insertNodeByPath(parentPath, index, block) + } else if (insertionMode === 'after') { + editor.insertNodeByPath(parentPath, index + 1, block) } else { - if (startInline && editor.isVoid(startInline)) { - const atEnd = start.isAtEndOfNode(startInline) - const siblingText = atEnd - ? document.getNextText(startKey) - : document.getPreviousText(startKey) - - const splitRange = atEnd - ? range.moveToStartOfNode(siblingText) - : range.moveToEndOfNode(siblingText) - - startKey = splitRange.start.key - startOffset = splitRange.start.offset - } + const point = + editor.getNextNonVoidPoint(start) || editor.getPreviousNonVoidPoint(start) editor.withoutNormalizing(() => { - editor.splitDescendantsByKey(startBlock.key, startKey, startOffset) - editor.insertNodeByKey(parent.key, index + 1, block) + editor.splitDescendantsByPath(blockPath, point.path, point.offset) + editor.insertNodeByPath(parentPath, index + 1, block) }) } } @@ -719,14 +687,14 @@ const getInsertionMode = (editor, range) => { const startInline = document.getClosestInline(startKey) if (editor.isVoid(startBlock)) { - if (start.isAtEndOfNode(startBlock)) return 'behind' + if (start.isAtEndOfNode(startBlock)) return 'after' else return 'before' } else if (!startInline && startBlock.text === '') { - return 'behind' + return 'after' } else if (start.isAtStartOfNode(startBlock)) { return 'before' } else if (start.isAtEndOfNode(startBlock)) { - return 'behind' + return 'after' } return 'split' } @@ -781,12 +749,7 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => { insertionNode === fragment && (firstChild.hasBlockChildren() || lastChild.hasBlockChildren()) ) { - // check if reversal is necessary or not - const insertionMode = getInsertionMode(editor, range) - const nodes = - insertionMode === 'before' ? fragment.nodes : fragment.nodes.reverse() - - nodes.forEach(node => { + fragment.nodes.reverse().forEach(node => { editor.insertBlockAtRange(range, node) }) return @@ -904,22 +867,16 @@ const findInsertionNode = (fragment, document, startKey) => { */ Commands.insertInlineAtRange = (editor, range, inline) => { - inline = Inline.create(inline) - editor.withoutNormalizing(() => { + inline = Inline.create(inline) range = deleteExpandedAtRange(editor, range) - - const { value } = editor - const { document } = value + const { value: { document } } = editor const { start } = range - - document.assertDescendant(start.path) - + const closestVoid = document.closest(start.path, editor.isVoid) const parentPath = PathUtils.lift(start.path) const index = start.path.last() - const parent = document.getNode(parentPath) - if (editor.isVoid(parent)) { + if (closestVoid) { return } @@ -940,18 +897,15 @@ Commands.insertInlineAtRange = (editor, range, inline) => { Commands.insertTextAtRange = (editor, range, text, marks) => { editor.withoutNormalizing(() => { range = deleteExpandedAtRange(editor, range) - - const { value } = editor - const { document } = value + const { value: { document } } = editor const { start } = range - const offset = start.offset - const parent = document.getParent(start.path) + const closestVoid = document.closest(start.path, editor.isVoid) - if (editor.isVoid(parent)) { + if (closestVoid) { return } - editor.insertTextByPath(start.path, offset, text, marks) + editor.insertTextByPath(start.path, start.offset, text, marks) }) } @@ -1007,33 +961,17 @@ Commands.removeMarkAtRange = (editor, range, mark) => { */ Commands.setBlocksAtRange = (editor, range, properties) => { - const { value } = editor - const { document } = value - const blocks = document.getLeafBlocksAtRange(range) - - const { start, end, isCollapsed } = range - const isStartVoid = document.hasVoidParent(start.path, editor) - const startBlock = document.getClosestBlock(start.path) - const endBlock = document.getClosestBlock(end.path) - - // Check if we have a "hanging" selection case where the even though the - // selection extends into the start of the end node, we actually want to - // ignore that for UX reasons. - const isHanging = - isCollapsed === false && - start.offset === 0 && - end.offset === 0 && - isStartVoid === false && - start.key === startBlock.getFirstText().key && - end.key === endBlock.getFirstText().key - - // If it's a hanging selection, ignore the last block. - const sets = isHanging ? blocks.slice(0, -1) : blocks - editor.withoutNormalizing(() => { - sets.forEach(block => { - editor.setNodeByKey(block.key, properties) + const { value: { document } } = editor + const iterable = document.blocks({ + range, + includeHanging: false, + onlyLeaves: true, }) + + for (const [, path] of iterable) { + editor.setNodeByPath(path, properties) + } }) } @@ -1046,11 +984,11 @@ Commands.setBlocksAtRange = (editor, range, properties) => { */ Commands.setInlinesAtRange = (editor, range, properties) => { - const { value } = editor - const { document } = value - editor.withoutNormalizing(() => { - for (const [, path] of document.inlines({ range, onlyLeaves: true })) { + const { value: { document } } = editor + const iterable = document.inlines({ range, onlyLeaves: true }) + + for (const [, path] of iterable) { editor.setNodeByPath(path, properties) } }) @@ -1065,42 +1003,24 @@ Commands.setInlinesAtRange = (editor, range, properties) => { */ Commands.splitBlockAtRange = (editor, range, height = 1) => { - range = deleteExpandedAtRange(editor, range) - - const { start, end } = range - let { value } = editor - let { document } = value - let node = document.assertDescendant(start.path) - let parent = document.getClosestBlock(node.key) - let h = 0 - - while (parent && parent.object === 'block' && h < height) { - node = parent - parent = document.getClosestBlock(parent.key) - h++ - } - editor.withoutNormalizing(() => { - editor.splitDescendantsByKey(node.key, start.path, start.offset) - - value = editor.value - document = value.document - - if (range.isExpanded) { - if (range.isBackward) { - range = range.flip() - } - - const nextBlock = document.getNextBlock(node.key) - range = range.moveAnchorToStartOfNode(nextBlock) - range = range.setFocus(range.focus.setPath(null)) + range = deleteExpandedAtRange(editor, range) + const { start } = range + const { value: { document } } = editor + let h = 0 + let targetPath - if (start.path.equals(end.path)) { - range = range.moveFocusTo(range.anchor.key, end.offset - start.offset) + for (const [node, path] of document.ancestors(start.path)) { + if (h >= height) { + break + } else if (node.object === 'block') { + targetPath = path + h++ } + } - range = document.resolveRange(range) - editor.deleteAtRange(range) + if (targetPath) { + editor.splitDescendantsByKey(targetPath, start.path, start.offset) } }) } @@ -1114,23 +1034,26 @@ Commands.splitBlockAtRange = (editor, range, height = 1) => { */ Commands.splitInlineAtRange = (editor, range, height = Infinity) => { - range = deleteExpandedAtRange(editor, range) - const { start } = range - const { value } = editor - const { document } = value - let h = 0 - let targetPath + editor.withoutNormalizing(() => { + range = deleteExpandedAtRange(editor, range) + const { start } = range + const { value: { document } } = editor + let h = 0 + let targetPath - for (const [node, path] of document.ancestors(start.path)) { - if (node.object === 'inline' && h < height) { - targetPath = path - h++ - } else { - break + for (const [node, path] of document.ancestors(start.path)) { + if (h >= height) { + break + } else if (node.object === 'inline') { + targetPath = path + h++ + } } - } - editor.splitDescendantsByPath(targetPath, start.path, start.offset) + if (targetPath) { + editor.splitDescendantsByPath(targetPath, start.path, start.offset) + } + }) } /** @@ -1162,81 +1085,39 @@ Commands.toggleMarkAtRange = (editor, range, mark) => { /** * Unwrap all of the block nodes in a `range` from a block with `properties`. * + * TODO: This should be aligned with `unwrapInlineAtRange`, which currently does + * not split parent nodes in the ranges, and instead removes any matching inline + * parent nodes in the range. I think we probably need to different concepts, + * and then to allow each for blocks and inlines. + * * @param {Editor} editor * @param {Range} range * @param {String|Object} properties */ Commands.unwrapBlockAtRange = (editor, range, properties) => { - properties = Node.createProperties(properties) - - const { value } = editor - let { document } = value - const blocks = document.getLeafBlocksAtRange(range) - const wrappers = blocks - .map(block => { - return document.getClosest(block.key, parent => { - if (parent.object !== 'block') return false - if (properties.type != null && parent.type !== properties.type) - return false - if (properties.data != null && !parent.data.isSuperset(properties.data)) + editor.withoutNormalizing(() => { + const { value: { document } } = editor + const iterable = document.blocks({ + range, + match: (block, path) => { + if (block.hasProperties(properties)) { return false - return true - }) + } else { + const parentPath = PathUtils.lift(path) + const parent = document.getNode(parentPath) + return parent && parent.hasProperties(properties) + } + }, }) - .filter(exists => exists) - .toOrderedSet() - .toList() - editor.withoutNormalizing(() => { - wrappers.forEach(block => { - const first = block.nodes.first() - const last = block.nodes.last() - const parent = editor.value.document.getParent(block.key) - const index = parent.nodes.indexOf(block) - - const children = block.nodes.filter(child => { - return blocks.some(b => child === b || child.hasDescendant(b.key)) - }) - - const firstMatch = children.first() - const lastMatch = children.last() - - if (first === firstMatch && last === lastMatch) { - block.nodes.forEach((child, i) => { - editor.moveNodeByKey(child.key, parent.key, index + i) - }) + // We need to reverse the paths here, because unwrapping each inline will + // affect the paths of the inlines after it, so we go backwards instead. + const paths = Array.from(iterable, ([, path]) => path).reverse() - editor.removeNodeByKey(block.key) - } else if (last === lastMatch) { - block.nodes.skipUntil(n => n === firstMatch).forEach((child, i) => { - editor.moveNodeByKey(child.key, parent.key, index + 1 + i) - }) - } else if (first === firstMatch) { - block.nodes - .takeUntil(n => n === lastMatch) - .push(lastMatch) - .forEach((child, i) => { - editor.moveNodeByKey(child.key, parent.key, index + i) - }) - } else { - const firstText = firstMatch.getFirstText() - - editor.splitDescendantsByKey(block.key, firstText.key, 0) - - document = editor.value.document - - children.forEach((child, i) => { - if (i === 0) { - const extra = child - child = document.getNextBlock(child.key) - editor.removeNodeByKey(extra.key) - } - - editor.moveNodeByKey(child.key, parent.key, index + 1 + i) - }) - } - }) + for (const path of paths) { + editor.unwrapNodeByPath(path) + } }) } @@ -1249,37 +1130,20 @@ Commands.unwrapBlockAtRange = (editor, range, properties) => { */ Commands.unwrapInlineAtRange = (editor, range, properties) => { - properties = Node.createProperties(properties) - - const { value } = editor - const { document } = value - const texts = document.getTextsAtRange(range) - const inlines = texts - .map(text => { - return document.getClosest(text.key, parent => { - if (parent.object !== 'inline') return false - if (properties.type != null && parent.type !== properties.type) - return false - if (properties.data != null && !parent.data.isSuperset(properties.data)) - return false - return true - }) - }) - .filter(exists => exists) - .toOrderedSet() - .toList() - editor.withoutNormalizing(() => { - inlines.forEach(inline => { - const parent = editor.value.document.getParent(inline.key) - const index = parent.nodes.indexOf(inline) + const { value: { document } } = editor + const iterable = document.inlines({ + range, + match: inline => inline.hasProperties(properties), + }) - inline.nodes.forEach((child, i) => { - editor.moveNodeByKey(child.key, parent.key, index + i) - }) + // We need to reverse the paths here, because unwrapping each inline will + // affect the paths of the inlines after it, so we go backwards instead. + const paths = Array.from(iterable, ([, path]) => path).reverse() - editor.removeNodeByKey(inline.key) - }) + for (const path of paths) { + editor.unwrapChildrenByPath(path) + } }) } diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js index b38df873e5..87b8000135 100644 --- a/packages/slate/src/interfaces/element.js +++ b/packages/slate/src/interfaces/element.js @@ -8,6 +8,7 @@ import Block from '../models/block' import Decoration from '../models/decoration' import Document from '../models/document' import Inline from '../models/inline' +import Node from '../models/node' import Operation from '../models/operation' import PathUtils from '../utils/path-utils' import Point from '../models/point' @@ -126,6 +127,7 @@ class ElementInterface { upward = true, includeBlocks = true, includeDocument = true, + includeHanging = true, includeInlines = true, includeRoot = false, includeTarget = !!options.range, @@ -188,6 +190,31 @@ class ElementInterface { return next() } + if ( + !includeHanging && + targetRange && + targetRange.isExpanded && + targetRange.end.offset === 0 && + (PathUtils.isAbove(path, targetRange.end.path) || + PathUtils.isEqual(path, targetRange.end.path)) + ) { + const closestBlock = root.closestBlock(targetRange.end.path) + + // We also need to ensure that not only is the point's offset zero, + // but that the point refers to the zero offset in the block itself. + // Otherwise it could be inside a nested inline, in which case it + // should not be considered hanging. + if (closestBlock) { + const [blockNode, blockPath] = closestBlock + const relativePath = targetRange.end.path.slice(blockPath.size) + const offset = blockNode.getOffset(relativePath) + + if (offset === 0) { + return next() + } + } + } + if (match && !match(node, path)) { return next() } @@ -1327,6 +1354,28 @@ class ElementInterface { return !!descendant } + /** + * Check if a node has `properties`. + * + * @param {Object} properties + * @return {Boolean} + */ + + hasProperties(properties) { + const node = this + + if (node.object === 'text') { + return false + } + + properties = Node.createProperties(properties) + + return ( + (properties.type == null || node.type === properties.type) && + (properties.data == null || node.data.isSuperset(properties.data)) + ) + } + /** * Check if a node has a void parent. * diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index bff0420019..5f92a11a17 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -42,7 +42,8 @@ function CoreQueriesPlugin() { * @return {Point|Null} */ - getNextPoint(editor, point) { + getNextPoint(editor, point, options = {}) { + const { allowZeroWidth = false } = options const { value } = editor const { document } = value const { path, offset } = point @@ -52,10 +53,11 @@ function CoreQueriesPlugin() { // PERF: if we're not in a void and we have offset to gain, do it easily. if (!closestVoid && offset < node.text.length) { - return point.setOffset(offset + 1) + const next = point.setOffset(offset + 1) + return next.normalize(document) } - for (const [, nextPath] of document.nextTexts({ path })) { + for (const [nextNode, nextPath] of document.texts({ path })) { // If we're still inside the void node, keep going until we exit it. if (closestVoid) { const [, voidPath] = closestVoid @@ -72,22 +74,94 @@ function CoreQueriesPlugin() { const [, blockPath] = closestBlock if (PathUtils.isAfter(nextPath, blockPath)) { - return point.moveTo(nextPath, 0) + const next = point.moveTo(nextPath, 0) + return next.normalize(document) } } - return point.moveTo(nextPath, 1) + // If the text node and we're still in the same block, continue onwards + // because we need to have moved one point forwards, and an empty text + // will be perceived as not moving. + if (nextNode.text.length === 0) { + if (allowZeroWidth) { + const next = point.moveTo(nextPath, 0) + return next.normalize(document) + } else { + continue + } + } + + const next = point.moveTo(nextPath, 1) + return next.normalize(document) } return null }, + /** + * Calculate the next character boundary from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point|Null} + */ + + getNextCharacterPoint(editor, point) { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + const blockText = block.getText() + + if (blockOffset + offset === blockText.length) { + return editor.getNextPoint(point) + } + + const o = blockOffset + offset + const n = TextUtils.getCharOffsetForward(blockText, o) + let next = point + + for (let i = 0; i < n; i++) { + next = editor.getNextPoint(next) + + if (!next) { + break + } + } + + return next + }, + + /** + * Get the next point in the document that is not inside a void node. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point|Null} + */ + + getNextNonVoidPoint(editor, point) { + const { value: { document } } = editor + let next = point + + while (next) { + const closestVoid = document.closest(next.path, editor.isVoid) + + if (closestVoid) { + next = editor.getNextPoint(next, { allowZeroWidth: true }) + } else { + return next + } + } + }, + /** * Calculate the next word boundary from a `point`. * * @param {Editor} editor * @param {Point} point - * @return {Point} + * @return {Point|Null} */ getNextWordPoint(editor, point) { @@ -108,6 +182,10 @@ function CoreQueriesPlugin() { for (let i = 0; i < n; i++) { next = editor.getNextPoint(next) + + if (!next) { + break + } } return next @@ -121,7 +199,8 @@ function CoreQueriesPlugin() { * @return {Point|Null} */ - getPreviousPoint(editor, point) { + getPreviousPoint(editor, point, options = {}) { + const { allowZeroWidth = false } = options const { value } = editor const { document } = value const { path, offset } = point @@ -130,10 +209,13 @@ function CoreQueriesPlugin() { // PERF: if we're not in a void and we have offset to lose, do it easily. if (!closestVoid && offset > 0) { - return point.setOffset(offset - 1) + const prev = point.setOffset(offset - 1) + return prev.normalize(document) } - for (const [prevNode, prevPath] of document.previousTexts({ path })) { + const iterable = document.texts({ path, direction: 'backward' }) + + for (const [prevNode, prevPath] of iterable) { // If we're still inside the void node, keep going until we exit it. if (closestVoid) { const [, voidPath] = closestVoid @@ -150,22 +232,94 @@ function CoreQueriesPlugin() { const [, blockPath] = closestBlock if (PathUtils.isBefore(prevPath, blockPath)) { - return point.moveTo(prevPath, prevNode.text.length) + const prev = point.moveTo(prevPath, prevNode.text.length) + return prev.normalize(document) } } - return point.moveTo(prevPath, prevNode.text.length - 1) + // If the text node and we're still in the same block, continue onwards + // because we need to have moved one point backwards, and an empty text + // will be perceived as not moving. + if (prevNode.text.length === 0) { + if (allowZeroWidth) { + const prev = point.moveTo(prevPath, 0) + return prev.normalize(document) + } else { + continue + } + } + + const prev = point.moveTo(prevPath, prevNode.text.length - 1) + return prev.normalize(document) } return null }, + /** + * Calculate the previous character boundary from a `point`. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point|Null} + */ + + getPreviousCharacterPoint(editor, point) { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + + if (blockOffset + offset === 0) { + return editor.getPreviousPoint(point) + } + + const blockText = block.getText() + const o = blockOffset + offset + const n = TextUtils.getCharOffsetBackward(blockText, o) + let prev = point + + for (let i = 0; i < n; i++) { + prev = editor.getPreviousPoint(prev) + + if (!prev) { + break + } + } + + return prev + }, + + /** + * Get the previous point in the document that is not inside a void node. + * + * @param {Editor} editor + * @param {Point} point + * @return {Point|Null} + */ + + getPreviousNonVoidPoint(editor, point) { + const { value: { document } } = editor + let prev = point + + while (prev) { + const closestVoid = document.closest(prev.path, editor.isVoid) + + if (closestVoid) { + prev = editor.getPreviousPoint(prev, { allowZeroWidth: true }) + } else { + return prev + } + } + }, + /** * Calculate the previous word boundary from a `point`. * * @param {Editor} editor * @param {Point} point - * @return {Point} + * @return {Point|Null} */ getPreviousWordPoint(editor, point) { @@ -186,6 +340,10 @@ function CoreQueriesPlugin() { for (let i = 0; i < n; i++) { prev = editor.getPreviousPoint(prev) + + if (!prev) { + break + } } return prev diff --git a/packages/slate/test/commands/at-current-range/delete-backward/join-blocks-from-inline.js b/packages/slate/test/commands/at-current-range/delete-backward/join-blocks-from-inline.js index d3ed5afa02..6debcd02f2 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/join-blocks-from-inline.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/join-blocks-from-inline.js @@ -11,8 +11,10 @@ export const input = ( onetwo + + three four @@ -26,6 +28,7 @@ export const output = ( onetwo + three four diff --git a/packages/slate/test/commands/at-current-range/insert-block/is-inline-void.js b/packages/slate/test/commands/at-current-range/insert-block/is-inline-void.js index d7f3f9f6c0..3ed415febe 100644 --- a/packages/slate/test/commands/at-current-range/insert-block/is-inline-void.js +++ b/packages/slate/test/commands/at-current-range/insert-block/is-inline-void.js @@ -10,9 +10,11 @@ export const input = ( + + @@ -22,7 +24,9 @@ export const output = ( + + diff --git a/packages/slate/test/commands/at-current-range/set-block/across-inlines.js b/packages/slate/test/commands/at-current-range/set-block/across-inlines.js index af3e3035c2..db1c63d0d6 100644 --- a/packages/slate/test/commands/at-current-range/set-block/across-inlines.js +++ b/packages/slate/test/commands/at-current-range/set-block/across-inlines.js @@ -16,7 +16,7 @@ export const input = ( - another + another @@ -33,7 +33,7 @@ export const output = ( - another + another diff --git a/packages/slate/test/commands/at-current-range/set-block/hanging-selection-across-inlines.js b/packages/slate/test/commands/at-current-range/set-block/hanging-selection-across-inlines.js new file mode 100644 index 0000000000..30144f027f --- /dev/null +++ b/packages/slate/test/commands/at-current-range/set-block/hanging-selection-across-inlines.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.setBlocks({ type: 'code' }) +} + +export const input = ( + + + + + word + + + + + another + + + + +) + +export const output = ( + + + + + word + + + + + another + + + + +) diff --git a/packages/slate/test/commands/at-current-range/split-inline/depth.js b/packages/slate/test/commands/at-current-range/split-inline/height.js similarity index 77% rename from packages/slate/test/commands/at-current-range/split-inline/depth.js rename to packages/slate/test/commands/at-current-range/split-inline/height.js index cc683c532b..654bfd3c05 100644 --- a/packages/slate/test/commands/at-current-range/split-inline/depth.js +++ b/packages/slate/test/commands/at-current-range/split-inline/height.js @@ -10,11 +10,15 @@ export const input = ( + + word + + @@ -24,12 +28,17 @@ export const output = ( + + wo + rd + + From b8a1ef2c6ddaedf388b4f51664889217edf8b25b Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 7 Jun 2019 17:44:49 -0700 Subject: [PATCH 008/165] convert wrapBlock and wrapInline to not use keys --- packages/slate/src/commands/at-range.js | 298 +++++++++--------- .../slate/src/plugins/core/core-queries.js | 22 ++ packages/slate/src/utils/path-utils.js | 2 +- .../wrap-block/nested-block-with-object.js | 36 +++ .../wrap-inline/across-blocks.js | 2 + ...out-parent-void-inline.js => collapsed.js} | 5 +- .../{inside-inlines-end.js => inline-end.js} | 16 +- ...inlines.js => inline-middle-with-marks.js} | 25 +- ...inlines-with-marks.js => inline-middle.js} | 19 +- ...de-inlines-begining.js => inline-start.js} | 12 +- .../wrap-inline/inline-void.js | 8 +- .../at-current-range/wrap-inline/twice.js | 4 +- .../wrap-inline/whole-block.js | 3 +- 13 files changed, 270 insertions(+), 182 deletions(-) create mode 100644 packages/slate/test/commands/at-current-range/wrap-block/nested-block-with-object.js rename packages/slate/test/commands/at-current-range/wrap-inline/{collapsed-range-without-parent-void-inline.js => collapsed.js} (82%) rename packages/slate/test/commands/at-current-range/wrap-inline/{inside-inlines-end.js => inline-end.js} (72%) rename packages/slate/test/commands/at-current-range/wrap-inline/{inside-inlines.js => inline-middle-with-marks.js} (52%) rename packages/slate/test/commands/at-current-range/wrap-inline/{inside-inlines-with-marks.js => inline-middle.js} (73%) rename packages/slate/test/commands/at-current-range/wrap-inline/{inside-inlines-begining.js => inline-start.js} (80%) diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 536f83d493..98ad6373d5 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -31,6 +31,45 @@ function deleteExpandedAtRange(editor, range) { return range } +/** + * Ensure that the edges of a range are split such that they are at the edge of + * all of the inline and text nodes they are in. This will split inline nodes + * and text nodes and update the range to be inside the split. + * + * @param {Editor} + */ + +function splitInlinesAtRange(editor, range) { + if (range.isExpanded) { + editor.deleteAtRange(range) + } + + const { value: { document } } = editor + const start = editor.getPreviousNonVoidPoint(range.start) + const startText = document.getNode(start.path) + const startInline = document.furthestInline(start.path) + const end = editor.getNextNonVoidPoint(range.end) + const endText = document.getNode(end.path) + const endInline = document.furthestInline(end.path) + + if (end.offset !== 0 && end.offset !== endText.text.length) { + editor.splitNodeByPath(end.path, end.offset) + } + + if (start.offset !== 0 && start.offset !== startText.text.length) { + editor.splitNodeByPath(start.path, start.offset) + + const newStart = start + .setPath(PathUtils.increment(start.path)) + .setOffset(0) + .normalize(document) + + range = range.setStart(newStart) + } + + return range +} + /** * Commands. * @@ -681,10 +720,11 @@ Commands.insertBlockAtRange = (editor, range, block) => { const getInsertionMode = (editor, range) => { const { value } = editor const { document } = value + + range = range.normalize(document) const { start } = range - const startKey = start.key - const startBlock = document.getClosestBlock(startKey) - const startInline = document.getClosestInline(startKey) + const startBlock = document.getClosestBlock(start.path) + const startInline = document.getClosestInline(start.path) if (editor.isVoid(startBlock)) { if (start.isAtEndOfNode(startBlock)) return 'after' @@ -725,7 +765,7 @@ Commands.insertFragmentAtRange = (editor, range, fragment) => { const { value } = editor let { document } = value let startText = document.getDescendant(start.path) - let startBlock = document.getClosestBlock(startText.key) + let startBlock = document.getClosestBlock(start.path) let startChild = startBlock.getFurthestChild(startText.key) const isAtStart = start.isAtStartOfNode(startBlock) const parent = document.getParent(startBlock.key) @@ -1159,57 +1199,25 @@ Commands.wrapBlockAtRange = (editor, range, block) => { block = Block.create(block) block = block.set('nodes', block.nodes.clear()) - const { value } = editor - const { document } = value - - const blocks = document.getLeafBlocksAtRange(range) - const firstblock = blocks.first() - const lastblock = blocks.last() - let parent, siblings, index - - // If there is only one block in the selection then we know the parent and - // siblings. - if (blocks.length === 1) { - parent = document.getParent(firstblock.key) - siblings = blocks - } else { - // Determine closest shared parent to all blocks in selection. - parent = document.getClosest(firstblock.key, p1 => { - return !!document.getClosest(lastblock.key, p2 => p1 === p2) - }) - } - - // If no shared parent could be found then the parent is the document. - if (parent == null) { - parent = document - } - - // Create a list of direct children siblings of parent that fall in the - // selection. - if (siblings == null) { - const indexes = parent.nodes.reduce((ind, node, i) => { - if (node === firstblock || node.hasDescendant(firstblock.key)) ind[0] = i - if (node === lastblock || node.hasDescendant(lastblock.key)) ind[1] = i - return ind - }, []) - - index = indexes[0] - siblings = parent.nodes.slice(indexes[0], indexes[1] + 1) - } + const { value: { document } } = editor + const { start, end } = range + const [, firstPath] = document.closestBlock(start.path) + const [, lastPath] = document.closestBlock(end.path) + const ancestorPath = firstPath.equals(lastPath) + ? PathUtils.lift(firstPath) + : PathUtils.relate(firstPath, lastPath) - // Get the index to place the new wrapped node at. - if (index == null) { - index = parent.nodes.indexOf(siblings.first()) - } + const startIndex = firstPath.get(ancestorPath.size) + const endIndex = lastPath.get(ancestorPath.size) editor.withoutNormalizing(() => { - // Inject the new block node into the parent. - editor.insertNodeByKey(parent.key, index, block) + editor.insertNodeByPath(ancestorPath, startIndex, block) - // Move the sibling nodes into the new block node. - siblings.forEach((node, i) => { - editor.moveNodeByKey(node.key, block.key, i) - }) + for (let i = 0; i <= endIndex - startIndex; i++) { + const path = ancestorPath.concat(startIndex + 1) + const newPath = ancestorPath.concat(startIndex) + editor.moveNodeByPath(path, newPath, i) + } }) } @@ -1222,116 +1230,110 @@ Commands.wrapBlockAtRange = (editor, range, block) => { */ Commands.wrapInlineAtRange = (editor, range, inline) => { - const { value } = editor - let { document } = value - const { start, end } = range - - if (range.isCollapsed) { - // Wrapping an inline void - const inlineParent = document.getClosestInline(start.path) - - if (!inlineParent) { - return - } - - if (!editor.isVoid(inlineParent)) { - return - } - - return editor.wrapInlineByKey(inlineParent.key, inline) - } - inline = Inline.create(inline) inline = inline.set('nodes', inline.nodes.clear()) - const blocks = document.getLeafBlocksAtRange(range) - let startBlock = document.getClosestBlock(start.path) - let endBlock = document.getClosestBlock(end.path) - const startInline = document.getClosestInline(start.path) - const endInline = document.getClosestInline(end.path) - let startChild = startBlock.getFurthestChild(start.key) - let endChild = endBlock.getFurthestChild(end.key) - editor.withoutNormalizing(() => { - if (!startInline || startInline !== endInline) { - editor.splitDescendantsByKey(endChild.key, end.key, end.offset) - editor.splitDescendantsByKey(startChild.key, start.key, start.offset) + const { value: { document } } = editor + let start = editor.getPreviousNonVoidPoint(range.start) + let end = editor.getNextNonVoidPoint(range.end) + const startText = document.getNode(start.path) + const endText = document.getNode(end.path) + const startFurthest = document.furthestInline(start.path) + const endFurthest = document.furthestInline(end.path) + + if (endFurthest) { + const [furthestNode, furthestPath] = endFurthest + const [lastText, lastPath] = furthestNode.lastText() + const relativePath = end.path.slice(furthestPath.size) + + if ( + end.offset !== lastText.text.length || + !relativePath.equals(lastPath) + ) { + editor.splitDescendantsByPath(furthestPath, end.path, end.offset) + } + } else if (end.offset !== 0 && end.offset !== endText.text.length) { + editor.splitNodeByPath(end.path, end.offset) + + end = end + .setPath(PathUtils.increment(end.path)) + .setOffset(0) + .setKey(null) + .normalize(editor.value.document) } - document = editor.value.document - startBlock = document.getDescendant(startBlock.key) - endBlock = document.getDescendant(endBlock.key) - startChild = startBlock.getFurthestChild(start.key) - endChild = endBlock.getFurthestChild(end.key) - const startIndex = startBlock.nodes.indexOf(startChild) - const endIndex = endBlock.nodes.indexOf(endChild) - - if (startInline && startInline === endInline) { - const texts = startBlock.getTextsAtRange(range).map(text => { - if (start.key === text.key && end.key === text.key) { - return text - .splitText(start.offset)[1] - .splitText(end.offset - start.offset)[0] - .regenerateKey() - } else if (start.key === text.key) { - return text.splitText(start.offset)[1].regenerateKey() - } else if (end.key === text.key) { - return text.splitText(end.offset)[0].regenerateKey() - } else { - return text.regenerateKey() + if (startFurthest) { + const [furthestNode, furthestPath] = startFurthest + const [, firstPath] = furthestNode.firstText() + const relativePath = start.path.slice(furthestPath.size) + + if (start.offset !== 0 || !relativePath.equals(firstPath)) { + editor.splitDescendantsByPath(furthestPath, start.path, start.offset) + + if ( + PathUtils.isYounger(furthestPath, end.path) || + PathUtils.isAbove(furthestPath, end.path) || + PathUtils.isEqual(furthestPath, end.path) + ) { + end = end + .setPath(PathUtils.increment(end.path, 1, furthestPath.size - 1)) + .setKey(null) + .normalize(editor.value.document) } - }) - inline = inline.set('nodes', texts) - editor.insertInlineAtRange(range, inline) - } else if (startBlock === endBlock) { - document = editor.value.document - startBlock = document.getClosestBlock(start.key) - startChild = startBlock.getFurthestChild(start.key) - - const startInner = document.getNextSibling(startChild.key) - const startInnerIndex = startBlock.nodes.indexOf(startInner) - const endInner = - start.key === end.key - ? startInner - : startBlock.getFurthestChild(end.key) - const inlines = startBlock.nodes - .skipUntil(n => n === startInner) - .takeUntil(n => n === endInner) - .push(endInner) - - const node = inline.regenerateKey() - - editor.insertNodeByKey(startBlock.key, startInnerIndex, node) - - inlines.forEach((child, i) => { - editor.moveNodeByKey(child.key, node.key, i) - }) - } else { - const startInlines = startBlock.nodes.slice(startIndex + 1) - const endInlines = endBlock.nodes.slice(0, endIndex + 1) - const startNode = inline.regenerateKey() - const endNode = inline.regenerateKey() + start = start + .setPath( + PathUtils.increment(furthestPath).concat(relativePath.map(() => 0)) + ) + .setOffset(0) + .setKey(null) + .normalize(editor.value.document) + } + } else if (start.offset !== 0 && start.offset !== startText.text.length) { + editor.splitNodeByPath(start.path, start.offset) + + if ( + PathUtils.isYounger(start.path, end.path) || + PathUtils.isAbove(start.path, end.path) || + PathUtils.isEqual(start.path, end.path) + ) { + end = end + .setPath(PathUtils.increment(end.path, 1, start.path.size - 1)) + .setKey(null) + .normalize(editor.value.document) + } - editor.insertNodeByKey(startBlock.key, startIndex + 1, startNode) - editor.insertNodeByKey(endBlock.key, endIndex, endNode) + start = start + .setPath(PathUtils.increment(start.path)) + .setOffset(0) + .setKey(null) + .normalize(editor.value.document) + } - startInlines.forEach((child, i) => { - editor.moveNodeByKey(child.key, startNode.key, i) - }) + range = range.setAnchor(start).setFocus(end) + range = editor.getNonHangingRange(range) - endInlines.forEach((child, i) => { - editor.moveNodeByKey(child.key, endNode.key, i) - }) + const iterable = editor.value.document.blocks({ range, onlyLeaves: true }) - blocks.slice(1, -1).forEach(block => { - const node = inline.regenerateKey() - editor.insertNodeByKey(block.key, 0, node) + for (const [block, blockPath] of iterable) { + const isStart = PathUtils.isAbove(blockPath, range.start.path) + const isEnd = PathUtils.isAbove(blockPath, range.end.path) + const startIndex = isStart ? range.start.path.get(blockPath.size) : 0 + const endIndex = isEnd + ? range.end.path.get(blockPath.size) + : block.nodes.size - 1 - block.nodes.forEach((child, i) => { - editor.moveNodeByKey(child.key, node.key, i) - }) - }) + editor.insertNodeByPath(blockPath, startIndex, inline) + // HACK: need to regenerate the key to ensure that subsequent inserts + // don't re-use the same key. + inline = inline.regenerateKey() + + for (let i = 0; i <= endIndex - startIndex; i++) { + const path = blockPath.concat(startIndex + 1) + const newPath = blockPath.concat(startIndex) + editor.moveNodeByPath(path, newPath, i) + } } }) } diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index 5f92a11a17..027539fbbb 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -191,6 +191,28 @@ function CoreQueriesPlugin() { return next }, + /** + * Calculate a non-hanging range from a `range`. + * + * @param {Editor} editor + * @param {Range} range + * @return {Range} + */ + + getNonHangingRange(editor, range) { + const { value: { document } } = editor + const { isExpanded, start, end } = range + + if (isExpanded && end.offset === 0 && !start.path.equals(end.path)) { + const [prevText, prevPath] = document.previousText(end.path) + const newEnd = end.moveTo(prevPath, prevText.text.length) + const nonHanging = range.setEnd(newEnd) + return nonHanging + } else { + return range + } + }, + /** * Calculate the previous point backward from a `point`. * diff --git a/packages/slate/src/utils/path-utils.js b/packages/slate/src/utils/path-utils.js index 471f944201..bff28ac046 100644 --- a/packages/slate/src/utils/path-utils.js +++ b/packages/slate/src/utils/path-utils.js @@ -90,7 +90,7 @@ function decrement(path, n = 1, index = path.size - 1) { } /** - * Get all ancestor paths of th given path. + * Get all ancestor paths of the given path. * * @param {List} path * @returns {List} diff --git a/packages/slate/test/commands/at-current-range/wrap-block/nested-block-with-object.js b/packages/slate/test/commands/at-current-range/wrap-block/nested-block-with-object.js new file mode 100644 index 0000000000..3e9bbe9074 --- /dev/null +++ b/packages/slate/test/commands/at-current-range/wrap-block/nested-block-with-object.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.wrapBlock({ + type: 'quote', + data: { thing: 'value' }, + }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + + word + + + + + +) diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/across-blocks.js b/packages/slate/test/commands/at-current-range/wrap-inline/across-blocks.js index 8942c1074c..ab934c7f28 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/across-blocks.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/across-blocks.js @@ -26,8 +26,10 @@ export const output = ( wo rd + + an other diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/collapsed-range-without-parent-void-inline.js b/packages/slate/test/commands/at-current-range/wrap-inline/collapsed.js similarity index 82% rename from packages/slate/test/commands/at-current-range/wrap-inline/collapsed-range-without-parent-void-inline.js rename to packages/slate/test/commands/at-current-range/wrap-inline/collapsed.js index 15c54fb75f..11e7b30c6b 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/collapsed-range-without-parent-void-inline.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/collapsed.js @@ -20,7 +20,10 @@ export const output = ( - wd + w + + + d diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-end.js b/packages/slate/test/commands/at-current-range/wrap-inline/inline-end.js similarity index 72% rename from packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-end.js rename to packages/slate/test/commands/at-current-range/wrap-inline/inline-end.js index 46061485db..5636b8a7a6 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-end.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/inline-end.js @@ -20,18 +20,20 @@ export const input = ( ) -// TODO: this selection logic isn't right export const output = ( - - hello - - - - + hel + + + + + lo + + + diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines.js b/packages/slate/test/commands/at-current-range/wrap-inline/inline-middle-with-marks.js similarity index 52% rename from packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines.js rename to packages/slate/test/commands/at-current-range/wrap-inline/inline-middle-with-marks.js index c46808196e..64082ff3c4 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/inline-middle-with-marks.js @@ -10,9 +10,13 @@ export const input = ( + - hello + + hello + + @@ -23,10 +27,25 @@ export const output = ( + - hell - o + he + + + + + ll + + + + + + + o + + + diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-with-marks.js b/packages/slate/test/commands/at-current-range/wrap-inline/inline-middle.js similarity index 73% rename from packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-with-marks.js rename to packages/slate/test/commands/at-current-range/wrap-inline/inline-middle.js index c558bc7827..eb423ffef0 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-with-marks.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/inline-middle.js @@ -12,10 +12,7 @@ export const input = ( - - hell - - o + hello @@ -28,14 +25,16 @@ export const output = ( + + he + + + + ll + + - h - - - ell - - o diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-begining.js b/packages/slate/test/commands/at-current-range/wrap-inline/inline-start.js similarity index 80% rename from packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-begining.js rename to packages/slate/test/commands/at-current-range/wrap-inline/inline-start.js index b1351e60f8..dc241eab99 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/inside-inlines-begining.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/inline-start.js @@ -20,16 +20,20 @@ export const input = ( ) -// TODO: the selection logic here is wrong export const output = ( - + + + + hel + - hel - + + + lo diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inline-void.js b/packages/slate/test/commands/at-current-range/wrap-inline/inline-void.js index 1414ed677b..5a49950bc3 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/inline-void.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/inline-void.js @@ -3,9 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.wrapInline({ - type: 'link', - }) + editor.wrapInline('link') } export const input = ( @@ -13,7 +11,7 @@ export const input = ( - {' '} + @@ -26,7 +24,7 @@ export const output = ( - {' '} + diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/twice.js b/packages/slate/test/commands/at-current-range/wrap-inline/twice.js index 7beabbca71..234328faa8 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/twice.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/twice.js @@ -20,11 +20,13 @@ export const output = ( - w + w + or + d diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/whole-block.js b/packages/slate/test/commands/at-current-range/wrap-inline/whole-block.js index c1c4f2a815..20272ae46b 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/whole-block.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/whole-block.js @@ -21,9 +21,8 @@ export const output = ( - word + word - From f64b604826f046f8f6f2ba0d3076e873b01b63db Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 7 Jun 2019 17:45:54 -0700 Subject: [PATCH 009/165] cleanup --- packages/slate/src/commands/at-range.js | 2 -- packages/slate/src/controllers/editor.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 98ad6373d5..255b61cf0e 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -2,8 +2,6 @@ import { List } from 'immutable' import Block from '../models/block' import Inline from '../models/inline' import Mark from '../models/mark' -import Node from '../models/node' -import TextUtils from '../utils/text-utils' import PathUtils from '../utils/path-utils' /** diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index 07faac674f..52f55ecfc9 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -168,7 +168,6 @@ class Editor { hasCommand(type) { const { controller } = this const has = type in controller && controller[type].__command - return has } @@ -182,7 +181,6 @@ class Editor { hasQuery(type) { const { controller } = this const has = type in controller && controller[type].__query - return has } From 2e206f0883fea959df8fc4e8ecd8efb3053a3cc8 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 7 Jun 2019 17:59:19 -0700 Subject: [PATCH 010/165] remove chainability from editor --- packages/slate/src/commands/on-selection.js | 9 ++++++--- packages/slate/src/commands/with-intent.js | 11 ++++++++--- packages/slate/src/controllers/editor.js | 14 +++----------- .../add-mark/collapsed-selection-end.js | 3 ++- .../add-mark/collapsed-selection-middle.js | 3 ++- .../add-mark/collapsed-selection-start.js | 3 ++- .../add-marks/collapsed-selection-end.js | 3 ++- .../add-marks/collapsed-selection-middle.js | 3 ++- .../add-marks/collapsed-selection-start.js | 3 ++- .../remove-mark/collapsed-selection.js | 7 +++---- .../at-current-range/split-block/with-marks.js | 7 +++---- .../add-collapsed-selection-start.js | 3 ++- .../toggle-mark/add-collapsed-selection.js | 3 ++- .../remove-collapsed-selection-beginning.js | 7 +++---- .../toggle-mark/remove-collapsed-selection.js | 7 +++---- .../at-current-range/wrap-inline/twice.js | 3 ++- .../editor/has-command/existing-registered.js | 4 +++- .../editor/has-command/missing-registered.js | 4 +++- .../editor/has-query/existing-registered.js | 4 +++- .../editor/has-query/missing-registered.js | 4 +++- .../test/history/undo/add-mark-across-blocks.js | 3 ++- .../test/history/undo/add-mark-across-marks.js | 3 ++- .../history/undo/add-mark-across-same-mark.js | 3 ++- packages/slate/test/history/undo/add-mark.js | 3 ++- .../test/history/undo/delete-across-blocks.js | 3 ++- .../test/history/undo/delete-across-inlines.js | 3 ++- .../test/history/undo/delete-across-marks.js | 3 ++- .../undo/delete-backward-nested-blocks.js | 3 ++- .../slate/test/history/undo/delete-backward.js | 3 ++- packages/slate/test/history/undo/delete.js | 3 ++- .../slate/test/history/undo/insert-block.js | 3 ++- .../slate/test/history/undo/insert-fragment.js | 7 +++---- .../test/history/undo/insert-text-contiguous.js | 9 ++++++--- .../history/undo/insert-text-not-contiguous.js | 17 ++++++++--------- packages/slate/test/history/undo/insert-text.js | 3 ++- .../history/undo/move-node-affecting-path.js | 3 ++- .../history/undo/move-node-before-itself.js | 3 ++- .../slate/test/history/undo/move-node-by-key.js | 3 ++- .../move-node-by-path-ancestor-left-sibling.js | 3 ++- .../test/history/undo/move-node-by-path.js | 3 ++- packages/slate/test/history/undo/remove-mark.js | 3 ++- .../test/history/undo/remove-node-by-key.js | 3 ++- packages/slate/test/history/undo/remove-text.js | 11 +++++------ .../history/undo/set-node-by-key-with-data.js | 3 ++- .../history/undo/split-node-by-key-block.js | 3 ++- .../test/history/undo/unwrap-node-by-key.js | 3 ++- .../history/undo/wrap-inline-across-blocks.js | 3 ++- 47 files changed, 127 insertions(+), 91 deletions(-) diff --git a/packages/slate/src/commands/on-selection.js b/packages/slate/src/commands/on-selection.js index 57de7cf51c..dafa68ce46 100644 --- a/packages/slate/src/commands/on-selection.js +++ b/packages/slate/src/commands/on-selection.js @@ -496,7 +496,8 @@ Commands.moveAnchorWordForward = editor => { */ Commands.moveBackward = (editor, n) => { - editor.moveAnchorBackward(n).moveFocusBackward(n) + editor.moveAnchorBackward(n) + editor.moveFocusBackward(n) } /** @@ -507,7 +508,8 @@ Commands.moveBackward = (editor, n) => { */ Commands.moveWordBackward = (editor, n) => { - editor.moveAnchorWordBackward(n).moveFocusWordBackward(n) + editor.moveAnchorWordBackward(n) + editor.moveFocusWordBackward(n) } /** @@ -1303,7 +1305,8 @@ Commands.moveFocusWordForward = editor => { */ Commands.moveForward = (editor, ...args) => { - editor.moveAnchorForward(...args).moveFocusForward(...args) + editor.moveAnchorForward(...args) + editor.moveFocusForward(...args) } /** diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js index d553e1f338..40162d239d 100644 --- a/packages/slate/src/commands/with-intent.js +++ b/packages/slate/src/commands/with-intent.js @@ -293,7 +293,8 @@ Commands.insertFragment = (editor, fragment) => { (acc, val) => acc + val.text.length, 0 ) - editor.moveToStartOfNode(newText).moveForward(remainingTextLength) + editor.moveToStartOfNode(newText) + editor.moveForward(remainingTextLength) } } @@ -314,7 +315,10 @@ Commands.insertInline = (editor, inline) => { // If the node was successfully inserted, update the selection. const node = editor.value.document.getNode(inline.key) - if (node) editor.moveToEndOfNode(node) + + if (node) { + editor.moveToEndOfNode(node) + } } /** @@ -420,7 +424,8 @@ Commands.splitBlock = (editor, depth = 1) => { const { value } = editor const { selection, document } = value const marks = selection.marks || document.getInsertMarksAtRange(selection) - editor.splitBlockAtRange(selection, depth).moveToEnd() + editor.splitBlockAtRange(selection, depth) + editor.moveToEnd() if (marks && marks.size !== 0) { editor.select({ marks }) diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index 52f55ecfc9..85c1ef4b23 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -114,8 +114,6 @@ class Editor { this.tmp.flushing = true Promise.resolve().then(() => this.flush()) } - - return controller } /** @@ -126,12 +124,11 @@ class Editor { flush() { this.run('onChange') - const { value, operations, controller } = this + const { value, operations } = this const change = { value, operations } this.operations = List() this.tmp.flushing = false this.onChange(change) - return controller } /** @@ -153,9 +150,9 @@ class Editor { debug('command', { type, args }) const obj = { type, args } - this.run('onCommand', obj) + const ret = this.run('onCommand', obj) normalizeDirtyPaths(this) - return controller + return ret } /** @@ -207,8 +204,6 @@ class Editor { if (selection.isUnset && document.nodes.size) { controller.moveToStartOfDocument() } - - return controller } /** @@ -253,7 +248,6 @@ class Editor { const method = (...args) => this.command(type, ...args) controller[type] = method method.__command = true - return controller } /** @@ -278,7 +272,6 @@ class Editor { const method = (...args) => this.query(type, ...args) controller[type] = method method.__query = true - return controller } /** @@ -400,7 +393,6 @@ class Editor { fn(controller) this.tmp.normalize = value normalizeDirtyPaths(this) - return controller } /** diff --git a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-end.js b/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-end.js index 0c1b3eafbf..7251a5dcfa 100644 --- a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-end.js +++ b/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-end.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.addMark('bold').insertText('a') + editor.addMark('bold') + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-middle.js b/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-middle.js index fe6eb3ad42..17175f0434 100644 --- a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-middle.js +++ b/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-middle.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.addMark('bold').insertText('a') + editor.addMark('bold') + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-start.js b/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-start.js index 30ca0b13a2..9608b93230 100644 --- a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-start.js +++ b/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-start.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.addMark('bold').insertText('a') + editor.addMark('bold') + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-end.js b/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-end.js index 8b98dfbd14..d43947067c 100644 --- a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-end.js +++ b/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-end.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.addMarks(['bold', 'italic']).insertText('a') + editor.addMarks(['bold', 'italic']) + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-middle.js b/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-middle.js index b026c96833..42e7638024 100644 --- a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-middle.js +++ b/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-middle.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.addMarks(['bold', 'italic']).insertText('a') + editor.addMarks(['bold', 'italic']) + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-start.js b/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-start.js index 961cce6e0b..68ed7f6d2e 100644 --- a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-start.js +++ b/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-start.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.addMarks(['bold', 'italic']).insertText('a') + editor.addMarks(['bold', 'italic']) + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/remove-mark/collapsed-selection.js b/packages/slate/test/commands/at-current-range/remove-mark/collapsed-selection.js index 25a33d6986..45d186c896 100644 --- a/packages/slate/test/commands/at-current-range/remove-mark/collapsed-selection.js +++ b/packages/slate/test/commands/at-current-range/remove-mark/collapsed-selection.js @@ -3,10 +3,9 @@ import h from '../../../helpers/h' export default function(editor) { - editor - .addMark('bold') - .removeMark('bold') - .insertText('a') + editor.addMark('bold') + editor.removeMark('bold') + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/split-block/with-marks.js b/packages/slate/test/commands/at-current-range/split-block/with-marks.js index 808e5d0536..1d609d6cf2 100644 --- a/packages/slate/test/commands/at-current-range/split-block/with-marks.js +++ b/packages/slate/test/commands/at-current-range/split-block/with-marks.js @@ -3,10 +3,9 @@ import h from '../../../helpers/h' export default function(editor) { - editor - .addMark('italic') - .splitBlock() - .insertText('cat is cute') + editor.addMark('italic') + editor.splitBlock() + editor.insertText('cat is cute') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection-start.js b/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection-start.js index e5ce254345..0fe9f5294e 100644 --- a/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection-start.js +++ b/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection-start.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.toggleMark('bold').insertText('a') + editor.toggleMark('bold') + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection.js b/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection.js index ed82d16f5f..99c8de1c10 100644 --- a/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection.js +++ b/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.toggleMark('bold').insertText('s') + editor.toggleMark('bold') + editor.insertText('s') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection-beginning.js b/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection-beginning.js index 52f1716f7e..ad8eccd41f 100644 --- a/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection-beginning.js +++ b/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection-beginning.js @@ -3,10 +3,9 @@ import h from '../../../helpers/h' export default function(editor) { - editor - .toggleMark('bold') - .toggleMark('bold') - .insertText('a') + editor.toggleMark('bold') + editor.toggleMark('bold') + editor.insertText('a') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection.js b/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection.js index 2711ff73b2..9dd1af655f 100644 --- a/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection.js +++ b/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection.js @@ -3,10 +3,9 @@ import h from '../../../helpers/h' export default function(editor) { - editor - .toggleMark('bold') - .toggleMark('bold') - .insertText('s') + editor.toggleMark('bold') + editor.toggleMark('bold') + editor.insertText('s') } export const input = ( diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/twice.js b/packages/slate/test/commands/at-current-range/wrap-inline/twice.js index 234328faa8..fdd6d5a070 100644 --- a/packages/slate/test/commands/at-current-range/wrap-inline/twice.js +++ b/packages/slate/test/commands/at-current-range/wrap-inline/twice.js @@ -3,7 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.wrapInline('link').wrapInline('hashtag') + editor.wrapInline('link') + editor.wrapInline('hashtag') } export const input = ( diff --git a/packages/slate/test/controllers/editor/has-command/existing-registered.js b/packages/slate/test/controllers/editor/has-command/existing-registered.js index a69dba5ac1..09252ace47 100644 --- a/packages/slate/test/controllers/editor/has-command/existing-registered.js +++ b/packages/slate/test/controllers/editor/has-command/existing-registered.js @@ -2,7 +2,9 @@ import { Editor } from 'slate' -export const input = new Editor().registerCommand('customCommand') +export const input = new Editor() + +input.registerCommand('customCommand') export default function(editor) { return editor.hasCommand('customCommand') diff --git a/packages/slate/test/controllers/editor/has-command/missing-registered.js b/packages/slate/test/controllers/editor/has-command/missing-registered.js index 9b9fc7b679..cd0cf9c35b 100644 --- a/packages/slate/test/controllers/editor/has-command/missing-registered.js +++ b/packages/slate/test/controllers/editor/has-command/missing-registered.js @@ -2,7 +2,9 @@ import { Editor } from 'slate' -export const input = new Editor().registerCommand('customCommand') +export const input = new Editor() + +input.registerCommand('customCommand') export default function(editor) { return editor.hasCommand('otherCommand') diff --git a/packages/slate/test/controllers/editor/has-query/existing-registered.js b/packages/slate/test/controllers/editor/has-query/existing-registered.js index 2affe22d65..1fa354135e 100644 --- a/packages/slate/test/controllers/editor/has-query/existing-registered.js +++ b/packages/slate/test/controllers/editor/has-query/existing-registered.js @@ -2,7 +2,9 @@ import { Editor } from 'slate' -export const input = new Editor().registerQuery('customQuery') +export const input = new Editor() + +input.registerQuery('customQuery') export default function(editor) { return editor.hasQuery('customQuery') diff --git a/packages/slate/test/controllers/editor/has-query/missing-registered.js b/packages/slate/test/controllers/editor/has-query/missing-registered.js index 35f5f50c2d..b8109f1f66 100644 --- a/packages/slate/test/controllers/editor/has-query/missing-registered.js +++ b/packages/slate/test/controllers/editor/has-query/missing-registered.js @@ -2,7 +2,9 @@ import { Editor } from 'slate' -export const input = new Editor().registerQuery('customQuery') +export const input = new Editor() + +input.registerQuery('customQuery') export default function(editor) { return editor.hasQuery('otherQuery') diff --git a/packages/slate/test/history/undo/add-mark-across-blocks.js b/packages/slate/test/history/undo/add-mark-across-blocks.js index 310c6f1eb7..7f37eac94f 100644 --- a/packages/slate/test/history/undo/add-mark-across-blocks.js +++ b/packages/slate/test/history/undo/add-mark-across-blocks.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.addMark('bold') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/add-mark-across-marks.js b/packages/slate/test/history/undo/add-mark-across-marks.js index 3036f95a59..434c4fb99a 100644 --- a/packages/slate/test/history/undo/add-mark-across-marks.js +++ b/packages/slate/test/history/undo/add-mark-across-marks.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.addMark('bold') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/add-mark-across-same-mark.js b/packages/slate/test/history/undo/add-mark-across-same-mark.js index aa1e5cb0b3..9f0c6e1b64 100644 --- a/packages/slate/test/history/undo/add-mark-across-same-mark.js +++ b/packages/slate/test/history/undo/add-mark-across-same-mark.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.addMark('bold') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/add-mark.js b/packages/slate/test/history/undo/add-mark.js index bb2cd613ef..efddf6dd39 100644 --- a/packages/slate/test/history/undo/add-mark.js +++ b/packages/slate/test/history/undo/add-mark.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.addMark('bold') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/delete-across-blocks.js b/packages/slate/test/history/undo/delete-across-blocks.js index 08574322d0..f257340e1e 100644 --- a/packages/slate/test/history/undo/delete-across-blocks.js +++ b/packages/slate/test/history/undo/delete-across-blocks.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.delete() - editor.flush().undo() + editor.flush() + editor.undo() } // the paragraph and code blocks have some random data diff --git a/packages/slate/test/history/undo/delete-across-inlines.js b/packages/slate/test/history/undo/delete-across-inlines.js index ff66422912..b573ea546b 100644 --- a/packages/slate/test/history/undo/delete-across-inlines.js +++ b/packages/slate/test/history/undo/delete-across-inlines.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.delete() - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/delete-across-marks.js b/packages/slate/test/history/undo/delete-across-marks.js index bf1220eabd..2ea9eceb1a 100644 --- a/packages/slate/test/history/undo/delete-across-marks.js +++ b/packages/slate/test/history/undo/delete-across-marks.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.delete() - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/delete-backward-nested-blocks.js b/packages/slate/test/history/undo/delete-backward-nested-blocks.js index 9e8e50d6bb..9ff9012dc1 100644 --- a/packages/slate/test/history/undo/delete-backward-nested-blocks.js +++ b/packages/slate/test/history/undo/delete-backward-nested-blocks.js @@ -3,7 +3,8 @@ import h from '../../helpers/h' export default function(editor) { - editor.deleteBackward().undo() + editor.deleteBackward() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/delete-backward.js b/packages/slate/test/history/undo/delete-backward.js index 8149c45ea7..eae8de6874 100644 --- a/packages/slate/test/history/undo/delete-backward.js +++ b/packages/slate/test/history/undo/delete-backward.js @@ -3,7 +3,8 @@ import h from '../../helpers/h' export default function(editor) { - editor.deleteBackward().undo() + editor.deleteBackward() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/delete.js b/packages/slate/test/history/undo/delete.js index 13f496e490..2ae6806520 100644 --- a/packages/slate/test/history/undo/delete.js +++ b/packages/slate/test/history/undo/delete.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.delete() - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/insert-block.js b/packages/slate/test/history/undo/insert-block.js index 409599402e..5011a7f81a 100644 --- a/packages/slate/test/history/undo/insert-block.js +++ b/packages/slate/test/history/undo/insert-block.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.insertBlock('quote') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/insert-fragment.js b/packages/slate/test/history/undo/insert-fragment.js index f0e6f3f802..f151066a34 100644 --- a/packages/slate/test/history/undo/insert-fragment.js +++ b/packages/slate/test/history/undo/insert-fragment.js @@ -24,10 +24,9 @@ const fragment = ( ) export default function(editor) { - editor - .insertFragment(fragment) - .flush() - .undo() + editor.insertFragment(fragment) + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/insert-text-contiguous.js b/packages/slate/test/history/undo/insert-text-contiguous.js index 8dca965c9b..cae034da0e 100644 --- a/packages/slate/test/history/undo/insert-text-contiguous.js +++ b/packages/slate/test/history/undo/insert-text-contiguous.js @@ -4,9 +4,12 @@ import h from '../../helpers/h' export default function(editor) { editor.insertText('t') - editor.flush().insertText('w') - editor.flush().insertText('o') - editor.flush().undo() + editor.flush() + editor.insertText('w') + editor.flush() + editor.insertText('o') + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/insert-text-not-contiguous.js b/packages/slate/test/history/undo/insert-text-not-contiguous.js index 92bfe1f5aa..def6c4beab 100644 --- a/packages/slate/test/history/undo/insert-text-not-contiguous.js +++ b/packages/slate/test/history/undo/insert-text-not-contiguous.js @@ -5,17 +5,16 @@ import h from '../../helpers/h' export default function(editor) { editor.insertText('t') - editor - .flush() - .moveBackward(1) - .insertText('w') + editor.flush() + editor.moveBackward(1) + editor.insertText('w') - editor - .flush() - .moveBackward(1) - .insertText('o') + editor.flush() + editor.moveBackward(1) + editor.insertText('o') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/insert-text.js b/packages/slate/test/history/undo/insert-text.js index a3dbff1e83..98d78c4bb0 100644 --- a/packages/slate/test/history/undo/insert-text.js +++ b/packages/slate/test/history/undo/insert-text.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.insertText('text') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/move-node-affecting-path.js b/packages/slate/test/history/undo/move-node-affecting-path.js index 830815e381..9bec4c656b 100644 --- a/packages/slate/test/history/undo/move-node-affecting-path.js +++ b/packages/slate/test/history/undo/move-node-affecting-path.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.moveNodeByKey('c', 'd', 1) - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/move-node-before-itself.js b/packages/slate/test/history/undo/move-node-before-itself.js index 0bc82fb7db..fdc584299e 100644 --- a/packages/slate/test/history/undo/move-node-before-itself.js +++ b/packages/slate/test/history/undo/move-node-before-itself.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.moveNodeByKey('h', 'a', 0) - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/move-node-by-key.js b/packages/slate/test/history/undo/move-node-by-key.js index e16f0423ce..93d3c9e315 100644 --- a/packages/slate/test/history/undo/move-node-by-key.js +++ b/packages/slate/test/history/undo/move-node-by-key.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.moveNodeByKey('b', 'a', 1) - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js b/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js index 634dcc4455..142e60f35e 100644 --- a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js +++ b/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js @@ -8,7 +8,8 @@ const pathB = PathUtils.create([1]) export default function(editor) { editor.moveNodeByPath(pathA, pathB, 1) - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/move-node-by-path.js b/packages/slate/test/history/undo/move-node-by-path.js index c54a0b44fd..2d8005ecc5 100644 --- a/packages/slate/test/history/undo/move-node-by-path.js +++ b/packages/slate/test/history/undo/move-node-by-path.js @@ -8,7 +8,8 @@ const pathB = PathUtils.create([1]) export default function(editor) { editor.moveNodeByPath(pathA, pathB, 1) - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/remove-mark.js b/packages/slate/test/history/undo/remove-mark.js index 0e1002b905..5dd751bea2 100644 --- a/packages/slate/test/history/undo/remove-mark.js +++ b/packages/slate/test/history/undo/remove-mark.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.removeMark('bold') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/remove-node-by-key.js b/packages/slate/test/history/undo/remove-node-by-key.js index d099bb99eb..54b9a6a757 100644 --- a/packages/slate/test/history/undo/remove-node-by-key.js +++ b/packages/slate/test/history/undo/remove-node-by-key.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.removeNodeByKey('a') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/remove-text.js b/packages/slate/test/history/undo/remove-text.js index 695b770e78..77f9d7493f 100644 --- a/packages/slate/test/history/undo/remove-text.js +++ b/packages/slate/test/history/undo/remove-text.js @@ -3,12 +3,11 @@ import h from '../../helpers/h' export default function(editor) { - editor - .moveAnchorForward(4) - .moveFocusForward(7) - .delete() - - editor.flush().undo() + editor.moveAnchorForward(4) + editor.moveFocusForward(7) + editor.delete() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/set-node-by-key-with-data.js b/packages/slate/test/history/undo/set-node-by-key-with-data.js index 02a97b635e..2289c17eb1 100644 --- a/packages/slate/test/history/undo/set-node-by-key-with-data.js +++ b/packages/slate/test/history/undo/set-node-by-key-with-data.js @@ -7,7 +7,8 @@ export default function(editor) { data: { thing: 'value' }, }) - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/split-node-by-key-block.js b/packages/slate/test/history/undo/split-node-by-key-block.js index 906a4ded44..27d563d35c 100644 --- a/packages/slate/test/history/undo/split-node-by-key-block.js +++ b/packages/slate/test/history/undo/split-node-by-key-block.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.splitNodeByKey('a', 2) - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/unwrap-node-by-key.js b/packages/slate/test/history/undo/unwrap-node-by-key.js index 62893ea09d..a91bbab5d6 100644 --- a/packages/slate/test/history/undo/unwrap-node-by-key.js +++ b/packages/slate/test/history/undo/unwrap-node-by-key.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.unwrapNodeByKey('a') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( diff --git a/packages/slate/test/history/undo/wrap-inline-across-blocks.js b/packages/slate/test/history/undo/wrap-inline-across-blocks.js index 3338911ebc..c84c55e2a6 100644 --- a/packages/slate/test/history/undo/wrap-inline-across-blocks.js +++ b/packages/slate/test/history/undo/wrap-inline-across-blocks.js @@ -4,7 +4,8 @@ import h from '../../helpers/h' export default function(editor) { editor.wrapInline('hashtag') - editor.flush().undo() + editor.flush() + editor.undo() } export const input = ( From 2228958ae52621f3456a191c023c5046b0ec9793 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sat, 8 Jun 2019 09:27:30 -0700 Subject: [PATCH 011/165] simplify commands, queries and middleware --- packages/slate-react-placeholder/src/index.js | 11 +- packages/slate-react/src/components/editor.js | 62 +- .../slate-react/src/plugins/android/index.js | 36 +- .../src/plugins/debug/debug-batch-events.js | 4 +- .../src/plugins/debug/debug-events.js | 4 +- packages/slate-react/src/plugins/dom/after.js | 81 +-- .../slate-react/src/plugins/dom/before.js | 76 +-- .../slate-react/src/plugins/react/commands.js | 12 +- .../slate-react/src/plugins/react/queries.js | 38 +- .../src/plugins/react/rendering.js | 16 +- .../src/plugins/react/restore-dom.js | 22 +- .../editor/has-command/existing-plugin.js | 21 - .../editor/has-command/missing-plugin.js | 21 - .../editor/has-query/missing-plugin.js | 21 - .../core-query.js => has/core-exists.js} | 2 +- .../custom-exists.js} | 6 +- .../core-command.js => has/custom-missing.js} | 4 +- packages/slate/src/commands/at-range.js | 118 +--- packages/slate/src/commands/by-path.js | 93 ++- packages/slate/src/commands/on-history.js | 32 +- packages/slate/src/commands/on-selection.js | 643 +++++------------- packages/slate/src/commands/on-value.js | 9 +- packages/slate/src/commands/with-intent.js | 81 +-- packages/slate/src/controllers/editor.js | 340 ++++----- packages/slate/src/interfaces/element.js | 2 +- packages/slate/src/interfaces/node.js | 4 +- .../slate/src/plugins/core/core-commands.js | 7 +- .../slate/src/plugins/core/core-queries.js | 38 +- packages/slate/src/plugins/schema/index.js | 38 +- .../empty-after-multiple-void-blocks.js | 11 +- .../with-plugin-normalization.js | 6 +- .../general/call/call-with-arguments.js | 34 - .../editor/has-command/existing-plugin.js | 19 - .../editor/has-command/existing-registered.js | 13 - .../editor/has-command/missing-registered.js | 13 - .../editor/has-query/existing-registered.js | 13 - .../editor/has-query/missing-plugin.js | 19 - .../editor/has-query/missing-registered.js | 13 - .../existing-plugin.js => has/exists.js} | 6 +- .../missing-plugin.js => has/missing.js} | 0 40 files changed, 645 insertions(+), 1344 deletions(-) delete mode 100644 packages/slate-react/test/components/editor/has-command/existing-plugin.js delete mode 100644 packages/slate-react/test/components/editor/has-command/missing-plugin.js delete mode 100644 packages/slate-react/test/components/editor/has-query/missing-plugin.js rename packages/slate-react/test/components/editor/{has-query/core-query.js => has/core-exists.js} (85%) rename packages/slate-react/test/components/editor/{has-query/existing-plugin.js => has/custom-exists.js} (72%) rename packages/slate-react/test/components/editor/{has-command/core-command.js => has/custom-missing.js} (72%) delete mode 100644 packages/slate/test/commands/general/call/call-with-arguments.js delete mode 100644 packages/slate/test/controllers/editor/has-command/existing-plugin.js delete mode 100644 packages/slate/test/controllers/editor/has-command/existing-registered.js delete mode 100644 packages/slate/test/controllers/editor/has-command/missing-registered.js delete mode 100644 packages/slate/test/controllers/editor/has-query/existing-registered.js delete mode 100644 packages/slate/test/controllers/editor/has-query/missing-plugin.js delete mode 100644 packages/slate/test/controllers/editor/has-query/missing-registered.js rename packages/slate/test/controllers/editor/{has-query/existing-plugin.js => has/exists.js} (67%) rename packages/slate/test/controllers/editor/{has-command/missing-plugin.js => has/missing.js} (100%) diff --git a/packages/slate-react-placeholder/src/index.js b/packages/slate-react-placeholder/src/index.js index 0a04583fd3..eec608cf77 100644 --- a/packages/slate-react-placeholder/src/index.js +++ b/packages/slate-react-placeholder/src/index.js @@ -37,12 +37,13 @@ function SlateReactPlaceholder(options = {}) { * @return {Array} */ - function decorateNode(node, editor, next) { + const decorateNode = (fn, editor) => node => { + const others = fn(node) + if (!editor.query(when, node)) { - return next() + return others } - const others = next() const [first] = node.texts() const [last] = node.texts({ direction: 'backward' }) const [firstNode, firstPath] = first @@ -70,7 +71,7 @@ function SlateReactPlaceholder(options = {}) { * @return {Element} */ - function renderMark(props, editor, next) { + const renderMark = (fn, editor) => props => { const { children, mark } = props if (mark.type === 'placeholder' && mark.data.get('key') === instanceId) { @@ -94,7 +95,7 @@ function SlateReactPlaceholder(options = {}) { ) } - return next() + return fn(props) } /** diff --git a/packages/slate-react/src/components/editor.js b/packages/slate-react/src/components/editor.js index 5988de7e9b..fc610930bf 100644 --- a/packages/slate-react/src/components/editor.js +++ b/packages/slate-react/src/components/editor.js @@ -174,7 +174,7 @@ class Editor extends React.Component { contentKey={contentKey} editor={this} id={id} - onEvent={(handler, event) => this.run(handler, event)} + onEvent={(handler, event) => this.exec(handler, event)} readOnly={readOnly} role={role} spellCheck={spellCheck} @@ -185,7 +185,7 @@ class Editor extends React.Component { ) // Render the editor's children with the controller. - const element = this.controller.run('renderEditor', { + const element = this.controller.exec('renderEditor', { ...this.props, editor: this, children, @@ -235,7 +235,7 @@ class Editor extends React.Component { { controller: this, construct: false } ) - this.controller.run('onConstruct') + this.controller.exec('onConstruct') } ) @@ -272,38 +272,18 @@ class Editor extends React.Component { return this.controller.applyOperation(...args) } - command(...args) { - return this.controller.command(...args) + exec(...args) { + return this.controller.exec(...args) } - hasCommand(...args) { - return this.controller.hasCommand(...args) - } - - hasQuery(...args) { - return this.controller.hasQuery(...args) + has(...args) { + return this.controller.has(...args) } normalize(...args) { return this.controller.normalize(...args) } - query(...args) { - return this.controller.query(...args) - } - - registerCommand(...args) { - return this.controller.registerCommand(...args) - } - - registerQuery(...args) { - return this.controller.registerQuery(...args) - } - - run(...args) { - return this.controller.run(...args) - } - withoutNormalizing(...args) { return this.controller.withoutNormalizing(...args) } @@ -361,6 +341,34 @@ class Editor extends React.Component { withoutNormalization(...args) { return this.controller.withoutNormalization(...args) } + + query(...args) { + return this.controller.query(...args) + } + + registerCommand(...args) { + return this.controller.registerCommand(...args) + } + + registerQuery(...args) { + return this.controller.registerQuery(...args) + } + + run(...args) { + return this.controller.run(...args) + } + + command(...args) { + return this.controller.command(...args) + } + + hasCommand(...args) { + return this.controller.hasCommand(...args) + } + + hasQuery(...args) { + return this.controller.hasQuery(...args) + } } /** diff --git a/packages/slate-react/src/plugins/android/index.js b/packages/slate-react/src/plugins/android/index.js index 8372e6ed78..4167430b6e 100644 --- a/packages/slate-react/src/plugins/android/index.js +++ b/packages/slate-react/src/plugins/android/index.js @@ -152,11 +152,9 @@ function AndroidPlugin() { * not necessarily mean that the React version is cancelled. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ - function onBeforeInput(event, editor, next) { + const onBeforeInput = (fn, editor) => event => { const isNative = !event.nativeEvent debug('onBeforeInput', { @@ -241,7 +239,7 @@ function AndroidPlugin() { break default: - if (status !== COMPOSING) next() + if (status !== COMPOSING) fn(event) } } @@ -254,11 +252,9 @@ function AndroidPlugin() { * Instead, we want the `delete` to take precedence. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ - function onCompositionEnd(event, editor, next) { + const onCompositionEnd = (fn, editor) => event => { debug('onCompositionEnd', { event }) const window = getWindow(event.target) const domSelection = window.getSelection() @@ -292,11 +288,9 @@ function AndroidPlugin() { * On composition start. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ - function onCompositionStart(event, editor, next) { + const onCompositionStart = (fn, editor) => event => { debug('onCompositionStart', { event }) status = COMPOSING nodes.clear() @@ -306,11 +300,9 @@ function AndroidPlugin() { * On composition update. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ - function onCompositionUpdate(event, editor, next) { + const onCompositionUpdate = (fn, editor) => event => { debug('onCompositionUpdate', { event }) } @@ -318,11 +310,9 @@ function AndroidPlugin() { * On input. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ - function onInput(event, editor, next) { + const onInput = (fn, editor) => event => { debug('onInput', { event, status, @@ -435,7 +425,7 @@ function AndroidPlugin() { break default: if (status === COMPOSING) return - next() + fn(event) } } @@ -443,11 +433,9 @@ function AndroidPlugin() { * On key down. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ - function onKeyDown(event, editor, next) { + const onKeyDown = (fn, editor) => event => { debug('onKeyDown', { event, status, @@ -486,7 +474,7 @@ function AndroidPlugin() { // const window = getWindow(event.target) // const selection = window.getSelection() // setSelectionFromDom(window, editor, selection) - next() + fn(event) } break @@ -566,7 +554,7 @@ function AndroidPlugin() { default: if (status !== COMPOSING) { - next() + fn(event) } } } @@ -575,11 +563,9 @@ function AndroidPlugin() { * On select. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ - function onSelect(event, editor, next) { + const onSelect = (fn, editor) => event => { debug('onSelect', { event, status }) switch (ANDROID_API_VERSION) { diff --git a/packages/slate-react/src/plugins/debug/debug-batch-events.js b/packages/slate-react/src/plugins/debug/debug-batch-events.js index d9f9df8490..dbcc622f88 100644 --- a/packages/slate-react/src/plugins/debug/debug-batch-events.js +++ b/packages/slate-react/src/plugins/debug/debug-batch-events.js @@ -87,9 +87,9 @@ function DebugBatchEventsPlugin() { const plugin = {} for (const eventName of EVENT_HANDLERS) { - plugin[eventName] = function(event, editor, next) { + plugin[eventName] = (fn, editor) => event => { pushEvent(event) - next() + fn(event) } } diff --git a/packages/slate-react/src/plugins/debug/debug-events.js b/packages/slate-react/src/plugins/debug/debug-events.js index 6eb00f0de9..18f663dcb4 100644 --- a/packages/slate-react/src/plugins/debug/debug-events.js +++ b/packages/slate-react/src/plugins/debug/debug-events.js @@ -27,10 +27,10 @@ function DebugEventsPlugin() { const plugin = {} for (const eventName of EVENT_HANDLERS) { - plugin[eventName] = function(event, editor, next) { + plugin[eventName] = (fn, editor) => event => { const s = stringifyEvent(event) debug(s) - next() + fn(event) } } diff --git a/packages/slate-react/src/plugins/dom/after.js b/packages/slate-react/src/plugins/dom/after.js index 8eb86536ef..2b82044216 100644 --- a/packages/slate-react/src/plugins/dom/after.js +++ b/packages/slate-react/src/plugins/dom/after.js @@ -36,7 +36,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onBeforeInput(event, editor, next) { + const onBeforeInput = (fn, editor) => event => { const { value } = editor const isSynthetic = !!event.nativeEvent @@ -46,13 +46,16 @@ function AfterPlugin(options = {}) { if (isSynthetic) { event.preventDefault() editor.insertText(event.data) - return next() + return fn(event) } // Otherwise, we can use the information in the `beforeinput` event to // figure out the exact change that will occur, and prevent it. const [targetRange] = event.getTargetRanges() - if (!targetRange) return next() + + if (!targetRange) { + return fn(event) + } debug('onBeforeInput', { event }) @@ -135,7 +138,7 @@ function AfterPlugin(options = {}) { } } - next() + fn(event) } /** @@ -146,10 +149,10 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onBlur(event, editor, next) { + const onBlur = (fn, editor) => event => { debug('onBlur', { event }) editor.blur() - next() + fn(event) } /** @@ -160,13 +163,13 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onClick(event, editor, next) { - if (editor.readOnly) return next() + const onClick = (fn, editor) => event => { + if (editor.readOnly) return fn(event) const { value } = editor const { document } = value const path = editor.findPath(event.target) - if (!path) return next() + if (!path) return fn(event) debug('onClick', { event }) @@ -183,7 +186,7 @@ function AfterPlugin(options = {}) { editor.focus().moveToEndOfNode(node) } - next() + fn(event) } /** @@ -194,10 +197,10 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onCopy(event, editor, next) { + const onCopy = (fn, editor) => event => { debug('onCopy', { event }) cloneFragment(event, editor) - next() + fn(event) } /** @@ -208,7 +211,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onCut(event, editor, next) { + const onCut = (fn, editor) => event => { debug('onCut', { event }) // Once the fake cut content has successfully been added to the clipboard, @@ -237,7 +240,7 @@ function AfterPlugin(options = {}) { } }) - next() + fn(event) } /** @@ -248,10 +251,10 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onDragEnd(event, editor, next) { + const onDragEnd = (fn, editor) => event => { debug('onDragEnd', { event }) isDraggingInternally = null - next() + fn(event) } /** @@ -262,7 +265,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onDragStart(event, editor, next) { + const onDragStart = (fn, editor) => event => { debug('onDragStart', { event }) isDraggingInternally = true @@ -284,7 +287,7 @@ function AfterPlugin(options = {}) { const fragment = editor.value.fragment const encoded = Base64.serializeNode(fragment) setEventTransfer(event, 'fragment', encoded) - next() + fn(event) } /** @@ -295,14 +298,14 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onDrop(event, editor, next) { + const onDrop = (fn, editor) => event => { const { value } = editor const { document, selection } = value const window = getWindow(event.target) let target = editor.findEventRange(event) if (!target) { - return next() + return fn(event) } debug('onDrop', { event }) @@ -338,7 +341,6 @@ function AfterPlugin(options = {}) { if (hasVoidParent) { let p = anchor.path - let n = document.getNode(anchor.path) while (hasVoidParent) { const [nxt] = document.texts({ path: p }) @@ -347,7 +349,7 @@ function AfterPlugin(options = {}) { break } - ;[n, p] = nxt + ;[, p] = nxt hasVoidParent = document.hasVoidParent(p, editor) } @@ -384,7 +386,7 @@ function AfterPlugin(options = {}) { ) } - next() + fn(event) } /** @@ -395,7 +397,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onFocus(event, editor, next) { + const onFocus = (fn, editor) => event => { debug('onFocus', { event }) // COMPAT: If the focus event is a mouse-based one, it will be shortly @@ -408,7 +410,7 @@ function AfterPlugin(options = {}) { editor.focus() } - next() + fn(event) } /** @@ -419,7 +421,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onInput(event, editor, next) { + const onInput = (fn, editor) => event => { debug('onInput') const window = getWindow(event.target) @@ -434,8 +436,7 @@ function AfterPlugin(options = {}) { const { anchorNode } = domSelection editor.reconcileDOMNode(anchorNode) - - next() + fn(event) } /** @@ -446,7 +447,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onKeyDown(event, editor, next) { + const onKeyDown = (fn, editor) => event => { debug('onKeyDown', { event }) const { value } = editor @@ -587,7 +588,7 @@ function AfterPlugin(options = {}) { } } - next() + fn(event) } /** @@ -598,10 +599,10 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onMouseDown(event, editor, next) { + const onMouseDown = (fn, editor) => event => { debug('onMouseDown', { event }) isMouseDown = true - next() + fn(event) } /** @@ -612,10 +613,10 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onMouseUp(event, editor, next) { + const onMouseUp = (fn, editor) => event => { debug('onMouseUp', { event }) isMouseDown = false - next() + fn(event) } /** @@ -626,7 +627,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onPaste(event, editor, next) { + const onPaste = (fn, editor) => event => { debug('onPaste', { event }) const { value } = editor @@ -638,9 +639,9 @@ function AfterPlugin(options = {}) { } if (type === 'text' || type === 'html') { - if (!text) return next() + if (!text) return fn(event) const { document, selection, startBlock } = value - if (editor.isVoid(startBlock)) return next() + if (editor.isVoid(startBlock)) return fn(event) const defaultBlock = startBlock const defaultMarks = document.getInsertMarksAtRange(selection) @@ -649,7 +650,7 @@ function AfterPlugin(options = {}) { editor.insertFragment(frag) } - next() + fn(event) } /** @@ -660,7 +661,7 @@ function AfterPlugin(options = {}) { * @param {Function} next */ - function onSelect(event, editor, next) { + const onSelect = (fn, editor) => event => { debug('onSelect', { event }) const window = getWindow(event.target) const domSelection = window.getSelection() @@ -676,7 +677,7 @@ function AfterPlugin(options = {}) { // happens outside the editor. This is needed for `onFocus` handling. isMouseDown = false - next() + fn(event) } /** diff --git a/packages/slate-react/src/plugins/dom/before.js b/packages/slate-react/src/plugins/dom/before.js index 86c85752b1..cb72d3fccb 100644 --- a/packages/slate-react/src/plugins/dom/before.js +++ b/packages/slate-react/src/plugins/dom/before.js @@ -39,7 +39,7 @@ function BeforePlugin() { * @param {Function} next */ - function onBeforeInput(event, editor, next) { + const onBeforeInput = (fn, editor) => event => { const isSynthetic = !!event.nativeEvent if (editor.readOnly) return @@ -49,7 +49,7 @@ function BeforePlugin() { if (isSynthetic && HAS_INPUT_EVENTS_LEVEL_2) return debug('onBeforeInput', { event }) - next() + fn(event) } /** @@ -60,7 +60,7 @@ function BeforePlugin() { * @param {Function} next */ - function onBlur(event, editor, next) { + const onBlur = (fn, editor) => event => { if (isCopying) return if (editor.readOnly) return @@ -98,7 +98,7 @@ function BeforePlugin() { } debug('onBlur', { event }) - next() + fn(event) } /** @@ -109,7 +109,7 @@ function BeforePlugin() { * @param {Function} next */ - function onCompositionEnd(event, editor, next) { + const onCompositionEnd = (fn, editor) => event => { const n = compositionCount // The `count` check here ensures that if another composition starts @@ -121,7 +121,7 @@ function BeforePlugin() { }) debug('onCompositionEnd', { event }) - next() + fn(event) } /** @@ -132,9 +132,9 @@ function BeforePlugin() { * @param {Function} next */ - function onClick(event, editor, next) { + const onClick = (fn, editor) => event => { debug('onClick', { event }) - next() + fn(event) } /** @@ -145,7 +145,7 @@ function BeforePlugin() { * @param {Function} next */ - function onCompositionStart(event, editor, next) { + const onCompositionStart = (fn, editor) => event => { isComposing = true compositionCount++ @@ -164,7 +164,7 @@ function BeforePlugin() { } debug('onCompositionStart', { event }) - next() + fn(event) } /** @@ -175,13 +175,13 @@ function BeforePlugin() { * @param {Function} next */ - function onCopy(event, editor, next) { + const onCopy = (fn, editor) => event => { const window = getWindow(event.target) isCopying = true window.requestAnimationFrame(() => (isCopying = false)) debug('onCopy', { event }) - next() + fn(event) } /** @@ -192,7 +192,7 @@ function BeforePlugin() { * @param {Function} next */ - function onCut(event, editor, next) { + const onCut = (fn, editor) => event => { if (editor.readOnly) return const window = getWindow(event.target) @@ -200,7 +200,7 @@ function BeforePlugin() { window.requestAnimationFrame(() => (isCopying = false)) debug('onCut', { event }) - next() + fn(event) } /** @@ -211,10 +211,10 @@ function BeforePlugin() { * @param {Function} next */ - function onDragEnd(event, editor, next) { + const onDragEnd = (fn, editor) => event => { isDragging = false debug('onDragEnd', { event }) - next() + fn(event) } /** @@ -225,9 +225,9 @@ function BeforePlugin() { * @param {Function} next */ - function onDragEnter(event, editor, next) { + const onDragEnter = (fn, editor) => event => { debug('onDragEnter', { event }) - next() + fn(event) } /** @@ -238,9 +238,9 @@ function BeforePlugin() { * @param {Function} next */ - function onDragExit(event, editor, next) { + const onDragExit = (fn, editor) => event => { debug('onDragExit', { event }) - next() + fn(event) } /** @@ -251,9 +251,9 @@ function BeforePlugin() { * @param {Function} next */ - function onDragLeave(event, editor, next) { + const onDragLeave = (fn, editor) => event => { debug('onDragLeave', { event }) - next() + fn(event) } /** @@ -264,7 +264,7 @@ function BeforePlugin() { * @param {Function} next */ - function onDragOver(event, editor, next) { + const onDragOver = (fn, editor) => event => { // If the target is inside a void node, and only in this case, // call `preventDefault` to signal that drops are allowed. // When the target is editable, dropping is already allowed by @@ -295,7 +295,7 @@ function BeforePlugin() { } debug('onDragOver', { event }) - next() + fn(event) } /** @@ -306,10 +306,10 @@ function BeforePlugin() { * @param {Function} next */ - function onDragStart(event, editor, next) { + const onDragStart = (fn, editor) => event => { isDragging = true debug('onDragStart', { event }) - next() + fn(event) } /** @@ -320,14 +320,14 @@ function BeforePlugin() { * @param {Function} next */ - function onDrop(event, editor, next) { + const onDrop = (fn, editor) => event => { if (editor.readOnly) return // Prevent default so the DOM's value isn't corrupted. event.preventDefault() debug('onDrop', { event }) - next() + fn(event) } /** @@ -338,7 +338,7 @@ function BeforePlugin() { * @param {Function} next */ - function onFocus(event, editor, next) { + const onFocus = (fn, editor) => event => { if (isCopying) return if (editor.readOnly) return @@ -357,7 +357,7 @@ function BeforePlugin() { } debug('onFocus', { event }) - next() + fn(event) } /** @@ -368,11 +368,11 @@ function BeforePlugin() { * @param {Function} next */ - function onInput(event, editor, next) { + const onInput = (fn, editor) => event => { if (isComposing) return if (editor.value.selection.isBlurred) return debug('onInput', { event }) - next() + fn(event) } /** @@ -383,7 +383,7 @@ function BeforePlugin() { * @param {Function} next */ - function onKeyDown(event, editor, next) { + const onKeyDown = (fn, editor) => event => { if (editor.readOnly) return // When composing, we need to prevent all hotkeys from executing while @@ -416,7 +416,7 @@ function BeforePlugin() { } debug('onKeyDown', { event }) - next() + fn(event) } /** @@ -427,14 +427,14 @@ function BeforePlugin() { * @param {Function} next */ - function onPaste(event, editor, next) { + const onPaste = (fn, editor) => event => { if (editor.readOnly) return // Prevent defaults so the DOM state isn't corrupted. event.preventDefault() debug('onPaste', { event }) - next() + fn(event) } /** @@ -445,7 +445,7 @@ function BeforePlugin() { * @param {Function} next */ - function onSelect(event, editor, next) { + const onSelect = (fn, editor) => event => { if (isCopying) return if (isComposing) return @@ -456,7 +456,7 @@ function BeforePlugin() { activeElement = window.document.activeElement debug('onSelect', { event }) - next() + fn(event) } /** diff --git a/packages/slate-react/src/plugins/react/commands.js b/packages/slate-react/src/plugins/react/commands.js index ca0249fb00..9d5ad4798c 100644 --- a/packages/slate-react/src/plugins/react/commands.js +++ b/packages/slate-react/src/plugins/react/commands.js @@ -9,11 +9,10 @@ function CommandsPlugin() { * Takes a `node`, find the matching `domNode` and uses it to set the text * in the `node`. * - * @param {Editor} editor * @param {Node} node */ - function reconcileNode(editor, node) { + const reconcileNode = (fn, editor) => node => { const { value } = editor const { document, selection } = value const path = document.getPath(node.key) @@ -51,21 +50,18 @@ function CommandsPlugin() { * Takes text from the `domNode` and uses it to set the text in the matching * `node` in Slate. * - * @param {Editor} editor * @param {DOMNode} domNode */ - function reconcileDOMNode(editor, domNode) { + const reconcileDOMNode = (fn, editor) => domNode => { const domElement = domNode.parentElement.closest('[data-key]') const node = editor.findNode(domElement) editor.reconcileNode(node) } return { - commands: { - reconcileNode, - reconcileDOMNode, - }, + reconcileNode, + reconcileDOMNode, } } diff --git a/packages/slate-react/src/plugins/react/queries.js b/packages/slate-react/src/plugins/react/queries.js index acd3ff1b70..0a3c681a1c 100644 --- a/packages/slate-react/src/plugins/react/queries.js +++ b/packages/slate-react/src/plugins/react/queries.js @@ -19,7 +19,7 @@ function QueriesPlugin() { * @return {DOMNode|Null} */ - function findDOMNode(editor, path) { + const findDOMNode = (fn, editor) => path => { path = PathUtils.create(path) const content = editor.tmp.contentRef.current @@ -63,7 +63,7 @@ function QueriesPlugin() { * @return {Object|Null} */ - function findDOMPoint(editor, point) { + const findDOMPoint = (fn, editor) => point => { const el = editor.findDOMNode(point.path) let start = 0 @@ -108,7 +108,7 @@ function QueriesPlugin() { * @return {DOMRange|Null} */ - function findDOMRange(editor, range) { + const findDOMRange = (fn, editor) => range => { const { anchor, focus, isBackward, isCollapsed } = range const domAnchor = editor.findDOMPoint(anchor) const domFocus = isCollapsed ? domAnchor : editor.findDOMPoint(focus) @@ -134,7 +134,7 @@ function QueriesPlugin() { * @return {List|Null} */ - function findNode(editor, element) { + const findNode = (fn, editor) => element => { const path = editor.findPath(element) if (!path) { @@ -155,7 +155,7 @@ function QueriesPlugin() { * @return {Range} */ - function findEventRange(editor, event) { + const findEventRange = (fn, editor) => event => { if (event.nativeEvent) { event = event.nativeEvent } @@ -232,7 +232,7 @@ function QueriesPlugin() { * @return {List|Null} */ - function findPath(editor, element) { + const findPath = (fn, editor) => element => { const content = editor.tmp.contentRef.current let nodeElement = element @@ -303,7 +303,7 @@ function QueriesPlugin() { * @return {Point} */ - function findPoint(editor, nativeNode, nativeOffset) { + const findPoint = (fn, editor) => (nativeNode, nativeOffset) => { const { node: nearestNode, offset: nearestOffset } = normalizeNodeAndOffset( nativeNode, nativeOffset @@ -390,7 +390,7 @@ function QueriesPlugin() { * @return {Range} */ - function findRange(editor, domRange) { + const findRange = (fn, editor) => domRange => { const el = domRange.anchorNode || domRange.startContainer if (!el) { @@ -447,7 +447,7 @@ function QueriesPlugin() { * @return {Range} */ - function findSelection(editor, domSelection) { + const findSelection = (fn, editor) => domSelection => { const { value } = editor const { document } = value @@ -540,17 +540,15 @@ function QueriesPlugin() { } return { - queries: { - findDOMNode, - findDOMPoint, - findDOMRange, - findEventRange, - findNode, - findPath, - findPoint, - findRange, - findSelection, - }, + findDOMNode, + findDOMPoint, + findDOMRange, + findEventRange, + findNode, + findPath, + findPoint, + findRange, + findSelection, } } diff --git a/packages/slate-react/src/plugins/react/rendering.js b/packages/slate-react/src/plugins/react/rendering.js index 096d7b6e35..90277a1b72 100644 --- a/packages/slate-react/src/plugins/react/rendering.js +++ b/packages/slate-react/src/plugins/react/rendering.js @@ -8,15 +8,15 @@ import React from 'react' function Rendering() { return { - decorateNode() { + decorateNode: () => () => { return [] }, - renderAnnotation({ attributes, children }) { + renderAnnotation: () => ({ attributes, children }) => { return {children} }, - renderBlock({ attributes, children }) { + renderBlock: () => ({ attributes, children }) => { return (
{children} @@ -24,19 +24,19 @@ function Rendering() { ) }, - renderDecoration({ attributes, children }) { + renderDecoration: () => ({ attributes, children }) => { return {children} }, - renderDocument({ children }) { + renderDocument: () => ({ children }) => { return children }, - renderEditor({ children }) { + renderEditor: () => ({ children }) => { return children }, - renderInline({ attributes, children }) { + renderInline: () => ({ attributes, children }) => { return ( {children} @@ -44,7 +44,7 @@ function Rendering() { ) }, - renderMark({ attributes, children }) { + renderMark: () => ({ attributes, children }) => { return {children} }, } diff --git a/packages/slate-react/src/plugins/react/restore-dom.js b/packages/slate-react/src/plugins/react/restore-dom.js index c40a9c521f..96d90e8f17 100644 --- a/packages/slate-react/src/plugins/react/restore-dom.js +++ b/packages/slate-react/src/plugins/react/restore-dom.js @@ -1,19 +1,13 @@ -function RestoreDOMPlugin() { - /** - * Makes sure that on the next Content `render` the DOM is restored. - * This gets us around issues where the DOM is in a different state than - * React's virtual DOM and would crash. - * - * @param {Editor} editor - */ - - function restoreDOM(editor) { - editor.setState({ contentKey: editor.state.contentKey + 1 }) - } +/** + * Makes sure that on the next Content `render` the DOM is restored. + * This gets us around issues where the DOM is in a different state than + * React's virtual DOM and would crash. + */ +function RestoreDOMPlugin() { return { - commands: { - restoreDOM, + restoreDOM: (fn, editor) => () => { + editor.setState({ contentKey: editor.state.contentKey + 1 }) }, } } diff --git a/packages/slate-react/test/components/editor/has-command/existing-plugin.js b/packages/slate-react/test/components/editor/has-command/existing-plugin.js deleted file mode 100644 index ddae7417b2..0000000000 --- a/packages/slate-react/test/components/editor/has-command/existing-plugin.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import Plain from 'slate-plain-serializer' - -const defaultValue = Plain.deserialize('') - -const plugins = [ - { - commands: { - customCommand: () => {}, - }, - }, -] - -export const input = { defaultValue, plugins } - -export default function(editor) { - return editor.hasCommand('customCommand') -} - -export const output = true diff --git a/packages/slate-react/test/components/editor/has-command/missing-plugin.js b/packages/slate-react/test/components/editor/has-command/missing-plugin.js deleted file mode 100644 index 9ec7db1c13..0000000000 --- a/packages/slate-react/test/components/editor/has-command/missing-plugin.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import Plain from 'slate-plain-serializer' - -const defaultValue = Plain.deserialize('') - -const plugins = [ - { - commands: { - customCommand: () => {}, - }, - }, -] - -export const input = { defaultValue, plugins } - -export default function(editor) { - return editor.hasCommand('otherCommand') -} - -export const output = false diff --git a/packages/slate-react/test/components/editor/has-query/missing-plugin.js b/packages/slate-react/test/components/editor/has-query/missing-plugin.js deleted file mode 100644 index 74201da9e3..0000000000 --- a/packages/slate-react/test/components/editor/has-query/missing-plugin.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import Plain from 'slate-plain-serializer' - -const defaultValue = Plain.deserialize('') - -const plugins = [ - { - queries: { - customQuery: () => {}, - }, - }, -] - -export const input = { defaultValue, plugins } - -export default function(editor) { - return editor.hasQuery('otherQuery') -} - -export const output = false diff --git a/packages/slate-react/test/components/editor/has-query/core-query.js b/packages/slate-react/test/components/editor/has/core-exists.js similarity index 85% rename from packages/slate-react/test/components/editor/has-query/core-query.js rename to packages/slate-react/test/components/editor/has/core-exists.js index 704be8a093..896fa233f0 100644 --- a/packages/slate-react/test/components/editor/has-query/core-query.js +++ b/packages/slate-react/test/components/editor/has/core-exists.js @@ -7,7 +7,7 @@ const defaultValue = Plain.deserialize('') export const input = { defaultValue } export default function(editor) { - return editor.hasQuery('isVoid') + return editor.has('insertText') } export const output = true diff --git a/packages/slate-react/test/components/editor/has-query/existing-plugin.js b/packages/slate-react/test/components/editor/has/custom-exists.js similarity index 72% rename from packages/slate-react/test/components/editor/has-query/existing-plugin.js rename to packages/slate-react/test/components/editor/has/custom-exists.js index 7e7d57d32e..7aec9ad28f 100644 --- a/packages/slate-react/test/components/editor/has-query/existing-plugin.js +++ b/packages/slate-react/test/components/editor/has/custom-exists.js @@ -6,16 +6,14 @@ const defaultValue = Plain.deserialize('') const plugins = [ { - queries: { - customQuery: () => {}, - }, + customCommand: () => {}, }, ] export const input = { defaultValue, plugins } export default function(editor) { - return editor.hasQuery('customQuery') + return editor.has('customCommand') } export const output = true diff --git a/packages/slate-react/test/components/editor/has-command/core-command.js b/packages/slate-react/test/components/editor/has/custom-missing.js similarity index 72% rename from packages/slate-react/test/components/editor/has-command/core-command.js rename to packages/slate-react/test/components/editor/has/custom-missing.js index e06349804b..def2ed71c6 100644 --- a/packages/slate-react/test/components/editor/has-command/core-command.js +++ b/packages/slate-react/test/components/editor/has/custom-missing.js @@ -7,7 +7,7 @@ const defaultValue = Plain.deserialize('') export const input = { defaultValue } export default function(editor) { - return editor.hasCommand('insertText') + return editor.has('unknownCommand') } -export const output = true +export const output = false diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 255b61cf0e..d82537b1b7 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -29,45 +29,6 @@ function deleteExpandedAtRange(editor, range) { return range } -/** - * Ensure that the edges of a range are split such that they are at the edge of - * all of the inline and text nodes they are in. This will split inline nodes - * and text nodes and update the range to be inside the split. - * - * @param {Editor} - */ - -function splitInlinesAtRange(editor, range) { - if (range.isExpanded) { - editor.deleteAtRange(range) - } - - const { value: { document } } = editor - const start = editor.getPreviousNonVoidPoint(range.start) - const startText = document.getNode(start.path) - const startInline = document.furthestInline(start.path) - const end = editor.getNextNonVoidPoint(range.end) - const endText = document.getNode(end.path) - const endInline = document.furthestInline(end.path) - - if (end.offset !== 0 && end.offset !== endText.text.length) { - editor.splitNodeByPath(end.path, end.offset) - } - - if (start.offset !== 0 && start.offset !== startText.text.length) { - editor.splitNodeByPath(start.path, start.offset) - - const newStart = start - .setPath(PathUtils.increment(start.path)) - .setOffset(0) - .normalize(document) - - range = range.setStart(newStart) - } - - return range -} - /** * Commands. * @@ -79,12 +40,11 @@ const Commands = {} /** * Add a new `mark` to the characters at `range`. * - * @param {Editor} editor * @param {Range} range * @param {Mixed} mark */ -Commands.addMarkAtRange = (editor, range, mark) => { +Commands.addMarkAtRange = (fn, editor) => (range, mark) => { if (range.isCollapsed) { return } @@ -118,23 +78,21 @@ Commands.addMarkAtRange = (editor, range, mark) => { /** * Add a list of `marks` to the characters at `range`. * - * @param {Editor} editor * @param {Range} range * @param {Array} mark */ -Commands.addMarksAtRange = (editor, range, marks) => { +Commands.addMarksAtRange = (fn, editor) => (range, marks) => { marks.forEach(mark => editor.addMarkAtRange(range, mark)) } /** * Delete everything in a `range`. * - * @param {Editor} editor * @param {Range} range */ -Commands.deleteAtRange = (editor, range) => { +Commands.deleteAtRange = (fn, editor) => range => { // Snapshot the selection, which creates an extra undo save point, so that // when you undo a delete, the expanded selection will be retained. editor.snapshotSelection() @@ -333,12 +291,11 @@ Commands.deleteAtRange = (editor, range) => { /** * Delete backward `n` characters at a `range`. * - * @param {Editor} editor * @param {Range} range * @param {Number} n (optional) */ -Commands.deleteBackwardAtRange = (editor, range, n = 1) => { +Commands.deleteBackwardAtRange = (fn, editor) => (range, n = 1) => { if (range.isExpanded) { editor.deleteAtRange(range) return @@ -443,11 +400,10 @@ Commands.deleteBackwardAtRange = (editor, range, n = 1) => { /** * Delete backward until the character boundary at a `range`. * - * @param {Editor} editor * @param {Range} range */ -Commands.deleteCharBackwardAtRange = (editor, range) => { +Commands.deleteCharBackwardAtRange = (fn, editor) => range => { if (range.isExpanded) { editor.deleteAtRange(range) } else { @@ -463,11 +419,10 @@ Commands.deleteCharBackwardAtRange = (editor, range) => { /** * Delete forward until the character boundary at a `range`. * - * @param {Editor} editor * @param {Range} range */ -Commands.deleteCharForwardAtRange = (editor, range) => { +Commands.deleteCharForwardAtRange = (fn, editor) => range => { if (range.isExpanded) { editor.deleteAtRange(range) } else { @@ -483,12 +438,11 @@ Commands.deleteCharForwardAtRange = (editor, range) => { /** * Delete forward `n` characters at a `range`. * - * @param {Editor} editor * @param {Range} range * @param {Number} n (optional) */ -Commands.deleteForwardAtRange = (editor, range, n = 1) => { +Commands.deleteForwardAtRange = (fn, editor) => (range, n = 1) => { if (range.isExpanded) { editor.deleteAtRange(range) return @@ -590,11 +544,10 @@ Commands.deleteForwardAtRange = (editor, range, n = 1) => { /** * Delete backward until the line boundary at a `range`. * - * @param {Editor} editor * @param {Range} range */ -Commands.deleteLineBackwardAtRange = (editor, range) => { +Commands.deleteLineBackwardAtRange = (fn, editor) => range => { if (range.isExpanded) { editor.deleteAtRange(range) return @@ -613,11 +566,10 @@ Commands.deleteLineBackwardAtRange = (editor, range) => { /** * Delete forward until the line boundary at a `range`. * - * @param {Editor} editor * @param {Range} range */ -Commands.deleteLineForwardAtRange = (editor, range) => { +Commands.deleteLineForwardAtRange = (fn, editor) => range => { if (range.isExpanded) { editor.deleteAtRange(range) return @@ -636,11 +588,10 @@ Commands.deleteLineForwardAtRange = (editor, range) => { /** * Delete backward until the word boundary at a `range`. * - * @param {Editor} editor * @param {Range} range */ -Commands.deleteWordBackwardAtRange = (editor, range) => { +Commands.deleteWordBackwardAtRange = (fn, editor) => range => { if (range.isExpanded) { editor.deleteAtRange(range) } else { @@ -656,11 +607,10 @@ Commands.deleteWordBackwardAtRange = (editor, range) => { /** * Delete forward until the word boundary at a `range`. * - * @param {Editor} editor * @param {Range} range */ -Commands.deleteWordForwardAtRange = (editor, range) => { +Commands.deleteWordForwardAtRange = (fn, editor) => range => { if (range.isExpanded) { editor.deleteAtRange(range) } else { @@ -676,12 +626,11 @@ Commands.deleteWordForwardAtRange = (editor, range) => { /** * Insert a `block` node at `range`. * - * @param {Editor} editor * @param {Range} range * @param {Block|String|Object} block */ -Commands.insertBlockAtRange = (editor, range, block) => { +Commands.insertBlockAtRange = (fn, editor) => (range, block) => { range = deleteExpandedAtRange(editor, range) block = Block.create(block) @@ -711,7 +660,6 @@ Commands.insertBlockAtRange = (editor, range, block) => { /** * Check if current block should be split or new block should be added before or behind it. * - * @param {Editor} editor * @param {Range} range */ @@ -740,12 +688,11 @@ const getInsertionMode = (editor, range) => { /** * Insert a `fragment` at a `range`. * - * @param {Editor} editor * @param {Range} range * @param {Document} fragment */ -Commands.insertFragmentAtRange = (editor, range, fragment) => { +Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { editor.withoutNormalizing(() => { range = deleteExpandedAtRange(editor, range) @@ -899,12 +846,11 @@ const findInsertionNode = (fragment, document, startKey) => { /** * Insert an `inline` node at `range`. * - * @param {Editor} editor * @param {Range} range * @param {Inline|String|Object} inline */ -Commands.insertInlineAtRange = (editor, range, inline) => { +Commands.insertInlineAtRange = (fn, editor) => (range, inline) => { editor.withoutNormalizing(() => { inline = Inline.create(inline) range = deleteExpandedAtRange(editor, range) @@ -926,13 +872,12 @@ Commands.insertInlineAtRange = (editor, range, inline) => { /** * Insert `text` at a `range`, with optional `marks`. * - * @param {Editor} editor * @param {Range} range * @param {String} text * @param {Set} marks (optional) */ -Commands.insertTextAtRange = (editor, range, text, marks) => { +Commands.insertTextAtRange = (fn, editor) => (range, text, marks) => { editor.withoutNormalizing(() => { range = deleteExpandedAtRange(editor, range) const { value: { document } } = editor @@ -950,12 +895,11 @@ Commands.insertTextAtRange = (editor, range, text, marks) => { /** * Remove an existing `mark` to the characters at `range`. * - * @param {Editor} editor * @param {Range} range * @param {Mark|String} mark (optional) */ -Commands.removeMarkAtRange = (editor, range, mark) => { +Commands.removeMarkAtRange = (fn, editor) => (range, mark) => { if (range.isCollapsed) { return } @@ -993,12 +937,11 @@ Commands.removeMarkAtRange = (editor, range, mark) => { /** * Set the `properties` of block nodes in a `range`. * - * @param {Editor} editor * @param {Range} range * @param {Object|String} properties */ -Commands.setBlocksAtRange = (editor, range, properties) => { +Commands.setBlocksAtRange = (fn, editor) => (range, properties) => { editor.withoutNormalizing(() => { const { value: { document } } = editor const iterable = document.blocks({ @@ -1016,12 +959,11 @@ Commands.setBlocksAtRange = (editor, range, properties) => { /** * Set the `properties` of inline nodes in a `range`. * - * @param {Editor} editor * @param {Range} range * @param {Object|String} properties */ -Commands.setInlinesAtRange = (editor, range, properties) => { +Commands.setInlinesAtRange = (fn, editor) => (range, properties) => { editor.withoutNormalizing(() => { const { value: { document } } = editor const iterable = document.inlines({ range, onlyLeaves: true }) @@ -1035,12 +977,11 @@ Commands.setInlinesAtRange = (editor, range, properties) => { /** * Split the block nodes at a `range`, to optional `height`. * - * @param {Editor} editor * @param {Range} range * @param {Number} height (optional) */ -Commands.splitBlockAtRange = (editor, range, height = 1) => { +Commands.splitBlockAtRange = (fn, editor) => (range, height = 1) => { editor.withoutNormalizing(() => { range = deleteExpandedAtRange(editor, range) const { start } = range @@ -1066,12 +1007,11 @@ Commands.splitBlockAtRange = (editor, range, height = 1) => { /** * Split the inline nodes at a `range`, to optional `height`. * - * @param {Editor} editor * @param {Range} range * @param {Number} height (optional) */ -Commands.splitInlineAtRange = (editor, range, height = Infinity) => { +Commands.splitInlineAtRange = (fn, editor) => (range, height = Infinity) => { editor.withoutNormalizing(() => { range = deleteExpandedAtRange(editor, range) const { start } = range @@ -1098,12 +1038,11 @@ Commands.splitInlineAtRange = (editor, range, height = Infinity) => { * Add or remove a `mark` from the characters at `range`, depending on whether * it's already there. * - * @param {Editor} editor * @param {Range} range * @param {Mixed} mark */ -Commands.toggleMarkAtRange = (editor, range, mark) => { +Commands.toggleMarkAtRange = (fn, editor) => (range, mark) => { if (range.isCollapsed) return mark = Mark.create(mark) @@ -1128,12 +1067,11 @@ Commands.toggleMarkAtRange = (editor, range, mark) => { * parent nodes in the range. I think we probably need to different concepts, * and then to allow each for blocks and inlines. * - * @param {Editor} editor * @param {Range} range * @param {String|Object} properties */ -Commands.unwrapBlockAtRange = (editor, range, properties) => { +Commands.unwrapBlockAtRange = (fn, editor) => (range, properties) => { editor.withoutNormalizing(() => { const { value: { document } } = editor const iterable = document.blocks({ @@ -1162,12 +1100,11 @@ Commands.unwrapBlockAtRange = (editor, range, properties) => { /** * Unwrap the inline nodes in a `range` from an inline with `properties`. * - * @param {Editor} editor * @param {Range} range * @param {String|Object} properties */ -Commands.unwrapInlineAtRange = (editor, range, properties) => { +Commands.unwrapInlineAtRange = (fn, editor) => (range, properties) => { editor.withoutNormalizing(() => { const { value: { document } } = editor const iterable = document.inlines({ @@ -1188,12 +1125,11 @@ Commands.unwrapInlineAtRange = (editor, range, properties) => { /** * Wrap all of the blocks in a `range` in a new `block`. * - * @param {Editor} editor * @param {Range} range * @param {Block|Object|String} block */ -Commands.wrapBlockAtRange = (editor, range, block) => { +Commands.wrapBlockAtRange = (fn, editor) => (range, block) => { block = Block.create(block) block = block.set('nodes', block.nodes.clear()) @@ -1222,12 +1158,11 @@ Commands.wrapBlockAtRange = (editor, range, block) => { /** * Wrap the text and inlines in a `range` in a new `inline`. * - * @param {Editor} editor * @param {Range} range * @param {Inline|Object|String} inline */ -Commands.wrapInlineAtRange = (editor, range, inline) => { +Commands.wrapInlineAtRange = (fn, editor) => (range, inline) => { inline = Inline.create(inline) inline = inline.set('nodes', inline.nodes.clear()) @@ -1339,13 +1274,12 @@ Commands.wrapInlineAtRange = (editor, range, inline) => { /** * Wrap the text in a `range` in a prefix/suffix. * - * @param {Editor} editor * @param {Range} range * @param {String} prefix * @param {String} suffix (optional) */ -Commands.wrapTextAtRange = (editor, range, prefix, suffix = prefix) => { +Commands.wrapTextAtRange = (fn, editor) => (range, prefix, suffix = prefix) => { const { start, end } = range const startRange = range.moveToStart() let endRange = range.moveToEnd() diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index dfed0c4472..bbe326d208 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -16,19 +16,18 @@ const Commands = {} /** * Add mark to text at `offset` and `length` in node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset * @param {Number} length * @param {Mixed} mark */ -Commands.addMarkByPath = (editor, path, offset, length, mark) => { +Commands.addMarkByPath = (fn, editor) => (path, offset, length, mark) => { mark = Mark.create(mark) editor.addMarksByPath(path, offset, length, [mark]) } -Commands.addMarksByPath = (editor, path, offset, length, marks) => { +Commands.addMarksByPath = (fn, editor) => (path, offset, length, marks) => { marks = Mark.createSet(marks) if (!marks.size) { @@ -72,13 +71,12 @@ Commands.addMarksByPath = (editor, path, offset, length, marks) => { /** * Insert a `fragment` at `index` in a node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Number} index * @param {Fragment} fragment */ -Commands.insertFragmentByPath = (editor, path, index, fragment) => { +Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { fragment.nodes.forEach((node, i) => { editor.insertNodeByPath(path, index + i, node) }) @@ -87,13 +85,12 @@ Commands.insertFragmentByPath = (editor, path, index, fragment) => { /** * Insert a `node` at `index` in a node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Number} index * @param {Node} node */ -Commands.insertNodeByPath = (editor, path, index, node) => { +Commands.insertNodeByPath = (fn, editor) => (path, index, node) => { editor.applyOperation({ type: 'insert_node', path: path.concat(index), @@ -104,14 +101,13 @@ Commands.insertNodeByPath = (editor, path, index, node) => { /** * Insert `text` at `offset` in node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset * @param {String} text * @param {Set} marks (optional) */ -Commands.insertTextByPath = (editor, path, offset, text, marks) => { +Commands.insertTextByPath = (fn, editor) => (path, offset, text, marks) => { marks = Mark.createSet(marks) const { value } = editor const { annotations, document } = value @@ -154,11 +150,10 @@ Commands.insertTextByPath = (editor, path, offset, text, marks) => { /** * Merge a node by `path` with the previous node. * - * @param {Editor} editor * @param {Array} path */ -Commands.mergeNodeByPath = (editor, path) => { +Commands.mergeNodeByPath = (fn, editor) => path => { const { value } = editor const { document } = value const original = document.getDescendant(path) @@ -190,13 +185,12 @@ Commands.mergeNodeByPath = (editor, path) => { /** * Move a node by `path` to a new parent by `newParentPath` and `newIndex`. * - * @param {Editor} editor * @param {Array} path * @param {String} newParentPath * @param {Number} newIndex */ -Commands.moveNodeByPath = (editor, path, newParentPath, newIndex) => { +Commands.moveNodeByPath = (fn, editor) => (path, newParentPath, newIndex) => { // If the operation path and newParentPath are the same, // this should be considered a NOOP if (PathUtils.isEqual(path, newParentPath)) { @@ -219,19 +213,18 @@ Commands.moveNodeByPath = (editor, path, newParentPath, newIndex) => { /** * Remove mark from text at `offset` and `length` in node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset * @param {Number} length * @param {Mark} mark */ -Commands.removeMarkByPath = (editor, path, offset, length, mark) => { +Commands.removeMarkByPath = (fn, editor) => (path, offset, length, mark) => { mark = Mark.create(mark) editor.removeMarksByPath(path, offset, length, [mark]) } -Commands.removeMarksByPath = (editor, path, offset, length, marks) => { +Commands.removeMarksByPath = (fn, editor) => (path, offset, length, marks) => { marks = Mark.createSet(marks) if (!marks.size) { @@ -277,11 +270,10 @@ Commands.removeMarksByPath = (editor, path, offset, length, marks) => { /** * Remove all `marks` from node by `path`. * - * @param {Editor} editor * @param {Array} path */ -Commands.removeAllMarksByPath = (editor, path) => { +Commands.removeAllMarksByPath = (fn, editor) => path => { const { state } = editor const { document } = state const node = document.assertNode(path) @@ -302,11 +294,10 @@ Commands.removeAllMarksByPath = (editor, path) => { /** * Remove a node by `path`. * - * @param {Editor} editor * @param {Array} path */ -Commands.removeNodeByPath = (editor, path) => { +Commands.removeNodeByPath = (fn, editor) => path => { const { value } = editor const { document } = value const node = document.assertNode(path) @@ -321,13 +312,12 @@ Commands.removeNodeByPath = (editor, path) => { /** * Remove text at `offset` and `length` in node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset * @param {Number} length */ -Commands.removeTextByPath = (editor, path, offset, length) => { +Commands.removeTextByPath = (fn, editor) => (path, offset, length) => { const { value } = editor const { document, annotations } = value const node = document.assertNode(path) @@ -366,12 +356,11 @@ Commands.removeTextByPath = (editor, path, offset, length) => { /** `* Replace a `node` with another `node` * - * @param {Editor} editor * @param {Array} path * @param {Object|Node} node */ -Commands.replaceNodeByPath = (editor, path, newNode) => { +Commands.replaceNodeByPath = (fn, editor) => (path, newNode) => { newNode = Node.create(newNode) const index = path.last() const parentPath = PathUtils.lift(path) @@ -385,7 +374,6 @@ Commands.replaceNodeByPath = (editor, path, newNode) => { /** * Replace a `length` of text at `offset` with new `text` and optional `marks`. * - * @param {Editor} editor * @param {String} key * @param {Number} offset * @param {Number} length @@ -393,7 +381,13 @@ Commands.replaceNodeByPath = (editor, path, newNode) => { * @param {Set} marks (optional) */ -Commands.replaceTextByPath = (editor, path, offset, length, text, marks) => { +Commands.replaceTextByPath = (fn, editor) => ( + path, + offset, + length, + text, + marks +) => { editor.withoutNormalizing(() => { editor.removeTextByPath(path, offset, length) editor.insertTextByPath(path, offset, text, marks) @@ -403,7 +397,6 @@ Commands.replaceTextByPath = (editor, path, offset, length, text, marks) => { /** * Set `newProperties` on mark on text at `offset` and `length` in node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset * @param {Number} length @@ -411,8 +404,7 @@ Commands.replaceTextByPath = (editor, path, offset, length, text, marks) => { * @param {Object} newProperties */ -Commands.setMarkByPath = ( - editor, +Commands.setMarkByPath = (fn, editor) => ( path, offset, length, @@ -453,12 +445,11 @@ Commands.setMarkByPath = ( /** * Set `properties` on a node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {Object|String} newProperties */ -Commands.setNodeByPath = (editor, path, newProperties) => { +Commands.setNodeByPath = (fn, editor) => (path, newProperties) => { const { value } = editor const { document } = value const node = document.assertNode(path) @@ -476,13 +467,12 @@ Commands.setNodeByPath = (editor, path, newProperties) => { /** * Insert `text` at `offset` in node by `path`. * - * @param {Editor} editor * @param {Array} path * @param {String} text * @param {Set} marks (optional) */ -Commands.setTextByPath = (editor, path, text, marks) => { +Commands.setTextByPath = (fn, editor) => (path, text, marks) => { const { value } = editor const { document } = value const node = document.assertNode(path) @@ -493,13 +483,12 @@ Commands.setTextByPath = (editor, path, text, marks) => { /** * Split a node by `path` at `position`. * - * @param {Editor} editor * @param {Array} path * @param {Number} position * @param {Object} options */ -Commands.splitNodeByPath = (editor, path, position, options = {}) => { +Commands.splitNodeByPath = (fn, editor) => (path, position, options = {}) => { const { target = null } = options const { value } = editor const { document } = value @@ -520,13 +509,16 @@ Commands.splitNodeByPath = (editor, path, position, options = {}) => { /** * Split a node deeply down the tree by `path`, `textPath` and `textOffset`. * - * @param {Editor} editor * @param {Array} path * @param {Array} textPath * @param {Number} textOffset */ -Commands.splitDescendantsByPath = (editor, path, textPath, textOffset) => { +Commands.splitDescendantsByPath = (fn, editor) => ( + path, + textPath, + textOffset +) => { if (path.equals(textPath)) { editor.splitNodeByPath(textPath, textOffset) return @@ -556,12 +548,11 @@ Commands.splitDescendantsByPath = (editor, path, textPath, textOffset) => { /** * Unwrap content from an inline parent with `properties`. * - * @param {Editor} editor * @param {Array} path * @param {Object|String} properties */ -Commands.unwrapInlineByPath = (editor, path, properties) => { +Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { const { value } = editor const { document, selection } = value const node = document.assertNode(path) @@ -574,12 +565,11 @@ Commands.unwrapInlineByPath = (editor, path, properties) => { /** * Unwrap content from a block parent with `properties`. * - * @param {Editor} editor * @param {Array} path * @param {Object|String} properties */ -Commands.unwrapBlockByPath = (editor, path, properties) => { +Commands.unwrapBlockByPath = (fn, editor) => (path, properties) => { const { value } = editor const { document, selection } = value const node = document.assertNode(path) @@ -596,11 +586,10 @@ Commands.unwrapBlockByPath = (editor, path, properties) => { * split. If the node is the only child, the parent is removed, and * simply replaced by the node itself. Cannot unwrap a root node. * - * @param {Editor} editor * @param {Array} path */ -Commands.unwrapNodeByPath = (editor, path) => { +Commands.unwrapNodeByPath = (fn, editor) => path => { const { value } = editor const { document } = value document.assertNode(path) @@ -634,11 +623,10 @@ Commands.unwrapNodeByPath = (editor, path) => { * Unwrap all of the children of a node, by removing the node and replacing it * with the children in the tree. * - * @param {Editor} editor * @param {Array} path */ -Commands.unwrapChildrenByPath = (editor, path) => { +Commands.unwrapChildrenByPath = (fn, editor) => path => { path = PathUtils.create(path) const { value } = editor const { document } = value @@ -661,12 +649,11 @@ Commands.unwrapChildrenByPath = (editor, path) => { /** * Wrap a node in a block with `properties`. * - * @param {Editor} editor * @param {Array} path * @param {Block|Object|String} block */ -Commands.wrapBlockByPath = (editor, path, block) => { +Commands.wrapBlockByPath = (fn, editor) => (path, block) => { block = Block.create(block) block = block.set('nodes', block.nodes.clear()) const parentPath = PathUtils.lift(path) @@ -682,12 +669,11 @@ Commands.wrapBlockByPath = (editor, path, block) => { /** * Wrap a node in an inline with `properties`. * - * @param {Editor} editor * @param {Array} path * @param {Block|Object|String} inline */ -Commands.wrapInlineByPath = (editor, path, inline) => { +Commands.wrapInlineByPath = (fn, editor) => (path, inline) => { inline = Inline.create(inline) inline = inline.set('nodes', inline.nodes.clear()) const parentPath = PathUtils.lift(path) @@ -703,12 +689,11 @@ Commands.wrapInlineByPath = (editor, path, inline) => { /** * Wrap a node by `path` with `node`. * - * @param {Editor} editor * @param {Array} path * @param {Node|Object} node */ -Commands.wrapNodeByPath = (editor, path, node) => { +Commands.wrapNodeByPath = (fn, editor) => (path, node) => { node = Node.create(node) if (node.object === 'block') { @@ -748,7 +733,7 @@ const COMMANDS = [ ] for (const method of COMMANDS) { - Commands[`${method}ByKey`] = (editor, key, ...args) => { + Commands[`${method}ByKey`] = (fn, editor) => (key, ...args) => { const { value } = editor const { document } = value const path = document.assertPath(key) @@ -757,7 +742,7 @@ for (const method of COMMANDS) { } // Moving nodes takes two keys, so it's slightly different. -Commands.moveNodeByKey = (editor, key, newKey, ...args) => { +Commands.moveNodeByKey = (fn, editor) => (key, newKey, ...args) => { const { value } = editor const { document } = value const path = document.assertPath(key) @@ -766,7 +751,7 @@ Commands.moveNodeByKey = (editor, key, newKey, ...args) => { } // Splitting descendants takes two keys, so it's slightly different. -Commands.splitDescendantsByKey = (editor, key, textKey, ...args) => { +Commands.splitDescendantsByKey = (fn, editor) => (key, textKey, ...args) => { const { value } = editor const { document } = value const path = document.assertPath(key) diff --git a/packages/slate/src/commands/on-history.js b/packages/slate/src/commands/on-history.js index 36645ec3d6..ded686274e 100644 --- a/packages/slate/src/commands/on-history.js +++ b/packages/slate/src/commands/on-history.js @@ -12,15 +12,17 @@ const Commands = {} /** * Save an `operation` into the history. * - * @param {Editor} editor * @param {Object} operation */ -Commands.save = (editor, operation) => { - const { operations, value } = editor +Commands.save = (fn, editor) => operation => { + const { operations, value, tmp } = editor const { data } = value - let { save, merge } = editor.tmp - if (save === false) return + let merge = tmp.merge + + if (tmp.save === false) { + return + } let undos = data.get('undos') || List() const lastBatch = undos.last() @@ -63,10 +65,9 @@ Commands.save = (editor, operation) => { /** * Redo to the next value in the history. * - * @param {Editor} editor */ -Commands.redo = editor => { +Commands.redo = (fn, editor) => () => { const { value } = editor const { data } = value let redos = data.get('redos') || List() @@ -101,10 +102,9 @@ Commands.redo = editor => { /** * Undo the previous operations in the history. * - * @param {Editor} editor */ -Commands.undo = editor => { +Commands.undo = (fn, editor) => () => { const { value } = editor const { data } = value let redos = data.get('redos') || List() @@ -144,14 +144,13 @@ Commands.undo = editor => { * Apply a series of changes inside a synchronous `fn`, without merging any of * the new operations into previous save point in the history. * - * @param {Editor} editor - * @param {Function} fn + * @param {Function} run */ -Commands.withoutMerging = (editor, fn) => { +Commands.withoutMerging = (fn, editor) => run => { const value = editor.tmp.merge editor.tmp.merge = false - fn(editor) + run(editor) editor.tmp.merge = value } @@ -159,14 +158,13 @@ Commands.withoutMerging = (editor, fn) => { * Apply a series of changes inside a synchronous `fn`, without saving any of * their operations into the history. * - * @param {Editor} editor - * @param {Function} fn + * @param {Function} run */ -Commands.withoutSaving = (editor, fn) => { +Commands.withoutSaving = (fn, editor) => run => { const value = editor.tmp.save editor.tmp.save = false - fn(editor) + run(editor) editor.tmp.save = value } diff --git a/packages/slate/src/commands/on-selection.js b/packages/slate/src/commands/on-selection.js index dafa68ce46..49ad6f260d 100644 --- a/packages/slate/src/commands/on-selection.js +++ b/packages/slate/src/commands/on-selection.js @@ -9,7 +9,6 @@ const Commands = {} /** * Get the next point by `n`. * - * @param {Editor} editor * @param {Point} point * @param {Number} n * @return {Point} @@ -26,7 +25,6 @@ function getNextPoint(editor, point, n) { /** * Get the previous point by `n`. * - * @param {Editor} editor * @param {Point} point * @param {Number} n * @return {Point} @@ -42,41 +40,33 @@ function getPreviousPoint(editor, point, n) { /** * Blur the selection. - * - * @param {Editor} editor */ -Commands.blur = editor => { +Commands.blur = (fn, editor) => () => { editor.select({ isFocused: false }) } /** * Deselect the selection. - * - * @param {Editor} editor */ -Commands.deselect = editor => { +Commands.deselect = (fn, editor) => () => { editor.select(Selection.create()) } /** * Focus the selection. - * - * @param {Editor} editor */ -Commands.focus = editor => { +Commands.focus = (fn, editor) => () => { editor.select({ isFocused: true }) } /** * Flip the selection's anchor and focus points. - * - * @param {Editor} editor */ -Commands.flip = editor => { +Commands.flip = (fn, editor) => () => { const { value: { selection } } = editor const range = selection.flip() editor.select(range) @@ -85,11 +75,10 @@ Commands.flip = editor => { /** * Move the selection's anchor point backwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveAnchorBackward = (editor, n = 1) => { +Commands.moveAnchorBackward = (fn, editor) => (n = 1) => { const { value: { selection } } = editor const point = getPreviousPoint(editor, selection.anchor, n) editor.setAnchor(point) @@ -98,11 +87,10 @@ Commands.moveAnchorBackward = (editor, n = 1) => { /** * Move the selection's anchor point forwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveAnchorForward = (editor, n = 1) => { +Commands.moveAnchorForward = (fn, editor) => (n = 1) => { const { value: { selection } } = editor const point = getNextPoint(editor, selection.anchor, n) editor.setAnchor(point) @@ -111,12 +99,11 @@ Commands.moveAnchorForward = (editor, n = 1) => { /** * Move the selection's anchor point to a specific `path` and `offset`. * - * @param {Editor} editor * @param {Path} path * @param {Number} offset */ -Commands.moveAnchorTo = (editor, path, offset) => { +Commands.moveAnchorTo = (fn, editor) => (path, offset) => { const { value: { selection } } = editor const range = selection.moveAnchorTo(path, offset) editor.select(range) @@ -124,11 +111,9 @@ Commands.moveAnchorTo = (editor, path, offset) => { /** * Move the selection's anchor point to the end of the block it's in. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfBlock = editor => { +Commands.moveAnchorToEndOfBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestBlock(selection.anchor.path) @@ -140,11 +125,9 @@ Commands.moveAnchorToEndOfBlock = editor => { /** * Move the selection's anchor point to the end of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfPath = (editor, path) => { +Commands.moveAnchorToEndOfPath = (fn, editor) => path => { const { value: { document } } = editor const entry = document.lastText({ path }) @@ -156,11 +139,9 @@ Commands.moveAnchorToEndOfPath = (editor, path) => { /** * Move the selection's anchor point to the end of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfInline = editor => { +Commands.moveAnchorToEndOfInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestInline(selection.anchor.path) @@ -172,11 +153,9 @@ Commands.moveAnchorToEndOfInline = editor => { /** * Move the selection's anchor point to the end of the document. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfDocument = editor => { +Commands.moveAnchorToEndOfDocument = (fn, editor) => () => { const { value: { document } } = editor const entry = document.lastText() @@ -188,11 +167,9 @@ Commands.moveAnchorToEndOfDocument = editor => { /** * Move the selection's anchor point to the end of the next block. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfNextBlock = editor => { +Commands.moveAnchorToEndOfNextBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextBlock(selection.anchor.path) @@ -204,11 +181,9 @@ Commands.moveAnchorToEndOfNextBlock = editor => { /** * Move the selection's anchor point to the end of the next inline. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfNextInline = editor => { +Commands.moveAnchorToEndOfNextInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextInline(selection.anchor.path) @@ -220,11 +195,9 @@ Commands.moveAnchorToEndOfNextInline = editor => { /** * Move the selection's anchor point to the end of the next text node. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfNextText = editor => { +Commands.moveAnchorToEndOfNextText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextText(selection.anchor.path) @@ -236,11 +209,9 @@ Commands.moveAnchorToEndOfNextText = editor => { /** * Move the selection's anchor point to the end of the previous block. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfPreviousBlock = editor => { +Commands.moveAnchorToEndOfPreviousBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousBlock(selection.anchor.path) @@ -252,11 +223,9 @@ Commands.moveAnchorToEndOfPreviousBlock = editor => { /** * Move the selection's anchor point to the end of the previous inline. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfPreviousInline = editor => { +Commands.moveAnchorToEndOfPreviousInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousInline(selection.anchor.path) @@ -268,11 +237,9 @@ Commands.moveAnchorToEndOfPreviousInline = editor => { /** * Move the selection's anchor point to the end of the previous text node. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfPreviousText = editor => { +Commands.moveAnchorToEndOfPreviousText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousText(selection.anchor.path) @@ -284,22 +251,18 @@ Commands.moveAnchorToEndOfPreviousText = editor => { /** * Move the selection's anchor point to the end of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveAnchorToEndOfText = editor => { +Commands.moveAnchorToEndOfText = (fn, editor) => () => { const { value: { selection } } = editor editor.moveAnchorToEndOfPath(selection.anchor.path) } /** * Move the selection's anchor point to the start of the block it's in. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfBlock = editor => { +Commands.moveAnchorToStartOfBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestBlock(selection.anchor.path) @@ -311,11 +274,9 @@ Commands.moveAnchorToStartOfBlock = editor => { /** * Move the selection's anchor point to the start of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfPath = (editor, path) => { +Commands.moveAnchorToStartOfPath = (fn, editor) => path => { const { value: { document } } = editor const entry = document.lastText({ path }) @@ -327,11 +288,9 @@ Commands.moveAnchorToStartOfPath = (editor, path) => { /** * Move the selection's anchor point to the start of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfInline = editor => { +Commands.moveAnchorToStartOfInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestInline(selection.anchor.path) @@ -343,11 +302,9 @@ Commands.moveAnchorToStartOfInline = editor => { /** * Move the selection's anchor point to the start of the document. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfDocument = editor => { +Commands.moveAnchorToStartOfDocument = (fn, editor) => () => { const { value: { document } } = editor const entry = document.firstText() @@ -359,11 +316,9 @@ Commands.moveAnchorToStartOfDocument = editor => { /** * Move the selection's anchor point to the start of the next block. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfNextBlock = editor => { +Commands.moveAnchorToStartOfNextBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextBlock(selection.anchor.path) @@ -375,11 +330,9 @@ Commands.moveAnchorToStartOfNextBlock = editor => { /** * Move the selection's anchor point to the start of the next inline. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfNextInline = editor => { +Commands.moveAnchorToStartOfNextInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextInline(selection.anchor.path) @@ -391,11 +344,9 @@ Commands.moveAnchorToStartOfNextInline = editor => { /** * Move the selection's anchor point to the start of the next text node. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfNextText = editor => { +Commands.moveAnchorToStartOfNextText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextText(selection.anchor.path) @@ -407,11 +358,9 @@ Commands.moveAnchorToStartOfNextText = editor => { /** * Move the selection's anchor point to the start of the previous block. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfPreviousBlock = editor => { +Commands.moveAnchorToStartOfPreviousBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousBlock(selection.anchor.path) @@ -423,11 +372,9 @@ Commands.moveAnchorToStartOfPreviousBlock = editor => { /** * Move the selection's anchor point to the start of the previous inline. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfPreviousInline = editor => { +Commands.moveAnchorToStartOfPreviousInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousInline(selection.anchor.path) @@ -439,11 +386,9 @@ Commands.moveAnchorToStartOfPreviousInline = editor => { /** * Move the selection's anchor point to the start of the previous text node. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfPreviousText = editor => { +Commands.moveAnchorToStartOfPreviousText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousText(selection.anchor.path) @@ -455,22 +400,18 @@ Commands.moveAnchorToStartOfPreviousText = editor => { /** * Move the selection's anchor point to the start of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveAnchorToStartOfText = editor => { +Commands.moveAnchorToStartOfText = (fn, editor) => () => { const { value: { selection } } = editor editor.moveAnchorToStartOfPath(selection.anchor.path) } /** * Move the selection's anchor point backward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveAnchorWordBackward = editor => { +Commands.moveAnchorWordBackward = (fn, editor) => () => { const { value: { selection } } = editor const point = editor.getPreviousWordPoint(selection.anchor) editor.setAnchor(point) @@ -478,11 +419,9 @@ Commands.moveAnchorWordBackward = editor => { /** * Move the selection's anchor point forward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveAnchorWordForward = editor => { +Commands.moveAnchorWordForward = (fn, editor) => () => { const { value: { selection } } = editor const point = editor.getNextWordPoint(selection.anchor) editor.setAnchor(point) @@ -491,35 +430,21 @@ Commands.moveAnchorWordForward = editor => { /** * Move the selection backward by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveBackward = (editor, n) => { +Commands.moveBackward = (fn, editor) => n => { editor.moveAnchorBackward(n) editor.moveFocusBackward(n) } -/** - * Move the selection backward by `n` words. - * - * @param {Editor} editor - * @param {Number} n - */ - -Commands.moveWordBackward = (editor, n) => { - editor.moveAnchorWordBackward(n) - editor.moveFocusWordBackward(n) -} - /** * Move the selection's end point backwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveEndBackward = (editor, n = 1) => { +Commands.moveEndBackward = (fn, editor) => (n = 1) => { if (editor.value.selection.isForward) { editor.moveFocusBackward(n) } else { @@ -530,11 +455,10 @@ Commands.moveEndBackward = (editor, n = 1) => { /** * Move the selection's end point forwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveEndForward = (editor, n = 1) => { +Commands.moveEndForward = (fn, editor) => (n = 1) => { if (editor.value.selection.isForward) { editor.moveFocusForward(n) } else { @@ -545,12 +469,11 @@ Commands.moveEndForward = (editor, n = 1) => { /** * Move the selection's end point to a specific `path` and `offset`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset */ -Commands.moveEndTo = (editor, path, offset) => { +Commands.moveEndTo = (fn, editor) => (path, offset) => { const { value: { selection } } = editor const range = selection.moveEndTo(path, offset) editor.select(range) @@ -558,11 +481,9 @@ Commands.moveEndTo = (editor, path, offset) => { /** * Move the selection's end point to the end of the block it's in. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfBlock = editor => { +Commands.moveEndToEndOfBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfBlock() } else { @@ -572,11 +493,9 @@ Commands.moveEndToEndOfBlock = editor => { /** * Move the selection's end point to the end of the document. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfDocument = editor => { +Commands.moveEndToEndOfDocument = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfDocument() } else { @@ -586,11 +505,9 @@ Commands.moveEndToEndOfDocument = editor => { /** * Move the selection's end point to the end of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfInline = editor => { +Commands.moveEndToEndOfInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfInline() } else { @@ -600,11 +517,9 @@ Commands.moveEndToEndOfInline = editor => { /** * Move the selection's end point to the end of the next block. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfNextBlock = editor => { +Commands.moveEndToEndOfNextBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfNextBlock() } else { @@ -614,11 +529,9 @@ Commands.moveEndToEndOfNextBlock = editor => { /** * Move the selection's end point to the end of the next inline. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfNextInline = editor => { +Commands.moveEndToEndOfNextInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfNextInline() } else { @@ -628,11 +541,9 @@ Commands.moveEndToEndOfNextInline = editor => { /** * Move the selection's end point to the end of the next text node. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfNextText = editor => { +Commands.moveEndToEndOfNextText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfNextText() } else { @@ -642,11 +553,9 @@ Commands.moveEndToEndOfNextText = editor => { /** * Move the selection's end point to the end of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfPath = (editor, path) => { +Commands.moveEndToEndOfPath = (fn, editor) => path => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfPath(path) } else { @@ -656,11 +565,9 @@ Commands.moveEndToEndOfPath = (editor, path) => { /** * Move the selection's end point to the end of the previous block. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfPreviousBlock = editor => { +Commands.moveEndToEndOfPreviousBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfPreviousBlock() } else { @@ -670,11 +577,9 @@ Commands.moveEndToEndOfPreviousBlock = editor => { /** * Move the selection's end point to the end of the previous inline. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfPreviousInline = editor => { +Commands.moveEndToEndOfPreviousInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfPreviousInline() } else { @@ -684,11 +589,9 @@ Commands.moveEndToEndOfPreviousInline = editor => { /** * Move the selection's end point to the end of the previous text node. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfPreviousText = editor => { +Commands.moveEndToEndOfPreviousText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfPreviousText() } else { @@ -698,11 +601,9 @@ Commands.moveEndToEndOfPreviousText = editor => { /** * Move the selection's end point to the end of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveEndToEndOfText = editor => { +Commands.moveEndToEndOfText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToEndOfText() } else { @@ -712,11 +613,9 @@ Commands.moveEndToEndOfText = editor => { /** * Move the selection's end point to the start of the block it's in. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfBlock = editor => { +Commands.moveEndToStartOfBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfBlock() } else { @@ -726,11 +625,9 @@ Commands.moveEndToStartOfBlock = editor => { /** * Move the selection's end point to the start of the document. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfDocument = editor => { +Commands.moveEndToStartOfDocument = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfDocument() } else { @@ -740,11 +637,9 @@ Commands.moveEndToStartOfDocument = editor => { /** * Move the selection's end point to the start of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfInline = editor => { +Commands.moveEndToStartOfInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfInline() } else { @@ -754,11 +649,9 @@ Commands.moveEndToStartOfInline = editor => { /** * Move the selection's end point to the start of the next block. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfNextBlock = editor => { +Commands.moveEndToStartOfNextBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfNextBlock() } else { @@ -768,11 +661,9 @@ Commands.moveEndToStartOfNextBlock = editor => { /** * Move the selection's end point to the start of the next inline. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfNextInline = editor => { +Commands.moveEndToStartOfNextInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfNextInline() } else { @@ -782,11 +673,9 @@ Commands.moveEndToStartOfNextInline = editor => { /** * Move the selection's end point to the start of the next text node. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfNextText = editor => { +Commands.moveEndToStartOfNextText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfNextText() } else { @@ -796,11 +685,9 @@ Commands.moveEndToStartOfNextText = editor => { /** * Move the selection's end point to the start of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfPath = (editor, path) => { +Commands.moveEndToStartOfPath = (fn, editor) => path => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfPath(path) } else { @@ -810,11 +697,9 @@ Commands.moveEndToStartOfPath = (editor, path) => { /** * Move the selection's end point to the start of the previous block. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfPreviousBlock = editor => { +Commands.moveEndToStartOfPreviousBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfPreviousBlock() } else { @@ -824,11 +709,9 @@ Commands.moveEndToStartOfPreviousBlock = editor => { /** * Move the selection's end point to the start of the previous inline. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfPreviousInline = editor => { +Commands.moveEndToStartOfPreviousInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfPreviousInline() } else { @@ -838,11 +721,9 @@ Commands.moveEndToStartOfPreviousInline = editor => { /** * Move the selection's end point to the start of the previous text node. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfPreviousText = editor => { +Commands.moveEndToStartOfPreviousText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfPreviousText() } else { @@ -852,11 +733,9 @@ Commands.moveEndToStartOfPreviousText = editor => { /** * Move the selection's end point to the start of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveEndToStartOfText = editor => { +Commands.moveEndToStartOfText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveFocusToStartOfText() } else { @@ -866,11 +745,9 @@ Commands.moveEndToStartOfText = editor => { /** * Move the selection's end point backward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveEndWordBackward = (editor, ...args) => { +Commands.moveEndWordBackward = (fn, editor) => (...args) => { if (editor.value.selection.isForward) { editor.moveFocusWordBackward() } else { @@ -880,11 +757,9 @@ Commands.moveEndWordBackward = (editor, ...args) => { /** * Move the selection's end point forward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveEndWordForward = (editor, ...args) => { +Commands.moveEndWordForward = (fn, editor) => (...args) => { if (editor.value.selection.isForward) { editor.moveFocusWordForward() } else { @@ -895,11 +770,10 @@ Commands.moveEndWordForward = (editor, ...args) => { /** * Move the selection's focus point backwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveFocusBackward = (editor, n = 1) => { +Commands.moveFocusBackward = (fn, editor) => (n = 1) => { const { value: { selection } } = editor const point = getPreviousPoint(editor, selection.focus, n) editor.setFocus(point) @@ -908,11 +782,10 @@ Commands.moveFocusBackward = (editor, n = 1) => { /** * Move the selection's focus point forwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveFocusForward = (editor, n = 1) => { +Commands.moveFocusForward = (fn, editor) => (n = 1) => { const { value: { selection } } = editor const point = getNextPoint(editor, selection.focus, n) editor.setFocus(point) @@ -923,10 +796,9 @@ Commands.moveFocusForward = (editor, n = 1) => { * * @param {Path} path * @param {Number} offset - * @param {Editor} editor */ -Commands.moveFocusTo = (editor, path, offset) => { +Commands.moveFocusTo = (fn, editor) => (path, offset) => { const { value: { selection } } = editor const range = selection.moveFocusTo(path, offset) editor.select(range) @@ -934,11 +806,9 @@ Commands.moveFocusTo = (editor, path, offset) => { /** * Move the selection's focus point to the end of the block it's in. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfBlock = editor => { +Commands.moveFocusToEndOfBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestBlock(selection.focus.path) @@ -950,11 +820,9 @@ Commands.moveFocusToEndOfBlock = editor => { /** * Move the selection's focus point to the end of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfPath = (editor, path) => { +Commands.moveFocusToEndOfPath = (fn, editor) => path => { const { value: { document } } = editor const entry = document.lastText({ path }) @@ -966,11 +834,9 @@ Commands.moveFocusToEndOfPath = (editor, path) => { /** * Move the selection's focus point to the end of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfInline = editor => { +Commands.moveFocusToEndOfInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestInline(selection.focus.path) @@ -982,11 +848,9 @@ Commands.moveFocusToEndOfInline = editor => { /** * Move the selection's focus point to the end of the document. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfDocument = editor => { +Commands.moveFocusToEndOfDocument = (fn, editor) => () => { const { value: { document } } = editor const entry = document.lastText() @@ -998,11 +862,9 @@ Commands.moveFocusToEndOfDocument = editor => { /** * Move the selection's focus point to the end of the next block. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfNextBlock = editor => { +Commands.moveFocusToEndOfNextBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextBlock(selection.focus.path) @@ -1014,11 +876,9 @@ Commands.moveFocusToEndOfNextBlock = editor => { /** * Move the selection's focus point to the end of the next inline. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfNextInline = editor => { +Commands.moveFocusToEndOfNextInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextInline(selection.focus.path) @@ -1030,11 +890,9 @@ Commands.moveFocusToEndOfNextInline = editor => { /** * Move the selection's focus point to the end of the next text node. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfNextText = editor => { +Commands.moveFocusToEndOfNextText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextText(selection.focus.path) @@ -1046,11 +904,9 @@ Commands.moveFocusToEndOfNextText = editor => { /** * Move the selection's focus point to the end of the previous block. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfPreviousBlock = editor => { +Commands.moveFocusToEndOfPreviousBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousBlock(selection.focus.path) @@ -1062,11 +918,9 @@ Commands.moveFocusToEndOfPreviousBlock = editor => { /** * Move the selection's focus point to the end of the previous inline. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfPreviousInline = editor => { +Commands.moveFocusToEndOfPreviousInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousInline(selection.focus.path) @@ -1078,11 +932,9 @@ Commands.moveFocusToEndOfPreviousInline = editor => { /** * Move the selection's focus point to the end of the previous text node. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfPreviousText = editor => { +Commands.moveFocusToEndOfPreviousText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousText(selection.focus.path) @@ -1094,22 +946,18 @@ Commands.moveFocusToEndOfPreviousText = editor => { /** * Move the selection's focus point to the end of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveFocusToEndOfText = editor => { +Commands.moveFocusToEndOfText = (fn, editor) => () => { const { value: { selection } } = editor editor.moveFocusToEndOfPath(selection.focus.path) } /** * Move the selection's focus point to the start of the block it's in. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfBlock = editor => { +Commands.moveFocusToStartOfBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestBlock(selection.focus.path) @@ -1121,11 +969,9 @@ Commands.moveFocusToStartOfBlock = editor => { /** * Move the selection's focus point to the start of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfPath = (editor, path) => { +Commands.moveFocusToStartOfPath = (fn, editor) => path => { const { value: { document } } = editor const entry = document.lastText({ path }) @@ -1137,11 +983,9 @@ Commands.moveFocusToStartOfPath = (editor, path) => { /** * Move the selection's focus point to the start of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfInline = editor => { +Commands.moveFocusToStartOfInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.closestInline(selection.focus.path) @@ -1153,11 +997,9 @@ Commands.moveFocusToStartOfInline = editor => { /** * Move the selection's focus point to the start of the document. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfDocument = editor => { +Commands.moveFocusToStartOfDocument = (fn, editor) => () => { const { value: { document } } = editor const entry = document.firstText() @@ -1169,11 +1011,9 @@ Commands.moveFocusToStartOfDocument = editor => { /** * Move the selection's focus point to the start of the next block. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfNextBlock = editor => { +Commands.moveFocusToStartOfNextBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextBlock(selection.focus.path) @@ -1185,11 +1025,9 @@ Commands.moveFocusToStartOfNextBlock = editor => { /** * Move the selection's focus point to the start of the next inline. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfNextInline = editor => { +Commands.moveFocusToStartOfNextInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextInline(selection.focus.path) @@ -1201,11 +1039,9 @@ Commands.moveFocusToStartOfNextInline = editor => { /** * Move the selection's focus point to the start of the next text node. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfNextText = editor => { +Commands.moveFocusToStartOfNextText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.nextText(selection.focus.path) @@ -1217,11 +1053,9 @@ Commands.moveFocusToStartOfNextText = editor => { /** * Move the selection's focus point to the start of the previous block. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfPreviousBlock = editor => { +Commands.moveFocusToStartOfPreviousBlock = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousBlock(selection.focus.path) @@ -1233,11 +1067,9 @@ Commands.moveFocusToStartOfPreviousBlock = editor => { /** * Move the selection's focus point to the start of the previous inline. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfPreviousInline = editor => { +Commands.moveFocusToStartOfPreviousInline = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousInline(selection.focus.path) @@ -1249,11 +1081,9 @@ Commands.moveFocusToStartOfPreviousInline = editor => { /** * Move the selection's focus point to the start of the previous text node. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfPreviousText = editor => { +Commands.moveFocusToStartOfPreviousText = (fn, editor) => () => { const { value: { document, selection } } = editor const entry = document.previousText(selection.focus.path) @@ -1265,22 +1095,18 @@ Commands.moveFocusToStartOfPreviousText = editor => { /** * Move the selection's focus point to the start of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveFocusToStartOfText = editor => { +Commands.moveFocusToStartOfText = (fn, editor) => () => { const { value: { selection } } = editor editor.moveFocusToStartOfPath(selection.focus.path) } /** * Move the selection's focus point backward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveFocusWordBackward = editor => { +Commands.moveFocusWordBackward = (fn, editor) => () => { const { value: { selection } } = editor const point = editor.getPreviousWordPoint(selection.focus) editor.setFocus(point) @@ -1288,11 +1114,9 @@ Commands.moveFocusWordBackward = editor => { /** * Move the selection's focus point forward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveFocusWordForward = editor => { +Commands.moveFocusWordForward = (fn, editor) => () => { const { value: { selection } } = editor const point = editor.getNextWordPoint(selection.focus) editor.setFocus(point) @@ -1300,11 +1124,9 @@ Commands.moveFocusWordForward = editor => { /** * Move the selection's points each forward by one character. - * - * @param {Editor} editor */ -Commands.moveForward = (editor, ...args) => { +Commands.moveForward = (fn, editor) => (...args) => { editor.moveAnchorForward(...args) editor.moveFocusForward(...args) } @@ -1312,11 +1134,10 @@ Commands.moveForward = (editor, ...args) => { /** * Move the selection's start point backwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveStartBackward = (editor, n = 1) => { +Commands.moveStartBackward = (fn, editor) => (n = 1) => { if (editor.value.selection.isForward) { editor.moveAnchorBackward(n) } else { @@ -1327,11 +1148,10 @@ Commands.moveStartBackward = (editor, n = 1) => { /** * Move the selection's start point forwards by `n`. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveStartForward = (editor, n = 1) => { +Commands.moveStartForward = (fn, editor) => (n = 1) => { if (editor.value.selection.isForward) { editor.moveAnchorForward(n) } else { @@ -1342,12 +1162,11 @@ Commands.moveStartForward = (editor, n = 1) => { /** * Move the selection's start point to a specific `path` and `offset`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset */ -Commands.moveStartTo = (editor, path, offset) => { +Commands.moveStartTo = (fn, editor) => (path, offset) => { const { value: { selection } } = editor const range = selection.moveStartTo(path, offset) editor.select(range) @@ -1355,11 +1174,9 @@ Commands.moveStartTo = (editor, path, offset) => { /** * Move the selection's start point to the end of the block it's in. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfBlock = editor => { +Commands.moveStartToEndOfBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfBlock() } else { @@ -1369,11 +1186,9 @@ Commands.moveStartToEndOfBlock = editor => { /** * Move the selection's start point to the end of the document. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfDocument = editor => { +Commands.moveStartToEndOfDocument = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfDocument() } else { @@ -1383,11 +1198,9 @@ Commands.moveStartToEndOfDocument = editor => { /** * Move the selection's start point to the end of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfInline = editor => { +Commands.moveStartToEndOfInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfInline() } else { @@ -1397,11 +1210,9 @@ Commands.moveStartToEndOfInline = editor => { /** * Move the selection's start point to the end of the next block. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfNextBlock = editor => { +Commands.moveStartToEndOfNextBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfNextBlock() } else { @@ -1411,11 +1222,9 @@ Commands.moveStartToEndOfNextBlock = editor => { /** * Move the selection's start point to the end of the next inline. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfNextInline = editor => { +Commands.moveStartToEndOfNextInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfNextInline() } else { @@ -1425,11 +1234,9 @@ Commands.moveStartToEndOfNextInline = editor => { /** * Move the selection's start point to the end of the next text node. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfNextText = editor => { +Commands.moveStartToEndOfNextText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfNextText() } else { @@ -1439,11 +1246,9 @@ Commands.moveStartToEndOfNextText = editor => { /** * Move the selection's start point to the end of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfPath = (editor, path) => { +Commands.moveStartToEndOfPath = (fn, editor) => path => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfPath(path) } else { @@ -1453,11 +1258,9 @@ Commands.moveStartToEndOfPath = (editor, path) => { /** * Move the selection's start point to the end of the previous block. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfPreviousBlock = editor => { +Commands.moveStartToEndOfPreviousBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfPreviousBlock() } else { @@ -1467,11 +1270,9 @@ Commands.moveStartToEndOfPreviousBlock = editor => { /** * Move the selection's start point to the end of the previous inline. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfPreviousInline = editor => { +Commands.moveStartToEndOfPreviousInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfPreviousInline() } else { @@ -1481,11 +1282,9 @@ Commands.moveStartToEndOfPreviousInline = editor => { /** * Move the selection's start point to the end of the previous text node. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfPreviousText = editor => { +Commands.moveStartToEndOfPreviousText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfPreviousText() } else { @@ -1495,11 +1294,9 @@ Commands.moveStartToEndOfPreviousText = editor => { /** * Move the selection's start point to the end of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveStartToEndOfText = editor => { +Commands.moveStartToEndOfText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToEndOfText() } else { @@ -1509,11 +1306,9 @@ Commands.moveStartToEndOfText = editor => { /** * Move the selection's start point to the start of the block it's in. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfBlock = editor => { +Commands.moveStartToStartOfBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfBlock() } else { @@ -1523,11 +1318,9 @@ Commands.moveStartToStartOfBlock = editor => { /** * Move the selection's start point to the start of the document. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfDocument = editor => { +Commands.moveStartToStartOfDocument = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfDocument() } else { @@ -1537,11 +1330,9 @@ Commands.moveStartToStartOfDocument = editor => { /** * Move the selection's start point to the start of the nearest inline. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfInline = editor => { +Commands.moveStartToStartOfInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfInline() } else { @@ -1551,11 +1342,9 @@ Commands.moveStartToStartOfInline = editor => { /** * Move the selection's start point to the start of the next block. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfNextBlock = editor => { +Commands.moveStartToStartOfNextBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfNextBlock() } else { @@ -1565,11 +1354,9 @@ Commands.moveStartToStartOfNextBlock = editor => { /** * Move the selection's start point to the start of the next inline. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfNextInline = editor => { +Commands.moveStartToStartOfNextInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfNextInline() } else { @@ -1579,11 +1366,9 @@ Commands.moveStartToStartOfNextInline = editor => { /** * Move the selection's start point to the start of the next text node. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfNextText = editor => { +Commands.moveStartToStartOfNextText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfNextText() } else { @@ -1593,11 +1378,9 @@ Commands.moveStartToStartOfNextText = editor => { /** * Move the selection's start point to the start of the node at `path`. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfPath = (editor, path) => { +Commands.moveStartToStartOfPath = (fn, editor) => path => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfPath(path) } else { @@ -1607,11 +1390,9 @@ Commands.moveStartToStartOfPath = (editor, path) => { /** * Move the selection's start point to the start of the previous block. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfPreviousBlock = editor => { +Commands.moveStartToStartOfPreviousBlock = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfPreviousBlock() } else { @@ -1621,11 +1402,9 @@ Commands.moveStartToStartOfPreviousBlock = editor => { /** * Move the selection's start point to the start of the previous inline. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfPreviousInline = editor => { +Commands.moveStartToStartOfPreviousInline = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfPreviousInline() } else { @@ -1635,11 +1414,9 @@ Commands.moveStartToStartOfPreviousInline = editor => { /** * Move the selection's start point to the start of the previous text node. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfPreviousText = editor => { +Commands.moveStartToStartOfPreviousText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfPreviousText() } else { @@ -1649,11 +1426,9 @@ Commands.moveStartToStartOfPreviousText = editor => { /** * Move the selection's start point to the start of the text node it's in. - * - * @param {Editor} editor */ -Commands.moveStartToStartOfText = editor => { +Commands.moveStartToStartOfText = (fn, editor) => () => { if (editor.value.selection.isForward) { editor.moveAnchorToStartOfText() } else { @@ -1663,11 +1438,9 @@ Commands.moveStartToStartOfText = editor => { /** * Move the selection's start point backward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveStartWordBackward = (editor, ...args) => { +Commands.moveStartWordBackward = (fn, editor) => (...args) => { if (editor.value.selection.isForward) { editor.moveAnchorWordBackward() } else { @@ -1677,11 +1450,9 @@ Commands.moveStartWordBackward = (editor, ...args) => { /** * Move the selection's start point forward to the edge of the nearest word. - * - * @param {Editor} editor */ -Commands.moveStartWordForward = (editor, ...args) => { +Commands.moveStartWordForward = (fn, editor) => (...args) => { if (editor.value.selection.isForward) { editor.moveAnchorWordForward() } else { @@ -1692,12 +1463,11 @@ Commands.moveStartWordForward = (editor, ...args) => { /** * Move the cursor to a specific `path` and `offset`. * - * @param {Editor} editor * @param {Array} path * @param {Number} offset */ -Commands.moveTo = (editor, path, offset) => { +Commands.moveTo = (fn, editor) => (path, offset) => { const { value: { selection } } = editor const range = selection.moveTo(path, offset) editor.select(range) @@ -1705,11 +1475,9 @@ Commands.moveTo = (editor, path, offset) => { /** * Collapse the cursor to the selection's anchor point. - * - * @param {Editor} editor */ -Commands.moveToAnchor = editor => { +Commands.moveToAnchor = (fn, editor) => () => { const { value: { selection } } = editor const range = selection.moveToAnchor() editor.select(range) @@ -1717,11 +1485,9 @@ Commands.moveToAnchor = editor => { /** * Collapse the cursor to the selection's end point. - * - * @param {Editor} editor */ -Commands.moveToEnd = editor => { +Commands.moveToEnd = (fn, editor) => () => { const { value: { selection } } = editor const range = selection.moveToEnd() editor.select(range) @@ -1729,66 +1495,54 @@ Commands.moveToEnd = editor => { /** * Collapse the cursor to the end of the current block. - * - * @param {Editor} editor */ -Commands.moveToEndOfBlock = editor => { +Commands.moveToEndOfBlock = (fn, editor) => () => { editor.moveEndToEndOfBlock() editor.moveToEnd() } /** * Collapse the cursor to the end of the document. - * - * @param {Editor} editor */ -Commands.moveToEndOfDocument = editor => { +Commands.moveToEndOfDocument = (fn, editor) => () => { editor.moveEndToEndOfDocument() editor.moveToEnd() } /** * Collapse the cursor to the end of the current inline. - * - * @param {Editor} editor */ -Commands.moveToEndOfInline = editor => { +Commands.moveToEndOfInline = (fn, editor) => () => { editor.moveEndToEndOfInline() editor.moveToEnd() } /** * Collapse the cursor to the end of the next block. - * - * @param {Editor} editor */ -Commands.moveToEndOfNextBlock = editor => { +Commands.moveToEndOfNextBlock = (fn, editor) => () => { editor.moveEndToEndOfNextBlock() editor.moveToEnd() } /** * Collapse the cursor to the end of the next inline. - * - * @param {Editor} editor */ -Commands.moveToEndOfNextInline = editor => { +Commands.moveToEndOfNextInline = (fn, editor) => () => { editor.moveEndToEndOfNextInline() editor.moveToEnd() } /** * Collapse the cursor to the end of the next text node. - * - * @param {Editor} editor */ -Commands.moveToEndOfNextText = editor => { +Commands.moveToEndOfNextText = (fn, editor) => () => { editor.moveEndToEndOfNextText() editor.moveToEnd() } @@ -1800,62 +1554,52 @@ Commands.moveToEndOfNextText = editor => { * @param {Array} path */ -Commands.moveToEndOfPath = (editor, path) => { +Commands.moveToEndOfPath = (fn, editor) => path => { editor.moveAnchorToEndOfPath(path) editor.moveToAnchor() } /** * Collapse the cursor to the end of the previous block. - * - * @param {Editor} editor */ -Commands.moveToEndOfPreviousBlock = editor => { +Commands.moveToEndOfPreviousBlock = (fn, editor) => () => { editor.moveStartToEndOfPreviousBlock() editor.moveToStart() } /** * Collapse the cursor to the end of the previous inline. - * - * @param {Editor} editor */ -Commands.moveToEndOfPreviousInline = editor => { +Commands.moveToEndOfPreviousInline = (fn, editor) => () => { editor.moveStartToEndOfPreviousInline() editor.moveToStart() } /** * Collapse the cursor to the end of the previous text node. - * - * @param {Editor} editor */ -Commands.moveToEndOfPreviousText = editor => { +Commands.moveToEndOfPreviousText = (fn, editor) => () => { editor.moveStartToEndOfPreviousText() editor.moveToStart() } /** * Collapse the cursor to the end of the current text node. - * - * @param {Editor} editor */ -Commands.moveToEndOfText = editor => { +Commands.moveToEndOfText = (fn, editor) => () => { editor.moveEndToEndOfText() editor.moveToEnd() } /** * Collapse the cursor to the selection's focus point. - * - * @param {Editor} editor */ -Commands.moveToFocus = editor => { +Commands.moveToFocus = (fn, editor) => () => { const { value: { selection } } = editor const range = selection.moveToFocus() editor.select(range) @@ -1864,11 +1608,9 @@ Commands.moveToFocus = editor => { /** * Move the selection's anchor and focus points to the start and end of the * document, respectively. - * - * @param {Editor} editor */ -Commands.moveToRangeOfDocument = editor => { +Commands.moveToRangeOfDocument = (fn, editor) => () => { editor.moveAnchorToStartOfDocument() editor.moveFocusToEndOfDocument() } @@ -1876,24 +1618,9 @@ Commands.moveToRangeOfDocument = editor => { /** * Move the selection's anchor and focus points to the start and end of the * current block, respectively. - * - * @param {Editor} editor */ -Commands.moveToRangeOfBlock = editor => { - editor.moveToStart() - editor.moveAnchorToStartOfBlock() - editor.moveFocusToEndOfBlock() -} - -/** - * Move the selection's anchor and focus points to the start and end of the - * current inline, respectively. - * - * @param {Editor} editor - */ - -Commands.moveToRangeOfInline = editor => { +Commands.moveToRangeOfBlock = (fn, editor) => () => { editor.moveToStart() editor.moveAnchorToStartOfBlock() editor.moveFocusToEndOfBlock() @@ -1902,11 +1629,9 @@ Commands.moveToRangeOfInline = editor => { /** * Move the selection's anchor and focus points to the start and end of the * current text node, respectively. - * - * @param {Editor} editor */ -Commands.moveToRangeOfInline = editor => { +Commands.moveToRangeOfInline = (fn, editor) => () => { editor.moveToStart() editor.moveAnchorToStartOfText() editor.moveFocusToEndOfText() @@ -1919,18 +1644,16 @@ Commands.moveToRangeOfInline = editor => { * @param {Array} path */ -Commands.moveToRangeOfPath = (editor, path) => { +Commands.moveToRangeOfPath = (fn, editor) => path => { editor.moveAnchorToStartOfPath(path) editor.moveFocusToEndOfPath(path) } /** * Collapse the cursor to the selection's start point. - * - * @param {Editor} editor */ -Commands.moveToStart = editor => { +Commands.moveToStart = (fn, editor) => () => { const { value: { selection } } = editor const range = selection.moveToStart() editor.select(range) @@ -1938,66 +1661,54 @@ Commands.moveToStart = editor => { /** * Collapse the cursor to the start of the current block. - * - * @param {Editor} editor */ -Commands.moveToStartOfBlock = editor => { +Commands.moveToStartOfBlock = (fn, editor) => () => { editor.moveStartToStartOfBlock() editor.moveToStart() } /** * Collapse the cursor to the start of the document. - * - * @param {Editor} editor */ -Commands.moveToStartOfDocument = editor => { +Commands.moveToStartOfDocument = (fn, editor) => () => { editor.moveStartToStartOfDocument() editor.moveToStart() } /** * Collapse the cursor to the start of the current inline. - * - * @param {Editor} editor */ -Commands.moveToStartOfInline = editor => { +Commands.moveToStartOfInline = (fn, editor) => () => { editor.moveStartToStartOfInline() editor.moveToStart() } /** * Collapse the cursor to the start of the next block. - * - * @param {Editor} editor */ -Commands.moveToStartOfNextBlock = editor => { +Commands.moveToStartOfNextBlock = (fn, editor) => () => { editor.moveEndToStartOfNextBlock() editor.moveToEnd() } /** * Collapse the cursor to the start of the next inline. - * - * @param {Editor} editor */ -Commands.moveToStartOfNextInline = editor => { +Commands.moveToStartOfNextInline = (fn, editor) => () => { editor.moveEndToStartOfNextInline() editor.moveToEnd() } /** * Collapse the cursor to the start of the next text node. - * - * @param {Editor} editor */ -Commands.moveToStartOfNextText = editor => { +Commands.moveToStartOfNextText = (fn, editor) => () => { editor.moveEndToStartOfNextText() editor.moveToEnd() } @@ -2005,55 +1716,46 @@ Commands.moveToStartOfNextText = editor => { /** * Collapse the cursor to the start of the node at `path`. * - * @param {Editor} editor * @param {Array} path */ -Commands.moveToStartOfPath = (editor, path) => { +Commands.moveToStartOfPath = (fn, editor) => path => { editor.moveAnchorToStartOfPath(path) editor.moveToAnchor() } /** * Collapse the cursor to the start of the previous block. - * - * @param {Editor} editor */ -Commands.moveToStartOfPreviousBlock = editor => { +Commands.moveToStartOfPreviousBlock = (fn, editor) => () => { editor.moveStartToStartOfPreviousBlock() editor.moveToStart() } /** * Collapse the cursor to the start of the previous inline. - * - * @param {Editor} editor */ -Commands.moveToStartOfPreviousInline = editor => { +Commands.moveToStartOfPreviousInline = (fn, editor) => () => { editor.moveStartToStartOfPreviousInline() editor.moveToStart() } /** * Collapse the cursor to the start of the previous text node. - * - * @param {Editor} editor */ -Commands.moveToStartOfPreviousText = editor => { +Commands.moveToStartOfPreviousText = (fn, editor) => () => { editor.moveStartToStartOfPreviousText() editor.moveToStart() } /** * Collapse the cursor to the start of the current text node. - * - * @param {Editor} editor */ -Commands.moveToStartOfText = editor => { +Commands.moveToStartOfText = (fn, editor) => () => { editor.moveStartToStartOfText() editor.moveToStart() } @@ -2061,11 +1763,10 @@ Commands.moveToStartOfText = editor => { /** * Move the selection's points each backward by `n` words. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveWordBackward = (editor, n) => { +Commands.moveWordBackward = (fn, editor) => n => { editor.moveAnchorWordBackward(n) editor.moveFocusWordBackward(n) } @@ -2073,11 +1774,10 @@ Commands.moveWordBackward = (editor, n) => { /** * Move the selection's points each forward by `n` words. * - * @param {Editor} editor * @param {Number} n */ -Commands.moveWordForward = (editor, n) => { +Commands.moveWordForward = (fn, editor) => n => { editor.moveAnchorWordForward(n) editor.moveFocusWordForward(n) } @@ -2085,12 +1785,11 @@ Commands.moveWordForward = (editor, n) => { /** * Set new `properties` on the selection. * - * @param {Editor} editor * @param {Object} properties * @param {Object} options */ -Commands.select = (editor, properties, options = {}) => { +Commands.select = (fn, editor) => (properties, options = {}) => { properties = Selection.createProperties(properties) const { snapshot = false } = options const { value } = editor @@ -2143,62 +1842,56 @@ Commands.select = (editor, properties, options = {}) => { /** * Set the selection's anchor point to the return value of `fn`. * - * @param {Editor} editor * @param {Function} fn */ -Commands.setAnchor = (editor, fn) => { +Commands.setAnchor = (fn, editor) => value => { const { value: { selection } } = editor - const range = selection.setAnchor(fn) + const range = selection.setAnchor(value) editor.select(range) } /** * Set the selection's end point to the return value of `fn`. * - * @param {Editor} editor * @param {Function} fn */ -Commands.setEnd = (editor, fn) => { +Commands.setEnd = (fn, editor) => value => { const { value: { selection } } = editor - const range = selection.setEnd(fn) + const range = selection.setEnd(value) editor.select(range) } /** * Set the selection's focus point to the return value of `fn`. * - * @param {Editor} editor * @param {Function} fn */ -Commands.setFocus = (editor, fn) => { +Commands.setFocus = (fn, editor) => value => { const { value: { selection } } = editor - const range = selection.setFocus(fn) + const range = selection.setFocus(value) editor.select(range) } /** * Set the selection's start point to the return value of `fn`. * - * @param {Editor} editor * @param {Function} fn */ -Commands.setStart = (editor, fn) => { +Commands.setStart = (fn, editor) => value => { const { value: { selection } } = editor - const range = selection.setStart(fn) + const range = selection.setStart(value) editor.select(range) } /** * HACK: Snapshot the selection, saving an entry in the history. - * - * @param {Editor} editor */ -Commands.snapshotSelection = editor => { +Commands.snapshotSelection = (fn, editor) => () => { editor.withoutMerging(() => { editor.select(editor.value.selection, { snapshot: true }) }) @@ -2208,7 +1901,7 @@ Commands.snapshotSelection = editor => { * Deprecated. */ -Commands.moveAnchorToEndOfNode = (editor, ...args) => { +Commands.moveAnchorToEndOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveAnchorToEndOfNode(node) command is deprecated. Use the `editor.moveAnchorToEndOfPath(path)` command instead.' @@ -2219,7 +1912,7 @@ Commands.moveAnchorToEndOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveAnchorToStartOfNode = (editor, ...args) => { +Commands.moveAnchorToStartOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveAnchorToStartOfNode(node) command is deprecated. Use the `editor.moveAnchorToStartOfPath(path)` command instead.' @@ -2230,7 +1923,7 @@ Commands.moveAnchorToStartOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveEndToEndOfNode = (editor, ...args) => { +Commands.moveEndToEndOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveEndToEndOfNode(node) command is deprecated. Use the `editor.moveEndToEndOfPath(path)` command instead.' @@ -2241,7 +1934,7 @@ Commands.moveEndToEndOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveEndToStartOfNode = (editor, ...args) => { +Commands.moveEndToStartOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveEndToStartOfNode(node) command is deprecated. Use the `editor.moveEndToStartOfPath(path)` command instead.' @@ -2252,7 +1945,7 @@ Commands.moveEndToStartOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveFocusToEndOfNode = (editor, ...args) => { +Commands.moveFocusToEndOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveFocusToEndOfNode(node) command is deprecated. Use the `editor.moveFocusToEndOfPath(path)` command instead.' @@ -2263,7 +1956,7 @@ Commands.moveFocusToEndOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveFocusToStartOfNode = (editor, ...args) => { +Commands.moveFocusToStartOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveFocusToStartOfNode(node) command is deprecated. Use the `editor.moveFocusToStartOfPath(path)` command instead.' @@ -2274,7 +1967,7 @@ Commands.moveFocusToStartOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveStartToEndOfNode = (editor, ...args) => { +Commands.moveStartToEndOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveStartToEndOfNode(node) command is deprecated. Use the `editor.moveStartToEndOfPath(path)` command instead.' @@ -2285,7 +1978,7 @@ Commands.moveStartToEndOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveStartToStartOfNode = (editor, ...args) => { +Commands.moveStartToStartOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveStartToStartOfNode(node) command is deprecated. Use the `editor.moveStartToStartOfPath(path)` command instead.' @@ -2296,7 +1989,7 @@ Commands.moveStartToStartOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveToEndOfNode = (editor, ...args) => { +Commands.moveToEndOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveToEndOfNode(node) command is deprecated. Use the `editor.moveToEndOfPath(path)` command instead.' @@ -2307,7 +2000,7 @@ Commands.moveToEndOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveToRangeOfNode = (editor, ...args) => { +Commands.moveToRangeOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveToRangeOfNode(node) command is deprecated. Use the `editor.moveToRangeOfPath(path)` command instead.' @@ -2318,7 +2011,7 @@ Commands.moveToRangeOfNode = (editor, ...args) => { editor.select(range) } -Commands.moveToStartOfNode = (editor, ...args) => { +Commands.moveToStartOfNode = (fn, editor) => (...args) => { warning( false, 'As of slate@0.48 the `editor.moveToStartOfNode(node) command is deprecated. Use the `editor.moveToStartOfPath(path)` command instead.' diff --git a/packages/slate/src/commands/on-value.js b/packages/slate/src/commands/on-value.js index 4d877be186..9c4eebfb2c 100644 --- a/packages/slate/src/commands/on-value.js +++ b/packages/slate/src/commands/on-value.js @@ -13,11 +13,10 @@ const Commands = {} /** * Set `properties` on the value. * - * @param {Editor} editor * @param {Object|Value} properties */ -Commands.setData = (editor, data = {}) => { +Commands.setData = (fn, editor) => (data = {}) => { const { value } = editor const newProperties = Value.createProperties({ data }) const prevProperties = pick(value, Object.keys(newProperties)) @@ -29,7 +28,7 @@ Commands.setData = (editor, data = {}) => { }) } -Commands.addAnnotation = (editor, annotation) => { +Commands.addAnnotation = (fn, editor) => annotation => { annotation = Annotation.create(annotation) editor.applyOperation({ @@ -38,7 +37,7 @@ Commands.addAnnotation = (editor, annotation) => { }) } -Commands.removeAnnotation = (editor, annotation) => { +Commands.removeAnnotation = (fn, editor) => annotation => { annotation = Annotation.create(annotation) editor.applyOperation({ @@ -47,7 +46,7 @@ Commands.removeAnnotation = (editor, annotation) => { }) } -Commands.setAnnotation = (editor, annotation, newProperties) => { +Commands.setAnnotation = (fn, editor) => (annotation, newProperties) => { annotation = Annotation.create(annotation) newProperties = Annotation.createProperties(newProperties) diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js index 40162d239d..38c7042934 100644 --- a/packages/slate/src/commands/with-intent.js +++ b/packages/slate/src/commands/with-intent.js @@ -30,11 +30,10 @@ const Commands = {} /** * Add a `mark` to the characters in the current selection. * - * @param {Editor} editor * @param {Mark} mark */ -Commands.addMark = (editor, mark) => { +Commands.addMark = (fn, editor) => mark => { mark = Mark.create(mark) const { value } = editor const { document, selection } = value @@ -55,21 +54,19 @@ Commands.addMark = (editor, mark) => { /** * Add a list of `marks` to the characters in the current selection. * - * @param {Editor} editor * @param {Set|Array} marks */ -Commands.addMarks = (editor, marks) => { +Commands.addMarks = (fn, editor) => marks => { marks.forEach(mark => editor.addMark(mark)) } /** * Delete at the current selection. * - * @param {Editor} editor */ -Commands.delete = editor => { +Commands.delete = (fn, editor) => () => { const { value } = editor const { selection } = value editor.deleteAtRange(selection) @@ -83,11 +80,10 @@ Commands.delete = editor => { /** * Delete backward `n` characters. * - * @param {Editor} editor * @param {Number} n (optional) */ -Commands.deleteBackward = (editor, n = 1) => { +Commands.deleteBackward = (fn, editor) => (n = 1) => { const { value } = editor const { selection } = value @@ -101,10 +97,9 @@ Commands.deleteBackward = (editor, n = 1) => { /** * Delete backward one character. * - * @param {Editor} editor */ -Commands.deleteCharBackward = editor => { +Commands.deleteCharBackward = (fn, editor) => () => { const { value } = editor const { selection } = value @@ -118,10 +113,9 @@ Commands.deleteCharBackward = editor => { /** * Delete backward one line. * - * @param {Editor} editor */ -Commands.deleteLineBackward = editor => { +Commands.deleteLineBackward = (fn, editor) => () => { const { value } = editor const { selection } = value @@ -135,10 +129,9 @@ Commands.deleteLineBackward = editor => { /** * Delete backward one word. * - * @param {Editor} editor */ -Commands.deleteWordBackward = editor => { +Commands.deleteWordBackward = (fn, editor) => () => { const { value } = editor const { selection } = value @@ -152,11 +145,10 @@ Commands.deleteWordBackward = editor => { /** * Delete backward `n` characters. * - * @param {Editor} editor * @param {Number} n (optional) */ -Commands.deleteForward = (editor, n = 1) => { +Commands.deleteForward = (fn, editor) => (n = 1) => { const { value } = editor const { selection } = value @@ -170,10 +162,9 @@ Commands.deleteForward = (editor, n = 1) => { /** * Delete backward one character. * - * @param {Editor} editor */ -Commands.deleteCharForward = editor => { +Commands.deleteCharForward = (fn, editor) => () => { const { value } = editor const { selection } = value @@ -187,10 +178,9 @@ Commands.deleteCharForward = editor => { /** * Delete backward one line. * - * @param {Editor} editor */ -Commands.deleteLineForward = editor => { +Commands.deleteLineForward = (fn, editor) => () => { const { value } = editor const { selection } = value @@ -204,10 +194,9 @@ Commands.deleteLineForward = editor => { /** * Delete backward one word. * - * @param {Editor} editor */ -Commands.deleteWordForward = editor => { +Commands.deleteWordForward = (fn, editor) => () => { const { value } = editor const { selection } = value @@ -221,11 +210,10 @@ Commands.deleteWordForward = editor => { /** * Insert a `block` at the current selection. * - * @param {Editor} editor * @param {String|Object|Block} block */ -Commands.insertBlock = (editor, block) => { +Commands.insertBlock = (fn, editor) => block => { deleteExpanded(editor) block = Block.create(block) @@ -244,11 +232,10 @@ Commands.insertBlock = (editor, block) => { /** * Insert a `fragment` at the current selection. * - * @param {Editor} editor * @param {Document} fragment */ -Commands.insertFragment = (editor, fragment) => { +Commands.insertFragment = (fn, editor) => fragment => { if (!fragment.nodes.size) return deleteExpanded(editor) @@ -301,11 +288,10 @@ Commands.insertFragment = (editor, fragment) => { /** * Insert an `inline` at the current selection. * - * @param {Editor} editor * @param {String|Object|Inline} inline */ -Commands.insertInline = (editor, inline) => { +Commands.insertInline = (fn, editor) => inline => { deleteExpanded(editor) inline = Inline.create(inline) @@ -324,12 +310,11 @@ Commands.insertInline = (editor, inline) => { /** * Insert a string of `text` with optional `marks` at the current selection. * - * @param {Editor} editor * @param {String} text * @param {Set} marks (optional) */ -Commands.insertText = (editor, text, marks) => { +Commands.insertText = (fn, editor) => (text, marks) => { deleteExpanded(editor) const { value } = editor @@ -350,11 +335,10 @@ Commands.insertText = (editor, text, marks) => { /** * Remove a `mark` from the characters in the current selection. * - * @param {Editor} editor * @param {Mark} mark */ -Commands.removeMark = (editor, mark) => { +Commands.removeMark = (fn, editor) => mark => { mark = Mark.create(mark) const { value } = editor const { document, selection } = value @@ -375,12 +359,11 @@ Commands.removeMark = (editor, mark) => { /** * Replace an `oldMark` with a `newMark` in the characters in the current selection. * - * @param {Editor} editor * @param {Mark} oldMark * @param {Mark} newMark */ -Commands.replaceMark = (editor, oldMark, newMark) => { +Commands.replaceMark = (fn, editor) => (oldMark, newMark) => { editor.removeMark(oldMark) editor.addMark(newMark) } @@ -388,11 +371,10 @@ Commands.replaceMark = (editor, oldMark, newMark) => { /** * Set the `properties` of block nodes. * - * @param {Editor} editor * @param {Object|String} properties */ -Commands.setBlocks = (editor, properties) => { +Commands.setBlocks = (fn, editor) => properties => { const { value } = editor const { selection } = value editor.setBlocksAtRange(selection, properties) @@ -401,11 +383,10 @@ Commands.setBlocks = (editor, properties) => { /** * Set the `properties` of inline nodes. * - * @param {Editor} editor * @param {Object|String} properties */ -Commands.setInlines = (editor, properties) => { +Commands.setInlines = (fn, editor) => properties => { const { value } = editor const { selection } = value editor.setInlinesAtRange(selection, properties) @@ -414,11 +395,10 @@ Commands.setInlines = (editor, properties) => { /** * Split the block node at the current selection, to optional `depth`. * - * @param {Editor} editor * @param {Number} depth (optional) */ -Commands.splitBlock = (editor, depth = 1) => { +Commands.splitBlock = (fn, editor) => (depth = 1) => { deleteExpanded(editor) const { value } = editor @@ -435,11 +415,10 @@ Commands.splitBlock = (editor, depth = 1) => { /** * Split the inline nodes to optional `height`. * - * @param {Editor} editor * @param {Number} height (optional) */ -Commands.splitInline = (editor, height) => { +Commands.splitInline = (fn, editor) => height => { deleteExpanded(editor) const { value } = editor const { selection } = value @@ -450,11 +429,10 @@ Commands.splitInline = (editor, height) => { * Add or remove a `mark` from the characters in the current selection, * depending on whether it's already there. * - * @param {Editor} editor * @param {Mark} mark */ -Commands.toggleMark = (editor, mark) => { +Commands.toggleMark = (fn, editor) => mark => { mark = Mark.create(mark) const { value } = editor const exists = value.activeMarks.has(mark) @@ -469,11 +447,10 @@ Commands.toggleMark = (editor, mark) => { /** * Unwrap nodes from a block with `properties`. * - * @param {Editor} editor * @param {String|Object} properties */ -Commands.unwrapBlock = (editor, properties) => { +Commands.unwrapBlock = (fn, editor) => properties => { const { value } = editor const { selection } = value editor.unwrapBlockAtRange(selection, properties) @@ -482,11 +459,10 @@ Commands.unwrapBlock = (editor, properties) => { /** * Unwrap nodes from an inline with `properties`. * - * @param {Editor} editor * @param {String|Object} properties */ -Commands.unwrapInline = (editor, properties) => { +Commands.unwrapInline = (fn, editor) => properties => { const { value } = editor const { selection } = value editor.unwrapInlineAtRange(selection, properties) @@ -495,11 +471,10 @@ Commands.unwrapInline = (editor, properties) => { /** * Wrap nodes in a new `block`. * - * @param {Editor} editor * @param {Block|Object|String} block */ -Commands.wrapBlock = (editor, block) => { +Commands.wrapBlock = (fn, editor) => block => { const { value } = editor const { selection } = value editor.wrapBlockAtRange(selection, block) @@ -508,11 +483,10 @@ Commands.wrapBlock = (editor, block) => { /** * Wrap nodes in a new `inline`. * - * @param {Editor} editor * @param {Inline|Object|String} inline */ -Commands.wrapInline = (editor, inline) => { +Commands.wrapInline = (fn, editor) => inline => { const { value } = editor const { selection } = value editor.wrapInlineAtRange(selection, inline) @@ -521,12 +495,11 @@ Commands.wrapInline = (editor, inline) => { /** * Wrap the current selection with prefix/suffix. * - * @param {Editor} editor * @param {String} prefix * @param {String} suffix */ -Commands.wrapText = (editor, prefix, suffix = prefix) => { +Commands.wrapText = (fn, editor) => (prefix, suffix = prefix) => { const { value } = editor const { selection } = value editor.wrapTextAtRange(selection, prefix, suffix) diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index 85c1ef4b23..f223c17ad2 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -4,11 +4,9 @@ import isPlainObject from 'is-plain-object' import warning from 'tiny-warning' import { List } from 'immutable' -import CommandsPlugin from '../plugins/commands' import CorePlugin from '../plugins/core' import Operation from '../models/operation' import PathUtils from '../utils/path-utils' -import QueriesPlugin from '../plugins/queries' import SchemaPlugin from '../plugins/schema' import Value from '../models/value' @@ -44,11 +42,11 @@ class Editor { } = attrs this.controller = controller - this.middleware = {} this.onChange = onChange this.operations = List() this.readOnly = null this.value = null + this.handlers = {} this.tmp = { dirty: [], @@ -59,10 +57,10 @@ class Editor { } const core = CorePlugin({ plugins }) - registerPlugin(this, core) + registerPlugin(this, controller, core) if (construct) { - this.run('onConstruct') + this.exec('onConstruct') this.setReadOnly(readOnly) this.setValue(value, options) } @@ -76,7 +74,7 @@ class Editor { */ applyOperation(operation) { - const { operations, controller } = this + const { operations } = this let value = this.value // Add in the current `value` in case the operation was serialized. @@ -89,7 +87,7 @@ class Editor { // Save the operation into the history. Since `save` is a command, we need // to do it without normalizing, since it would have side effects. this.withoutNormalizing(() => { - controller.save(operation) + this.save(operation) value = this.value }) @@ -117,68 +115,51 @@ class Editor { } /** - * Flush the editor's current change. - * - * @return {Editor} - */ - - flush() { - this.run('onChange') - const { value, operations } = this - const change = { value, operations } - this.operations = List() - this.tmp.flushing = false - this.onChange(change) - } - - /** - * Trigger a command by `type` with `...args`. + * Exec a handler of the editor by `name` with `...args`. * - * @param {String|Function} type + * @param {String} name * @param {Any} ...args - * @return {Editor} + * @return {Any} */ - command(type, ...args) { - const { controller } = this + exec(name, ...args) { + invariant( + typeof name === 'string', + 'As of slate@0.48 the `editor.exec` method must take a name string, not a function.' + ) - if (typeof type === 'function') { - type(controller, ...args) - normalizeDirtyPaths(this) - return controller - } + invariant(this.has(name), `No editor middleware found named "${name}"!`) - debug('command', { type, args }) - const obj = { type, args } - const ret = this.run('onCommand', obj) + const fn = this.handlers[name] + const ret = fn(...args) normalizeDirtyPaths(this) return ret } /** - * Checks if a command by `type` has been registered. + * Flush the editor's current change. * - * @param {String} type - * @return {Boolean} + * @return {Editor} */ - hasCommand(type) { - const { controller } = this - const has = type in controller && controller[type].__command - return has + flush() { + this.exec('onChange') + const { value, operations } = this + const change = { value, operations } + this.operations = List() + this.tmp.flushing = false + this.onChange(change) } /** - * Checks if a query by `type` has been registered. + * Check if the editor has a handler by `name`. * - * @param {String} type + * @param {String} name * @return {Boolean} */ - hasQuery(type) { - const { controller } = this - const has = type in controller && controller[type].__query - return has + has(name) { + return name in this.handlers } /** @@ -188,7 +169,7 @@ class Editor { */ normalize() { - const { value, controller } = this + const { value } = this let { document } = value const paths = Array.from( document.descendants({ includeTarget: true, includeRoot: true }), @@ -202,149 +183,8 @@ class Editor { document = value.document if (selection.isUnset && document.nodes.size) { - controller.moveToStartOfDocument() - } - } - - /** - * Ask a query by `type` with `...args`. - * - * @param {String|Function} type - * @param {Any} ...args - * @return {Any} - */ - - query(type, ...args) { - const { controller } = this - - if (typeof type === 'function') { - return type(controller, ...args) - } - - debug('query', { type, args }) - const obj = { type, args } - return this.run('onQuery', obj) - } - - /** - * Register a command `type` with the editor. - * - * @param {String} type - * @return {Editor} - */ - - registerCommand(type) { - const { controller } = this - - if (type in controller && controller[type].__command) { - return controller - } - - invariant( - !(type in controller), - `You cannot register a \`${type}\` command because it would overwrite an existing property of the \`Editor\`.` - ) - - const method = (...args) => this.command(type, ...args) - controller[type] = method - method.__command = true - } - - /** - * Register a query `type` with the editor. - * - * @param {String} type - * @return {Editor} - */ - - registerQuery(type) { - const { controller } = this - - if (type in controller && controller[type].__query) { - return controller - } - - invariant( - !(type in controller), - `You cannot register a \`${type}\` query because it would overwrite an existing property of the \`Editor\`.` - ) - - const method = (...args) => this.query(type, ...args) - controller[type] = method - method.__query = true - } - - /** - * Run through the middleware stack by `key` with `args`. - * - * @param {String} key - * @param {Any} ...args - * @return {Any} - */ - - run(key, ...args) { - const { controller, middleware } = this - const fns = middleware[key] || [] - let i = 0 - - function next(...overrides) { - const fn = fns[i++] - if (!fn) return - - if (overrides.length) { - args = overrides - } - - const ret = fn(...args, controller, next) - return ret + this.moveToStartOfDocument() } - - Object.defineProperty(next, 'change', { - get() { - invariant( - false, - 'As of Slate 0.42, the `editor` is no longer passed as the third argument to event handlers. You can access it via `change.editor` instead.' - ) - }, - }) - - Object.defineProperty(next, 'onChange', { - get() { - invariant( - false, - 'As of Slate 0.42, the `editor` is no longer passed as the third argument to event handlers. You can access it via `change.editor` instead.' - ) - }, - }) - - Object.defineProperty(next, 'props', { - get() { - invariant( - false, - 'As of Slate 0.42, the `editor` is no longer passed as the third argument to event handlers. You can access it via `change.editor` instead.' - ) - }, - }) - - Object.defineProperty(next, 'schema', { - get() { - invariant( - false, - 'As of Slate 0.42, the `editor` is no longer passed as the third argument to event handlers. You can access it via `change.editor` instead.' - ) - }, - }) - - Object.defineProperty(next, 'stack', { - get() { - invariant( - false, - 'As of Slate 0.42, the `editor` is no longer passed as the third argument to event handlers. You can access it via `change.editor` instead.' - ) - }, - }) - - return next() } /** @@ -387,10 +227,9 @@ class Editor { */ withoutNormalizing(fn) { - const { controller } = this const value = this.tmp.normalize this.tmp.normalize = false - fn(controller) + fn() this.tmp.normalize = value normalizeDirtyPaths(this) } @@ -474,6 +313,70 @@ class Editor { return this.withoutNormalizing(fn) } + + run(fn, ...args) { + warning( + false, + 'As of slate@0.48 the `editor.run` method has been renamed to `editor.exec`.' + ) + + invariant( + typeof fn === 'string', + 'As of slate@0.48 the `editor.run` method must take a middleware name string, not a function.' + ) + + return this.exec(fn, ...args) + } + + command(type, ...args) { + warning( + false, + 'As of slate@0.48 the `editor.command` method is deprecated. Please use `editor.exec` instead.' + ) + + return this.exec(type, ...args) + } + + hasCommand(type) { + warning( + false, + 'As of slate@0.48 the `editor.hasCommand` method is deprecated. Please use `editor.has` instead.' + ) + + return this.has(type) + } + + hasQuery(type) { + warning( + false, + 'As of slate@0.48 the `editor.hasQuery` method is deprecated. Please use `editor.has` instead.' + ) + + return this.has(type) + } + + query(type, ...args) { + warning( + false, + 'As of slate@0.48 the `editor.query` method is deprecated. Please use `editor.exec` instead.' + ) + + return this.exec(type, ...args) + } + + registerCommand(type) { + invariant( + false, + 'As of slate@0.48 the `editor.registerCommand` method has been removed.' + ) + } + + registerQuery(type) { + invariant( + false, + 'As of slate@0.48 the `editor.registerQuery` method has been removed.' + ) + } } /** @@ -616,7 +519,7 @@ function normalizeNodeByPath( // Run the normalize `fn` to fix the node. const opCount = editor.operations.size - fn(controller) + fn() // Now that normalizing operations have been applied, we need to refind the // path, transformed by all the new operations. @@ -650,9 +553,13 @@ function normalizeNodeByPath( * @param {Object|Array|Null} plugin */ -function registerPlugin(editor, plugin) { +function registerPlugin(editor, controller, plugin) { if (Array.isArray(plugin)) { - plugin.forEach(p => registerPlugin(editor, p)) + plugin + .slice() + .reverse() + .forEach(p => registerPlugin(editor, controller, p)) + return } @@ -663,27 +570,54 @@ function registerPlugin(editor, plugin) { const { commands, queries, schema, ...rest } = plugin if (commands) { - const commandsPlugin = CommandsPlugin(commands) - registerPlugin(editor, commandsPlugin) + warning( + false, + 'As of slate@0.48 the `plugin.commands` dictionary is deprecated. Register the commands as top-level functions in the plugin instead.' + ) + + for (const key in commands) { + const command = commands[key] + + registerHandler(editor, controller, key, () => (...args) => + command(editor, ...args) + ) + } } if (queries) { - const queriesPlugin = QueriesPlugin(queries) - registerPlugin(editor, queriesPlugin) + warning( + false, + 'As of slate@0.48 the `plugin.queries` dictionary is deprecated. Register the queries as top-level functions in the plugin instead.' + ) + + for (const key in queries) { + const query = queries[key] + + registerHandler(editor, controller, key, () => (...args) => + query(editor, ...args) + ) + } } if (schema) { const schemaPlugin = SchemaPlugin(schema) - registerPlugin(editor, schemaPlugin) + registerPlugin(editor, controller, schemaPlugin) } for (const key in rest) { const fn = rest[key] - const middleware = (editor.middleware[key] = editor.middleware[key] || []) - middleware.push(fn) + registerHandler(editor, controller, key, fn) } } +function registerHandler(editor, controller, name, fn) { + const existing = editor.handlers[name] || noop + editor.handlers[name] = fn(existing, controller) + editor[name] = editor[name] || ((...args) => editor.exec(name, ...args)) +} + +function noop() {} + /** * Export. * diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js index 87b8000135..225f3a6459 100644 --- a/packages/slate/src/interfaces/element.js +++ b/packages/slate/src/interfaces/element.js @@ -664,7 +664,7 @@ class ElementInterface { */ getDecorations(editor) { - let decorations = editor.run('decorateNode', this) + let decorations = editor.exec('decorateNode', this) decorations = Decoration.createList(decorations) return decorations } diff --git a/packages/slate/src/interfaces/node.js b/packages/slate/src/interfaces/node.js index 5a1e2a9a87..c7024d1226 100644 --- a/packages/slate/src/interfaces/node.js +++ b/packages/slate/src/interfaces/node.js @@ -170,7 +170,7 @@ class NodeInterface { */ normalize(editor) { - const normalizer = editor.run('normalizeNode', this) + const normalizer = editor.exec('normalizeNode', this) return normalizer } @@ -221,7 +221,7 @@ class NodeInterface { */ validate(editor) { - const error = editor.run('validateNode', this) + const error = editor.exec('validateNode', this) return error } } diff --git a/packages/slate/src/plugins/core/core-commands.js b/packages/slate/src/plugins/core/core-commands.js index bbe9b92bd6..ecdf335cdb 100644 --- a/packages/slate/src/plugins/core/core-commands.js +++ b/packages/slate/src/plugins/core/core-commands.js @@ -1,6 +1,5 @@ import AtRange from '../../commands/at-range' import ByPath from '../../commands/by-path' -import Commands from '../commands' import OnHistory from '../../commands/on-history' import OnSelection from '../../commands/on-selection' import OnValue from '../../commands/on-value' @@ -13,14 +12,16 @@ import WithIntent from '../../commands/with-intent' */ function CoreCommandsPlugin() { - return Commands({ + return { + onConstruct: () => () => {}, + onChange: () => () => {}, ...AtRange, ...ByPath, ...OnHistory, ...OnSelection, ...OnValue, ...WithIntent, - }) + } } /** diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index 027539fbbb..054772dddd 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -1,6 +1,5 @@ import PathUtils from '../../utils/path-utils' import TextUtils from '../../utils/text-utils' -import Queries from '../queries' /** * A plugin that defines the core Slate query logic. @@ -9,40 +8,37 @@ import Queries from '../queries' */ function CoreQueriesPlugin() { - return Queries({ + return { /** * By default, no formats are atomic in Slate. * - * @param {Editor} editor * @param {Annotation|Decoration|Mark} object * @return {Boolean} */ - isAtomic() { + isAtomic: (fn, editor) => () => { return false }, /** * By default, no nodes are void in Slate. * - * @param {Editor} editor * @param {Node} node * @return {Boolean} */ - isVoid() { + isVoid: (fn, editor) => () => { return false }, /** * Calculate the next point forward from a `point`. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getNextPoint(editor, point, options = {}) { + getNextPoint: (fn, editor) => (point, options = {}) => { const { allowZeroWidth = false } = options const { value } = editor const { document } = value @@ -101,12 +97,11 @@ function CoreQueriesPlugin() { /** * Calculate the next character boundary from a `point`. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getNextCharacterPoint(editor, point) { + getNextCharacterPoint: (fn, editor) => point => { const { value: { document } } = editor const { path, offset } = point const [block, blockPath] = document.closestBlock(path) @@ -136,12 +131,11 @@ function CoreQueriesPlugin() { /** * Get the next point in the document that is not inside a void node. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getNextNonVoidPoint(editor, point) { + getNextNonVoidPoint: (fn, editor) => point => { const { value: { document } } = editor let next = point @@ -159,12 +153,11 @@ function CoreQueriesPlugin() { /** * Calculate the next word boundary from a `point`. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getNextWordPoint(editor, point) { + getNextWordPoint: (fn, editor) => point => { const { value: { document } } = editor const { path, offset } = point const [block, blockPath] = document.closestBlock(path) @@ -194,12 +187,11 @@ function CoreQueriesPlugin() { /** * Calculate a non-hanging range from a `range`. * - * @param {Editor} editor * @param {Range} range * @return {Range} */ - getNonHangingRange(editor, range) { + getNonHangingRange: (fn, editor) => range => { const { value: { document } } = editor const { isExpanded, start, end } = range @@ -216,12 +208,11 @@ function CoreQueriesPlugin() { /** * Calculate the previous point backward from a `point`. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getPreviousPoint(editor, point, options = {}) { + getPreviousPoint: (fn, editor) => (point, options = {}) => { const { allowZeroWidth = false } = options const { value } = editor const { document } = value @@ -281,12 +272,11 @@ function CoreQueriesPlugin() { /** * Calculate the previous character boundary from a `point`. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getPreviousCharacterPoint(editor, point) { + getPreviousCharacterPoint: (fn, editor) => point => { const { value: { document } } = editor const { path, offset } = point const [block, blockPath] = document.closestBlock(path) @@ -316,12 +306,11 @@ function CoreQueriesPlugin() { /** * Get the previous point in the document that is not inside a void node. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getPreviousNonVoidPoint(editor, point) { + getPreviousNonVoidPoint: (fn, editor) => point => { const { value: { document } } = editor let prev = point @@ -339,12 +328,11 @@ function CoreQueriesPlugin() { /** * Calculate the previous word boundary from a `point`. * - * @param {Editor} editor * @param {Point} point * @return {Point|Null} */ - getPreviousWordPoint(editor, point) { + getPreviousWordPoint: (fn, editor) => point => { const { value: { document } } = editor const { path, offset } = point const [block, blockPath] = document.closestBlock(path) @@ -370,7 +358,7 @@ function CoreQueriesPlugin() { return prev }, - }) + } } /** diff --git a/packages/slate/src/plugins/schema/index.js b/packages/slate/src/plugins/schema/index.js index 6f08129dcf..0d17dd7007 100644 --- a/packages/slate/src/plugins/schema/index.js +++ b/packages/slate/src/plugins/schema/index.js @@ -1,5 +1,4 @@ import SlateError from '../../utils/slate-error' -import Queries from '../queries' /** * Create a plugin from a `schema` definition. @@ -84,12 +83,12 @@ function SchemaPlugin(schema) { * @return {Boolean} */ - function isAtomic(editor, format) { + const isAtomic = (fn, editor) => format => { const rule = schemaRules.find( r => 'isAtomic' in r && testRules(format, r.match) ) - return rule && rule.isAtomic + return rule ? rule.isAtomic : fn(format) } /** @@ -100,12 +99,12 @@ function SchemaPlugin(schema) { * @return {Boolean} */ - function isVoid(editor, node) { + const isVoid = (fn, editor) => node => { const rule = schemaRules.find( r => 'isVoid' in r && testRules(node, r.match) ) - return rule && rule.isVoid + return rule ? rule.isVoid : fn(node) } /** @@ -118,11 +117,17 @@ function SchemaPlugin(schema) { * @return {Function|Void} */ - function normalizeNode(node, editor, next) { - const error = validateNode(node, editor, () => {}) + let validate + + const normalizeNode = (fn, editor) => node => { + if (!validate) { + validate = validateNode(() => {}, editor) + } + + const error = validate(node) if (!error) { - return next() + return fn(node) } return () => { @@ -152,12 +157,12 @@ function SchemaPlugin(schema) { * @return {Error|Void} */ - function validateNode(node, editor, next) { + const validateNode = (fn, editor) => node => { const matches = schemaRules.filter(r => testRules(node, r.match)) const failure = validateRules(node, matches, schemaRules, { every: true }) if (!failure) { - return next() + return fn(node) } const error = new SlateError(failure.code, failure) @@ -165,21 +170,12 @@ function SchemaPlugin(schema) { } /** - * On schema-related queries, respond if we can. - * - * @param {Object} query - * @param {Function} next - */ - - const queries = Queries({ isAtomic, isVoid }) - - /** - * Return the plugins. + * Return the plugin. * * @type {Object} */ - return [{ normalizeNode, validateNode }, queries] + return { normalizeNode, validateNode, isAtomic, isVoid } } /** diff --git a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-multiple-void-blocks.js b/packages/slate/test/commands/at-current-range/delete-backward/empty-after-multiple-void-blocks.js index 228f5d6a9c..3b2936c794 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-multiple-void-blocks.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/empty-after-multiple-void-blocks.js @@ -10,9 +10,13 @@ export const input = ( + + - + + + @@ -23,8 +27,11 @@ export const output = ( + - + + + diff --git a/packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js b/packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js index 6684f3854e..b2ad99d2be 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' import { Block, Text } from 'slate' -function normalizeNode(node, editor, next) { +const normalizeNode = (fn, editor) => node => { if (node.type === 'container' && node.nodes.first().type === 'container') { return () => editor.insertNodeByKey( @@ -14,9 +14,9 @@ function normalizeNode(node, editor, next) { nodes: [Text.create()], }) ) + } else { + return fn(node) } - - return next() } export const plugins = [{ normalizeNode }] diff --git a/packages/slate/test/commands/general/call/call-with-arguments.js b/packages/slate/test/commands/general/call/call-with-arguments.js deleted file mode 100644 index 8256fe19db..0000000000 --- a/packages/slate/test/commands/general/call/call-with-arguments.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -function insertBlockByType(editor, blockType) { - editor.insertBlock({ type: blockType }) -} - -export default function(editor) { - editor.command(insertBlockByType, 'image') -} - -export const input = ( - - - - one - - two - - -) - -export const output = ( - - - - - - one - two - - -) diff --git a/packages/slate/test/controllers/editor/has-command/existing-plugin.js b/packages/slate/test/controllers/editor/has-command/existing-plugin.js deleted file mode 100644 index ad7826d47e..0000000000 --- a/packages/slate/test/controllers/editor/has-command/existing-plugin.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -const plugins = [ - { - commands: { - customCommand: () => {}, - }, - }, -] - -export const input = new Editor({ plugins }) - -export default function(editor) { - return editor.hasCommand('customCommand') -} - -export const output = true diff --git a/packages/slate/test/controllers/editor/has-command/existing-registered.js b/packages/slate/test/controllers/editor/has-command/existing-registered.js deleted file mode 100644 index 09252ace47..0000000000 --- a/packages/slate/test/controllers/editor/has-command/existing-registered.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -export const input = new Editor() - -input.registerCommand('customCommand') - -export default function(editor) { - return editor.hasCommand('customCommand') -} - -export const output = true diff --git a/packages/slate/test/controllers/editor/has-command/missing-registered.js b/packages/slate/test/controllers/editor/has-command/missing-registered.js deleted file mode 100644 index cd0cf9c35b..0000000000 --- a/packages/slate/test/controllers/editor/has-command/missing-registered.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -export const input = new Editor() - -input.registerCommand('customCommand') - -export default function(editor) { - return editor.hasCommand('otherCommand') -} - -export const output = false diff --git a/packages/slate/test/controllers/editor/has-query/existing-registered.js b/packages/slate/test/controllers/editor/has-query/existing-registered.js deleted file mode 100644 index 1fa354135e..0000000000 --- a/packages/slate/test/controllers/editor/has-query/existing-registered.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -export const input = new Editor() - -input.registerQuery('customQuery') - -export default function(editor) { - return editor.hasQuery('customQuery') -} - -export const output = true diff --git a/packages/slate/test/controllers/editor/has-query/missing-plugin.js b/packages/slate/test/controllers/editor/has-query/missing-plugin.js deleted file mode 100644 index 2635fd5f56..0000000000 --- a/packages/slate/test/controllers/editor/has-query/missing-plugin.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -const plugins = [ - { - queries: { - customquery: () => {}, - }, - }, -] - -export const input = new Editor({ plugins }) - -export default function(editor) { - return editor.hasQuery('otherquery') -} - -export const output = false diff --git a/packages/slate/test/controllers/editor/has-query/missing-registered.js b/packages/slate/test/controllers/editor/has-query/missing-registered.js deleted file mode 100644 index b8109f1f66..0000000000 --- a/packages/slate/test/controllers/editor/has-query/missing-registered.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -export const input = new Editor() - -input.registerQuery('customQuery') - -export default function(editor) { - return editor.hasQuery('otherQuery') -} - -export const output = false diff --git a/packages/slate/test/controllers/editor/has-query/existing-plugin.js b/packages/slate/test/controllers/editor/has/exists.js similarity index 67% rename from packages/slate/test/controllers/editor/has-query/existing-plugin.js rename to packages/slate/test/controllers/editor/has/exists.js index a97a06b4a2..7f331fa3a3 100644 --- a/packages/slate/test/controllers/editor/has-query/existing-plugin.js +++ b/packages/slate/test/controllers/editor/has/exists.js @@ -4,16 +4,14 @@ import { Editor } from 'slate' const plugins = [ { - queries: { - customQuery: () => {}, - }, + customCommand: () => () => {}, }, ] export const input = new Editor({ plugins }) export default function(editor) { - return editor.hasQuery('customQuery') + return editor.has('customCommand') } export const output = true diff --git a/packages/slate/test/controllers/editor/has-command/missing-plugin.js b/packages/slate/test/controllers/editor/has/missing.js similarity index 100% rename from packages/slate/test/controllers/editor/has-command/missing-plugin.js rename to packages/slate/test/controllers/editor/has/missing.js From 90790eb35bbee3efdbfb6cac7b2a203b434ec14f Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 9 Jun 2019 11:45:35 -0700 Subject: [PATCH 012/165] convert deleteAtRange --- packages/slate/src/commands/at-point.js | 43 ++ packages/slate/src/commands/at-range.js | 652 ++++++------------ packages/slate/src/commands/by-path.js | 69 +- .../slate/src/plugins/core/core-commands.js | 2 + .../slate/src/plugins/core/core-queries.js | 77 ++- packages/slate/src/utils/path-utils.js | 51 +- .../delete-backward/empty-after-void-block.js | 4 +- ...d-blocks.js => empty-after-void-inline.js} | 6 - .../delete-backward/inline-after.js | 5 +- .../delete-backward/inline-before.js | 8 +- .../delete-backward/inline-inside.js | 7 +- .../inline-after-emoji.js | 5 +- .../delete-char-backward/inline-only-emoji.js | 5 +- .../inline-before-emoji.js | 5 +- .../delete-char-forward/inline-start-emoji.js | 5 +- .../delete-forward/before-inline-sibling.js | 6 +- .../empty-before-void-inline.js | 33 + .../delete-forward/inside-inline-sibling.js | 6 +- .../inline-middle-emoji.js | 1 - .../inline-after-emoji.js | 1 - .../inline-middle-emoji.js | 5 +- .../inline-middle-emoji.js | 1 - .../at-current-range/delete/across-blocks.js | 30 + .../delete/all-nested-blocks.js | 39 ++ .../delete/all-with-nested-blocks.js | 44 -- .../delete/before-inline-sibling.js | 6 +- .../delete/expanded-across-whole-mark.js | 4 +- .../delete/inside-inline-sibling.js | 5 +- .../at-current-range/delete/inside-inline.js | 31 + .../at-current-range/delete/whole-inline.js | 5 +- .../insert-text/expanded-with-mark.js | 4 +- 31 files changed, 604 insertions(+), 561 deletions(-) create mode 100644 packages/slate/src/commands/at-point.js rename packages/slate/test/commands/at-current-range/delete-backward/{empty-after-multiple-void-blocks.js => empty-after-void-inline.js} (81%) create mode 100644 packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-inline.js create mode 100644 packages/slate/test/commands/at-current-range/delete/across-blocks.js create mode 100644 packages/slate/test/commands/at-current-range/delete/all-nested-blocks.js delete mode 100644 packages/slate/test/commands/at-current-range/delete/all-with-nested-blocks.js create mode 100644 packages/slate/test/commands/at-current-range/delete/inside-inline.js diff --git a/packages/slate/src/commands/at-point.js b/packages/slate/src/commands/at-point.js new file mode 100644 index 0000000000..cea4dc8f06 --- /dev/null +++ b/packages/slate/src/commands/at-point.js @@ -0,0 +1,43 @@ +/** + * Commands. + * + * @type {Object} + */ + +const Commands = {} + +/** + * Split all of the text and inline nodes at a `point`. + * + * @param {Point} point + * @return {Point} + */ + +Commands.splitInlineAtPoint = (fn, editor) => point => { + let { value: { document } } = editor + const furthestInline = document.furthestInline(point.path) + let targetPath = point.path + + if (furthestInline) { + ;[, targetPath] = furthestInline + } + + editor.splitDescendantsByPath(targetPath, point.path, point.offset) + + document = editor.value.document + const [, nextPath] = document.nextText(point.path) + const newPoint = point + .moveTo(nextPath, 0) + .setKey(null) + .normalize(document) + + return newPoint +} + +/** + * Export. + * + * @type {Object} + */ + +export default Commands diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index d82537b1b7..0a0f2a00f7 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -2,7 +2,7 @@ import { List } from 'immutable' import Block from '../models/block' import Inline from '../models/inline' import Mark from '../models/mark' -import PathUtils from '../utils/path-utils' +import Path from '../utils/path-utils' /** * Ensure that an expanded selection is deleted first, and return the updated @@ -93,198 +93,122 @@ Commands.addMarksAtRange = (fn, editor) => (range, marks) => { */ Commands.deleteAtRange = (fn, editor) => range => { - // Snapshot the selection, which creates an extra undo save point, so that - // when you undo a delete, the expanded selection will be retained. - editor.snapshotSelection() - - const { value } = editor - const { start, end } = range - let startKey = start.key - let startOffset = start.offset - let endKey = end.key - let endOffset = end.offset - let { document } = value - let isStartVoid = document.hasVoidParent(startKey, editor) - let isEndVoid = document.hasVoidParent(endKey, editor) - let startBlock = document.getClosestBlock(startKey) - let endBlock = document.getClosestBlock(endKey) - - // Check if we have a "hanging" selection case where the even though the - // selection extends into the start of the end node, we actually want to - // ignore that for UX reasons. - const isHanging = - startOffset === 0 && - endOffset === 0 && - isStartVoid === false && - startKey === startBlock.getFirstText().key && - endKey === endBlock.getFirstText().key && - startKey !== endKey - - // If it's a hanging selection, nudge it back to end in the previous text. - if (isHanging && isEndVoid) { - const prevText = document.getPreviousText(endKey) - endKey = prevText.key - endOffset = prevText.text.length - isEndVoid = document.hasVoidParent(endKey, editor) - } - editor.withoutNormalizing(() => { - // If the start node is inside a void node, remove the void node and update - // the starting point to be right after it, continuously until the start point - // is not a void, or until the entire range is handled. - while (isStartVoid) { - const startVoid = document.getClosestVoid(startKey, editor) - const nextText = document.getNextText(startKey) - editor.removeNodeByKey(startVoid.key) - - // If the start and end keys are the same, we're done. - if (startKey === endKey) return - - // If there is no next text node, we're done. - if (!nextText) return - - // Continue... - document = editor.value.document - startKey = nextText.key - startOffset = 0 - isStartVoid = document.hasVoidParent(startKey, editor) - } - - // If the end node is inside a void node, do the same thing but backwards. But - // we don't need any aborting checks because if we've gotten this far there - // must be a non-void node that will exit the loop. - while (isEndVoid) { - const endVoid = document.getClosestVoid(endKey, editor) - const prevText = document.getPreviousText(endKey) - editor.removeNodeByKey(endVoid.key) - - // Continue... - document = editor.value.document - endKey = prevText.key - endOffset = prevText.text.length - isEndVoid = document.hasVoidParent(endKey, editor) - } - - // If the start and end key are the same, and it was a hanging selection, we - // can just remove the entire block. - if (startKey === endKey && isHanging) { - editor.removeNodeByKey(startBlock.key) - return - } else if (startKey === endKey) { - // Otherwise, if it wasn't hanging, we're inside a single text node, so we can - // simply remove the text in the range. - const index = startOffset - const length = endOffset - startOffset - editor.removeTextByKey(startKey, index, length) - return - } else { - // Otherwise, we need to recursively remove text and nodes inside the start - // block after the start offset and inside the end block before the end - // offset. Then remove any blocks that are in between the start and end - // blocks. Then finally merge the start and end nodes. - startBlock = document.getClosestBlock(startKey) - endBlock = document.getClosestBlock(endKey) - const startText = document.getNode(startKey) - const endText = document.getNode(endKey) - const startLength = startText.text.length - startOffset - const endLength = endOffset - - const ancestor = document.getCommonAncestor(startKey, endKey) - const startChild = ancestor.getFurthestChild(startKey) - const endChild = ancestor.getFurthestChild(endKey) - - const startParent = document.getParent(startBlock.key) - const startParentIndex = startParent.nodes.indexOf(startBlock) - const endParentIndex = startParent.nodes.indexOf(endBlock) - - let child - - // Iterate through all of the nodes in the tree after the start text node - // but inside the end child, and remove them. - child = startText - - while (child.key !== startChild.key) { - const parent = document.getParent(child.key) - const index = parent.nodes.indexOf(child) - const afters = parent.nodes.slice(index + 1) - - afters.reverse().forEach(node => { - editor.removeNodeByKey(node.key) - }) - - child = parent - } - - // Remove all of the middle children. - const startChildIndex = ancestor.nodes.indexOf(startChild) - const endChildIndex = ancestor.nodes.indexOf(endChild) - const middles = ancestor.nodes.slice(startChildIndex + 1, endChildIndex) - - middles.reverse().forEach(node => { - editor.removeNodeByKey(node.key) - }) - - // Remove the nodes before the end text node in the tree. - child = endText - - while (child.key !== endChild.key) { - const parent = document.getParent(child.key) - const index = parent.nodes.indexOf(child) - const befores = parent.nodes.slice(0, index) - - befores.reverse().forEach(node => { - editor.removeNodeByKey(node.key) - }) - - child = parent - } - - // Remove any overlapping text content from the leaf text nodes. - if (startLength !== 0) { - editor.removeTextByKey(startKey, startOffset, startLength) - } + // HACK: Snapshot the selection, which creates an extra undo save point, so + // that when you undo a delete, the expanded selection will be retained. We + // should find a better way to do this... + editor.snapshotSelection() - if (endLength !== 0) { - editor.removeTextByKey(endKey, 0, endOffset) - } - - // If the start and end blocks aren't the same, move and merge the end block - // into the start block. - if (startBlock.key !== endBlock.key) { - document = editor.value.document - let onlyChildAncestor - - for (const [node] of document.ancestors(endBlock.key)) { - if (node.nodes.size > 1) { - break - } else { - onlyChildAncestor = node - } - } - - // Move the end block to be right after the start block. - if (endParentIndex !== startParentIndex + 1) { - editor.moveNodeByKey( - endBlock.key, - startParent.key, - startParentIndex + 1 - ) - } + const { value: { document } } = editor + const iterable = document.descendants({ range }) + const { start, end } = range + const [startBlock, startBlockPath] = document.closestBlock(start.path) + const [endBlock, endBlockPath] = document.closestBlock(end.path) + const isAcrossBlocks = !startBlockPath.equals(endBlockPath) + const isAcrossTexts = !start.path.equals(end.path) + const entries = Array.from(iterable).reverse() + let mergePath = endBlockPath + + // COMPAT: Rich text editors have a special behavior when triple-clicking + // which results in the end point being at the start of the next block. In + // this case, they preserve the end block instead of merging it. + const isHanging = + range.isExpanded && + editor.isAtStartOfBlock(range.start) && + editor.isAtStartOfBlock(range.end) + + const isStartVoid = !!document.closest( + start.path, + n => n.object === 'block' && editor.isVoid(n) + ) + + const isEndVoid = !!document.closest( + end.path, + n => n.object === 'block' && editor.isVoid(n) + ) + + for (const [node, path] of entries) { + if (isHanging && Path.isIn(path, endBlockPath)) { + // Don't remove the end block's nodes if it's hanging. + } else if (editor.isVoid(node)) { + editor.removeNodeByPath(path) + } else if (document.closest(path, editor.isVoid)) { + // Don't bother removing children of voides. + } else if ( + Path.isChild(path, startBlockPath) || + Path.isChild(path, endBlockPath) || + (!isAcrossTexts && path.equals(start.path)) + ) { + const isAtStart = Path.isAt(path, start.path) + const isAtEnd = Path.isAt(path, end.path) + const splitEnd = isAtEnd && !editor.isAtEndOfPath(end, path) + const splitStart = isAtStart && !editor.isAtStartOfPath(start, path) + const splitLater = !isAcrossTexts && !path.equals(start.path) - // If the selection is hanging, just remove the start block, otherwise - // merge the end block into it. - if (isHanging) { - editor.removeNodeByKey(startBlock.key) - } else { - editor.mergeNodeByKey(endBlock.key) + if ( + (isAtEnd && editor.isAtStartOfPath(end, path)) || + (isAtStart && editor.isAtEndOfPath(start, path)) + ) { + // Do nothing, since it's before/after. + } else if (splitLater) { + // Don't split yet, since we're too high up. + } else if (splitEnd && splitStart) { + const newPath = Path.increment(path) + editor.splitDescendantsByPath(path, end.path, end.offset) + editor.splitDescendantsByPath(path, start.path, start.offset) + editor.removeNodeByPath(newPath) + } else if ( + splitEnd || + (isAtEnd && !splitStart && endBlock.nodes.size === 1) + ) { + editor.splitDescendantsByPath(path, end.path, end.offset) + editor.removeNodeByPath(path) + } else if ( + splitStart || + (isAtStart && !splitEnd && startBlock.nodes.size === 1) + ) { + const newPath = Path.increment(path) + editor.splitDescendantsByPath(path, start.path, start.offset) + editor.removeNodeByPath(newPath) + } else if ( + isAtStart || + isAtEnd || + Path.isBetween(path, start.path, end.path) + ) { + editor.removeNodeByPath(path) } + } else if (Path.isBetween(path, startBlockPath, endBlockPath)) { + editor.removeNodeByPath(path) - // If nested empty blocks are left over above the end block, remove them. - if (onlyChildAncestor) { - editor.removeNodeByKey(onlyChildAncestor.key) + if (Path.isYounger(path, mergePath)) { + mergePath = Path.decrement(mergePath, 1, path.size - 1) } } } + + // TODO: this `isHanging` logic could probably be simplified by editing the + // range before iterating, instead of trying to handle each edge case here. + if (isHanging && isStartVoid && !isEndVoid) { + // If the selection is hanging, and the start block was a void, it will + // have already been removed, so we do nothing. + } else if (isHanging && (isStartVoid || isEndVoid)) { + editor.removeNodeByPath(startBlockPath) + } else if (isStartVoid || isEndVoid) { + // If the selection wasn't hanging, and it started or ended in a void node + // they will have already been removed, so we're done. + } else if (isHanging) { + // If the selection was hanging, we want to remove the start block + // entirely instead of merging it with the end block. This is a rich text + // editor behavior that's fairly standard. + const newParentPath = Path.lift(startBlockPath) + const newIndex = startBlockPath.last() + 1 + editor.moveNodeByPath(mergePath, newParentPath, newIndex) + editor.removeNodeByPath(startBlockPath) + } else if (isAcrossBlocks) { + // If the selection wasn't hanging, but we were across blocks, we need to + // merge the block into the previous one. + editor.mergeBlockByPath(mergePath) + } }) } @@ -297,66 +221,7 @@ Commands.deleteAtRange = (fn, editor) => range => { Commands.deleteBackwardAtRange = (fn, editor) => (range, n = 1) => { if (range.isExpanded) { - editor.deleteAtRange(range) - return - } - - if (n === 0) { - return - } - - const { value } = editor - const { document } = value - const { start } = range - const closestVoid = document.closest(start.path, editor.isVoid) - - if (closestVoid) { - const [, voidPath] = closestVoid - editor.removeNodeByPath(voidPath) - return - } - - // If the range is at the start of the document, abort. - if (start.isAtStartOfNode(document)) { - return - } - - const block = document.getClosestBlock(start.path) - - // PERF: If the closest block is empty, remove it. This is just a shortcut, - // since merging it would result in the same outcome. - if ( - document.nodes.size !== 1 && - block && - block.text === '' && - block.nodes.size === 1 - ) { - editor.removeNodeByKey(block.key) - return - } - - // If the range is at the start of the text node, we need to figure out what - // is behind it to know how to delete... - const text = document.getDescendant(start.path) - - if (start.isAtStartOfNode(text)) { - let prev = document.getPreviousText(text.key) - const inline = document.getClosestInline(text.key) - - // If the range is at the start of the inline node, and previous text node - // is empty, take the text node before that, or "prevBlock" would be the - // same node as "block" - if (inline && prev.text === '') { - prev = document.getPreviousText(prev.key) - } - - const prevVoid = document.getClosestVoid(prev.key, editor) - - // If the previous text node has a void parent, remove it. - if (prevVoid) { - editor.removeNodeByKey(prevVoid.key) - return - } + return editor.deleteAtRange(range) } let point = range.start @@ -372,31 +237,9 @@ Commands.deleteBackwardAtRange = (fn, editor) => (range, n = 1) => { } range = range.setStart(point) - editor.deleteAtRange(range) - return + return editor.deleteAtRange(range) } -// Commands.deleteBackwardAtRange = (editor, range, n = 1) => { -// if (range.isExpanded) { -// editor.deleteAtRange(range) -// } else { -// let point = range.start - -// for (let i = 0; i < n; i++) { -// const next = editor.getPreviousPoint(point) - -// if (!next) { -// break -// } else { -// point = next -// } -// } - -// range = range.setStart(point) -// editor.deleteAtRange(range) -// } -// } - /** * Delete backward until the character boundary at a `range`. * @@ -444,101 +287,23 @@ Commands.deleteCharForwardAtRange = (fn, editor) => range => { Commands.deleteForwardAtRange = (fn, editor) => (range, n = 1) => { if (range.isExpanded) { - editor.deleteAtRange(range) - return - } - - if (n === 0) { - return - } - - const { value } = editor - const { document } = value - const { start, focus } = range - const voidParent = document.getClosestVoid(start.path, editor) - - // If the node has a void parent, delete it. - if (voidParent) { - editor.removeNodeByKey(voidParent.key) - return - } - - const block = document.getClosestBlock(start.path) - - // If the closest is not void, but empty, remove it - if ( - block && - !editor.isVoid(block) && - block.text === '' && - document.nodes.size !== 1 - ) { - const nextBlock = document.getNextBlock(block.key) - editor.removeNodeByKey(block.key) - - if (nextBlock && nextBlock.key) { - editor.moveToStartOfNode(nextBlock) - } - - return - } - - // If the range is at the start of the document, abort. - if (start.isAtEndOfNode(document)) { - return + return editor.deleteAtRange(range) } - // If the range is at the start of the text node, we need to figure out what - // is behind it to know how to delete... - const text = document.getDescendant(start.path) - - if (start.isAtEndOfNode(text)) { - const next = document.getNextText(text.key) - const nextBlock = document.getClosestBlock(next.key) - const nextVoid = document.getClosestVoid(next.key, editor) - - // If the next text node has a void parent, remove it. - if (nextVoid) { - editor.removeNodeByKey(nextVoid.key) - return - } - - // If we're deleting by one character and the previous text node is not - // inside the current block, we need to merge the two blocks together. - if (n === 1 && nextBlock !== block) { - range = range.moveFocusTo(next.key, 0) - editor.deleteAtRange(range) - return - } - } - - // If the remaining characters to the end of the node is greater than or equal - // to the number of characters to delete, just remove the characters forwards - // inside the current node. - if (n <= text.text.length - focus.offset) { - range = range.moveFocusForward(n) - editor.deleteAtRange(range) - return - } - - // Otherwise, we need to see how many nodes forwards to go. - let node = text - let offset = focus.offset - let traversed = text.text.length - focus.offset + let point = range.start - while (n > traversed) { - node = document.getNextText(node.key) - const next = traversed + node.text.length + for (let i = 0; i < n; i++) { + const next = editor.getNextPoint(point) - if (n <= next) { - offset = n - traversed + if (!next) { break } else { - traversed = next + point = next } } - range = range.moveFocusTo(node.key, offset) - editor.deleteAtRange(range) + range = range.setStart(point) + return editor.deleteAtRange(range) } /** @@ -638,7 +403,7 @@ Commands.insertBlockAtRange = (fn, editor) => (range, block) => { const { document } = value const { start } = range const [, blockPath] = document.closestBlock(start.path) - const parentPath = PathUtils.lift(blockPath) + const parentPath = Path.lift(blockPath) const index = blockPath.last() const insertionMode = getInsertionMode(editor, range) @@ -857,7 +622,7 @@ Commands.insertInlineAtRange = (fn, editor) => (range, inline) => { const { value: { document } } = editor const { start } = range const closestVoid = document.closest(start.path, editor.isVoid) - const parentPath = PathUtils.lift(start.path) + const parentPath = Path.lift(start.path) const index = start.path.last() if (closestVoid) { @@ -1034,6 +799,91 @@ Commands.splitInlineAtRange = (fn, editor) => (range, height = Infinity) => { }) } +Commands.splitInlineEdgesAtRange = (fn, editor) => range => { + editor.withoutNormalizing(() => { + const { value: { document } } = editor + let start = editor.getPreviousNonVoidPoint(range.start) + let end = editor.getNextNonVoidPoint(range.end) + const startText = document.getNode(start.path) + const endText = document.getNode(end.path) + const startFurthest = document.furthestInline(start.path) + const endFurthest = document.furthestInline(end.path) + + if (endFurthest) { + const [furthestNode, furthestPath] = endFurthest + const [lastText, lastPath] = furthestNode.lastText() + const relativePath = end.path.slice(furthestPath.size) + + if ( + end.offset !== lastText.text.length || + !relativePath.equals(lastPath) + ) { + editor.splitDescendantsByPath(furthestPath, end.path, end.offset) + } + } else if (end.offset !== 0 && end.offset !== endText.text.length) { + editor.splitNodeByPath(end.path, end.offset) + + end = end + .setPath(Path.increment(end.path)) + .setOffset(0) + .setKey(null) + .normalize(editor.value.document) + } + + if (startFurthest) { + const [furthestNode, furthestPath] = startFurthest + const [, firstPath] = furthestNode.firstText() + const relativePath = start.path.slice(furthestPath.size) + + if (start.offset !== 0 || !relativePath.equals(firstPath)) { + editor.splitDescendantsByPath(furthestPath, start.path, start.offset) + + if ( + Path.isYounger(furthestPath, end.path) || + Path.isAbove(furthestPath, end.path) || + Path.isEqual(furthestPath, end.path) + ) { + end = end + .setPath(Path.increment(end.path, 1, furthestPath.size - 1)) + .setKey(null) + .normalize(editor.value.document) + } + + start = start + .setPath( + Path.increment(furthestPath).concat(relativePath.map(() => 0)) + ) + .setOffset(0) + .setKey(null) + .normalize(editor.value.document) + } + } else if (start.offset !== 0 && start.offset !== startText.text.length) { + editor.splitNodeByPath(start.path, start.offset) + + if ( + Path.isYounger(start.path, end.path) || + Path.isAbove(start.path, end.path) || + Path.isEqual(start.path, end.path) + ) { + end = end + .setPath(Path.increment(end.path, 1, start.path.size - 1)) + .setKey(null) + .normalize(editor.value.document) + } + + start = start + .setPath(Path.increment(start.path)) + .setOffset(0) + .setKey(null) + .normalize(editor.value.document) + } + + range = range.setAnchor(start).setFocus(end) + }) + + return range +} + /** * Add or remove a `mark` from the characters at `range`, depending on whether * it's already there. @@ -1080,7 +930,7 @@ Commands.unwrapBlockAtRange = (fn, editor) => (range, properties) => { if (block.hasProperties(properties)) { return false } else { - const parentPath = PathUtils.lift(path) + const parentPath = Path.lift(path) const parent = document.getNode(parentPath) return parent && parent.hasProperties(properties) } @@ -1138,8 +988,8 @@ Commands.wrapBlockAtRange = (fn, editor) => (range, block) => { const [, firstPath] = document.closestBlock(start.path) const [, lastPath] = document.closestBlock(end.path) const ancestorPath = firstPath.equals(lastPath) - ? PathUtils.lift(firstPath) - : PathUtils.relate(firstPath, lastPath) + ? Path.lift(firstPath) + : Path.relate(firstPath, lastPath) const startIndex = firstPath.get(ancestorPath.size) const endIndex = lastPath.get(ancestorPath.size) @@ -1167,91 +1017,13 @@ Commands.wrapInlineAtRange = (fn, editor) => (range, inline) => { inline = inline.set('nodes', inline.nodes.clear()) editor.withoutNormalizing(() => { - const { value: { document } } = editor - let start = editor.getPreviousNonVoidPoint(range.start) - let end = editor.getNextNonVoidPoint(range.end) - const startText = document.getNode(start.path) - const endText = document.getNode(end.path) - const startFurthest = document.furthestInline(start.path) - const endFurthest = document.furthestInline(end.path) - - if (endFurthest) { - const [furthestNode, furthestPath] = endFurthest - const [lastText, lastPath] = furthestNode.lastText() - const relativePath = end.path.slice(furthestPath.size) - - if ( - end.offset !== lastText.text.length || - !relativePath.equals(lastPath) - ) { - editor.splitDescendantsByPath(furthestPath, end.path, end.offset) - } - } else if (end.offset !== 0 && end.offset !== endText.text.length) { - editor.splitNodeByPath(end.path, end.offset) - - end = end - .setPath(PathUtils.increment(end.path)) - .setOffset(0) - .setKey(null) - .normalize(editor.value.document) - } - - if (startFurthest) { - const [furthestNode, furthestPath] = startFurthest - const [, firstPath] = furthestNode.firstText() - const relativePath = start.path.slice(furthestPath.size) - - if (start.offset !== 0 || !relativePath.equals(firstPath)) { - editor.splitDescendantsByPath(furthestPath, start.path, start.offset) - - if ( - PathUtils.isYounger(furthestPath, end.path) || - PathUtils.isAbove(furthestPath, end.path) || - PathUtils.isEqual(furthestPath, end.path) - ) { - end = end - .setPath(PathUtils.increment(end.path, 1, furthestPath.size - 1)) - .setKey(null) - .normalize(editor.value.document) - } - - start = start - .setPath( - PathUtils.increment(furthestPath).concat(relativePath.map(() => 0)) - ) - .setOffset(0) - .setKey(null) - .normalize(editor.value.document) - } - } else if (start.offset !== 0 && start.offset !== startText.text.length) { - editor.splitNodeByPath(start.path, start.offset) - - if ( - PathUtils.isYounger(start.path, end.path) || - PathUtils.isAbove(start.path, end.path) || - PathUtils.isEqual(start.path, end.path) - ) { - end = end - .setPath(PathUtils.increment(end.path, 1, start.path.size - 1)) - .setKey(null) - .normalize(editor.value.document) - } - - start = start - .setPath(PathUtils.increment(start.path)) - .setOffset(0) - .setKey(null) - .normalize(editor.value.document) - } - - range = range.setAnchor(start).setFocus(end) + range = editor.splitInlineEdgesAtRange(range) range = editor.getNonHangingRange(range) - const iterable = editor.value.document.blocks({ range, onlyLeaves: true }) for (const [block, blockPath] of iterable) { - const isStart = PathUtils.isAbove(blockPath, range.start.path) - const isEnd = PathUtils.isAbove(blockPath, range.end.path) + const isStart = Path.isAbove(blockPath, range.start.path) + const isEnd = Path.isAbove(blockPath, range.end.path) const startIndex = isStart ? range.start.path.get(blockPath.size) : 0 const endIndex = isEnd ? range.end.path.get(blockPath.size) diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index bbe326d208..220e9d8d19 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -154,31 +154,64 @@ Commands.insertTextByPath = (fn, editor) => (path, offset, text, marks) => { */ Commands.mergeNodeByPath = (fn, editor) => path => { - const { value } = editor - const { document } = value - const original = document.getDescendant(path) - const previous = document.getPreviousSibling(path) - - if (!previous) { - throw new Error( - `Unable to merge node with path "${path}", because it has no previous sibling.` - ) - } - - const position = - previous.object === 'text' ? previous.text.length : previous.nodes.size + const { value: { document } } = editor + const node = document.assertNode(path) + const prevPath = PathUtils.decrement(path) + const prev = document.assertNode(prevPath) + const position = prev.object === 'text' ? prev.text.length : prev.nodes.size editor.applyOperation({ type: 'merge_node', path, position, - // for undos to succeed we only need the type and data because - // these are the only properties that get changed in the merge operation + target: null, properties: { - type: original.type, - data: original.data, + type: node.type, + data: node.data, }, - target: null, + }) +} + +Commands.mergeBlockByPath = (fn, editor) => path => { + editor.withoutNormalizing(() => { + const { value: { document } } = editor + document.assertNode(path) + + const node = document.assertNode(path) + let blockPath + + // HACK: this should not be required, but since `closest` doesn't match the + // current node first, we have to do this, since people can pass in the path + // of the block to merge. + if (node.object === 'block') { + blockPath = path + } else { + ;[, blockPath] = document.closestBlock(path) + } + + const prevBlock = document.previousBlock(path, { onlyLeaves: true }) + + if (!prevBlock) { + return + } + + const [, prevPath] = prevBlock + const newParentPath = PathUtils.lift(prevPath) + const newIndex = prevPath.last() + 1 + const newPath = newParentPath.concat(newIndex) + + editor.moveNodeByPath(blockPath, newParentPath, newIndex) + editor.mergeNodeByPath(newPath) + + for (const [ancestor, ancestorPath] of document.ancestors(blockPath)) { + if (ancestorPath.equals(newParentPath)) { + break + } + + if (ancestor.nodes.size === 1) { + editor.removeNodeByPath(ancestorPath) + } + } }) } diff --git a/packages/slate/src/plugins/core/core-commands.js b/packages/slate/src/plugins/core/core-commands.js index ecdf335cdb..800144ae17 100644 --- a/packages/slate/src/plugins/core/core-commands.js +++ b/packages/slate/src/plugins/core/core-commands.js @@ -1,3 +1,4 @@ +import AtPoint from '../../commands/at-point' import AtRange from '../../commands/at-range' import ByPath from '../../commands/by-path' import OnHistory from '../../commands/on-history' @@ -15,6 +16,7 @@ function CoreCommandsPlugin() { return { onConstruct: () => () => {}, onChange: () => () => {}, + ...AtPoint, ...AtRange, ...ByPath, ...OnHistory, diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index 054772dddd..fa30d30ed5 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -10,9 +10,9 @@ import TextUtils from '../../utils/text-utils' function CoreQueriesPlugin() { return { /** - * By default, no formats are atomic in Slate. + * Check whether a `format` is atomic, defaults to false. * - * @param {Annotation|Decoration|Mark} object + * @param {Annotation|Decoration|Mark} format * @return {Boolean} */ @@ -21,7 +21,60 @@ function CoreQueriesPlugin() { }, /** - * By default, no nodes are void in Slate. + * Check whether a `range` is hanging. + * + * @param {Range} range + * @return {Boolean} + */ + + isHanging: (fn, editor) => range => { + const { isExpanded, start, end } = range + return isExpanded && end.offset === 0 && !start.path.equals(end.path) + }, + + isHangingBlock: (fn, editor) => range => { + const { value: { document } } = editor + const { isExpanded, start, end } = range + const [, endBlockPath] = document.closestBlock(end.path) + const [, firstTextPath] = document.firstText({ path: endBlockPath }) + + return ( + isExpanded && + end.offset === 0 && + !start.path.equals(end.path) && + end.path.equals(firstTextPath) + ) + }, + + isAtStartOfBlock: (fn, editor) => point => { + const { value: { document } } = editor + const [, blockPath] = document.closestBlock(point.path) + const [, firstTextPath] = document.firstText({ path: blockPath }) + return point.offset === 0 && point.path.equals(firstTextPath) + }, + + isAtStartOfPath: (fn, editor) => (point, path) => { + const { value: { document } } = editor + const [, firstPath] = document.firstText({ path }) + return point.offset === 0 && point.path.equals(firstPath) + }, + + isAtEndOfPath: (fn, editor) => (point, path) => { + const { value: { document } } = editor + const [firstNode, firstPath] = document.firstText({ path }) + return ( + point.offset === firstNode.text.length && point.path.equals(firstPath) + ) + }, + + isAtEdgeOfPath: (fn, editor) => (point, path) => { + return ( + editor.isAtStartOfPath(point, path) || editor.isAtEndOfPath(point, path) + ) + }, + + /** + * Check whether a `node` is void, defaults to false. * * @param {Node} node * @return {Boolean} @@ -75,11 +128,15 @@ function CoreQueriesPlugin() { } } + // If the point is now inside a new void node, no matter if the void + // node is zero-width, we still count it as a new point. + const nextClosestVoid = document.closest(nextPath, editor.isVoid) + // If the text node and we're still in the same block, continue onwards // because we need to have moved one point forwards, and an empty text // will be perceived as not moving. if (nextNode.text.length === 0) { - if (allowZeroWidth) { + if (nextClosestVoid || allowZeroWidth) { const next = point.moveTo(nextPath, 0) return next.normalize(document) } else { @@ -193,12 +250,12 @@ function CoreQueriesPlugin() { getNonHangingRange: (fn, editor) => range => { const { value: { document } } = editor - const { isExpanded, start, end } = range + const { end } = range - if (isExpanded && end.offset === 0 && !start.path.equals(end.path)) { + if (editor.isHanging(range)) { const [prevText, prevPath] = document.previousText(end.path) const newEnd = end.moveTo(prevPath, prevText.text.length) - const nonHanging = range.setEnd(newEnd) + const nonHanging = range.setEnd(newEnd).normalize(document) return nonHanging } else { return range @@ -250,11 +307,15 @@ function CoreQueriesPlugin() { } } + // If the point is now inside a new void node, no matter if the void + // node is zero-width, we still count it as a new point. + const prevClosestVoid = document.closest(prevPath, editor.isVoid) + // If the text node and we're still in the same block, continue onwards // because we need to have moved one point backwards, and an empty text // will be perceived as not moving. if (prevNode.text.length === 0) { - if (allowZeroWidth) { + if (prevClosestVoid || allowZeroWidth) { const prev = point.moveTo(prevPath, 0) return prev.normalize(document) } else { diff --git a/packages/slate/src/utils/path-utils.js b/packages/slate/src/utils/path-utils.js index bff28ac046..0e03a7ddf1 100644 --- a/packages/slate/src/utils/path-utils.js +++ b/packages/slate/src/utils/path-utils.js @@ -131,7 +131,12 @@ function increment(path, n = 1, index = path.size - 1) { function isAbove(path, target) { const [p, t] = crop(path, target) - return path.size < target.size && compare(p, t) === 0 + return path.size < target.size && isEqual(p, t) +} + +function isUnder(path, target) { + const [p, t] = crop(path, target) + return path.size > target.size && isEqual(p, t) } /** @@ -160,6 +165,23 @@ function isBefore(path, target) { return compare(p, t) === -1 } +/** + * Is a `path` a chidl of `target` path? + * + * @param {List} path + * @param {List} target + * @return {Boolean} + */ + +function isChild(path, target) { + if (path.size !== target.size + 1) { + return false + } + + const [p, t] = crop(path, target) + return p.equals(t) +} + /** * Is a `path` equal to another `target` path in a document? * @@ -189,6 +211,10 @@ function isOlder(path, target) { return isEqual(p, t) && pl > tl } +function isOlderSibling(path, target) { + return isSibling(path, target) && isOlder(path, target) +} + /** * Is an `any` object a path? * @@ -235,6 +261,10 @@ function isYounger(path, target) { return isEqual(p, t) && pl < tl } +function isYoungerSibling(path, target) { + return isSibling(path, target) && isYounger(path, target) +} + /** * Lift a `path` to refer to its `n`th ancestor. * @@ -416,6 +446,18 @@ function transform(path, operation) { * @type {Object} */ +function isAt(path, target) { + return isEqual(path, target) || isAbove(path, target) +} + +function isBetween(path, start, end) { + return isAfter(path, start) && isBefore(path, end) +} + +function isIn(path, target) { + return isEqual(path, target) || isUnder(path, target) +} + export default { compare, contains, @@ -438,4 +480,11 @@ export default { min, relate, transform, + isChild, + isOlderSibling, + isAt, + isYoungerSibling, + isBetween, + isUnder, + isIn, } diff --git a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-block.js b/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-block.js index b43f35ab3e..b57ff90dff 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-block.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-block.js @@ -20,9 +20,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-multiple-void-blocks.js b/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-inline.js similarity index 81% rename from packages/slate/test/commands/at-current-range/delete-backward/empty-after-multiple-void-blocks.js rename to packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-inline.js index 3b2936c794..13acf32749 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-multiple-void-blocks.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-inline.js @@ -10,15 +10,12 @@ export const input = ( - - - ) @@ -27,13 +24,10 @@ export const output = ( - - - ) diff --git a/packages/slate/test/commands/at-current-range/delete-backward/inline-after.js b/packages/slate/test/commands/at-current-range/delete-backward/inline-after.js index 4a0de145bd..42359e0f34 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/inline-after.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/inline-after.js @@ -20,8 +20,9 @@ export const output = ( - onetwo - + one + two + diff --git a/packages/slate/test/commands/at-current-range/delete-backward/inline-before.js b/packages/slate/test/commands/at-current-range/delete-backward/inline-before.js index 0c09480259..62c17209a4 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/inline-before.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/inline-before.js @@ -12,6 +12,7 @@ export const input = ( a two + @@ -21,8 +22,11 @@ export const output = ( - - two + + + two + + diff --git a/packages/slate/test/commands/at-current-range/delete-backward/inline-inside.js b/packages/slate/test/commands/at-current-range/delete-backward/inline-inside.js index 1399c13b49..ee4a7e7419 100644 --- a/packages/slate/test/commands/at-current-range/delete-backward/inline-inside.js +++ b/packages/slate/test/commands/at-current-range/delete-backward/inline-inside.js @@ -22,9 +22,10 @@ export const output = ( - one - - two + one + + + two diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-after-emoji.js b/packages/slate/test/commands/at-current-range/delete-char-backward/inline-after-emoji.js index 06f0bda1a4..c4dc78349f 100644 --- a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-after-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-char-backward/inline-after-emoji.js @@ -20,8 +20,9 @@ export const output = ( - word - + + word + diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-only-emoji.js b/packages/slate/test/commands/at-current-range/delete-char-backward/inline-only-emoji.js index d83c039a3f..94f7dd4c9d 100644 --- a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-only-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-char-backward/inline-only-emoji.js @@ -22,9 +22,8 @@ export const output = ( - - - + + diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/inline-before-emoji.js b/packages/slate/test/commands/at-current-range/delete-char-forward/inline-before-emoji.js index a50875d7ae..fdf6e04392 100644 --- a/packages/slate/test/commands/at-current-range/delete-char-forward/inline-before-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-char-forward/inline-before-emoji.js @@ -20,8 +20,9 @@ export const output = ( - - word + + word + diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/inline-start-emoji.js b/packages/slate/test/commands/at-current-range/delete-char-forward/inline-start-emoji.js index 8a7879fe5b..c1fc23d83f 100644 --- a/packages/slate/test/commands/at-current-range/delete-char-forward/inline-start-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-char-forward/inline-start-emoji.js @@ -22,9 +22,8 @@ export const output = ( - - word - + + word diff --git a/packages/slate/test/commands/at-current-range/delete-forward/before-inline-sibling.js b/packages/slate/test/commands/at-current-range/delete-forward/before-inline-sibling.js index 9fa865a27f..fdef4ed5c7 100644 --- a/packages/slate/test/commands/at-current-range/delete-forward/before-inline-sibling.js +++ b/packages/slate/test/commands/at-current-range/delete-forward/before-inline-sibling.js @@ -21,8 +21,10 @@ export const output = ( - onetwo - + one + two + + diff --git a/packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-inline.js b/packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-inline.js new file mode 100644 index 0000000000..4370d44c1b --- /dev/null +++ b/packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-inline.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.deleteForward() +} + +export const input = ( + + + + + + + + + + + +) + +export const output = ( + + + + + + + + + +) diff --git a/packages/slate/test/commands/at-current-range/delete-forward/inside-inline-sibling.js b/packages/slate/test/commands/at-current-range/delete-forward/inside-inline-sibling.js index 4b315e99d0..685312a51c 100644 --- a/packages/slate/test/commands/at-current-range/delete-forward/inside-inline-sibling.js +++ b/packages/slate/test/commands/at-current-range/delete-forward/inside-inline-sibling.js @@ -22,9 +22,9 @@ export const output = ( - one - - two + one + + two diff --git a/packages/slate/test/commands/at-current-range/delete-line-forward/inline-middle-emoji.js b/packages/slate/test/commands/at-current-range/delete-line-forward/inline-middle-emoji.js index bf1ba92890..a4af45b8f7 100644 --- a/packages/slate/test/commands/at-current-range/delete-line-forward/inline-middle-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-line-forward/inline-middle-emoji.js @@ -22,7 +22,6 @@ export const output = ( - diff --git a/packages/slate/test/commands/at-current-range/delete-word-backward/inline-after-emoji.js b/packages/slate/test/commands/at-current-range/delete-word-backward/inline-after-emoji.js index e5dabbdaf7..3afd1a3960 100644 --- a/packages/slate/test/commands/at-current-range/delete-word-backward/inline-after-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-word-backward/inline-after-emoji.js @@ -20,7 +20,6 @@ export const output = ( - diff --git a/packages/slate/test/commands/at-current-range/delete-word-backward/inline-middle-emoji.js b/packages/slate/test/commands/at-current-range/delete-word-backward/inline-middle-emoji.js index 95fa1d3ae5..859662a09f 100644 --- a/packages/slate/test/commands/at-current-range/delete-word-backward/inline-middle-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-word-backward/inline-middle-emoji.js @@ -22,9 +22,8 @@ export const output = ( - - - + + diff --git a/packages/slate/test/commands/at-current-range/delete-word-forward/inline-middle-emoji.js b/packages/slate/test/commands/at-current-range/delete-word-forward/inline-middle-emoji.js index abe7e59ef3..780637ea76 100644 --- a/packages/slate/test/commands/at-current-range/delete-word-forward/inline-middle-emoji.js +++ b/packages/slate/test/commands/at-current-range/delete-word-forward/inline-middle-emoji.js @@ -22,7 +22,6 @@ export const output = ( - diff --git a/packages/slate/test/commands/at-current-range/delete/across-blocks.js b/packages/slate/test/commands/at-current-range/delete/across-blocks.js new file mode 100644 index 0000000000..6b0276cefd --- /dev/null +++ b/packages/slate/test/commands/at-current-range/delete/across-blocks.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.delete() +} + +export const input = ( + + + + word + + + another + + + +) + +export const output = ( + + + + woother + + + +) diff --git a/packages/slate/test/commands/at-current-range/delete/all-nested-blocks.js b/packages/slate/test/commands/at-current-range/delete/all-nested-blocks.js new file mode 100644 index 0000000000..76fb368803 --- /dev/null +++ b/packages/slate/test/commands/at-current-range/delete/all-nested-blocks.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.delete() +} + +export const input = ( + + + + + one + + + two + + + three + + + + + + +) + +export const output = ( + + + + + + + + + +) diff --git a/packages/slate/test/commands/at-current-range/delete/all-with-nested-blocks.js b/packages/slate/test/commands/at-current-range/delete/all-with-nested-blocks.js deleted file mode 100644 index eaa79a48ef..0000000000 --- a/packages/slate/test/commands/at-current-range/delete/all-with-nested-blocks.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.delete() -} - -export const input = ( - - - - - one - - - two - three - - four - - - {' '} - five - - - - - - - -) - -export const output = ( - - - - - - - - - -) diff --git a/packages/slate/test/commands/at-current-range/delete/before-inline-sibling.js b/packages/slate/test/commands/at-current-range/delete/before-inline-sibling.js index 506d5b150a..f2cae192ae 100644 --- a/packages/slate/test/commands/at-current-range/delete/before-inline-sibling.js +++ b/packages/slate/test/commands/at-current-range/delete/before-inline-sibling.js @@ -21,8 +21,10 @@ export const output = ( - onetwo - + one + two + + diff --git a/packages/slate/test/commands/at-current-range/delete/expanded-across-whole-mark.js b/packages/slate/test/commands/at-current-range/delete/expanded-across-whole-mark.js index 2f220ad7d1..c48c5bc518 100644 --- a/packages/slate/test/commands/at-current-range/delete/expanded-across-whole-mark.js +++ b/packages/slate/test/commands/at-current-range/delete/expanded-across-whole-mark.js @@ -26,9 +26,7 @@ export const output = ( - - - + diff --git a/packages/slate/test/commands/at-current-range/delete/inside-inline-sibling.js b/packages/slate/test/commands/at-current-range/delete/inside-inline-sibling.js index 56641deccb..6c84852576 100644 --- a/packages/slate/test/commands/at-current-range/delete/inside-inline-sibling.js +++ b/packages/slate/test/commands/at-current-range/delete/inside-inline-sibling.js @@ -22,9 +22,8 @@ export const output = ( - one - - two + one + two diff --git a/packages/slate/test/commands/at-current-range/delete/inside-inline.js b/packages/slate/test/commands/at-current-range/delete/inside-inline.js new file mode 100644 index 0000000000..189d6fa27c --- /dev/null +++ b/packages/slate/test/commands/at-current-range/delete/inside-inline.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.delete() +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + wod + + + + +) diff --git a/packages/slate/test/commands/at-current-range/delete/whole-inline.js b/packages/slate/test/commands/at-current-range/delete/whole-inline.js index 602317162e..95e218c2f0 100644 --- a/packages/slate/test/commands/at-current-range/delete/whole-inline.js +++ b/packages/slate/test/commands/at-current-range/delete/whole-inline.js @@ -22,9 +22,8 @@ export const output = ( - - - + + diff --git a/packages/slate/test/commands/at-current-range/insert-text/expanded-with-mark.js b/packages/slate/test/commands/at-current-range/insert-text/expanded-with-mark.js index be57764c37..02c2e0bfbb 100644 --- a/packages/slate/test/commands/at-current-range/insert-text/expanded-with-mark.js +++ b/packages/slate/test/commands/at-current-range/insert-text/expanded-with-mark.js @@ -27,9 +27,7 @@ export const output = ( - - ab - + ab From 0fd0cb0a19183fd0866ed9bd740dfe8c56ae347a Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 27 Aug 2019 16:29:38 -0400 Subject: [PATCH 013/165] remove key usage from schema, deprecate *ByKey methods --- packages/slate/src/commands/at-range.js | 28 +-- packages/slate/src/commands/by-path.js | 103 +++++++-- packages/slate/src/commands/with-intent.js | 16 +- packages/slate/src/interfaces/node.js | 8 +- .../slate/src/plugins/core/core-schema.js | 63 ++--- packages/slate/src/plugins/schema/index.js | 216 +++++++++++------- .../with-plugin-normalization.js | 62 ----- .../test/controllers/editor/has/missing.js | 6 +- .../history/undo/move-node-affecting-path.js | 3 +- .../history/undo/move-node-before-itself.js | 3 +- .../test/history/undo/move-node-by-key.js | 3 +- ...move-node-by-path-ancestor-left-sibling.js | 7 +- .../test/history/undo/move-node-by-path.js | 7 +- ...hild-kind-invalid-custom-optional-first.js | 6 +- .../custom/child-kind-invalid-custom.js | 4 +- .../schema/custom/child-max-invalid-custom.js | 4 +- .../custom/child-min-invalid-at-end-custom.js | 4 +- .../schema/custom/child-min-invalid-custom.js | 6 +- .../custom/child-type-invalid-custom.js | 4 +- .../schema/custom/child-unknown-custom.js | 11 +- .../custom/first-child-kind-invalid-custom.js | 4 +- .../custom/first-child-type-invalid-custom.js | 4 +- .../custom/last-child-kind-invalid-custom.js | 4 +- .../custom/last-child-type-invalid-custom.js | 4 +- .../schema/custom/next-kind-invalid-custom.js | 4 +- .../schema/custom/next-type-invalid-custom.js | 4 +- .../schema/custom/node-data-invalid-custom.js | 4 +- .../schema/custom/node-mark-invalid-custom.js | 4 +- .../schema/custom/node-text-invalid-custom.js | 4 +- .../custom/parent-kind-invalid-custom.js | 4 +- .../custom/parent-type-invalid-custom.js | 4 +- .../custom/previous-kind-invalid-custom.js | 4 +- .../custom/previous-type-invalid-custom.js | 6 +- 33 files changed, 327 insertions(+), 291 deletions(-) delete mode 100644 packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 0a0f2a00f7..d85e9da604 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -403,21 +403,20 @@ Commands.insertBlockAtRange = (fn, editor) => (range, block) => { const { document } = value const { start } = range const [, blockPath] = document.closestBlock(start.path) - const parentPath = Path.lift(blockPath) - const index = blockPath.last() + const afterPath = Path.increment(blockPath) const insertionMode = getInsertionMode(editor, range) if (insertionMode === 'before') { - editor.insertNodeByPath(parentPath, index, block) + editor.insertNodeByPath(blockPath, block) } else if (insertionMode === 'after') { - editor.insertNodeByPath(parentPath, index + 1, block) + editor.insertNodeByPath(afterPath, block) } else { const point = editor.getNextNonVoidPoint(start) || editor.getPreviousNonVoidPoint(start) editor.withoutNormalizing(() => { editor.splitDescendantsByPath(blockPath, point.path, point.offset) - editor.insertNodeByPath(parentPath, index + 1, block) + editor.insertNodeByPath(afterPath, block) }) } } @@ -620,17 +619,16 @@ Commands.insertInlineAtRange = (fn, editor) => (range, inline) => { inline = Inline.create(inline) range = deleteExpandedAtRange(editor, range) const { value: { document } } = editor - const { start } = range - const closestVoid = document.closest(start.path, editor.isVoid) - const parentPath = Path.lift(start.path) - const index = start.path.last() + const { start: { path, offset } } = range + const insertPath = Path.increment(path) + const closestVoid = document.closest(path, editor.isVoid) if (closestVoid) { return } - editor.splitNodeByPath(start.path, start.offset) - editor.insertNodeByPath(parentPath, index + 1, inline) + editor.splitNodeByPath(path, offset) + editor.insertNodeByPath(insertPath, inline) }) } @@ -764,7 +762,7 @@ Commands.splitBlockAtRange = (fn, editor) => (range, height = 1) => { } if (targetPath) { - editor.splitDescendantsByKey(targetPath, start.path, start.offset) + editor.splitDescendantsByPath(targetPath, start.path, start.offset) } }) } @@ -995,7 +993,8 @@ Commands.wrapBlockAtRange = (fn, editor) => (range, block) => { const endIndex = lastPath.get(ancestorPath.size) editor.withoutNormalizing(() => { - editor.insertNodeByPath(ancestorPath, startIndex, block) + const targetPath = ancestorPath.concat([startIndex]) + editor.insertNodeByPath(targetPath, block) for (let i = 0; i <= endIndex - startIndex; i++) { const path = ancestorPath.concat(startIndex + 1) @@ -1029,7 +1028,8 @@ Commands.wrapInlineAtRange = (fn, editor) => (range, inline) => { ? range.end.path.get(blockPath.size) : block.nodes.size - 1 - editor.insertNodeByPath(blockPath, startIndex, inline) + const targetPath = blockPath.concat([startIndex]) + editor.insertNodeByPath(targetPath, inline) // HACK: need to regenerate the key to ensure that subsequent inserts // don't re-use the same key. inline = inline.regenerateKey() diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index 220e9d8d19..8bb1238886 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -1,4 +1,6 @@ import pick from 'lodash/pick' +import warning from 'tiny-warning' + import Block from '../models/block' import Inline from '../models/inline' import Mark from '../models/mark' @@ -77,8 +79,25 @@ Commands.addMarksByPath = (fn, editor) => (path, offset, length, marks) => { */ Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { + if (typeof index === 'number' && fragment) { + warning( + false, + `As of slate@0.48 the \`editor.insertFragmentByPath\` command takes \`(targetPath, fragment)\`, instead of a \`(parentPath, index, fragment)\`.` + ) + + path = path.concat(index) + index = null + } else { + fragment = index + index = null + } + + const parentPath = PathUtils.lift(path) + const start = path.last() + fragment.nodes.forEach((node, i) => { - editor.insertNodeByPath(path, index + i, node) + const targetPath = parentPath.concat([start + i]) + editor.insertNodeByPath(targetPath, node) }) } @@ -91,9 +110,22 @@ Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { */ Commands.insertNodeByPath = (fn, editor) => (path, index, node) => { + if (typeof index === 'number' && node) { + warning( + false, + `As of slate@0.48 the \`editor.insertNodeByPath\` command takes \`(targetPath, node)\`, instead of a \`(parentPath, index, node)\`.` + ) + + path = path.concat(index) + index = null + } else { + node = index + index = null + } + editor.applyOperation({ type: 'insert_node', - path: path.concat(index), + path, node, }) } @@ -223,14 +255,22 @@ Commands.mergeBlockByPath = (fn, editor) => path => { * @param {Number} newIndex */ -Commands.moveNodeByPath = (fn, editor) => (path, newParentPath, newIndex) => { - // If the operation path and newParentPath are the same, - // this should be considered a NOOP - if (PathUtils.isEqual(path, newParentPath)) { - return editor +Commands.moveNodeByPath = (fn, editor) => (path, newPath, index) => { + if (typeof index === 'number') { + warning( + false, + `As of slate@0.48 the \`editor.moveNodeByPath\` command takes \`(oldPath, newPath)\`, instead of a \`(oldPath, newParentPath, index)\`.` + ) + + newPath = newPath.concat(index) + index = null } - const newPath = newParentPath.concat(newIndex) + // It doesn't make sense to move a node into itself, so abort. + // TODO: This should probably throw an error instead? + if (PathUtils.isAbove(path, newPath)) { + return editor + } if (PathUtils.isEqual(path, newPath)) { return editor @@ -342,6 +382,20 @@ Commands.removeNodeByPath = (fn, editor) => path => { }) } +Commands.removeChildrenByPath = (fn, editor) => path => { + const { value: { document } } = editor + const node = document.assertNode(path) + + editor.withoutNormalizing(() => { + const { size } = node.nodes + const childPath = path.concat([0]) + + for (let i = 0; i < size; i++) { + editor.removeNodeByPath(childPath) + } + }) +} + /** * Remove text at `offset` and `length` in node by `path`. * @@ -393,14 +447,12 @@ Commands.removeTextByPath = (fn, editor) => (path, offset, length) => { * @param {Object|Node} node */ -Commands.replaceNodeByPath = (fn, editor) => (path, newNode) => { - newNode = Node.create(newNode) - const index = path.last() - const parentPath = PathUtils.lift(path) +Commands.replaceNodeByPath = (fn, editor) => (path, node) => { + node = Node.create(node) editor.withoutNormalizing(() => { editor.removeNodeByPath(path) - editor.insertNodeByPath(parentPath, index, newNode) + editor.insertNodeByPath(path, node) }) } @@ -563,7 +615,7 @@ Commands.splitDescendantsByPath = (fn, editor) => ( let lastPath = textPath editor.withoutNormalizing(() => { - editor.splitNodeByKey(textPath, textOffset) + editor.splitNodeByPath(textPath, textOffset) for (const [, ancestorPath] of document.ancestors(textPath)) { const target = index @@ -689,12 +741,10 @@ Commands.unwrapChildrenByPath = (fn, editor) => path => { Commands.wrapBlockByPath = (fn, editor) => (path, block) => { block = Block.create(block) block = block.set('nodes', block.nodes.clear()) - const parentPath = PathUtils.lift(path) - const index = path.last() const newPath = PathUtils.increment(path) editor.withoutNormalizing(() => { - editor.insertNodeByPath(parentPath, index, block) + editor.insertNodeByPath(path, block) editor.moveNodeByPath(newPath, path, 0) }) } @@ -709,12 +759,10 @@ Commands.wrapBlockByPath = (fn, editor) => (path, block) => { Commands.wrapInlineByPath = (fn, editor) => (path, inline) => { inline = Inline.create(inline) inline = inline.set('nodes', inline.nodes.clear()) - const parentPath = PathUtils.lift(path) - const index = path.last() const newPath = PathUtils.increment(path) editor.withoutNormalizing(() => { - editor.insertNodeByPath(parentPath, index, inline) + editor.insertNodeByPath(path, inline) editor.moveNodeByPath(newPath, path, 0) }) } @@ -767,6 +815,11 @@ const COMMANDS = [ for (const method of COMMANDS) { Commands[`${method}ByKey`] = (fn, editor) => (key, ...args) => { + warning( + false, + `As of slate@0.48 the \`editor.${method}ByKey\` command is deprecated. Use the \`editor.${method}ByPath\` command instead.` + ) + const { value } = editor const { document } = value const path = document.assertPath(key) @@ -776,6 +829,11 @@ for (const method of COMMANDS) { // Moving nodes takes two keys, so it's slightly different. Commands.moveNodeByKey = (fn, editor) => (key, newKey, ...args) => { + warning( + false, + `As of slate@0.48 the \`editor.moveNodeByKey\` command is deprecated. Use the \`editor.moveNodeByPath\` command instead.` + ) + const { value } = editor const { document } = value const path = document.assertPath(key) @@ -785,6 +843,11 @@ Commands.moveNodeByKey = (fn, editor) => (key, newKey, ...args) => { // Splitting descendants takes two keys, so it's slightly different. Commands.splitDescendantsByKey = (fn, editor) => (key, textKey, ...args) => { + warning( + false, + `As of slate@0.48 the \`editor.splitDescendantsByKey\` command is deprecated. Use the \`editor.splitDescendantsByPath\` command instead.` + ) + const { value } = editor const { document } = value const path = document.assertPath(key) diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js index 38c7042934..9e9571afd4 100644 --- a/packages/slate/src/commands/with-intent.js +++ b/packages/slate/src/commands/with-intent.js @@ -221,12 +221,8 @@ Commands.insertBlock = (fn, editor) => block => { const { selection } = value editor.insertBlockAtRange(selection, block) - // If the node was successfully inserted, update the selection. - const node = editor.value.document.getNode(block.key) - - if (node) { - editor.moveToEndOfNode(node) - } + const path = editor.value.document.getPath(block.key) + editor.moveToEndOfPath(path) } /** @@ -299,12 +295,8 @@ Commands.insertInline = (fn, editor) => inline => { const { selection } = value editor.insertInlineAtRange(selection, inline) - // If the node was successfully inserted, update the selection. - const node = editor.value.document.getNode(inline.key) - - if (node) { - editor.moveToEndOfNode(node) - } + const path = editor.value.document.getPath(inline.key) + editor.moveToEndOfPath(path) } /** diff --git a/packages/slate/src/interfaces/node.js b/packages/slate/src/interfaces/node.js index c7024d1226..a3a751cbfe 100644 --- a/packages/slate/src/interfaces/node.js +++ b/packages/slate/src/interfaces/node.js @@ -125,8 +125,14 @@ class NodeInterface { // COMPAT: Handle a node object by iterating the descendants tree, so that // we avoid using keys for the future. if (Node.isNode(key) && this.descendants) { + if (key === this) { + return List([]) + } + for (const [node, path] of this.descendants()) { - if (key === node) return path + if (key === node) { + return path + } } } diff --git a/packages/slate/src/plugins/core/core-schema.js b/packages/slate/src/plugins/core/core-schema.js index 340c1aa376..6885c5d8bd 100644 --- a/packages/slate/src/plugins/core/core-schema.js +++ b/packages/slate/src/plugins/core/core-schema.js @@ -1,5 +1,6 @@ import Schema from '../schema' import Text from '../../models/text' +import Path from '../../utils/path-utils' /** * A plugin that defines the core Slate schema. @@ -56,10 +57,11 @@ function CoreSchemaPlugin(options = {}) { match: [{ object: 'block' }, { object: 'inline' }], nodes: [{ min: 1 }], normalize: (editor, error) => { - const { code, node } = error + const { code, path } = error - if (code === 'child_min_invalid' && node.nodes.isEmpty()) { - editor.insertNodeByKey(node.key, 0, Text.create()) + if (code === 'child_min_invalid') { + const text = Text.create() + editor.insertNodeByPath(path, text) } }, }, @@ -70,19 +72,19 @@ function CoreSchemaPlugin(options = {}) { first: [{ object: 'block' }, { object: 'text' }], last: [{ object: 'block' }, { object: 'text' }], normalize: (editor, error) => { - const { code, node } = error - const text = Text.create() - let i + const { code, path } = error + let targetPath if (code === 'first_child_object_invalid') { - i = 0 + targetPath = path } else if (code === 'last_child_object_invalid') { - i = node.nodes.size + targetPath = Path.increment(path) } else { return } - editor.insertNodeByKey(node.key, i, text) + const text = Text.create() + editor.insertNodeByPath(targetPath, text) }, }, { @@ -92,23 +94,25 @@ function CoreSchemaPlugin(options = {}) { previous: [{ object: 'block' }, { object: 'text' }], next: [{ object: 'block' }, { object: 'text' }], normalize: (editor, error) => { - const { code, node, index } = error - const text = Text.create() - let i - - if (code === 'first_child_object_invalid') { - i = 0 - } else if (code === 'last_child_object_invalid') { - i = node.nodes.size - } else if (code === 'previous_sibling_object_invalid') { - i = index - } else if (code === 'next_sibling_object_invalid') { - i = index + 1 + const { code, path } = error + let targetPath + + if ( + code === 'first_child_object_invalid' || + code === 'next_sibling_object_invalid' + ) { + targetPath = path + } else if ( + code === 'last_child_object_invalid' || + code === 'previous_sibling_object_invalid' + ) { + targetPath = Path.increment(path) } else { return } - editor.insertNodeByKey(node.key, i, text) + const text = Text.create() + editor.insertNodeByPath(targetPath, text) }, }, @@ -119,10 +123,10 @@ function CoreSchemaPlugin(options = {}) { return next.object !== 'text' || !match.marks.equals(next.marks) }, normalize: (editor, error) => { - const { code, next } = error + const { code, path } = error if (code === 'next_sibling_invalid') { - editor.mergeNodeByKey(next.key) + editor.mergeNodeByPath(path) } }, }, @@ -137,12 +141,13 @@ function CoreSchemaPlugin(options = {}) { return next.object !== 'text' || next.text !== '' }, normalize: (editor, error) => { - const { code, next, previous } = error + const { code, path } = error - if (code === 'next_sibling_invalid') { - editor.removeNodeByKey(next.key) - } else if (code === 'previous_sibling_invalid') { - editor.removeNodeByKey(previous.key) + if ( + code === 'next_sibling_invalid' || + code === 'previous_sibling_invalid' + ) { + editor.removeNodeByPath(path) } }, }, diff --git a/packages/slate/src/plugins/schema/index.js b/packages/slate/src/plugins/schema/index.js index 0d17dd7007..68a317ea9e 100644 --- a/packages/slate/src/plugins/schema/index.js +++ b/packages/slate/src/plugins/schema/index.js @@ -1,4 +1,5 @@ import SlateError from '../../utils/slate-error' +import Path from '../../utils/path-utils' /** * Create a plugin from a `schema` definition. @@ -85,7 +86,7 @@ function SchemaPlugin(schema) { const isAtomic = (fn, editor) => format => { const rule = schemaRules.find( - r => 'isAtomic' in r && testRules(format, r.match) + r => 'isAtomic' in r && testRules(format, null, r.match) ) return rule ? rule.isAtomic : fn(format) @@ -100,8 +101,9 @@ function SchemaPlugin(schema) { */ const isVoid = (fn, editor) => node => { + const path = editor.value.document.getPath(node) const rule = schemaRules.find( - r => 'isVoid' in r && testRules(node, r.match) + r => 'isVoid' in r && testRules(node, path, r.match) ) return rule ? rule.isVoid : fn(node) @@ -158,8 +160,11 @@ function SchemaPlugin(schema) { */ const validateNode = (fn, editor) => node => { - const matches = schemaRules.filter(r => testRules(node, r.match)) - const failure = validateRules(node, matches, schemaRules, { every: true }) + const path = editor.value.document.getPath(node) + const matches = schemaRules.filter(r => testRules(node, path, r.match)) + const failure = validateRules(node, path, matches, schemaRules, { + every: true, + }) if (!failure) { return fn(node) @@ -186,7 +191,11 @@ function SchemaPlugin(schema) { */ function defaultNormalize(editor, error) { - const { code, node, child, next, previous, key, mark } = error + const { value: { document } } = editor + const { code, key, mark, path } = error + const parentPath = Path.lift(path) + const parent = document.getNode(parentPath) + const node = document.getNode(path) switch (code) { case 'child_max_invalid': @@ -196,55 +205,67 @@ function defaultNormalize(editor, error) { case 'first_child_object_invalid': case 'first_child_type_invalid': case 'last_child_object_invalid': - case 'last_child_type_invalid': { - return child.object === 'text' && - node.object === 'block' && - node.nodes.size === 1 - ? editor.removeNodeByKey(node.key) - : editor.removeNodeByKey(child.key) - } - + case 'last_child_type_invalid': case 'previous_sibling_object_invalid': - case 'previous_sibling_type_invalid': { - return previous.object === 'text' && - node.object === 'block' && - node.nodes.size === 1 - ? editor.removeNodeByKey(node.key) - : editor.removeNodeByKey(previous.key) - } - + case 'previous_sibling_type_invalid': case 'next_sibling_object_invalid': case 'next_sibling_type_invalid': { - return next.object === 'text' && - node.object === 'block' && - node.nodes.size === 1 - ? editor.removeNodeByKey(node.key) - : editor.removeNodeByKey(next.key) + const isOnlyText = + node.object === 'text' && + parent.object === 'block' && + parent.nodes.size === 1 + const targetPath = isOnlyText ? parentPath : path + editor.removeNodeByPath(targetPath) + break + } + + case 'child_min_invalid': { + if (parent.object === 'document') { + editor.removeChildrenByPath(parentPath) + } else { + editor.removeNodeByPath(parentPath) + } + + break } - case 'child_min_invalid': case 'node_text_invalid': case 'parent_object_invalid': case 'parent_type_invalid': { - return node.object === 'document' - ? node.nodes.forEach(n => editor.removeNodeByKey(n.key)) - : editor.removeNodeByKey(node.key) + if (node.object === 'document') { + editor.removeChildrenByPath(path) + } else { + editor.removeNodeByPath(path) + } + + break } case 'node_data_invalid': { - return node.data.get(key) === undefined && node.object !== 'document' - ? editor.removeNodeByKey(node.key) - : editor.setNodeByKey(node.key, { data: node.data.delete(key) }) + const isUnset = + node.data.get(key) === undefined && node.object !== 'document' + + if (isUnset) { + editor.removeNodeByPath(path) + } else { + editor.setNodeByPath(path, { data: node.data.delete(key) }) + } + + break } case 'node_mark_invalid': { - return node - .getTexts() - .forEach(t => editor.removeMarkByKey(t.key, 0, t.text.length, mark)) + for (const [text, relativePath] of node.texts()) { + const textPath = path.concat(relativePath) + editor.removeMarkByPath(textPath, 0, text.text.length, mark) + } + + break } default: { - return editor.removeNodeByKey(node.key) + editor.removeNodeByPath(path) + break } } } @@ -253,12 +274,13 @@ function defaultNormalize(editor, error) { * Check that an `object` matches one of a set of `rules`. * * @param {Mixed} object + * @param {Array} path * @param {Object|Array} rules * @return {Boolean} */ -function testRules(object, rules) { - const error = validateRules(object, rules) +function testRules(object, path, rules) { + const error = validateRules(object, path, rules) return !error } @@ -266,17 +288,18 @@ function testRules(object, rules) { * Validate that a `object` matches a `rule` object or array. * * @param {Mixed} object + * @param {Array} path * @param {Object|Array} rule * @param {Array|Void} rules * @return {Error|Void} */ -function validateRules(object, rule, rules, options = {}) { +function validateRules(object, path, rule, rules, options = {}) { const { every = false, match = null } = options if (typeof rule === 'function') { const valid = rule(object, match) - return valid ? null : fail('node_invalid', { rule, node: object }) + return valid ? null : fail('node_invalid', { rule, node: object, path }) } if (Array.isArray(rule)) { @@ -284,7 +307,7 @@ function validateRules(object, rule, rules, options = {}) { let first for (const r of array) { - const error = validateRules(object, r, rules) + const error = validateRules(object, path, r, rules) first = first || error if (every && error) return error if (!every && !error) return @@ -294,39 +317,39 @@ function validateRules(object, rule, rules, options = {}) { } const error = - validateObject(object, rule) || - validateType(object, rule) || - validateData(object, rule) || - validateMarks(object, rule) || - validateText(object, rule) || - validateFirst(object, rule) || - validateLast(object, rule) || - validateNodes(object, rule, rules) + validateObject(object, path, rule) || + validateType(object, path, rule) || + validateData(object, path, rule) || + validateMarks(object, path, rule) || + validateText(object, path, rule) || + validateFirst(object, path, rule) || + validateLast(object, path, rule) || + validateNodes(object, path, rule, rules) return error } -function validateObject(node, rule) { +function validateObject(node, path, rule) { if (rule.object == null) return if (rule.object === node.object) return if (typeof rule.object === 'function' && rule.object(node.object)) return - return fail('node_object_invalid', { rule, node }) + return fail('node_object_invalid', { rule, node, path }) } -function validateType(node, rule) { +function validateType(node, path, rule) { if (rule.type == null) return if (rule.type === node.type) return if (typeof rule.type === 'function' && rule.type(node.type)) return - return fail('node_type_invalid', { rule, node }) + return fail('node_type_invalid', { rule, node, path }) } -function validateData(node, rule) { +function validateData(node, path, rule) { if (rule.data == null) return if (node.data == null) return if (typeof rule.data === 'function') { if (rule.data(node.data)) return - return fail('node_data_invalid', { rule, node }) + return fail('node_data_invalid', { rule, node, path }) } for (const key in rule.data) { @@ -334,11 +357,11 @@ function validateData(node, rule) { const value = node.data && node.data.get(key) const valid = typeof fn === 'function' ? fn(value) : fn === value if (valid) continue - return fail('node_data_invalid', { rule, node, key, value }) + return fail('node_data_invalid', { rule, node, path, key, value }) } } -function validateMarks(node, rule) { +function validateMarks(node, path, rule) { if (rule.marks == null) return const marks = @@ -352,24 +375,25 @@ function validateMarks(node, rule) { : def.type === mark.type ) if (valid) continue - return fail('node_mark_invalid', { rule, node, mark }) + return fail('node_mark_invalid', { rule, node, path, mark }) } } -function validateText(node, rule) { +function validateText(node, path, rule) { if (rule.text == null) return const { text } = node const valid = typeof rule.text === 'function' ? rule.text(text) : rule.text.test(text) if (valid) return - return fail('node_text_invalid', { rule, node, text }) + return fail('node_text_invalid', { rule, node, path, text }) } -function validateFirst(node, rule) { +function validateFirst(node, path, rule) { if (rule.first == null) return const first = node.nodes.first() if (!first) return - const error = validateRules(first, rule.first) + const firstPath = path.concat([0]) + const error = validateRules(first, firstPath, rule.first) if (!error) return error.rule = rule error.node = node @@ -378,11 +402,12 @@ function validateFirst(node, rule) { return error } -function validateLast(node, rule) { +function validateLast(node, path, rule) { if (rule.last == null) return const last = node.nodes.last() if (!last) return - const error = validateRules(last, rule.last) + const lastPath = path.concat([node.nodes.size - 1]) + const error = validateRules(last, lastPath, rule.last) if (!error) return error.rule = rule error.node = node @@ -391,7 +416,7 @@ function validateLast(node, rule) { return error } -function validateNodes(node, rule, rules = []) { +function validateNodes(node, path, rule, rules = []) { if (node.nodes == null) return const children = node.nodes @@ -403,6 +428,7 @@ function validateNodes(node, rule, rules = []) { let def = null let max = null let child = null + let childPath = null let previous = null let next = null @@ -420,6 +446,7 @@ function validateNodes(node, rule, rules = []) { index += 1 previous = index ? children.get(index - 1) : null child = children.get(index) + childPath = path.concat([index]) next = children.get(index + 1) if (!child) return false lastCount = count @@ -440,19 +467,25 @@ function validateNodes(node, rule, rules = []) { while (nextChild()) { const err = - validateParent(node, child, rules) || - validatePrevious(node, child, previous, index, rules) || - validateNext(node, child, next, index, rules) + validateParent(node, child, childPath, rules) || + validatePrevious(node, child, childPath, previous, index, rules) || + validateNext(node, child, childPath, next, index, rules) if (err) return err if (rule.nodes != null) { if (!def) { - return fail('child_unknown', { rule, node, child, index }) + return fail('child_unknown', { + rule, + node, + child, + index, + path: childPath, + }) } if (def.match) { - const error = validateRules(child, def.match) + const error = validateRules(child, childPath, def.match) if (error) { // Since we want to report overflow on last matching child we don't @@ -466,6 +499,7 @@ function validateNodes(node, rule, rules = []) { index, child: children.get(index), count, + path: path.concat([index]), limit: max, }) } @@ -489,12 +523,13 @@ function validateNodes(node, rule, rules = []) { // current child is in fact the first of the next group. If so, the // next def will not report errors, in which case we can rewind and // report an minimum error. - if (validateRules(child, def.match) == null) { + if (validateRules(child, childPath, def.match) == null) { rewind() return fail('child_min_invalid', { rule, node, index, + path: path.concat([index]), count: lastCount - 1, limit: lastMin, }) @@ -519,7 +554,13 @@ function validateNodes(node, rule, rules = []) { // Otherwise either we exhausted the last group, in which case it's // an unknown child, ... if (max != null && count > max) { - return fail('child_unknown', { rule, node, child, index }) + return fail('child_unknown', { + rule, + node, + child, + index, + path: path.concat([index]), + }) } // ... or it's an invalid child for the last group. @@ -537,12 +578,14 @@ function validateNodes(node, rule, rules = []) { // Since we want to report overflow on last matching child we don't // immediately check for count > max, but do so after processing all nodes. if (max != null && count > max) { + const i = index - 1 return fail('child_max_invalid', { rule, node, - index: index - 1, + index: i, count, - child: children.get(index - 1), + path: path.concat([i]), + child: children.get(i), limit: max, }) } @@ -555,6 +598,7 @@ function validateNodes(node, rule, rules = []) { node, index, count, + path: path.concat([index]), limit: min, }) } @@ -562,30 +606,33 @@ function validateNodes(node, rule, rules = []) { } } -function validateParent(node, child, rules) { +function validateParent(node, child, childPath, rules) { for (const rule of rules) { if (rule.parent == null) continue - if (!testRules(child, rule.match)) continue + if (!testRules(child, childPath, rule.match)) continue - const error = validateRules(node, rule.parent) + const parentPath = Path.lift(childPath) + const error = validateRules(node, parentPath, rule.parent) if (!error) continue error.rule = rule error.parent = node error.node = child + error.path = childPath error.code = error.code.replace('node_', 'parent_') return error } } -function validatePrevious(node, child, previous, index, rules) { +function validatePrevious(node, child, childPath, previous, index, rules) { if (!previous) return for (const rule of rules) { if (rule.previous == null) continue - if (!testRules(child, rule.match)) continue + if (!testRules(child, childPath, rule.match)) continue - const error = validateRules(previous, rule.previous) + const previousPath = Path.decrement(childPath) + const error = validateRules(previous, previousPath, rule.previous) if (!error) continue error.rule = rule @@ -598,14 +645,15 @@ function validatePrevious(node, child, previous, index, rules) { } } -function validateNext(node, child, next, index, rules) { +function validateNext(node, child, childPath, next, index, rules) { if (!next) return for (const rule of rules) { if (rule.next == null) continue - if (!testRules(child, rule.match)) continue + if (!testRules(child, childPath, rule.match)) continue - const error = validateRules(next, rule.next, [], { match: child }) + const nextPath = Path.increment(childPath) + const error = validateRules(next, nextPath, rule.next, [], { match: child }) if (!error) continue error.rule = rule diff --git a/packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js b/packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js deleted file mode 100644 index b2ad99d2be..0000000000 --- a/packages/slate/test/commands/at-current-range/delete-backward/with-plugin-normalization.js +++ /dev/null @@ -1,62 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Block, Text } from 'slate' - -const normalizeNode = (fn, editor) => node => { - if (node.type === 'container' && node.nodes.first().type === 'container') { - return () => - editor.insertNodeByKey( - node.key, - 0, - Block.create({ - type: 'paragraph', - nodes: [Text.create()], - }) - ) - } else { - return fn(node) - } -} - -export const plugins = [{ normalizeNode }] - -export default function(editor) { - editor.deleteBackward() -} - -export const input = ( - - - - 1 - - - 1.1 - - - 1.1.1 - - - - - -) - -export const output = ( - - - - - 1 1.1 - - - - - 1.1.1 - - - - - -) diff --git a/packages/slate/test/controllers/editor/has/missing.js b/packages/slate/test/controllers/editor/has/missing.js index bc9bfebd18..411498367d 100644 --- a/packages/slate/test/controllers/editor/has/missing.js +++ b/packages/slate/test/controllers/editor/has/missing.js @@ -4,16 +4,14 @@ import { Editor } from 'slate' const plugins = [ { - commands: { - customCommand: () => {}, - }, + customCommand: () => {}, }, ] export const input = new Editor({ plugins }) export default function(editor) { - return editor.hasCommand('otherCommand') + return editor.has('otherCommand') } export const output = false diff --git a/packages/slate/test/history/undo/move-node-affecting-path.js b/packages/slate/test/history/undo/move-node-affecting-path.js index 9bec4c656b..dd587fbf65 100644 --- a/packages/slate/test/history/undo/move-node-affecting-path.js +++ b/packages/slate/test/history/undo/move-node-affecting-path.js @@ -1,9 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' +import { PathUtils } from 'slate' export default function(editor) { - editor.moveNodeByKey('c', 'd', 1) + editor.moveNodeByPath(PathUtils.create([1]), PathUtils.create([2, 1])) editor.flush() editor.undo() } diff --git a/packages/slate/test/history/undo/move-node-before-itself.js b/packages/slate/test/history/undo/move-node-before-itself.js index fdc584299e..39d1fcc10f 100644 --- a/packages/slate/test/history/undo/move-node-before-itself.js +++ b/packages/slate/test/history/undo/move-node-before-itself.js @@ -1,9 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' +import { PathUtils } from 'slate' export default function(editor) { - editor.moveNodeByKey('h', 'a', 0) + editor.moveNodeByPath(PathUtils.create([1, 1, 2]), PathUtils.create([0])) editor.flush() editor.undo() } diff --git a/packages/slate/test/history/undo/move-node-by-key.js b/packages/slate/test/history/undo/move-node-by-key.js index 93d3c9e315..b10a328ce3 100644 --- a/packages/slate/test/history/undo/move-node-by-key.js +++ b/packages/slate/test/history/undo/move-node-by-key.js @@ -1,9 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' +import { PathUtils } from 'slate' export default function(editor) { - editor.moveNodeByKey('b', 'a', 1) + editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1])) editor.flush() editor.undo() } diff --git a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js b/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js index 142e60f35e..4e54465267 100644 --- a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js +++ b/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js @@ -1,13 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' -import PathUtils from '../../../src/utils/path-utils' - -const pathA = PathUtils.create([0]) -const pathB = PathUtils.create([1]) +import { PathUtils } from 'slate' export default function(editor) { - editor.moveNodeByPath(pathA, pathB, 1) + editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1, 1])) editor.flush() editor.undo() } diff --git a/packages/slate/test/history/undo/move-node-by-path.js b/packages/slate/test/history/undo/move-node-by-path.js index 2d8005ecc5..662c7eecc7 100644 --- a/packages/slate/test/history/undo/move-node-by-path.js +++ b/packages/slate/test/history/undo/move-node-by-path.js @@ -1,13 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' -import PathUtils from '../../../src/utils/path-utils' - -const pathA = PathUtils.create([0, 0]) -const pathB = PathUtils.create([1]) +import { PathUtils } from 'slate' export default function(editor) { - editor.moveNodeByPath(pathA, pathB, 1) + editor.moveNodeByPath(PathUtils.create([0, 0]), PathUtils.create([1, 1])) editor.flush() editor.undo() } diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js b/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js index 8434c4da5e..aba40acdac 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js @@ -17,11 +17,9 @@ export const schema = { min: 1, }, ], - normalize: (editor, error) => { - const { code, child } = error - + normalize: (editor, { code, path }) => { if (code === 'child_object_invalid') { - editor.wrapBlockByKey(child.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom.js b/packages/slate/test/schema/custom/child-kind-invalid-custom.js index 0f84b62fe1..82c3131ccd 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-custom.js @@ -11,9 +11,9 @@ export const schema = { match: [{ object: 'block' }], }, ], - normalize: (editor, { code, child }) => { + normalize: (editor, { code, path }) => { if (code === 'child_object_invalid') { - editor.wrapBlockByKey(child.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/child-max-invalid-custom.js b/packages/slate/test/schema/custom/child-max-invalid-custom.js index 2004bc66f4..3f1cc836d8 100644 --- a/packages/slate/test/schema/custom/child-max-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-max-invalid-custom.js @@ -15,9 +15,9 @@ export const schema = { match: [{ type: 'paragraph' }], }, ], - normalize: (editor, { code, node, index }) => { + normalize: (editor, { code, path }) => { if (code === 'child_max_invalid') { - editor.mergeNodeByKey(node.nodes.get(index).key) + editor.mergeNodeByPath(path) } }, }, diff --git a/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js b/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js index 3773a44b7f..949a1a51cf 100644 --- a/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js +++ b/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js @@ -12,9 +12,9 @@ export const schema = { min: 2, }, ], - normalize: (editor, { code, node, index }) => { + normalize: (editor, { code, path }) => { if (code === 'child_min_invalid') { - editor.insertNodeByKey(node.key, index, { + editor.insertNodeByPath(path, { object: 'block', type: 'paragraph', }) diff --git a/packages/slate/test/schema/custom/child-min-invalid-custom.js b/packages/slate/test/schema/custom/child-min-invalid-custom.js index d5f44a476c..ff44791063 100644 --- a/packages/slate/test/schema/custom/child-min-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-min-invalid-custom.js @@ -16,9 +16,9 @@ export const schema = { match: [{ type: 'paragraph' }], }, ], - normalize: (editor, { code, node, index }) => { - if (code === 'child_min_invalid' && index === 0) { - editor.insertNodeByKey(node.key, index, { + normalize: (editor, { code, path }) => { + if (code === 'child_min_invalid') { + editor.insertNodeByPath(path, { object: 'block', type: 'title', }) diff --git a/packages/slate/test/schema/custom/child-type-invalid-custom.js b/packages/slate/test/schema/custom/child-type-invalid-custom.js index 055efa618a..8f853ff106 100644 --- a/packages/slate/test/schema/custom/child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-type-invalid-custom.js @@ -11,9 +11,9 @@ export const schema = { match: [{ type: 'paragraph' }], }, ], - normalize: (editor, { code, child }) => { + normalize: (editor, { code, path }) => { if (code === 'child_type_invalid') { - editor.wrapBlockByKey(child.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/child-unknown-custom.js b/packages/slate/test/schema/custom/child-unknown-custom.js index d76196b05f..62e4674811 100644 --- a/packages/slate/test/schema/custom/child-unknown-custom.js +++ b/packages/slate/test/schema/custom/child-unknown-custom.js @@ -12,16 +12,9 @@ export const schema = { max: 1, }, ], - normalize: (editor, { code, node, child }) => { + normalize: (editor, { code, path }) => { if (code === 'child_unknown') { - const previous = node.getPreviousSibling(child.key) - const offset = previous.nodes.size - - child.nodes.forEach((n, i) => - editor.moveNodeByKey(n.key, previous.key, offset + i) - ) - - editor.removeNodeByKey(child.key) + editor.mergeNodeByPath(path) } }, }, diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js b/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js index e6933b9b52..86ff482fc2 100644 --- a/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js @@ -7,9 +7,9 @@ export const schema = { paragraph: {}, quote: { first: [{ object: 'block' }], - normalize: (editor, { code, child }) => { + normalize: (editor, { code, path }) => { if (code === 'first_child_object_invalid') { - editor.wrapBlockByKey(child.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-custom.js b/packages/slate/test/schema/custom/first-child-type-invalid-custom.js index e55242f3ed..a1c4078dc7 100644 --- a/packages/slate/test/schema/custom/first-child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/first-child-type-invalid-custom.js @@ -7,9 +7,9 @@ export const schema = { paragraph: {}, quote: { first: [{ type: 'paragraph' }], - normalize: (editor, { code, child }) => { + normalize: (editor, { code, path }) => { if (code === 'first_child_type_invalid') { - editor.wrapBlockByKey(child.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js b/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js index 5ace6badd8..9d91bb239a 100644 --- a/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js @@ -7,9 +7,9 @@ export const schema = { paragraph: {}, quote: { last: [{ object: 'block' }], - normalize: (editor, { code, child }) => { + normalize: (editor, { code, path }) => { if (code === 'last_child_object_invalid') { - editor.wrapBlockByKey(child.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-custom.js b/packages/slate/test/schema/custom/last-child-type-invalid-custom.js index a6af798bcc..6eb48ab014 100644 --- a/packages/slate/test/schema/custom/last-child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/last-child-type-invalid-custom.js @@ -7,9 +7,9 @@ export const schema = { paragraph: {}, quote: { last: [{ type: 'paragraph' }], - normalize: (editor, { code, child }) => { + normalize: (editor, { code, path }) => { if (code === 'last_child_type_invalid') { - editor.wrapBlockByKey(child.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/next-kind-invalid-custom.js b/packages/slate/test/schema/custom/next-kind-invalid-custom.js index fe1a6e6aa0..1b917e81c6 100644 --- a/packages/slate/test/schema/custom/next-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/next-kind-invalid-custom.js @@ -6,9 +6,9 @@ export const schema = { blocks: { image: { next: [{ object: 'inline' }, { object: 'text' }], - normalize: (editor, { code, next }) => { + normalize: (editor, { code, path }) => { if (code === 'next_sibling_object_invalid') { - editor.unwrapBlockByKey(next.key, 'paragraph') + editor.unwrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/next-type-invalid-custom.js b/packages/slate/test/schema/custom/next-type-invalid-custom.js index fee2c2498f..550aca4c91 100644 --- a/packages/slate/test/schema/custom/next-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/next-type-invalid-custom.js @@ -6,9 +6,9 @@ export const schema = { blocks: { paragraph: { next: [{ type: 'paragraph' }], - normalize: (editor, { code, next }) => { + normalize: (editor, { code, path }) => { if (code === 'next_sibling_type_invalid') { - editor.wrapBlockByKey(next.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/node-data-invalid-custom.js b/packages/slate/test/schema/custom/node-data-invalid-custom.js index 1082c13e8b..00977aa0b1 100644 --- a/packages/slate/test/schema/custom/node-data-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-data-invalid-custom.js @@ -8,9 +8,9 @@ export const schema = { data: { thing: v => v === 'value', }, - normalize: (editor, { code, node, key }) => { + normalize: (editor, { code, path }) => { if (code === 'node_data_invalid') { - editor.setNodeByKey(node.key, { data: { thing: 'value' } }) + editor.setNodeByPath(path, { data: { thing: 'value' } }) } }, }, diff --git a/packages/slate/test/schema/custom/node-mark-invalid-custom.js b/packages/slate/test/schema/custom/node-mark-invalid-custom.js index af229e029a..3d1b582fca 100644 --- a/packages/slate/test/schema/custom/node-mark-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-mark-invalid-custom.js @@ -6,9 +6,9 @@ export const schema = { blocks: { paragraph: { marks: [{ type: 'bold' }], - normalize: (editor, { code, node }) => { + normalize: (editor, { code, path }) => { if (code === 'node_mark_invalid') { - node.nodes.forEach(n => editor.removeNodeByKey(n.key)) + editor.removeChildrenByPath(path) } }, }, diff --git a/packages/slate/test/schema/custom/node-text-invalid-custom.js b/packages/slate/test/schema/custom/node-text-invalid-custom.js index 67ef1de8e1..6efd103eb8 100644 --- a/packages/slate/test/schema/custom/node-text-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-text-invalid-custom.js @@ -6,9 +6,9 @@ export const schema = { blocks: { paragraph: { text: /^\d*$/, - normalize: (editor, { code, node }) => { + normalize: (editor, { code, path }) => { if (code === 'node_text_invalid') { - node.nodes.forEach(n => editor.removeNodeByKey(n.key)) + editor.removeChildrenByPath(path) } }, }, diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-custom.js b/packages/slate/test/schema/custom/parent-kind-invalid-custom.js index 2d93cb680c..3fcefb5249 100644 --- a/packages/slate/test/schema/custom/parent-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/parent-kind-invalid-custom.js @@ -6,9 +6,9 @@ export const schema = { blocks: { paragraph: { parent: { object: 'document' }, - normalize: (editor, { code, node }) => { + normalize: (editor, { code, path }) => { if (code === 'parent_object_invalid') { - editor.unwrapNodeByKey(node.key) + editor.unwrapNodeByPath(path) } }, }, diff --git a/packages/slate/test/schema/custom/parent-type-invalid-custom.js b/packages/slate/test/schema/custom/parent-type-invalid-custom.js index 73ef855e0f..e2f2f078aa 100644 --- a/packages/slate/test/schema/custom/parent-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/parent-type-invalid-custom.js @@ -7,9 +7,9 @@ export const schema = { list: {}, item: { parent: { type: 'list' }, - normalize: (editor, { code, node }) => { + normalize: (editor, { code, path }) => { if (code === 'parent_type_invalid') { - editor.wrapBlockByKey(node.key, 'list') + editor.wrapBlockByPath(path, 'list') } }, }, diff --git a/packages/slate/test/schema/custom/previous-kind-invalid-custom.js b/packages/slate/test/schema/custom/previous-kind-invalid-custom.js index 7a1e58a78b..7bba930272 100644 --- a/packages/slate/test/schema/custom/previous-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/previous-kind-invalid-custom.js @@ -6,9 +6,9 @@ export const schema = { blocks: { image: { previous: [{ object: 'inline' }, { object: 'text' }], - normalize: (editor, { code, previous }) => { + normalize: (editor, { code, path }) => { if (code === 'previous_sibling_object_invalid') { - editor.unwrapBlockByKey(previous.key, 'paragraph') + editor.unwrapBlockByPath(path, 'paragraph') } }, }, diff --git a/packages/slate/test/schema/custom/previous-type-invalid-custom.js b/packages/slate/test/schema/custom/previous-type-invalid-custom.js index 2bd516db6d..6b40a83c56 100644 --- a/packages/slate/test/schema/custom/previous-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/previous-type-invalid-custom.js @@ -6,11 +6,9 @@ export const schema = { blocks: { paragraph: { previous: [{ type: 'paragraph' }], - normalize: (editor, error) => { - const { code, previous } = error - + normalize: (editor, { code, path }) => { if (code === 'previous_sibling_type_invalid') { - editor.wrapBlockByKey(previous.key, 'paragraph') + editor.wrapBlockByPath(path, 'paragraph') } }, }, From f21c5408088914fe1655f2ba7de0fd10fab92c72 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 27 Aug 2019 18:48:20 -0400 Subject: [PATCH 014/165] migrate *ByKey tests, remove index from *ByPath signatures --- packages/slate/src/commands/at-range.js | 13 ++- packages/slate/src/commands/by-path.js | 87 +++++++++++++------ .../by-key/insert-node-by-key/duplicate.js | 35 -------- .../replace-with-active-marks-with-data.js | 40 --------- .../replace-with-mark-and-active-mark.js | 40 --------- .../replace-with-node-index-mark.js | 30 ------- .../replace-without-any-marks.js | 28 ------ .../replace-with-string-and-mark.js | 33 ------- .../insert-fragment-by-path}/end-of-target.js | 7 +- .../middle-of-target.js | 7 +- .../start-of-target.js | 7 +- .../insert-node-by-path}/block.js | 4 +- .../insert-node-by-path}/inline.js | 4 +- .../decoration-after-atomic.js | 2 +- .../decoration-before-atomic.js | 2 +- .../decoration-middle-atomic.js | 2 +- .../insert-text-by-path}/selection-after.js | 2 +- .../insert-text-by-path}/selection-before.js | 2 +- .../insert-text-by-path}/selection-end.js | 2 +- .../insert-text-by-path}/selection-middle.js | 2 +- .../insert-text-by-path}/selection-start.js | 2 +- .../text-end-with-marks.js | 2 +- .../insert-text-by-path}/text-end.js | 2 +- .../text-middle-with-marks.js | 2 +- .../insert-text-by-path}/text-middle.js | 2 +- .../text-start-with-marks.js | 2 +- .../insert-text-by-path}/text-start.js | 2 +- .../merge-node-by-path}/block.js | 4 +- .../move-node-by-path}/block.js | 6 +- .../move-node-by-path}/inline.js | 12 ++- .../inside-next-text-sibling.js | 30 +++++++ .../by-path/move-node-by-path/inside-next.js | 34 ++++++++ .../by-path/move-node-by-path/nested.js | 33 +++++++ .../move-node-by-path/new-path-exists.js | 38 -------- .../new-sibling-is-text-node.js | 34 -------- .../by-path/move-node-by-path/noop-equal.js | 19 ++++ .../by-path/move-node-by-path/noop-inside.js | 19 ++++ .../move-node-by-path/path-equals-new-path.js | 34 -------- .../path-left-sibling-of-new-path-ancestor.js | 39 --------- .../by-path/move-node-by-path/sibling-swap.js | 21 ++--- .../by-path/move-node-by-path/text-nodes.js | 15 ++-- .../move-node-by-path}/text.js | 8 +- .../move-node-by-path}/to-sibling.js | 2 +- .../remove-node-by-path}/block.js | 2 +- .../remove-node-by-path}/inline.js | 2 +- .../remove-node-by-path}/selection-inside.js | 2 +- .../remove-node-by-path}/text.js | 2 +- .../adjacent-non-void-inlines.js | 7 +- .../decoration-after-atomic.js | 2 +- .../decoration-before-atomic.js | 2 +- .../decoration-middle-atomic.js | 2 +- .../inline-last-character.js | 2 +- .../inline-nested-last-character.js | 10 ++- .../remove-text-by-path}/inline-void.js | 6 +- .../remove-text-by-path}/inline.js | 2 +- .../remove-text-by-path}/next-void-inline.js | 7 +- .../previous-void-inline.js | 2 +- .../remove-text-by-path}/selection-after.js | 2 +- .../remove-text-by-path}/selection-before.js | 2 +- .../remove-text-by-path}/selection-middle.js | 2 +- .../remove-text-by-path}/selection-start.js | 2 +- .../remove-text-by-path}/text.js | 2 +- .../replace-node-by-path}/block.js | 2 +- .../replace-node-by-path}/inline.js | 10 ++- .../replace-node-by-path}/text.js | 6 +- .../replace-text-by-path/replace.js} | 6 +- .../replace-text-by-path/with-mark.js} | 14 +-- .../set-mark-by-path}/with-data.js | 8 +- .../set-node-by-path}/block.js | 2 +- .../set-node-by-path}/inline-with-is-void.js | 6 +- .../set-node-by-path}/string-shorthand.js | 4 +- .../commands/by-path/set-text-by-path/set.js | 27 ++++++ .../by-path/set-text-by-path/with-mark.js | 28 ++++++ .../block-with-selection.js | 2 +- .../split-descendants-by-path}/block.js | 2 +- .../block-with-selection.js | 2 +- .../split-node-by-path}/block.js | 2 +- .../unwrap-block-by-path}/single-block.js | 2 +- .../block-multiple.js | 2 +- .../unwrap-children-by-path}/block.js | 2 +- .../unwrap-inline-by-path}/single-block.js | 2 +- .../unwrap-node-by-path}/block.js | 2 +- .../unwrap-node-by-path}/first-block.js | 2 +- .../unwrap-node-by-path}/last-block.js | 2 +- .../unwrap-node-by-path}/middle-block.js | 2 +- .../wrap-block-by-path}/block.js | 2 +- .../wrap-block-by-path}/text.js | 2 +- .../test/history/undo/move-node-by-key.js | 21 ----- ...-node-by-key.js => remove-node-by-path.js} | 3 +- ...-data.js => set-node-by-path-with-data.js} | 3 +- ...y-block.js => split-node-by-path-block.js} | 3 +- ...-node-by-key.js => unwrap-node-by-path.js} | 5 +- 92 files changed, 407 insertions(+), 540 deletions(-) delete mode 100644 packages/slate/test/commands/by-key/insert-node-by-key/duplicate.js delete mode 100644 packages/slate/test/commands/by-key/replace-text-by-key/replace-with-active-marks-with-data.js delete mode 100644 packages/slate/test/commands/by-key/replace-text-by-key/replace-with-mark-and-active-mark.js delete mode 100644 packages/slate/test/commands/by-key/replace-text-by-key/replace-with-node-index-mark.js delete mode 100644 packages/slate/test/commands/by-key/replace-text-by-key/replace-without-any-marks.js delete mode 100644 packages/slate/test/commands/by-key/set-text-by-key/replace-with-string-and-mark.js rename packages/slate/test/commands/{by-key/insert-fragment-by-key => by-path/insert-fragment-by-path}/end-of-target.js (87%) rename packages/slate/test/commands/{by-key/insert-fragment-by-key => by-path/insert-fragment-by-path}/middle-of-target.js (88%) rename packages/slate/test/commands/{by-key/insert-fragment-by-key => by-path/insert-fragment-by-path}/start-of-target.js (88%) rename packages/slate/test/commands/{by-key/insert-node-by-key => by-path/insert-node-by-path}/block.js (82%) rename packages/slate/test/commands/{by-key/insert-node-by-key => by-path/insert-node-by-path}/inline.js (82%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/decoration-after-atomic.js (91%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/decoration-before-atomic.js (91%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/decoration-middle-atomic.js (91%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/selection-after.js (90%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/selection-before.js (90%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/selection-end.js (90%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/selection-middle.js (90%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/selection-start.js (90%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/text-end-with-marks.js (91%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/text-end.js (89%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/text-middle-with-marks.js (86%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/text-middle.js (89%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/text-start-with-marks.js (91%) rename packages/slate/test/commands/{by-key/insert-text-by-key => by-path/insert-text-by-path}/text-start.js (90%) rename packages/slate/test/commands/{by-key/merge-node-by-key => by-path/merge-node-by-path}/block.js (81%) rename packages/slate/test/commands/{by-key/move-node-by-key => by-path/move-node-by-path}/block.js (82%) rename packages/slate/test/commands/{by-key/move-node-by-key => by-path/move-node-by-path}/inline.js (71%) create mode 100644 packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js create mode 100644 packages/slate/test/commands/by-path/move-node-by-path/inside-next.js create mode 100644 packages/slate/test/commands/by-path/move-node-by-path/nested.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/new-path-exists.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/new-sibling-is-text-node.js create mode 100644 packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js create mode 100644 packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/path-equals-new-path.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/path-left-sibling-of-new-path-ancestor.js rename packages/slate/test/commands/{by-key/move-node-by-key => by-path/move-node-by-path}/text.js (67%) rename packages/slate/test/commands/{by-key/move-node-by-key => by-path/move-node-by-path}/to-sibling.js (93%) rename packages/slate/test/commands/{by-key/remove-node-by-key => by-path/remove-node-by-path}/block.js (91%) rename packages/slate/test/commands/{by-key/remove-node-by-key => by-path/remove-node-by-path}/inline.js (93%) rename packages/slate/test/commands/{by-key/remove-node-by-key => by-path/remove-node-by-path}/selection-inside.js (93%) rename packages/slate/test/commands/{by-key/remove-node-by-key => by-path/remove-node-by-path}/text.js (93%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/adjacent-non-void-inlines.js (78%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/decoration-after-atomic.js (92%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/decoration-before-atomic.js (92%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/decoration-middle-atomic.js (91%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/inline-last-character.js (92%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/inline-nested-last-character.js (74%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/inline-void.js (80%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/inline.js (91%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/next-void-inline.js (77%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/previous-void-inline.js (92%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/selection-after.js (91%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/selection-before.js (91%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/selection-middle.js (91%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/selection-start.js (91%) rename packages/slate/test/commands/{by-key/remove-text-by-key => by-path/remove-text-by-path}/text.js (89%) rename packages/slate/test/commands/{by-key/replace-node-by-key => by-path/replace-node-by-path}/block.js (84%) rename packages/slate/test/commands/{by-key/replace-node-by-key => by-path/replace-node-by-path}/inline.js (72%) rename packages/slate/test/commands/{by-key/replace-node-by-key => by-path/replace-node-by-path}/text.js (71%) rename packages/slate/test/commands/{by-key/set-text-by-key/replace-with-string.js => by-path/replace-text-by-path/replace.js} (71%) rename packages/slate/test/commands/{by-key/replace-text-by-key/replace-with-active-marks.js => by-path/replace-text-by-path/with-mark.js} (63%) rename packages/slate/test/commands/{by-key/set-mark-by-key => by-path/set-mark-by-path}/with-data.js (84%) rename packages/slate/test/commands/{by-key/set-node-by-key => by-path/set-node-by-path}/block.js (92%) rename packages/slate/test/commands/{by-key/set-node-by-key => by-path/set-node-by-path}/inline-with-is-void.js (80%) rename packages/slate/test/commands/{by-key/set-node-by-key => by-path/set-node-by-path}/string-shorthand.js (77%) create mode 100644 packages/slate/test/commands/by-path/set-text-by-path/set.js create mode 100644 packages/slate/test/commands/by-path/set-text-by-path/with-mark.js rename packages/slate/test/commands/{by-key/split-descendants-by-key => by-path/split-descendants-by-path}/block-with-selection.js (90%) rename packages/slate/test/commands/{by-key/split-descendants-by-key => by-path/split-descendants-by-path}/block.js (88%) rename packages/slate/test/commands/{by-key/split-node-by-key => by-path/split-node-by-path}/block-with-selection.js (94%) rename packages/slate/test/commands/{by-key/split-node-by-key => by-path/split-node-by-path}/block.js (93%) rename packages/slate/test/commands/{by-key/unwrap-block-by-key => by-path/unwrap-block-by-path}/single-block.js (91%) rename packages/slate/test/commands/{by-key/unwrap-children-by-key => by-path/unwrap-children-by-path}/block-multiple.js (92%) rename packages/slate/test/commands/{by-key/unwrap-children-by-key => by-path/unwrap-children-by-path}/block.js (90%) rename packages/slate/test/commands/{by-key/unwrap-inline-by-key => by-path/unwrap-inline-by-path}/single-block.js (90%) rename packages/slate/test/commands/{by-key/unwrap-node-by-key => by-path/unwrap-node-by-path}/block.js (91%) rename packages/slate/test/commands/{by-key/unwrap-node-by-key => by-path/unwrap-node-by-path}/first-block.js (92%) rename packages/slate/test/commands/{by-key/unwrap-node-by-key => by-path/unwrap-node-by-path}/last-block.js (92%) rename packages/slate/test/commands/{by-key/unwrap-node-by-key => by-path/unwrap-node-by-path}/middle-block.js (94%) rename packages/slate/test/commands/{by-key/wrap-block-by-key => by-path/wrap-block-by-path}/block.js (90%) rename packages/slate/test/commands/{by-key/wrap-block-by-key => by-path/wrap-block-by-path}/text.js (90%) delete mode 100644 packages/slate/test/history/undo/move-node-by-key.js rename packages/slate/test/history/undo/{remove-node-by-key.js => remove-node-by-path.js} (77%) rename packages/slate/test/history/undo/{set-node-by-key-with-data.js => set-node-by-path-with-data.js} (78%) rename packages/slate/test/history/undo/{split-node-by-key-block.js => split-node-by-path-block.js} (82%) rename packages/slate/test/history/undo/{unwrap-node-by-key.js => unwrap-node-by-path.js} (77%) diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index d85e9da604..0e65057303 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -200,9 +200,8 @@ Commands.deleteAtRange = (fn, editor) => range => { // If the selection was hanging, we want to remove the start block // entirely instead of merging it with the end block. This is a rich text // editor behavior that's fairly standard. - const newParentPath = Path.lift(startBlockPath) - const newIndex = startBlockPath.last() + 1 - editor.moveNodeByPath(mergePath, newParentPath, newIndex) + const newPath = Path.increment(startBlockPath) + editor.moveNodeByPath(mergePath, newPath) editor.removeNodeByPath(startBlockPath) } else if (isAcrossBlocks) { // If the selection wasn't hanging, but we were across blocks, we need to @@ -998,8 +997,8 @@ Commands.wrapBlockAtRange = (fn, editor) => (range, block) => { for (let i = 0; i <= endIndex - startIndex; i++) { const path = ancestorPath.concat(startIndex + 1) - const newPath = ancestorPath.concat(startIndex) - editor.moveNodeByPath(path, newPath, i) + const newPath = ancestorPath.concat([startIndex, i]) + editor.moveNodeByPath(path, newPath) } }) } @@ -1036,8 +1035,8 @@ Commands.wrapInlineAtRange = (fn, editor) => (range, inline) => { for (let i = 0; i <= endIndex - startIndex; i++) { const path = blockPath.concat(startIndex + 1) - const newPath = blockPath.concat(startIndex) - editor.moveNodeByPath(path, newPath, i) + const newPath = blockPath.concat([startIndex, i]) + editor.moveNodeByPath(path, newPath) } } }) diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index 8bb1238886..c3205ae9a5 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -5,7 +5,7 @@ import Block from '../models/block' import Inline from '../models/inline' import Mark from '../models/mark' import Node from '../models/node' -import PathUtils from '../utils/path-utils' +import Path from '../utils/path-utils' /** * Commands. @@ -25,11 +25,13 @@ const Commands = {} */ Commands.addMarkByPath = (fn, editor) => (path, offset, length, mark) => { + path = Path.create(path) mark = Mark.create(mark) editor.addMarksByPath(path, offset, length, [mark]) } Commands.addMarksByPath = (fn, editor) => (path, offset, length, marks) => { + path = Path.create(path) marks = Mark.createSet(marks) if (!marks.size) { @@ -56,7 +58,7 @@ Commands.addMarksByPath = (fn, editor) => (path, offset, length, marks) => { // update our path and offset to point to the new start. if (offset > 0) { editor.splitNodeByPath(path, offset) - path = PathUtils.increment(path) + path = Path.increment(path) offset = 0 } @@ -79,6 +81,8 @@ Commands.addMarksByPath = (fn, editor) => (path, offset, length, marks) => { */ Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { + path = Path.create(path) + if (typeof index === 'number' && fragment) { warning( false, @@ -92,7 +96,7 @@ Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { index = null } - const parentPath = PathUtils.lift(path) + const parentPath = Path.lift(path) const start = path.last() fragment.nodes.forEach((node, i) => { @@ -110,6 +114,8 @@ Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { */ Commands.insertNodeByPath = (fn, editor) => (path, index, node) => { + path = Path.create(path) + if (typeof index === 'number' && node) { warning( false, @@ -140,6 +146,7 @@ Commands.insertNodeByPath = (fn, editor) => (path, index, node) => { */ Commands.insertTextByPath = (fn, editor) => (path, offset, text, marks) => { + path = Path.create(path) marks = Mark.createSet(marks) const { value } = editor const { annotations, document } = value @@ -186,9 +193,10 @@ Commands.insertTextByPath = (fn, editor) => (path, offset, text, marks) => { */ Commands.mergeNodeByPath = (fn, editor) => path => { + path = Path.create(path) const { value: { document } } = editor const node = document.assertNode(path) - const prevPath = PathUtils.decrement(path) + const prevPath = Path.decrement(path) const prev = document.assertNode(prevPath) const position = prev.object === 'text' ? prev.text.length : prev.nodes.size @@ -205,6 +213,8 @@ Commands.mergeNodeByPath = (fn, editor) => path => { } Commands.mergeBlockByPath = (fn, editor) => path => { + path = Path.create(path) + editor.withoutNormalizing(() => { const { value: { document } } = editor document.assertNode(path) @@ -228,11 +238,10 @@ Commands.mergeBlockByPath = (fn, editor) => path => { } const [, prevPath] = prevBlock - const newParentPath = PathUtils.lift(prevPath) - const newIndex = prevPath.last() + 1 - const newPath = newParentPath.concat(newIndex) + const newPath = Path.increment(prevPath) + const newParentPath = Path.lift(prevPath) - editor.moveNodeByPath(blockPath, newParentPath, newIndex) + editor.moveNodeByPath(blockPath, newPath) editor.mergeNodeByPath(newPath) for (const [ancestor, ancestorPath] of document.ancestors(blockPath)) { @@ -256,6 +265,9 @@ Commands.mergeBlockByPath = (fn, editor) => path => { */ Commands.moveNodeByPath = (fn, editor) => (path, newPath, index) => { + path = Path.create(path) + newPath = Path.create(newPath) + if (typeof index === 'number') { warning( false, @@ -268,11 +280,11 @@ Commands.moveNodeByPath = (fn, editor) => (path, newPath, index) => { // It doesn't make sense to move a node into itself, so abort. // TODO: This should probably throw an error instead? - if (PathUtils.isAbove(path, newPath)) { + if (Path.isAbove(path, newPath)) { return editor } - if (PathUtils.isEqual(path, newPath)) { + if (Path.isEqual(path, newPath)) { return editor } @@ -293,11 +305,13 @@ Commands.moveNodeByPath = (fn, editor) => (path, newPath, index) => { */ Commands.removeMarkByPath = (fn, editor) => (path, offset, length, mark) => { + path = Path.create(path) mark = Mark.create(mark) editor.removeMarksByPath(path, offset, length, [mark]) } Commands.removeMarksByPath = (fn, editor) => (path, offset, length, marks) => { + path = Path.create(path) marks = Mark.createSet(marks) if (!marks.size) { @@ -324,7 +338,7 @@ Commands.removeMarksByPath = (fn, editor) => (path, offset, length, marks) => { // update our path and offset to point to the new start. if (offset > 0) { editor.splitNodeByPath(path, offset) - path = PathUtils.increment(path) + path = Path.increment(path) offset = 0 } @@ -347,6 +361,7 @@ Commands.removeMarksByPath = (fn, editor) => (path, offset, length, marks) => { */ Commands.removeAllMarksByPath = (fn, editor) => path => { + path = Path.create(path) const { state } = editor const { document } = state const node = document.assertNode(path) @@ -371,6 +386,7 @@ Commands.removeAllMarksByPath = (fn, editor) => path => { */ Commands.removeNodeByPath = (fn, editor) => path => { + path = Path.create(path) const { value } = editor const { document } = value const node = document.assertNode(path) @@ -383,6 +399,7 @@ Commands.removeNodeByPath = (fn, editor) => path => { } Commands.removeChildrenByPath = (fn, editor) => path => { + path = Path.create(path) const { value: { document } } = editor const node = document.assertNode(path) @@ -405,6 +422,7 @@ Commands.removeChildrenByPath = (fn, editor) => path => { */ Commands.removeTextByPath = (fn, editor) => (path, offset, length) => { + path = Path.create(path) const { value } = editor const { document, annotations } = value const node = document.assertNode(path) @@ -448,6 +466,7 @@ Commands.removeTextByPath = (fn, editor) => (path, offset, length) => { */ Commands.replaceNodeByPath = (fn, editor) => (path, node) => { + path = Path.create(path) node = Node.create(node) editor.withoutNormalizing(() => { @@ -496,6 +515,7 @@ Commands.setMarkByPath = (fn, editor) => ( properties, newProperties ) => { + path = Path.create(path) properties = Mark.create(properties) newProperties = Mark.createProperties(newProperties) @@ -514,7 +534,7 @@ Commands.setMarkByPath = (fn, editor) => ( // update our path and offset to point to the new start. if (offset > 0) { editor.splitNodeByPath(path, offset) - path = PathUtils.increment(path) + path = Path.increment(path) offset = 0 } @@ -535,10 +555,11 @@ Commands.setMarkByPath = (fn, editor) => ( */ Commands.setNodeByPath = (fn, editor) => (path, newProperties) => { + path = Path.create(path) + newProperties = Node.createProperties(newProperties) const { value } = editor const { document } = value const node = document.assertNode(path) - newProperties = Node.createProperties(newProperties) const prevProperties = pick(node, Object.keys(newProperties)) editor.applyOperation({ @@ -558,6 +579,7 @@ Commands.setNodeByPath = (fn, editor) => (path, newProperties) => { */ Commands.setTextByPath = (fn, editor) => (path, text, marks) => { + path = Path.create(path) const { value } = editor const { document } = value const node = document.assertNode(path) @@ -574,6 +596,7 @@ Commands.setTextByPath = (fn, editor) => (path, text, marks) => { */ Commands.splitNodeByPath = (fn, editor) => (path, position, options = {}) => { + path = Path.create(path) const { target = null } = options const { value } = editor const { document } = value @@ -604,6 +627,9 @@ Commands.splitDescendantsByPath = (fn, editor) => ( textPath, textOffset ) => { + path = Path.create(path) + textPath = Path.create(textPath) + if (path.equals(textPath)) { editor.splitNodeByPath(textPath, textOffset) return @@ -638,6 +664,7 @@ Commands.splitDescendantsByPath = (fn, editor) => ( */ Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { + path = Path.create(path) const { value } = editor const { document, selection } = value const node = document.assertNode(path) @@ -655,6 +682,7 @@ Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { */ Commands.unwrapBlockByPath = (fn, editor) => (path, properties) => { + path = Path.create(path) const { value } = editor const { document, selection } = value const node = document.assertNode(path) @@ -675,31 +703,32 @@ Commands.unwrapBlockByPath = (fn, editor) => (path, properties) => { */ Commands.unwrapNodeByPath = (fn, editor) => path => { + path = Path.create(path) const { value } = editor const { document } = value document.assertNode(path) - const parentPath = PathUtils.lift(path) + const parentPath = Path.lift(path) const parent = document.assertNode(parentPath) const index = path.last() const parentIndex = parentPath.last() - const grandPath = PathUtils.lift(parentPath) + const grandPath = Path.lift(parentPath) const isFirst = index === 0 const isLast = index === parent.nodes.size - 1 editor.withoutNormalizing(() => { if (parent.nodes.size === 1) { - editor.moveNodeByPath(path, grandPath, parentIndex + 1) + editor.moveNodeByPath(path, grandPath.concat(parentIndex + 1)) editor.removeNodeByPath(parentPath) } else if (isFirst) { - editor.moveNodeByPath(path, grandPath, parentIndex) + editor.moveNodeByPath(path, grandPath.concat(parentIndex)) } else if (isLast) { - editor.moveNodeByPath(path, grandPath, parentIndex + 1) + editor.moveNodeByPath(path, grandPath.concat(parentIndex + 1)) } else { - let updatedPath = PathUtils.increment(path, 1, parentPath.size - 1) + let updatedPath = Path.increment(path, 1, parentPath.size - 1) updatedPath = updatedPath.set(updatedPath.size - 1, 0) editor.splitNodeByPath(parentPath, index) - editor.moveNodeByPath(updatedPath, grandPath, parentIndex + 1) + editor.moveNodeByPath(updatedPath, grandPath.concat(parentIndex + 1)) } }) } @@ -712,19 +741,18 @@ Commands.unwrapNodeByPath = (fn, editor) => path => { */ Commands.unwrapChildrenByPath = (fn, editor) => path => { - path = PathUtils.create(path) + path = Path.create(path) const { value } = editor const { document } = value const node = document.assertNode(path) - const parentPath = PathUtils.lift(path) - const index = path.last() + const newPath = Path.increment(path) const { nodes } = node editor.withoutNormalizing(() => { nodes.reverse().forEach((child, i) => { const childIndex = nodes.size - i - 1 const childPath = path.push(childIndex) - editor.moveNodeByPath(childPath, parentPath, index + 1) + editor.moveNodeByPath(childPath, newPath) }) editor.removeNodeByPath(path) @@ -739,13 +767,14 @@ Commands.unwrapChildrenByPath = (fn, editor) => path => { */ Commands.wrapBlockByPath = (fn, editor) => (path, block) => { + path = Path.create(path) block = Block.create(block) block = block.set('nodes', block.nodes.clear()) - const newPath = PathUtils.increment(path) + const newPath = Path.increment(path) editor.withoutNormalizing(() => { editor.insertNodeByPath(path, block) - editor.moveNodeByPath(newPath, path, 0) + editor.moveNodeByPath(newPath, path.concat(0)) }) } @@ -757,13 +786,14 @@ Commands.wrapBlockByPath = (fn, editor) => (path, block) => { */ Commands.wrapInlineByPath = (fn, editor) => (path, inline) => { + path = Path.create(path) inline = Inline.create(inline) inline = inline.set('nodes', inline.nodes.clear()) - const newPath = PathUtils.increment(path) + const newPath = Path.increment(path) editor.withoutNormalizing(() => { editor.insertNodeByPath(path, inline) - editor.moveNodeByPath(newPath, path, 0) + editor.moveNodeByPath(newPath, path.concat(0)) }) } @@ -775,6 +805,7 @@ Commands.wrapInlineByPath = (fn, editor) => (path, inline) => { */ Commands.wrapNodeByPath = (fn, editor) => (path, node) => { + path = Path.create(path) node = Node.create(node) if (node.object === 'block') { diff --git a/packages/slate/test/commands/by-key/insert-node-by-key/duplicate.js b/packages/slate/test/commands/by-key/insert-node-by-key/duplicate.js deleted file mode 100644 index 8374a5b69e..0000000000 --- a/packages/slate/test/commands/by-key/insert-node-by-key/duplicate.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - const node = editor.value.document.getBlocks().first() - editor.insertNodeByKey('a', 0, node) -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - one - - one - - - -) - -/* - * Slate v0.37: We no longer support duplicate key check in either insertNode and replaceNode -*/ - -export const skip = true diff --git a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-active-marks-with-data.js b/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-active-marks-with-data.js deleted file mode 100644 index 37c798eebb..0000000000 --- a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-active-marks-with-data.js +++ /dev/null @@ -1,40 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - const { anchor } = editor.value.selection - - editor.replaceTextByKey(anchor.key, anchor.offset, 3, 'cat is cute', [ - { type: 'font-size', data: { size: 16 } }, - ]) -} - -export const input = ( - - - - Meow,{' '} - - word. - - - - -) - -export const output = ( - - - - Meow,{' '} - - cat is cute - - - d. - - - - -) diff --git a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-mark-and-active-mark.js b/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-mark-and-active-mark.js deleted file mode 100644 index cd889c4fff..0000000000 --- a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-mark-and-active-mark.js +++ /dev/null @@ -1,40 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - const { anchor } = editor.value.selection - - editor.replaceTextByKey(anchor.key, anchor.offset, 3, 'cat is cute', [ - { type: 'italic' }, - ]) -} - -export const input = ( - - - - Meow,{' '} - - word. - - - - -) - -export const output = ( - - - - Meow,{' '} - - cat is cute - - - d. - - - - -) diff --git a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-node-index-mark.js b/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-node-index-mark.js deleted file mode 100644 index 5cea7912f5..0000000000 --- a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-node-index-mark.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - const { anchor } = editor.value.selection - editor.replaceTextByKey(anchor.key, anchor.offset, 3, 'cat is cute') -} - -export const input = ( - - - - Meow, - word. - - - -) - -export const output = ( - - - - Meow, - cat is cuted. - - - -) diff --git a/packages/slate/test/commands/by-key/replace-text-by-key/replace-without-any-marks.js b/packages/slate/test/commands/by-key/replace-text-by-key/replace-without-any-marks.js deleted file mode 100644 index f03bfc83a6..0000000000 --- a/packages/slate/test/commands/by-key/replace-text-by-key/replace-without-any-marks.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - const { anchor } = editor.value.selection - editor.replaceTextByKey(anchor.key, anchor.offset, 3, 'cat is cute') -} - -export const input = ( - - - - Meow, word. - - - -) - -export const output = ( - - - - Meow, cat is cuted. - - - -) diff --git a/packages/slate/test/commands/by-key/set-text-by-key/replace-with-string-and-mark.js b/packages/slate/test/commands/by-key/set-text-by-key/replace-with-string-and-mark.js deleted file mode 100644 index 60268f44a9..0000000000 --- a/packages/slate/test/commands/by-key/set-text-by-key/replace-with-string-and-mark.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.setTextByKey(editor.value.selection.anchor.key, 'cat is cute', [ - { type: 'bold' }, - { type: 'italic' }, - ]) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - cat is cute - - - - - -) diff --git a/packages/slate/test/commands/by-key/insert-fragment-by-key/end-of-target.js b/packages/slate/test/commands/by-path/insert-fragment-by-path/end-of-target.js similarity index 87% rename from packages/slate/test/commands/by-key/insert-fragment-by-key/end-of-target.js rename to packages/slate/test/commands/by-path/insert-fragment-by-path/end-of-target.js index ee7cda6bb5..ea63b917f9 100644 --- a/packages/slate/test/commands/by-key/insert-fragment-by-key/end-of-target.js +++ b/packages/slate/test/commands/by-path/insert-fragment-by-path/end-of-target.js @@ -3,9 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertFragmentByKey( - 'a', - 1, + editor.insertFragmentByPath( + [1], one two @@ -15,7 +14,7 @@ export default function(editor) { export const input = ( - + word diff --git a/packages/slate/test/commands/by-key/insert-fragment-by-key/middle-of-target.js b/packages/slate/test/commands/by-path/insert-fragment-by-path/middle-of-target.js similarity index 88% rename from packages/slate/test/commands/by-key/insert-fragment-by-key/middle-of-target.js rename to packages/slate/test/commands/by-path/insert-fragment-by-path/middle-of-target.js index b786649ff5..c6c630da80 100644 --- a/packages/slate/test/commands/by-key/insert-fragment-by-key/middle-of-target.js +++ b/packages/slate/test/commands/by-path/insert-fragment-by-path/middle-of-target.js @@ -3,9 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertFragmentByKey( - 'a', - 1, + editor.insertFragmentByPath( + [1], one two @@ -15,7 +14,7 @@ export default function(editor) { export const input = ( - + word another diff --git a/packages/slate/test/commands/by-key/insert-fragment-by-key/start-of-target.js b/packages/slate/test/commands/by-path/insert-fragment-by-path/start-of-target.js similarity index 88% rename from packages/slate/test/commands/by-key/insert-fragment-by-key/start-of-target.js rename to packages/slate/test/commands/by-path/insert-fragment-by-path/start-of-target.js index f000145825..c26ccf3d78 100644 --- a/packages/slate/test/commands/by-key/insert-fragment-by-key/start-of-target.js +++ b/packages/slate/test/commands/by-path/insert-fragment-by-path/start-of-target.js @@ -3,9 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertFragmentByKey( - 'a', - 0, + editor.insertFragmentByPath( + [0], one two @@ -15,7 +14,7 @@ export default function(editor) { export const input = ( - + word diff --git a/packages/slate/test/commands/by-key/insert-node-by-key/block.js b/packages/slate/test/commands/by-path/insert-node-by-path/block.js similarity index 82% rename from packages/slate/test/commands/by-key/insert-node-by-key/block.js rename to packages/slate/test/commands/by-path/insert-node-by-path/block.js index 44af310c36..1e45d87f6e 100644 --- a/packages/slate/test/commands/by-key/insert-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/insert-node-by-path/block.js @@ -4,12 +4,12 @@ import h from '../../../helpers/h' import { Block } from 'slate' export default function(editor) { - editor.insertNodeByKey('a', 0, Block.create('paragraph')) + editor.insertNodeByPath([0], Block.create('paragraph')) } export const input = ( - + one diff --git a/packages/slate/test/commands/by-key/insert-node-by-key/inline.js b/packages/slate/test/commands/by-path/insert-node-by-path/inline.js similarity index 82% rename from packages/slate/test/commands/by-key/insert-node-by-key/inline.js rename to packages/slate/test/commands/by-path/insert-node-by-path/inline.js index 9e4c640341..425e6ec08c 100644 --- a/packages/slate/test/commands/by-key/insert-node-by-key/inline.js +++ b/packages/slate/test/commands/by-path/insert-node-by-path/inline.js @@ -4,13 +4,13 @@ import h from '../../../helpers/h' import { Inline } from 'slate' export default function(editor) { - editor.insertNodeByKey('a', 0, Inline.create('emoji')) + editor.insertNodeByPath([0, 0], Inline.create('emoji')) } export const input = ( - + word diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/decoration-after-atomic.js b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-after-atomic.js similarity index 91% rename from packages/slate/test/commands/by-key/insert-text-by-key/decoration-after-atomic.js rename to packages/slate/test/commands/by-path/insert-text-by-path/decoration-after-atomic.js index 3d4b1ff110..a5db353e78 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/decoration-after-atomic.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-after-atomic.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 4, 'x') + editor.insertTextByPath([0, 0], 4, 'x') } export const options = { diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/decoration-before-atomic.js b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-before-atomic.js similarity index 91% rename from packages/slate/test/commands/by-key/insert-text-by-key/decoration-before-atomic.js rename to packages/slate/test/commands/by-path/insert-text-by-path/decoration-before-atomic.js index be17eee6b2..19bf659d6e 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/decoration-before-atomic.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-before-atomic.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 1, 'x') + editor.insertTextByPath([0, 0], 1, 'x') } export const options = { diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/decoration-middle-atomic.js b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-middle-atomic.js similarity index 91% rename from packages/slate/test/commands/by-key/insert-text-by-key/decoration-middle-atomic.js rename to packages/slate/test/commands/by-path/insert-text-by-path/decoration-middle-atomic.js index fbaf854eed..42dccf5ca2 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/decoration-middle-atomic.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-middle-atomic.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 2, 'x') + editor.insertTextByPath([0, 0], 2, 'x') } export const options = { diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/selection-after.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-after.js similarity index 90% rename from packages/slate/test/commands/by-key/insert-text-by-key/selection-after.js rename to packages/slate/test/commands/by-path/insert-text-by-path/selection-after.js index 9f44b51db2..ea3fa19e77 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/selection-after.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/selection-after.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 4, 'x') + editor.insertTextByPath([0, 0], 4, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/selection-before.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-before.js similarity index 90% rename from packages/slate/test/commands/by-key/insert-text-by-key/selection-before.js rename to packages/slate/test/commands/by-path/insert-text-by-path/selection-before.js index dcbdf6ffb4..50ca1145d6 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/selection-before.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/selection-before.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 0, 'x') + editor.insertTextByPath([0, 0], 0, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/selection-end.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-end.js similarity index 90% rename from packages/slate/test/commands/by-key/insert-text-by-key/selection-end.js rename to packages/slate/test/commands/by-path/insert-text-by-path/selection-end.js index f199d056d3..be11f8392e 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/selection-end.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/selection-end.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 3, 'x') + editor.insertTextByPath([0, 0], 3, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/selection-middle.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-middle.js similarity index 90% rename from packages/slate/test/commands/by-key/insert-text-by-key/selection-middle.js rename to packages/slate/test/commands/by-path/insert-text-by-path/selection-middle.js index 42f04c49ce..17cf47a9e3 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/selection-middle.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/selection-middle.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 2, 'x') + editor.insertTextByPath([0, 0], 2, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/selection-start.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-start.js similarity index 90% rename from packages/slate/test/commands/by-key/insert-text-by-key/selection-start.js rename to packages/slate/test/commands/by-path/insert-text-by-path/selection-start.js index 8fc097c50e..da3696d5ee 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/selection-start.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/selection-start.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 1, 'x') + editor.insertTextByPath([0, 0], 1, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/text-end-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js similarity index 91% rename from packages/slate/test/commands/by-key/insert-text-by-key/text-end-with-marks.js rename to packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js index 4e7201f062..2820e8a150 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/text-end-with-marks.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 4, 'x') + editor.insertTextByPath([0, 0], 4, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/text-end.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-end.js similarity index 89% rename from packages/slate/test/commands/by-key/insert-text-by-key/text-end.js rename to packages/slate/test/commands/by-path/insert-text-by-path/text-end.js index c562a83b2c..c58803edcd 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/text-end.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-end.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 4, 'x') + editor.insertTextByPath([0, 0], 4, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/text-middle-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-middle-with-marks.js similarity index 86% rename from packages/slate/test/commands/by-key/insert-text-by-key/text-middle-with-marks.js rename to packages/slate/test/commands/by-path/insert-text-by-path/text-middle-with-marks.js index e130a9a2a6..5430d29389 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/text-middle-with-marks.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-middle-with-marks.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 2, 'x', [{ type: 'bold' }]) + editor.insertTextByPath([0, 0], 2, 'x', [{ type: 'bold' }]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/text-middle.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-middle.js similarity index 89% rename from packages/slate/test/commands/by-key/insert-text-by-key/text-middle.js rename to packages/slate/test/commands/by-path/insert-text-by-path/text-middle.js index aa29046c0c..3f21253722 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/text-middle.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-middle.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 2, 'x') + editor.insertTextByPath([0, 0], 2, 'x') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/text-start-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js similarity index 91% rename from packages/slate/test/commands/by-key/insert-text-by-key/text-start-with-marks.js rename to packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js index 05d9c5614d..039fabe31e 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/text-start-with-marks.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 0, 'a') + editor.insertTextByPath([0, 0], 0, 'a') } export const input = ( diff --git a/packages/slate/test/commands/by-key/insert-text-by-key/text-start.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-start.js similarity index 90% rename from packages/slate/test/commands/by-key/insert-text-by-key/text-start.js rename to packages/slate/test/commands/by-path/insert-text-by-path/text-start.js index bac3ecd802..217d1e3c4e 100644 --- a/packages/slate/test/commands/by-key/insert-text-by-key/text-start.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-start.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.insertTextByKey('a', 0, 'a') + editor.insertTextByPath([0, 0], 0, 'a') } export const input = ( diff --git a/packages/slate/test/commands/by-key/merge-node-by-key/block.js b/packages/slate/test/commands/by-path/merge-node-by-path/block.js similarity index 81% rename from packages/slate/test/commands/by-key/merge-node-by-key/block.js rename to packages/slate/test/commands/by-path/merge-node-by-path/block.js index 8ff3a64de2..7c8f423b9c 100644 --- a/packages/slate/test/commands/by-key/merge-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/merge-node-by-path/block.js @@ -3,14 +3,14 @@ import h from '../../../helpers/h' export default function(editor) { - editor.mergeNodeByKey('a') + editor.mergeNodeByPath([1]) } export const input = ( one - two + two ) diff --git a/packages/slate/test/commands/by-key/move-node-by-key/block.js b/packages/slate/test/commands/by-path/move-node-by-path/block.js similarity index 82% rename from packages/slate/test/commands/by-key/move-node-by-key/block.js rename to packages/slate/test/commands/by-path/move-node-by-path/block.js index 8ace0a4738..2286e6a7ec 100644 --- a/packages/slate/test/commands/by-key/move-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/move-node-by-path/block.js @@ -3,13 +3,13 @@ import h from '../../../helpers/h' export default function(editor) { - editor.moveNodeByKey('a', 'b', 1) + editor.moveNodeByPath([0], [1]) } export const input = ( - - + + one two diff --git a/packages/slate/test/commands/by-key/move-node-by-key/inline.js b/packages/slate/test/commands/by-path/move-node-by-path/inline.js similarity index 71% rename from packages/slate/test/commands/by-key/move-node-by-key/inline.js rename to packages/slate/test/commands/by-path/move-node-by-path/inline.js index bf661259e8..9912480162 100644 --- a/packages/slate/test/commands/by-key/move-node-by-key/inline.js +++ b/packages/slate/test/commands/by-path/move-node-by-path/inline.js @@ -3,17 +3,20 @@ import h from '../../../helpers/h' export default function(editor) { - editor.moveNodeByKey('a', 'b', 3) + editor.moveNodeByPath([0, 1], [0, 3]) } export const input = ( - - + + + one + two + @@ -23,10 +26,13 @@ export const output = ( + two + one + diff --git a/packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js b/packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js new file mode 100644 index 0000000000..6627b4164c --- /dev/null +++ b/packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.moveNodeByPath([0], [1, 0]) +} + +export const input = ( + + + one + + two + + + +) + +export const output = ( + + + + + one + + + + +) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/inside-next.js b/packages/slate/test/commands/by-path/move-node-by-path/inside-next.js new file mode 100644 index 0000000000..37235dac8a --- /dev/null +++ b/packages/slate/test/commands/by-path/move-node-by-path/inside-next.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import h from '../../../helpers/h' +import { PathUtils } from 'slate' + +export default function(editor) { + editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1, 1])) +} + +export const input = ( + + + + one + + + two + + + +) + +export const output = ( + + + + two + + one + + + + +) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/nested.js b/packages/slate/test/commands/by-path/move-node-by-path/nested.js new file mode 100644 index 0000000000..44ec5b7bcd --- /dev/null +++ b/packages/slate/test/commands/by-path/move-node-by-path/nested.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' +import { PathUtils } from 'slate' + +export default function(editor) { + editor.moveNodeByPath(PathUtils.create([0, 0]), PathUtils.create([1, 0])) +} + +export const input = ( + + + + one + + + two + + + +) + +export const output = ( + + + + + one + two + + + +) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/new-path-exists.js b/packages/slate/test/commands/by-path/move-node-by-path/new-path-exists.js deleted file mode 100644 index 97f503b4b6..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/new-path-exists.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' -import assert from 'assert' - -const pathA = PathUtils.create([0, 0]) -const pathB = PathUtils.create([1]) - -export default function(editor) { - editor.moveNodeByPath(pathA, pathB, 0) - assert(editor.operations.size >= 1) -} - -export const input = ( - - - - I am gonna move - - - I am an existing node at newPath - - - -) - -export const output = ( - - - - - I am gonna move - I am an existing node at newPath - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/new-sibling-is-text-node.js b/packages/slate/test/commands/by-path/move-node-by-path/new-sibling-is-text-node.js deleted file mode 100644 index 507c03bb4b..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/new-sibling-is-text-node.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' -import assert from 'assert' - -const pathA = PathUtils.create([0]) -const pathB = PathUtils.create([1]) - -export default function(editor) { - editor.moveNodeByPath(pathA, pathB, 1) - assert(editor.operations.size >= 1) -} - -export const input = ( - - - I am gonna move - - Existing text - - - -) - -export const output = ( - - - - Existing textI am gonna move - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js b/packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js new file mode 100644 index 0000000000..c4c4e7f059 --- /dev/null +++ b/packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import h from '../../../helpers/h' +import { PathUtils } from 'slate' + +export default function(editor) { + editor.moveNodeByPath(PathUtils.create([1]), PathUtils.create([1])) +} + +export const input = ( + + + 1 + 2 + + +) + +export const output = input diff --git a/packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js b/packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js new file mode 100644 index 0000000000..f9d8f1a105 --- /dev/null +++ b/packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import h from '../../../helpers/h' +import { PathUtils } from 'slate' + +export default function(editor) { + editor.moveNodeByPath(PathUtils.create([1]), PathUtils.create([1, 0])) +} + +export const input = ( + + + 1 + 2 + + +) + +export const output = input diff --git a/packages/slate/test/commands/by-path/move-node-by-path/path-equals-new-path.js b/packages/slate/test/commands/by-path/move-node-by-path/path-equals-new-path.js deleted file mode 100644 index f18c2ced2a..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/path-equals-new-path.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' -import assert from 'assert' - -const pathA = PathUtils.create([0]) -const pathB = PathUtils.create([1]) - -export default function(editor) { - editor.moveNodeByPath(pathA, pathA, 0) - editor.moveNodeByPath(pathA, pathA, 1) - editor.moveNodeByPath(pathB, pathB, 0) - editor.moveNodeByPath(pathB, pathB, 1) - assert(editor.operations.size === 0) -} - -export const input = ( - - - 1 - 2 - - -) - -export const output = ( - - - 1 - 2 - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/path-left-sibling-of-new-path-ancestor.js b/packages/slate/test/commands/by-path/move-node-by-path/path-left-sibling-of-new-path-ancestor.js deleted file mode 100644 index 77515b3133..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/path-left-sibling-of-new-path-ancestor.js +++ /dev/null @@ -1,39 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' -import assert from 'assert' - -const pathA = PathUtils.create([0]) -const pathB = PathUtils.create([1]) - -export default function(editor) { - editor.moveNodeByPath(pathA, pathB, 1) - assert(editor.operations.size >= 1) -} - -export const input = ( - - - - I am gonna move - - - I am an existing node in newParent - - - -) - -export const output = ( - - - - I am an existing node in newParent - - I am gonna move - - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js b/packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js index f9d0445938..bcd209ecc0 100644 --- a/packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js +++ b/packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js @@ -1,26 +1,19 @@ /** @jsx h */ import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' -import assert from 'assert' - -const pathA = PathUtils.create([0, 0]) -const pathB = PathUtils.create([0]) +import { PathUtils } from 'slate' export default function(editor) { - editor.moveNodeByPath(pathA, pathB, 1) - assert(editor.operations.size >= 1) + editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1])) } export const input = ( - - I am gonna move - - I am an existing node at newPath + one + two ) @@ -28,11 +21,9 @@ export const input = ( export const output = ( + two - I am an existing node at newPath - - I am gonna move - + one diff --git a/packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js b/packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js index 1266663ab0..d5f339798b 100644 --- a/packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js +++ b/packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js @@ -1,23 +1,18 @@ /** @jsx h */ import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' -import assert from 'assert' - -const pathA = PathUtils.create([0, 0]) -const pathB = PathUtils.create([1]) +import { PathUtils } from 'slate' export default function(editor) { - editor.moveNodeByPath(pathA, pathB, 1) - assert(editor.operations.size >= 1) + editor.moveNodeByPath(PathUtils.create([0, 0]), PathUtils.create([1, 0])) } export const input = ( - Text that will move + one - Existing text + two @@ -28,7 +23,7 @@ export const output = ( - Existing textText that will move + onetwo diff --git a/packages/slate/test/commands/by-key/move-node-by-key/text.js b/packages/slate/test/commands/by-path/move-node-by-path/text.js similarity index 67% rename from packages/slate/test/commands/by-key/move-node-by-key/text.js rename to packages/slate/test/commands/by-path/move-node-by-path/text.js index ec1cc4c920..cfe8ebd6e4 100644 --- a/packages/slate/test/commands/by-key/move-node-by-key/text.js +++ b/packages/slate/test/commands/by-path/move-node-by-path/text.js @@ -3,16 +3,14 @@ import h from '../../../helpers/h' export default function(editor) { - editor.moveNodeByKey('a', 'b', 1) + editor.moveNodeByPath([1, 0], [0, 1]) } export const input = ( - one - - two - + one + two ) diff --git a/packages/slate/test/commands/by-key/move-node-by-key/to-sibling.js b/packages/slate/test/commands/by-path/move-node-by-path/to-sibling.js similarity index 93% rename from packages/slate/test/commands/by-key/move-node-by-key/to-sibling.js rename to packages/slate/test/commands/by-path/move-node-by-path/to-sibling.js index 0af8b27612..bb2c0313e8 100644 --- a/packages/slate/test/commands/by-key/move-node-by-key/to-sibling.js +++ b/packages/slate/test/commands/by-path/move-node-by-path/to-sibling.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.moveNodeByKey('a', 'b', 1) + editor.moveNodeByPath([0], [1, 1]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-node-by-key/block.js b/packages/slate/test/commands/by-path/remove-node-by-path/block.js similarity index 91% rename from packages/slate/test/commands/by-key/remove-node-by-key/block.js rename to packages/slate/test/commands/by-path/remove-node-by-path/block.js index cd42f9a505..119d1f1439 100644 --- a/packages/slate/test/commands/by-key/remove-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/remove-node-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeNodeByKey('a') + editor.removeNodeByPath([1]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-node-by-key/inline.js b/packages/slate/test/commands/by-path/remove-node-by-path/inline.js similarity index 93% rename from packages/slate/test/commands/by-key/remove-node-by-key/inline.js rename to packages/slate/test/commands/by-path/remove-node-by-path/inline.js index 02773dbaa3..7a44de904a 100644 --- a/packages/slate/test/commands/by-key/remove-node-by-key/inline.js +++ b/packages/slate/test/commands/by-path/remove-node-by-path/inline.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeNodeByKey('a') + editor.removeNodeByPath([0, 1]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-node-by-key/selection-inside.js b/packages/slate/test/commands/by-path/remove-node-by-path/selection-inside.js similarity index 93% rename from packages/slate/test/commands/by-key/remove-node-by-key/selection-inside.js rename to packages/slate/test/commands/by-path/remove-node-by-path/selection-inside.js index b6f88b17c1..a9c2fde90b 100644 --- a/packages/slate/test/commands/by-key/remove-node-by-key/selection-inside.js +++ b/packages/slate/test/commands/by-path/remove-node-by-path/selection-inside.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeNodeByKey('a') + editor.removeNodeByPath([1, 0]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-node-by-key/text.js b/packages/slate/test/commands/by-path/remove-node-by-path/text.js similarity index 93% rename from packages/slate/test/commands/by-key/remove-node-by-key/text.js rename to packages/slate/test/commands/by-path/remove-node-by-path/text.js index 827f27bd3d..f36e1215a1 100644 --- a/packages/slate/test/commands/by-key/remove-node-by-key/text.js +++ b/packages/slate/test/commands/by-path/remove-node-by-path/text.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeNodeByKey('a') + editor.removeNodeByPath([0, 0]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/adjacent-non-void-inlines.js b/packages/slate/test/commands/by-path/remove-text-by-path/adjacent-non-void-inlines.js similarity index 78% rename from packages/slate/test/commands/by-key/remove-text-by-key/adjacent-non-void-inlines.js rename to packages/slate/test/commands/by-path/remove-text-by-path/adjacent-non-void-inlines.js index a114e13434..1acff4e7d4 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/adjacent-non-void-inlines.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/adjacent-non-void-inlines.js @@ -3,16 +3,18 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 2], 0, 1) } export const input = ( + one a two + @@ -22,8 +24,11 @@ export const output = ( + one + two + diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/decoration-after-atomic.js b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-after-atomic.js similarity index 92% rename from packages/slate/test/commands/by-key/remove-text-by-key/decoration-after-atomic.js rename to packages/slate/test/commands/by-path/remove-text-by-path/decoration-after-atomic.js index 0067d3785f..cd500f8a68 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/decoration-after-atomic.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-after-atomic.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 3, 1) + editor.removeTextByPath([0, 0], 3, 1) } export const options = { diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/decoration-before-atomic.js b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-before-atomic.js similarity index 92% rename from packages/slate/test/commands/by-key/remove-text-by-key/decoration-before-atomic.js rename to packages/slate/test/commands/by-path/remove-text-by-path/decoration-before-atomic.js index c2c4388f33..566a23118e 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/decoration-before-atomic.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-before-atomic.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 0], 0, 1) } export const options = { diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/decoration-middle-atomic.js b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-middle-atomic.js similarity index 91% rename from packages/slate/test/commands/by-key/remove-text-by-key/decoration-middle-atomic.js rename to packages/slate/test/commands/by-path/remove-text-by-path/decoration-middle-atomic.js index e3b68c90ed..a0b646b193 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/decoration-middle-atomic.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-middle-atomic.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 2, 1) + editor.removeTextByPath([0, 0], 2, 1) } export const options = { diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/inline-last-character.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline-last-character.js similarity index 92% rename from packages/slate/test/commands/by-key/remove-text-by-key/inline-last-character.js rename to packages/slate/test/commands/by-path/remove-text-by-path/inline-last-character.js index 5837b1cc27..28f60d1864 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/inline-last-character.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/inline-last-character.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 1, 0], 0, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/inline-nested-last-character.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline-nested-last-character.js similarity index 74% rename from packages/slate/test/commands/by-key/remove-text-by-key/inline-nested-last-character.js rename to packages/slate/test/commands/by-path/remove-text-by-path/inline-nested-last-character.js index 129f2b3997..332bd28a80 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/inline-nested-last-character.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/inline-nested-last-character.js @@ -3,20 +3,24 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 1, 1, 0], 0, 1) } export const input = ( + + a + + @@ -26,11 +30,15 @@ export const output = ( + + + + diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/inline-void.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline-void.js similarity index 80% rename from packages/slate/test/commands/by-key/remove-text-by-key/inline-void.js rename to packages/slate/test/commands/by-path/remove-text-by-path/inline-void.js index f5f426b632..b0bdc186d6 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/inline-void.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/inline-void.js @@ -3,18 +3,20 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 1, 0], 0, 1) } export const input = ( + a + @@ -24,9 +26,11 @@ export const output = ( + + diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/inline.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline.js similarity index 91% rename from packages/slate/test/commands/by-key/remove-text-by-key/inline.js rename to packages/slate/test/commands/by-path/remove-text-by-path/inline.js index 248ba20522..854cbc2f33 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/inline.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/inline.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 3, 1) + editor.removeTextByPath([0, 1, 0], 3, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/next-void-inline.js b/packages/slate/test/commands/by-path/remove-text-by-path/next-void-inline.js similarity index 77% rename from packages/slate/test/commands/by-key/remove-text-by-key/next-void-inline.js rename to packages/slate/test/commands/by-path/remove-text-by-path/next-void-inline.js index 302957a9ae..259e41033b 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/next-void-inline.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/next-void-inline.js @@ -3,16 +3,18 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 2], 0, 1) } export const input = ( + one a + @@ -22,8 +24,11 @@ export const output = ( + one + + diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/previous-void-inline.js b/packages/slate/test/commands/by-path/remove-text-by-path/previous-void-inline.js similarity index 92% rename from packages/slate/test/commands/by-key/remove-text-by-key/previous-void-inline.js rename to packages/slate/test/commands/by-path/remove-text-by-path/previous-void-inline.js index 937f21c7cd..0441200f8b 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/previous-void-inline.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/previous-void-inline.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 2], 0, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/selection-after.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-after.js similarity index 91% rename from packages/slate/test/commands/by-key/remove-text-by-key/selection-after.js rename to packages/slate/test/commands/by-path/remove-text-by-path/selection-after.js index a7ee4b9675..a7cb2f9095 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/selection-after.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/selection-after.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 3, 1) + editor.removeTextByPath([0, 0], 3, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/selection-before.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-before.js similarity index 91% rename from packages/slate/test/commands/by-key/remove-text-by-key/selection-before.js rename to packages/slate/test/commands/by-path/remove-text-by-path/selection-before.js index 071d5577b3..866855a78a 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/selection-before.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/selection-before.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 0, 1) + editor.removeTextByPath([0, 0], 0, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/selection-middle.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-middle.js similarity index 91% rename from packages/slate/test/commands/by-key/remove-text-by-key/selection-middle.js rename to packages/slate/test/commands/by-path/remove-text-by-path/selection-middle.js index bb6e4e7784..ab1fe117bd 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/selection-middle.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/selection-middle.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 2, 1) + editor.removeTextByPath([0, 0], 2, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/selection-start.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-start.js similarity index 91% rename from packages/slate/test/commands/by-key/remove-text-by-key/selection-start.js rename to packages/slate/test/commands/by-path/remove-text-by-path/selection-start.js index 27b849419c..9856d38c01 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/selection-start.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/selection-start.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 2, 1) + editor.removeTextByPath([0, 0], 2, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/remove-text-by-key/text.js b/packages/slate/test/commands/by-path/remove-text-by-path/text.js similarity index 89% rename from packages/slate/test/commands/by-key/remove-text-by-key/text.js rename to packages/slate/test/commands/by-path/remove-text-by-path/text.js index cc4acc14fb..85ac9ecbc0 100644 --- a/packages/slate/test/commands/by-key/remove-text-by-key/text.js +++ b/packages/slate/test/commands/by-path/remove-text-by-path/text.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.removeTextByKey('a', 3, 1) + editor.removeTextByPath([0, 0], 3, 1) } export const input = ( diff --git a/packages/slate/test/commands/by-key/replace-node-by-key/block.js b/packages/slate/test/commands/by-path/replace-node-by-path/block.js similarity index 84% rename from packages/slate/test/commands/by-key/replace-node-by-key/block.js rename to packages/slate/test/commands/by-path/replace-node-by-path/block.js index 5dcd16492d..2536c1541d 100644 --- a/packages/slate/test/commands/by-key/replace-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/replace-node-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.replaceNodeByKey('a', { object: 'block', type: 'quote' }) + editor.replaceNodeByPath([1], { object: 'block', type: 'quote' }) } export const input = ( diff --git a/packages/slate/test/commands/by-key/replace-node-by-key/inline.js b/packages/slate/test/commands/by-path/replace-node-by-path/inline.js similarity index 72% rename from packages/slate/test/commands/by-key/replace-node-by-key/inline.js rename to packages/slate/test/commands/by-path/replace-node-by-path/inline.js index 864ad926f3..e95a23fb09 100644 --- a/packages/slate/test/commands/by-key/replace-node-by-key/inline.js +++ b/packages/slate/test/commands/by-path/replace-node-by-path/inline.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.replaceNodeByKey('a', { + editor.replaceNodeByPath([0, 1], { object: 'inline', type: 'emoji', }) @@ -13,7 +13,9 @@ export const input = ( - one two + one + two + three @@ -23,7 +25,9 @@ export const output = ( - one + one + + three diff --git a/packages/slate/test/commands/by-key/replace-node-by-key/text.js b/packages/slate/test/commands/by-path/replace-node-by-path/text.js similarity index 71% rename from packages/slate/test/commands/by-key/replace-node-by-key/text.js rename to packages/slate/test/commands/by-path/replace-node-by-path/text.js index 1935cee447..92c83ac6a3 100644 --- a/packages/slate/test/commands/by-key/replace-node-by-key/text.js +++ b/packages/slate/test/commands/by-path/replace-node-by-path/text.js @@ -3,16 +3,14 @@ import h from '../../../helpers/h' export default function(editor) { - editor.replaceNodeByKey('a', { object: 'text', text: 'three' }) + editor.replaceNodeByPath([1, 0], { object: 'text', text: 'three' }) } export const input = ( one - - one - + two ) diff --git a/packages/slate/test/commands/by-key/set-text-by-key/replace-with-string.js b/packages/slate/test/commands/by-path/replace-text-by-path/replace.js similarity index 71% rename from packages/slate/test/commands/by-key/set-text-by-key/replace-with-string.js rename to packages/slate/test/commands/by-path/replace-text-by-path/replace.js index 1f0cb10291..c225f26732 100644 --- a/packages/slate/test/commands/by-key/set-text-by-key/replace-with-string.js +++ b/packages/slate/test/commands/by-path/replace-text-by-path/replace.js @@ -3,14 +3,14 @@ import h from '../../../helpers/h' export default function(editor) { - editor.setTextByKey(editor.value.selection.anchor.key, 'cat is cute') + editor.replaceTextByPath([0, 0], 3, 1, 'three') } export const input = ( - word + onetwo @@ -20,7 +20,7 @@ export const output = ( - cat is cute + onethreewo diff --git a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-active-marks.js b/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js similarity index 63% rename from packages/slate/test/commands/by-key/replace-text-by-key/replace-with-active-marks.js rename to packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js index e04f282b17..dcfdc236fc 100644 --- a/packages/slate/test/commands/by-key/replace-text-by-key/replace-with-active-marks.js +++ b/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js @@ -3,17 +3,16 @@ import h from '../../../helpers/h' export default function(editor) { - const { anchor } = editor.value.selection - editor.replaceTextByKey(anchor.key, anchor.offset, 3, 'cat is cute') + editor.replaceTextByPath([0, 1], 0, 1, 'three', ['italic']) } export const input = ( - Meow,{' '} + one - word. + two @@ -24,9 +23,12 @@ export const output = ( - Meow,{' '} + one + + three + - cat is cuted. + wo diff --git a/packages/slate/test/commands/by-key/set-mark-by-key/with-data.js b/packages/slate/test/commands/by-path/set-mark-by-path/with-data.js similarity index 84% rename from packages/slate/test/commands/by-key/set-mark-by-key/with-data.js rename to packages/slate/test/commands/by-path/set-mark-by-path/with-data.js index 0fb34cbef9..b6d02d0d29 100644 --- a/packages/slate/test/commands/by-key/set-mark-by-key/with-data.js +++ b/packages/slate/test/commands/by-path/set-mark-by-path/with-data.js @@ -3,8 +3,8 @@ import h from '../../../helpers/h' export default function(editor) { - editor.setMarkByKey( - 'a', + editor.setMarkByPath( + [0, 0], 0, 2, { @@ -21,9 +21,7 @@ export const input = ( - - word - + word diff --git a/packages/slate/test/commands/by-key/set-node-by-key/block.js b/packages/slate/test/commands/by-path/set-node-by-path/block.js similarity index 92% rename from packages/slate/test/commands/by-key/set-node-by-key/block.js rename to packages/slate/test/commands/by-path/set-node-by-path/block.js index 3d3dfcc8bb..23c44cf917 100644 --- a/packages/slate/test/commands/by-key/set-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/set-node-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.setNodeByKey('a', { + editor.setNodeByPath([0], { type: 'quote', data: { thing: false }, }) diff --git a/packages/slate/test/commands/by-key/set-node-by-key/inline-with-is-void.js b/packages/slate/test/commands/by-path/set-node-by-path/inline-with-is-void.js similarity index 80% rename from packages/slate/test/commands/by-key/set-node-by-key/inline-with-is-void.js rename to packages/slate/test/commands/by-path/set-node-by-path/inline-with-is-void.js index 872fd2f12e..94c5c71376 100644 --- a/packages/slate/test/commands/by-key/set-node-by-key/inline-with-is-void.js +++ b/packages/slate/test/commands/by-path/set-node-by-path/inline-with-is-void.js @@ -3,16 +3,18 @@ import h from '../../../helpers/h' export default function(editor) { - editor.setNodeByKey('a', 'emoji') + editor.setNodeByPath([0, 1], 'emoji') } export const input = ( + word + @@ -22,9 +24,11 @@ export const output = ( + word + diff --git a/packages/slate/test/commands/by-key/set-node-by-key/string-shorthand.js b/packages/slate/test/commands/by-path/set-node-by-path/string-shorthand.js similarity index 77% rename from packages/slate/test/commands/by-key/set-node-by-key/string-shorthand.js rename to packages/slate/test/commands/by-path/set-node-by-path/string-shorthand.js index 7611833c3e..e6a1f929a1 100644 --- a/packages/slate/test/commands/by-key/set-node-by-key/string-shorthand.js +++ b/packages/slate/test/commands/by-path/set-node-by-path/string-shorthand.js @@ -3,13 +3,13 @@ import h from '../../../helpers/h' export default function(editor) { - editor.setNodeByKey('a', 'quote') + editor.setNodeByPath([0], 'quote') } export const input = ( - word + word ) diff --git a/packages/slate/test/commands/by-path/set-text-by-path/set.js b/packages/slate/test/commands/by-path/set-text-by-path/set.js new file mode 100644 index 0000000000..9cc1f2624e --- /dev/null +++ b/packages/slate/test/commands/by-path/set-text-by-path/set.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.setTextByPath([0, 0], 'two') +} + +export const input = ( + + + + one + + + +) + +export const output = ( + + + + two + + + +) diff --git a/packages/slate/test/commands/by-path/set-text-by-path/with-mark.js b/packages/slate/test/commands/by-path/set-text-by-path/with-mark.js new file mode 100644 index 0000000000..cb0190872d --- /dev/null +++ b/packages/slate/test/commands/by-path/set-text-by-path/with-mark.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.setTextByPath([0, 0], 'two', ['bold']) +} + +export const input = ( + + + + one + + + +) + +export const output = ( + + + + two + + + + +) diff --git a/packages/slate/test/commands/by-key/split-descendants-by-key/block-with-selection.js b/packages/slate/test/commands/by-path/split-descendants-by-path/block-with-selection.js similarity index 90% rename from packages/slate/test/commands/by-key/split-descendants-by-key/block-with-selection.js rename to packages/slate/test/commands/by-path/split-descendants-by-path/block-with-selection.js index e27de45274..a84d0bb410 100644 --- a/packages/slate/test/commands/by-key/split-descendants-by-key/block-with-selection.js +++ b/packages/slate/test/commands/by-path/split-descendants-by-path/block-with-selection.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.splitDescendantsByKey('a', 'b', 2) + editor.splitDescendantsByPath([0], [0, 0], 2) } export const input = ( diff --git a/packages/slate/test/commands/by-key/split-descendants-by-key/block.js b/packages/slate/test/commands/by-path/split-descendants-by-path/block.js similarity index 88% rename from packages/slate/test/commands/by-key/split-descendants-by-key/block.js rename to packages/slate/test/commands/by-path/split-descendants-by-path/block.js index ffd42fd0f9..20796f1672 100644 --- a/packages/slate/test/commands/by-key/split-descendants-by-key/block.js +++ b/packages/slate/test/commands/by-path/split-descendants-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.splitDescendantsByKey('a', 'b', 2) + editor.splitDescendantsByPath([0], [0, 0], 2) } export const input = ( diff --git a/packages/slate/test/commands/by-key/split-node-by-key/block-with-selection.js b/packages/slate/test/commands/by-path/split-node-by-path/block-with-selection.js similarity index 94% rename from packages/slate/test/commands/by-key/split-node-by-key/block-with-selection.js rename to packages/slate/test/commands/by-path/split-node-by-path/block-with-selection.js index 2d08f628ea..78510748a2 100644 --- a/packages/slate/test/commands/by-key/split-node-by-key/block-with-selection.js +++ b/packages/slate/test/commands/by-path/split-node-by-path/block-with-selection.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.splitNodeByKey('a', 2) + editor.splitNodeByPath([0], 2) } export const input = ( diff --git a/packages/slate/test/commands/by-key/split-node-by-key/block.js b/packages/slate/test/commands/by-path/split-node-by-path/block.js similarity index 93% rename from packages/slate/test/commands/by-key/split-node-by-key/block.js rename to packages/slate/test/commands/by-path/split-node-by-path/block.js index d764a41a15..dcc8eea8c7 100644 --- a/packages/slate/test/commands/by-key/split-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/split-node-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.splitNodeByKey('a', 2) + editor.splitNodeByPath([0], 2) } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-block-by-key/single-block.js b/packages/slate/test/commands/by-path/unwrap-block-by-path/single-block.js similarity index 91% rename from packages/slate/test/commands/by-key/unwrap-block-by-key/single-block.js rename to packages/slate/test/commands/by-path/unwrap-block-by-path/single-block.js index 5ec04af082..0426685720 100644 --- a/packages/slate/test/commands/by-key/unwrap-block-by-key/single-block.js +++ b/packages/slate/test/commands/by-path/unwrap-block-by-path/single-block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapBlockByKey('a', 'quote') + editor.unwrapBlockByPath([0, 0], 'quote') } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-children-by-key/block-multiple.js b/packages/slate/test/commands/by-path/unwrap-children-by-path/block-multiple.js similarity index 92% rename from packages/slate/test/commands/by-key/unwrap-children-by-key/block-multiple.js rename to packages/slate/test/commands/by-path/unwrap-children-by-path/block-multiple.js index 8336743250..b9f5d5dbd1 100644 --- a/packages/slate/test/commands/by-key/unwrap-children-by-key/block-multiple.js +++ b/packages/slate/test/commands/by-path/unwrap-children-by-path/block-multiple.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapChildrenByKey('a') + editor.unwrapChildrenByPath([0]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-children-by-key/block.js b/packages/slate/test/commands/by-path/unwrap-children-by-path/block.js similarity index 90% rename from packages/slate/test/commands/by-key/unwrap-children-by-key/block.js rename to packages/slate/test/commands/by-path/unwrap-children-by-path/block.js index 7ef551d676..b809e52ed7 100644 --- a/packages/slate/test/commands/by-key/unwrap-children-by-key/block.js +++ b/packages/slate/test/commands/by-path/unwrap-children-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapChildrenByKey('a') + editor.unwrapChildrenByPath([0]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-inline-by-key/single-block.js b/packages/slate/test/commands/by-path/unwrap-inline-by-path/single-block.js similarity index 90% rename from packages/slate/test/commands/by-key/unwrap-inline-by-key/single-block.js rename to packages/slate/test/commands/by-path/unwrap-inline-by-path/single-block.js index 3b562b9862..0734f8fdd7 100644 --- a/packages/slate/test/commands/by-key/unwrap-inline-by-key/single-block.js +++ b/packages/slate/test/commands/by-path/unwrap-inline-by-path/single-block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapInlineByKey('a', 'link') + editor.unwrapInlineByPath([0, 1], 'link') } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-node-by-key/block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/block.js similarity index 91% rename from packages/slate/test/commands/by-key/unwrap-node-by-key/block.js rename to packages/slate/test/commands/by-path/unwrap-node-by-path/block.js index 9eba8fb001..f68249f64e 100644 --- a/packages/slate/test/commands/by-key/unwrap-node-by-key/block.js +++ b/packages/slate/test/commands/by-path/unwrap-node-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapNodeByKey('a') + editor.unwrapNodeByPath([0, 0]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-node-by-key/first-block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/first-block.js similarity index 92% rename from packages/slate/test/commands/by-key/unwrap-node-by-key/first-block.js rename to packages/slate/test/commands/by-path/unwrap-node-by-path/first-block.js index 8fce8e56b7..8217a09bf1 100644 --- a/packages/slate/test/commands/by-key/unwrap-node-by-key/first-block.js +++ b/packages/slate/test/commands/by-path/unwrap-node-by-path/first-block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapNodeByKey('a') + editor.unwrapNodeByPath([0, 0]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-node-by-key/last-block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/last-block.js similarity index 92% rename from packages/slate/test/commands/by-key/unwrap-node-by-key/last-block.js rename to packages/slate/test/commands/by-path/unwrap-node-by-path/last-block.js index 357ec8bdd0..a2d5801c5d 100644 --- a/packages/slate/test/commands/by-key/unwrap-node-by-key/last-block.js +++ b/packages/slate/test/commands/by-path/unwrap-node-by-path/last-block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapNodeByKey('a') + editor.unwrapNodeByPath([0, 1]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/unwrap-node-by-key/middle-block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/middle-block.js similarity index 94% rename from packages/slate/test/commands/by-key/unwrap-node-by-key/middle-block.js rename to packages/slate/test/commands/by-path/unwrap-node-by-path/middle-block.js index 3d27882f78..534aad2409 100644 --- a/packages/slate/test/commands/by-key/unwrap-node-by-key/middle-block.js +++ b/packages/slate/test/commands/by-path/unwrap-node-by-path/middle-block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.unwrapNodeByKey('a') + editor.unwrapNodeByPath([0, 1]) } export const input = ( diff --git a/packages/slate/test/commands/by-key/wrap-block-by-key/block.js b/packages/slate/test/commands/by-path/wrap-block-by-path/block.js similarity index 90% rename from packages/slate/test/commands/by-key/wrap-block-by-key/block.js rename to packages/slate/test/commands/by-path/wrap-block-by-path/block.js index 7f12ccfa58..0be9adb058 100644 --- a/packages/slate/test/commands/by-key/wrap-block-by-key/block.js +++ b/packages/slate/test/commands/by-path/wrap-block-by-path/block.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.wrapBlockByKey('a', 'quote') + editor.wrapBlockByPath([0], 'quote') } export const input = ( diff --git a/packages/slate/test/commands/by-key/wrap-block-by-key/text.js b/packages/slate/test/commands/by-path/wrap-block-by-path/text.js similarity index 90% rename from packages/slate/test/commands/by-key/wrap-block-by-key/text.js rename to packages/slate/test/commands/by-path/wrap-block-by-path/text.js index bfdb504092..375971fddd 100644 --- a/packages/slate/test/commands/by-key/wrap-block-by-key/text.js +++ b/packages/slate/test/commands/by-path/wrap-block-by-path/text.js @@ -3,7 +3,7 @@ import h from '../../../helpers/h' export default function(editor) { - editor.wrapBlockByKey('a', 'quote') + editor.wrapBlockByPath([0, 0], 'quote') } export const input = ( diff --git a/packages/slate/test/history/undo/move-node-by-key.js b/packages/slate/test/history/undo/move-node-by-key.js deleted file mode 100644 index b10a328ce3..0000000000 --- a/packages/slate/test/history/undo/move-node-by-key.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function(editor) { - editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1])) - editor.flush() - editor.undo() -} - -export const input = ( - - - one - two - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/remove-node-by-key.js b/packages/slate/test/history/undo/remove-node-by-path.js similarity index 77% rename from packages/slate/test/history/undo/remove-node-by-key.js rename to packages/slate/test/history/undo/remove-node-by-path.js index 54b9a6a757..5fd84229db 100644 --- a/packages/slate/test/history/undo/remove-node-by-key.js +++ b/packages/slate/test/history/undo/remove-node-by-path.js @@ -1,9 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' +import { PathUtils } from 'slate' export default function(editor) { - editor.removeNodeByKey('a') + editor.removeNodeByPath(PathUtils.create([0])) editor.flush() editor.undo() } diff --git a/packages/slate/test/history/undo/set-node-by-key-with-data.js b/packages/slate/test/history/undo/set-node-by-path-with-data.js similarity index 78% rename from packages/slate/test/history/undo/set-node-by-key-with-data.js rename to packages/slate/test/history/undo/set-node-by-path-with-data.js index 2289c17eb1..81bf2fc734 100644 --- a/packages/slate/test/history/undo/set-node-by-key-with-data.js +++ b/packages/slate/test/history/undo/set-node-by-path-with-data.js @@ -1,9 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' +import { PathUtils } from 'slate' export default function(editor) { - editor.setNodeByKey('a', { + editor.setNodeByPath(PathUtils.create([0]), { data: { thing: 'value' }, }) diff --git a/packages/slate/test/history/undo/split-node-by-key-block.js b/packages/slate/test/history/undo/split-node-by-path-block.js similarity index 82% rename from packages/slate/test/history/undo/split-node-by-key-block.js rename to packages/slate/test/history/undo/split-node-by-path-block.js index 27d563d35c..c5db5582d2 100644 --- a/packages/slate/test/history/undo/split-node-by-key-block.js +++ b/packages/slate/test/history/undo/split-node-by-path-block.js @@ -1,9 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' +import { PathUtils } from 'slate' export default function(editor) { - editor.splitNodeByKey('a', 2) + editor.splitNodeByPath(PathUtils.create([0]), 2) editor.flush() editor.undo() } diff --git a/packages/slate/test/history/undo/unwrap-node-by-key.js b/packages/slate/test/history/undo/unwrap-node-by-path.js similarity index 77% rename from packages/slate/test/history/undo/unwrap-node-by-key.js rename to packages/slate/test/history/undo/unwrap-node-by-path.js index a91bbab5d6..421bdff407 100644 --- a/packages/slate/test/history/undo/unwrap-node-by-key.js +++ b/packages/slate/test/history/undo/unwrap-node-by-path.js @@ -1,9 +1,10 @@ /** @jsx h */ import h from '../../helpers/h' +import { PathUtils } from 'slate' export default function(editor) { - editor.unwrapNodeByKey('a') + editor.unwrapNodeByPath(PathUtils.create([0, 0])) editor.flush() editor.undo() } @@ -12,7 +13,7 @@ export const input = ( - + one two From 3006fe05e85aa8c6053739cc61c52a1a4dac8028 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 27 Aug 2019 18:50:16 -0400 Subject: [PATCH 015/165] rename at-current-range tests --- .../{at-current-range => with-intent}/add-mark/across-blocks.js | 0 .../{at-current-range => with-intent}/add-mark/across-inlines.js | 0 .../add-mark/collapsed-selection-end.js | 0 .../add-mark/collapsed-selection-middle.js | 0 .../add-mark/collapsed-selection-start.js | 0 .../add-mark/existing-marks-across-blocks-at-edge.js | 0 .../add-mark/existing-marks-across-blocks.js | 0 .../{at-current-range => with-intent}/add-mark/existing-marks.js | 0 .../{at-current-range => with-intent}/add-mark/first-character.js | 0 .../{at-current-range => with-intent}/add-mark/last-character.js | 0 .../add-mark/middle-character.js | 0 .../{at-current-range => with-intent}/add-mark/whole-word.js | 0 .../add-mark/with-mark-object.js | 0 .../add-mark/with-plain-object.js | 0 .../{at-current-range => with-intent}/add-marks/across-blocks.js | 0 .../{at-current-range => with-intent}/add-marks/across-inlines.js | 0 .../{at-current-range => with-intent}/add-marks/across-marks.js | 0 .../add-marks/collapsed-selection-end.js | 0 .../add-marks/collapsed-selection-middle.js | 0 .../add-marks/collapsed-selection-start.js | 0 .../add-marks/first-character.js | 0 .../{at-current-range => with-intent}/add-marks/inside-mark.js | 0 .../{at-current-range => with-intent}/add-marks/last-character.js | 0 .../add-marks/middle-character.js | 0 .../{at-current-range => with-intent}/add-marks/whole-word.js | 0 .../add-marks/with-mark-object.js | 0 .../add-marks/with-plain-object.js | 0 .../delete-backward/empty-after-void-block.js | 0 .../delete-backward/empty-after-void-inline.js | 0 .../delete-backward/first-character.js | 0 .../delete-backward/inline-after.js | 0 .../delete-backward/inline-before.js | 0 .../delete-backward/inline-end.js | 0 .../delete-backward/inline-inside.js | 0 .../delete-backward/join-blocks-from-inline.js | 0 .../delete-backward/join-blocks-with-inline-void.js | 0 .../delete-backward/join-blocks-with-inline.js | 0 .../delete-backward/join-blocks.js | 0 .../delete-backward/join-nested-blocks-different-depth.js | 0 .../delete-backward/join-nested-blocks.js | 0 .../delete-backward/last-character.js | 0 .../delete-backward/middle-character.js | 0 .../delete-backward/multiple-characters.js | 0 .../delete-backward/single-non-void-block.js | 0 .../delete-backward/single-void-block.js | 0 .../delete-backward/start-of-document.js | 0 .../delete-char-backward/inline-after-emoji.js | 0 .../delete-char-backward/inline-end-emoji.js | 0 .../delete-char-backward/inline-inside-emoji.js | 0 .../delete-char-backward/inline-only-emoji.js | 0 .../delete-char-backward/text-end.js | 0 .../delete-char-backward/text-middle.js | 0 .../delete-char-backward/text-start.js | 0 .../delete-char-forward/inline-before-emoji.js | 0 .../delete-char-forward/inline-middle-emoji.js | 0 .../delete-char-forward/inline-start-emoji.js | 0 .../delete-char-forward/text-last.js | 0 .../delete-char-forward/text-middle.js | 0 .../delete-char-forward/text-start.js | 0 .../delete-forward/before-inline-sibling.js | 0 .../delete-forward/empty-before-void-block.js | 0 .../delete-forward/empty-before-void-inline.js | 0 .../delete-forward/end-of-document.js | 0 .../delete-forward/first-character.js | 0 .../delete-forward/inside-inline-sibling.js | 0 .../delete-forward/join-blocks-with-inline-void.js | 0 .../delete-forward/join-blocks-with-inline.js | 0 .../delete-forward/join-blocks.js | 0 .../delete-forward/join-nested-blocks.js | 0 .../delete-forward/last-character.js | 0 .../delete-forward/middle-character.js | 0 .../delete-forward/multiple-characters.js | 0 .../delete-forward/single-non-void-block.js | 0 .../delete-forward/single-void-block.js | 0 .../delete-forward/start-text-middle-inline.js | 0 .../delete-line-backward/inline-middle-emoji.js | 0 .../delete-line-backward/inline-multi-voids.js | 0 .../delete-line-backward/inline-void-first.js | 0 .../delete-line-backward/text-end.js | 0 .../delete-line-backward/text-start.js | 0 .../delete-line-backward/word-middle.js | 0 .../delete-line-forward/inline-middle-emoji.js | 0 .../delete-line-forward/inline-multi-voids.js | 0 .../delete-line-forward/inline-void-end.js | 0 .../delete-line-forward/text-end.js | 0 .../delete-line-forward/text-start.js | 0 .../delete-line-forward/word-middle.js | 0 .../delete-word-backward/inline-after-emoji.js | 0 .../delete-word-backward/inline-middle-emoji.js | 0 .../delete-word-backward/join-blocks.js | 0 .../delete-word-backward/text-end.js | 0 .../delete-word-backward/word-middle.js | 0 .../delete-word-forward/inline-after-emoji.js | 0 .../delete-word-forward/inline-middle-emoji.js | 0 .../delete-word-forward/join-blocks.js | 0 .../delete-word-forward/word-middle.js | 0 .../delete-word-forward/word-start.js | 0 .../delete/across-blocks-inlines.js | 0 .../{at-current-range => with-intent}/delete/across-blocks.js | 0 .../{at-current-range => with-intent}/delete/across-depths.js | 0 .../delete/across-nested-blocks.js | 0 .../delete/across-texts-and-inlines.js | 0 .../{at-current-range => with-intent}/delete/all-nested-blocks.js | 0 .../delete/before-inline-sibling.js | 0 .../delete/expanded-across-whole-mark.js | 0 .../{at-current-range => with-intent}/delete/first-character.js | 0 .../{at-current-range => with-intent}/delete/first-position.js | 0 .../delete/hanging-selection-multiple-blocks.js | 0 .../delete/hanging-selection-single-block.js | 0 .../delete/inside-inline-sibling.js | 0 .../{at-current-range => with-intent}/delete/inside-inline.js | 0 .../delete/join-blocks-and-trim.js | 0 .../delete/join-blocks-with-inlines.js | 0 .../{at-current-range => with-intent}/delete/join-blocks.js | 0 .../delete/join-double-nested-blocks.js | 0 .../delete/join-nested-blocks.js | 0 .../{at-current-range => with-intent}/delete/last-character.js | 0 .../{at-current-range => with-intent}/delete/middle-character.js | 0 .../{at-current-range => with-intent}/delete/nested-block.js | 0 .../non-void-block-as-first-with-void-siblings-only-non-void.js | 0 ...th-void-siblings-partially-non-void-and-up-to-start-of-void.js | 0 ...ock-as-first-with-void-siblings-partially-non-void-and-void.js | 0 ...n-void-block-as-first-with-void-siblings-partially-non-void.js | 0 .../{at-current-range => with-intent}/delete/non-void-triple.js | 0 .../delete/void-block-as-first-with-non-void-siblings-all.js | 0 ...lock-as-first-with-non-void-siblings-backward-selection-all.js | 0 .../void-block-as-first-with-non-void-siblings-only-void.js | 0 ...k-as-first-with-non-void-siblings-select-void-and-next-word.js | 0 ...-first-with-non-void-siblings-select-void-end-and-next-word.js | 0 .../delete/void-block-as-only.js | 0 ...void-blocks-as-first-with-non-void-siblings-only-first-void.js | 0 .../void-blocks-as-first-with-non-void-siblings-only-voids.js | 0 .../delete/void-inline-as-first-with-non-void-block-next.js | 0 .../delete/void-inline-as-first-with-non-void-sibling.js | 0 .../delete/void-inline-as-last-with-non-void-previous-siblings.js | 0 .../{at-current-range => with-intent}/delete/whole-inline.js | 0 .../{at-current-range => with-intent}/delete/whole-word-mark.js | 0 .../{at-current-range => with-intent}/delete/whole-word.js | 0 .../{at-current-range => with-intent}/insert-block/block-end.js | 0 .../insert-block/block-middle.js | 0 .../{at-current-range => with-intent}/insert-block/block-start.js | 0 .../{at-current-range => with-intent}/insert-block/is-empty.js | 0 .../insert-block/is-inline-void.js | 0 .../{at-current-range => with-intent}/insert-block/is-void-end.js | 0 .../insert-block/is-void-start.js | 0 .../{at-current-range => with-intent}/insert-block/with-block.js | 0 .../{at-current-range => with-intent}/insert-block/with-object.js | 0 .../insert-fragment/end-block-multiple-blocks.js | 0 .../insert-fragment/end-block.js | 0 .../insert-fragment/end-inline.js | 0 .../insert-fragment/fragment-adjacent-texts.js | 0 .../insert-fragment/fragment-inline-node.js | 0 .../insert-fragment/fragment-multiple-blocks.js | 0 .../insert-fragment/fragment-nested-blocks-end-of-node.js | 0 .../insert-fragment/fragment-nested-blocks-start-of-node.js | 0 .../insert-fragment/fragment-nested-blocks.js | 0 .../insert-fragment/fragment-single-child-block.js | 0 .../insert-fragment/hanging-selection-single-block.js | 0 .../insert-fragment/merge-deep-nested.js | 0 .../insert-fragment/merge-lists.js | 0 .../insert-fragment/middle-block.js | 0 .../insert-fragment/middle-fragment-adjacent-texts.js | 0 .../insert-fragment/middle-inline-fragment-inline.js | 0 .../insert-fragment/middle-inline.js | 0 .../insert-fragment/nested-block-fragment-nested-blocks.js | 0 .../insert-fragment/start-block-multiple-blocks.js | 0 .../insert-fragment/start-block-with-void-no-text.js | 0 .../insert-fragment/start-block.js | 0 .../insert-fragment/start-inline.js | 0 .../insert-fragment/start-second-block.js | 0 .../insert-fragment/with-delete-across-blocks.js | 0 .../{at-current-range => with-intent}/insert-inline/block-end.js | 0 .../insert-inline/block-middle.js | 0 .../insert-inline/block-start.js | 0 .../insert-inline/inline-middle.js | 0 .../{at-current-range => with-intent}/insert-inline/is-empty.js | 0 .../{at-current-range => with-intent}/insert-inline/is-void.js | 0 .../insert-inline/with-inline.js | 0 .../{at-current-range => with-intent}/insert-text/after-mark.js | 0 .../{at-current-range => with-intent}/insert-text/before-mark.js | 0 .../insert-text/blocks-with-overlapping-marks.js | 0 .../{at-current-range => with-intent}/insert-text/during-mark.js | 0 .../insert-text/empty-block-with-mark.js | 0 .../insert-text/expanded-with-mark.js | 0 .../insert-text/first-character.js | 0 .../{at-current-range => with-intent}/insert-text/first-space.js | 0 .../{at-current-range => with-intent}/insert-text/first-words.js | 0 .../insert-text/hanging-selection-multiple-blocks.js | 0 .../insert-text/hanging-selection-single-block.js | 0 .../{at-current-range => with-intent}/insert-text/inside-void.js | 0 .../insert-text/last-character.js | 0 .../{at-current-range => with-intent}/insert-text/last-space.js | 0 .../{at-current-range => with-intent}/insert-text/last-words.js | 0 .../insert-text/middle-character.js | 0 .../{at-current-range => with-intent}/insert-text/middle-space.js | 0 .../{at-current-range => with-intent}/insert-text/middle-words.js | 0 .../{at-current-range => with-intent}/insert-text/with-marks.js | 0 .../remove-mark/across-blocks.js | 0 .../remove-mark/across-inlines.js | 0 .../remove-mark/collapsed-selection.js | 0 .../remove-mark/existing-marks.js | 0 .../remove-mark/first-character.js | 0 .../remove-mark/last-character.js | 0 .../remove-mark/middle-character.js | 0 .../{at-current-range => with-intent}/remove-mark/whole-word.js | 0 .../remove-mark/with-mark-object.js | 0 .../remove-mark/with-plain-object.js | 0 .../replace-mark/across-blocks.js | 0 .../replace-mark/across-inlines.js | 0 .../replace-mark/existing-marks.js | 0 .../replace-mark/first-character.js | 0 .../replace-mark/last-character.js | 0 .../replace-mark/middle-character.js | 0 .../{at-current-range => with-intent}/replace-mark/whole-word.js | 0 .../replace-mark/with-mark-object.js | 0 .../replace-mark/with-plain-object.js | 0 .../{at-current-range => with-intent}/set-block/across-blocks.js | 0 .../{at-current-range => with-intent}/set-block/across-inlines.js | 0 .../{at-current-range => with-intent}/set-block/data-only.js | 0 .../set-block/hanging-selection-across-inlines.js | 0 .../set-block/hanging-selection.js | 0 .../{at-current-range => with-intent}/set-block/nested-block.js | 0 .../set-block/single-block-string-shorthand.js | 0 .../{at-current-range => with-intent}/set-block/single-block.js | 0 .../set-block/with-data-as-map.js | 0 .../set-block/with-data-as-object.js | 0 .../{at-current-range => with-intent}/set-block/with-is-void.js | 0 .../set-inline/across-inlines.js | 0 .../{at-current-range => with-intent}/set-inline/data-only.js | 0 .../{at-current-range => with-intent}/set-inline/nested-inline.js | 0 .../set-inline/single-inline-string-shorthand.js | 0 .../{at-current-range => with-intent}/set-inline/single-inline.js | 0 .../set-inline/with-data-object.js | 0 .../{at-current-range => with-intent}/set-inline/with-data.js | 0 .../{at-current-range => with-intent}/set-inline/with-is-void.js | 0 .../split-block/after-inline-void.js | 0 .../{at-current-range => with-intent}/split-block/after-inline.js | 0 .../split-block/before-inline.js | 0 .../{at-current-range => with-intent}/split-block/block-end.js | 0 .../{at-current-range => with-intent}/split-block/block-middle.js | 0 .../{at-current-range => with-intent}/split-block/block-start.js | 0 .../{at-current-range => with-intent}/split-block/depth.js | 0 .../split-block/with-delete-across-blocks-and-inlines.js | 0 .../split-block/with-delete-across-blocks.js | 0 .../split-block/with-delete-hanging-selection.js | 0 .../{at-current-range => with-intent}/split-block/with-delete.js | 0 .../{at-current-range => with-intent}/split-block/with-inline.js | 0 .../{at-current-range => with-intent}/split-block/with-marks.js | 0 .../{at-current-range => with-intent}/split-inline/block-end.js | 0 .../split-inline/block-middle.js | 0 .../{at-current-range => with-intent}/split-inline/block-start.js | 0 .../{at-current-range => with-intent}/split-inline/height.js | 0 .../{at-current-range => with-intent}/split-inline/with-delete.js | 0 .../{at-current-range => with-intent}/split-inline/with-marks.js | 0 .../toggle-mark/add-across-blocks.js | 0 .../toggle-mark/add-across-inlines.js | 0 .../toggle-mark/add-collapsed-selection-start.js | 0 .../toggle-mark/add-collapsed-selection.js | 0 .../toggle-mark/add-existing-marks-partially-marked.js | 0 .../toggle-mark/add-existing-marks.js | 0 .../toggle-mark/add-first-character.js | 0 .../toggle-mark/add-last-character.js | 0 .../toggle-mark/add-middle-character.js | 0 .../toggle-mark/add-partially-marked.js | 0 .../toggle-mark/add-whole-word.js | 0 .../toggle-mark/add-with-mark-object.js | 0 .../toggle-mark/add-with-plain-object.js | 0 .../toggle-mark/remove-across-blocks.js | 0 .../toggle-mark/remove-across-inlines.js | 0 .../toggle-mark/remove-collapsed-selection-beginning.js | 0 .../toggle-mark/remove-collapsed-selection.js | 0 .../toggle-mark/remove-existing-marks.js | 0 .../toggle-mark/remove-first-character.js | 0 .../toggle-mark/remove-last-character.js | 0 .../toggle-mark/remove-middle-character.js | 0 .../toggle-mark/remove-whole-word.js | 0 .../toggle-mark/remove-with-mark-object.js | 0 .../toggle-mark/remove-with-plain-object.js | 0 .../unwrap-block/across-blocks.js | 0 .../unwrap-block/across-inlines.js | 0 .../unwrap-block/ending-child-blocks.js | 0 .../unwrap-block/middle-child-blocks-with-backward-selection.js | 0 .../unwrap-block/middle-child-blocks.js | 0 .../unwrap-block/nested-block.js | 0 .../unwrap-block/single-block.js | 0 .../unwrap-block/starting-child-blocks.js | 0 .../{at-current-range => with-intent}/unwrap-block/with-object.js | 0 .../unwrap-inline/across-blocks.js | 0 .../unwrap-inline/across-inlines-and-text.js | 0 .../unwrap-inline/across-inlines.js | 0 .../unwrap-inline/nested-block.js | 0 .../{at-current-range => with-intent}/unwrap-inline/only-one.js | 0 .../unwrap-inline/single-block.js | 0 .../unwrap-inline/with-object.js | 0 .../{at-current-range => with-intent}/wrap-block/across-blocks.js | 0 .../wrap-block/across-inlines.js | 0 .../wrap-block/nested-block-with-object.js | 0 .../{at-current-range => with-intent}/wrap-block/nested-block.js | 0 .../{at-current-range => with-intent}/wrap-block/single-block.js | 0 .../{at-current-range => with-intent}/wrap-block/with-object.js | 0 .../wrap-inline/across-blocks.js | 0 .../wrap-inline/across-inlines.js | 0 .../{at-current-range => with-intent}/wrap-inline/collapsed.js | 0 .../{at-current-range => with-intent}/wrap-inline/inline-end.js | 0 .../wrap-inline/inline-middle-with-marks.js | 0 .../wrap-inline/inline-middle.js | 0 .../{at-current-range => with-intent}/wrap-inline/inline-start.js | 0 .../{at-current-range => with-intent}/wrap-inline/inline-void.js | 0 .../{at-current-range => with-intent}/wrap-inline/nested-block.js | 0 .../{at-current-range => with-intent}/wrap-inline/single-block.js | 0 .../{at-current-range => with-intent}/wrap-inline/twice.js | 0 .../{at-current-range => with-intent}/wrap-inline/whole-block.js | 0 .../{at-current-range => with-intent}/wrap-inline/with-object.js | 0 .../{at-current-range => with-intent}/wrap-text/across-blocks.js | 0 .../{at-current-range => with-intent}/wrap-text/across-inlines.js | 0 .../wrap-text/backwards-selection.js | 0 .../{at-current-range => with-intent}/wrap-text/empty-block.js | 0 .../{at-current-range => with-intent}/wrap-text/end-of-block.js | 0 .../wrap-text/middle-of-block.js | 0 .../{at-current-range => with-intent}/wrap-text/start-of-block.js | 0 .../{at-current-range => with-intent}/wrap-text/whole-block.js | 0 .../{at-current-range => with-intent}/wrap-text/without-suffix.js | 0 322 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/collapsed-selection-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/collapsed-selection-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/collapsed-selection-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/existing-marks-across-blocks-at-edge.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/existing-marks-across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/existing-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/whole-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/with-mark-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-mark/with-plain-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/across-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/collapsed-selection-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/collapsed-selection-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/collapsed-selection-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/inside-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/whole-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/with-mark-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/add-marks/with-plain-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/empty-after-void-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/empty-after-void-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/inline-after.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/inline-before.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/inline-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/inline-inside.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/join-blocks-from-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/join-blocks-with-inline-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/join-blocks-with-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/join-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/join-nested-blocks-different-depth.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/join-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/multiple-characters.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/single-non-void-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/single-void-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-backward/start-of-document.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-backward/inline-after-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-backward/inline-end-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-backward/inline-inside-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-backward/inline-only-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-backward/text-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-backward/text-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-backward/text-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-forward/inline-before-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-forward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-forward/inline-start-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-forward/text-last.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-forward/text-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-char-forward/text-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/before-inline-sibling.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/empty-before-void-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/empty-before-void-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/end-of-document.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/inside-inline-sibling.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/join-blocks-with-inline-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/join-blocks-with-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/join-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/join-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/multiple-characters.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/single-non-void-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/single-void-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-forward/start-text-middle-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-backward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-backward/inline-multi-voids.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-backward/inline-void-first.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-backward/text-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-backward/text-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-backward/word-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-forward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-forward/inline-multi-voids.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-forward/inline-void-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-forward/text-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-forward/text-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-line-forward/word-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-backward/inline-after-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-backward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-backward/join-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-backward/text-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-backward/word-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-forward/inline-after-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-forward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-forward/join-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-forward/word-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete-word-forward/word-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/across-blocks-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/across-depths.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/across-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/across-texts-and-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/all-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/before-inline-sibling.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/expanded-across-whole-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/first-position.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/hanging-selection-multiple-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/inside-inline-sibling.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/inside-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/join-blocks-and-trim.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/join-blocks-with-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/join-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/join-double-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/join-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/nested-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/non-void-block-as-first-with-void-siblings-only-non-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/non-void-triple.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-block-as-first-with-non-void-siblings-all.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-block-as-first-with-non-void-siblings-only-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-block-as-only.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-inline-as-first-with-non-void-block-next.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-inline-as-first-with-non-void-sibling.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/void-inline-as-last-with-non-void-previous-siblings.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/whole-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/whole-word-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/delete/whole-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/block-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/block-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/block-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/is-empty.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/is-inline-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/is-void-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/is-void-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/with-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-block/with-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/end-block-multiple-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/end-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/end-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/fragment-adjacent-texts.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/fragment-inline-node.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/fragment-multiple-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/fragment-nested-blocks-end-of-node.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/fragment-nested-blocks-start-of-node.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/fragment-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/fragment-single-child-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/merge-deep-nested.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/merge-lists.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/middle-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/middle-fragment-adjacent-texts.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/middle-inline-fragment-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/middle-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/nested-block-fragment-nested-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/start-block-multiple-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/start-block-with-void-no-text.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/start-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/start-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/start-second-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-fragment/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-inline/block-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-inline/block-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-inline/block-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-inline/inline-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-inline/is-empty.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-inline/is-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-inline/with-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/after-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/before-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/blocks-with-overlapping-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/during-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/empty-block-with-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/expanded-with-mark.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/first-space.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/first-words.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/hanging-selection-multiple-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/inside-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/last-space.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/last-words.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/middle-space.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/middle-words.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/insert-text/with-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/collapsed-selection.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/existing-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/whole-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/with-mark-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/remove-mark/with-plain-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/existing-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/whole-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/with-mark-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/replace-mark/with-plain-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/data-only.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/hanging-selection-across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/hanging-selection.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/nested-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/single-block-string-shorthand.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/with-data-as-map.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/with-data-as-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-block/with-is-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/data-only.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/nested-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/single-inline-string-shorthand.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/single-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/with-data-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/with-data.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/set-inline/with-is-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/after-inline-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/after-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/before-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/block-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/block-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/block-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/depth.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/with-delete-across-blocks-and-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/with-delete-hanging-selection.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/with-delete.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/with-inline.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-block/with-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-inline/block-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-inline/block-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-inline/block-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-inline/height.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-inline/with-delete.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/split-inline/with-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-collapsed-selection-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-collapsed-selection.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-existing-marks-partially-marked.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-existing-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-partially-marked.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-whole-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-with-mark-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/add-with-plain-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-collapsed-selection-beginning.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-collapsed-selection.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-existing-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-first-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-last-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-middle-character.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-whole-word.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-with-mark-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/toggle-mark/remove-with-plain-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/ending-child-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/middle-child-blocks-with-backward-selection.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/middle-child-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/nested-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/starting-child-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-block/with-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-inline/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-inline/across-inlines-and-text.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-inline/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-inline/nested-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-inline/only-one.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-inline/single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/unwrap-inline/with-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-block/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-block/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-block/nested-block-with-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-block/nested-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-block/single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-block/with-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/collapsed.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/inline-end.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/inline-middle-with-marks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/inline-middle.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/inline-start.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/inline-void.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/nested-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/single-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/twice.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/whole-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-inline/with-object.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/across-blocks.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/across-inlines.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/backwards-selection.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/empty-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/end-of-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/middle-of-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/start-of-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/whole-block.js (100%) rename packages/slate/test/commands/{at-current-range => with-intent}/wrap-text/without-suffix.js (100%) diff --git a/packages/slate/test/commands/at-current-range/add-mark/across-blocks.js b/packages/slate/test/commands/with-intent/add-mark/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/across-blocks.js rename to packages/slate/test/commands/with-intent/add-mark/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/across-inlines.js b/packages/slate/test/commands/with-intent/add-mark/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/across-inlines.js rename to packages/slate/test/commands/with-intent/add-mark/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-end.js b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-end.js rename to packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-middle.js b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-middle.js rename to packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-start.js b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/collapsed-selection-start.js rename to packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/existing-marks-across-blocks-at-edge.js b/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/existing-marks-across-blocks-at-edge.js rename to packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/existing-marks-across-blocks.js b/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/existing-marks-across-blocks.js rename to packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/existing-marks.js b/packages/slate/test/commands/with-intent/add-mark/existing-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/existing-marks.js rename to packages/slate/test/commands/with-intent/add-mark/existing-marks.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/first-character.js b/packages/slate/test/commands/with-intent/add-mark/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/first-character.js rename to packages/slate/test/commands/with-intent/add-mark/first-character.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/last-character.js b/packages/slate/test/commands/with-intent/add-mark/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/last-character.js rename to packages/slate/test/commands/with-intent/add-mark/last-character.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/middle-character.js b/packages/slate/test/commands/with-intent/add-mark/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/middle-character.js rename to packages/slate/test/commands/with-intent/add-mark/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/whole-word.js b/packages/slate/test/commands/with-intent/add-mark/whole-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/whole-word.js rename to packages/slate/test/commands/with-intent/add-mark/whole-word.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/with-mark-object.js b/packages/slate/test/commands/with-intent/add-mark/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/with-mark-object.js rename to packages/slate/test/commands/with-intent/add-mark/with-mark-object.js diff --git a/packages/slate/test/commands/at-current-range/add-mark/with-plain-object.js b/packages/slate/test/commands/with-intent/add-mark/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-mark/with-plain-object.js rename to packages/slate/test/commands/with-intent/add-mark/with-plain-object.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/across-blocks.js b/packages/slate/test/commands/with-intent/add-marks/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/across-blocks.js rename to packages/slate/test/commands/with-intent/add-marks/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/across-inlines.js b/packages/slate/test/commands/with-intent/add-marks/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/across-inlines.js rename to packages/slate/test/commands/with-intent/add-marks/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/across-marks.js b/packages/slate/test/commands/with-intent/add-marks/across-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/across-marks.js rename to packages/slate/test/commands/with-intent/add-marks/across-marks.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-end.js b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-end.js rename to packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-middle.js b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-middle.js rename to packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-start.js b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/collapsed-selection-start.js rename to packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/first-character.js b/packages/slate/test/commands/with-intent/add-marks/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/first-character.js rename to packages/slate/test/commands/with-intent/add-marks/first-character.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/inside-mark.js b/packages/slate/test/commands/with-intent/add-marks/inside-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/inside-mark.js rename to packages/slate/test/commands/with-intent/add-marks/inside-mark.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/last-character.js b/packages/slate/test/commands/with-intent/add-marks/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/last-character.js rename to packages/slate/test/commands/with-intent/add-marks/last-character.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/middle-character.js b/packages/slate/test/commands/with-intent/add-marks/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/middle-character.js rename to packages/slate/test/commands/with-intent/add-marks/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/whole-word.js b/packages/slate/test/commands/with-intent/add-marks/whole-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/whole-word.js rename to packages/slate/test/commands/with-intent/add-marks/whole-word.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/with-mark-object.js b/packages/slate/test/commands/with-intent/add-marks/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/with-mark-object.js rename to packages/slate/test/commands/with-intent/add-marks/with-mark-object.js diff --git a/packages/slate/test/commands/at-current-range/add-marks/with-plain-object.js b/packages/slate/test/commands/with-intent/add-marks/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/add-marks/with-plain-object.js rename to packages/slate/test/commands/with-intent/add-marks/with-plain-object.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-block.js b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-block.js rename to packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-inline.js b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/empty-after-void-inline.js rename to packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/first-character.js b/packages/slate/test/commands/with-intent/delete-backward/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/first-character.js rename to packages/slate/test/commands/with-intent/delete-backward/first-character.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/inline-after.js b/packages/slate/test/commands/with-intent/delete-backward/inline-after.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/inline-after.js rename to packages/slate/test/commands/with-intent/delete-backward/inline-after.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/inline-before.js b/packages/slate/test/commands/with-intent/delete-backward/inline-before.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/inline-before.js rename to packages/slate/test/commands/with-intent/delete-backward/inline-before.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/inline-end.js b/packages/slate/test/commands/with-intent/delete-backward/inline-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/inline-end.js rename to packages/slate/test/commands/with-intent/delete-backward/inline-end.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/inline-inside.js b/packages/slate/test/commands/with-intent/delete-backward/inline-inside.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/inline-inside.js rename to packages/slate/test/commands/with-intent/delete-backward/inline-inside.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/join-blocks-from-inline.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/join-blocks-from-inline.js rename to packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/join-blocks-with-inline-void.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/join-blocks-with-inline-void.js rename to packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/join-blocks-with-inline.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/join-blocks-with-inline.js rename to packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/join-blocks.js rename to packages/slate/test/commands/with-intent/delete-backward/join-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/join-nested-blocks-different-depth.js b/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/join-nested-blocks-different-depth.js rename to packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/join-nested-blocks.js b/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/join-nested-blocks.js rename to packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/last-character.js b/packages/slate/test/commands/with-intent/delete-backward/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/last-character.js rename to packages/slate/test/commands/with-intent/delete-backward/last-character.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/middle-character.js b/packages/slate/test/commands/with-intent/delete-backward/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/middle-character.js rename to packages/slate/test/commands/with-intent/delete-backward/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/multiple-characters.js b/packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/multiple-characters.js rename to packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/single-non-void-block.js b/packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/single-non-void-block.js rename to packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/single-void-block.js b/packages/slate/test/commands/with-intent/delete-backward/single-void-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/single-void-block.js rename to packages/slate/test/commands/with-intent/delete-backward/single-void-block.js diff --git a/packages/slate/test/commands/at-current-range/delete-backward/start-of-document.js b/packages/slate/test/commands/with-intent/delete-backward/start-of-document.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-backward/start-of-document.js rename to packages/slate/test/commands/with-intent/delete-backward/start-of-document.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-after-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-backward/inline-after-emoji.js rename to packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-end-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-backward/inline-end-emoji.js rename to packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-inside-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-backward/inline-inside-emoji.js rename to packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/inline-only-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-backward/inline-only-emoji.js rename to packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/text-end.js b/packages/slate/test/commands/with-intent/delete-char-backward/text-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-backward/text-end.js rename to packages/slate/test/commands/with-intent/delete-char-backward/text-end.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/text-middle.js b/packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-backward/text-middle.js rename to packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-backward/text-start.js b/packages/slate/test/commands/with-intent/delete-char-backward/text-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-backward/text-start.js rename to packages/slate/test/commands/with-intent/delete-char-backward/text-start.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/inline-before-emoji.js b/packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-forward/inline-before-emoji.js rename to packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-forward/inline-middle-emoji.js rename to packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/inline-start-emoji.js b/packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-forward/inline-start-emoji.js rename to packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/text-last.js b/packages/slate/test/commands/with-intent/delete-char-forward/text-last.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-forward/text-last.js rename to packages/slate/test/commands/with-intent/delete-char-forward/text-last.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/text-middle.js b/packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-forward/text-middle.js rename to packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js diff --git a/packages/slate/test/commands/at-current-range/delete-char-forward/text-start.js b/packages/slate/test/commands/with-intent/delete-char-forward/text-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-char-forward/text-start.js rename to packages/slate/test/commands/with-intent/delete-char-forward/text-start.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/before-inline-sibling.js b/packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/before-inline-sibling.js rename to packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-block.js b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-block.js rename to packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-inline.js b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/empty-before-void-inline.js rename to packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/end-of-document.js b/packages/slate/test/commands/with-intent/delete-forward/end-of-document.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/end-of-document.js rename to packages/slate/test/commands/with-intent/delete-forward/end-of-document.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/first-character.js b/packages/slate/test/commands/with-intent/delete-forward/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/first-character.js rename to packages/slate/test/commands/with-intent/delete-forward/first-character.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/inside-inline-sibling.js b/packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/inside-inline-sibling.js rename to packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/join-blocks-with-inline-void.js b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/join-blocks-with-inline-void.js rename to packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/join-blocks-with-inline.js b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/join-blocks-with-inline.js rename to packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-forward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/join-blocks.js rename to packages/slate/test/commands/with-intent/delete-forward/join-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/join-nested-blocks.js b/packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/join-nested-blocks.js rename to packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/last-character.js b/packages/slate/test/commands/with-intent/delete-forward/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/last-character.js rename to packages/slate/test/commands/with-intent/delete-forward/last-character.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/middle-character.js b/packages/slate/test/commands/with-intent/delete-forward/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/middle-character.js rename to packages/slate/test/commands/with-intent/delete-forward/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/multiple-characters.js b/packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/multiple-characters.js rename to packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/single-non-void-block.js b/packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/single-non-void-block.js rename to packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/single-void-block.js b/packages/slate/test/commands/with-intent/delete-forward/single-void-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/single-void-block.js rename to packages/slate/test/commands/with-intent/delete-forward/single-void-block.js diff --git a/packages/slate/test/commands/at-current-range/delete-forward/start-text-middle-inline.js b/packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-forward/start-text-middle-inline.js rename to packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-backward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-backward/inline-middle-emoji.js rename to packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-backward/inline-multi-voids.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-backward/inline-multi-voids.js rename to packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-backward/inline-void-first.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-backward/inline-void-first.js rename to packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-backward/text-end.js b/packages/slate/test/commands/with-intent/delete-line-backward/text-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-backward/text-end.js rename to packages/slate/test/commands/with-intent/delete-line-backward/text-end.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-backward/text-start.js b/packages/slate/test/commands/with-intent/delete-line-backward/text-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-backward/text-start.js rename to packages/slate/test/commands/with-intent/delete-line-backward/text-start.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-backward/word-middle.js b/packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-backward/word-middle.js rename to packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-forward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-forward/inline-middle-emoji.js rename to packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-forward/inline-multi-voids.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-forward/inline-multi-voids.js rename to packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-forward/inline-void-end.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-forward/inline-void-end.js rename to packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-forward/text-end.js b/packages/slate/test/commands/with-intent/delete-line-forward/text-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-forward/text-end.js rename to packages/slate/test/commands/with-intent/delete-line-forward/text-end.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-forward/text-start.js b/packages/slate/test/commands/with-intent/delete-line-forward/text-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-forward/text-start.js rename to packages/slate/test/commands/with-intent/delete-line-forward/text-start.js diff --git a/packages/slate/test/commands/at-current-range/delete-line-forward/word-middle.js b/packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-line-forward/word-middle.js rename to packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-backward/inline-after-emoji.js b/packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-backward/inline-after-emoji.js rename to packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-backward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-backward/inline-middle-emoji.js rename to packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-backward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-backward/join-blocks.js rename to packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-backward/text-end.js b/packages/slate/test/commands/with-intent/delete-word-backward/text-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-backward/text-end.js rename to packages/slate/test/commands/with-intent/delete-word-backward/text-end.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-backward/word-middle.js b/packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-backward/word-middle.js rename to packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-forward/inline-after-emoji.js b/packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-forward/inline-after-emoji.js rename to packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-forward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-forward/inline-middle-emoji.js rename to packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-forward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-forward/join-blocks.js rename to packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-forward/word-middle.js b/packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-forward/word-middle.js rename to packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js diff --git a/packages/slate/test/commands/at-current-range/delete-word-forward/word-start.js b/packages/slate/test/commands/with-intent/delete-word-forward/word-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete-word-forward/word-start.js rename to packages/slate/test/commands/with-intent/delete-word-forward/word-start.js diff --git a/packages/slate/test/commands/at-current-range/delete/across-blocks-inlines.js b/packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/across-blocks-inlines.js rename to packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js diff --git a/packages/slate/test/commands/at-current-range/delete/across-blocks.js b/packages/slate/test/commands/with-intent/delete/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/across-blocks.js rename to packages/slate/test/commands/with-intent/delete/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete/across-depths.js b/packages/slate/test/commands/with-intent/delete/across-depths.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/across-depths.js rename to packages/slate/test/commands/with-intent/delete/across-depths.js diff --git a/packages/slate/test/commands/at-current-range/delete/across-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/across-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/across-nested-blocks.js rename to packages/slate/test/commands/with-intent/delete/across-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete/across-texts-and-inlines.js b/packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/across-texts-and-inlines.js rename to packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js diff --git a/packages/slate/test/commands/at-current-range/delete/all-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/all-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/all-nested-blocks.js rename to packages/slate/test/commands/with-intent/delete/all-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete/before-inline-sibling.js b/packages/slate/test/commands/with-intent/delete/before-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/before-inline-sibling.js rename to packages/slate/test/commands/with-intent/delete/before-inline-sibling.js diff --git a/packages/slate/test/commands/at-current-range/delete/expanded-across-whole-mark.js b/packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/expanded-across-whole-mark.js rename to packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js diff --git a/packages/slate/test/commands/at-current-range/delete/first-character.js b/packages/slate/test/commands/with-intent/delete/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/first-character.js rename to packages/slate/test/commands/with-intent/delete/first-character.js diff --git a/packages/slate/test/commands/at-current-range/delete/first-position.js b/packages/slate/test/commands/with-intent/delete/first-position.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/first-position.js rename to packages/slate/test/commands/with-intent/delete/first-position.js diff --git a/packages/slate/test/commands/at-current-range/delete/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/hanging-selection-multiple-blocks.js rename to packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete/hanging-selection-single-block.js b/packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/hanging-selection-single-block.js rename to packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/at-current-range/delete/inside-inline-sibling.js b/packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/inside-inline-sibling.js rename to packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js diff --git a/packages/slate/test/commands/at-current-range/delete/inside-inline.js b/packages/slate/test/commands/with-intent/delete/inside-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/inside-inline.js rename to packages/slate/test/commands/with-intent/delete/inside-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete/join-blocks-and-trim.js b/packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/join-blocks-and-trim.js rename to packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js diff --git a/packages/slate/test/commands/at-current-range/delete/join-blocks-with-inlines.js b/packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/join-blocks-with-inlines.js rename to packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js diff --git a/packages/slate/test/commands/at-current-range/delete/join-blocks.js b/packages/slate/test/commands/with-intent/delete/join-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/join-blocks.js rename to packages/slate/test/commands/with-intent/delete/join-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete/join-double-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/join-double-nested-blocks.js rename to packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete/join-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/join-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/join-nested-blocks.js rename to packages/slate/test/commands/with-intent/delete/join-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/delete/last-character.js b/packages/slate/test/commands/with-intent/delete/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/last-character.js rename to packages/slate/test/commands/with-intent/delete/last-character.js diff --git a/packages/slate/test/commands/at-current-range/delete/middle-character.js b/packages/slate/test/commands/with-intent/delete/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/middle-character.js rename to packages/slate/test/commands/with-intent/delete/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/delete/nested-block.js b/packages/slate/test/commands/with-intent/delete/nested-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/nested-block.js rename to packages/slate/test/commands/with-intent/delete/nested-block.js diff --git a/packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-only-non-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-only-non-void.js rename to packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js diff --git a/packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js rename to packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js diff --git a/packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js rename to packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js diff --git a/packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js rename to packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js diff --git a/packages/slate/test/commands/at-current-range/delete/non-void-triple.js b/packages/slate/test/commands/with-intent/delete/non-void-triple.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/non-void-triple.js rename to packages/slate/test/commands/with-intent/delete/non-void-triple.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-all.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-all.js rename to packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js rename to packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-only-void.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-only-void.js rename to packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js rename to packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js rename to packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-block-as-only.js b/packages/slate/test/commands/with-intent/delete/void-block-as-only.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-block-as-only.js rename to packages/slate/test/commands/with-intent/delete/void-block-as-only.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js b/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js rename to packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js b/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js rename to packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-inline-as-first-with-non-void-block-next.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-inline-as-first-with-non-void-block-next.js rename to packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-inline-as-first-with-non-void-sibling.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-inline-as-first-with-non-void-sibling.js rename to packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js diff --git a/packages/slate/test/commands/at-current-range/delete/void-inline-as-last-with-non-void-previous-siblings.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/void-inline-as-last-with-non-void-previous-siblings.js rename to packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js diff --git a/packages/slate/test/commands/at-current-range/delete/whole-inline.js b/packages/slate/test/commands/with-intent/delete/whole-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/whole-inline.js rename to packages/slate/test/commands/with-intent/delete/whole-inline.js diff --git a/packages/slate/test/commands/at-current-range/delete/whole-word-mark.js b/packages/slate/test/commands/with-intent/delete/whole-word-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/whole-word-mark.js rename to packages/slate/test/commands/with-intent/delete/whole-word-mark.js diff --git a/packages/slate/test/commands/at-current-range/delete/whole-word.js b/packages/slate/test/commands/with-intent/delete/whole-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/delete/whole-word.js rename to packages/slate/test/commands/with-intent/delete/whole-word.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/block-end.js b/packages/slate/test/commands/with-intent/insert-block/block-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/block-end.js rename to packages/slate/test/commands/with-intent/insert-block/block-end.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/block-middle.js b/packages/slate/test/commands/with-intent/insert-block/block-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/block-middle.js rename to packages/slate/test/commands/with-intent/insert-block/block-middle.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/block-start.js b/packages/slate/test/commands/with-intent/insert-block/block-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/block-start.js rename to packages/slate/test/commands/with-intent/insert-block/block-start.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/is-empty.js b/packages/slate/test/commands/with-intent/insert-block/is-empty.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/is-empty.js rename to packages/slate/test/commands/with-intent/insert-block/is-empty.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/is-inline-void.js b/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/is-inline-void.js rename to packages/slate/test/commands/with-intent/insert-block/is-inline-void.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/is-void-end.js b/packages/slate/test/commands/with-intent/insert-block/is-void-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/is-void-end.js rename to packages/slate/test/commands/with-intent/insert-block/is-void-end.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/is-void-start.js b/packages/slate/test/commands/with-intent/insert-block/is-void-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/is-void-start.js rename to packages/slate/test/commands/with-intent/insert-block/is-void-start.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/with-block.js b/packages/slate/test/commands/with-intent/insert-block/with-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/with-block.js rename to packages/slate/test/commands/with-intent/insert-block/with-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-block/with-object.js b/packages/slate/test/commands/with-intent/insert-block/with-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-block/with-object.js rename to packages/slate/test/commands/with-intent/insert-block/with-object.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/end-block-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/end-block-multiple-blocks.js rename to packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/end-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/end-block.js rename to packages/slate/test/commands/with-intent/insert-fragment/end-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/end-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/end-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/end-inline.js rename to packages/slate/test/commands/with-intent/insert-fragment/end-inline.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-adjacent-texts.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/fragment-adjacent-texts.js rename to packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-inline-node.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/fragment-inline-node.js rename to packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/fragment-multiple-blocks.js rename to packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-nested-blocks-end-of-node.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/fragment-nested-blocks-end-of-node.js rename to packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-nested-blocks-start-of-node.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/fragment-nested-blocks-start-of-node.js rename to packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-nested-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/fragment-nested-blocks.js rename to packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/fragment-single-child-block.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/fragment-single-child-block.js rename to packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/hanging-selection-single-block.js b/packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/hanging-selection-single-block.js rename to packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/merge-deep-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/merge-deep-nested.js rename to packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/merge-lists.js b/packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/merge-lists.js rename to packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/middle-block.js rename to packages/slate/test/commands/with-intent/insert-fragment/middle-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/middle-fragment-adjacent-texts.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/middle-fragment-adjacent-texts.js rename to packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/middle-inline-fragment-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/middle-inline-fragment-inline.js rename to packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/middle-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/middle-inline.js rename to packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/nested-block-fragment-nested-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/nested-block-fragment-nested-blocks.js rename to packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/start-block-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/start-block-multiple-blocks.js rename to packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/start-block-with-void-no-text.js b/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/start-block-with-void-no-text.js rename to packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/start-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/start-block.js rename to packages/slate/test/commands/with-intent/insert-fragment/start-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/start-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/start-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/start-inline.js rename to packages/slate/test/commands/with-intent/insert-fragment/start-inline.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/start-second-block.js b/packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/start-second-block.js rename to packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-fragment/with-delete-across-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-fragment/with-delete-across-blocks.js rename to packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/insert-inline/block-end.js b/packages/slate/test/commands/with-intent/insert-inline/block-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-inline/block-end.js rename to packages/slate/test/commands/with-intent/insert-inline/block-end.js diff --git a/packages/slate/test/commands/at-current-range/insert-inline/block-middle.js b/packages/slate/test/commands/with-intent/insert-inline/block-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-inline/block-middle.js rename to packages/slate/test/commands/with-intent/insert-inline/block-middle.js diff --git a/packages/slate/test/commands/at-current-range/insert-inline/block-start.js b/packages/slate/test/commands/with-intent/insert-inline/block-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-inline/block-start.js rename to packages/slate/test/commands/with-intent/insert-inline/block-start.js diff --git a/packages/slate/test/commands/at-current-range/insert-inline/inline-middle.js b/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-inline/inline-middle.js rename to packages/slate/test/commands/with-intent/insert-inline/inline-middle.js diff --git a/packages/slate/test/commands/at-current-range/insert-inline/is-empty.js b/packages/slate/test/commands/with-intent/insert-inline/is-empty.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-inline/is-empty.js rename to packages/slate/test/commands/with-intent/insert-inline/is-empty.js diff --git a/packages/slate/test/commands/at-current-range/insert-inline/is-void.js b/packages/slate/test/commands/with-intent/insert-inline/is-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-inline/is-void.js rename to packages/slate/test/commands/with-intent/insert-inline/is-void.js diff --git a/packages/slate/test/commands/at-current-range/insert-inline/with-inline.js b/packages/slate/test/commands/with-intent/insert-inline/with-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-inline/with-inline.js rename to packages/slate/test/commands/with-intent/insert-inline/with-inline.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/after-mark.js b/packages/slate/test/commands/with-intent/insert-text/after-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/after-mark.js rename to packages/slate/test/commands/with-intent/insert-text/after-mark.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/before-mark.js b/packages/slate/test/commands/with-intent/insert-text/before-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/before-mark.js rename to packages/slate/test/commands/with-intent/insert-text/before-mark.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/blocks-with-overlapping-marks.js b/packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/blocks-with-overlapping-marks.js rename to packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/during-mark.js b/packages/slate/test/commands/with-intent/insert-text/during-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/during-mark.js rename to packages/slate/test/commands/with-intent/insert-text/during-mark.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/empty-block-with-mark.js b/packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/empty-block-with-mark.js rename to packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/expanded-with-mark.js b/packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/expanded-with-mark.js rename to packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/first-character.js b/packages/slate/test/commands/with-intent/insert-text/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/first-character.js rename to packages/slate/test/commands/with-intent/insert-text/first-character.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/first-space.js b/packages/slate/test/commands/with-intent/insert-text/first-space.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/first-space.js rename to packages/slate/test/commands/with-intent/insert-text/first-space.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/first-words.js b/packages/slate/test/commands/with-intent/insert-text/first-words.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/first-words.js rename to packages/slate/test/commands/with-intent/insert-text/first-words.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/hanging-selection-multiple-blocks.js rename to packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/hanging-selection-single-block.js b/packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/hanging-selection-single-block.js rename to packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/inside-void.js b/packages/slate/test/commands/with-intent/insert-text/inside-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/inside-void.js rename to packages/slate/test/commands/with-intent/insert-text/inside-void.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/last-character.js b/packages/slate/test/commands/with-intent/insert-text/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/last-character.js rename to packages/slate/test/commands/with-intent/insert-text/last-character.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/last-space.js b/packages/slate/test/commands/with-intent/insert-text/last-space.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/last-space.js rename to packages/slate/test/commands/with-intent/insert-text/last-space.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/last-words.js b/packages/slate/test/commands/with-intent/insert-text/last-words.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/last-words.js rename to packages/slate/test/commands/with-intent/insert-text/last-words.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/middle-character.js b/packages/slate/test/commands/with-intent/insert-text/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/middle-character.js rename to packages/slate/test/commands/with-intent/insert-text/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/middle-space.js b/packages/slate/test/commands/with-intent/insert-text/middle-space.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/middle-space.js rename to packages/slate/test/commands/with-intent/insert-text/middle-space.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/middle-words.js b/packages/slate/test/commands/with-intent/insert-text/middle-words.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/middle-words.js rename to packages/slate/test/commands/with-intent/insert-text/middle-words.js diff --git a/packages/slate/test/commands/at-current-range/insert-text/with-marks.js b/packages/slate/test/commands/with-intent/insert-text/with-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/insert-text/with-marks.js rename to packages/slate/test/commands/with-intent/insert-text/with-marks.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/across-blocks.js b/packages/slate/test/commands/with-intent/remove-mark/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/across-blocks.js rename to packages/slate/test/commands/with-intent/remove-mark/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/across-inlines.js b/packages/slate/test/commands/with-intent/remove-mark/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/across-inlines.js rename to packages/slate/test/commands/with-intent/remove-mark/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/collapsed-selection.js b/packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/collapsed-selection.js rename to packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/existing-marks.js b/packages/slate/test/commands/with-intent/remove-mark/existing-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/existing-marks.js rename to packages/slate/test/commands/with-intent/remove-mark/existing-marks.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/first-character.js b/packages/slate/test/commands/with-intent/remove-mark/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/first-character.js rename to packages/slate/test/commands/with-intent/remove-mark/first-character.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/last-character.js b/packages/slate/test/commands/with-intent/remove-mark/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/last-character.js rename to packages/slate/test/commands/with-intent/remove-mark/last-character.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/middle-character.js b/packages/slate/test/commands/with-intent/remove-mark/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/middle-character.js rename to packages/slate/test/commands/with-intent/remove-mark/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/whole-word.js b/packages/slate/test/commands/with-intent/remove-mark/whole-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/whole-word.js rename to packages/slate/test/commands/with-intent/remove-mark/whole-word.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/with-mark-object.js b/packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/with-mark-object.js rename to packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js diff --git a/packages/slate/test/commands/at-current-range/remove-mark/with-plain-object.js b/packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/remove-mark/with-plain-object.js rename to packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/across-blocks.js b/packages/slate/test/commands/with-intent/replace-mark/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/across-blocks.js rename to packages/slate/test/commands/with-intent/replace-mark/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/across-inlines.js b/packages/slate/test/commands/with-intent/replace-mark/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/across-inlines.js rename to packages/slate/test/commands/with-intent/replace-mark/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/existing-marks.js b/packages/slate/test/commands/with-intent/replace-mark/existing-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/existing-marks.js rename to packages/slate/test/commands/with-intent/replace-mark/existing-marks.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/first-character.js b/packages/slate/test/commands/with-intent/replace-mark/first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/first-character.js rename to packages/slate/test/commands/with-intent/replace-mark/first-character.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/last-character.js b/packages/slate/test/commands/with-intent/replace-mark/last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/last-character.js rename to packages/slate/test/commands/with-intent/replace-mark/last-character.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/middle-character.js b/packages/slate/test/commands/with-intent/replace-mark/middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/middle-character.js rename to packages/slate/test/commands/with-intent/replace-mark/middle-character.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/whole-word.js b/packages/slate/test/commands/with-intent/replace-mark/whole-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/whole-word.js rename to packages/slate/test/commands/with-intent/replace-mark/whole-word.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/with-mark-object.js b/packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/with-mark-object.js rename to packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js diff --git a/packages/slate/test/commands/at-current-range/replace-mark/with-plain-object.js b/packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/replace-mark/with-plain-object.js rename to packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js diff --git a/packages/slate/test/commands/at-current-range/set-block/across-blocks.js b/packages/slate/test/commands/with-intent/set-block/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/across-blocks.js rename to packages/slate/test/commands/with-intent/set-block/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/set-block/across-inlines.js b/packages/slate/test/commands/with-intent/set-block/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/across-inlines.js rename to packages/slate/test/commands/with-intent/set-block/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/set-block/data-only.js b/packages/slate/test/commands/with-intent/set-block/data-only.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/data-only.js rename to packages/slate/test/commands/with-intent/set-block/data-only.js diff --git a/packages/slate/test/commands/at-current-range/set-block/hanging-selection-across-inlines.js b/packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/hanging-selection-across-inlines.js rename to packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/set-block/hanging-selection.js b/packages/slate/test/commands/with-intent/set-block/hanging-selection.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/hanging-selection.js rename to packages/slate/test/commands/with-intent/set-block/hanging-selection.js diff --git a/packages/slate/test/commands/at-current-range/set-block/nested-block.js b/packages/slate/test/commands/with-intent/set-block/nested-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/nested-block.js rename to packages/slate/test/commands/with-intent/set-block/nested-block.js diff --git a/packages/slate/test/commands/at-current-range/set-block/single-block-string-shorthand.js b/packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/single-block-string-shorthand.js rename to packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js diff --git a/packages/slate/test/commands/at-current-range/set-block/single-block.js b/packages/slate/test/commands/with-intent/set-block/single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/single-block.js rename to packages/slate/test/commands/with-intent/set-block/single-block.js diff --git a/packages/slate/test/commands/at-current-range/set-block/with-data-as-map.js b/packages/slate/test/commands/with-intent/set-block/with-data-as-map.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/with-data-as-map.js rename to packages/slate/test/commands/with-intent/set-block/with-data-as-map.js diff --git a/packages/slate/test/commands/at-current-range/set-block/with-data-as-object.js b/packages/slate/test/commands/with-intent/set-block/with-data-as-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/with-data-as-object.js rename to packages/slate/test/commands/with-intent/set-block/with-data-as-object.js diff --git a/packages/slate/test/commands/at-current-range/set-block/with-is-void.js b/packages/slate/test/commands/with-intent/set-block/with-is-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-block/with-is-void.js rename to packages/slate/test/commands/with-intent/set-block/with-is-void.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/across-inlines.js b/packages/slate/test/commands/with-intent/set-inline/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/across-inlines.js rename to packages/slate/test/commands/with-intent/set-inline/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/data-only.js b/packages/slate/test/commands/with-intent/set-inline/data-only.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/data-only.js rename to packages/slate/test/commands/with-intent/set-inline/data-only.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/nested-inline.js b/packages/slate/test/commands/with-intent/set-inline/nested-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/nested-inline.js rename to packages/slate/test/commands/with-intent/set-inline/nested-inline.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/single-inline-string-shorthand.js b/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/single-inline-string-shorthand.js rename to packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/single-inline.js b/packages/slate/test/commands/with-intent/set-inline/single-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/single-inline.js rename to packages/slate/test/commands/with-intent/set-inline/single-inline.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/with-data-object.js b/packages/slate/test/commands/with-intent/set-inline/with-data-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/with-data-object.js rename to packages/slate/test/commands/with-intent/set-inline/with-data-object.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/with-data.js b/packages/slate/test/commands/with-intent/set-inline/with-data.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/with-data.js rename to packages/slate/test/commands/with-intent/set-inline/with-data.js diff --git a/packages/slate/test/commands/at-current-range/set-inline/with-is-void.js b/packages/slate/test/commands/with-intent/set-inline/with-is-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/set-inline/with-is-void.js rename to packages/slate/test/commands/with-intent/set-inline/with-is-void.js diff --git a/packages/slate/test/commands/at-current-range/split-block/after-inline-void.js b/packages/slate/test/commands/with-intent/split-block/after-inline-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/after-inline-void.js rename to packages/slate/test/commands/with-intent/split-block/after-inline-void.js diff --git a/packages/slate/test/commands/at-current-range/split-block/after-inline.js b/packages/slate/test/commands/with-intent/split-block/after-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/after-inline.js rename to packages/slate/test/commands/with-intent/split-block/after-inline.js diff --git a/packages/slate/test/commands/at-current-range/split-block/before-inline.js b/packages/slate/test/commands/with-intent/split-block/before-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/before-inline.js rename to packages/slate/test/commands/with-intent/split-block/before-inline.js diff --git a/packages/slate/test/commands/at-current-range/split-block/block-end.js b/packages/slate/test/commands/with-intent/split-block/block-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/block-end.js rename to packages/slate/test/commands/with-intent/split-block/block-end.js diff --git a/packages/slate/test/commands/at-current-range/split-block/block-middle.js b/packages/slate/test/commands/with-intent/split-block/block-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/block-middle.js rename to packages/slate/test/commands/with-intent/split-block/block-middle.js diff --git a/packages/slate/test/commands/at-current-range/split-block/block-start.js b/packages/slate/test/commands/with-intent/split-block/block-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/block-start.js rename to packages/slate/test/commands/with-intent/split-block/block-start.js diff --git a/packages/slate/test/commands/at-current-range/split-block/depth.js b/packages/slate/test/commands/with-intent/split-block/depth.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/depth.js rename to packages/slate/test/commands/with-intent/split-block/depth.js diff --git a/packages/slate/test/commands/at-current-range/split-block/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/with-delete-across-blocks-and-inlines.js rename to packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js diff --git a/packages/slate/test/commands/at-current-range/split-block/with-delete-across-blocks.js b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/with-delete-across-blocks.js rename to packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/split-block/with-delete-hanging-selection.js b/packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/with-delete-hanging-selection.js rename to packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js diff --git a/packages/slate/test/commands/at-current-range/split-block/with-delete.js b/packages/slate/test/commands/with-intent/split-block/with-delete.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/with-delete.js rename to packages/slate/test/commands/with-intent/split-block/with-delete.js diff --git a/packages/slate/test/commands/at-current-range/split-block/with-inline.js b/packages/slate/test/commands/with-intent/split-block/with-inline.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/with-inline.js rename to packages/slate/test/commands/with-intent/split-block/with-inline.js diff --git a/packages/slate/test/commands/at-current-range/split-block/with-marks.js b/packages/slate/test/commands/with-intent/split-block/with-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-block/with-marks.js rename to packages/slate/test/commands/with-intent/split-block/with-marks.js diff --git a/packages/slate/test/commands/at-current-range/split-inline/block-end.js b/packages/slate/test/commands/with-intent/split-inline/block-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-inline/block-end.js rename to packages/slate/test/commands/with-intent/split-inline/block-end.js diff --git a/packages/slate/test/commands/at-current-range/split-inline/block-middle.js b/packages/slate/test/commands/with-intent/split-inline/block-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-inline/block-middle.js rename to packages/slate/test/commands/with-intent/split-inline/block-middle.js diff --git a/packages/slate/test/commands/at-current-range/split-inline/block-start.js b/packages/slate/test/commands/with-intent/split-inline/block-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-inline/block-start.js rename to packages/slate/test/commands/with-intent/split-inline/block-start.js diff --git a/packages/slate/test/commands/at-current-range/split-inline/height.js b/packages/slate/test/commands/with-intent/split-inline/height.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-inline/height.js rename to packages/slate/test/commands/with-intent/split-inline/height.js diff --git a/packages/slate/test/commands/at-current-range/split-inline/with-delete.js b/packages/slate/test/commands/with-intent/split-inline/with-delete.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-inline/with-delete.js rename to packages/slate/test/commands/with-intent/split-inline/with-delete.js diff --git a/packages/slate/test/commands/at-current-range/split-inline/with-marks.js b/packages/slate/test/commands/with-intent/split-inline/with-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/split-inline/with-marks.js rename to packages/slate/test/commands/with-intent/split-inline/with-marks.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-across-blocks.js b/packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-across-blocks.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-across-inlines.js b/packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-across-inlines.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection-start.js b/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection-start.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection.js b/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-collapsed-selection.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-existing-marks-partially-marked.js b/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-existing-marks-partially-marked.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-existing-marks.js b/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-existing-marks.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-first-character.js b/packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-first-character.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-last-character.js b/packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-last-character.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-middle-character.js b/packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-middle-character.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-partially-marked.js b/packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-partially-marked.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-whole-word.js b/packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-whole-word.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-with-mark-object.js b/packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-with-mark-object.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/add-with-plain-object.js b/packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/add-with-plain-object.js rename to packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-across-blocks.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-across-blocks.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-across-inlines.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-across-inlines.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection-beginning.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection-beginning.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-collapsed-selection.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-existing-marks.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-existing-marks.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-first-character.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-first-character.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-last-character.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-last-character.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-middle-character.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-middle-character.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-whole-word.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-whole-word.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-with-mark-object.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-with-mark-object.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js diff --git a/packages/slate/test/commands/at-current-range/toggle-mark/remove-with-plain-object.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/toggle-mark/remove-with-plain-object.js rename to packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/across-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/across-blocks.js rename to packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/across-inlines.js b/packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/across-inlines.js rename to packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/ending-child-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/ending-child-blocks.js rename to packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/middle-child-blocks-with-backward-selection.js b/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/middle-child-blocks-with-backward-selection.js rename to packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/middle-child-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/middle-child-blocks.js rename to packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/nested-block.js b/packages/slate/test/commands/with-intent/unwrap-block/nested-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/nested-block.js rename to packages/slate/test/commands/with-intent/unwrap-block/nested-block.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/single-block.js b/packages/slate/test/commands/with-intent/unwrap-block/single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/single-block.js rename to packages/slate/test/commands/with-intent/unwrap-block/single-block.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/starting-child-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/starting-child-blocks.js rename to packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-block/with-object.js b/packages/slate/test/commands/with-intent/unwrap-block/with-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-block/with-object.js rename to packages/slate/test/commands/with-intent/unwrap-block/with-object.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-inline/across-blocks.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-inline/across-blocks.js rename to packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-inline/across-inlines-and-text.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-inline/across-inlines-and-text.js rename to packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-inline/across-inlines.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-inline/across-inlines.js rename to packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-inline/nested-block.js b/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-inline/nested-block.js rename to packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-inline/only-one.js b/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-inline/only-one.js rename to packages/slate/test/commands/with-intent/unwrap-inline/only-one.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-inline/single-block.js b/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-inline/single-block.js rename to packages/slate/test/commands/with-intent/unwrap-inline/single-block.js diff --git a/packages/slate/test/commands/at-current-range/unwrap-inline/with-object.js b/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/unwrap-inline/with-object.js rename to packages/slate/test/commands/with-intent/unwrap-inline/with-object.js diff --git a/packages/slate/test/commands/at-current-range/wrap-block/across-blocks.js b/packages/slate/test/commands/with-intent/wrap-block/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-block/across-blocks.js rename to packages/slate/test/commands/with-intent/wrap-block/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/wrap-block/across-inlines.js b/packages/slate/test/commands/with-intent/wrap-block/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-block/across-inlines.js rename to packages/slate/test/commands/with-intent/wrap-block/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/wrap-block/nested-block-with-object.js b/packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-block/nested-block-with-object.js rename to packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js diff --git a/packages/slate/test/commands/at-current-range/wrap-block/nested-block.js b/packages/slate/test/commands/with-intent/wrap-block/nested-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-block/nested-block.js rename to packages/slate/test/commands/with-intent/wrap-block/nested-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-block/single-block.js b/packages/slate/test/commands/with-intent/wrap-block/single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-block/single-block.js rename to packages/slate/test/commands/with-intent/wrap-block/single-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-block/with-object.js b/packages/slate/test/commands/with-intent/wrap-block/with-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-block/with-object.js rename to packages/slate/test/commands/with-intent/wrap-block/with-object.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/across-blocks.js b/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/across-blocks.js rename to packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/across-inlines.js b/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/across-inlines.js rename to packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/collapsed.js b/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/collapsed.js rename to packages/slate/test/commands/with-intent/wrap-inline/collapsed.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inline-end.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/inline-end.js rename to packages/slate/test/commands/with-intent/wrap-inline/inline-end.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inline-middle-with-marks.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/inline-middle-with-marks.js rename to packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inline-middle.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/inline-middle.js rename to packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inline-start.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/inline-start.js rename to packages/slate/test/commands/with-intent/wrap-inline/inline-start.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/inline-void.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/inline-void.js rename to packages/slate/test/commands/with-intent/wrap-inline/inline-void.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/nested-block.js b/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/nested-block.js rename to packages/slate/test/commands/with-intent/wrap-inline/nested-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/single-block.js b/packages/slate/test/commands/with-intent/wrap-inline/single-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/single-block.js rename to packages/slate/test/commands/with-intent/wrap-inline/single-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/twice.js b/packages/slate/test/commands/with-intent/wrap-inline/twice.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/twice.js rename to packages/slate/test/commands/with-intent/wrap-inline/twice.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/whole-block.js b/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/whole-block.js rename to packages/slate/test/commands/with-intent/wrap-inline/whole-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/with-object.js b/packages/slate/test/commands/with-intent/wrap-inline/with-object.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-inline/with-object.js rename to packages/slate/test/commands/with-intent/wrap-inline/with-object.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/across-blocks.js b/packages/slate/test/commands/with-intent/wrap-text/across-blocks.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/across-blocks.js rename to packages/slate/test/commands/with-intent/wrap-text/across-blocks.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/across-inlines.js b/packages/slate/test/commands/with-intent/wrap-text/across-inlines.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/across-inlines.js rename to packages/slate/test/commands/with-intent/wrap-text/across-inlines.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/backwards-selection.js b/packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/backwards-selection.js rename to packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/empty-block.js b/packages/slate/test/commands/with-intent/wrap-text/empty-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/empty-block.js rename to packages/slate/test/commands/with-intent/wrap-text/empty-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/end-of-block.js b/packages/slate/test/commands/with-intent/wrap-text/end-of-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/end-of-block.js rename to packages/slate/test/commands/with-intent/wrap-text/end-of-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/middle-of-block.js b/packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/middle-of-block.js rename to packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/start-of-block.js b/packages/slate/test/commands/with-intent/wrap-text/start-of-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/start-of-block.js rename to packages/slate/test/commands/with-intent/wrap-text/start-of-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/whole-block.js b/packages/slate/test/commands/with-intent/wrap-text/whole-block.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/whole-block.js rename to packages/slate/test/commands/with-intent/wrap-text/whole-block.js diff --git a/packages/slate/test/commands/at-current-range/wrap-text/without-suffix.js b/packages/slate/test/commands/with-intent/wrap-text/without-suffix.js similarity index 100% rename from packages/slate/test/commands/at-current-range/wrap-text/without-suffix.js rename to packages/slate/test/commands/with-intent/wrap-text/without-suffix.js From fb6889f3df7f1f60aeaf5afdf1dedc45edcf762f Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 27 Aug 2019 23:16:49 -0400 Subject: [PATCH 016/165] deprecate mode key usage, migrate more tests away from keys --- packages/slate-hyperscript/src/creators.js | 3 +- .../test/fixtures/selection.js | 4 +- packages/slate/src/commands/by-path.js | 16 ++------ packages/slate/src/interfaces/node.js | 18 +++++++-- packages/slate/src/interfaces/range.js | 12 ------ packages/slate/src/models/point.js | 21 +++++----- packages/slate/src/models/value.js | 15 +++++++- .../slate/src/plugins/core/core-queries.js | 32 ++++++++++++++++ .../inside-next-text-sibling.js | 30 --------------- .../on-selection/select/with-object.js | 12 +++--- .../on-selection/select/with-selection.js | 17 +++++---- .../get-closest/{by-key.js => by-path.js} | 2 +- .../single-void-block.js | 4 +- .../single-void-block.js | 4 +- .../get-next-block/{by-key.js => by-path.js} | 2 +- .../{by-key.js => by-path.js} | 2 +- .../single-void-block.js | 4 +- .../node/is-in-range/block-above-using-key.js | 35 ----------------- .../node/is-in-range/block-below-using-key.js | 38 ------------------- .../first-block-inside-using-key.js | 35 ----------------- .../first-text-inside-using-key.js | 35 ----------------- .../last-block-inside-using-key.js | 35 ----------------- .../is-in-range/last-text-inside-using-key.js | 35 ----------------- .../node/is-in-range/text-above-using-key.js | 35 ----------------- .../node/is-in-range/text-below-using-key.js | 38 ------------------- .../text-in-middle-inside-using-key.js | 35 ----------------- 26 files changed, 103 insertions(+), 416 deletions(-) delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js rename packages/slate/test/models/node/get-closest/{by-key.js => by-path.js} (88%) rename packages/slate/test/models/node/get-next-block/{by-key.js => by-path.js} (88%) rename packages/slate/test/models/node/get-previous-block/{by-key.js => by-path.js} (87%) delete mode 100644 packages/slate/test/models/node/is-in-range/block-above-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/block-below-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/first-block-inside-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/first-text-inside-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/last-block-inside-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/last-text-inside-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/text-above-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/text-below-using-key.js delete mode 100644 packages/slate/test/models/node/is-in-range/text-in-middle-inside-using-key.js diff --git a/packages/slate-hyperscript/src/creators.js b/packages/slate-hyperscript/src/creators.js index 451f57a805..dd6f15b231 100644 --- a/packages/slate-hyperscript/src/creators.js +++ b/packages/slate-hyperscript/src/creators.js @@ -296,6 +296,7 @@ export function createValue(tagName, attributes, children) { if (!partial) { ann.key = node.key + ann.path = path partials[id] = ann continue } @@ -306,7 +307,7 @@ export function createValue(tagName, attributes, children) { data: ann.data, anchor: { key: partial.key, - path: document.getPath(partial.key), + path: partial.path, offset: partial.offset, }, focus: { diff --git a/packages/slate-hyperscript/test/fixtures/selection.js b/packages/slate-hyperscript/test/fixtures/selection.js index e8d53f8f83..2c29eb3c16 100644 --- a/packages/slate-hyperscript/test/fixtures/selection.js +++ b/packages/slate-hyperscript/test/fixtures/selection.js @@ -10,8 +10,8 @@ export const input = ( - - + + ) diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index c3205ae9a5..3edda00d58 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -478,7 +478,7 @@ Commands.replaceNodeByPath = (fn, editor) => (path, node) => { /** * Replace a `length` of text at `offset` with new `text` and optional `marks`. * - * @param {String} key + * @param {Array} path * @param {Number} offset * @param {Number} length * @param {string} text @@ -665,12 +665,7 @@ Commands.splitDescendantsByPath = (fn, editor) => ( Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { path = Path.create(path) - const { value } = editor - const { document, selection } = value - const node = document.assertNode(path) - const first = node.getFirstText() - const last = node.getLastText() - const range = selection.moveToRangeOfNode(first, last) + const range = editor.getRange(path) editor.unwrapInlineAtRange(range, properties) } @@ -683,12 +678,7 @@ Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { Commands.unwrapBlockByPath = (fn, editor) => (path, properties) => { path = Path.create(path) - const { value } = editor - const { document, selection } = value - const node = document.assertNode(path) - const first = node.getFirstText() - const last = node.getLastText() - const range = selection.moveToRangeOfNode(first, last) + const range = editor.getRange(path) editor.unwrapBlockAtRange(range, properties) } diff --git a/packages/slate/src/interfaces/node.js b/packages/slate/src/interfaces/node.js index a3a751cbfe..19b377899c 100644 --- a/packages/slate/src/interfaces/node.js +++ b/packages/slate/src/interfaces/node.js @@ -124,18 +124,28 @@ class NodeInterface { // COMPAT: Handle a node object by iterating the descendants tree, so that // we avoid using keys for the future. - if (Node.isNode(key) && this.descendants) { + if (Node.isNode(key)) { if (key === this) { return List([]) } - for (const [node, path] of this.descendants()) { - if (key === node) { - return path + if (this.descendants) { + for (const [node, path] of this.descendants()) { + if (key === node) { + return path + } } } + + return null } + // console.trace() + warning( + false, + 'As of slate@0.48 passing a `key` string to `node.getPath` is deprecated. You can pass in a `node` instance instead to iterate the entire tree for a specific node.' + ) + const dict = this.getKeysToPathsTable() const path = dict[key] return path ? List(path) : null diff --git a/packages/slate/src/interfaces/range.js b/packages/slate/src/interfaces/range.js index 0242d43e6d..a2e4da8b94 100644 --- a/packages/slate/src/interfaces/range.js +++ b/packages/slate/src/interfaces/range.js @@ -179,9 +179,6 @@ class RangeInterface { /** * Move the range's anchor point to a new `path` and `offset`. * - * Optionally, the `path` can be a key string, or omitted entirely in which - * case it would be the offset number. - * * @param {List|String} path * @param {Number} offset * @return {Range} @@ -243,9 +240,6 @@ class RangeInterface { /** * Move the range's end point to a new `path` and `offset`. * - * Optionally, the `path` can be a key string, or omitted entirely in which - * case it would be the offset number. - * * @param {List|String} path * @param {Number} offset * @return {Range} @@ -307,9 +301,6 @@ class RangeInterface { /** * Move the range's focus point to a new `path` and `offset`. * - * Optionally, the `path` can be a key string, or omitted entirely in which - * case it would be the offset number. - * * @param {List|String} path * @param {Number} offset * @return {Range} @@ -371,9 +362,6 @@ class RangeInterface { /** * Move the range's start point to a new `path` and `offset`. * - * Optionally, the `path` can be a key string, or omitted entirely in which - * case it would be the offset number. - * * @param {List|String} path * @param {Number} offset * @return {Range} diff --git a/packages/slate/src/models/point.js b/packages/slate/src/models/point.js index 9dcb6ff3c9..c603c2ecf8 100644 --- a/packages/slate/src/models/point.js +++ b/packages/slate/src/models/point.js @@ -312,9 +312,6 @@ class Point extends Record(DEFAULTS) { /** * Move the point's anchor point to a new `path` and `offset`. * - * Optionally, the `path` can be a key string, or omitted entirely in which - * case it would be the offset number. - * * @param {List|String|Number} path * @param {Number} offset * @return {Point} @@ -384,13 +381,18 @@ class Point extends Record(DEFAULTS) { // to avoid creating the key -> path lookup table, we attempt to look up by path first. let target = path && node.getNode(path) - if (!target) { + if (!target && key) { + warning( + false, + 'As of slate@0.48 a point cannot be created with a `key` but without a `path`.' + ) + target = node.getNode(key) if (target) { // There is a misalignment of path and key const point = this.merge({ - path: node.getPath(key), + path: node.getPath(target), }) return point @@ -398,7 +400,6 @@ class Point extends Record(DEFAULTS) { } if (!target) { - debugger warning(false, "A point's `path` or `key` invalid and was reset!") const text = node.getFirstText() @@ -407,7 +408,7 @@ class Point extends Record(DEFAULTS) { const point = this.merge({ key: text.key, offset: 0, - path: node.getPath(text.key), + path: node.getPath(text), }) return point @@ -421,7 +422,7 @@ class Point extends Record(DEFAULTS) { const point = this.merge({ offset: offset - before, key: text.key, - path: node.getPath(text.key), + path: node.getPath(text), }) return point @@ -435,7 +436,7 @@ class Point extends Record(DEFAULTS) { let point = this.merge({ key: target.key, - path: path == null ? node.getPath(target.key) : path, + path: path == null ? node.getPath(target) : path, offset: offset == null ? 0 : Math.min(offset, target.text.length), }) @@ -450,7 +451,7 @@ class Point extends Record(DEFAULTS) { if (next) { point = point.merge({ key: next.key, - path: node.getPath(next.key), + path: node.getPath(next), offset: 0, }) } diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index 9e9b647c73..a84fa5a9a7 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -97,8 +97,19 @@ class Value extends Record(DEFAULTS) { annotations = Annotation.createMap(annotations) if (selection.isUnset) { - const text = document.getFirstText() - if (text) selection = selection.moveToStartOfNode(text) + const first = document.firstText() + + if (first) { + const [firstText, firstPath] = first + const start = document.createPoint({ + key: firstText.key, + path: firstPath, + offset: 0, + }) + + selection = selection.setPoints([start, start]) + } + selection = document.createSelection(selection) } diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index fa30d30ed5..7ba043fce2 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -1,3 +1,4 @@ +import Range from '../../models/range' import PathUtils from '../../utils/path-utils' import TextUtils from '../../utils/text-utils' @@ -84,6 +85,37 @@ function CoreQueriesPlugin() { return false }, + getFirstPoint: (fn, editor) => path => { + const { value: { document } } = editor + const [firstText, firstPath] = document.firstText({ path }) + const firstPoint = document.createPoint({ + key: firstText.key, + path: firstPath, + offset: 0, + }) + + return firstPoint + }, + + getLastPoint: (fn, editor) => path => { + const { value: { document } } = editor + const [lastText, lastPath] = document.lastText({ path }) + const lastPoint = document.createPoint({ + key: lastText.key, + path: lastPath, + offset: lastText.text.length, + }) + + return lastPoint + }, + + getRange: (fn, editor) => path => { + const anchor = editor.getFirstPoint(path) + const focus = editor.getLastPoint(path) + const range = Range.create({ anchor, focus }) + return range + }, + /** * Calculate the next point forward from a `point`. * diff --git a/packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js b/packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js deleted file mode 100644 index 6627b4164c..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/inside-next-text-sibling.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.moveNodeByPath([0], [1, 0]) -} - -export const input = ( - - - one - - two - - - -) - -export const output = ( - - - - - one - - - - -) diff --git a/packages/slate/test/commands/on-selection/select/with-object.js b/packages/slate/test/commands/on-selection/select/with-object.js index 9019e63a76..a1de73ecde 100644 --- a/packages/slate/test/commands/on-selection/select/with-object.js +++ b/packages/slate/test/commands/on-selection/select/with-object.js @@ -3,17 +3,19 @@ import h from '../../../helpers/h' export default function(editor) { - const { value } = editor - const { startText } = value + const { value: { document } } = editor + const [[node]] = document.texts() editor.select({ anchor: { - key: startText.key, + path: [0, 0], + key: node.key, offset: 0, }, focus: { - key: startText.key, - offset: startText.text.length, + path: [0, 0], + key: node.key, + offset: node.text.length, }, }) } diff --git a/packages/slate/test/commands/on-selection/select/with-selection.js b/packages/slate/test/commands/on-selection/select/with-selection.js index e148720671..7876cec3d9 100644 --- a/packages/slate/test/commands/on-selection/select/with-selection.js +++ b/packages/slate/test/commands/on-selection/select/with-selection.js @@ -3,20 +3,23 @@ import h from '../../../helpers/h' export default function(editor) { - const { value } = editor - const { selection, startText } = value - const range = selection.setProperties({ + const { value: { document, selection } } = editor + const [[node]] = document.texts() + + const next = selection.setProperties({ anchor: { - key: startText.key, + path: [0, 0], + key: node.key, offset: 0, }, focus: { - key: startText.key, - offset: startText.text.length, + path: [0, 0], + key: node.key, + offset: node.text.length, }, }) - editor.select(range) + editor.select(next) } export const input = ( diff --git a/packages/slate/test/models/node/get-closest/by-key.js b/packages/slate/test/models/node/get-closest/by-path.js similarity index 88% rename from packages/slate/test/models/node/get-closest/by-key.js rename to packages/slate/test/models/node/get-closest/by-path.js index 22d9928887..c7ddef248d 100644 --- a/packages/slate/test/models/node/get-closest/by-key.js +++ b/packages/slate/test/models/node/get-closest/by-path.js @@ -16,7 +16,7 @@ export const input = ( ) export default function({ document, selection }) { - return document.getClosestBlock(selection.end.key) + return document.getClosestBlock(selection.end.path) } export const output = ( diff --git a/packages/slate/test/models/node/get-descendants-at-range/single-void-block.js b/packages/slate/test/models/node/get-descendants-at-range/single-void-block.js index d2abcb79e3..3f24f2beb1 100644 --- a/packages/slate/test/models/node/get-descendants-at-range/single-void-block.js +++ b/packages/slate/test/models/node/get-descendants-at-range/single-void-block.js @@ -10,8 +10,8 @@ export const input = ( - - + + ) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js index ae5e9e188d..e6c9585a00 100644 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js +++ b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js @@ -11,8 +11,8 @@ export const input = ( - - + + ) diff --git a/packages/slate/test/models/node/get-next-block/by-key.js b/packages/slate/test/models/node/get-next-block/by-path.js similarity index 88% rename from packages/slate/test/models/node/get-next-block/by-key.js rename to packages/slate/test/models/node/get-next-block/by-path.js index 6004f50d34..84f2f102af 100644 --- a/packages/slate/test/models/node/get-next-block/by-key.js +++ b/packages/slate/test/models/node/get-next-block/by-path.js @@ -16,7 +16,7 @@ export const input = ( ) export default function({ document, selection }) { - return document.getNextBlock(selection.end.key) + return document.getNextBlock(selection.end.path) } export const output = three diff --git a/packages/slate/test/models/node/get-previous-block/by-key.js b/packages/slate/test/models/node/get-previous-block/by-path.js similarity index 87% rename from packages/slate/test/models/node/get-previous-block/by-key.js rename to packages/slate/test/models/node/get-previous-block/by-path.js index 3bde784972..c5c14ad6f3 100644 --- a/packages/slate/test/models/node/get-previous-block/by-key.js +++ b/packages/slate/test/models/node/get-previous-block/by-path.js @@ -16,7 +16,7 @@ export const input = ( ) export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.key) + return document.getPreviousBlock(selection.end.path) } export const output = one diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js b/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js index 502337c539..70ae64a4b2 100644 --- a/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js +++ b/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js @@ -11,8 +11,8 @@ export const input = ( - - + + ) diff --git a/packages/slate/test/models/node/is-in-range/block-above-using-key.js b/packages/slate/test/models/node/is-in-range/block-above-using-key.js deleted file mode 100644 index b4f3337a00..0000000000 --- a/packages/slate/test/models/node/is-in-range/block-above-using-key.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange('a', selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/block-below-using-key.js b/packages/slate/test/models/node/is-in-range/block-below-using-key.js deleted file mode 100644 index 5f1ead6207..0000000000 --- a/packages/slate/test/models/node/is-in-range/block-below-using-key.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - five - - - -) - -export default function({ document, selection }) { - return document.isInRange('k', selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/first-block-inside-using-key.js b/packages/slate/test/models/node/is-in-range/first-block-inside-using-key.js deleted file mode 100644 index f61a92f2f3..0000000000 --- a/packages/slate/test/models/node/is-in-range/first-block-inside-using-key.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange('c', selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/first-text-inside-using-key.js b/packages/slate/test/models/node/is-in-range/first-text-inside-using-key.js deleted file mode 100644 index 64a428a783..0000000000 --- a/packages/slate/test/models/node/is-in-range/first-text-inside-using-key.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange('d', selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/last-block-inside-using-key.js b/packages/slate/test/models/node/is-in-range/last-block-inside-using-key.js deleted file mode 100644 index 3d1004e2eb..0000000000 --- a/packages/slate/test/models/node/is-in-range/last-block-inside-using-key.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange('g', selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/last-text-inside-using-key.js b/packages/slate/test/models/node/is-in-range/last-text-inside-using-key.js deleted file mode 100644 index 4cc16ec48f..0000000000 --- a/packages/slate/test/models/node/is-in-range/last-text-inside-using-key.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange('j', selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/text-above-using-key.js b/packages/slate/test/models/node/is-in-range/text-above-using-key.js deleted file mode 100644 index c8fa0a374b..0000000000 --- a/packages/slate/test/models/node/is-in-range/text-above-using-key.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange('b', selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/text-below-using-key.js b/packages/slate/test/models/node/is-in-range/text-below-using-key.js deleted file mode 100644 index b4dfbab9f0..0000000000 --- a/packages/slate/test/models/node/is-in-range/text-below-using-key.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - five - - - -) - -export default function({ document, selection }) { - return document.isInRange('l', selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/text-in-middle-inside-using-key.js b/packages/slate/test/models/node/is-in-range/text-in-middle-inside-using-key.js deleted file mode 100644 index 8c12975f91..0000000000 --- a/packages/slate/test/models/node/is-in-range/text-in-middle-inside-using-key.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange('f', selection) -} - -export const output = true From 636d35063e517a4275f0cc47cb355aed6aa03d27 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 27 Aug 2019 23:24:28 -0400 Subject: [PATCH 017/165] deprecate range and point methods which rely on keys to work --- packages/slate/src/interfaces/range.js | 57 ++++++++++++++++++++++++++ packages/slate/src/models/point.js | 42 +++++++++++++++++-- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/packages/slate/src/interfaces/range.js b/packages/slate/src/interfaces/range.js index a2e4da8b94..57bf6694d6 100644 --- a/packages/slate/src/interfaces/range.js +++ b/packages/slate/src/interfaces/range.js @@ -1,3 +1,5 @@ +import warning from 'tiny-warning' + import mixin from '../utils/mixin' import Annotation from '../models/annotation' import Decoration from '../models/decoration' @@ -197,6 +199,11 @@ class RangeInterface { */ moveAnchorToStartOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveAnchorToStartOfNode` method is deprecated.' + ) + const range = this.setAnchor(this.anchor.moveToStartOfNode(node)) return range } @@ -209,6 +216,11 @@ class RangeInterface { */ moveAnchorToEndOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveAnchorToEndOfNode` method is deprecated.' + ) + const range = this.setAnchor(this.anchor.moveToEndOfNode(node)) return range } @@ -258,6 +270,11 @@ class RangeInterface { */ moveEndToStartOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveEndToStartOfNode` method is deprecated.' + ) + const range = this.setEnd(this.end.moveToStartOfNode(node)) return range } @@ -270,6 +287,11 @@ class RangeInterface { */ moveEndToEndOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveEndToEndOfNode` method is deprecated.' + ) + const range = this.setEnd(this.end.moveToEndOfNode(node)) return range } @@ -319,6 +341,11 @@ class RangeInterface { */ moveFocusToStartOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveFocusToStartOfNode` method is deprecated.' + ) + const range = this.setFocus(this.focus.moveToStartOfNode(node)) return range } @@ -331,6 +358,11 @@ class RangeInterface { */ moveFocusToEndOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveFocusToEndOfNode` method is deprecated.' + ) + const range = this.setFocus(this.focus.moveToEndOfNode(node)) return range } @@ -380,6 +412,11 @@ class RangeInterface { */ moveStartToStartOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveStartToStartOfNode` method is deprecated.' + ) + const range = this.setStart(this.start.moveToStartOfNode(node)) return range } @@ -392,6 +429,11 @@ class RangeInterface { */ moveStartToEndOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveStartToEndOfNode` method is deprecated.' + ) + const range = this.setStart(this.start.moveToEndOfNode(node)) return range } @@ -437,6 +479,11 @@ class RangeInterface { */ moveToEndOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveToEndOfNode` method is deprecated.' + ) + return this.updatePoints(point => point.moveToEndOfNode(node)) } @@ -460,6 +507,11 @@ class RangeInterface { */ moveToRangeOfNode(start, end = start) { + warning( + false, + 'As of slate@0.48 the `range.moveToRangeOfNode` method is deprecated.' + ) + const range = this.setPoints([ this.anchor.moveToStartOfNode(start), this.focus.moveToEndOfNode(end), @@ -487,6 +539,11 @@ class RangeInterface { */ moveToStartOfNode(node) { + warning( + false, + 'As of slate@0.48 the `range.moveToStartOfNode` method is deprecated.' + ) + return this.updatePoints(point => point.moveToStartOfNode(node)) } diff --git a/packages/slate/src/models/point.js b/packages/slate/src/models/point.js index c603c2ecf8..9e73b59bf6 100644 --- a/packages/slate/src/models/point.js +++ b/packages/slate/src/models/point.js @@ -235,6 +235,11 @@ class Point extends Record(DEFAULTS) { */ isAtEndOfNode(node) { + warning( + false, + 'As of slate@0.48 the `point.isAtEndOfNode` method is deprecated.' + ) + if (this.isUnset) { return false } @@ -252,6 +257,11 @@ class Point extends Record(DEFAULTS) { */ isAtStartOfNode(node) { + warning( + false, + 'As of slate@0.48 the `point.isAtStartOfNode` method is deprecated.' + ) + if (this.isUnset) { return false } @@ -272,6 +282,11 @@ class Point extends Record(DEFAULTS) { */ isInNode(node) { + warning( + false, + 'As of slate@0.48 the `point.isInNode` method is deprecated.' + ) + if (this.isUnset) { return false } @@ -342,6 +357,11 @@ class Point extends Record(DEFAULTS) { */ moveToStartOfNode(node) { + warning( + false, + 'As of slate@0.48 the `point.moveToStartOfNode` method is deprecated.' + ) + const first = node.getFirstText() const point = this.moveTo(first.key, 0) return point @@ -355,6 +375,11 @@ class Point extends Record(DEFAULTS) { */ moveToEndOfNode(node) { + warning( + false, + 'As of slate@0.48 the `point.moveToEndOfNode` method is deprecated.' + ) + const last = node.getLastText() const point = this.moveTo(last.key, last.text.length) return point @@ -384,7 +409,7 @@ class Point extends Record(DEFAULTS) { if (!target && key) { warning( false, - 'As of slate@0.48 a point cannot be created with a `key` but without a `path`.' + 'As of slate@0.48 a point cannot be created with a `key` but without a `path`, and this line will fail in a future version.' ) target = node.getNode(key) @@ -400,7 +425,10 @@ class Point extends Record(DEFAULTS) { } if (!target) { - warning(false, "A point's `path` or `key` invalid and was reset!") + warning( + false, + "A point's `path` or `key` invalid and was reset! This will fail in a future version." + ) const text = node.getFirstText() if (!text) return Point.create() @@ -415,7 +443,10 @@ class Point extends Record(DEFAULTS) { } if (target.object !== 'text') { - warning(false, 'A point should not reference a non-text node!') + warning( + false, + 'A point should not reference a non-text node! This will fail in a future version.' + ) const text = target.getTextAtOffset(offset) const before = target.getOffset(text.key) @@ -429,7 +460,10 @@ class Point extends Record(DEFAULTS) { } if (target && path && key && key !== target.key) { - warning(false, "A point's `key` did not match its `path`!") + warning( + false, + "A point's `key` did not match its `path`! This will fail in a future version." + ) // TODO: if we look up by path above and it differs by key, do we want to reset it to looking up by key? } From 89d89b2d0cf7f583e7eb4458457bd3ff9cd86b4e Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 28 Aug 2019 11:26:50 -0400 Subject: [PATCH 018/165] refactor insertBlock, without fixing warnings --- packages/slate/src/commands/at-range.js | 33 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 0e65057303..2ea84a2f41 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -404,20 +404,29 @@ Commands.insertBlockAtRange = (fn, editor) => (range, block) => { const [, blockPath] = document.closestBlock(start.path) const afterPath = Path.increment(blockPath) const insertionMode = getInsertionMode(editor, range) + let targetPath - if (insertionMode === 'before') { - editor.insertNodeByPath(blockPath, block) - } else if (insertionMode === 'after') { - editor.insertNodeByPath(afterPath, block) - } else { - const point = - editor.getNextNonVoidPoint(start) || editor.getPreviousNonVoidPoint(start) + editor.withoutNormalizing(() => { + if (insertionMode === 'before') { + targetPath = blockPath + } else if (insertionMode === 'after') { + targetPath = afterPath + } else { + const splitPoint = + editor.getNextNonVoidPoint(start) || + editor.getPreviousNonVoidPoint(start) + + editor.splitDescendantsByPath( + blockPath, + splitPoint.path, + splitPoint.offset + ) - editor.withoutNormalizing(() => { - editor.splitDescendantsByPath(blockPath, point.path, point.offset) - editor.insertNodeByPath(afterPath, block) - }) - } + targetPath = afterPath + } + + editor.insertNodeByPath(targetPath, block) + }) } /** From fdb774740f5f78bbd3215c72297ff94f32165338 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 28 Aug 2019 12:15:43 -0400 Subject: [PATCH 019/165] add pathRef/pointRef, fix insertBlock/Inline deprecations, work on insertFragment --- packages/slate/src/commands/at-point.js | 45 +- packages/slate/src/commands/at-range.js | 564 +++++++++++++----- packages/slate/src/commands/by-path.js | 29 +- packages/slate/src/commands/with-intent.js | 24 +- packages/slate/src/controllers/editor.js | 59 ++ packages/slate/src/interfaces/element.js | 21 + packages/slate/src/models/point.js | 72 ++- .../slate/src/plugins/core/core-queries.js | 31 + packages/slate/src/utils/path-utils.js | 17 + .../insert-fragment/block-empty.js | 33 + .../with-intent/insert-fragment/block-end.js | 31 + .../insert-fragment/block-middle.js | 31 + .../insert-fragment/block-start.js | 31 + .../insert-fragment/hanging-block.js | 42 ++ .../insert-fragment/inline-middle.js | 35 ++ .../insert-fragment/inline-start.js | 33 + .../insert-fragment/insert-block.js | 33 + .../insert-inline-at-inline-middle.js | 39 ++ .../insert-fragment/insert-inline.js | 35 ++ .../insert-multiple-blocks-at-middle.js | 33 + .../insert-multiple-blocks-at-start.js | 35 ++ .../insert-fragment/insert-multiple-texts.js | 34 ++ .../insert-nested-blocks-at-end.js | 39 ++ .../insert-nested-blocks-at-middle.js | 37 ++ .../insert-nested-blocks-at-start.js | 39 ++ .../last-block-fragment-multiple.js | 35 ++ .../last-block-fragment-single.js | 31 + .../last-block-inline-fragment-single.js | 33 + .../insert-fragment/merge-deep-nested.js | 46 +- .../insert-fragment/with-previous-block.js | 33 + 30 files changed, 1389 insertions(+), 211 deletions(-) create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/block-empty.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/block-end.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/block-middle.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/block-start.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/inline-start.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js diff --git a/packages/slate/src/commands/at-point.js b/packages/slate/src/commands/at-point.js index cea4dc8f06..b7061e8bff 100644 --- a/packages/slate/src/commands/at-point.js +++ b/packages/slate/src/commands/at-point.js @@ -6,32 +6,25 @@ const Commands = {} -/** - * Split all of the text and inline nodes at a `point`. - * - * @param {Point} point - * @return {Point} - */ - -Commands.splitInlineAtPoint = (fn, editor) => point => { - let { value: { document } } = editor - const furthestInline = document.furthestInline(point.path) - let targetPath = point.path - - if (furthestInline) { - ;[, targetPath] = furthestInline - } - - editor.splitDescendantsByPath(targetPath, point.path, point.offset) - - document = editor.value.document - const [, nextPath] = document.nextText(point.path) - const newPoint = point - .moveTo(nextPath, 0) - .setKey(null) - .normalize(document) - - return newPoint +Commands.splitBlockAtPoint = (fn, editor) => (point, height = 1) => { + editor.withoutNormalizing(() => { + const { value: { document } } = editor + let h = 0 + let blockPath + + for (const [node, path] of document.ancestors(point.path)) { + if (h >= height) { + break + } else if (node.object === 'block') { + blockPath = path + h++ + } + } + + if (blockPath) { + editor.splitDescendantsByPath(blockPath, point.path, point.offset) + } + }) } /** diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 2ea84a2f41..95e6b1652f 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -2,6 +2,7 @@ import { List } from 'immutable' import Block from '../models/block' import Inline from '../models/inline' import Mark from '../models/mark' +import Node from '../models/node' import Path from '../utils/path-utils' /** @@ -397,79 +398,188 @@ Commands.deleteWordForwardAtRange = (fn, editor) => range => { Commands.insertBlockAtRange = (fn, editor) => (range, block) => { range = deleteExpandedAtRange(editor, range) block = Block.create(block) - - const { value } = editor - const { document } = value + const { value: { document } } = editor const { start } = range - const [, blockPath] = document.closestBlock(start.path) - const afterPath = Path.increment(blockPath) - const insertionMode = getInsertionMode(editor, range) + const [closestBlock, closestBlockPath] = document.closestBlock(start.path) + const closestInline = document.closestInline(start.path) let targetPath + let pathRef editor.withoutNormalizing(() => { - if (insertionMode === 'before') { - targetPath = blockPath - } else if (insertionMode === 'after') { - targetPath = afterPath + if ( + (!closestInline && closestBlock.text === '') || + editor.isAtEndOfPath(start, closestBlockPath) + ) { + targetPath = Path.increment(closestBlockPath) + } else if ( + editor.isAtStartOfPath(start, closestBlockPath) || + editor.isVoid(closestBlock) + ) { + targetPath = closestBlockPath } else { const splitPoint = editor.getNextNonVoidPoint(start) || editor.getPreviousNonVoidPoint(start) editor.splitDescendantsByPath( - blockPath, + closestBlockPath, splitPoint.path, splitPoint.offset ) - targetPath = afterPath + targetPath = Path.increment(closestBlockPath) } editor.insertNodeByPath(targetPath, block) + pathRef = editor.createPathRef(targetPath) }) + + pathRef.unref() + return pathRef.path } /** - * Check if current block should be split or new block should be added before or behind it. + * Insert a `fragment` at a `range`. * * @param {Range} range + * @param {Document} fragment */ -const getInsertionMode = (editor, range) => { - const { value } = editor - const { document } = value +Commands.getBackwardMostPoint = (fn, editor) => point => { + if (point.offset === 0) { + return point + } else { + return editor.getPreviousPoint(point, { allowZeroWidth: true }) + } +} - range = range.normalize(document) - const { start } = range - const startBlock = document.getClosestBlock(start.path) - const startInline = document.getClosestInline(start.path) - - if (editor.isVoid(startBlock)) { - if (start.isAtEndOfNode(startBlock)) return 'after' - else return 'before' - } else if (!startInline && startBlock.text === '') { - return 'after' - } else if (start.isAtStartOfNode(startBlock)) { - return 'before' - } else if (start.isAtEndOfNode(startBlock)) { - return 'after' +Commands.getForwardMostPoint = (fn, editor) => point => { + const { value: { document } } = editor + const node = document.getNode(point.path) + + if (point.offset === node.text.length) { + return point + } else { + return editor.getNextPoint(point, { allowZeroWidth: true }) } - return 'split' } -/** - * Insert a `fragment` at a `range`. - * - * @param {Range} range - * @param {Document} fragment - */ +Commands.getInnerMostRange = (fn, editor) => range => { + const start = editor.getForwardMostPoint(range.start) + const end = editor.getBackwardMostPoint(range.end) + return range.setPoints([start, end]) +} + +Commands.ensureSplitBlockAtRange = (fn, editor) => range => { + const { value: { document } } = editor + const { isExpanded, start, end } = range + const [, startBlockPath] = document.closestBlock(start.path) + const [, endBlockPath] = document.closestBlock(end.path) + + // if (!editor.isAtEdgeOfPath(end, endBlockPath)) { + editor.splitDescendantsByPath(endBlockPath, end.path, end.offset) + // } + + if (isExpanded && !editor.isAtEdgeOfPath(start, startBlockPath)) { + editor.splitDescendantsByPath(startBlockPath, start.path, start.offset) + } +} Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { + editor.withoutNormalizing(() => { + range = deleteExpandedAtRange(editor, range) + + if (!fragment.nodes.size) { + return + } + + const point = range.start + const { value: { document } } = editor + const [, fragTextPath] = fragment.firstText() + let fragBlock = fragment.closestBlock(fragTextPath) + let height = 0 + let splitPath + + // Get a list of the nodes in the fragment that are top-level ancestors that + // only have a single child. Because sometimes, if the target point has + // matching ancestors then we avoid inserting them again. And instead insert + // just their children nodes. + const fragSingleAncestors = [] + const fragAncestors = Array.from(fragment.ancestors(fragTextPath)) + .reverse() + .map(([n]) => n) + + for (const ancestor of fragAncestors) { + fragSingleAncestors.push(ancestor) + + if (ancestor.nodes.size !== 1) { + break + } + } + + for (const [node, path] of document.ancestors(point.path)) { + debugger + + if (node.object === 'document') { + break + } + + if (node.object === 'block' && fragBlock) { + const [fragBlockNode, fragBlockPath] = fragBlock + debugger + + if (fragSingleAncestors.some(a => a.isSimilar(node))) { + fragment = fragment.set('nodes', fragBlockNode.nodes) + break + } + + if (fragBlockNode.isSimilar(node)) { + height++ + splitPath = path + fragBlock = fragment.closestBlock(fragBlockPath) + } + } + } + + debugger + editor.splitBlockAtPoint(point, height) + + const firstPath = Path.increment(splitPath) + const afterPathRef = editor.createPathRef(firstPath) + + fragment = fragment.mapDescendants(child => child.regenerateKey()) + + for (const node of fragment.nodes) { + const { path } = afterPathRef + const parentPath = Path.lift(path) + const index = path.last() + editor.insertNodeByPath(parentPath, index, node) + } + + const lastPath = Path.decrement(afterPathRef.path) + const firstPoint = editor.getPointAtStartOfPath(firstPath) + const afterPoint = editor.getPointAtStartOfPath(afterPathRef.path) + const lastPoint = editor.getPointAtEndOfPath(lastPath) + const lastPointRef = editor.createPointRef(lastPoint) + debugger + editor.mergeBlockByPath(afterPoint.path) + debugger + editor.mergeBlockByPath(firstPoint.path) + + range = range.setPoints([lastPointRef.point, lastPointRef.point]) + afterPathRef.unref() + lastPointRef.unref() + }) + + return range + editor.withoutNormalizing(() => { range = deleteExpandedAtRange(editor, range) // If the fragment is empty, there's nothing to do after deleting. - if (!fragment.nodes.size) return + if (!fragment.nodes.size) { + return + } // Regenerate the keys for all of the fragments nodes, so that they're // guaranteed not to collide with the existing keys in the document. Otherwise @@ -477,110 +587,276 @@ Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { // reference them. fragment = fragment.mapDescendants(child => child.regenerateKey()) - // Calculate a few things... + const { value: { document } } = editor const { start } = range - const { value } = editor - let { document } = value - let startText = document.getDescendant(start.path) - let startBlock = document.getClosestBlock(start.path) - let startChild = startBlock.getFurthestChild(startText.key) - const isAtStart = start.isAtStartOfNode(startBlock) - const parent = document.getParent(startBlock.key) - const index = parent.nodes.indexOf(startBlock) - const blocks = fragment.getBlocks() - const firstChild = fragment.nodes.first() - const lastChild = fragment.nodes.last() - const firstBlock = blocks.first() - const lastBlock = blocks.last() - const insertionNode = findInsertionNode(fragment, document, startBlock.key) - - // If the fragment only contains a void block, use `insertBlock` instead. - if (firstBlock === lastBlock && editor.isVoid(firstBlock)) { - editor.insertBlockAtRange(range, firstBlock) - return + const [startBlock, startBlockPath] = document.closestBlock(start.path) + const hasMultipleBlocks = fragment.nodes.size !== 1 + let insertPath = Path.increment(startBlockPath) + let parentPath = Path.lift(insertPath) + let startBlockInsertIndex = startBlock.nodes.size + let endBlockInsertIndex = 0 + let splitStart = false + let splitEnd = false + + for (const [node, path] of fragment.descendants()) { + const index = path.last() + const isChild = path.size === 1 + const isFirst = index === 0 + const isLast = index === fragment.nodes.size - 1 + + if (Path.isAt(path, [0]) && hasMultipleBlocks) { + if (Path.isChild(path, startBlockPath)) { + // Before the first child, we might need to split the start block. + if (path.last() === 0) { + if (editor.isAtStartOfPath(start, startBlockPath)) { + insertPath = startBlockPath + } else if (!editor.isAtEndOfPath(start, startBlockPath)) { + editor.splitDescendantsByPath( + startBlockPath, + start.path, + start.offset + ) + insertPath = Path.increment(insertPath) + startBlockInsertIndex = start.path.get(startBlockPath.size) + } + } + + editor.insertNodeByPath(startBlockPath, startBlockInsertIndex, node) + startBlockInsertIndex++ + } else { + // Do nothing, since these will get merged in. + } + } else if (Path.isAt(path, [fragment.nodes.size - 1])) { + if (Path.isChild(path, endBlockPath)) { + // Before the first child, we might need to split the end block. + if (path.last() === 0) { + if (editor.isAtStartOfPath(end, endBlockPath)) { + insertPath = endBlockPath + } else if (!editor.isAtEndOfPath(end, endBlockPath)) { + editor.splitDescendantsByPath(endBlockPath, end.path, end.offset) + insertPath = Path.increment(insertPath) + endBlockInsertIndex = end.path.get(endBlockPath.size) + } + } + + editor.insertNodeByPath(endBlockPath, endBlockInsertIndex, node) + endBlockInsertIndex++ + } else { + // Do nothing, since these will get merged in. + } + } else { + const parentPath = Path.lift(insertPath) + const index = insertPath.last() + 1 + editor.insertNodeByPath(parentPath, index, node) + insertPath = Path.increment(insertPath) + } + + if (path.equals(startBlockPath)) { + } else if (Path.isChild(path, startBlockPath)) { + editor.insertNodeByPath(startBlockPath, startBlockInsertIndex, node) + startBlockInsertIndex++ + } else if (path.equals(endBlockPath)) { + } else { + const parentPath = Path.lift(insertPath) + const index = insertPath.last() + editor.insertNodeByPath(parentPath, index, node) + } + + // if is start, and not merging, insert it + // if is middle, insert it + // if is end, and not merging, insert it + // if is end and merge, insert its children + // if is end parent and merging, remove } + }) - // If inserting the entire fragment and it starts or ends with a single - // nested block, e.g. a table, we do not merge it with existing blocks. - if ( - insertionNode === fragment && - (firstChild.hasBlockChildren() || lastChild.hasBlockChildren()) - ) { - fragment.nodes.reverse().forEach(node => { - editor.insertBlockAtRange(range, node) - }) + return range + + editor.withoutNormalizing(() => { + range = deleteExpandedAtRange(editor, range) + + // If the fragment is empty, there's nothing to do after deleting. + if (!fragment.nodes.size) { return } - // If the first and last block aren't the same, we need to insert all of the - // nodes after the insertion node's first block at the index. - if (firstBlock !== lastBlock) { - const lonelyParent = insertionNode.getFurthest( - firstBlock.key, - p => p.nodes.size === 1 - ) - const lonelyChild = lonelyParent || firstBlock - - const startIndex = parent.nodes.indexOf(startBlock) - const excludingLonelyChild = insertionNode.removeNode(lonelyChild.key) + // Regenerate the keys for all of the fragments nodes, so that they're + // guaranteed not to collide with the existing keys in the document. Otherwise + // they will be rengerated automatically and we won't have an easy way to + // reference them. + fragment = fragment.mapDescendants(child => child.regenerateKey()) - excludingLonelyChild.nodes.forEach((node, i) => { - const newIndex = startIndex + i + 1 - editor.insertNodeByKey(parent.key, newIndex, node) - }) + const { value: { document } } = editor + const { start } = range + const [, startBlockPath] = document.closestBlock(start.path) + const prevBlock = document.previousBlock(start.path) + const nextBlock = document.nextBlock(start.path) + const parentPath = Path.lift(startBlockPath) + let prevPath = prevBlock ? prevBlock[1] : null + let nextPath = nextBlock ? nextBlock[1] : null + let insertPath = Path.increment(startBlockPath) + + if (editor.isAtStartOfPath(start, startBlockPath)) { + nextPath = startBlockPath + insertPath = startBlockPath + } else if (editor.isAtEndOfPath(start, startBlockPath)) { + prevPath = startBlockPath + } else { + editor.splitDescendantsByPath(startBlockPath, start.path, start.offset) + prevPath = startBlockPath + nextPath = Path.increment(startBlockPath) } - // Check if we need to split the node. - if (start.offset !== 0) { - editor.splitDescendantsByKey(startChild.key, start.key, start.offset) + const firstPath = insertPath + + for (const [node] of fragment.blocks({ onlyRoots: true })) { + const index = insertPath.last() + editor.insertNodeByPath(parentPath, index, node) + + if ( + nextPath && + (Path.endsBefore(insertPath, nextPath) || + Path.endsAt(insertPath, nextPath)) + ) { + nextPath = Path.increment(nextPath, 1, insertPath.size - 1) + } + + insertPath = Path.increment(insertPath) } - // Update our variables with the new value. - document = editor.value.document - startText = document.getDescendant(start.key) - startBlock = document.getClosestBlock(start.key) - startChild = startBlock.getFurthestChild(startText.key) - - // If the first and last block aren't the same, we need to move any of the - // starting block's children after the split into the last block of the - // fragment, which has already been inserted. - if (firstBlock !== lastBlock) { - const nextChild = isAtStart - ? startChild - : startBlock.getNextSibling(startChild.key) - const nextNodes = nextChild - ? startBlock.nodes.skipUntil(n => n.key === nextChild.key) - : List() - const lastIndex = lastBlock.nodes.size - - nextNodes.forEach((node, i) => { - const newIndex = lastIndex + i - editor.moveNodeByKey(node.key, lastBlock.key, newIndex) - }) + const lastPath = Path.decrement(insertPath) + const lastText = fragment.lastText() + const [textNode, textPath] = lastText + const [, blockPath] = fragment.closestBlock(textPath) + const relativePath = textPath.slice(blockPath.size) + const path = lastPath.concat(relativePath) + const pathRef = editor.createPathRef(path) + + if (nextPath) { + nextPath = editor.mergeBlockByPath(nextPath) } - // If the starting block is empty, we replace it entirely with the first block - // of the fragment, since this leads to a more expected behavior for the user. - if ( - !editor.isVoid(startBlock) && - startBlock.text === '' && - !startBlock.findDescendant(n => editor.isVoid(n)) - ) { - editor.removeNodeByKey(startBlock.key) - editor.insertNodeByKey(parent.key, index, firstBlock) - } else { - // Otherwise, we maintain the starting block, and insert all of the first - // block's inline nodes into it at the split point. - const inlineChild = startBlock.getFurthestChild(startText.key) - const inlineIndex = startBlock.nodes.indexOf(inlineChild) - - firstBlock.nodes.forEach((inline, i) => { - const o = start.offset === 0 ? 0 : 1 - const newIndex = inlineIndex + i + o - editor.insertNodeByKey(startBlock.key, newIndex, inline) - }) + if (prevPath) { + if ( + nextPath && + (Path.endsBefore(firstPath, nextPath) || + Path.endsAt(firstPath, nextPath)) + ) { + nextPath = Path.decrement(nextPath, 1, firstPath.size - 1) + } + + editor.mergeBlockByPath(firstPath) } + + const offset = textNode.text.length + const point = editor.createPoint({ path: pathRef.path, offset }) + range = range.setPoints([point, point]) + pathRef.unref() }) + + // Calculate a few things... + const { start } = range + const { value } = editor + let { document } = value + let startText = document.getDescendant(start.path) + let startBlock = document.getClosestBlock(start.path) + let startChild = startBlock.getFurthestChild(startText.key) + const isAtStart = start.isAtStartOfNode(startBlock) + const parent = document.getParent(startBlock.key) + const index = parent.nodes.indexOf(startBlock) + const blocks = fragment.getBlocks() + const firstChild = fragment.nodes.first() + const lastChild = fragment.nodes.last() + const firstBlock = blocks.first() + const lastBlock = blocks.last() + const insertionNode = findInsertionNode(fragment, document, startBlock.key) + + // If the fragment only contains a void block, use `insertBlock` instead. + if (firstBlock === lastBlock && editor.isVoid(firstBlock)) { + editor.insertBlockAtRange(range, firstBlock) + return + } + + // If inserting the entire fragment and it starts or ends with a single + // nested block, e.g. a table, we do not merge it with existing blocks. + if ( + insertionNode === fragment && + (firstChild.hasBlockChildren() || lastChild.hasBlockChildren()) + ) { + fragment.nodes.reverse().forEach(node => { + editor.insertBlockAtRange(range, node) + }) + return + } + + // If the first and last block aren't the same, we need to insert all of the + // nodes after the insertion node's first block at the index. + if (firstBlock !== lastBlock) { + const lonelyParent = insertionNode.getFurthest( + firstBlock.key, + p => p.nodes.size === 1 + ) + const lonelyChild = lonelyParent || firstBlock + + const startIndex = parent.nodes.indexOf(startBlock) + const excludingLonelyChild = insertionNode.removeNode(lonelyChild.key) + + excludingLonelyChild.nodes.forEach((node, i) => { + const newIndex = startIndex + i + 1 + editor.insertNodeByKey(parent.key, newIndex, node) + }) + } + + // Check if we need to split the node. + if (start.offset !== 0) { + editor.splitDescendantsByKey(startChild.key, start.key, start.offset) + } + + // Update our variables with the new value. + document = editor.value.document + startText = document.getDescendant(start.key) + startBlock = document.getClosestBlock(start.key) + startChild = startBlock.getFurthestChild(startText.key) + + // If the first and last block aren't the same, we need to move any of the + // starting block's children after the split into the last block of the + // fragment, which has already been inserted. + if (firstBlock !== lastBlock) { + const nextChild = isAtStart + ? startChild + : startBlock.getNextSibling(startChild.key) + const nextNodes = nextChild + ? startBlock.nodes.skipUntil(n => n.key === nextChild.key) + : List() + const lastIndex = lastBlock.nodes.size + + nextNodes.forEach((node, i) => { + const newIndex = lastIndex + i + editor.moveNodeByKey(node.key, lastBlock.key, newIndex) + }) + } + + // If the starting block is empty, we replace it entirely with the first block + // of the fragment, since this leads to a more expected behavior for the user. + if ( + !editor.isVoid(startBlock) && + startBlock.text === '' && + !startBlock.findDescendant(n => editor.isVoid(n)) + ) { + editor.removeNodeByKey(startBlock.key) + editor.insertNodeByKey(parent.key, index, firstBlock) + } else { + // Otherwise, we maintain the starting block, and insert all of the first + // block's inline nodes into it at the split point. + const inlineChild = startBlock.getFurthestChild(startText.key) + const inlineIndex = startBlock.nodes.indexOf(inlineChild) + + firstBlock.nodes.forEach((inline, i) => { + const o = start.offset === 0 ? 0 : 1 + const newIndex = inlineIndex + i + o + editor.insertNodeByKey(startBlock.key, newIndex, inline) + }) + } } const findInsertionNode = (fragment, document, startKey) => { @@ -589,16 +865,21 @@ const findInsertionNode = (fragment, document, startKey) => { return object.nodes.size === 1 } - const firstNode = object => object && object.nodes.first() + const firstNode = object => { + return object && object.nodes.first() + } + let node = fragment if (hasSingleNode(fragment)) { let fragmentInner = firstNode(fragment) + let documentInner = document.getFurthest(startKey, documentNode => { + return documentNode.type === fragmentInner.type + }) - const matches = documentNode => documentNode.type === fragmentInner.type - let documentInner = document.getFurthest(startKey, matches) - - if (documentInner === document.getParent(startKey)) node = fragmentInner + if (documentInner === document.getParent(startKey)) { + node = fragmentInner + } while (hasSingleNode(fragmentInner) && hasSingleNode(documentInner)) { fragmentInner = firstNode(fragmentInner) @@ -623,21 +904,30 @@ const findInsertionNode = (fragment, document, startKey) => { */ Commands.insertInlineAtRange = (fn, editor) => (range, inline) => { + inline = Inline.create(inline) + let pathRef + editor.withoutNormalizing(() => { - inline = Inline.create(inline) range = deleteExpandedAtRange(editor, range) const { value: { document } } = editor - const { start: { path, offset } } = range - const insertPath = Path.increment(path) + let { start: { path, offset } } = range const closestVoid = document.closest(path, editor.isVoid) if (closestVoid) { return } - editor.splitNodeByPath(path, offset) - editor.insertNodeByPath(insertPath, inline) + path = editor.splitNodeByPath(path, offset) + path = editor.insertNodeByPath(path, inline) + pathRef = editor.createPathRef(path) }) + + if (!pathRef) { + return null + } + + pathRef.unref() + return pathRef.path } /** diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index 3edda00d58..e28f792905 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -134,6 +134,8 @@ Commands.insertNodeByPath = (fn, editor) => (path, index, node) => { path, node, }) + + return path } /** @@ -190,6 +192,7 @@ Commands.insertTextByPath = (fn, editor) => (path, offset, text, marks) => { * Merge a node by `path` with the previous node. * * @param {Array} path + * @return {List} */ Commands.mergeNodeByPath = (fn, editor) => path => { @@ -210,6 +213,8 @@ Commands.mergeNodeByPath = (fn, editor) => path => { data: node.data, }, }) + + return prevPath } Commands.mergeBlockByPath = (fn, editor) => path => { @@ -217,8 +222,6 @@ Commands.mergeBlockByPath = (fn, editor) => path => { editor.withoutNormalizing(() => { const { value: { document } } = editor - document.assertNode(path) - const node = document.assertNode(path) let blockPath @@ -239,21 +242,26 @@ Commands.mergeBlockByPath = (fn, editor) => path => { const [, prevPath] = prevBlock const newPath = Path.increment(prevPath) - const newParentPath = Path.lift(prevPath) + const commonAncestorPath = Path.relate(blockPath, prevPath) editor.moveNodeByPath(blockPath, newPath) - editor.mergeNodeByPath(newPath) + path = editor.mergeNodeByPath(newPath) for (const [ancestor, ancestorPath] of document.ancestors(blockPath)) { - if (ancestorPath.equals(newParentPath)) { - break - } + if (ancestor.object === 'block') { + if ( + ancestorPath.equals(commonAncestorPath) || + ancestor.nodes.size !== 1 + ) { + break + } - if (ancestor.nodes.size === 1) { editor.removeNodeByPath(ancestorPath) } } }) + + return path } /** @@ -612,6 +620,8 @@ Commands.splitNodeByPath = (fn, editor) => (path, position, options = {}) => { data: node.data, }, }) + + return Path.increment(path) } /** @@ -631,8 +641,7 @@ Commands.splitDescendantsByPath = (fn, editor) => ( textPath = Path.create(textPath) if (path.equals(textPath)) { - editor.splitNodeByPath(textPath, textOffset) - return + return editor.splitNodeByPath(textPath, textOffset) } const { value } = editor diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js index 9e9571afd4..5279f3ca84 100644 --- a/packages/slate/src/commands/with-intent.js +++ b/packages/slate/src/commands/with-intent.js @@ -215,14 +215,11 @@ Commands.deleteWordForward = (fn, editor) => () => { Commands.insertBlock = (fn, editor) => block => { deleteExpanded(editor) - block = Block.create(block) const { value } = editor const { selection } = value - editor.insertBlockAtRange(selection, block) - - const path = editor.value.document.getPath(block.key) - editor.moveToEndOfPath(path) + const blockPath = editor.insertBlockAtRange(selection, block) + editor.moveToEndOfPath(blockPath) } /** @@ -232,6 +229,15 @@ Commands.insertBlock = (fn, editor) => block => { */ Commands.insertFragment = (fn, editor) => fragment => { + editor.withoutNormalizing(() => { + const { value: { selection } } = editor + const range = editor.insertFragmentAtRange(selection, fragment) + debugger + editor.select(range) + }) + + return + if (!fragment.nodes.size) return deleteExpanded(editor) @@ -289,14 +295,14 @@ Commands.insertFragment = (fn, editor) => fragment => { Commands.insertInline = (fn, editor) => inline => { deleteExpanded(editor) - inline = Inline.create(inline) const { value } = editor const { selection } = value - editor.insertInlineAtRange(selection, inline) + const path = editor.insertInlineAtRange(selection, inline) - const path = editor.value.document.getPath(inline.key) - editor.moveToEndOfPath(path) + if (path) { + editor.moveToEndOfPath(path) + } } /** diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index f223c17ad2..d15ae34fce 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -10,6 +10,8 @@ import PathUtils from '../utils/path-utils' import SchemaPlugin from '../plugins/schema' import Value from '../models/value' +let refIds = 0 + /** * Debug. * @@ -50,6 +52,8 @@ class Editor { this.tmp = { dirty: [], + pathRefs: [], + pointRefs: [], flushing: false, merge: null, normalize: true, @@ -107,6 +111,33 @@ class Editor { this.tmp.dirty = dirty + // Iterate all of the path refs to update them. If the operation results in + // the path being destroyed, unref them since they'll never change. + for (const id in this.tmp.pathRefs) { + const ref = this.tmp.pathRefs[id] + const path = PathUtils.transform(ref.path, operation).last() + + if (!path) { + ref.path = null + ref.unref() + } else { + ref.path = path + } + } + + // Do the same with any point refs. + for (const id in this.tmp.pointRefs) { + const ref = this.tmp.pointRefs[id] + const point = ref.point.transform(operation) + + if (!point) { + ref.point = null + ref.unref() + } else { + ref.point = point.normalize(this.value.document) + } + } + // If we're not already, queue the flushing process on the next tick. if (!this.tmp.flushing) { this.tmp.flushing = true @@ -114,6 +145,34 @@ class Editor { } } + createPathRef(path) { + const id = refIds++ + const ref = { + path, + unref: () => delete this.tmp.pathRefs[id], + } + + if (path) { + this.tmp.pathRefs[id] = ref + } + + return ref + } + + createPointRef(point) { + const id = refIds++ + const ref = { + point, + unref: () => delete this.tmp.pointRefs[id], + } + + if (point) { + this.tmp.pointRefs[id] = ref + } + + return ref + } + /** * Exec a handler of the editor by `name` with `...args`. * diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js index 225f3a6459..bf8df9ccc9 100644 --- a/packages/slate/src/interfaces/element.js +++ b/packages/slate/src/interfaces/element.js @@ -1376,6 +1376,18 @@ class ElementInterface { ) } + isSimilar(other) { + // HACK: this shouldn't need to be special-cased. + if (other.object === 'document' && this.object === 'document') { + return true + } else if (other.object === 'document' || this.object === 'document') { + return false + } + + const props = Node.createProperties(this) + return other.hasProperties(props) + } + /** * Check if a node has a void parent. * @@ -1831,6 +1843,15 @@ class ElementInterface { return last } + lastBlock(options) { + const [last] = this.blocks({ + direction: 'backward', + ...options, + }) + + return last + } + closest(path, predicate) { for (const [n, p] of this.ancestors(path)) { if (predicate(n, p)) { diff --git a/packages/slate/src/models/point.js b/packages/slate/src/models/point.js index 9e73b59bf6..8a6d427bbf 100644 --- a/packages/slate/src/models/point.js +++ b/packages/slate/src/models/point.js @@ -3,7 +3,7 @@ import warning from 'tiny-warning' import { Record } from 'immutable' import KeyUtils from '../utils/key-utils' -import PathUtils from '../utils/path-utils' +import Path from '../utils/path-utils' /** * Default properties. @@ -65,7 +65,7 @@ class Point extends Record(DEFAULTS) { const p = {} if ('key' in a) p.key = a.key if ('offset' in a) p.offset = a.offset - if ('path' in a) p.path = PathUtils.create(a.path) + if ('path' in a) p.path = Path.create(a.path) // If only a path is set, or only a key is set, ensure that the other is // set to null so that it can be normalized back to the right value. @@ -94,7 +94,7 @@ class Point extends Record(DEFAULTS) { const point = new Point({ key, offset, - path: PathUtils.create(path), + path: Path.create(path), }) return point @@ -131,7 +131,7 @@ class Point extends Record(DEFAULTS) { return false } - const result = PathUtils.compare(this.path, point.path) + const result = Path.compare(this.path, point.path) const isAfter = (result === 0 && this.offset > point.offset) || result === 1 return isAfter } @@ -187,7 +187,7 @@ class Point extends Record(DEFAULTS) { return false } - const result = PathUtils.compare(this.path, point.path) + const result = Path.compare(this.path, point.path) const isBefore = (result === 0 && this.offset < point.offset) || result === -1 @@ -531,7 +531,7 @@ class Point extends Record(DEFAULTS) { setPath(path) { if (path != null) { - path = PathUtils.create(path) + path = Path.create(path) } const point = this.set('path', path) @@ -573,6 +573,66 @@ class Point extends Record(DEFAULTS) { path: null, }) } + + transform(op) { + const point = this + const { path, offset } = point + + if (op.type === 'insert_text') { + if (Path.isEqual(op.path, path) && op.offset <= offset) { + const newOffset = offset + op.text.length + return point.setOffset(newOffset) + } + } + + if (op.type === 'remove_text') { + if (Path.isEqual(op.path, path) && op.offset <= offset) { + const newOffset = offset + op.text.length + return point.setOffset(newOffset) + } + } + + if (op.type === 'remove_node') { + if (Path.isEqual(op.path, path)) { + return null + } + } + + if (op.type === 'split_node') { + if (Path.isEqual(op.path, path) && op.position <= offset) { + const newPath = Path.increment(path) + const newOffset = offset - op.position + return point + .setPath(newPath) + .setOffset(newOffset) + .setKey(null) + } + } + + if (op.type === 'merge_node') { + if (Path.isEqual(op.path, path)) { + const newPath = Path.decrement(path) + const newOffset = offset + op.position + return point + .setPath(newPath) + .setOffset(newOffset) + .setKey(null) + } + } + + if ( + op.type === 'insert_node' || + op.type === 'merge_node' || + op.type === 'move_node' || + op.type === 'remove_node' || + op.type === 'split_node' + ) { + const [first] = Path.transform(path, op) + return point.setPath(first).setKey(null) + } + + return point + } } /** diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index 7ba043fce2..b5089cf8fa 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -74,6 +74,37 @@ function CoreQueriesPlugin() { ) }, + getPointAtStartOfPath: (fn, editor) => path => { + const { value: { document } } = editor + const [, firstPath] = document.firstText({ path }) + const point = document.createPoint({ path: firstPath, offset: 0 }) + return point + }, + + getPointAtEndOfPath: (fn, editor) => path => { + const { value: { document } } = editor + const [lastNode, lastPath] = document.lastText({ path }) + const point = document.createPoint({ + path: lastPath, + offset: lastNode.text.length, + }) + + return point + }, + + getRangeAtEndOfPath: (fn, editor) => path => { + const { value: { document } } = editor + const point = editor.getPointAtEndOfPath(path) + const range = document.createRange({ anchor: point, focus: point }) + return range + }, + + createPoint: (fn, editor) => props => { + const { value: { document } } = editor + const point = document.createPoint(props) + return point + }, + /** * Check whether a `node` is void, defaults to false. * diff --git a/packages/slate/src/utils/path-utils.js b/packages/slate/src/utils/path-utils.js index 0e03a7ddf1..ccba074839 100644 --- a/packages/slate/src/utils/path-utils.js +++ b/packages/slate/src/utils/path-utils.js @@ -261,6 +261,20 @@ function isYounger(path, target) { return isEqual(p, t) && pl < tl } +function endsBefore(path, target) { + return isYounger(path, target) +} + +function endsAfter(path, target) { + return isOlder(path, target) +} + +function endsAt(path, target) { + const index = path.size + const [p, t] = crop(path, target, index) + return isEqual(p, t) +} + function isYoungerSibling(path, target) { return isSibling(path, target) && isYounger(path, target) } @@ -487,4 +501,7 @@ export default { isBetween, isUnder, isIn, + endsAt, + endsAfter, + endsBefore, } diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js b/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js new file mode 100644 index 0000000000..371628e95b --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + + + ) +} + +export const input = ( + + + + + + + +) + +export const output = ( + + + + one + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-end.js b/packages/slate/test/commands/with-intent/insert-fragment/block-end.js new file mode 100644 index 0000000000..f7da4747d1 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-end.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + wordfragment + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js new file mode 100644 index 0000000000..02221340a8 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + wofragmentrd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-start.js b/packages/slate/test/commands/with-intent/insert-fragment/block-start.js new file mode 100644 index 0000000000..5f3f691738 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-start.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + fragmentword + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js b/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js new file mode 100644 index 0000000000..9806eecd65 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js @@ -0,0 +1,42 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +const fragment = ( + + 1 + 2 + 3 + +) + +export default function(editor) { + editor.insertFragment(fragment) +} + +export const input = ( + + + one + + two + + + three + + + +) + +export const output = ( + + + one + 1 + 2 + + 3three + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js new file mode 100644 index 0000000000..0baadba0c6 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + wo + fragment + rd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js b/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js new file mode 100644 index 0000000000..4437ae2815 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + + word + + + +) + +export const output = ( + + + + fragment + word + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js new file mode 100644 index 0000000000..e16fdf3db3 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + two + + + ) +} + +export const input = ( + + + + one + + + +) + +export const output = ( + + + + onetwo + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js new file mode 100644 index 0000000000..629276bbc9 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + fragment + + + ) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + wo + + fragment + + rd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js new file mode 100644 index 0000000000..fff3b21fe2 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + three + + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + woonetwothreerd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js new file mode 100644 index 0000000000..cf03f6846f --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + one + two + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + woone + + tword + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js new file mode 100644 index 0000000000..f8779423d8 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + one + two + three + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + one + two + + threeword + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js new file mode 100644 index 0000000000..95ef72c090 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + + ) +} + +export const input = ( + + + + + + + +) + +export const output = ( + + + + onetwo + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js new file mode 100644 index 0000000000..f3e820c9f1 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + after quote + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wordone + + two + + + after quote + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js new file mode 100644 index 0000000000..6d83ae50eb --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + woone + + + tword + + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js new file mode 100644 index 0000000000..c9685dd945 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + after quote + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + one + + two + + + after quoteword + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js new file mode 100644 index 0000000000..fdfa818d28 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + one + two + three + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wordone + two + + three + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js new file mode 100644 index 0000000000..f7da4747d1 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + wordfragment + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js b/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js new file mode 100644 index 0000000000..12329bfe72 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + + +) + +export const output = ( + + + + word + fragment + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js index 950c19ef92..b276ee2ecb 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js @@ -5,12 +5,14 @@ import h from '../../../helpers/h' export default function(editor) { editor.insertFragment( - - + + 2 + + 3 - - + + ) } @@ -18,15 +20,13 @@ export default function(editor) { export const input = ( - - - - - 1 - - - - + + + + 1 + + + ) @@ -34,16 +34,16 @@ export const input = ( export const output = ( - - - - 12 - - 3 - - - - + + + 12 + + + + 3 + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js b/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js new file mode 100644 index 0000000000..07af463504 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + word + + another + + + +) + +export const output = ( + + + word + + fragmentanother + + + +) From fbb62d6af8e11f82f63c4a6bf4c0e9d8a9bd4c39 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 28 Aug 2019 14:34:54 -0400 Subject: [PATCH 020/165] refactor insertFragment --- package.json | 2 +- packages/slate/src/commands/at-range.js | 413 +-------------- packages/slate/src/commands/by-path.js | 2 + packages/slate/src/commands/with-intent.js | 52 +- .../middle-inline-fragment-inline.js | 5 +- yarn.lock | 478 +++++++++++++++++- 6 files changed, 498 insertions(+), 454 deletions(-) diff --git a/package.json b/package.json index 39a66c8a0c..caf08ed7e1 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "lodash": "^4.17.4", "matcha": "^0.7.0", "memoize-one": "^4.0.0", - "mocha": "^2.5.3", + "mocha": "^6.2.0", "mocha-lcov-reporter": "^1.3.0", "npm-run-all": "^4.1.2", "prettier": "^1.10.2", diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 95e6b1652f..7be14ce96a 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -2,7 +2,6 @@ import { List } from 'immutable' import Block from '../models/block' import Inline from '../models/inline' import Mark from '../models/mark' -import Node from '../models/node' import Path from '../utils/path-utils' /** @@ -486,6 +485,10 @@ Commands.ensureSplitBlockAtRange = (fn, editor) => range => { } Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { + let startPointRef + let endPointRef + let afterPathRef + editor.withoutNormalizing(() => { range = deleteExpandedAtRange(editor, range) @@ -495,405 +498,31 @@ Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { const point = range.start const { value: { document } } = editor - const [, fragTextPath] = fragment.firstText() - let fragBlock = fragment.closestBlock(fragTextPath) - let height = 0 - let splitPath - - // Get a list of the nodes in the fragment that are top-level ancestors that - // only have a single child. Because sometimes, if the target point has - // matching ancestors then we avoid inserting them again. And instead insert - // just their children nodes. - const fragSingleAncestors = [] - const fragAncestors = Array.from(fragment.ancestors(fragTextPath)) - .reverse() - .map(([n]) => n) - - for (const ancestor of fragAncestors) { - fragSingleAncestors.push(ancestor) - - if (ancestor.nodes.size !== 1) { - break - } - } - - for (const [node, path] of document.ancestors(point.path)) { - debugger - - if (node.object === 'document') { - break - } - - if (node.object === 'block' && fragBlock) { - const [fragBlockNode, fragBlockPath] = fragBlock - debugger - - if (fragSingleAncestors.some(a => a.isSimilar(node))) { - fragment = fragment.set('nodes', fragBlockNode.nodes) - break - } - - if (fragBlockNode.isSimilar(node)) { - height++ - splitPath = path - fragBlock = fragment.closestBlock(fragBlockPath) - } - } - } + const [, splitPath] = document.closestBlock(point.path) - debugger - editor.splitBlockAtPoint(point, height) + editor.splitBlockAtPoint(point, 1) - const firstPath = Path.increment(splitPath) - const afterPathRef = editor.createPathRef(firstPath) + const startPath = Path.increment(splitPath) + afterPathRef = editor.createPathRef(startPath) + editor.insertFragmentByPath(startPath, fragment) - fragment = fragment.mapDescendants(child => child.regenerateKey()) - - for (const node of fragment.nodes) { - const { path } = afterPathRef - const parentPath = Path.lift(path) - const index = path.last() - editor.insertNodeByPath(parentPath, index, node) - } - - const lastPath = Path.decrement(afterPathRef.path) - const firstPoint = editor.getPointAtStartOfPath(firstPath) - const afterPoint = editor.getPointAtStartOfPath(afterPathRef.path) - const lastPoint = editor.getPointAtEndOfPath(lastPath) - const lastPointRef = editor.createPointRef(lastPoint) - debugger + const afterPath = afterPathRef.path + const endPath = Path.decrement(afterPath) + const startPoint = editor.getPointAtStartOfPath(startPath) + const endPoint = editor.getPointAtEndOfPath(endPath) + const afterPoint = editor.getPointAtStartOfPath(afterPath) + startPointRef = editor.createPointRef(startPoint) + endPointRef = editor.createPointRef(endPoint) editor.mergeBlockByPath(afterPoint.path) - debugger - editor.mergeBlockByPath(firstPoint.path) - - range = range.setPoints([lastPointRef.point, lastPointRef.point]) - afterPathRef.unref() - lastPointRef.unref() + editor.mergeBlockByPath(startPoint.path) }) - return range - - editor.withoutNormalizing(() => { - range = deleteExpandedAtRange(editor, range) - - // If the fragment is empty, there's nothing to do after deleting. - if (!fragment.nodes.size) { - return - } - - // Regenerate the keys for all of the fragments nodes, so that they're - // guaranteed not to collide with the existing keys in the document. Otherwise - // they will be rengerated automatically and we won't have an easy way to - // reference them. - fragment = fragment.mapDescendants(child => child.regenerateKey()) - - const { value: { document } } = editor - const { start } = range - const [startBlock, startBlockPath] = document.closestBlock(start.path) - const hasMultipleBlocks = fragment.nodes.size !== 1 - let insertPath = Path.increment(startBlockPath) - let parentPath = Path.lift(insertPath) - let startBlockInsertIndex = startBlock.nodes.size - let endBlockInsertIndex = 0 - let splitStart = false - let splitEnd = false - - for (const [node, path] of fragment.descendants()) { - const index = path.last() - const isChild = path.size === 1 - const isFirst = index === 0 - const isLast = index === fragment.nodes.size - 1 - - if (Path.isAt(path, [0]) && hasMultipleBlocks) { - if (Path.isChild(path, startBlockPath)) { - // Before the first child, we might need to split the start block. - if (path.last() === 0) { - if (editor.isAtStartOfPath(start, startBlockPath)) { - insertPath = startBlockPath - } else if (!editor.isAtEndOfPath(start, startBlockPath)) { - editor.splitDescendantsByPath( - startBlockPath, - start.path, - start.offset - ) - insertPath = Path.increment(insertPath) - startBlockInsertIndex = start.path.get(startBlockPath.size) - } - } - - editor.insertNodeByPath(startBlockPath, startBlockInsertIndex, node) - startBlockInsertIndex++ - } else { - // Do nothing, since these will get merged in. - } - } else if (Path.isAt(path, [fragment.nodes.size - 1])) { - if (Path.isChild(path, endBlockPath)) { - // Before the first child, we might need to split the end block. - if (path.last() === 0) { - if (editor.isAtStartOfPath(end, endBlockPath)) { - insertPath = endBlockPath - } else if (!editor.isAtEndOfPath(end, endBlockPath)) { - editor.splitDescendantsByPath(endBlockPath, end.path, end.offset) - insertPath = Path.increment(insertPath) - endBlockInsertIndex = end.path.get(endBlockPath.size) - } - } - - editor.insertNodeByPath(endBlockPath, endBlockInsertIndex, node) - endBlockInsertIndex++ - } else { - // Do nothing, since these will get merged in. - } - } else { - const parentPath = Path.lift(insertPath) - const index = insertPath.last() + 1 - editor.insertNodeByPath(parentPath, index, node) - insertPath = Path.increment(insertPath) - } - - if (path.equals(startBlockPath)) { - } else if (Path.isChild(path, startBlockPath)) { - editor.insertNodeByPath(startBlockPath, startBlockInsertIndex, node) - startBlockInsertIndex++ - } else if (path.equals(endBlockPath)) { - } else { - const parentPath = Path.lift(insertPath) - const index = insertPath.last() - editor.insertNodeByPath(parentPath, index, node) - } - - // if is start, and not merging, insert it - // if is middle, insert it - // if is end, and not merging, insert it - // if is end and merge, insert its children - // if is end parent and merging, remove - } - }) + startPointRef.unref() + endPointRef.unref() + afterPathRef.unref() + range = range.setPoints([startPointRef.point, endPointRef.point]) return range - - editor.withoutNormalizing(() => { - range = deleteExpandedAtRange(editor, range) - - // If the fragment is empty, there's nothing to do after deleting. - if (!fragment.nodes.size) { - return - } - - // Regenerate the keys for all of the fragments nodes, so that they're - // guaranteed not to collide with the existing keys in the document. Otherwise - // they will be rengerated automatically and we won't have an easy way to - // reference them. - fragment = fragment.mapDescendants(child => child.regenerateKey()) - - const { value: { document } } = editor - const { start } = range - const [, startBlockPath] = document.closestBlock(start.path) - const prevBlock = document.previousBlock(start.path) - const nextBlock = document.nextBlock(start.path) - const parentPath = Path.lift(startBlockPath) - let prevPath = prevBlock ? prevBlock[1] : null - let nextPath = nextBlock ? nextBlock[1] : null - let insertPath = Path.increment(startBlockPath) - - if (editor.isAtStartOfPath(start, startBlockPath)) { - nextPath = startBlockPath - insertPath = startBlockPath - } else if (editor.isAtEndOfPath(start, startBlockPath)) { - prevPath = startBlockPath - } else { - editor.splitDescendantsByPath(startBlockPath, start.path, start.offset) - prevPath = startBlockPath - nextPath = Path.increment(startBlockPath) - } - - const firstPath = insertPath - - for (const [node] of fragment.blocks({ onlyRoots: true })) { - const index = insertPath.last() - editor.insertNodeByPath(parentPath, index, node) - - if ( - nextPath && - (Path.endsBefore(insertPath, nextPath) || - Path.endsAt(insertPath, nextPath)) - ) { - nextPath = Path.increment(nextPath, 1, insertPath.size - 1) - } - - insertPath = Path.increment(insertPath) - } - - const lastPath = Path.decrement(insertPath) - const lastText = fragment.lastText() - const [textNode, textPath] = lastText - const [, blockPath] = fragment.closestBlock(textPath) - const relativePath = textPath.slice(blockPath.size) - const path = lastPath.concat(relativePath) - const pathRef = editor.createPathRef(path) - - if (nextPath) { - nextPath = editor.mergeBlockByPath(nextPath) - } - - if (prevPath) { - if ( - nextPath && - (Path.endsBefore(firstPath, nextPath) || - Path.endsAt(firstPath, nextPath)) - ) { - nextPath = Path.decrement(nextPath, 1, firstPath.size - 1) - } - - editor.mergeBlockByPath(firstPath) - } - - const offset = textNode.text.length - const point = editor.createPoint({ path: pathRef.path, offset }) - range = range.setPoints([point, point]) - pathRef.unref() - }) - - // Calculate a few things... - const { start } = range - const { value } = editor - let { document } = value - let startText = document.getDescendant(start.path) - let startBlock = document.getClosestBlock(start.path) - let startChild = startBlock.getFurthestChild(startText.key) - const isAtStart = start.isAtStartOfNode(startBlock) - const parent = document.getParent(startBlock.key) - const index = parent.nodes.indexOf(startBlock) - const blocks = fragment.getBlocks() - const firstChild = fragment.nodes.first() - const lastChild = fragment.nodes.last() - const firstBlock = blocks.first() - const lastBlock = blocks.last() - const insertionNode = findInsertionNode(fragment, document, startBlock.key) - - // If the fragment only contains a void block, use `insertBlock` instead. - if (firstBlock === lastBlock && editor.isVoid(firstBlock)) { - editor.insertBlockAtRange(range, firstBlock) - return - } - - // If inserting the entire fragment and it starts or ends with a single - // nested block, e.g. a table, we do not merge it with existing blocks. - if ( - insertionNode === fragment && - (firstChild.hasBlockChildren() || lastChild.hasBlockChildren()) - ) { - fragment.nodes.reverse().forEach(node => { - editor.insertBlockAtRange(range, node) - }) - return - } - - // If the first and last block aren't the same, we need to insert all of the - // nodes after the insertion node's first block at the index. - if (firstBlock !== lastBlock) { - const lonelyParent = insertionNode.getFurthest( - firstBlock.key, - p => p.nodes.size === 1 - ) - const lonelyChild = lonelyParent || firstBlock - - const startIndex = parent.nodes.indexOf(startBlock) - const excludingLonelyChild = insertionNode.removeNode(lonelyChild.key) - - excludingLonelyChild.nodes.forEach((node, i) => { - const newIndex = startIndex + i + 1 - editor.insertNodeByKey(parent.key, newIndex, node) - }) - } - - // Check if we need to split the node. - if (start.offset !== 0) { - editor.splitDescendantsByKey(startChild.key, start.key, start.offset) - } - - // Update our variables with the new value. - document = editor.value.document - startText = document.getDescendant(start.key) - startBlock = document.getClosestBlock(start.key) - startChild = startBlock.getFurthestChild(startText.key) - - // If the first and last block aren't the same, we need to move any of the - // starting block's children after the split into the last block of the - // fragment, which has already been inserted. - if (firstBlock !== lastBlock) { - const nextChild = isAtStart - ? startChild - : startBlock.getNextSibling(startChild.key) - const nextNodes = nextChild - ? startBlock.nodes.skipUntil(n => n.key === nextChild.key) - : List() - const lastIndex = lastBlock.nodes.size - - nextNodes.forEach((node, i) => { - const newIndex = lastIndex + i - editor.moveNodeByKey(node.key, lastBlock.key, newIndex) - }) - } - - // If the starting block is empty, we replace it entirely with the first block - // of the fragment, since this leads to a more expected behavior for the user. - if ( - !editor.isVoid(startBlock) && - startBlock.text === '' && - !startBlock.findDescendant(n => editor.isVoid(n)) - ) { - editor.removeNodeByKey(startBlock.key) - editor.insertNodeByKey(parent.key, index, firstBlock) - } else { - // Otherwise, we maintain the starting block, and insert all of the first - // block's inline nodes into it at the split point. - const inlineChild = startBlock.getFurthestChild(startText.key) - const inlineIndex = startBlock.nodes.indexOf(inlineChild) - - firstBlock.nodes.forEach((inline, i) => { - const o = start.offset === 0 ? 0 : 1 - const newIndex = inlineIndex + i + o - editor.insertNodeByKey(startBlock.key, newIndex, inline) - }) - } -} - -const findInsertionNode = (fragment, document, startKey) => { - const hasSingleNode = object => { - if (!object || object.object === 'text') return - return object.nodes.size === 1 - } - - const firstNode = object => { - return object && object.nodes.first() - } - - let node = fragment - - if (hasSingleNode(fragment)) { - let fragmentInner = firstNode(fragment) - let documentInner = document.getFurthest(startKey, documentNode => { - return documentNode.type === fragmentInner.type - }) - - if (documentInner === document.getParent(startKey)) { - node = fragmentInner - } - - while (hasSingleNode(fragmentInner) && hasSingleNode(documentInner)) { - fragmentInner = firstNode(fragmentInner) - documentInner = firstNode(documentInner) - - if (fragmentInner.type === documentInner.type) { - node = fragmentInner - } else { - break - } - } - } - - return node } /** diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index e28f792905..1551eb61b2 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -99,6 +99,8 @@ Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { const parentPath = Path.lift(path) const start = path.last() + fragment = fragment.mapDescendants(child => child.regenerateKey()) + fragment.nodes.forEach((node, i) => { const targetPath = parentPath.concat([start + i]) editor.insertNodeByPath(targetPath, node) diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js index 5279f3ca84..06ff237ad7 100644 --- a/packages/slate/src/commands/with-intent.js +++ b/packages/slate/src/commands/with-intent.js @@ -232,59 +232,9 @@ Commands.insertFragment = (fn, editor) => fragment => { editor.withoutNormalizing(() => { const { value: { selection } } = editor const range = editor.insertFragmentAtRange(selection, fragment) - debugger editor.select(range) + editor.moveToEnd() }) - - return - - if (!fragment.nodes.size) return - - deleteExpanded(editor) - - let { value } = editor - let { document, selection } = value - const { start, end } = selection - const { startText, endText, startInline } = value - const lastText = fragment.getLastText() - const lastInline = fragment.getClosestInline(lastText.key) - const lastBlock = fragment.getClosestBlock(lastText.key) - const firstChild = fragment.nodes.first() - const lastChild = fragment.nodes.last() - const keys = Array.from(document.texts(), ([text]) => text.key) - const isAppending = - !startInline || - (start.isAtStartOfNode(startText) || end.isAtStartOfNode(startText)) || - (start.isAtEndOfNode(endText) || end.isAtEndOfNode(endText)) - - const isInserting = - firstChild.hasBlockChildren() || lastChild.hasBlockChildren() - - editor.insertFragmentAtRange(selection, fragment) - value = editor.value - document = value.document - - const newTexts = document.getTexts().filter(n => !keys.includes(n.key)) - const newText = isAppending ? newTexts.last() : newTexts.takeLast(2).first() - - if (newText && (lastInline || isInserting)) { - editor.moveToEndOfNode(newText) - } else if (newText) { - // The position within the last text node needs to be calculated. This is the length - // of all text nodes within the last block, but if the last block contains inline nodes, - // these have to be skipped. - const { nodes } = lastBlock - const lastIndex = nodes.findLastIndex( - node => node && node.object === 'inline' - ) - const remainingTexts = nodes.takeLast(nodes.size - lastIndex - 1) - const remainingTextLength = remainingTexts.reduce( - (acc, val) => acc + val.text.length, - 0 - ) - editor.moveToStartOfNode(newText) - editor.moveForward(remainingTextLength) - } } /** diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js index c4723fb980..629276bbc9 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js @@ -29,8 +29,9 @@ export const output = ( wo - fragment - + + fragment + rd diff --git a/yarn.lock b/yarn.lock index e4637a127e..fd919390cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -248,6 +248,11 @@ amdefine@>=0.0.4: version "1.0.1" resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" +ansi-colors@3.2.3: + version "3.2.3" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.3.tgz#57d35b8686e851e2cc04c403f1c00203976a1813" + integrity sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw== + ansi-escapes@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.1.0.tgz#f73207bb81207d75fd6c83f125af26eea378ca30" @@ -264,6 +269,11 @@ ansi-regex@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" +ansi-regex@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" + integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg== + ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" @@ -1393,6 +1403,11 @@ browser-process-hrtime@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-0.1.2.tgz#425d68a58d3447f02a04aa894187fce8af8b7b8e" +browser-stdout@1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" + integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== + browserify-aes@^1.0.0, browserify-aes@^1.0.4: version "1.1.1" resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.1.1.tgz#38b7ab55edb806ff2dcda1a7f1620773a477c49f" @@ -1597,6 +1612,11 @@ camelcase@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" +camelcase@^5.0.0: + version "5.3.1" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" + integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== + caniuse-api@^1.5.2: version "1.6.1" resolved "https://registry.yarnpkg.com/caniuse-api/-/caniuse-api-1.6.1.tgz#b534e7c734c4f81ec5fbe8aca2ad24354b962c6c" @@ -1647,6 +1667,15 @@ chalk@^2.0.0, chalk@^2.1.0, chalk@^2.3.1: escape-string-regexp "^1.0.5" supports-color "^5.3.0" +chalk@^2.0.1: + version "2.4.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" + integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== + dependencies: + ansi-styles "^3.2.1" + escape-string-regexp "^1.0.5" + supports-color "^5.3.0" + chardet@^0.4.0: version "0.4.2" resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2" @@ -1758,6 +1787,15 @@ cliui@^3.2.0: strip-ansi "^3.0.1" wrap-ansi "^2.0.0" +cliui@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-4.1.0.tgz#348422dbe82d800b3022eef4f6ac10bf2e4d1b49" + integrity sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ== + dependencies: + string-width "^2.1.1" + strip-ansi "^4.0.0" + wrap-ansi "^2.0.0" + clone@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.3.tgz#298d7e2231660f40c003c2ed3140decf3f53085f" @@ -2227,6 +2265,17 @@ cross-spawn@^5.0.1, cross-spawn@^5.1.0: shebang-command "^1.2.0" which "^1.2.9" +cross-spawn@^6.0.0: + version "6.0.5" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" + integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== + dependencies: + nice-try "^1.0.4" + path-key "^2.0.1" + semver "^5.5.0" + shebang-command "^1.2.0" + which "^1.2.9" + cryptiles@2.x.x: version "2.0.5" resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8" @@ -2407,13 +2456,20 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.6, debug@^2.6.8, debug@^2.6. dependencies: ms "2.0.0" +debug@3.2.6: + version "3.2.6" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" + integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== + dependencies: + ms "^2.1.1" + debug@^3.0.1, debug@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" dependencies: ms "2.0.0" -decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2: +decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2, decamelize@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -2555,6 +2611,11 @@ diff@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" +diff@3.5.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" + integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== + diffie-hellman@^5.0.0: version "5.0.2" resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.2.tgz#b5835739270cfe26acf632099fded2a07f209e5e" @@ -2721,6 +2782,11 @@ elliptic@^6.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.0" +emoji-regex@^7.0.1: + version "7.0.3" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" + integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA== + emojis-list@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" @@ -2794,6 +2860,18 @@ es-abstract@^1.4.3, es-abstract@^1.7.0: is-callable "^1.1.3" is-regex "^1.0.4" +es-abstract@^1.5.1: + version "1.13.0" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.13.0.tgz#ac86145fdd5099d8dd49558ccba2eaf9b88e24e9" + integrity sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg== + dependencies: + es-to-primitive "^1.2.0" + function-bind "^1.1.1" + has "^1.0.3" + is-callable "^1.1.4" + is-regex "^1.0.4" + object-keys "^1.0.12" + es-to-primitive@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.1.1.tgz#45355248a88979034b6792e19bb81f2b7975dd0d" @@ -2802,6 +2880,15 @@ es-to-primitive@^1.1.1: is-date-object "^1.0.1" is-symbol "^1.0.1" +es-to-primitive@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.0.tgz#edf72478033456e8dda8ef09e00ad9650707f377" + integrity sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg== + dependencies: + is-callable "^1.1.4" + is-date-object "^1.0.1" + is-symbol "^1.0.2" + es5-ext@^0.10.14, es5-ext@^0.10.35, es5-ext@^0.10.9, es5-ext@~0.10.14: version "0.10.38" resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.38.tgz#fa7d40d65bbc9bb8a67e1d3f9cc656a00530eed3" @@ -2862,7 +2949,7 @@ escape-string-regexp@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1" -escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: +escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -3114,6 +3201,19 @@ execa@^0.8.0: signal-exit "^3.0.0" strip-eof "^1.0.0" +execa@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/execa/-/execa-1.0.0.tgz#c6236a5bb4df6d6f15e88e7f017798216749ddd8" + integrity sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA== + dependencies: + cross-spawn "^6.0.0" + get-stream "^4.0.0" + is-stream "^1.1.0" + npm-run-path "^2.0.0" + p-finally "^1.0.0" + signal-exit "^3.0.0" + strip-eof "^1.0.0" + expand-brackets@^0.1.4: version "0.1.5" resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b" @@ -3354,6 +3454,13 @@ find-root@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4" +find-up@3.0.0, find-up@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73" + integrity sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg== + dependencies: + locate-path "^3.0.0" + find-up@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f" @@ -3376,6 +3483,13 @@ flat-cache@^1.2.1: graceful-fs "^4.1.2" write "^0.2.1" +flat@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/flat/-/flat-4.1.0.tgz#090bec8b05e39cba309747f1d588f04dbaf98db2" + integrity sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw== + dependencies: + is-buffer "~2.0.3" + flatten@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" @@ -3547,6 +3661,11 @@ get-caller-file@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5" +get-caller-file@^2.0.1: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + get-document@1: version "1.0.0" resolved "https://registry.yarnpkg.com/get-document/-/get-document-1.0.0.tgz#4821bce66f1c24cb0331602be6cb6b12c4f01c4b" @@ -3577,6 +3696,13 @@ get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" +get-stream@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5" + integrity sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w== + dependencies: + pump "^3.0.0" + get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -3662,6 +3788,18 @@ glob@3.2.11: inherits "2" minimatch "0.3" +glob@7.1.3: + version "7.1.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1" + integrity sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + glob@^6.0.1: version "6.0.4" resolved "https://registry.yarnpkg.com/glob/-/glob-6.0.4.tgz#0f08860f6a155127b2fadd4f9ce24b1aab6e4d22" @@ -3775,6 +3913,11 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6, version "1.0.1" resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" +growl@1.10.5: + version "1.10.5" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" + integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== + growl@1.9.2: version "1.9.2" resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" @@ -3833,6 +3976,11 @@ has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" +has-symbols@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.0.tgz#ba1a8f1af2a0fc39650f5c850367704122063b44" + integrity sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q= + has-unicode@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" @@ -3870,6 +4018,13 @@ has@^1.0.1: dependencies: function-bind "^1.0.2" +has@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + hash-base@^2.0.0: version "2.0.2" resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-2.0.2.tgz#66ea1d856db4e8a5470cadf6fce23ae5244ef2e1" @@ -3903,6 +4058,11 @@ he@1.1.x: version "1.1.1" resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd" +he@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" + integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== + history@^4.7.2: version "4.7.2" resolved "https://registry.yarnpkg.com/history/-/history-4.7.2.tgz#22b5c7f31633c5b8021c7f4a8a954ac139ee8d5b" @@ -4190,6 +4350,11 @@ invert-kv@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" +invert-kv@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" + integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== + ip@^1.1.0, ip@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a" @@ -4228,6 +4393,11 @@ is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" +is-buffer@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725" + integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw== + is-builtin-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe" @@ -4238,6 +4408,11 @@ is-callable@^1.1.1, is-callable@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2" +is-callable@^1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75" + integrity sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA== + is-ci@^1.0.10: version "1.1.0" resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.1.0.tgz#247e4162e7860cebbdaf30b774d6b0ac7dcfe7a5" @@ -4448,6 +4623,13 @@ is-symbol@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572" +is-symbol@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.2.tgz#a055f6ae57192caee329e7a860118b497a950f38" + integrity sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw== + dependencies: + has-symbols "^1.0.0" + is-text-path@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/is-text-path/-/is-text-path-1.0.1.tgz#4e1aa0fb51bfbcb3e92688001397202c1775b66e" @@ -4552,6 +4734,14 @@ js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" +js-yaml@3.13.1: + version "3.13.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" + integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + js-yaml@^3.9.0, js-yaml@^3.9.1: version "3.12.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1" @@ -4726,6 +4916,13 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" +lcid@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/lcid/-/lcid-2.0.0.tgz#6ef5d2df60e52f82eb228a4c373e8d1f397253cf" + integrity sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA== + dependencies: + invert-kv "^2.0.0" + left-pad@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.2.0.tgz#d30a73c6b8201d8f7d8e7956ba9616087a68e0ee" @@ -4913,6 +5110,14 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" +locate-path@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e" + integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A== + dependencies: + p-locate "^3.0.0" + path-exists "^3.0.0" + lodash._reinterpolate@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" @@ -4963,6 +5168,13 @@ lodash@^4.17.11: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== +log-symbols@2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a" + integrity sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg== + dependencies: + chalk "^2.0.1" + loglevel@^1.4.1: version "1.6.1" resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.1.tgz#e0fc95133b6ef276cdc8887cdaf24aa6f156f8fa" @@ -5029,6 +5241,13 @@ make-dir@^1.0.0: dependencies: pify "^3.0.0" +map-age-cleaner@^0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a" + integrity sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w== + dependencies: + p-defer "^1.0.0" + map-cache@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" @@ -5075,6 +5294,15 @@ mem@^1.1.0: dependencies: mimic-fn "^1.0.0" +mem@^4.0.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/mem/-/mem-4.3.0.tgz#461af497bc4ae09608cdb2e60eefb69bff744178" + integrity sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w== + dependencies: + map-age-cleaner "^0.1.1" + mimic-fn "^2.0.0" + p-is-promise "^2.0.0" + memoize-one@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-4.0.0.tgz#fc5e2f1427a216676a62ec652cf7398cfad123db" @@ -5186,6 +5414,11 @@ mimic-fn@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" +mimic-fn@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" + integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== + min-document@^2.19.0: version "2.19.0" resolved "https://registry.yarnpkg.com/min-document/-/min-document-2.19.0.tgz#7bd282e3f5842ed295bb748cdd9f1ffa2c824685" @@ -5207,7 +5440,7 @@ minimatch@0.3: lru-cache "2" sigmund "~1.0.0" -"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: +"minimatch@2 || 3", minimatch@3.0.4, minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" dependencies: @@ -5291,6 +5524,35 @@ mocha@^2.5.3: supports-color "1.2.0" to-iso-string "0.0.2" +mocha@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-6.2.0.tgz#f896b642843445d1bb8bca60eabd9206b8916e56" + integrity sha512-qwfFgY+7EKAAUAdv7VYMZQknI7YJSGesxHyhn6qD52DV8UcSZs5XwCifcZGMVIE4a5fbmhvbotxC0DLQ0oKohQ== + dependencies: + ansi-colors "3.2.3" + browser-stdout "1.3.1" + debug "3.2.6" + diff "3.5.0" + escape-string-regexp "1.0.5" + find-up "3.0.0" + glob "7.1.3" + growl "1.10.5" + he "1.2.0" + js-yaml "3.13.1" + log-symbols "2.2.0" + minimatch "3.0.4" + mkdirp "0.5.1" + ms "2.1.1" + node-environment-flags "1.0.5" + object.assign "4.1.0" + strip-json-comments "2.0.1" + supports-color "6.0.0" + which "1.3.1" + wide-align "1.1.3" + yargs "13.2.2" + yargs-parser "13.0.0" + yargs-unparser "1.5.0" + modify-values@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.0.tgz#e2b6cdeb9ce19f99317a53722f3dbf5df5eaaab2" @@ -5318,6 +5580,16 @@ ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" +ms@2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" + integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== + +ms@^2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + multicast-dns-service-types@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/multicast-dns-service-types/-/multicast-dns-service-types-1.1.0.tgz#899f11d9686e5e05cb91b35d5f0e63b773cfc901" @@ -5375,12 +5647,25 @@ negotiator@0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" +nice-try@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" + integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== + no-case@^2.2.0: version "2.3.2" resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac" dependencies: lower-case "^1.1.1" +node-environment-flags@1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/node-environment-flags/-/node-environment-flags-1.0.5.tgz#fa930275f5bf5dae188d6192b24b4c8bbac3d76a" + integrity sha512-VNYPRfGfmZLx0Ye20jWzHUjyTW/c+6Wq+iLhDzUI4XmhrDd9l/FozXV3F2xOaXjvp0co0+v1YSR3CMP6g+VvLQ== + dependencies: + object.getownpropertydescriptors "^2.0.3" + semver "^5.7.0" + node-fetch@^1.0.1: version "1.6.3" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04" @@ -5534,6 +5819,11 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" +object-keys@^1.0.11, object-keys@^1.0.12: + version "1.1.1" + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" + integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== + object-keys@^1.0.6, object-keys@^1.0.8: version "1.0.12" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.12.tgz#09c53855377575310cca62f55bb334abff7b3ed2" @@ -5556,6 +5846,24 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" +object.assign@4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.0.tgz#968bf1100d7956bb3ca086f006f846b3bc4008da" + integrity sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w== + dependencies: + define-properties "^1.1.2" + function-bind "^1.1.1" + has-symbols "^1.0.0" + object-keys "^1.0.11" + +object.getownpropertydescriptors@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16" + integrity sha1-h1jIRvW0B62rDyNuCYbxSwUcqhY= + dependencies: + define-properties "^1.1.2" + es-abstract "^1.5.1" + object.omit@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/object.omit/-/object.omit-2.0.1.tgz#1a9c744829f39dbb858c76ca3579ae2a54ebd1fa" @@ -5651,6 +5959,15 @@ os-locale@^2.0.0: lcid "^1.0.0" mem "^1.1.0" +os-locale@^3.0.0, os-locale@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" + integrity sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q== + dependencies: + execa "^1.0.0" + lcid "^2.0.0" + mem "^4.0.0" + os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" @@ -5670,22 +5987,46 @@ output-file-sync@^1.1.2: mkdirp "^0.5.1" object-assign "^4.1.0" +p-defer@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c" + integrity sha1-n26xgvbJqozXQwBKfU+WsZaw+ww= + p-finally@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" +p-is-promise@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e" + integrity sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg== + p-limit@^1.0.0, p-limit@^1.1.0: version "1.2.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c" dependencies: p-try "^1.0.0" +p-limit@^2.0.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.2.1.tgz#aa07a788cc3151c939b5131f63570f0dd2009537" + integrity sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg== + dependencies: + p-try "^2.0.0" + p-locate@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" dependencies: p-limit "^1.1.0" +p-locate@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" + integrity sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ== + dependencies: + p-limit "^2.0.0" + p-map@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b" @@ -5694,6 +6035,11 @@ p-try@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" +p-try@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" + integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ== + package-json@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed" @@ -5797,7 +6143,7 @@ path-is-inside@^1.0.1, path-is-inside@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" -path-key@^2.0.0: +path-key@^2.0.0, path-key@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" @@ -6288,6 +6634,14 @@ pump@^2.0.0, pump@^2.0.1: end-of-stream "^1.1.0" once "^1.3.1" +pump@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64" + integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww== + dependencies: + end-of-stream "^1.1.0" + once "^1.3.1" + pumpify@^1.3.3: version "1.4.0" resolved "https://registry.yarnpkg.com/pumpify/-/pumpify-1.4.0.tgz#80b7c5df7e24153d03f0e7ac8a05a5d068bd07fb" @@ -6793,6 +7147,11 @@ require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + require-uncached@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" @@ -7051,6 +7410,11 @@ selfsigned@^1.9.1: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" +semver@^5.5.0, semver@^5.7.0: + version "5.7.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" + integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== + semver@~2.3.1: version "2.3.2" resolved "https://registry.yarnpkg.com/semver/-/semver-2.3.2.tgz#b9848f25d6cf36333073ec9ef8856d42f1233e52" @@ -7472,13 +7836,22 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" -string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1: +"string-width@^1.0.2 || 2", string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" dependencies: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +string-width@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" + integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w== + dependencies: + emoji-regex "^7.0.1" + is-fullwidth-code-point "^2.0.0" + strip-ansi "^5.1.0" + string.prototype.padend@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.0.0.tgz#f3aaef7c1719f170c5eab1c32bf780d96e21f2f0" @@ -7519,6 +7892,13 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" +strip-ansi@^5.1.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" + integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== + dependencies: + ansi-regex "^4.1.0" + strip-bom@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-2.0.0.tgz#6219a85616520491f35788bdbf1447a99c7e6b0e" @@ -7539,7 +7919,7 @@ strip-indent@^1.0.1: dependencies: get-stdin "^4.0.1" -strip-json-comments@~2.0.1: +strip-json-comments@2.0.1, strip-json-comments@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" @@ -7564,6 +7944,13 @@ supports-color@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-1.2.0.tgz#ff1ed1e61169d06b3cf2d588e188b18d8847e17e" +supports-color@6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.0.0.tgz#76cfe742cf1f41bb9b1c29ad03068c05b4c0e40a" + integrity sha512-on9Kwidc1IUQo+bQdhi8+Tijpo0e1SS6RoGo2guUwn5vdaxw8RXOF9Vb2ws+ihWOmh4JnCJOvaziZWP1VABaLg== + dependencies: + has-flag "^3.0.0" + supports-color@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" @@ -8261,12 +8648,19 @@ which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" -which@^1.2.9: +which@1.3.1, which@^1.2.9: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" dependencies: isexe "^2.0.0" +wide-align@1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457" + integrity sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA== + dependencies: + string-width "^1.0.2 || 2" + wide-align@^1.1.0: version "1.1.2" resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.2.tgz#571e0f1b0604636ebc0dfc21b0339bbe31341710" @@ -8379,7 +8773,7 @@ y18n@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" -y18n@^4.0.0: +"y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" @@ -8391,6 +8785,30 @@ yaml-js@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/yaml-js/-/yaml-js-0.0.8.tgz#87cfa5a9613f48e26005420d6a8ee0da6fe8daec" +yargs-parser@13.0.0: + version "13.0.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.0.0.tgz#3fc44f3e76a8bdb1cc3602e860108602e5ccde8b" + integrity sha512-w2LXjoL8oRdRQN+hOyppuXs+V/fVAYtpcrRxZuF7Kt/Oc+Jr2uAcVntaUTNT6w5ihoWfFDpNY8CPx1QskxZ/pw== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + +yargs-parser@^11.1.1: + version "11.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4" + integrity sha512-C6kB/WJDiaxONLJQnF8ccx9SEeoTTLek8RVbaOIsrAUS8VrBEXfmeSnCZxygc+XC2sNMBIwOOnfcxiynjHsVSQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + +yargs-parser@^13.0.0: + version "13.1.1" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.1.tgz#d26058532aa06d365fe091f6a1fc06b2f7e5eca0" + integrity sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^4.2.0: version "4.2.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-4.2.1.tgz#29cceac0dc4f03c6c87b4a9f217dd18c9f74871c" @@ -8403,6 +8821,32 @@ yargs-parser@^7.0.0: dependencies: camelcase "^4.1.0" +yargs-unparser@1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/yargs-unparser/-/yargs-unparser-1.5.0.tgz#f2bb2a7e83cbc87bb95c8e572828a06c9add6e0d" + integrity sha512-HK25qidFTCVuj/D1VfNiEndpLIeJN78aqgR23nL3y4N0U/91cOAzqfHlF8n2BvoNDcZmJKin3ddNSvOxSr8flw== + dependencies: + flat "^4.1.0" + lodash "^4.17.11" + yargs "^12.0.5" + +yargs@13.2.2: + version "13.2.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.2.2.tgz#0c101f580ae95cea7f39d927e7770e3fdc97f993" + integrity sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA== + dependencies: + cliui "^4.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" + os-locale "^3.1.0" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.0.0" + yargs@6.6.0: version "6.6.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-6.6.0.tgz#782ec21ef403345f830a808ca3d513af56065208" @@ -8421,6 +8865,24 @@ yargs@6.6.0: y18n "^3.2.1" yargs-parser "^4.2.0" +yargs@^12.0.5: + version "12.0.5" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13" + integrity sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw== + dependencies: + cliui "^4.0.0" + decamelize "^1.2.0" + find-up "^3.0.0" + get-caller-file "^1.0.1" + os-locale "^3.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1 || ^4.0.0" + yargs-parser "^11.1.1" + yargs@^8.0.2: version "8.0.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-8.0.2.tgz#6299a9055b1cefc969ff7e79c1d918dceb22c360" From 37dd7f4a893476ca892af514e7118a0ea52a5abd Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 28 Aug 2019 16:34:39 -0400 Subject: [PATCH 021/165] get rich-text example rendering --- examples/rich-text/index.js | 12 ++--- packages/slate-react-placeholder/src/index.js | 6 +-- packages/slate-react/src/components/editor.js | 3 +- packages/slate-react/src/components/leaf.js | 8 +-- packages/slate-react/src/components/node.js | 6 +-- .../slate-react/src/plugins/dom/before.js | 50 +++++-------------- .../src/plugins/react/rendering.js | 6 +++ packages/slate/src/commands/by-path.js | 2 +- packages/slate/src/commands/on-value.js | 2 +- packages/slate/src/controllers/editor.js | 1 + 10 files changed, 39 insertions(+), 57 deletions(-) diff --git a/examples/rich-text/index.js b/examples/rich-text/index.js index e106a77f9a..38cc3ed167 100644 --- a/examples/rich-text/index.js +++ b/examples/rich-text/index.js @@ -169,7 +169,7 @@ class RichTextExample extends React.Component { * @return {Element} */ - renderBlock = (props, editor, next) => { + renderBlock = (fn, editor) => props => { const { attributes, children, node } = props switch (node.type) { @@ -186,7 +186,7 @@ class RichTextExample extends React.Component { case 'numbered-list': return
    {children}
default: - return next() + return fn(props) } } @@ -197,7 +197,7 @@ class RichTextExample extends React.Component { * @return {Element} */ - renderMark = (props, editor, next) => { + renderMark = (fn, editor) => props => { const { children, mark, attributes } = props switch (mark.type) { @@ -210,7 +210,7 @@ class RichTextExample extends React.Component { case 'underlined': return {children} default: - return next() + return fn(props) } } @@ -232,7 +232,7 @@ class RichTextExample extends React.Component { * @return {Change} */ - onKeyDown = (event, editor, next) => { + onKeyDown = (fn, editor) => event => { let mark if (isBoldHotkey(event)) { @@ -244,7 +244,7 @@ class RichTextExample extends React.Component { } else if (isCodeHotkey(event)) { mark = 'code' } else { - return next() + return fn(event) } event.preventDefault() diff --git a/packages/slate-react-placeholder/src/index.js b/packages/slate-react-placeholder/src/index.js index efa89d082c..e83b2d71ab 100644 --- a/packages/slate-react-placeholder/src/index.js +++ b/packages/slate-react-placeholder/src/index.js @@ -24,8 +24,8 @@ function SlateReactPlaceholder(options = {}) { ) invariant( - typeof when === 'string' || typeof when === 'function', - 'You must pass `SlateReactPlaceholder` an `options.when` query.' + typeof when === 'function', + 'You must pass `SlateReactPlaceholder` an `options.when` matching function.' ) /** @@ -40,7 +40,7 @@ function SlateReactPlaceholder(options = {}) { const decorateNode = (fn, editor) => node => { const others = fn(node) - if (!editor.query(when, node)) { + if (!when(editor, node)) { return others } diff --git a/packages/slate-react/src/components/editor.js b/packages/slate-react/src/components/editor.js index a090697995..48a48452bc 100644 --- a/packages/slate-react/src/components/editor.js +++ b/packages/slate-react/src/components/editor.js @@ -110,7 +110,7 @@ class Editor extends React.Component { this.tmp.updates++ if (this.props.autoFocus) { - this.focus() + this.exec('focus') } if (this.tmp.change) { @@ -234,6 +234,7 @@ class Editor extends React.Component { ) this.tmp.resolves++ + const react = TheReactPlugin({ ...this.props, editor: this, diff --git a/packages/slate-react/src/components/leaf.js b/packages/slate-react/src/components/leaf.js index c8693b9624..71ff8ef940 100644 --- a/packages/slate-react/src/components/leaf.js +++ b/packages/slate-react/src/components/leaf.js @@ -73,7 +73,7 @@ const Leaf = props => { let children - if (editor.query('isVoid', parent)) { + if (editor.exec('isVoid', parent)) { // COMPAT: Render text inside void nodes with a zero-width space. // So the node can contain selection but the text is not visible. children = @@ -121,7 +121,7 @@ const Leaf = props => { // in certain misbehaving browsers they aren't weirdly cloned/destroyed by // contenteditable behaviors. (2019/05/08) for (const mark of marks) { - const ret = editor.run('renderMark', { + const ret = editor.exec('renderMark', { ...renderProps, mark, children, @@ -136,7 +136,7 @@ const Leaf = props => { } for (const decoration of decorations) { - const ret = editor.run('renderDecoration', { + const ret = editor.exec('renderDecoration', { ...renderProps, decoration, children, @@ -151,7 +151,7 @@ const Leaf = props => { } for (const annotation of annotations) { - const ret = editor.run('renderAnnotation', { + const ret = editor.exec('renderAnnotation', { ...renderProps, annotation, children, diff --git a/packages/slate-react/src/components/node.js b/packages/slate-react/src/components/node.js index 1840c18225..bb0015e67b 100644 --- a/packages/slate-react/src/components/node.js +++ b/packages/slate-react/src/components/node.js @@ -84,7 +84,7 @@ class Node extends React.Component { shouldComponentUpdate(nextProps) { const { props } = this const { editor } = props - const shouldUpdate = editor.run( + const shouldUpdate = editor.exec( 'shouldNodeComponentUpdate', props, nextProps @@ -234,7 +234,7 @@ class Node extends React.Component { render = 'renderInline' } - const element = editor.run(render, { + const element = editor.exec(render, { attributes, children, editor, @@ -245,7 +245,7 @@ class Node extends React.Component { readOnly, }) - return editor.isVoid(node) ? ( + return editor.exec('isVoid', node) ? ( { diff --git a/packages/slate-react/src/plugins/dom/before.js b/packages/slate-react/src/plugins/dom/before.js index cb72d3fccb..ef7f4078f4 100644 --- a/packages/slate-react/src/plugins/dom/before.js +++ b/packages/slate-react/src/plugins/dom/before.js @@ -35,8 +35,6 @@ function BeforePlugin() { * On before input. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onBeforeInput = (fn, editor) => event => { @@ -56,8 +54,6 @@ function BeforePlugin() { * On blur. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onBlur = (fn, editor) => event => { @@ -105,8 +101,6 @@ function BeforePlugin() { * On composition end. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onCompositionEnd = (fn, editor) => event => { @@ -128,8 +122,6 @@ function BeforePlugin() { * On click. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onClick = (fn, editor) => event => { @@ -141,8 +133,6 @@ function BeforePlugin() { * On composition start. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onCompositionStart = (fn, editor) => event => { @@ -171,8 +161,6 @@ function BeforePlugin() { * On copy. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onCopy = (fn, editor) => event => { @@ -188,8 +176,6 @@ function BeforePlugin() { * On cut. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onCut = (fn, editor) => event => { @@ -207,8 +193,6 @@ function BeforePlugin() { * On drag end. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onDragEnd = (fn, editor) => event => { @@ -221,8 +205,6 @@ function BeforePlugin() { * On drag enter. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onDragEnter = (fn, editor) => event => { @@ -234,8 +216,6 @@ function BeforePlugin() { * On drag exit. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onDragExit = (fn, editor) => event => { @@ -247,8 +227,6 @@ function BeforePlugin() { * On drag leave. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onDragLeave = (fn, editor) => event => { @@ -260,8 +238,6 @@ function BeforePlugin() { * On drag over. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onDragOver = (fn, editor) => event => { @@ -302,8 +278,6 @@ function BeforePlugin() { * On drag start. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onDragStart = (fn, editor) => event => { @@ -316,8 +290,6 @@ function BeforePlugin() { * On drop. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onDrop = (fn, editor) => event => { @@ -334,8 +306,6 @@ function BeforePlugin() { * On focus. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onFocus = (fn, editor) => event => { @@ -364,8 +334,6 @@ function BeforePlugin() { * On input. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onInput = (fn, editor) => event => { @@ -379,8 +347,6 @@ function BeforePlugin() { * On key down. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onKeyDown = (fn, editor) => event => { @@ -419,12 +385,21 @@ function BeforePlugin() { fn(event) } + /** + * On key up. + * + * @param {Event} event + */ + + const onKeyUp = (fn, editor) => event => { + debug('onKeyUp', { event }) + fn(event) + } + /** * On paste. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onPaste = (fn, editor) => event => { @@ -441,8 +416,6 @@ function BeforePlugin() { * On select. * * @param {Event} event - * @param {Editor} editor - * @param {Function} next */ const onSelect = (fn, editor) => event => { @@ -483,6 +456,7 @@ function BeforePlugin() { onFocus, onInput, onKeyDown, + onKeyUp, onPaste, onSelect, } diff --git a/packages/slate-react/src/plugins/react/rendering.js b/packages/slate-react/src/plugins/react/rendering.js index 90277a1b72..13b29f53cd 100644 --- a/packages/slate-react/src/plugins/react/rendering.js +++ b/packages/slate-react/src/plugins/react/rendering.js @@ -47,6 +47,12 @@ function Rendering() { renderMark: () => ({ attributes, children }) => { return {children} }, + + onRender: () => () => {}, + onComponentDidMount: () => () => {}, + onComponentDidUpdate: () => () => {}, + onComponentWillUnmount: () => () => {}, + shouldNodeComponentUpdate: () => () => {}, } } diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index ba6d5f41af..5d4f754e71 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -81,7 +81,7 @@ Commands.addMarksByPath = (fn, editor) => (path, offset, length, marks) => { * @param {Array} marks */ -Commands.replaceMarksByPath = (editor, path, offset, length, marks) => { +Commands.replaceMarksByPath = (fn, editor) => (path, offset, length, marks) => { const marksSet = Mark.createSet(marks) const { value } = editor diff --git a/packages/slate/src/commands/on-value.js b/packages/slate/src/commands/on-value.js index ef5d208975..01f1672f43 100644 --- a/packages/slate/src/commands/on-value.js +++ b/packages/slate/src/commands/on-value.js @@ -57,7 +57,7 @@ Commands.setAnnotation = (fn, editor) => (annotation, newProperties) => { }) } -Commands.setAnnotations = (editor, annotations = []) => { +Commands.setAnnotations = (fn, editor) => (annotations = []) => { const { value } = editor const newProperties = Value.createProperties({ annotations }) const prevProperties = pick(value, Object.keys(newProperties)) diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index 97fba704d6..9f9aa6b012 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -686,6 +686,7 @@ function registerHandler(editor, controller, name, fn) { const existing = editor.handlers[name] || noop editor.handlers[name] = fn(existing, controller) editor[name] = editor[name] || ((...args) => editor.exec(name, ...args)) + controller[name] = editor[name] } function noop() {} From 76bde0e2d4f8e70f3dedf617c5baa80c727f847d Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 28 Aug 2019 17:23:43 -0400 Subject: [PATCH 022/165] fix lint --- packages/slate/src/models/value.js | 326 ++++++++++++------------- packages/slate/src/operations/apply.js | 1 - 2 files changed, 151 insertions(+), 176 deletions(-) diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index e5857cfe26..b81ca776d8 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -124,346 +124,322 @@ class Value extends Record(DEFAULTS) { } /** - * Get the current start text node's closest block parent. + * Return a JSON representation of the value. * - * @return {Block} + * @param {Object} options + * @return {Object} + */ + + toJSON(options = {}) { + const object = { + object: this.object, + document: this.document.toJSON(options), + } + + if (options.preserveData) { + object.data = this.data.toJSON(options) + } + + if (options.preserveAnnotations) { + object.annotations = this.annotations + .map(a => a.toJSON(options)) + .toObject() + } + + if (options.preserveSelection) { + object.selection = this.selection.toJSON(options) + } + + return object + } + + /** + * Deprecated. */ get startBlock() { + warning( + false, + 'As of slate@0.48, the `value.startBlock` property is depreacted. Use `document.closestBlock()` instead.' + ) + return ( this.selection.start.path && this.document.getClosestBlock(this.selection.start.path) ) } - /** - * Get the current end text node's closest block parent. - * - * @return {Block} - */ - get endBlock() { + warning( + false, + 'As of slate@0.48, the `value.endBlock` property is depreacted. Use `document.closestBlock()` instead.' + ) + return ( this.selection.end.path && this.document.getClosestBlock(this.selection.end.path) ) } - /** - * Get the current anchor text node's closest block parent. - * - * @return {Block} - */ - get anchorBlock() { + warning( + false, + 'As of slate@0.48, the `value.anchorBlock` property is depreacted. Use `document.closestBlock()` instead.' + ) + return ( this.selection.anchor.path && this.document.getClosestBlock(this.selection.anchor.path) ) } - /** - * Get the current focus text node's closest block parent. - * - * @return {Block} - */ - get focusBlock() { + warning( + false, + 'As of slate@0.48, the `value.focusBlock` property is depreacted. Use `document.closestBlock()` instead.' + ) + return ( this.selection.focus.path && this.document.getClosestBlock(this.selection.focus.path) ) } - /** - * Get the current start text node's closest inline parent. - * - * @return {Inline} - */ - get startInline() { + warning( + false, + 'As of slate@0.48, the `value.startInline` property is depreacted. Use `document.closestInline()` instead.' + ) + return ( this.selection.start.path && this.document.getClosestInline(this.selection.start.path) ) } - /** - * Get the current end text node's closest inline parent. - * - * @return {Inline} - */ - get endInline() { + warning( + false, + 'As of slate@0.48, the `value.endInline` property is depreacted. Use `document.closestInline()` instead.' + ) + return ( this.selection.end.path && this.document.getClosestInline(this.selection.end.path) ) } - /** - * Get the current anchor text node's closest inline parent. - * - * @return {Inline} - */ - get anchorInline() { + warning( + false, + 'As of slate@0.48, the `value.anchorInline` property is depreacted. Use `document.closestInline()` instead.' + ) + return ( this.selection.anchor.path && this.document.getClosestInline(this.selection.anchor.path) ) } - /** - * Get the current focus text node's closest inline parent. - * - * @return {Inline} - */ - get focusInline() { + warning( + false, + 'As of slate@0.48, the `value.focusInline` property is depreacted. Use `document.closestInline()` instead.' + ) + return ( this.selection.focus.path && this.document.getClosestInline(this.selection.focus.path) ) } - /** - * Get the current start text node. - * - * @return {Text} - */ - get startText() { + warning( + false, + 'As of slate@0.48, the `value.startText` property is depreacted. Use `document.getNode()` instead.' + ) + return ( this.selection.start.path && this.document.getDescendant(this.selection.start.path) ) } - /** - * Get the current end node. - * - * @return {Text} - */ - get endText() { + warning( + false, + 'As of slate@0.48, the `value.endText` property is depreacted. Use `document.getNode()` instead.' + ) + return ( this.selection.end.path && this.document.getDescendant(this.selection.end.path) ) } - /** - * Get the current anchor node. - * - * @return {Text} - */ - get anchorText() { + warning( + false, + 'As of slate@0.48, the `value.anchorText` property is depreacted. Use `document.getNode()` instead.' + ) + return ( this.selection.anchor.path && this.document.getDescendant(this.selection.anchor.path) ) } - /** - * Get the current focus node. - * - * @return {Text} - */ - get focusText() { + warning( + false, + 'As of slate@0.48, the `value.focusText` property is depreacted. Use `document.getNode()` instead.' + ) + return ( this.selection.focus.path && this.document.getDescendant(this.selection.focus.path) ) } - /** - * Get the next block node. - * - * @return {Block} - */ - get nextBlock() { + warning( + false, + 'As of slate@0.48, the `value.nextBlock` property is depreacted. Use `document.nextBlock()` instead.' + ) + return ( this.selection.end.path && this.document.getNextBlock(this.selection.end.path) ) } - /** - * Get the previous block node. - * - * @return {Block} - */ - get previousBlock() { + warning( + false, + 'As of slate@0.48, the `value.previousBlock` property is depreacted. Use `document.previousBlock()` instead.' + ) + return ( this.selection.start.path && this.document.getPreviousBlock(this.selection.start.path) ) } - /** - * Get the next inline node. - * - * @return {Inline} - */ - get nextInline() { + warning( + false, + 'As of slate@0.48, the `value.nextInline` property is depreacted. Use `document.nextInline()` instead.' + ) + return ( this.selection.end.path && this.document.getNextInline(this.selection.end.path) ) } - /** - * Get the previous inline node. - * - * @return {Inline} - */ - get previousInline() { + warning( + false, + 'As of slate@0.48, the `value.previousInline` property is depreacted. Use `document.previousInline()` instead.' + ) + return ( this.selection.start.path && this.document.getPreviousInline(this.selection.start.path) ) } - /** - * Get the next text node. - * - * @return {Text} - */ - get nextText() { + warning( + false, + 'As of slate@0.48, the `value.nextText` property is depreacted. Use `document.nextText()` instead.' + ) + return ( this.selection.end.path && this.document.getNextText(this.selection.end.path) ) } - /** - * Get the previous text node. - * - * @return {Text} - */ - get previousText() { + warning( + false, + 'As of slate@0.48, the `value.previousText` property is depreacted. Use `document.previousText()` instead.' + ) + return ( this.selection.start.path && this.document.getPreviousText(this.selection.start.path) ) } - /** - * Get the marks of the current selection. - * - * @return {Set} - */ - get marks() { + warning( + false, + 'As of slate@0.48, the `value.marks` property is depreacted. Use `document.marks()` instead.' + ) + return this.selection.isUnset ? new Set() : this.selection.marks || this.document.getMarksAtRange(this.selection) } - /** - * Get the active marks of the current selection. - * - * @return {Set} - */ - get activeMarks() { + warning( + false, + 'As of slate@0.48, the `value.activeMarks` property is depreacted. Use `document.getActiveMarksAtRange()` instead.' + ) + return this.selection.isUnset ? new Set() : this.selection.marks || this.document.getActiveMarksAtRange(this.selection) } - /** - * Get the block nodes in the current selection. - * - * @return {List} - */ - get blocks() { + warning( + false, + 'As of slate@0.48, the `value.blocks` property is depreacted. Use `document.blocks()` instead.' + ) + return this.selection.isUnset ? new List() : this.document.getLeafBlocksAtRange(this.selection) } - /** - * Get the fragment of the current selection. - * - * @return {Document} - */ - get fragment() { + warning( + false, + 'As of slate@0.48, the `value.fragment` property is depreacted. Use `document.getFragmentAtRange()` instead.' + ) + return this.selection.isUnset ? Document.create() : this.document.getFragmentAtRange(this.selection) } - /** - * Get the bottom-most inline nodes in the current selection. - * - * @return {List} - */ - get inlines() { + warning( + false, + 'As of slate@0.48, the `value.inline` property is depreacted. Use `document.inline()` instead.' + ) + return this.selection.isUnset ? new List() : this.document.getLeafInlinesAtRange(this.selection) } - /** - * Get the text nodes in the current selection. - * - * @return {List} - */ - get texts() { + warning( + false, + 'As of slate@0.48, the `value.texts` property is depreacted. Use `document.texts()` instead.' + ) + return this.selection.isUnset ? new List() : this.document.getTextsAtRange(this.selection) } - /** - * Return a JSON representation of the value. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - document: this.document.toJSON(options), - } - - if (options.preserveData) { - object.data = this.data.toJSON(options) - } - - if (options.preserveAnnotations) { - object.annotations = this.annotations - .map(a => a.toJSON(options)) - .toObject() - } - - if (options.preserveSelection) { - object.selection = this.selection.toJSON(options) - } - - return object - } - - /** - * Deprecated. - */ - mapRanges(iterator) { warning( false, @@ -781,7 +757,7 @@ class Value extends Record(DEFAULTS) { annotation = Annotation.create(annotation) let value = this - let { annotations } = value + let { annotations, document } = value const { key } = annotation annotation = annotation.updatePoints(point => point.normalize(document)) annotations = annotations.set(key, annotation) diff --git a/packages/slate/src/operations/apply.js b/packages/slate/src/operations/apply.js index 76ae39d7ca..0d247014d9 100644 --- a/packages/slate/src/operations/apply.js +++ b/packages/slate/src/operations/apply.js @@ -1,7 +1,6 @@ import Debug from 'debug' import Annotation from '../models/annotation' -import Node from '../models/node' import Operation from '../models/operation' import Mark from '../models/mark' import PathUtils from '../utils/path-utils' From 91c04ded412c66b656e92b1dd74ed7ad470198c7 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 29 Aug 2019 09:47:22 -0400 Subject: [PATCH 023/165] refactor query files, fix more tests --- packages/slate/src/commands/with-intent.js | 10 +- .../slate/src/plugins/core/core-queries.js | 489 +----------------- packages/slate/src/queries/creators.js | 5 + packages/slate/src/queries/format.js | 10 + packages/slate/src/queries/node.js | 10 + packages/slate/src/queries/path.js | 78 +++ packages/slate/src/queries/point.js | 342 ++++++++++++ packages/slate/src/queries/range.js | 53 ++ .../delete-backward-at-range/from-offset.js | 13 +- .../text-end-with-marks.js | 8 +- .../text-start-with-marks.js | 8 +- .../by-path/replace-text-by-path/with-mark.js | 4 +- .../slate/test/history/undo/toggle-mark.js | 6 +- 13 files changed, 537 insertions(+), 499 deletions(-) create mode 100644 packages/slate/src/queries/creators.js create mode 100644 packages/slate/src/queries/format.js create mode 100644 packages/slate/src/queries/node.js create mode 100644 packages/slate/src/queries/path.js create mode 100644 packages/slate/src/queries/point.js create mode 100644 packages/slate/src/queries/range.js diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js index 06ff237ad7..00e6af9bdc 100644 --- a/packages/slate/src/commands/with-intent.js +++ b/packages/slate/src/commands/with-intent.js @@ -1,3 +1,5 @@ +import { Set } from 'immutable' + import Block from '../models/block' import Inline from '../models/inline' import Mark from '../models/mark' @@ -382,10 +384,12 @@ Commands.splitInline = (fn, editor) => height => { Commands.toggleMark = (fn, editor) => mark => { mark = Mark.create(mark) - const { value } = editor - const exists = value.activeMarks.has(mark) + const { value: { document, selection } } = editor + const activeMarks = selection.isUnset + ? new Set() + : selection.marks || document.getActiveMarksAtRange(selection) - if (exists) { + if (activeMarks.has(mark)) { editor.removeMark(mark) } else { editor.addMark(mark) diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index b5089cf8fa..66fb359e7b 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -1,487 +1,24 @@ -import Range from '../../models/range' -import PathUtils from '../../utils/path-utils' -import TextUtils from '../../utils/text-utils' +import * as Creators from '../../queries/creators' +import * as Format from '../../queries/format' +import * as Node from '../../queries/node' +import * as Path from '../../queries/path' +import * as Point from '../../queries/point' +import * as Range from '../../queries/range' /** - * A plugin that defines the core Slate query logic. + * A plugin that defines the core Slate queries. * * @return {Object} */ function CoreQueriesPlugin() { return { - /** - * Check whether a `format` is atomic, defaults to false. - * - * @param {Annotation|Decoration|Mark} format - * @return {Boolean} - */ - - isAtomic: (fn, editor) => () => { - return false - }, - - /** - * Check whether a `range` is hanging. - * - * @param {Range} range - * @return {Boolean} - */ - - isHanging: (fn, editor) => range => { - const { isExpanded, start, end } = range - return isExpanded && end.offset === 0 && !start.path.equals(end.path) - }, - - isHangingBlock: (fn, editor) => range => { - const { value: { document } } = editor - const { isExpanded, start, end } = range - const [, endBlockPath] = document.closestBlock(end.path) - const [, firstTextPath] = document.firstText({ path: endBlockPath }) - - return ( - isExpanded && - end.offset === 0 && - !start.path.equals(end.path) && - end.path.equals(firstTextPath) - ) - }, - - isAtStartOfBlock: (fn, editor) => point => { - const { value: { document } } = editor - const [, blockPath] = document.closestBlock(point.path) - const [, firstTextPath] = document.firstText({ path: blockPath }) - return point.offset === 0 && point.path.equals(firstTextPath) - }, - - isAtStartOfPath: (fn, editor) => (point, path) => { - const { value: { document } } = editor - const [, firstPath] = document.firstText({ path }) - return point.offset === 0 && point.path.equals(firstPath) - }, - - isAtEndOfPath: (fn, editor) => (point, path) => { - const { value: { document } } = editor - const [firstNode, firstPath] = document.firstText({ path }) - return ( - point.offset === firstNode.text.length && point.path.equals(firstPath) - ) - }, - - isAtEdgeOfPath: (fn, editor) => (point, path) => { - return ( - editor.isAtStartOfPath(point, path) || editor.isAtEndOfPath(point, path) - ) - }, - - getPointAtStartOfPath: (fn, editor) => path => { - const { value: { document } } = editor - const [, firstPath] = document.firstText({ path }) - const point = document.createPoint({ path: firstPath, offset: 0 }) - return point - }, - - getPointAtEndOfPath: (fn, editor) => path => { - const { value: { document } } = editor - const [lastNode, lastPath] = document.lastText({ path }) - const point = document.createPoint({ - path: lastPath, - offset: lastNode.text.length, - }) - - return point - }, - - getRangeAtEndOfPath: (fn, editor) => path => { - const { value: { document } } = editor - const point = editor.getPointAtEndOfPath(path) - const range = document.createRange({ anchor: point, focus: point }) - return range - }, - - createPoint: (fn, editor) => props => { - const { value: { document } } = editor - const point = document.createPoint(props) - return point - }, - - /** - * Check whether a `node` is void, defaults to false. - * - * @param {Node} node - * @return {Boolean} - */ - - isVoid: (fn, editor) => () => { - return false - }, - - getFirstPoint: (fn, editor) => path => { - const { value: { document } } = editor - const [firstText, firstPath] = document.firstText({ path }) - const firstPoint = document.createPoint({ - key: firstText.key, - path: firstPath, - offset: 0, - }) - - return firstPoint - }, - - getLastPoint: (fn, editor) => path => { - const { value: { document } } = editor - const [lastText, lastPath] = document.lastText({ path }) - const lastPoint = document.createPoint({ - key: lastText.key, - path: lastPath, - offset: lastText.text.length, - }) - - return lastPoint - }, - - getRange: (fn, editor) => path => { - const anchor = editor.getFirstPoint(path) - const focus = editor.getLastPoint(path) - const range = Range.create({ anchor, focus }) - return range - }, - - /** - * Calculate the next point forward from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - - getNextPoint: (fn, editor) => (point, options = {}) => { - const { allowZeroWidth = false } = options - const { value } = editor - const { document } = value - const { path, offset } = point - const closestBlock = document.closestBlock(path) - const closestVoid = document.closest(path, editor.isVoid) - const node = document.getNode(path) - - // PERF: if we're not in a void and we have offset to gain, do it easily. - if (!closestVoid && offset < node.text.length) { - const next = point.setOffset(offset + 1) - return next.normalize(document) - } - - for (const [nextNode, nextPath] of document.texts({ path })) { - // If we're still inside the void node, keep going until we exit it. - if (closestVoid) { - const [, voidPath] = closestVoid - - if (!PathUtils.isAfter(nextPath, voidPath)) { - continue - } - } - - // If we're no longer inside the original block node, we don't want to - // add an extra `1` to the offset, since we've changed blocks. Instead - // we move right to the start of the block. - if (closestBlock) { - const [, blockPath] = closestBlock - - if (PathUtils.isAfter(nextPath, blockPath)) { - const next = point.moveTo(nextPath, 0) - return next.normalize(document) - } - } - - // If the point is now inside a new void node, no matter if the void - // node is zero-width, we still count it as a new point. - const nextClosestVoid = document.closest(nextPath, editor.isVoid) - - // If the text node and we're still in the same block, continue onwards - // because we need to have moved one point forwards, and an empty text - // will be perceived as not moving. - if (nextNode.text.length === 0) { - if (nextClosestVoid || allowZeroWidth) { - const next = point.moveTo(nextPath, 0) - return next.normalize(document) - } else { - continue - } - } - - const next = point.moveTo(nextPath, 1) - return next.normalize(document) - } - - return null - }, - - /** - * Calculate the next character boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - - getNextCharacterPoint: (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - const blockText = block.getText() - - if (blockOffset + offset === blockText.length) { - return editor.getNextPoint(point) - } - - const o = blockOffset + offset - const n = TextUtils.getCharOffsetForward(blockText, o) - let next = point - - for (let i = 0; i < n; i++) { - next = editor.getNextPoint(next) - - if (!next) { - break - } - } - - return next - }, - - /** - * Get the next point in the document that is not inside a void node. - * - * @param {Point} point - * @return {Point|Null} - */ - - getNextNonVoidPoint: (fn, editor) => point => { - const { value: { document } } = editor - let next = point - - while (next) { - const closestVoid = document.closest(next.path, editor.isVoid) - - if (closestVoid) { - next = editor.getNextPoint(next, { allowZeroWidth: true }) - } else { - return next - } - } - }, - - /** - * Calculate the next word boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - - getNextWordPoint: (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - const blockText = block.getText() - - if (blockOffset + offset === blockText.length) { - return editor.getNextPoint(point) - } - - const o = blockOffset + offset - const n = TextUtils.getWordOffsetForward(blockText, o) - let next = point - - for (let i = 0; i < n; i++) { - next = editor.getNextPoint(next) - - if (!next) { - break - } - } - - return next - }, - - /** - * Calculate a non-hanging range from a `range`. - * - * @param {Range} range - * @return {Range} - */ - - getNonHangingRange: (fn, editor) => range => { - const { value: { document } } = editor - const { end } = range - - if (editor.isHanging(range)) { - const [prevText, prevPath] = document.previousText(end.path) - const newEnd = end.moveTo(prevPath, prevText.text.length) - const nonHanging = range.setEnd(newEnd).normalize(document) - return nonHanging - } else { - return range - } - }, - - /** - * Calculate the previous point backward from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - - getPreviousPoint: (fn, editor) => (point, options = {}) => { - const { allowZeroWidth = false } = options - const { value } = editor - const { document } = value - const { path, offset } = point - const closestBlock = document.closestBlock(path) - const closestVoid = document.closest(path, editor.isVoid) - - // PERF: if we're not in a void and we have offset to lose, do it easily. - if (!closestVoid && offset > 0) { - const prev = point.setOffset(offset - 1) - return prev.normalize(document) - } - - const iterable = document.texts({ path, direction: 'backward' }) - - for (const [prevNode, prevPath] of iterable) { - // If we're still inside the void node, keep going until we exit it. - if (closestVoid) { - const [, voidPath] = closestVoid - - if (!PathUtils.isBefore(prevPath, voidPath)) { - continue - } - } - - // If we're no longer inside the original block node, we don't want to - // remove an extra `1` from the offset, since we've changed blocks. - // Instead we move right to the end of the block. - if (closestBlock) { - const [, blockPath] = closestBlock - - if (PathUtils.isBefore(prevPath, blockPath)) { - const prev = point.moveTo(prevPath, prevNode.text.length) - return prev.normalize(document) - } - } - - // If the point is now inside a new void node, no matter if the void - // node is zero-width, we still count it as a new point. - const prevClosestVoid = document.closest(prevPath, editor.isVoid) - - // If the text node and we're still in the same block, continue onwards - // because we need to have moved one point backwards, and an empty text - // will be perceived as not moving. - if (prevNode.text.length === 0) { - if (prevClosestVoid || allowZeroWidth) { - const prev = point.moveTo(prevPath, 0) - return prev.normalize(document) - } else { - continue - } - } - - const prev = point.moveTo(prevPath, prevNode.text.length - 1) - return prev.normalize(document) - } - - return null - }, - - /** - * Calculate the previous character boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - - getPreviousCharacterPoint: (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - - if (blockOffset + offset === 0) { - return editor.getPreviousPoint(point) - } - - const blockText = block.getText() - const o = blockOffset + offset - const n = TextUtils.getCharOffsetBackward(blockText, o) - let prev = point - - for (let i = 0; i < n; i++) { - prev = editor.getPreviousPoint(prev) - - if (!prev) { - break - } - } - - return prev - }, - - /** - * Get the previous point in the document that is not inside a void node. - * - * @param {Point} point - * @return {Point|Null} - */ - - getPreviousNonVoidPoint: (fn, editor) => point => { - const { value: { document } } = editor - let prev = point - - while (prev) { - const closestVoid = document.closest(prev.path, editor.isVoid) - - if (closestVoid) { - prev = editor.getPreviousPoint(prev, { allowZeroWidth: true }) - } else { - return prev - } - } - }, - - /** - * Calculate the previous word boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - - getPreviousWordPoint: (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - - if (blockOffset + offset === 0) { - return editor.getPreviousPoint(point) - } - - const blockText = block.getText() - const o = blockOffset + offset - const n = TextUtils.getWordOffsetBackward(blockText, o) - let prev = point - - for (let i = 0; i < n; i++) { - prev = editor.getPreviousPoint(prev) - - if (!prev) { - break - } - } - - return prev - }, + ...Creators, + ...Format, + ...Node, + ...Path, + ...Point, + ...Range, } } diff --git a/packages/slate/src/queries/creators.js b/packages/slate/src/queries/creators.js new file mode 100644 index 0000000000..cac3cd9539 --- /dev/null +++ b/packages/slate/src/queries/creators.js @@ -0,0 +1,5 @@ +export const createPoint = (fn, editor) => props => { + const { value: { document } } = editor + const point = document.createPoint(props) + return point +} diff --git a/packages/slate/src/queries/format.js b/packages/slate/src/queries/format.js new file mode 100644 index 0000000000..89bc173e71 --- /dev/null +++ b/packages/slate/src/queries/format.js @@ -0,0 +1,10 @@ +/** + * Check whether a `format` is atomic, defaults to false. + * + * @param {Annotation|Decoration|Mark} format + * @return {Boolean} + */ + +export const isAtomic = (fn, editor) => () => { + return false +} diff --git a/packages/slate/src/queries/node.js b/packages/slate/src/queries/node.js new file mode 100644 index 0000000000..14c20f325e --- /dev/null +++ b/packages/slate/src/queries/node.js @@ -0,0 +1,10 @@ +/** + * Check whether a `node` is void, defaults to false. + * + * @param {Node} node + * @return {Boolean} + */ + +export const isVoid = (fn, editor) => node => { + return false +} diff --git a/packages/slate/src/queries/path.js b/packages/slate/src/queries/path.js new file mode 100644 index 0000000000..f5bf4e3eee --- /dev/null +++ b/packages/slate/src/queries/path.js @@ -0,0 +1,78 @@ +import { Range } from '..' + +/** + * Get the start point at a `path`. + * + * @param {Path} path + * @return {Point} + */ + +export const getPointAtStartOfPath = (fn, editor) => path => { + const { value: { document } } = editor + const [, firstPath] = document.firstText({ path }) + const point = document.createPoint({ path: firstPath, offset: 0 }) + return point +} + +/** + * Get the end point at a `path`. + * + * @param {Path} path + * @return {Point} + */ + +export const getPointAtEndOfPath = (fn, editor) => path => { + const { value: { document } } = editor + const [lastNode, lastPath] = document.lastText({ path }) + const point = document.createPoint({ + path: lastPath, + offset: lastNode.text.length, + }) + + return point +} + +/** + * Get a range at the end of a `path`. + * + * @param {Path} path + * @return {Point} + */ + +export const getRangeAtEndOfPath = (fn, editor) => path => { + const { value: { document } } = editor + const point = editor.getPointAtEndOfPath(path) + const range = document.createRange({ anchor: point, focus: point }) + return range +} + +export const getFirstPoint = (fn, editor) => path => { + const { value: { document } } = editor + const [firstText, firstPath] = document.firstText({ path }) + const firstPoint = document.createPoint({ + key: firstText.key, + path: firstPath, + offset: 0, + }) + + return firstPoint +} + +export const getLastPoint = (fn, editor) => path => { + const { value: { document } } = editor + const [lastText, lastPath] = document.lastText({ path }) + const lastPoint = document.createPoint({ + key: lastText.key, + path: lastPath, + offset: lastText.text.length, + }) + + return lastPoint +} + +export const getRange = (fn, editor) => path => { + const anchor = editor.getFirstPoint(path) + const focus = editor.getLastPoint(path) + const range = Range.create({ anchor, focus }) + return range +} diff --git a/packages/slate/src/queries/point.js b/packages/slate/src/queries/point.js new file mode 100644 index 0000000000..641a610ee0 --- /dev/null +++ b/packages/slate/src/queries/point.js @@ -0,0 +1,342 @@ +import PathUtils from '../utils/path-utils' +import TextUtils from '../utils/text-utils' + +export const isAtStartOfBlock = (fn, editor) => point => { + const { value: { document } } = editor + const [, blockPath] = document.closestBlock(point.path) + const [, firstTextPath] = document.firstText({ path: blockPath }) + return point.offset === 0 && point.path.equals(firstTextPath) +} + +export const isAtStartOfPath = (fn, editor) => (point, path) => { + const { value: { document } } = editor + const [, firstPath] = document.firstText({ path }) + return point.offset === 0 && point.path.equals(firstPath) +} + +export const isAtEndOfPath = (fn, editor) => (point, path) => { + const { value: { document } } = editor + const [firstNode, firstPath] = document.firstText({ path }) + return point.offset === firstNode.text.length && point.path.equals(firstPath) +} + +export const isAtEdgeOfPath = (fn, editor) => (point, path) => { + return ( + editor.isAtStartOfPath(point, path) || editor.isAtEndOfPath(point, path) + ) +} + +/** + * Calculate the next point forward from a `point`. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getNextPoint = (fn, editor) => (point, options = {}) => { + const { allowZeroWidth = false } = options + const { value } = editor + const { document } = value + const { path, offset } = point + const closestBlock = document.closestBlock(path) + const closestVoid = document.closest(path, editor.isVoid) + const node = document.getNode(path) + + // PERF: if we're not in a void and we have offset to gain, do it easily. + if (!closestVoid && offset < node.text.length) { + const next = point.setOffset(offset + 1) + return next.normalize(document) + } + + for (const [nextNode, nextPath] of document.texts({ path })) { + // If we're still inside the void node, keep going until we exit it. + if (closestVoid) { + const [, voidPath] = closestVoid + + if (!PathUtils.isAfter(nextPath, voidPath)) { + continue + } + } + + // If we're no longer inside the original block node, we don't want to + // add an extra `1` to the offset, since we've changed blocks. Instead + // we move right to the start of the block. + if (closestBlock) { + const [, blockPath] = closestBlock + + if (PathUtils.isAfter(nextPath, blockPath)) { + const next = point.moveTo(nextPath, 0) + return next.normalize(document) + } + } + + // If the point is now inside a new void node, no matter if the void + // node is zero-width, we still count it as a new point. + const nextClosestVoid = document.closest(nextPath, editor.isVoid) + + // If the text node and we're still in the same block, continue onwards + // because we need to have moved one point forwards, and an empty text + // will be perceived as not moving. + if (nextNode.text.length === 0) { + if (nextClosestVoid || allowZeroWidth) { + const next = point.moveTo(nextPath, 0) + return next.normalize(document) + } else { + continue + } + } + + const next = point.moveTo(nextPath, 1) + return next.normalize(document) + } + + return null +} + +/** + * Calculate the next character boundary from a `point`. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getNextCharacterPoint = (fn, editor) => point => { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + const blockText = block.getText() + + if (blockOffset + offset === blockText.length) { + return editor.getNextPoint(point) + } + + const o = blockOffset + offset + const n = TextUtils.getCharOffsetForward(blockText, o) + let next = point + + for (let i = 0; i < n; i++) { + next = editor.getNextPoint(next) + + if (!next) { + break + } + } + + return next +} + +/** + * Get the next point in the document that is not inside a void node. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getNextNonVoidPoint = (fn, editor) => point => { + const { value: { document } } = editor + let next = point + + while (next) { + const closestVoid = document.closest(next.path, editor.isVoid) + + if (closestVoid) { + next = editor.getNextPoint(next, { allowZeroWidth: true }) + } else { + return next + } + } +} + +/** + * Calculate the next word boundary from a `point`. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getNextWordPoint = (fn, editor) => point => { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + const blockText = block.getText() + + if (blockOffset + offset === blockText.length) { + return editor.getNextPoint(point) + } + + const o = blockOffset + offset + const n = TextUtils.getWordOffsetForward(blockText, o) + let next = point + + for (let i = 0; i < n; i++) { + next = editor.getNextPoint(next) + + if (!next) { + break + } + } + + return next +} + +/** + * Calculate the previous point backward from a `point`. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getPreviousPoint = (fn, editor) => (point, options = {}) => { + const { allowZeroWidth = false } = options + const { value } = editor + const { document } = value + const { path, offset } = point + const closestBlock = document.closestBlock(path) + const closestVoid = document.closest(path, editor.isVoid) + + // PERF: if we're not in a void and we have offset to lose, do it easily. + if (!closestVoid && offset > 0) { + const prev = point.setOffset(offset - 1) + return prev.normalize(document) + } + + const iterable = document.texts({ path, direction: 'backward' }) + + for (const [prevNode, prevPath] of iterable) { + // If we're still inside the void node, keep going until we exit it. + if (closestVoid) { + const [, voidPath] = closestVoid + + if (!PathUtils.isBefore(prevPath, voidPath)) { + continue + } + } + + // If we're no longer inside the original block node, we don't want to + // remove an extra `1` from the offset, since we've changed blocks. + // Instead we move right to the end of the block. + if (closestBlock) { + const [, blockPath] = closestBlock + + if (PathUtils.isBefore(prevPath, blockPath)) { + const prev = point.moveTo(prevPath, prevNode.text.length) + return prev.normalize(document) + } + } + + // If the point is now inside a new void node, no matter if the void + // node is zero-width, we still count it as a new point. + const prevClosestVoid = document.closest(prevPath, editor.isVoid) + + // If the text node and we're still in the same block, continue onwards + // because we need to have moved one point backwards, and an empty text + // will be perceived as not moving. + if (prevNode.text.length === 0) { + if (prevClosestVoid || allowZeroWidth) { + const prev = point.moveTo(prevPath, 0) + return prev.normalize(document) + } else { + continue + } + } + + const prev = point.moveTo(prevPath, prevNode.text.length - 1) + return prev.normalize(document) + } + + return null +} + +/** + * Calculate the previous character boundary from a `point`. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getPreviousCharacterPoint = (fn, editor) => point => { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + + if (blockOffset + offset === 0) { + return editor.getPreviousPoint(point) + } + + const blockText = block.getText() + const o = blockOffset + offset + const n = TextUtils.getCharOffsetBackward(blockText, o) + let prev = point + + for (let i = 0; i < n; i++) { + prev = editor.getPreviousPoint(prev) + + if (!prev) { + break + } + } + + return prev +} + +/** + * Get the previous point in the document that is not inside a void node. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getPreviousNonVoidPoint = (fn, editor) => point => { + const { value: { document } } = editor + let prev = point + + while (prev) { + const closestVoid = document.closest(prev.path, editor.isVoid) + + if (closestVoid) { + prev = editor.getPreviousPoint(prev, { allowZeroWidth: true }) + } else { + return prev + } + } +} + +/** + * Calculate the previous word boundary from a `point`. + * + * @param {Point} point + * @return {Point|Null} + */ + +export const getPreviousWordPoint = (fn, editor) => point => { + const { value: { document } } = editor + const { path, offset } = point + const [block, blockPath] = document.closestBlock(path) + const relativePath = path.slice(blockPath.size) + const blockOffset = block.getOffset(relativePath) + + if (blockOffset + offset === 0) { + return editor.getPreviousPoint(point) + } + + const blockText = block.getText() + const o = blockOffset + offset + const n = TextUtils.getWordOffsetBackward(blockText, o) + let prev = point + + for (let i = 0; i < n; i++) { + prev = editor.getPreviousPoint(prev) + + if (!prev) { + break + } + } + + return prev +} diff --git a/packages/slate/src/queries/range.js b/packages/slate/src/queries/range.js new file mode 100644 index 0000000000..42cf1d2f73 --- /dev/null +++ b/packages/slate/src/queries/range.js @@ -0,0 +1,53 @@ +/** + * Check whether a `range` is hanging. + * + * @param {Range} range + * @return {Boolean} + */ + +export const isHanging = (fn, editor) => range => { + const { isExpanded, start, end } = range + return isExpanded && end.offset === 0 && !start.path.equals(end.path) +} + +/** + * Check whether a `range` is hanging in a block. + * + * @param {Range} range + * @return {Boolean} + */ + +export const isHangingBlock = (fn, editor) => range => { + const { value: { document } } = editor + const { isExpanded, start, end } = range + const [, endBlockPath] = document.closestBlock(end.path) + const [, firstTextPath] = document.firstText({ path: endBlockPath }) + + return ( + isExpanded && + end.offset === 0 && + !start.path.equals(end.path) && + end.path.equals(firstTextPath) + ) +} + +/** + * Calculate a non-hanging range from a `range`. + * + * @param {Range} range + * @return {Range} + */ + +export const getNonHangingRange = (fn, editor) => range => { + const { value: { document } } = editor + const { end } = range + + if (editor.isHanging(range)) { + const [prevText, prevPath] = document.previousText(end.path) + const newEnd = end.moveTo(prevPath, prevText.text.length) + const nonHanging = range.setEnd(newEnd).normalize(document) + return nonHanging + } else { + return range + } +} diff --git a/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js b/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js index c6a3704e4e..611f4e8179 100644 --- a/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js +++ b/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js @@ -5,11 +5,10 @@ import { Point, Range } from 'slate' import h from '../../../helpers/h' export default function(editor) { - const { key } = editor.value.document.getFirstText() - const range = new Range({ - anchor: new Point({ key, offset: 2, path: [key] }), - focus: new Point({ key, offset: 2, path: [key] }), - }) + const { value: { document } } = editor + const [firstText, firstPath] = document.firstText() + const point = Point.create({ key: firstText.key, offset: 2, path: firstPath }) + const range = Range.create({ anchor: point, focus: point }) editor.deleteBackwardAtRange(range, 2) } @@ -18,7 +17,7 @@ export const input = ( - Sample Text + onetwo @@ -30,7 +29,7 @@ export const output = ( - mple Text + etwo diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js index 2820e8a150..6152576771 100644 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js @@ -10,9 +10,9 @@ export const input = ( - + word - + @@ -23,8 +23,8 @@ export const output = ( - wordx - + word + x diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js index 039fabe31e..90199e16c5 100644 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js +++ b/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js @@ -10,9 +10,9 @@ export const input = ( - + word - + @@ -22,8 +22,8 @@ export const output = ( - - aword + a + word diff --git a/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js b/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js index dcfdc236fc..ea9888b7b8 100644 --- a/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js +++ b/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js @@ -24,9 +24,7 @@ export const output = ( one - - three - + three wo diff --git a/packages/slate/test/history/undo/toggle-mark.js b/packages/slate/test/history/undo/toggle-mark.js index ac08ecf5c5..74d446dc30 100644 --- a/packages/slate/test/history/undo/toggle-mark.js +++ b/packages/slate/test/history/undo/toggle-mark.js @@ -4,8 +4,10 @@ import h from '../../helpers/h' export default function(editor) { editor.addMark('bold') - editor.flush().removeMark('bold') - editor.flush().undo() + editor.flush() + editor.removeMark('bold') + editor.flush() + editor.undo() } export const input = ( From 1d27e3275b5831a3da6d63444d615e763ccd5097 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 29 Aug 2019 10:05:43 -0400 Subject: [PATCH 024/165] remove unused queries, refactor others --- packages/slate/src/commands/at-range.js | 46 ++----------------- packages/slate/src/commands/by-path.js | 4 +- .../slate/src/plugins/core/core-queries.js | 2 - packages/slate/src/queries/creators.js | 5 -- packages/slate/src/queries/path.js | 45 +++--------------- 5 files changed, 12 insertions(+), 90 deletions(-) delete mode 100644 packages/slate/src/queries/creators.js diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 42388f8bbd..3163373f02 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -443,46 +443,6 @@ Commands.insertBlockAtRange = (fn, editor) => (range, block) => { * @param {Document} fragment */ -Commands.getBackwardMostPoint = (fn, editor) => point => { - if (point.offset === 0) { - return point - } else { - return editor.getPreviousPoint(point, { allowZeroWidth: true }) - } -} - -Commands.getForwardMostPoint = (fn, editor) => point => { - const { value: { document } } = editor - const node = document.getNode(point.path) - - if (point.offset === node.text.length) { - return point - } else { - return editor.getNextPoint(point, { allowZeroWidth: true }) - } -} - -Commands.getInnerMostRange = (fn, editor) => range => { - const start = editor.getForwardMostPoint(range.start) - const end = editor.getBackwardMostPoint(range.end) - return range.setPoints([start, end]) -} - -Commands.ensureSplitBlockAtRange = (fn, editor) => range => { - const { value: { document } } = editor - const { isExpanded, start, end } = range - const [, startBlockPath] = document.closestBlock(start.path) - const [, endBlockPath] = document.closestBlock(end.path) - - // if (!editor.isAtEdgeOfPath(end, endBlockPath)) { - editor.splitDescendantsByPath(endBlockPath, end.path, end.offset) - // } - - if (isExpanded && !editor.isAtEdgeOfPath(start, startBlockPath)) { - editor.splitDescendantsByPath(startBlockPath, start.path, start.offset) - } -} - Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { let startPointRef let endPointRef @@ -507,9 +467,9 @@ Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { const afterPath = afterPathRef.path const endPath = Path.decrement(afterPath) - const startPoint = editor.getPointAtStartOfPath(startPath) - const endPoint = editor.getPointAtEndOfPath(endPath) - const afterPoint = editor.getPointAtStartOfPath(afterPath) + const startPoint = editor.getStartOfPath(startPath) + const endPoint = editor.getEndOfPath(endPath) + const afterPoint = editor.getStartOfPath(afterPath) startPointRef = editor.createPointRef(startPoint) endPointRef = editor.createPointRef(endPoint) editor.mergeBlockByPath(afterPoint.path) diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index 5d4f754e71..9684b2e2e4 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -736,7 +736,7 @@ Commands.splitDescendantsByPath = (fn, editor) => ( Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { path = Path.create(path) - const range = editor.getRange(path) + const range = editor.getRangeOfPath(path) editor.unwrapInlineAtRange(range, properties) } @@ -749,7 +749,7 @@ Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { Commands.unwrapBlockByPath = (fn, editor) => (path, properties) => { path = Path.create(path) - const range = editor.getRange(path) + const range = editor.getRangeOfPath(path) editor.unwrapBlockAtRange(range, properties) } diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js index 66fb359e7b..878cb4022d 100644 --- a/packages/slate/src/plugins/core/core-queries.js +++ b/packages/slate/src/plugins/core/core-queries.js @@ -1,4 +1,3 @@ -import * as Creators from '../../queries/creators' import * as Format from '../../queries/format' import * as Node from '../../queries/node' import * as Path from '../../queries/path' @@ -13,7 +12,6 @@ import * as Range from '../../queries/range' function CoreQueriesPlugin() { return { - ...Creators, ...Format, ...Node, ...Path, diff --git a/packages/slate/src/queries/creators.js b/packages/slate/src/queries/creators.js deleted file mode 100644 index cac3cd9539..0000000000 --- a/packages/slate/src/queries/creators.js +++ /dev/null @@ -1,5 +0,0 @@ -export const createPoint = (fn, editor) => props => { - const { value: { document } } = editor - const point = document.createPoint(props) - return point -} diff --git a/packages/slate/src/queries/path.js b/packages/slate/src/queries/path.js index f5bf4e3eee..f598c63b2d 100644 --- a/packages/slate/src/queries/path.js +++ b/packages/slate/src/queries/path.js @@ -7,7 +7,7 @@ import { Range } from '..' * @return {Point} */ -export const getPointAtStartOfPath = (fn, editor) => path => { +export const getStartOfPath = (fn, editor) => path => { const { value: { document } } = editor const [, firstPath] = document.firstText({ path }) const point = document.createPoint({ path: firstPath, offset: 0 }) @@ -21,7 +21,7 @@ export const getPointAtStartOfPath = (fn, editor) => path => { * @return {Point} */ -export const getPointAtEndOfPath = (fn, editor) => path => { +export const getEndOfPath = (fn, editor) => path => { const { value: { document } } = editor const [lastNode, lastPath] = document.lastText({ path }) const point = document.createPoint({ @@ -33,46 +33,15 @@ export const getPointAtEndOfPath = (fn, editor) => path => { } /** - * Get a range at the end of a `path`. + * Get the range of a node at `path`. * * @param {Path} path - * @return {Point} + * @return {Range} */ -export const getRangeAtEndOfPath = (fn, editor) => path => { - const { value: { document } } = editor - const point = editor.getPointAtEndOfPath(path) - const range = document.createRange({ anchor: point, focus: point }) - return range -} - -export const getFirstPoint = (fn, editor) => path => { - const { value: { document } } = editor - const [firstText, firstPath] = document.firstText({ path }) - const firstPoint = document.createPoint({ - key: firstText.key, - path: firstPath, - offset: 0, - }) - - return firstPoint -} - -export const getLastPoint = (fn, editor) => path => { - const { value: { document } } = editor - const [lastText, lastPath] = document.lastText({ path }) - const lastPoint = document.createPoint({ - key: lastText.key, - path: lastPath, - offset: lastText.text.length, - }) - - return lastPoint -} - -export const getRange = (fn, editor) => path => { - const anchor = editor.getFirstPoint(path) - const focus = editor.getLastPoint(path) +export const getRangeOfPath = (fn, editor) => path => { + const anchor = editor.getStartOfPath(path) + const focus = editor.getEndOfPath(path) const range = Range.create({ anchor, focus }) return range } From 8bf36cee0fd33c0ca9b328cff433235f40f0d9b1 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 29 Aug 2019 10:34:50 -0400 Subject: [PATCH 025/165] deprecate splitDescendantsByPath --- packages/slate/src/commands/at-point.js | 48 ++++++++++++++- packages/slate/src/commands/at-range.js | 23 +++----- packages/slate/src/commands/by-path.js | 5 ++ packages/slate/src/plugins/commands/index.js | 57 ------------------ packages/slate/src/plugins/queries/index.js | 58 ------------------- .../block-with-selection.js | 8 ++- .../split-node-at-point}/block.js | 8 ++- 7 files changed, 71 insertions(+), 136 deletions(-) delete mode 100644 packages/slate/src/plugins/commands/index.js delete mode 100644 packages/slate/src/plugins/queries/index.js rename packages/slate/test/commands/{by-path/split-descendants-by-path => at-point/split-node-at-point}/block-with-selection.js (70%) rename packages/slate/test/commands/{by-path/split-descendants-by-path => at-point/split-node-at-point}/block.js (63%) diff --git a/packages/slate/src/commands/at-point.js b/packages/slate/src/commands/at-point.js index b7061e8bff..4368eb200c 100644 --- a/packages/slate/src/commands/at-point.js +++ b/packages/slate/src/commands/at-point.js @@ -1,3 +1,5 @@ +import Path from '../utils/path-utils' + /** * Commands. * @@ -6,6 +8,50 @@ const Commands = {} +/** + * Split at a `point` and up to a `parentPath`. + * + * @param {Point} point + * @param {Path} path + */ + +Commands.splitNodeAtPoint = (fn, editor) => (point, parentPath) => { + parentPath = Path.create(parentPath) + + editor.withoutNormalizing(() => { + const { value: { document } } = editor + const { path, offset } = point + editor.splitNodeByPath(path, offset) + + // If the parent path is the same as the text node, we're done. + if (parentPath.equals(path)) { + return + } + + let position = offset + let prevPath = path + + // Iterate up the ancestors, splitting each node until `parentPath` is met. + for (const [, ancestorPath] of document.ancestors(path)) { + const target = position + position = prevPath.last() + 1 + prevPath = ancestorPath + editor.splitNodeByPath(ancestorPath, position, { target }) + + if (ancestorPath.equals(parentPath)) { + break + } + } + }) +} + +/** + * Split at a `point` and up to blocks of `height`. + * + * @param {Point} point + * @param {number} height + */ + Commands.splitBlockAtPoint = (fn, editor) => (point, height = 1) => { editor.withoutNormalizing(() => { const { value: { document } } = editor @@ -22,7 +68,7 @@ Commands.splitBlockAtPoint = (fn, editor) => (point, height = 1) => { } if (blockPath) { - editor.splitDescendantsByPath(blockPath, point.path, point.offset) + editor.splitNodeAtPoint(point, blockPath) } }) } diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 3163373f02..3102084ecf 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -153,21 +153,21 @@ Commands.deleteAtRange = (fn, editor) => range => { // Don't split yet, since we're too high up. } else if (splitEnd && splitStart) { const newPath = Path.increment(path) - editor.splitDescendantsByPath(path, end.path, end.offset) - editor.splitDescendantsByPath(path, start.path, start.offset) + editor.splitNodeAtPoint(end, path) + editor.splitNodeAtPoint(start, path) editor.removeNodeByPath(newPath) } else if ( splitEnd || (isAtEnd && !splitStart && endBlock.nodes.size === 1) ) { - editor.splitDescendantsByPath(path, end.path, end.offset) + editor.splitNodeAtPoint(end, path) editor.removeNodeByPath(path) } else if ( splitStart || (isAtStart && !splitEnd && startBlock.nodes.size === 1) ) { const newPath = Path.increment(path) - editor.splitDescendantsByPath(path, start.path, start.offset) + editor.splitNodeAtPoint(start, path) editor.removeNodeByPath(newPath) } else if ( isAtStart || @@ -419,12 +419,7 @@ Commands.insertBlockAtRange = (fn, editor) => (range, block) => { editor.getNextNonVoidPoint(start) || editor.getPreviousNonVoidPoint(start) - editor.splitDescendantsByPath( - closestBlockPath, - splitPoint.path, - splitPoint.offset - ) - + editor.splitNodeAtPoint(splitPoint, closestBlockPath) targetPath = Path.increment(closestBlockPath) } @@ -648,7 +643,7 @@ Commands.splitBlockAtRange = (fn, editor) => (range, height = 1) => { } if (targetPath) { - editor.splitDescendantsByPath(targetPath, start.path, start.offset) + editor.splitNodeAtPoint(start, targetPath) } }) } @@ -678,7 +673,7 @@ Commands.splitInlineAtRange = (fn, editor) => (range, height = Infinity) => { } if (targetPath) { - editor.splitDescendantsByPath(targetPath, start.path, start.offset) + editor.splitNodeAtPoint(start, targetPath) } }) } @@ -702,7 +697,7 @@ Commands.splitInlineEdgesAtRange = (fn, editor) => range => { end.offset !== lastText.text.length || !relativePath.equals(lastPath) ) { - editor.splitDescendantsByPath(furthestPath, end.path, end.offset) + editor.splitNodeAtPoint(end, furthestPath) } } else if (end.offset !== 0 && end.offset !== endText.text.length) { editor.splitNodeByPath(end.path, end.offset) @@ -720,7 +715,7 @@ Commands.splitInlineEdgesAtRange = (fn, editor) => range => { const relativePath = start.path.slice(furthestPath.size) if (start.offset !== 0 || !relativePath.equals(firstPath)) { - editor.splitDescendantsByPath(furthestPath, start.path, start.offset) + editor.splitNodeAtPoint(start, furthestPath) if ( Path.isYounger(furthestPath, end.path) || diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js index 9684b2e2e4..d6ee945acd 100644 --- a/packages/slate/src/commands/by-path.js +++ b/packages/slate/src/commands/by-path.js @@ -699,6 +699,11 @@ Commands.splitDescendantsByPath = (fn, editor) => ( textPath, textOffset ) => { + warning( + false, + 'As of slate@0.48, the `editor.splitDescendantsByPath` command is deprecated. Use `editor.splitNodeAtPoint` instead.' + ) + path = Path.create(path) textPath = Path.create(textPath) diff --git a/packages/slate/src/plugins/commands/index.js b/packages/slate/src/plugins/commands/index.js deleted file mode 100644 index b6d2b252ff..0000000000 --- a/packages/slate/src/plugins/commands/index.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * A plugin that adds a set of commands to the editor. - * - * @param {Object} commands - * @return {Object} - */ - -function CommandsPlugin(commands = {}) { - /** - * On command, if it exists in our list of commands, call it. - * - * @param {Object} command - * @param {Editor} editor - * @param {Function} next - */ - - function onCommand(command, editor, next) { - const { type, args } = command - const fn = commands[type] - if (!fn) return next() - editor.command(fn, ...args) - } - - /** - * On construct, register all the commands. - * - * @param {Editor} editor - * @param {Function} next - */ - - function onConstruct(editor, next) { - for (const command in commands) { - editor.registerCommand(command) - } - - return next() - } - - /** - * Return the plugin. - * - * @type {Object} - */ - - return { - onCommand, - onConstruct, - } -} - -/** - * Export. - * - * @type {Object} - */ - -export default CommandsPlugin diff --git a/packages/slate/src/plugins/queries/index.js b/packages/slate/src/plugins/queries/index.js deleted file mode 100644 index a6e31ea7df..0000000000 --- a/packages/slate/src/plugins/queries/index.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * A plugin that adds a set of queries to the editor. - * - * @param {Object} queries - * @return {Object} - */ - -function QueriesPlugin(queries = {}) { - /** - * On construct, register all the queries. - * - * @param {Editor} editor - * @param {Function} next - */ - - function onConstruct(editor, next) { - for (const query in queries) { - editor.registerQuery(query) - } - - return next() - } - - /** - * On query, if it exists in our list of queries, call it. - * - * @param {Object} query - * @param {Editor} editor - * @param {Function} next - */ - - function onQuery(query, editor, next) { - const { type, args } = query - const fn = queries[type] - if (!fn) return next() - const ret = fn(editor, ...args) - return ret === undefined ? next() : ret - } - - /** - * Return the plugin. - * - * @type {Object} - */ - - return { - onConstruct, - onQuery, - } -} - -/** - * Export. - * - * @type {Object} - */ - -export default QueriesPlugin diff --git a/packages/slate/test/commands/by-path/split-descendants-by-path/block-with-selection.js b/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js similarity index 70% rename from packages/slate/test/commands/by-path/split-descendants-by-path/block-with-selection.js rename to packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js index a84d0bb410..68e1a616d2 100644 --- a/packages/slate/test/commands/by-path/split-descendants-by-path/block-with-selection.js +++ b/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js @@ -3,14 +3,16 @@ import h from '../../../helpers/h' export default function(editor) { - editor.splitDescendantsByPath([0], [0, 0], 2) + const { value: { document } } = editor + const point = document.createPoint({ path: [0, 0], offset: 2 }) + editor.splitNodeAtPoint(point, [0]) } export const input = ( - - + + word diff --git a/packages/slate/test/commands/by-path/split-descendants-by-path/block.js b/packages/slate/test/commands/at-point/split-node-at-point/block.js similarity index 63% rename from packages/slate/test/commands/by-path/split-descendants-by-path/block.js rename to packages/slate/test/commands/at-point/split-node-at-point/block.js index 20796f1672..4bd836d9b2 100644 --- a/packages/slate/test/commands/by-path/split-descendants-by-path/block.js +++ b/packages/slate/test/commands/at-point/split-node-at-point/block.js @@ -3,14 +3,16 @@ import h from '../../../helpers/h' export default function(editor) { - editor.splitDescendantsByPath([0], [0, 0], 2) + const { value: { document } } = editor + const point = document.createPoint({ path: [0, 0], offset: 2 }) + editor.splitNodeAtPoint(point, [0]) } export const input = ( - - word + + word From 129b7f86a4fbec6ec725b8eb0bb9e4e57b5d8b53 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 11 Oct 2019 16:29:33 -0400 Subject: [PATCH 026/165] merge master --- docs/general/resources.md | 2 + docs/guides/commands-and-queries.md | 2 +- docs/guides/data-model.md | 2 +- docs/guides/plugins.md | 2 +- docs/reference/slate-react/plugins.md | 1 + docs/reference/slate/commands.md | 16 +- docs/reference/slate/node.md | 2 +- docs/reference/slate/range.md | 6 +- docs/reference/slate/text.md | 2 +- examples/app.js | 2 +- examples/embeds/video.js | 34 +++- examples/emojis/index.js | 16 +- examples/emojis/value.json | 11 ++ packages/slate-react/package.json | 2 +- .../slate-react/src/components/content.js | 111 ++++++++--- packages/slate-react/src/plugins/dom/after.js | 50 ++--- .../slate-react/src/plugins/dom/before.js | 21 ++ .../slate-react/src/utils/clone-fragment.js | 11 +- packages/slate-react/src/utils/find-point.js | 6 +- packages/slate/src/commands/on-selection.js | 31 ++- packages/slate/src/utils/text-utils.js | 186 +++++++++++++++++- .../insert-fragment/flat-blocks/end-block.js | 35 ++++ .../hanging-selection-mixed-types.js | 43 ++++ .../flat-blocks/start-block.js | 35 ++++ .../between-texts-into-middle-block.js | 35 ++++ .../insert-fragment/inlines/middle-block.js | 41 ++++ .../insert-fragment/inlines/middle-inline.js | 39 ++++ .../insert-fragment/lists/merge-lists.js | 43 ++++ .../insert-fragment/marks/middle-block.js | 41 ++++ .../marks/multiple-marks-middle-block.js | 41 ++++ .../insert-fragment/merge-deep-nested.js | 2 + .../end-block.js | 42 ++++ .../middle-block-nested.js | 41 ++++ .../middle-block.js | 41 ++++ .../start-block.js | 43 ++++ .../end-block-nested.js | 51 +++++ .../start-block.js | 40 ++++ .../tables/merge-cells-with-nested-blocks.js | 71 +++++++ .../tables/merge-into-empty-cells.js | 56 ++++++ .../tables/merge-into-full-cells.js | 57 ++++++ .../words/adjacent-texts-after-void.js | 38 ++++ .../words/adjacent-texts-end-first-block.js | 37 ++++ .../words/adjacent-texts-into-empty-block.js | 34 ++++ .../insert-fragment/words/after-inline.js | 33 ++++ .../insert-fragment/words/before-inline.js | 33 ++++ .../insert-fragment/words/end-block.js | 31 +++ .../insert-fragment/words/end-inline.js | 37 ++++ .../insert-fragment/words/middle-block.js | 31 +++ .../insert-fragment/words/middle-inline.js | 36 ++++ .../insert-fragment/words/start-block.js | 31 +++ .../words/start-second-block.js | 33 ++++ .../words/with-delete-across-blocks.js | 34 ++++ packages/slate/test/helpers/h.js | 4 + 53 files changed, 1618 insertions(+), 107 deletions(-) create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js create mode 100644 packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js diff --git a/docs/general/resources.md b/docs/general/resources.md index b8c4775924..8a8802520b 100644 --- a/docs/general/resources.md +++ b/docs/general/resources.md @@ -20,6 +20,7 @@ These tools are helpful when developing with Slate: These products use Slate, and can give you an idea of what's possible: * [Cake](https://www.cake.co/) +* [Archbee](https://archbee.io) * [Chatterbug](https://chatterbug.com) * [GitBook](https://www.gitbook.com/) * [Grafana](https://grafana.com/) @@ -31,6 +32,7 @@ These products use Slate, and can give you an idea of what's possible: * [Sanity.io](https://www.sanity.io) * [Taskade](https://www.taskade.com/) * [Yuque](https://www.yuque.com/) +* [Thoughts](https://thoughts.teambition.com) ## Editors diff --git a/docs/guides/commands-and-queries.md b/docs/guides/commands-and-queries.md index 684848d7a3..e7e56a5095 100644 --- a/docs/guides/commands-and-queries.md +++ b/docs/guides/commands-and-queries.md @@ -55,7 +55,7 @@ There are a handful of different categories of commands that ship with Slate by ### At a Specific Range -These are commands like `deleteAtRange()`, `addMarkAtArange()`, `unwrapBlockAtRange()`, etc. that take in a [`Range`](../reference/slate/range.md) argument and apply a change to the document for all of the content in that range. These aren't used that often, because you'll usually be able to get away with using the next category of commands instead... +These are commands like `deleteAtRange()`, `addMarkAtRange()`, `unwrapBlockAtRange()`, etc. that take in a [`Range`](../reference/slate/range.md) argument and apply a change to the document for all of the content in that range. These aren't used that often, because you'll usually be able to get away with using the next category of commands instead... ### At the Current Selection diff --git a/docs/guides/data-model.md b/docs/guides/data-model.md index 07045608e0..c9ceaf3f92 100644 --- a/docs/guides/data-model.md +++ b/docs/guides/data-model.md @@ -83,7 +83,7 @@ Unlike the DOM, Slate offers some constraints to prevent "impossible" situations * **Documents must have block nodes as direct children.** This constraint mirrors how rich-text editors work. The top-most elements are blocks that may be split when pressing Enter. -* **Blocks may contain either other block nodes, or inlines and text nodes.** This constraint helps you avoid boilerplate `if` statements. You can trust blocks either wrap other blocks, or contain actual content. +* **Blocks may contain either only block nodes, or a combination of inline and text nodes.** This constraint helps you avoid boilerplate `if` statements. You can trust blocks either wrap (a) exclusively blocks, or (b) a combination of non-block nodes made up of inline and/or text nodes. * **Inlines can only contain inline or text nodes.** This constraint helps you avoid boilerplate code. When working within the context of an inline you can trust the contents do not contain blocks. diff --git a/docs/guides/plugins.md b/docs/guides/plugins.md index 21bf9dcf30..0c71110bc3 100644 --- a/docs/guides/plugins.md +++ b/docs/guides/plugins.md @@ -68,7 +68,7 @@ These are behaviors that all rich-text editors exhibit, and that don't make sens For the most part you don't need to worry about the core plugins. -_To learn more, check out the [Core Plugin reference](../reference/slate-react/core-plugins.md)._ +_To learn more, check out the [Core Plugin reference](../reference/slate/plugins.md)._ ## The "Editor" Plugin diff --git a/docs/reference/slate-react/plugins.md b/docs/reference/slate-react/plugins.md index 2fbadf1ae8..2828d6fcc0 100644 --- a/docs/reference/slate-react/plugins.md +++ b/docs/reference/slate-react/plugins.md @@ -19,6 +19,7 @@ In addition to the [core plugin hooks](../slate/plugins.md), when using `slate-r onFocus: Function, onKeyDown: Function, onKeyUp: Function, + onMouseUp: Function, onPaste: Function, onSelect: Function, renderEditor: Function, diff --git a/docs/reference/slate/commands.md b/docs/reference/slate/commands.md index cf1a748ee7..879ec4cb1f 100644 --- a/docs/reference/slate/commands.md +++ b/docs/reference/slate/commands.md @@ -12,7 +12,7 @@ These commands act on the `document` based on the current `selection`. They are `addMark(properties: Object) => Editor`
`addMark(type: String) => Editor` -Add a [`mark`](./mark.md) to the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. +Add a [`Mark`](./mark.md) to the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `delete` @@ -91,7 +91,7 @@ Split the [`Inline`](./inline.md) node in the current selection by `depth` level `removeMark(properties: Object) => Editor`
`removeMark(type: String) => Editor` -Remove a [`mark`](./mark.md) from the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. +Remove a [`Mark`](./mark.md) from the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `replaceMark` @@ -99,7 +99,7 @@ Remove a [`mark`](./mark.md) from the characters in the current selection. For c `replaceMark(oldProperties: Object, newProperties: Object) => Editor`
`replaceMark(oldType: String, newType: String) => Editor` -Replace a [`mark`](./mark.md) in the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. +Replace a [`Mark`](./mark.md) in the characters in the current selection. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `toggleMark` @@ -107,7 +107,7 @@ Replace a [`mark`](./mark.md) in the characters in the current selection. For co `toggleMark(properties: Object) => Editor`
`toggleMark(type: String) => Editor` -Add or remove a [`mark`](./mark.md) from the characters in the current selection, depending on it already exists on any or not. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. +Add or remove a [`Mark`](./mark.md) from the characters in the current selection, depending on it already exists on any or not. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `unwrapBlock` @@ -273,7 +273,7 @@ These commands act on a specific [`Range`](./range.md) of the document. `addMarkAtRange(range: Range, properties: Object) => Editor`
`addMarkAtRange(range: Range, type: String) => Editor` -Add a [`mark`](./mark.md) to the characters in a `range`. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. +Add a [`Mark`](./mark.md) to the characters in a `range`. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `deleteAtRange` @@ -352,7 +352,7 @@ Split the [`Inline`](./inline.md) node in a `range` by `depth` levels. If the se `removeMarkAtRange(range: Range, properties: Object) => Editor`
`removeMarkAtRange(range: Range, type: String) => Editor` -Remove a [`mark`](./mark.md) from the characters in a `range`. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. +Remove a [`Mark`](./mark.md) from the characters in a `range`. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `toggleMarkAtRange` @@ -360,7 +360,7 @@ Remove a [`mark`](./mark.md) from the characters in a `range`. For convenience, `toggleMarkAtRange(range: Range, properties: Object) => Editor`
`toggleMarkAtRange(range: Range, type: String) => Editor` -Add or remove a [`mark`](./mark.md) from the characters in a `range`, depending on whether any of them already have the mark. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. +Add or remove a [`Mark`](./mark.md) from the characters in a `range`, depending on whether any of them already have the mark. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `unwrapBlockAtRange` @@ -475,7 +475,7 @@ Remove `length` characters of text starting at an `offset` in a [`Node`](./node. `setMarkByKey(key: String, offset: Number, length: Number, properties: Object, newProperties: Object) => Editor` `setMarkByPath(path: List, offset: Number, length: Number, properties: Object, newProperties: Object) => Editor` -Set a dictionary of `newProperties` on a [`mark`](./mark.md) on a [`Node`](./node.md) by its `key` or `path`. +Set a dictionary of `newProperties` on a [`Mark`](./mark.md) on a [`Node`](./node.md) by its `key` or `path`. ### `setNodeByKey/Path` diff --git a/docs/reference/slate/node.md b/docs/reference/slate/node.md index b628e91a57..0926ffd50a 100644 --- a/docs/reference/slate/node.md +++ b/docs/reference/slate/node.md @@ -334,7 +334,7 @@ Get the direction of the text content in the node. ### `getTexts` -`getTexts(range: Range) => List` +`getTexts() => List` Get all of the [`Text`](./text.md) nodes in a node. diff --git a/docs/reference/slate/range.md b/docs/reference/slate/range.md index 746f73cbf3..ce01c1dcad 100644 --- a/docs/reference/slate/range.md +++ b/docs/reference/slate/range.md @@ -151,7 +151,7 @@ Move the `{Point}` of the range to a new `key`, `path` and `offset`. The `{Point Move the `{Point}` to the end of a `node`. The `{Point}` can be one of: `Anchor`, `Focus`, `Start`, `End`, or ommited to move both the `anchor` and `focus` point at once. -> 🤖 This method may need to be followed by `point.normalize(document)`, like [`move{Point}To`](#movepointto). +> 🤖 This method may need to be followed by `range.normalize(document)`, like [`move{Point}To`](#movepointto). ### `move{Point}ToStartOfNode` @@ -159,7 +159,7 @@ Move the `{Point}` to the end of a `node`. The `{Point}` can be one of: `Anchor` Move the `{Point}` to the start of a `node`. The `{Point}` can be one of: `Anchor`, `Focus`, `Start`, `End`, or ommited to move both the `anchor` and `focus` point at once. -> 🤖 This method may need to be followed by `point.normalize(document)`, like [`move{Point}To`](#movepointto). +> 🤖 This method may need to be followed by `range.normalize(document)`, like [`move{Point}To`](#movepointto). ### `moveTo{Point}` @@ -173,7 +173,7 @@ Move both points of the range to `{Point}`, collapsing it. The `{Point}` can be Move the range to be spanning the entirity of a `node`, by placing its `anchor` point at the start of the node and its `focus` point at the end of the node. -> 🤖 This method may need to be followed by `point.normalize(document)`, like [`move{Point}To`](#movepointto). +> 🤖 This method may need to be followed by `range.normalize(document)`, like [`move{Point}To`](#movepointto). ### `normalize` diff --git a/docs/reference/slate/text.md b/docs/reference/slate/text.md index 8e35337602..6ca2805f0e 100644 --- a/docs/reference/slate/text.md +++ b/docs/reference/slate/text.md @@ -30,7 +30,7 @@ The text contents of this node. ### `marks` -`Immutable.List,` +`Immutable.Set,` A list of marks for this node. diff --git a/examples/app.js b/examples/app.js index bc0f08cadd..11f7625152 100644 --- a/examples/app.js +++ b/examples/app.js @@ -59,7 +59,7 @@ const EXAMPLES = [ ['Markdown Shortcuts', MarkdownShortcuts, '/markdown-shortcuts'], ['Mentions', Mentions, '/mentions'], ['Paste HTML', PasteHtml, '/paste-html'], - ['Placeholders', Placeholder, '/placeholders'], + ['Placeholders', Placeholder, '/placeholder'], ['Plain Text', PlainText, '/plain-text'], ['Plugins', Plugins, '/plugins'], ['Read-only', ReadOnly, '/read-only'], diff --git a/examples/embeds/video.js b/examples/embeds/video.js index 8b4fa0f7dc..292947d815 100644 --- a/examples/embeds/video.js +++ b/examples/embeds/video.js @@ -13,8 +13,7 @@ class Video extends React.Component { * @param {Event} e */ - onChange = e => { - const video = e.target.value + onChange = video => { const { node, editor } = this.props editor.setNodeByKey(node.key, { data: { video } }) } @@ -108,8 +107,8 @@ class Video extends React.Component { } return ( - { + const [val, setVal] = React.useState(props.defaultValue) + + const onChange = React.useCallback( + e => { + setVal(e.target.value) + props.onChange(e.target.value) + }, + [props.onChange] + ) + + return ( + + ) +} + /** * Export. */ diff --git a/examples/emojis/index.js b/examples/emojis/index.js index e5f6fac990..8f22a6ce6e 100644 --- a/examples/emojis/index.js +++ b/examples/emojis/index.js @@ -37,7 +37,8 @@ const EMOJIS = [ '👻', '🍔', '🍑', - '🔑', + '👩‍❤️‍👩', + '👨‍👩‍👦', ] /** @@ -158,11 +159,16 @@ class Emojis extends React.Component { onClickEmoji = (e, code) => { e.preventDefault() + const { editor } = this - this.editor - .insertInline({ type: 'emoji', data: { code } }) - .moveToStartOfNextText() - .focus() + if (e.shiftKey) { + editor.insertText(code) + } else { + editor.insertInline({ type: 'emoji', data: { code } }) + editor.moveToStartOfNextText() + } + + editor.focus() } } diff --git a/examples/emojis/value.json b/examples/emojis/value.json index fffe28215d..746bf73217 100644 --- a/examples/emojis/value.json +++ b/examples/emojis/value.json @@ -43,6 +43,17 @@ "text": "This example shows emojis in action." } ] + }, + { + "object": "block", + "type": "paragraph", + "nodes": [ + { + "object": "text", + "text": + "Click on an emoji at the top to insert it as an inline node, shift-click to insert it as plain text." + } + ] } ] } diff --git a/packages/slate-react/package.json b/packages/slate-react/package.json index 2cb3d476cc..1cf092727f 100644 --- a/packages/slate-react/package.json +++ b/packages/slate-react/package.json @@ -1,7 +1,7 @@ { "name": "slate-react", "description": "A set of React components for building completely customizable rich-text editors.", - "version": "0.22.8", + "version": "0.22.9", "license": "MIT", "repository": "git://github.com/ianstormtaylor/slate.git", "main": "lib/slate-react.js", diff --git a/packages/slate-react/src/components/content.js b/packages/slate-react/src/components/content.js index 5ff5f13bc7..50a566b4d0 100644 --- a/packages/slate-react/src/components/content.js +++ b/packages/slate-react/src/components/content.js @@ -105,6 +105,7 @@ class Content extends React.Component { nodeRef: React.createRef(), nodeRefs: {}, contentKey: 0, + nativeSelection: {}, // Native selection object stored to check if `onNativeSelectionChange` has triggered yet } /** @@ -198,6 +199,7 @@ class Content extends React.Component { debug.update('componentDidUpdate') this.updateSelection() + this.props.editor.clearUserActionPerformed() this.props.onEvent('onComponentDidUpdate') } @@ -237,7 +239,35 @@ class Content extends React.Component { // If the Slate selection is unset, but the DOM selection has a range // selected in the editor, we need to remove the range. - if (selection.isUnset && rangeCount && this.isInEditor(anchorNode)) { + // However we should _not_ remove the range if the selection as + // reported by `getSelection` is not equal to `this.tmp.nativeSelection` + // as this suggests `onNativeSelectionChange` has not triggered yet (which can occur in Firefox) + // See: https://github.com/ianstormtaylor/slate/pull/2995 + + const propsToCompare = [ + 'anchorNode', + 'anchorOffset', + 'focusNode', + 'focusOffset', + 'isCollapsed', + 'rangeCount', + 'type', + ] + + let selectionsEqual = true + + for (const prop of propsToCompare) { + if (this.tmp.nativeSelection[prop] !== native[prop]) { + selectionsEqual = false + } + } + + if ( + selection.isUnset && + rangeCount && + this.isInEditor(anchorNode) && + selectionsEqual + ) { removeAllRanges(native) updated = true } @@ -288,39 +318,46 @@ class Content extends React.Component { // Otherwise, set the `isUpdatingSelection` flag and update the selection. updated = true this.tmp.isUpdatingSelection = true + removeAllRanges(native) - if (!IS_FIREFOX) { - removeAllRanges(native) - - // COMPAT: IE 11 does not support `setBaseAndExtent`. (2018/11/07) - if (native.setBaseAndExtent) { - // COMPAT: Since the DOM range has no concept of backwards/forwards - // we need to check and do the right thing here. - if (isBackward) { - native.setBaseAndExtent( - range.endContainer, - range.endOffset, - range.startContainer, - range.startOffset - ) - } else { - native.setBaseAndExtent( - range.startContainer, - range.startOffset, - range.endContainer, - range.endOffset - ) - } + // COMPAT: IE 11 does not support `setBaseAndExtent`. (2018/11/07) + if (native.setBaseAndExtent) { + // COMPAT: Since the DOM range has no concept of backwards/forwards + // we need to check and do the right thing here. + if (isBackward) { + native.setBaseAndExtent( + range.endContainer, + range.endOffset, + range.startContainer, + range.startOffset + ) } else { - native.addRange(range) + native.setBaseAndExtent( + range.startContainer, + range.startOffset, + range.endContainer, + range.endOffset + ) } + } else { + native.addRange(range) } - // Scroll to the selection, in case it's out of view. - scrollToSelection(native) + // Only scroll to selection when a user action is performed + if (editor.userActionPerformed() === true) { + // Scroll to the selection, in case it's out of view. + scrollToSelection(native) + } - // Then unset the `isUpdatingSelection` flag after a delay. + // Then unset the `isUpdatingSelection` flag after a delay, to ensure that + // it is still set when selection-related events from updating it fire. setTimeout(() => { + // COMPAT: In Firefox, it's not enough to create a range, you also need + // to focus the contenteditable element too. (2016/11/16) + if (IS_FIREFOX && this.ref.current) { + this.ref.current.focus() + } + this.tmp.isUpdatingSelection = false debug.update('updateSelection:setTimeout', { @@ -355,6 +392,12 @@ class Content extends React.Component { let el try { + // COMPAT: In Firefox, sometimes the node can be comment which doesn't + // have .closest and it crashes. + if (target.nodeType === 8) { + return false + } + // COMPAT: Text nodes don't have `isContentEditable` property. So, when // `target` is a text node use its parent node for check. el = target.nodeType === 3 ? target.parentNode : target @@ -481,12 +524,24 @@ class Content extends React.Component { const window = getWindow(event.target) const { activeElement } = window.document + const native = window.getSelection() + debug.update('onNativeSelectionChange', { - anchorOffset: window.getSelection().anchorOffset, + anchorOffset: native.anchorOffset, }) if (activeElement !== this.ref.current) return + this.tmp.nativeSelection = { + anchorNode: native.anchorNode, + anchorOffset: native.anchorOffset, + focusNode: native.focusNode, + focusOffset: native.focusOffset, + isCollapsed: native.isCollapsed, + rangeCount: native.rangeCount, + type: native.type, + } + this.props.onEvent('onSelect', event) }, 100) diff --git a/packages/slate-react/src/plugins/dom/after.js b/packages/slate-react/src/plugins/dom/after.js index 2b82044216..3458d82d0d 100644 --- a/packages/slate-react/src/plugins/dom/after.js +++ b/packages/slate-react/src/plugins/dom/after.js @@ -302,7 +302,7 @@ function AfterPlugin(options = {}) { const { value } = editor const { document, selection } = value const window = getWindow(event.target) - let target = editor.findEventRange(event) + const target = editor.findEventRange(event) if (!target) { return fn(event) @@ -315,26 +315,30 @@ function AfterPlugin(options = {}) { editor.focus() - // If the drag is internal and the target is after the selection, it - // needs to account for the selection's content being deleted. - if ( - isDraggingInternally && - selection.end.offset < target.end.offset && - selection.end.path.equals(target.end.path) - ) { - target = target.moveForward( - selection.start.path.equals(selection.end.path) - ? 0 - selection.end.offset + selection.start.offset - : 0 - selection.end.offset + // COMPAT: React's onSelect event breaks after an onDrop event + // has fired in a node: https://github.com/facebook/react/issues/11379. + // Until this is fixed in React, we dispatch a mouseup event on that + // DOM node, since that will make it go back to normal. + const el = editor.findDOMNode(target.focus.path) + + if (el) { + el.dispatchEvent( + new MouseEvent('mouseup', { + view: window, + bubbles: true, + cancelable: true, + }) ) } - if (isDraggingInternally) { - editor.delete() - } + const draggedRange = selection editor.select(target) + if (isDraggingInternally) { + editor.deleteAtRange(draggedRange) + } + if (type === 'text' || type === 'html') { const { anchor } = target let hasVoidParent = document.hasVoidParent(anchor.path, editor) @@ -370,22 +374,6 @@ function AfterPlugin(options = {}) { editor.insertFragment(fragment) } - // COMPAT: React's onSelect event breaks after an onDrop event - // has fired in a node: https://github.com/facebook/react/issues/11379. - // Until this is fixed in React, we dispatch a mouseup event on that - // DOM node, since that will make it go back to normal. - const el = editor.findDOMNode(target.focus.path) - - if (el) { - el.dispatchEvent( - new MouseEvent('mouseup', { - view: window, - bubbles: true, - cancelable: true, - }) - ) - } - fn(event) } diff --git a/packages/slate-react/src/plugins/dom/before.js b/packages/slate-react/src/plugins/dom/before.js index ef7f4078f4..436ceb74de 100644 --- a/packages/slate-react/src/plugins/dom/before.js +++ b/packages/slate-react/src/plugins/dom/before.js @@ -30,6 +30,7 @@ function BeforePlugin() { let isComposing = false let isCopying = false let isDragging = false + let isUserActionPerformed = false /** * On before input. @@ -40,6 +41,7 @@ function BeforePlugin() { const onBeforeInput = (fn, editor) => event => { const isSynthetic = !!event.nativeEvent if (editor.readOnly) return + isUserActionPerformed = true // COMPAT: If the browser supports Input Events Level 2, we will have // attached a custom handler for the real `beforeinput` events, instead of @@ -105,6 +107,7 @@ function BeforePlugin() { const onCompositionEnd = (fn, editor) => event => { const n = compositionCount + isUserActionPerformed = true // The `count` check here ensures that if another composition starts // before the timeout has closed out this one, we will abort unsetting the @@ -126,6 +129,7 @@ function BeforePlugin() { const onClick = (fn, editor) => event => { debug('onClick', { event }) + isUserActionPerformed = true fn(event) } @@ -141,6 +145,7 @@ function BeforePlugin() { const { value } = editor const { selection } = value + isUserActionPerformed = true if (!selection.isCollapsed) { // https://github.com/ianstormtaylor/slate/issues/1879 @@ -294,6 +299,7 @@ function BeforePlugin() { const onDrop = (fn, editor) => event => { if (editor.readOnly) return + isUserActionPerformed = true // Prevent default so the DOM's value isn't corrupted. event.preventDefault() @@ -339,6 +345,7 @@ function BeforePlugin() { const onInput = (fn, editor) => event => { if (isComposing) return if (editor.value.selection.isBlurred) return + isUserActionPerformed = true debug('onInput', { event }) fn(event) } @@ -381,6 +388,7 @@ function BeforePlugin() { event.preventDefault() } + isUserActionPerformed = true debug('onKeyDown', { event }) fn(event) } @@ -404,6 +412,7 @@ function BeforePlugin() { const onPaste = (fn, editor) => event => { if (editor.readOnly) return + isUserActionPerformed = true // Prevent defaults so the DOM state isn't corrupted. event.preventDefault() @@ -427,11 +436,21 @@ function BeforePlugin() { // Save the new `activeElement`. const window = getWindow(event.target) activeElement = window.document.activeElement + isUserActionPerformed = true debug('onSelect', { event }) fn(event) } + function userActionPerformed() { + return isUserActionPerformed + } + + function clearUserActionPerformed() { + isUserActionPerformed = false + return null + } + /** * Return the plugin. * @@ -459,6 +478,8 @@ function BeforePlugin() { onKeyUp, onPaste, onSelect, + queries: { userActionPerformed }, + commands: { clearUserActionPerformed }, } } diff --git a/packages/slate-react/src/utils/clone-fragment.js b/packages/slate-react/src/utils/clone-fragment.js index 4a9759ef5a..ddf9ccb7bc 100644 --- a/packages/slate-react/src/utils/clone-fragment.js +++ b/packages/slate-react/src/utils/clone-fragment.js @@ -7,7 +7,6 @@ import { Value } from 'slate' import TRANSFER_TYPES from '../constants/transfer-types' import removeAllRanges from './remove-all-ranges' -import findDOMNode from './find-dom-node' import DATA_ATTRS from '../constants/data-attributes' import SELECTORS from '../constants/selectors' @@ -56,9 +55,13 @@ function cloneFragment(event, editor, callback = () => undefined) { // content, since the spacer is before void's content in the DOM. if (endVoid) { const r = range.cloneRange() - const node = findDOMNode(endVoid, window) - r.setEndAfter(node) - contents = r.cloneContents() + const path = document.getPath(endVoid.key) + + if (path) { + const node = editor.findDOMNode(path) + r.setEndAfter(node) + contents = r.cloneContents() + } } // COMPAT: If the start node is a void node, we need to attach the encoded diff --git a/packages/slate-react/src/utils/find-point.js b/packages/slate-react/src/utils/find-point.js index 26e8a46e2c..3427a8f202 100644 --- a/packages/slate-react/src/utils/find-point.js +++ b/packages/slate-react/src/utils/find-point.js @@ -51,7 +51,11 @@ function findPoint(nativeNode, nativeOffset, editor) { // into \r\n. The bug causes a loop when slate-react attempts to reposition // its cursor to match the native position. Use textContent.length instead. // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/ - offset = range.cloneContents().textContent.length + const fragment = range.cloneContents() + const zeroWidthNodes = fragment.querySelectorAll( + `[${DATA_ATTRS.ZERO_WIDTH}]` + ) + offset = fragment.textContent.length - zeroWidthNodes.length } else { // For void nodes, the element with the offset key will be a cousin, not an // ancestor, so find it by going down from the nearest void parent. diff --git a/packages/slate/src/commands/on-selection.js b/packages/slate/src/commands/on-selection.js index 49ad6f260d..f4f28cb1ee 100644 --- a/packages/slate/src/commands/on-selection.js +++ b/packages/slate/src/commands/on-selection.js @@ -3,6 +3,7 @@ import warning from 'tiny-warning' import pick from 'lodash/pick' import Selection from '../models/selection' +import TextUtils from '../utils/text-utils' const Commands = {} @@ -433,9 +434,18 @@ Commands.moveAnchorWordForward = (fn, editor) => () => { * @param {Number} n */ -Commands.moveBackward = (fn, editor) => n => { - editor.moveAnchorBackward(n) - editor.moveFocusBackward(n) +Commands.moveBackward = (fn, editor) => (n = 1) => { + if (n === 0) return + const { value } = editor + const { document, selection } = value + const { start } = selection + const startBlock = document.getClosestBlock(start.key) + const o = startBlock.getOffset(start.key) + const offset = o + start.offset + const { text } = startBlock + const charsOffset = TextUtils.getCharOffsetBackward(text, offset, n) + editor.moveAnchorBackward(charsOffset) + editor.moveFocusBackward(charsOffset) } /** @@ -1126,9 +1136,18 @@ Commands.moveFocusWordForward = (fn, editor) => () => { * Move the selection's points each forward by one character. */ -Commands.moveForward = (fn, editor) => (...args) => { - editor.moveAnchorForward(...args) - editor.moveFocusForward(...args) +Commands.moveForward = (fn, editor) => (n = 1) => { + if (n === 0) return + const { value } = editor + const { document, selection } = value + const { start } = selection + const startBlock = document.getClosestBlock(start.path) + const o = startBlock.getOffset(start.key) + const offset = o + start.offset + const { text } = startBlock + const charsOffset = TextUtils.getCharOffsetForward(text, offset, n) + editor.moveAnchorForward(charsOffset) + editor.moveFocusForward(charsOffset) } /** diff --git a/packages/slate/src/utils/text-utils.js b/packages/slate/src/utils/text-utils.js index 70083f11af..e9ae219d08 100644 --- a/packages/slate/src/utils/text-utils.js +++ b/packages/slate/src/utils/text-utils.js @@ -45,6 +45,63 @@ function isSurrogate(code) { return SURROGATE_START <= code && code <= SURROGATE_END } +/** + * Does `code` form Modifier with next one. + * + * https://emojipedia.org/modifiers/ + * + * @param {Number} code + * @param {String} text + * @param {Number} offset + * @return {Boolean} + */ + +function isModifier(code, text, offset) { + if (code === 0xd83c) { + const next = text.charCodeAt(offset + 1) + return next <= 0xdfff && next >= 0xdffb + } + return false +} + +/** + * Is `code` a Variation Selector. + * + * https://codepoints.net/variation_selectors + * + * @param {Number} code + * @return {Boolean} + */ + +function isVariationSelector(code) { + return code <= 0xfe0f && code >= 0xfe00 +} + +/** + * Is `code` one of the BMP codes used in emoji sequences. + * + * https://emojipedia.org/emoji-zwj-sequences/ + * + * @param {Number} code + * @return {Boolean} + */ + +function isBMPEmoji(code) { + // This requires tiny bit of maintanance, better ideas? + // Fortunately it only happens if new Unicode Standard + // is released. Fails gracefully if upkeep lags behind, + // same way Slate previously behaved with all emojis. + return ( + code === 0x2764 || // heart (❤) + code === 0x2642 || // male (♂) + code === 0x2640 || // female (♀) + code === 0x2620 || // scull (☠) + code === 0x2695 || // medical (⚕) + code === 0x2708 || // plane (✈️) + code === 0x25ef // large circle (◯) + ) +} + /** * Is a character a word character? Needs the `remaining` characters too. * @@ -81,42 +138,151 @@ function getCharLength(char) { } /** - * Get the offset to the end of the first character in `text`. + * Get the offset to the end of the character(s) in `text`. + * This function is emoji aware and handles them correctly. * * @param {String} text + * @param {Number} chars + * @param {Boolean} forward * @return {Number} */ -function getCharOffset(text) { - const char = text.charAt(0) - return getCharLength(char) +function getCharOffset(text, chars, forward) { + let offset = 0 + + // Handle end/beginning of node: we have to return 1 in order not to + // break cursor's jumping to next/previous node. We need to return early + // because otherwise, ''.charCodeAt(0) returned NaN and, the default + // handling 'latin characters' at the end of the while loop would + // would never be reached an we returned '0' as offset. + if (text === '') return 1 + + // Calculate offset sum of each character + for (let i = 0; i < chars; i++) { + // `prev` types (better ideas?): + // - SURR: surrogate pair + // - MOD: modifier (technically also surrogate pair) + // - ZWJ: zero width joiner + // - VAR: variation selector + // - BMP: sequenceable character from Basic Multilingual Plane + let prev = null + let charCode = text.charCodeAt(offset) + + while (charCode) { + if (isSurrogate(charCode)) { + const modifier = isModifier(charCode, text, offset) + + // Early returns are the heart of this loop where + // we decide if previous and current codepoints + // should form a single character (in other words: + // how many of them should selection jump over). + if (forward) { + if ( + (!modifier && prev && prev !== 'ZWJ') || + (modifier && prev && prev !== 'SURR') + ) { + break + } + } else if (prev === 'SURR' || prev === 'BMP') { + break + } + + offset += 2 + prev = modifier ? 'MOD' : 'SURR' + charCode = text.charCodeAt(offset) + // It's okay to `continue` without checking + // because if `charCode` is NaN (which is + // the case when out of `text` range), next + // `while` loop won't execute and we're done. + continue + } + + // If zero width joiner + if (charCode === 0x200d) { + offset += 1 + prev = 'ZWJ' + charCode = text.charCodeAt(offset) + continue + } + + if (isBMPEmoji(charCode)) { + if ( + (forward && prev === 'VAR') || + (prev && prev !== 'ZWJ' && prev !== 'VAR') + ) { + break + } + + offset += 1 + prev = 'BMP' + charCode = text.charCodeAt(offset) + continue + } + + if (isVariationSelector(charCode)) { + if (!forward && prev && prev !== 'ZWJ') { + break + } + + offset += 1 + prev = 'VAR' + charCode = text.charCodeAt(offset) + continue + } + + // Modifier "fuses" with what ever character is before that + // (even whitespace), need to look ahead if loop gets here. + if (forward) { + const nextCharCode = text.charCodeAt(offset + 1) + + if (isModifier(nextCharCode, text, offset + 1)) { + offset += 3 + prev = 'MOD' + charCode = text.charCodeAt(offset) + continue + } + } else if (prev === 'MOD') { + offset += 1 + break + } + + // If while loop ever gets here, we're + // done (e.g Latin characters, length 1). + if (prev === null) offset += 1 + break + } + } + + return offset } /** - * Get the offset to the end of the character before an `offset` in `text`. + * Get the offset to the end of character(s) before an `offset` in `text`. * * @param {String} text * @param {Number} offset + * @param {Number} chars * @return {Number} */ -function getCharOffsetBackward(text, offset) { +function getCharOffsetBackward(text, offset, chars = 1) { text = text.slice(0, offset) text = reverse(text) - return getCharOffset(text) + return getCharOffset(text, chars) } /** - * Get the offset to the end of the character after an `offset` in `text`. + * Get the offset to the end of character(s) after an `offset` in `text`. * * @param {String} text * @param {Number} offset + * @param {Number} chars * @return {Number} */ -function getCharOffsetForward(text, offset) { +function getCharOffsetForward(text, offset, chars = 1) { text = text.slice(offset) - return getCharOffset(text) + return getCharOffset(text, chars, true) } /** diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js new file mode 100644 index 0000000000..59d77de82c --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + one + two + three + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wordone + two + + three + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js new file mode 100644 index 0000000000..94d3872768 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +const fragment = ( + + fragment zero + fragment one + fragment two + +) + +export default function(editor) { + editor.insertFragment(fragment) +} + +export const input = ( + + + zero + + one + + + two + + + +) + +// TODO: is this the right behavior? +export const output = ( + + + zero + fragment zero + fragment one + + fragment twotwo + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js new file mode 100644 index 0000000000..7b4b4d41c9 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + one + two + three + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + one + two + + threeword + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js new file mode 100644 index 0000000000..fa36c4a568 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + Some inline stuff + two + + + ) +} + +export const input = ( + + + + AB + + + +) + +export const output = ( + + + + AoneSome inline stufftwoB + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js new file mode 100644 index 0000000000..028d91557e --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + bar + + + ) +} + +export const input = ( + + + + + Foobaz + + + + +) + +export const output = ( + + + + + Foo + + bar + + baz + + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js new file mode 100644 index 0000000000..e98c37ac4e --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + fragment + + + ) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + wo + + fragment + + rd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js b/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js new file mode 100644 index 0000000000..95c6aea90c --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + 3 + 4 + + + ) +} + +export const input = ( + + + + 1 + + 2 + + + + +) + +export const output = ( + + + + 1 + 23 + + 4 + + + + +) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js new file mode 100644 index 0000000000..5a5efec409 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + bar + + + ) +} + +export const input = ( + + + + + Foobaz + + + + +) + +export const output = ( + + + + + Foo + + bar + + baz + + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js new file mode 100644 index 0000000000..85ef31a848 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + b + u + i + + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + wo + b + u + + i + + rd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js index b276ee2ecb..f881a64cb3 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js @@ -47,3 +47,5 @@ export const output = (
) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js new file mode 100644 index 0000000000..0e4b0321fc --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js @@ -0,0 +1,42 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + after quote + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + word + + one + two + + + after quote + + + +) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js new file mode 100644 index 0000000000..4d97589907 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + + ) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + woone + + tword + + + + +) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js new file mode 100644 index 0000000000..ad06318d40 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wo + + one + + two + + + rd + + +) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js new file mode 100644 index 0000000000..4b66e0e502 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + after quote + + ) +} + +export const input = ( + + + + word + + + +) + +// TODO: should "after quote" be put together with "word"? +export const output = ( + + + + one + two + + + after quote + + word + + +) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js new file mode 100644 index 0000000000..7dcd134412 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js @@ -0,0 +1,51 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + + 2 + 3 + + + + ) +} + +export const input = ( + + + + + + + 1 + + + + + + +) + +export const output = ( + + + + + + 12 + + 3 + + + + + + +) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js new file mode 100644 index 0000000000..8213b2fc06 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js @@ -0,0 +1,40 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + 2 + + + ) +} + +export const input = ( + + + + + {'1 '} + + + + + +) + +export const output = ( + + + + + 1 2 + + + + +) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js new file mode 100644 index 0000000000..215af41978 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js @@ -0,0 +1,71 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + + + + 1 + + + 2 + + + +
+
+ ) +} + +export const input = ( + + + + + + + + + + + + + + + +
+
+
+) + +// TODO: surely this is the wrong behavior. +// ideally, paragraph with "2" goes into second cell +export const output = ( + + + + + + + 1 + + + 2 + + + + + + + + +
+
+
+) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js new file mode 100644 index 0000000000..ed276d6e7f --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js @@ -0,0 +1,56 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + + + 1 + 2 + + +
+
+ ) +} + +export const input = ( + + + + + + + + + + + +
+
+
+) + +// TODO: paste "2" into second cell instead of creating new one? +export const output = ( + + + + + + 1 + + 2 + + + + +
+
+
+) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js new file mode 100644 index 0000000000..638645012d --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js @@ -0,0 +1,57 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + + + New 1 + New 2 + + +
+
+ ) +} + +export const input = ( + + + + + + + {'Existing 1 '} + + + Existing 2 + + +
+
+
+) + +// TODO: paste "Existing 2" before / after "New 2" in second cell? +export const output = ( + + + + + + Existing 1 New 1 + + New 2 + + Existing 2 + + +
+
+
+) + +export const skip = true diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js new file mode 100644 index 0000000000..cf9cb1beec --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js @@ -0,0 +1,38 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + + ) +} + +export const input = ( + + + + + + + + +) + +export const output = ( + + + + + + onetwo + + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js new file mode 100644 index 0000000000..33b5cd4870 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + {'one '} + two + + + ) +} + +export const input = ( + + + + {'word '} + + + another + + +) + +export const output = ( + + + + word one two + + another + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js new file mode 100644 index 0000000000..f288a55cbc --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + + one + two + + + ) +} + +export const input = ( + + + + + + + +) + +export const output = ( + + + + onetwo + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js new file mode 100644 index 0000000000..5324ad150f --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + + +) + +export const output = ( + + + + word + fragment + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js new file mode 100644 index 0000000000..27d9e1ed9e --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + + word + + + +) + +export const output = ( + + + + fragment + word + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js new file mode 100644 index 0000000000..1354581233 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + wordfragment + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js new file mode 100644 index 0000000000..414d41ffd9 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + + {'word '} + + + + + +) + +// TODO: argument to made that fragment should go into the inline +export const output = ( + + + + {'word '} + fragment + + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js new file mode 100644 index 0000000000..80ccdc225e --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + wofragmentrd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js new file mode 100644 index 0000000000..46137abd63 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + + word + + + + +) + +// TODO: argument to made that fragment should go into the inline +export const output = ( + + + + wo + fragment + rd + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js new file mode 100644 index 0000000000..06bf491cbf --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + fragmentword + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js new file mode 100644 index 0000000000..bf53068542 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + word + + another + + + +) + +export const output = ( + + + word + + fragmentanother + + + +) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js new file mode 100644 index 0000000000..b96af30ce3 --- /dev/null +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import h from '../../../../helpers/h' + +export default function(editor) { + editor.insertFragment( + + fragment + + ) +} + +export const input = ( + + + + word + + + another + + + +) + +export const output = ( + + + + wofragmentother + + + +) diff --git a/packages/slate/test/helpers/h.js b/packages/slate/test/helpers/h.js index 99cb807ec5..dea1347561 100644 --- a/packages/slate/test/helpers/h.js +++ b/packages/slate/test/helpers/h.js @@ -9,6 +9,10 @@ const h = createHyperscript({ list: 'list', item: 'item', image: 'image', + table: 'table', + table_body: 'table_body', + table_row: 'table_row', + table_cell: 'table_cell', }, inlines: { link: 'link', From 9873e1abaff303481a0180ecaa912a69d55261a4 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 14 Oct 2019 13:15:05 -0400 Subject: [PATCH 027/165] add typescript, convert slate, slate-hyperscript, slate-plain-serializer --- .babelrc | 64 - .prettierignore | 1 + babel.config.js | 29 + benchmark/compare.js | 115 - benchmark/config.js | 39 - benchmark/generate-report.js | 57 - benchmark/helpers/h.js | 45 - benchmark/index.js | 20 - .../html-serializer/deserialize.js | 58 - .../html-serializer/serialize.js | 54 - benchmark/slate-html-serializer/index.js | 37 - benchmark/slate-plain-serializer/index.js | 40 - .../plain-serializer/deserialize.js | 16 - .../plain-serializer/serialize.js | 26 - benchmark/slate-react/index.js | 40 - benchmark/slate-react/rendering/decoration.js | 57 - .../rendering/large-with-selection.js | 73 - benchmark/slate-react/rendering/normal.js | 29 - benchmark/slate/changes/add-mark.js | 41 - benchmark/slate/changes/delete-backward.js | 36 - benchmark/slate/changes/delete-forward.js | 36 - .../insert-fragment-deep-with-problems.js | 67 - .../slate/changes/insert-fragment-large.js | 36 - benchmark/slate/changes/insert-fragment.js | 36 - benchmark/slate/changes/insert-node-by-key.js | 34 - benchmark/slate/changes/insert-text-by-key.js | 38 - benchmark/slate/changes/insert-text.js | 40 - .../slate/changes/normalize-with-problems.js | 41 - benchmark/slate/changes/normalize.js | 40 - benchmark/slate/changes/remove-node-by-key.js | 38 - benchmark/slate/changes/set-blocks.js | 36 - benchmark/slate/changes/split-block.js | 40 - benchmark/slate/index.js | 37 - benchmark/slate/models/from-json-big.js | 54 - benchmark/slate/models/from-json.js | 50 - .../slate/models/get-active-marks-at-range.js | 36 - benchmark/slate/models/get-ancestors.js | 34 - benchmark/slate/models/get-blocks.js | 33 - benchmark/slate/models/get-common-ancestor.js | 34 - benchmark/slate/models/get-descendant.js | 34 - .../slate/models/get-furthest-ancestor.js | 34 - benchmark/slate/models/get-inlines.js | 29 - .../slate/models/get-leaf-blocks-at-range.js | 34 - .../slate/models/get-leaf-inlines-at-range.js | 34 - benchmark/slate/models/get-leaves.js | 30 - benchmark/slate/models/get-marks-at-range.js | 34 - benchmark/slate/models/get-marks.js | 29 - benchmark/slate/models/get-parent.js | 34 - benchmark/slate/models/get-path.js | 34 - benchmark/slate/models/get-texts-at-range.js | 34 - benchmark/slate/models/get-texts.js | 29 - benchmark/slate/models/has-node-multiple.js | 35 - benchmark/slate/models/has-node.js | 34 - benchmark/slate/models/to-json.js | 29 - {support => config}/rollup/factory.js | 72 +- config/rollup/rollup.config.js | 30 + config/typescript/tsconfig.json | 15 + {support => config}/webpack/config.js | 0 package.json | 113 +- packages/slate-dev-benchmark/Readme.md | 1 - packages/slate-dev-benchmark/package.json | 14 - packages/slate-dev-benchmark/src/Bench.js | 227 -- .../slate-dev-benchmark/src/Repository.js | 73 - packages/slate-dev-benchmark/src/Suite.js | 85 - packages/slate-dev-benchmark/src/Timer.js | 66 - packages/slate-dev-benchmark/src/compose.js | 22 - packages/slate-dev-benchmark/src/index.js | 5 - packages/slate-dev-benchmark/src/logger.js | 74 - .../slate-dev-benchmark/src/makeOptions.js | 40 - packages/slate-dev-benchmark/src/types.js | 11 - packages/slate-dev-benchmark/test/index.js | 12 - .../slate-dev-benchmark/test/time/index.js | 22 - .../test/time/max-time-async.js | 31 - .../test/time/max-time-with-small-step.js | 31 - .../slate-dev-benchmark/test/time/max-time.js | 28 - .../slate-dev-benchmark/test/tries/index.js | 25 - .../test/tries/max-tries.js | 19 - .../test/tries/min-tries.js | 18 - .../slate-dev-benchmark/test/utils/sleep.js | 10 - packages/slate-dev-test-utils/Readme.md | 1 - packages/slate-dev-test-utils/package.json | 18 - packages/slate-dev-test-utils/test/index.js | 0 packages/slate-html-serializer/test/index.js | 2 +- packages/slate-hyperscript/package.json | 9 +- packages/slate-hyperscript/src/creators.js | 583 ---- packages/slate-hyperscript/src/creators.ts | 301 ++ packages/slate-hyperscript/src/index.js | 132 - packages/slate-hyperscript/src/index.ts | 205 ++ .../src/resolve-descendants.ts | 71 + packages/slate-hyperscript/src/tokens.ts | 159 + .../test/annotations/across-blocks.js | 80 - .../test/annotations/across-marks.js | 88 - .../test/annotations/deep-anchors.js | 101 - .../test/annotations/intersecting-marks.js | 88 - .../test/annotations/multiple.js | 80 - .../test/annotations/nested.js | 98 - .../test/annotations/overlapping.js | 98 - .../test/fixtures/annotation-across-block.js | 72 - .../fixtures/annotation-across-element.js | 37 + .../fixtures/annotation-across-elements.js | 48 + .../test/fixtures/annotation-across-mark.js | 39 + .../test/fixtures/annotation-across-marks.js | 53 + .../annotation-across-multiple-blocks.js | 89 - .../test/fixtures/annotation-custom.js | 55 + .../test/fixtures/annotation-nested.js | 58 + .../test/fixtures/annotation-overlapping.js | 58 + .../test/fixtures/block-empty.js | 12 - .../test/fixtures/block-inline-empty.js | 23 - .../test/fixtures/block-mark-empty.js | 28 - .../test/fixtures/block-mark-full.js | 28 - .../test/fixtures/block-mark-multiple.js | 44 - .../test/fixtures/block-mark-nested.js | 59 - .../test/fixtures/block-string.js | 18 - .../test/fixtures/cursor-across-block.js | 60 - .../cursor-across-blocks-and-inlines.js | 125 - .../test/fixtures/cursor-across-blocks-end.js | 77 - .../fixtures/cursor-across-blocks-middle.js | 77 - .../fixtures/cursor-across-blocks-start.js | 77 - .../test/fixtures/cursor-across-element.js | 37 + .../fixtures/cursor-across-elements-empty.js | 52 + .../fixtures/cursor-across-elements-end.js | 48 + .../fixtures/cursor-across-elements-middle.js | 48 + .../fixtures/cursor-across-elements-start.js | 48 + .../fixtures/cursor-across-empty-blocks.js | 81 - .../cursor-across-multiple-blocks-end.js | 92 - .../cursor-across-multiple-blocks-middle.js | 92 - .../cursor-across-multiple-blocks-start.js | 92 - .../test/fixtures/cursor-block-end.js | 60 - .../test/fixtures/cursor-block-middle.js | 60 - .../test/fixtures/cursor-block-start.js | 60 - .../fixtures/cursor-custom-block-middle.js | 66 - .../test/fixtures/cursor-element-empty.js | 37 + .../test/fixtures/cursor-element-end.js | 37 + .../test/fixtures/cursor-element-middle.js | 37 + .../fixtures/cursor-element-nested-end.js | 43 + .../fixtures/cursor-element-nested-middle.js | 43 + .../fixtures/cursor-element-nested-start.js | 43 + .../test/fixtures/cursor-element-start.js | 37 + .../fixtures/cursor-empty-text-with-key.js | 62 - .../test/fixtures/cursor-empty-text.js | 62 - .../test/fixtures/cursor-inline-end.js | 84 - .../test/fixtures/cursor-inline-start.js | 84 - .../test/fixtures/cursor-inline.js | 84 - .../test/fixtures/cursor-is-focused-false.js | 51 +- .../test/fixtures/cursor-mark-after.js | 77 +- .../test/fixtures/cursor-mark-end.js | 84 +- .../test/fixtures/cursor-mark-middle.js | 44 + .../test/fixtures/cursor-mark-start.js | 84 +- .../test/fixtures/cursor-mark.js | 82 - .../test/fixtures/cursor-marks-empty.js | 51 +- .../test/fixtures/cursor-text-empty.js | 39 + .../test/fixtures/custom-marks-with-text.js | 68 - .../test/fixtures/custom-tags.js | 93 - .../test/fixtures/element-custom.js | 21 + .../{document-empty.js => element-empty.js} | 4 +- .../test/fixtures/element-nested-empty.js | 17 + ...nline-full.js => element-nested-string.js} | 13 +- .../{inline-full.js => element-string.js} | 6 +- ...ck-text-empty.js => element-text-empty.js} | 8 +- ...ck-text-full.js => element-text-string.js} | 8 +- .../test/fixtures/inline-empty.js | 12 - .../test/fixtures/mark-custom.js | 16 + .../test/fixtures/mark-nested-string.js | 14 + .../test/fixtures/mark-string.js | 10 + .../test/fixtures/mark-text.js | 14 + .../test/fixtures/selection.js | 53 +- .../test/fixtures/text-empty.js | 1 - .../test/fixtures/text-full.js | 1 - .../test/fixtures/text-nested.js | 1 - .../test/fixtures/text-with-key.js | 16 - .../test/fixtures/value-empty.js | 11 + packages/slate-hyperscript/test/index.js | 12 +- packages/slate-hyperscript/tsconfig.json | 9 + packages/slate-parse-plaintext/Changelog.md | 57 + packages/slate-parse-plaintext/Readme.md | 1 + packages/slate-parse-plaintext/package.json | 35 + packages/slate-parse-plaintext/src/index.ts | 40 + .../test/fixtures/delimiter.js | 21 + .../test/fixtures/element-props.js | 19 + .../test/fixtures/line-multiple.js | 15 + .../test/fixtures/line-single.js | 13 + .../test/fixtures/text-props.js | 23 + packages/slate-parse-plaintext/test/index.js | 11 + packages/slate-parse-plaintext/tsconfig.json | 9 + packages/slate-plain-serializer/test/index.js | 2 +- packages/slate-react/test/index.js | 2 +- packages/slate-render-plaintext/Changelog.md | 57 + packages/slate-render-plaintext/Readme.md | 1 + packages/slate-render-plaintext/package.json | 35 + packages/slate-render-plaintext/src/index.ts | 23 + .../test/fixtures/block-custom-property.js | 13 + .../test/fixtures/block-mark.js | 15 + .../test/fixtures/block-multiple-empty.js | 19 + .../test/fixtures/block-multiple.js | 17 + .../fixtures/block-nested-inline-nested.js | 25 + .../test/fixtures/block-nested-inline.js | 25 + .../test/fixtures/block-nested-nested.js | 25 + .../test/fixtures/block-nested.js | 23 + .../test/fixtures/block.js | 13 + .../test/fixtures/custom-delimiter.js | 24 + .../test/fixtures/inline-custom-property.js | 17 + .../test/fixtures/inline-mark.js | 19 + .../test/fixtures/inline-nested.js | 21 + .../test/fixtures/inline.js | 17 + packages/slate-render-plaintext/test/index.js | 11 + packages/slate-render-plaintext/tsconfig.json | 9 + packages/slate/package.json | 21 +- .../slate/src/classes/commands/annotation.ts | 84 + packages/slate/src/classes/commands/path.ts | 494 +++ packages/slate/src/classes/commands/point.ts | 305 ++ packages/slate/src/classes/commands/range.ts | 409 +++ .../slate/src/classes/commands/selection.ts | 290 ++ packages/slate/src/classes/commands/value.ts | 608 ++++ packages/slate/src/classes/editor.ts | 105 + packages/slate/src/classes/path-ref.ts | 62 + packages/slate/src/classes/point-ref.ts | 62 + packages/slate/src/classes/queries/mark.ts | 14 + packages/slate/src/classes/queries/node.ts | 48 + packages/slate/src/classes/queries/path.ts | 324 ++ packages/slate/src/classes/queries/point.ts | 163 + packages/slate/src/classes/queries/range.ts | 142 + packages/slate/src/classes/queries/value.ts | 328 ++ packages/slate/src/classes/range-ref.ts | 62 + packages/slate/src/commands/at-point.js | 82 - packages/slate/src/commands/at-range.js | 956 ------ packages/slate/src/commands/by-path.js | 962 ------ packages/slate/src/commands/on-history.js | 220 -- packages/slate/src/commands/on-selection.js | 2044 ------------ packages/slate/src/commands/on-value.js | 78 - packages/slate/src/commands/with-intent.js | 481 --- packages/slate/src/controllers/editor.js | 700 ----- packages/slate/src/index.js | 83 - packages/slate/src/index.ts | 19 + packages/slate/src/interfaces/annotation.ts | 48 + packages/slate/src/interfaces/change.ts | 29 + packages/slate/src/interfaces/element.js | 2793 ----------------- packages/slate/src/interfaces/element.ts | 43 + packages/slate/src/interfaces/fragment.ts | 23 + packages/slate/src/interfaces/mark.ts | 65 + packages/slate/src/interfaces/model.js | 62 - packages/slate/src/interfaces/node.js | 262 -- packages/slate/src/interfaces/node.ts | 578 ++++ packages/slate/src/interfaces/object.js | 69 - packages/slate/src/interfaces/operation.ts | 427 +++ packages/slate/src/interfaces/path.ts | 422 +++ packages/slate/src/interfaces/point.ts | 149 + packages/slate/src/interfaces/range.js | 707 ----- packages/slate/src/interfaces/range.ts | 158 + packages/slate/src/interfaces/selection.ts | 37 + packages/slate/src/interfaces/string.ts | 84 + packages/slate/src/interfaces/text.ts | 44 + packages/slate/src/interfaces/value.ts | 322 ++ packages/slate/src/models/annotation.js | 193 -- packages/slate/src/models/block.js | 138 - packages/slate/src/models/change.js | 88 - packages/slate/src/models/data.js | 59 - packages/slate/src/models/decoration.js | 183 -- packages/slate/src/models/document.js | 102 - packages/slate/src/models/inline.js | 138 - packages/slate/src/models/leaf.js | 299 -- packages/slate/src/models/mark.js | 158 - packages/slate/src/models/node.js | 206 -- packages/slate/src/models/operation.js | 350 --- packages/slate/src/models/point.js | 644 ---- packages/slate/src/models/range.js | 153 - packages/slate/src/models/selection.js | 195 -- packages/slate/src/models/text.js | 370 --- packages/slate/src/models/value.js | 841 ----- packages/slate/src/operations/apply.js | 408 --- packages/slate/src/operations/index.js | 13 - packages/slate/src/operations/invert.js | 112 - .../slate/src/plugins/core/core-commands.js | 35 - .../slate/src/plugins/core/core-queries.js | 29 - .../slate/src/plugins/core/core-schema.js | 164 - packages/slate/src/plugins/core/index.js | 26 - packages/slate/src/plugins/history/history.ts | 46 + packages/slate/src/plugins/history/index.ts | 2 + packages/slate/src/plugins/history/plugin.ts | 230 ++ packages/slate/src/plugins/schema/checkers.ts | 373 +++ packages/slate/src/plugins/schema/error.ts | 266 ++ packages/slate/src/plugins/schema/index.js | 687 ---- packages/slate/src/plugins/schema/index.ts | 3 + packages/slate/src/plugins/schema/plugin.ts | 284 ++ packages/slate/src/plugins/schema/rule.ts | 84 + packages/slate/src/queries/format.js | 10 - packages/slate/src/queries/node.js | 10 - packages/slate/src/queries/path.js | 47 - packages/slate/src/queries/point.js | 342 -- packages/slate/src/queries/range.js | 53 - packages/slate/src/symbols.ts | 6 + packages/slate/src/utils/identity.js | 3 - packages/slate/src/utils/is-object.js | 35 - packages/slate/src/utils/key-utils.js | 71 - packages/slate/src/utils/memoize.js | 221 -- packages/slate/src/utils/mixin.js | 24 - packages/slate/src/utils/path-utils.js | 510 --- packages/slate/src/utils/slate-error.js | 30 - packages/slate/src/utils/text-utils.js | 366 --- .../non-matching-section-and-range.js | 36 - .../test/controllers/editor/has/exists.js | 17 - .../test/controllers/editor/has/missing.js | 17 - packages/slate/test/index.js | 84 +- .../move_node/ends-after-to-ends-before.js | 15 + .../move_node/ends-before-to-ends-after.js | 15 + .../Point/isAfter/point/offset-after.js | 17 + .../Point/isAfter/point/offset-before.js | 17 + .../Point/isAfter/point/offset-equal.js | 17 + .../Point/isAfter/point/path-after.js | 17 + .../Point/isAfter/point/path-before.js | 17 + .../Point/isAfter/point/path-equal.js | 17 + .../different-marks-across-blocks.js | 34 - .../mixed-marks-across-range.js | 38 - .../same-mark-across-blocks.js | 34 - .../models/node/get-ancestors/from-block.js | 26 - .../node/get-ancestors/from-document.js | 24 - .../models/node/get-ancestors/from-inline.js | 30 - .../get-ancestors/from-text-blocks-nested.js | 26 - .../node/get-ancestors/from-text-inline.js | 28 - .../models/node/get-ancestors/from-text.js | 24 - .../test/models/node/get-closest/by-path.js | 26 - .../get-closest/get-block-parent-inline.js | 30 - .../test/models/node/get-closest/top-level.js | 21 - .../multiple-blocks.js | 38 - ...ks-cursor-in-first-leaf-of-first-parent.js | 31 - ...s-cursor-in-first-leaf-of-second-parent.js | 37 - ...s-cursor-in-second-leaf-of-first-parent.js | 35 - ...s-selection-overlapping-multiple-blocks.js | 46 - ...tion-overlapping-texts-in-second-parent.js | 44 - ...ed-blocks-selection-spanning-first-text.js | 31 - .../single-block-cursor-beginning-of-text.js | 28 - .../single-block-cursor-end-of-text.js | 31 - .../single-block-cursor-middle-of-text.js | 27 - .../single-block-with-inline.js | 27 - .../single-void-block.js | 26 - .../across-block-with-marks.js | 42 - .../get-fragment-at-range/block-across.js | 29 - .../node/get-fragment-at-range/block.js | 23 - .../multiple-blocks.js | 36 - ...ks-cursor-in-first-leaf-of-first-parent.js | 29 - ...s-cursor-in-first-leaf-of-second-parent.js | 35 - ...s-cursor-in-second-leaf-of-first-parent.js | 33 - ...s-selection-overlapping-multiple-blocks.js | 46 - ...tion-overlapping-texts-in-second-parent.js | 42 - ...ed-blocks-selection-spanning-first-text.js | 29 - .../single-block-with-inline.js | 25 - .../get-leaf-blocks-at-range/single-block.js | 26 - .../single-void-block.js | 24 - .../multiple-blocks-no-inline.js | 33 - .../multiple-blocks.js | 44 - .../nested-with-text-on-every-level.js | 37 - ...-with-zero-offset-with-no-previous-text.js | 23 - ...ith-previous-text-not-in-the-same-block.js | 26 - .../node/get-marks-at-point/marked-text.js | 25 - .../text-with-zero-offset.js | 30 - .../node/get-marks-at-point/unmarked-text.js | 22 - .../models/node/get-next-block/by-path.js | 22 - .../multiple-siblings-to-bypass.js | 24 - .../next-block-is-ancestor-sibling.js | 22 - ...-block-is-in-sibling-with-deeper-blocks.js | 27 - .../next-block-is-sibling-descendent.js | 24 - .../get-next-block/next-block-is-sibling.js | 21 - .../node/get-next-block/no-next-block.js | 25 - .../node/get-next-block/no-next-node.js | 24 - ...-is-ancestor-sibling-with-nested-blocks.js | 28 - .../next-node-is-ancestor-sibling.js | 22 - .../models/node/get-previous-block/by-path.js | 22 - .../multiple-siblings-to-bypass.js | 24 - .../node/get-previous-block/no-prev-block.js | 25 - .../node/get-previous-block/no-prev-node.js | 24 - .../prev-block-is-ancestor-sibling.js | 22 - ...-block-is-in-sibling-with-deeper-blocks.js | 32 - .../prev-block-is-sibling-descendent.js | 24 - .../prev-block-is-sibling.js | 21 - .../multiple-blocks.js | 36 - ...ks-cursor-in-first-leaf-of-first-parent.js | 29 - ...s-cursor-in-first-leaf-of-second-parent.js | 35 - ...s-cursor-in-second-leaf-of-first-parent.js | 33 - ...s-selection-overlapping-multiple-blocks.js | 44 - ...tion-overlapping-texts-in-second-parent.js | 42 - ...ed-blocks-selection-spanning-first-text.js | 29 - .../single-block-with-inline.js | 25 - .../get-root-blocks-at-range/single-block.js | 26 - .../single-void-block.js | 24 - .../multiple-blocks-no-inline.js | 33 - .../multiple-blocks.js | 44 - .../nested-with-text-on-every-level.js | 37 - .../models/node/is-in-range/block-above.js | 35 - .../models/node/is-in-range/block-below.js | 38 - .../node/is-in-range/first-block-inside.js | 35 - .../node/is-in-range/first-text-inside.js | 35 - .../node/is-in-range/last-block-inside.js | 35 - .../node/is-in-range/last-text-inside.js | 35 - .../models/node/is-in-range/text-above.js | 35 - .../models/node/is-in-range/text-below.js | 38 - .../node/is-in-range/text-in-middle-inside.js | 35 - .../operation/create/add-mark-with-data.js | 24 - .../operation/create/add-mark-without-data.js | 23 - .../point/is-after-point/after-target-path.js | 20 - .../is-after-point/before-target-path.js | 20 - .../same-node-after-target-offset.js | 20 - .../same-node-before-target-offset.js | 20 - .../is-after-point/same-node-same-offset.js | 20 - .../is-after-point/target-is-ancestor.js | 20 - .../is-after-point/target-is-descendant.js | 20 - .../point/is-after-range/after-end-node.js | 28 - .../point/is-after-range/after-end-offset.js | 28 - .../is-after-range/after-start-offset.js | 28 - .../point/is-after-range/before-end-offset.js | 28 - .../point/is-after-range/before-start-node.js | 28 - .../is-after-range/before-start-offset.js | 28 - .../point/is-after-range/between-nodes.js | 28 - .../models/point/is-after-range/is-end.js | 28 - .../models/point/is-after-range/is-start.js | 28 - .../is-at-end-of-range/after-end-node.js | 28 - .../is-at-end-of-range/after-end-offset.js | 28 - .../is-at-end-of-range/after-start-offset.js | 28 - .../is-at-end-of-range/before-end-offset.js | 28 - .../is-at-end-of-range/before-start-node.js | 28 - .../is-at-end-of-range/before-start-offset.js | 28 - .../point/is-at-end-of-range/between-nodes.js | 28 - .../models/point/is-at-end-of-range/is-end.js | 28 - .../point/is-at-end-of-range/is-start.js | 28 - .../is-at-start-of-range/after-end-node.js | 28 - .../is-at-start-of-range/after-end-offset.js | 28 - .../after-start-offset.js | 28 - .../is-at-start-of-range/before-end-offset.js | 28 - .../is-at-start-of-range/before-start-node.js | 28 - .../before-start-offset.js | 28 - .../is-at-start-of-range/between-nodes.js | 28 - .../point/is-at-start-of-range/is-end.js | 28 - .../point/is-at-start-of-range/is-start.js | 28 - .../is-before-point/after-target-path.js | 20 - .../is-before-point/before-target-path.js | 20 - .../same-node-after-target-offset.js | 20 - .../same-node-before-target-offset.js | 20 - .../is-before-point/same-node-same-offset.js | 20 - .../is-before-point/target-is-ancestor.js | 20 - .../is-before-point/target-is-descendant.js | 20 - .../point/is-before-range/after-end-node.js | 28 - .../point/is-before-range/after-end-offset.js | 28 - .../is-before-range/after-start-offset.js | 28 - .../is-before-range/before-end-offset.js | 28 - .../is-before-range/before-start-node.js | 28 - .../is-before-range/before-start-offset.js | 28 - .../point/is-before-range/between-nodes.js | 28 - .../models/point/is-before-range/is-end.js | 28 - .../models/point/is-before-range/is-start.js | 28 - .../point/is-in-range/after-end-node.js | 28 - .../point/is-in-range/after-end-offset.js | 28 - .../point/is-in-range/after-start-offset.js | 28 - .../point/is-in-range/before-end-offset.js | 28 - .../point/is-in-range/before-start-node.js | 28 - .../point/is-in-range/before-start-offset.js | 28 - .../models/point/is-in-range/between-nodes.js | 28 - .../test/models/point/is-in-range/is-end.js | 28 - .../test/models/point/is-in-range/is-start.js | 28 - .../across-leaves/connectable-after-remove.js | 19 - .../in-connectable-after-remove.js | 20 - .../differently-marked-text.js | 15 - .../delete/all-text-length/marked-text.js | 19 - .../all-text-length/partial-marked-text.js | 21 - .../inside-a-leaf/delete-a-char-with-mark.js | 19 - .../delete/inside-a-leaf/delete-a-char.js | 19 - .../from-end/pure-text-after-marked-text.js | 20 - .../from-end/pure-text-after-pure-text.js | 19 - .../from-end/pure-text-at-end-of-all-text.js | 19 - .../marked-text-in-middle-of-marked-text.js | 23 - .../marked-text-in-middle-of-pure-text.js | 17 - .../pure-text-into-middle-of-marks.js | 19 - .../text/insert/from-middle/pure-text.js | 11 - .../from-start/marked-text-on-null-text.js | 21 - ...ure-text-on-null-text-at-invalid-offset.js | 11 - .../from-start/pure-text-on-null-text.js | 11 - .../text/marks/add-marks/to-affect-nothing.js | 20 - .../marks/add-marks/to-cover-whole-text.js | 16 - .../marks/add-marks/to-merge-two-leaves.js | 21 - .../text/marks/add-marks/to-split-leaves.js | 25 - .../marked-text-at-leaf-end.js | 20 - ...arked-text-with-totally-different-marks.js | 17 - .../null-marked-text.js | 17 - .../get-active-marks/adject-same-marks.js | 20 - .../intersecting-marks-text.js | 25 - .../marks/get-active-marks/marked-text.js | 20 - .../get-active-marks/partially-marked-text.js | 18 - .../get-marks-at-index/null-marked-text.js | 17 - .../marked-text-with-leaf-end.js | 18 - .../marked-text-with-many-leaves.js | 30 - .../get-marks-between/null-marked-text.js | 17 - .../text/marks/get-marks/marked-text.js | 19 - .../marks/get-marks/null-text-with-marks.js | 17 - .../models/text/marks/get-marks/null-text.js | 12 - .../marks/get-marks/partially-marked-text.js | 19 - .../models/text/marks/get-marks/plain-text.js | 12 - .../text/marks/remove-mark/remove-mark.js | 20 - .../marked-text-with-some-other-marks.js | 22 - .../text/marks/update-mark/marked-text.js | 21 - .../null-mark-with-invalid-offset.js | 16 - .../marks/update-mark/null-marked-text.js | 20 - .../merge/empty-leaf-as-next/length-text.js | 22 - .../empty-leaf-as-start/another-empty-text.js | 22 - .../merge/empty-leaf-as-start/length-text.js | 18 - .../raw/deserialize/block-nested.js | 42 - .../raw/deserialize/block-with-data.js | 35 - .../test/serializers/raw/deserialize/block.js | 33 - .../raw/deserialize/inline-nested.js | 75 - .../raw/deserialize/inline-with-data.js | 56 - .../serializers/raw/deserialize/inline.js | 54 - .../raw/deserialize/range-with-mark.js | 51 - .../serializers/raw/serialize/block-nested.js | 42 - .../raw/serialize/block-with-data.js | 35 - .../test/serializers/raw/serialize/block.js | 33 - .../raw/serialize/inline-nested.js | 75 - .../raw/serialize/inline-with-data.js | 56 - .../test/serializers/raw/serialize/inline.js | 54 - .../raw/serialize/preserve-data.js | 38 - .../raw/serialize/preserve-keys.js | 42 - .../serialize/preserve-selection-and-keys.js | 60 - .../raw/serialize/preserve-selection.js | 52 - .../raw/serialize/range-with-mark.js | 51 - .../move-node/from-before-not-younger.js | 30 - .../transform/move-node/from-younger.js | 30 - .../transform/move-node/siblings-backward.js | 17 - .../transform/move-node/siblings-forward.js | 17 - packages/slate/tsconfig.json | 9 + support/benchmark/compare.js | 103 - .../src/index.js => support/fixtures.js | 4 - support/rollup/config.js | 26 - tsconfig.json | 13 + yarn.lock | 2677 ++++++++++------ 529 files changed, 11883 insertions(+), 30796 deletions(-) delete mode 100644 .babelrc create mode 100644 babel.config.js delete mode 100644 benchmark/compare.js delete mode 100644 benchmark/config.js delete mode 100644 benchmark/generate-report.js delete mode 100644 benchmark/helpers/h.js delete mode 100644 benchmark/index.js delete mode 100644 benchmark/slate-html-serializer/html-serializer/deserialize.js delete mode 100644 benchmark/slate-html-serializer/html-serializer/serialize.js delete mode 100644 benchmark/slate-html-serializer/index.js delete mode 100644 benchmark/slate-plain-serializer/index.js delete mode 100644 benchmark/slate-plain-serializer/plain-serializer/deserialize.js delete mode 100644 benchmark/slate-plain-serializer/plain-serializer/serialize.js delete mode 100644 benchmark/slate-react/index.js delete mode 100644 benchmark/slate-react/rendering/decoration.js delete mode 100644 benchmark/slate-react/rendering/large-with-selection.js delete mode 100644 benchmark/slate-react/rendering/normal.js delete mode 100644 benchmark/slate/changes/add-mark.js delete mode 100644 benchmark/slate/changes/delete-backward.js delete mode 100644 benchmark/slate/changes/delete-forward.js delete mode 100644 benchmark/slate/changes/insert-fragment-deep-with-problems.js delete mode 100644 benchmark/slate/changes/insert-fragment-large.js delete mode 100644 benchmark/slate/changes/insert-fragment.js delete mode 100644 benchmark/slate/changes/insert-node-by-key.js delete mode 100644 benchmark/slate/changes/insert-text-by-key.js delete mode 100644 benchmark/slate/changes/insert-text.js delete mode 100644 benchmark/slate/changes/normalize-with-problems.js delete mode 100644 benchmark/slate/changes/normalize.js delete mode 100644 benchmark/slate/changes/remove-node-by-key.js delete mode 100644 benchmark/slate/changes/set-blocks.js delete mode 100644 benchmark/slate/changes/split-block.js delete mode 100644 benchmark/slate/index.js delete mode 100644 benchmark/slate/models/from-json-big.js delete mode 100644 benchmark/slate/models/from-json.js delete mode 100644 benchmark/slate/models/get-active-marks-at-range.js delete mode 100644 benchmark/slate/models/get-ancestors.js delete mode 100644 benchmark/slate/models/get-blocks.js delete mode 100644 benchmark/slate/models/get-common-ancestor.js delete mode 100644 benchmark/slate/models/get-descendant.js delete mode 100644 benchmark/slate/models/get-furthest-ancestor.js delete mode 100644 benchmark/slate/models/get-inlines.js delete mode 100644 benchmark/slate/models/get-leaf-blocks-at-range.js delete mode 100644 benchmark/slate/models/get-leaf-inlines-at-range.js delete mode 100644 benchmark/slate/models/get-leaves.js delete mode 100644 benchmark/slate/models/get-marks-at-range.js delete mode 100644 benchmark/slate/models/get-marks.js delete mode 100644 benchmark/slate/models/get-parent.js delete mode 100644 benchmark/slate/models/get-path.js delete mode 100644 benchmark/slate/models/get-texts-at-range.js delete mode 100644 benchmark/slate/models/get-texts.js delete mode 100644 benchmark/slate/models/has-node-multiple.js delete mode 100644 benchmark/slate/models/has-node.js delete mode 100644 benchmark/slate/models/to-json.js rename {support => config}/rollup/factory.js (68%) create mode 100644 config/rollup/rollup.config.js create mode 100644 config/typescript/tsconfig.json rename {support => config}/webpack/config.js (100%) delete mode 100644 packages/slate-dev-benchmark/Readme.md delete mode 100644 packages/slate-dev-benchmark/package.json delete mode 100644 packages/slate-dev-benchmark/src/Bench.js delete mode 100644 packages/slate-dev-benchmark/src/Repository.js delete mode 100644 packages/slate-dev-benchmark/src/Suite.js delete mode 100644 packages/slate-dev-benchmark/src/Timer.js delete mode 100644 packages/slate-dev-benchmark/src/compose.js delete mode 100644 packages/slate-dev-benchmark/src/index.js delete mode 100644 packages/slate-dev-benchmark/src/logger.js delete mode 100644 packages/slate-dev-benchmark/src/makeOptions.js delete mode 100644 packages/slate-dev-benchmark/src/types.js delete mode 100644 packages/slate-dev-benchmark/test/index.js delete mode 100644 packages/slate-dev-benchmark/test/time/index.js delete mode 100644 packages/slate-dev-benchmark/test/time/max-time-async.js delete mode 100644 packages/slate-dev-benchmark/test/time/max-time-with-small-step.js delete mode 100644 packages/slate-dev-benchmark/test/time/max-time.js delete mode 100644 packages/slate-dev-benchmark/test/tries/index.js delete mode 100644 packages/slate-dev-benchmark/test/tries/max-tries.js delete mode 100644 packages/slate-dev-benchmark/test/tries/min-tries.js delete mode 100644 packages/slate-dev-benchmark/test/utils/sleep.js delete mode 100644 packages/slate-dev-test-utils/Readme.md delete mode 100644 packages/slate-dev-test-utils/package.json delete mode 100644 packages/slate-dev-test-utils/test/index.js delete mode 100644 packages/slate-hyperscript/src/creators.js create mode 100644 packages/slate-hyperscript/src/creators.ts delete mode 100644 packages/slate-hyperscript/src/index.js create mode 100644 packages/slate-hyperscript/src/index.ts create mode 100644 packages/slate-hyperscript/src/resolve-descendants.ts create mode 100644 packages/slate-hyperscript/src/tokens.ts delete mode 100644 packages/slate-hyperscript/test/annotations/across-blocks.js delete mode 100644 packages/slate-hyperscript/test/annotations/across-marks.js delete mode 100644 packages/slate-hyperscript/test/annotations/deep-anchors.js delete mode 100644 packages/slate-hyperscript/test/annotations/intersecting-marks.js delete mode 100644 packages/slate-hyperscript/test/annotations/multiple.js delete mode 100644 packages/slate-hyperscript/test/annotations/nested.js delete mode 100644 packages/slate-hyperscript/test/annotations/overlapping.js delete mode 100644 packages/slate-hyperscript/test/fixtures/annotation-across-block.js create mode 100644 packages/slate-hyperscript/test/fixtures/annotation-across-element.js create mode 100644 packages/slate-hyperscript/test/fixtures/annotation-across-elements.js create mode 100644 packages/slate-hyperscript/test/fixtures/annotation-across-mark.js create mode 100644 packages/slate-hyperscript/test/fixtures/annotation-across-marks.js delete mode 100644 packages/slate-hyperscript/test/fixtures/annotation-across-multiple-blocks.js create mode 100644 packages/slate-hyperscript/test/fixtures/annotation-custom.js create mode 100644 packages/slate-hyperscript/test/fixtures/annotation-nested.js create mode 100644 packages/slate-hyperscript/test/fixtures/annotation-overlapping.js delete mode 100644 packages/slate-hyperscript/test/fixtures/block-empty.js delete mode 100644 packages/slate-hyperscript/test/fixtures/block-inline-empty.js delete mode 100644 packages/slate-hyperscript/test/fixtures/block-mark-empty.js delete mode 100644 packages/slate-hyperscript/test/fixtures/block-mark-full.js delete mode 100644 packages/slate-hyperscript/test/fixtures/block-mark-multiple.js delete mode 100644 packages/slate-hyperscript/test/fixtures/block-mark-nested.js delete mode 100644 packages/slate-hyperscript/test/fixtures/block-string.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-block.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-blocks-and-inlines.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-blocks-end.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-blocks-middle.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-blocks-start.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-element.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-empty-blocks.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-end.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-middle.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-start.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-block-end.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-block-middle.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-block-start.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-custom-block-middle.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-element-empty.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-element-end.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-element-middle.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-element-start.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-empty-text-with-key.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-empty-text.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-inline-end.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-inline-start.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-inline.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js delete mode 100644 packages/slate-hyperscript/test/fixtures/cursor-mark.js create mode 100644 packages/slate-hyperscript/test/fixtures/cursor-text-empty.js delete mode 100644 packages/slate-hyperscript/test/fixtures/custom-marks-with-text.js delete mode 100644 packages/slate-hyperscript/test/fixtures/custom-tags.js create mode 100644 packages/slate-hyperscript/test/fixtures/element-custom.js rename packages/slate-hyperscript/test/fixtures/{document-empty.js => element-empty.js} (56%) create mode 100644 packages/slate-hyperscript/test/fixtures/element-nested-empty.js rename packages/slate-hyperscript/test/fixtures/{block-inline-full.js => element-nested-string.js} (50%) rename packages/slate-hyperscript/test/fixtures/{inline-full.js => element-string.js} (53%) rename packages/slate-hyperscript/test/fixtures/{block-text-empty.js => element-text-empty.js} (61%) rename packages/slate-hyperscript/test/fixtures/{block-text-full.js => element-text-string.js} (62%) delete mode 100644 packages/slate-hyperscript/test/fixtures/inline-empty.js create mode 100644 packages/slate-hyperscript/test/fixtures/mark-custom.js create mode 100644 packages/slate-hyperscript/test/fixtures/mark-nested-string.js create mode 100644 packages/slate-hyperscript/test/fixtures/mark-string.js create mode 100644 packages/slate-hyperscript/test/fixtures/mark-text.js delete mode 100644 packages/slate-hyperscript/test/fixtures/text-with-key.js create mode 100644 packages/slate-hyperscript/test/fixtures/value-empty.js create mode 100644 packages/slate-hyperscript/tsconfig.json create mode 100644 packages/slate-parse-plaintext/Changelog.md create mode 100644 packages/slate-parse-plaintext/Readme.md create mode 100644 packages/slate-parse-plaintext/package.json create mode 100644 packages/slate-parse-plaintext/src/index.ts create mode 100644 packages/slate-parse-plaintext/test/fixtures/delimiter.js create mode 100644 packages/slate-parse-plaintext/test/fixtures/element-props.js create mode 100644 packages/slate-parse-plaintext/test/fixtures/line-multiple.js create mode 100644 packages/slate-parse-plaintext/test/fixtures/line-single.js create mode 100644 packages/slate-parse-plaintext/test/fixtures/text-props.js create mode 100644 packages/slate-parse-plaintext/test/index.js create mode 100644 packages/slate-parse-plaintext/tsconfig.json create mode 100644 packages/slate-render-plaintext/Changelog.md create mode 100644 packages/slate-render-plaintext/Readme.md create mode 100644 packages/slate-render-plaintext/package.json create mode 100644 packages/slate-render-plaintext/src/index.ts create mode 100644 packages/slate-render-plaintext/test/fixtures/block-custom-property.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block-mark.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block-multiple-empty.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block-multiple.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block-nested-inline-nested.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block-nested-inline.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block-nested-nested.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block-nested.js create mode 100644 packages/slate-render-plaintext/test/fixtures/block.js create mode 100644 packages/slate-render-plaintext/test/fixtures/custom-delimiter.js create mode 100644 packages/slate-render-plaintext/test/fixtures/inline-custom-property.js create mode 100644 packages/slate-render-plaintext/test/fixtures/inline-mark.js create mode 100644 packages/slate-render-plaintext/test/fixtures/inline-nested.js create mode 100644 packages/slate-render-plaintext/test/fixtures/inline.js create mode 100644 packages/slate-render-plaintext/test/index.js create mode 100644 packages/slate-render-plaintext/tsconfig.json create mode 100755 packages/slate/src/classes/commands/annotation.ts create mode 100755 packages/slate/src/classes/commands/path.ts create mode 100755 packages/slate/src/classes/commands/point.ts create mode 100755 packages/slate/src/classes/commands/range.ts create mode 100755 packages/slate/src/classes/commands/selection.ts create mode 100755 packages/slate/src/classes/commands/value.ts create mode 100755 packages/slate/src/classes/editor.ts create mode 100644 packages/slate/src/classes/path-ref.ts create mode 100644 packages/slate/src/classes/point-ref.ts create mode 100644 packages/slate/src/classes/queries/mark.ts create mode 100644 packages/slate/src/classes/queries/node.ts create mode 100644 packages/slate/src/classes/queries/path.ts create mode 100644 packages/slate/src/classes/queries/point.ts create mode 100644 packages/slate/src/classes/queries/range.ts create mode 100644 packages/slate/src/classes/queries/value.ts create mode 100644 packages/slate/src/classes/range-ref.ts delete mode 100644 packages/slate/src/commands/at-point.js delete mode 100644 packages/slate/src/commands/at-range.js delete mode 100644 packages/slate/src/commands/by-path.js delete mode 100644 packages/slate/src/commands/on-history.js delete mode 100644 packages/slate/src/commands/on-selection.js delete mode 100644 packages/slate/src/commands/on-value.js delete mode 100644 packages/slate/src/commands/with-intent.js delete mode 100644 packages/slate/src/controllers/editor.js delete mode 100644 packages/slate/src/index.js create mode 100755 packages/slate/src/index.ts create mode 100755 packages/slate/src/interfaces/annotation.ts create mode 100644 packages/slate/src/interfaces/change.ts delete mode 100644 packages/slate/src/interfaces/element.js create mode 100755 packages/slate/src/interfaces/element.ts create mode 100755 packages/slate/src/interfaces/fragment.ts create mode 100755 packages/slate/src/interfaces/mark.ts delete mode 100644 packages/slate/src/interfaces/model.js delete mode 100644 packages/slate/src/interfaces/node.js create mode 100755 packages/slate/src/interfaces/node.ts delete mode 100644 packages/slate/src/interfaces/object.js create mode 100755 packages/slate/src/interfaces/operation.ts create mode 100755 packages/slate/src/interfaces/path.ts create mode 100755 packages/slate/src/interfaces/point.ts delete mode 100644 packages/slate/src/interfaces/range.js create mode 100755 packages/slate/src/interfaces/range.ts create mode 100755 packages/slate/src/interfaces/selection.ts create mode 100644 packages/slate/src/interfaces/string.ts create mode 100755 packages/slate/src/interfaces/text.ts create mode 100755 packages/slate/src/interfaces/value.ts delete mode 100644 packages/slate/src/models/annotation.js delete mode 100644 packages/slate/src/models/block.js delete mode 100644 packages/slate/src/models/change.js delete mode 100644 packages/slate/src/models/data.js delete mode 100644 packages/slate/src/models/decoration.js delete mode 100644 packages/slate/src/models/document.js delete mode 100644 packages/slate/src/models/inline.js delete mode 100644 packages/slate/src/models/leaf.js delete mode 100644 packages/slate/src/models/mark.js delete mode 100644 packages/slate/src/models/node.js delete mode 100644 packages/slate/src/models/operation.js delete mode 100644 packages/slate/src/models/point.js delete mode 100644 packages/slate/src/models/range.js delete mode 100644 packages/slate/src/models/selection.js delete mode 100644 packages/slate/src/models/text.js delete mode 100644 packages/slate/src/models/value.js delete mode 100644 packages/slate/src/operations/apply.js delete mode 100644 packages/slate/src/operations/index.js delete mode 100644 packages/slate/src/operations/invert.js delete mode 100644 packages/slate/src/plugins/core/core-commands.js delete mode 100644 packages/slate/src/plugins/core/core-queries.js delete mode 100644 packages/slate/src/plugins/core/core-schema.js delete mode 100644 packages/slate/src/plugins/core/index.js create mode 100644 packages/slate/src/plugins/history/history.ts create mode 100644 packages/slate/src/plugins/history/index.ts create mode 100644 packages/slate/src/plugins/history/plugin.ts create mode 100644 packages/slate/src/plugins/schema/checkers.ts create mode 100644 packages/slate/src/plugins/schema/error.ts delete mode 100644 packages/slate/src/plugins/schema/index.js create mode 100644 packages/slate/src/plugins/schema/index.ts create mode 100644 packages/slate/src/plugins/schema/plugin.ts create mode 100644 packages/slate/src/plugins/schema/rule.ts delete mode 100644 packages/slate/src/queries/format.js delete mode 100644 packages/slate/src/queries/node.js delete mode 100644 packages/slate/src/queries/path.js delete mode 100644 packages/slate/src/queries/point.js delete mode 100644 packages/slate/src/queries/range.js create mode 100644 packages/slate/src/symbols.ts delete mode 100644 packages/slate/src/utils/identity.js delete mode 100644 packages/slate/src/utils/is-object.js delete mode 100644 packages/slate/src/utils/key-utils.js delete mode 100644 packages/slate/src/utils/memoize.js delete mode 100644 packages/slate/src/utils/mixin.js delete mode 100644 packages/slate/src/utils/path-utils.js delete mode 100644 packages/slate/src/utils/slate-error.js delete mode 100644 packages/slate/src/utils/text-utils.js delete mode 100644 packages/slate/test/changes/at-range/insert-text-at-range/non-matching-section-and-range.js delete mode 100644 packages/slate/test/controllers/editor/has/exists.js delete mode 100644 packages/slate/test/controllers/editor/has/missing.js create mode 100644 packages/slate/test/interfaces/Path/transform/move_node/ends-after-to-ends-before.js create mode 100644 packages/slate/test/interfaces/Path/transform/move_node/ends-before-to-ends-after.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/point/offset-after.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/point/offset-before.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/point/path-after.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/point/path-before.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/point/path-equal.js delete mode 100644 packages/slate/test/models/node/get-active-marks-at-range.js/different-marks-across-blocks.js delete mode 100644 packages/slate/test/models/node/get-active-marks-at-range.js/mixed-marks-across-range.js delete mode 100644 packages/slate/test/models/node/get-active-marks-at-range.js/same-mark-across-blocks.js delete mode 100644 packages/slate/test/models/node/get-ancestors/from-block.js delete mode 100644 packages/slate/test/models/node/get-ancestors/from-document.js delete mode 100644 packages/slate/test/models/node/get-ancestors/from-inline.js delete mode 100644 packages/slate/test/models/node/get-ancestors/from-text-blocks-nested.js delete mode 100644 packages/slate/test/models/node/get-ancestors/from-text-inline.js delete mode 100644 packages/slate/test/models/node/get-ancestors/from-text.js delete mode 100644 packages/slate/test/models/node/get-closest/by-path.js delete mode 100644 packages/slate/test/models/node/get-closest/get-block-parent-inline.js delete mode 100644 packages/slate/test/models/node/get-closest/top-level.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-spanning-first-text.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-beginning-of-text.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-end-of-text.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-middle-of-text.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/single-block-with-inline.js delete mode 100644 packages/slate/test/models/node/get-descendants-at-range/single-void-block.js delete mode 100644 packages/slate/test/models/node/get-fragment-at-range/across-block-with-marks.js delete mode 100644 packages/slate/test/models/node/get-fragment-at-range/block-across.js delete mode 100644 packages/slate/test/models/node/get-fragment-at-range/block.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-spanning-first-text.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/single-block-with-inline.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/single-block.js delete mode 100644 packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js delete mode 100644 packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks-no-inline.js delete mode 100644 packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-leaf-inlines-at-range/nested-with-text-on-every-level.js delete mode 100644 packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-no-previous-text.js delete mode 100644 packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-previous-text-not-in-the-same-block.js delete mode 100644 packages/slate/test/models/node/get-marks-at-point/marked-text.js delete mode 100644 packages/slate/test/models/node/get-marks-at-point/text-with-zero-offset.js delete mode 100644 packages/slate/test/models/node/get-marks-at-point/unmarked-text.js delete mode 100644 packages/slate/test/models/node/get-next-block/by-path.js delete mode 100644 packages/slate/test/models/node/get-next-block/multiple-siblings-to-bypass.js delete mode 100644 packages/slate/test/models/node/get-next-block/next-block-is-ancestor-sibling.js delete mode 100644 packages/slate/test/models/node/get-next-block/next-block-is-in-sibling-with-deeper-blocks.js delete mode 100644 packages/slate/test/models/node/get-next-block/next-block-is-sibling-descendent.js delete mode 100644 packages/slate/test/models/node/get-next-block/next-block-is-sibling.js delete mode 100644 packages/slate/test/models/node/get-next-block/no-next-block.js delete mode 100644 packages/slate/test/models/node/get-next-block/no-next-node.js delete mode 100644 packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling-with-nested-blocks.js delete mode 100644 packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling.js delete mode 100644 packages/slate/test/models/node/get-previous-block/by-path.js delete mode 100644 packages/slate/test/models/node/get-previous-block/multiple-siblings-to-bypass.js delete mode 100644 packages/slate/test/models/node/get-previous-block/no-prev-block.js delete mode 100644 packages/slate/test/models/node/get-previous-block/no-prev-node.js delete mode 100644 packages/slate/test/models/node/get-previous-block/prev-block-is-ancestor-sibling.js delete mode 100644 packages/slate/test/models/node/get-previous-block/prev-block-is-in-sibling-with-deeper-blocks.js delete mode 100644 packages/slate/test/models/node/get-previous-block/prev-block-is-sibling-descendent.js delete mode 100644 packages/slate/test/models/node/get-previous-block/prev-block-is-sibling.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-spanning-first-text.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/single-block-with-inline.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/single-block.js delete mode 100644 packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js delete mode 100644 packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks-no-inline.js delete mode 100644 packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks.js delete mode 100644 packages/slate/test/models/node/get-root-inlines-at-range/nested-with-text-on-every-level.js delete mode 100644 packages/slate/test/models/node/is-in-range/block-above.js delete mode 100644 packages/slate/test/models/node/is-in-range/block-below.js delete mode 100644 packages/slate/test/models/node/is-in-range/first-block-inside.js delete mode 100644 packages/slate/test/models/node/is-in-range/first-text-inside.js delete mode 100644 packages/slate/test/models/node/is-in-range/last-block-inside.js delete mode 100644 packages/slate/test/models/node/is-in-range/last-text-inside.js delete mode 100644 packages/slate/test/models/node/is-in-range/text-above.js delete mode 100644 packages/slate/test/models/node/is-in-range/text-below.js delete mode 100644 packages/slate/test/models/node/is-in-range/text-in-middle-inside.js delete mode 100644 packages/slate/test/models/operation/create/add-mark-with-data.js delete mode 100644 packages/slate/test/models/operation/create/add-mark-without-data.js delete mode 100644 packages/slate/test/models/point/is-after-point/after-target-path.js delete mode 100644 packages/slate/test/models/point/is-after-point/before-target-path.js delete mode 100644 packages/slate/test/models/point/is-after-point/same-node-after-target-offset.js delete mode 100644 packages/slate/test/models/point/is-after-point/same-node-before-target-offset.js delete mode 100644 packages/slate/test/models/point/is-after-point/same-node-same-offset.js delete mode 100644 packages/slate/test/models/point/is-after-point/target-is-ancestor.js delete mode 100644 packages/slate/test/models/point/is-after-point/target-is-descendant.js delete mode 100644 packages/slate/test/models/point/is-after-range/after-end-node.js delete mode 100644 packages/slate/test/models/point/is-after-range/after-end-offset.js delete mode 100644 packages/slate/test/models/point/is-after-range/after-start-offset.js delete mode 100644 packages/slate/test/models/point/is-after-range/before-end-offset.js delete mode 100644 packages/slate/test/models/point/is-after-range/before-start-node.js delete mode 100644 packages/slate/test/models/point/is-after-range/before-start-offset.js delete mode 100644 packages/slate/test/models/point/is-after-range/between-nodes.js delete mode 100644 packages/slate/test/models/point/is-after-range/is-end.js delete mode 100644 packages/slate/test/models/point/is-after-range/is-start.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/after-end-node.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/after-end-offset.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/after-start-offset.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/before-end-offset.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/before-start-node.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/before-start-offset.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/between-nodes.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/is-end.js delete mode 100644 packages/slate/test/models/point/is-at-end-of-range/is-start.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/after-end-node.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/after-end-offset.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/after-start-offset.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/before-end-offset.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/before-start-node.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/before-start-offset.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/between-nodes.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/is-end.js delete mode 100644 packages/slate/test/models/point/is-at-start-of-range/is-start.js delete mode 100644 packages/slate/test/models/point/is-before-point/after-target-path.js delete mode 100644 packages/slate/test/models/point/is-before-point/before-target-path.js delete mode 100644 packages/slate/test/models/point/is-before-point/same-node-after-target-offset.js delete mode 100644 packages/slate/test/models/point/is-before-point/same-node-before-target-offset.js delete mode 100644 packages/slate/test/models/point/is-before-point/same-node-same-offset.js delete mode 100644 packages/slate/test/models/point/is-before-point/target-is-ancestor.js delete mode 100644 packages/slate/test/models/point/is-before-point/target-is-descendant.js delete mode 100644 packages/slate/test/models/point/is-before-range/after-end-node.js delete mode 100644 packages/slate/test/models/point/is-before-range/after-end-offset.js delete mode 100644 packages/slate/test/models/point/is-before-range/after-start-offset.js delete mode 100644 packages/slate/test/models/point/is-before-range/before-end-offset.js delete mode 100644 packages/slate/test/models/point/is-before-range/before-start-node.js delete mode 100644 packages/slate/test/models/point/is-before-range/before-start-offset.js delete mode 100644 packages/slate/test/models/point/is-before-range/between-nodes.js delete mode 100644 packages/slate/test/models/point/is-before-range/is-end.js delete mode 100644 packages/slate/test/models/point/is-before-range/is-start.js delete mode 100644 packages/slate/test/models/point/is-in-range/after-end-node.js delete mode 100644 packages/slate/test/models/point/is-in-range/after-end-offset.js delete mode 100644 packages/slate/test/models/point/is-in-range/after-start-offset.js delete mode 100644 packages/slate/test/models/point/is-in-range/before-end-offset.js delete mode 100644 packages/slate/test/models/point/is-in-range/before-start-node.js delete mode 100644 packages/slate/test/models/point/is-in-range/before-start-offset.js delete mode 100644 packages/slate/test/models/point/is-in-range/between-nodes.js delete mode 100644 packages/slate/test/models/point/is-in-range/is-end.js delete mode 100644 packages/slate/test/models/point/is-in-range/is-start.js delete mode 100644 packages/slate/test/models/text/delete/across-leaves/connectable-after-remove.js delete mode 100644 packages/slate/test/models/text/delete/across-leaves/in-connectable-after-remove.js delete mode 100644 packages/slate/test/models/text/delete/all-text-length/differently-marked-text.js delete mode 100644 packages/slate/test/models/text/delete/all-text-length/marked-text.js delete mode 100644 packages/slate/test/models/text/delete/all-text-length/partial-marked-text.js delete mode 100644 packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char-with-mark.js delete mode 100644 packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char.js delete mode 100644 packages/slate/test/models/text/insert/from-end/pure-text-after-marked-text.js delete mode 100644 packages/slate/test/models/text/insert/from-end/pure-text-after-pure-text.js delete mode 100644 packages/slate/test/models/text/insert/from-end/pure-text-at-end-of-all-text.js delete mode 100644 packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-marked-text.js delete mode 100644 packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-pure-text.js delete mode 100644 packages/slate/test/models/text/insert/from-middle/pure-text-into-middle-of-marks.js delete mode 100644 packages/slate/test/models/text/insert/from-middle/pure-text.js delete mode 100644 packages/slate/test/models/text/insert/from-start/marked-text-on-null-text.js delete mode 100644 packages/slate/test/models/text/insert/from-start/pure-text-on-null-text-at-invalid-offset.js delete mode 100644 packages/slate/test/models/text/insert/from-start/pure-text-on-null-text.js delete mode 100644 packages/slate/test/models/text/marks/add-marks/to-affect-nothing.js delete mode 100644 packages/slate/test/models/text/marks/add-marks/to-cover-whole-text.js delete mode 100644 packages/slate/test/models/text/marks/add-marks/to-merge-two-leaves.js delete mode 100644 packages/slate/test/models/text/marks/add-marks/to-split-leaves.js delete mode 100644 packages/slate/test/models/text/marks/get-active-marks-between/marked-text-at-leaf-end.js delete mode 100644 packages/slate/test/models/text/marks/get-active-marks-between/marked-text-with-totally-different-marks.js delete mode 100644 packages/slate/test/models/text/marks/get-active-marks-between/null-marked-text.js delete mode 100644 packages/slate/test/models/text/marks/get-active-marks/adject-same-marks.js delete mode 100644 packages/slate/test/models/text/marks/get-active-marks/intersecting-marks-text.js delete mode 100644 packages/slate/test/models/text/marks/get-active-marks/marked-text.js delete mode 100644 packages/slate/test/models/text/marks/get-active-marks/partially-marked-text.js delete mode 100644 packages/slate/test/models/text/marks/get-marks-at-index/null-marked-text.js delete mode 100644 packages/slate/test/models/text/marks/get-marks-between/marked-text-with-leaf-end.js delete mode 100644 packages/slate/test/models/text/marks/get-marks-between/marked-text-with-many-leaves.js delete mode 100644 packages/slate/test/models/text/marks/get-marks-between/null-marked-text.js delete mode 100644 packages/slate/test/models/text/marks/get-marks/marked-text.js delete mode 100644 packages/slate/test/models/text/marks/get-marks/null-text-with-marks.js delete mode 100644 packages/slate/test/models/text/marks/get-marks/null-text.js delete mode 100644 packages/slate/test/models/text/marks/get-marks/partially-marked-text.js delete mode 100644 packages/slate/test/models/text/marks/get-marks/plain-text.js delete mode 100644 packages/slate/test/models/text/marks/remove-mark/remove-mark.js delete mode 100644 packages/slate/test/models/text/marks/update-mark/marked-text-with-some-other-marks.js delete mode 100644 packages/slate/test/models/text/marks/update-mark/marked-text.js delete mode 100644 packages/slate/test/models/text/marks/update-mark/null-mark-with-invalid-offset.js delete mode 100644 packages/slate/test/models/text/marks/update-mark/null-marked-text.js delete mode 100644 packages/slate/test/models/text/merge/empty-leaf-as-next/length-text.js delete mode 100644 packages/slate/test/models/text/merge/empty-leaf-as-start/another-empty-text.js delete mode 100644 packages/slate/test/models/text/merge/empty-leaf-as-start/length-text.js delete mode 100644 packages/slate/test/serializers/raw/deserialize/block-nested.js delete mode 100644 packages/slate/test/serializers/raw/deserialize/block-with-data.js delete mode 100644 packages/slate/test/serializers/raw/deserialize/block.js delete mode 100644 packages/slate/test/serializers/raw/deserialize/inline-nested.js delete mode 100644 packages/slate/test/serializers/raw/deserialize/inline-with-data.js delete mode 100644 packages/slate/test/serializers/raw/deserialize/inline.js delete mode 100644 packages/slate/test/serializers/raw/deserialize/range-with-mark.js delete mode 100644 packages/slate/test/serializers/raw/serialize/block-nested.js delete mode 100644 packages/slate/test/serializers/raw/serialize/block-with-data.js delete mode 100644 packages/slate/test/serializers/raw/serialize/block.js delete mode 100644 packages/slate/test/serializers/raw/serialize/inline-nested.js delete mode 100644 packages/slate/test/serializers/raw/serialize/inline-with-data.js delete mode 100644 packages/slate/test/serializers/raw/serialize/inline.js delete mode 100644 packages/slate/test/serializers/raw/serialize/preserve-data.js delete mode 100644 packages/slate/test/serializers/raw/serialize/preserve-keys.js delete mode 100644 packages/slate/test/serializers/raw/serialize/preserve-selection-and-keys.js delete mode 100644 packages/slate/test/serializers/raw/serialize/preserve-selection.js delete mode 100644 packages/slate/test/serializers/raw/serialize/range-with-mark.js delete mode 100644 packages/slate/test/utils/path-utils/transform/move-node/from-before-not-younger.js delete mode 100644 packages/slate/test/utils/path-utils/transform/move-node/from-younger.js delete mode 100644 packages/slate/test/utils/path-utils/transform/move-node/siblings-backward.js delete mode 100644 packages/slate/test/utils/path-utils/transform/move-node/siblings-forward.js create mode 100644 packages/slate/tsconfig.json delete mode 100644 support/benchmark/compare.js rename packages/slate-dev-test-utils/src/index.js => support/fixtures.js (85%) delete mode 100644 support/rollup/config.js create mode 100644 tsconfig.json diff --git a/.babelrc b/.babelrc deleted file mode 100644 index b2c668c74d..0000000000 --- a/.babelrc +++ /dev/null @@ -1,64 +0,0 @@ -{ - "presets": [ - [ - "env", - { - "modules": false - } - ], - "react", - "stage-0" - ], - "plugins": ["external-helpers"], - "env": { - "webpack": { - "presets": [ - [ - "env", - { - "modules": false - } - ], - "react", - "stage-0" - ], - "plugins": ["transform-runtime", "react-hot-loader/babel"] - }, - "test": { - "presets": [ - [ - "env", - { - "exclude": ["transform-regenerator"] - } - ], - "react", - "stage-0" - ], - "plugins": [ - "transform-runtime", - [ - "module-resolver", - { - "alias": { - "^(slate.*)": "./packages/\\1/src" - } - } - ] - ] - }, - "benchmark": { - "presets": [ - [ - "env", - { - "exclude": ["transform-regenerator"] - } - ], - "react", - "stage-0" - ], - "plugins": ["transform-runtime"] - } - } -} diff --git a/.prettierignore b/.prettierignore index a24a71a6a6..5154ba7af7 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,3 +4,4 @@ package.json packages/*/dist/ packages/*/lib/ tmp/ +.babelrc diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000000..38a21d9b67 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,29 @@ +module.exports = { + presets: [ + '@babel/preset-typescript', + ['@babel/preset-env', { modules: false }], + '@babel/preset-react', + ], + plugins: [ + '@babel/plugin-transform-runtime', + '@babel/plugin-proposal-class-properties', + ], + env: { + webpack: { + presets: [ + '@babel/preset-typescript', + ['@babel/preset-env', { modules: false }], + '@babel/preset-react', + ], + plugins: ['@babel/plugin-transform-runtime', 'react-hot-loader/babel'], + }, + test: { + inputSourceMap: true, + presets: [ + '@babel/preset-typescript', + ['@babel/preset-env', { targets: { node: 'current' } }], + '@babel/preset-react', + ], + }, + }, +} diff --git a/benchmark/compare.js b/benchmark/compare.js deleted file mode 100644 index 7a9e87c207..0000000000 --- a/benchmark/compare.js +++ /dev/null @@ -1,115 +0,0 @@ -/* eslint-disable no-console */ - -const chalk = require('chalk') -const figures = require('figures') -const emojis = require('emojis') -const { resolve } = require('path') - -const baseline = require(resolve(process.cwd(), 'tmp/benchmark-baseline')) -const comparison = require(resolve(process.cwd(), 'tmp/benchmark-comparison')) -const { existsSync } = require('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() diff --git a/benchmark/config.js b/benchmark/config.js deleted file mode 100644 index 3179a415ca..0000000000 --- a/benchmark/config.js +++ /dev/null @@ -1,39 +0,0 @@ -const { resolve } = require('path') -const { existsSync } = require('fs') -const program = require('commander') - -program - .option('-g, --grep []', 'Add grep pattern to filter running benchmarks') - .option('-c, --config [file]', 'Add config to filter running benchmarks') - .parse(process.argv) - -const { grep } = program - -if (grep) { - const pattern = new RegExp(grep) - - module.exports.include = { - slate: pattern, - 'slate-html-serializer': pattern, - 'slate-plain-serializer': pattern, - 'slate-react': pattern, - } -} else { - let { config = 'tmp/benchmark-config.js' } = program - config = resolve(config) - - const userConfig = existsSync(config) ? require(config) : {} - - if (userConfig.include) { - module.exports.include = userConfig.include - } else if (userConfig.default) { - module.exports.inlcude = userConfig.default - } else { - module.exports.include = { - slate: /^/, - 'slate-html-serializer': /^/, - 'slate-plain-serializer': /^/, - 'slate-react': /^/, - } - } -} diff --git a/benchmark/generate-report.js b/benchmark/generate-report.js deleted file mode 100644 index aac443d4ac..0000000000 --- a/benchmark/generate-report.js +++ /dev/null @@ -1,57 +0,0 @@ -const { writeFileSync } = require('fs') - -function convertRepo(report) { - const result = [] - - for (const name in report) { - const suite = report[name] - - result.push({ - name, - type: 'suite', - benchmarks: convertSuite(suite), - }) - } - return result -} - -function convertSuite(suite) { - const result = [] - - for (const name in suite) { - const bench = suite[name] - const { user, cycles } = bench - - result.push({ - name, - type: 'bench', - elapsed: user, - iterations: cycles, - ops: 1000 * cycles / user, - ...bench, - }) - } - return result -} - -const IS_COMPARE = process.env.COMPARE -const filePath = IS_COMPARE - ? './tmp/benchmark-comparison.json' - : './tmp/benchmark-baseline.json' - -function generateReport(repo) { - repo - .run() - .then(report => { - const data = JSON.stringify(convertRepo(report)) - writeFileSync(filePath, data) - return report - }) - .then(report => { - if (IS_COMPARE) { - require('./compare') - } - }) -} - -module.exports = { generateReport } diff --git a/benchmark/helpers/h.js b/benchmark/helpers/h.js deleted file mode 100644 index e84420cb2e..0000000000 --- a/benchmark/helpers/h.js +++ /dev/null @@ -1,45 +0,0 @@ -/* eslint-disable import/no-extraneous-dependencies */ -const { createHyperscript } = require('slate-hyperscript') - -/** - * Define a hyperscript. - * - * @type {Function} - */ - -const h = createHyperscript({ - blocks: { - line: 'line', - paragraph: 'paragraph', - quote: 'quote', - code: 'code', - list: 'list', - item: 'item', - image: 'image', - table: 'table', - tbody: 'tbody', - tr: 'tr', - td: 'td', - thead: 'thead', - th: 'th', - }, - inlines: { - link: 'link', - hashtag: 'hashtag', - comment: 'comment', - emoji: 'emoji', - }, - marks: { - b: 'bold', - i: 'italic', - u: 'underline', - }, -}) - -/** - * Export. - * - * @type {Function} - */ - -module.exports = h diff --git a/benchmark/index.js b/benchmark/index.js deleted file mode 100644 index b01f60286f..0000000000 --- a/benchmark/index.js +++ /dev/null @@ -1,20 +0,0 @@ -const { repo } = require('slate-dev-benchmark') -const { resolve } = require('path') -const { readdirSync } = require('fs') -const { generateReport } = require('./generate-report') -const { include } = require('./config') - -const categoryDir = resolve(__dirname) - -const categories = readdirSync(categoryDir).filter( - c => c[0] !== '.' && c.match(/^slate/) -) - -categories.forEach(dir => { - if (include && include[dir]) { - const { run } = require(`./${dir}`) - run(include[dir]) - } -}) - -generateReport(repo) diff --git a/benchmark/slate-html-serializer/html-serializer/deserialize.js b/benchmark/slate-html-serializer/html-serializer/deserialize.js deleted file mode 100644 index 43c3e1ce00..0000000000 --- a/benchmark/slate-html-serializer/html-serializer/deserialize.js +++ /dev/null @@ -1,58 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const Html = require('slate-html-serializer').default -const { JSDOM } = require('jsdom') // eslint-disable-line import/no-extraneous-dependencies - -const html = new Html({ - parseHtml: JSDOM.fragment, - rules: [ - { - deserialize(el, next) { - switch (el.tagName.toLowerCase()) { - case 'blockquote': - return { - object: 'block', - type: 'quote', - nodes: next(el.childNodes), - } - case 'p': { - return { - object: 'block', - type: 'paragraph', - nodes: next(el.childNodes), - } - } - case 'strong': { - return { - object: 'mark', - type: 'bold', - nodes: next(el.childNodes), - } - } - case 'em': { - return { - object: 'mark', - type: 'italic', - nodes: next(el.childNodes), - } - } - } - }, - }, - ], -}) - -module.exports.default = function(string) { - html.deserialize(string) -} - -module.exports.input = ` -
-

- This is editable rich text, much better than a textarea! -

-
-` - .trim() - .repeat(10) diff --git a/benchmark/slate-html-serializer/html-serializer/serialize.js b/benchmark/slate-html-serializer/html-serializer/serialize.js deleted file mode 100644 index f2d3ea76aa..0000000000 --- a/benchmark/slate-html-serializer/html-serializer/serialize.js +++ /dev/null @@ -1,54 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const Html = require('slate-html-serializer').default -const React = require('react') -const h = require('../../helpers/h') -const { JSDOM } = require('jsdom') // eslint-disable-line import/no-extraneous-dependencies - -const html = new Html({ - parseHtml: JSDOM.fragment, - rules: [ - { - serialize(obj, children) { - switch (obj.object) { - case 'block': { - switch (obj.type) { - case 'paragraph': - return React.createElement('p', {}, children) - case 'quote': - return React.createElement('blockquote', {}, children) - } - } - case 'mark': { - switch (obj.type) { - case 'bold': - return React.createElement('strong', {}, children) - case 'italic': - return React.createElement('em', {}, children) - } - } - } - }, - }, - ], -}) - -module.exports.default = function(state) { - html.serialize(state) -} - -module.exports.input = ( - - - {Array.from(Array(10)).map(() => ( - - - This is editable rich text, much better than a - textarea! - - - ))} - - -) diff --git a/benchmark/slate-html-serializer/index.js b/benchmark/slate-html-serializer/index.js deleted file mode 100644 index 237b715b5e..0000000000 --- a/benchmark/slate-html-serializer/index.js +++ /dev/null @@ -1,37 +0,0 @@ -const { readdirSync } = require('fs') -const { basename, extname, resolve } = require('path') -const { resetMemoization } = require('slate') -const { Suite, Bench } = require('slate-dev-benchmark') - -/** - * Benchmarks. - */ - -module.exports.run = function(include) { - const categoryDir = resolve(__dirname) - const categories = readdirSync(categoryDir).filter( - c => c[0] !== '.' && c !== 'index.js' - ) - - categories.forEach(category => { - const suite = new Suite(category, { minTries: 100, minTime: 1000 }) - const benchmarkDir = resolve(categoryDir, category) - const benchmarks = readdirSync(benchmarkDir) - .filter(b => b[0] !== '.' && !!~b.indexOf('.js')) - .map(b => basename(b, extname(b))) - - benchmarks.forEach(benchmark => { - if (include && !benchmark.match(include)) return - const bench = new Bench(suite, benchmark) - const dir = resolve(benchmarkDir, benchmark) - const module = require(dir) - const fn = module.default - bench.input(() => module.input) - - bench.run(input => { - fn(input) - resetMemoization() - }) - }) - }) -} diff --git a/benchmark/slate-plain-serializer/index.js b/benchmark/slate-plain-serializer/index.js deleted file mode 100644 index 8a072ded9c..0000000000 --- a/benchmark/slate-plain-serializer/index.js +++ /dev/null @@ -1,40 +0,0 @@ -const { basename, extname, resolve } = require('path') -const { readdirSync } = require('fs') -const { resetMemoization } = require('slate') -const { Suite, Bench } = require('slate-dev-benchmark') - -/** - * Benchmarks. - */ - -module.exports.run = function(include) { - const categoryDir = resolve(__dirname) - const categories = readdirSync(categoryDir).filter( - c => c[0] !== '.' && c !== 'index.js' - ) - - categories.forEach(category => { - const suite = new Suite(category, { - minTries: 100, - minTime: 1000, - }) - const benchmarkDir = resolve(categoryDir, category) - const benchmarks = readdirSync(benchmarkDir) - .filter(b => b[0] !== '.' && !!~b.indexOf('.js')) - .map(b => basename(b, extname(b))) - - benchmarks.forEach(benchmark => { - if (include && !benchmark.match(include)) return - const bench = new Bench(suite, benchmark) - const dir = resolve(benchmarkDir, benchmark) - const module = require(dir) - const fn = module.default - bench.input(() => module.input) - - bench.run(input => { - fn(input) - resetMemoization() - }) - }) - }) -} diff --git a/benchmark/slate-plain-serializer/plain-serializer/deserialize.js b/benchmark/slate-plain-serializer/plain-serializer/deserialize.js deleted file mode 100644 index d8e4a724a7..0000000000 --- a/benchmark/slate-plain-serializer/plain-serializer/deserialize.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const Plain = require('slate-plain-serializer').default - -const input = ` - This is editable plain text, just like a text area. -` - .trim() - .repeat(10) - -module.exports.input = input - -module.exports.default = function(string) { - Plain.deserialize(string) -} diff --git a/benchmark/slate-plain-serializer/plain-serializer/serialize.js b/benchmark/slate-plain-serializer/plain-serializer/serialize.js deleted file mode 100644 index eb70eab30e..0000000000 --- a/benchmark/slate-plain-serializer/plain-serializer/serialize.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const Plain = require('slate-plain-serializer').default -const h = require('../../helpers/h') - -module.exports.default = function(state) { - Plain.serialize(state) -} - -module.exports.input = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) diff --git a/benchmark/slate-react/index.js b/benchmark/slate-react/index.js deleted file mode 100644 index 438749dbfa..0000000000 --- a/benchmark/slate-react/index.js +++ /dev/null @@ -1,40 +0,0 @@ -const { basename, extname, resolve } = require('path') -const { readdirSync } = require('fs') -const { resetMemoization } = require('slate') -const { Suite, Bench } = require('slate-dev-benchmark') - -/** - * Benchmarks. - */ - -module.exports.run = function(include) { - const categoryDir = resolve(__dirname) - const categories = readdirSync(categoryDir).filter( - c => c[0] !== '.' && c !== 'index.js' - ) - - categories.forEach(category => { - const suite = new Suite(category, { - minTries: 100, - minTime: 1000, - }) - const benchmarkDir = resolve(categoryDir, category) - const benchmarks = readdirSync(benchmarkDir) - .filter(b => b[0] !== '.' && !!~b.indexOf('.js')) - .map(b => basename(b, extname(b))) - - benchmarks.forEach(benchmark => { - if (include && !benchmark.match(include)) return - const bench = new Bench(suite, benchmark) - const dir = resolve(benchmarkDir, benchmark) - const module = require(dir) - const fn = module.default - bench.input(module.input) - - bench.run(input => { - fn(input) - resetMemoization() - }) - }) - }) -} diff --git a/benchmark/slate-react/rendering/decoration.js b/benchmark/slate-react/rendering/decoration.js deleted file mode 100644 index 33bae82644..0000000000 --- a/benchmark/slate-react/rendering/decoration.js +++ /dev/null @@ -1,57 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const React = require('react') -const ReactDOM = require('react-dom/server') -const h = require('../../helpers/h') -const { Editor } = require('slate') -const { Editor: EditorComponent } = require('slate-react') - -module.exports.default = function(value) { - const el = React.createElement(EditorComponent, { value }) - ReactDOM.renderToStaticMarkup(el) -} - -let value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -const texts = value.document.getTexts() -const decorations = texts.flatMap((t, index) => { - if (index % 4 !== 0) return [] - if (t.length === 0) return [] - return [ - { - anchor: { - key: t.key, - offset: 0, - }, - focus: { - key: t.key, - offset: 1, - }, - mark: { - type: 'underline', - }, - }, - ] -}) - -value = value.setProperties({ decorations }) - -const editor = new Editor({ value }) - -module.exports.input = editor.value diff --git a/benchmark/slate-react/rendering/large-with-selection.js b/benchmark/slate-react/rendering/large-with-selection.js deleted file mode 100644 index d4c3af45ea..0000000000 --- a/benchmark/slate-react/rendering/large-with-selection.js +++ /dev/null @@ -1,73 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const React = require('react') -const ReactDOM = require('react-dom/server') -const h = require('../../helpers/h') -const { Editor } = require('slate-react') - -module.exports.default = function(value) { - const el = React.createElement(Editor, { value }) - ReactDOM.renderToStaticMarkup(el) -} - -module.exports.input = ( - - - - Breve whipped ristretto ut as to go café au lait. Extra, skinny - trifecta, cup chicory medium cup dripper whipped coffee cultivar. Body - crema iced whipped, grounds turkish coffee steamed crema affogato.{' '} - Skinny that wings aged cream, grounds siphon coffee french press - mazagran irish roast. - - - - - - - Extra, brewed caffeine fair trade, whipped cup bar flavour grounds - organic. Café au lait blue mountain cortado saucer, macchiato ut - that caramelization flavour. - - - - Crema frappuccino so decaffeinated, sit café au lait irish - cultivar doppio café au lait. Dripper irish fair trade kopi-luwak - ut beans skinny saucer. - - - - - - - Half and half, irish rich sugar medium frappuccino spoon. Whipped, - caramelization, caffeine french press cinnamon variety rich redeye - acerbic americano aftertaste. Shop crema filter seasonal, filter - aromatic, french press mazagran affogato cappuccino single origin. - - - Plunger pot aromatic, crema, cultivar french press, skinny and - percolator so single origin. Id variety and cinnamon brewed - flavour cultivar acerbic half and half et cappuccino. - - - Cup qui a barista crema white kopi-luwak chicory trifecta. - - - - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) diff --git a/benchmark/slate-react/rendering/normal.js b/benchmark/slate-react/rendering/normal.js deleted file mode 100644 index 42d9244b93..0000000000 --- a/benchmark/slate-react/rendering/normal.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const React = require('react') -const ReactDOM = require('react-dom/server') -const h = require('../../helpers/h') -const { Editor } = require('slate-react') - -module.exports.default = function(value) { - const el = React.createElement(Editor, { value }) - ReactDOM.renderToStaticMarkup(el) -} - -module.exports.input = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) diff --git a/benchmark/slate/changes/add-mark.js b/benchmark/slate/changes/add-mark.js deleted file mode 100644 index f1379cde7f..0000000000 --- a/benchmark/slate/changes/add-mark.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .addMark('bold') - .moveForward(5) - .addMark('bold') - .moveForward(5) - .addMark('bold') - .moveForward(5) - .addMark('bold') - .moveForward(5) - .addMark('bold') -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - This is editable {i === 0 ? : null}rich{i === 0 ? ( - - ) : null} - text, much better than a textarea! For reals. - - - - ))} - - -) - -module.exports.input = () => { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/delete-backward.js b/benchmark/slate/changes/delete-backward.js deleted file mode 100644 index d94a3e8347..0000000000 --- a/benchmark/slate/changes/delete-backward.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .deleteBackward() - .deleteBackward() - .deleteBackward() - .deleteBackward() - .deleteBackward() -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - This is editable rich text, much better than a - textarea! - {i === 0 ? : null} - - - - ))} - - -) - -module.exports.input = () => { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/delete-forward.js b/benchmark/slate/changes/delete-forward.js deleted file mode 100644 index 7b7c7b7e4c..0000000000 --- a/benchmark/slate/changes/delete-forward.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .deleteForward() - .deleteForward() - .deleteForward() - .deleteForward() - .deleteForward() -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - {i === 0 ? : null} - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = () => { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/insert-fragment-deep-with-problems.js b/benchmark/slate/changes/insert-fragment-deep-with-problems.js deleted file mode 100644 index fe2097b28e..0000000000 --- a/benchmark/slate/changes/insert-fragment-deep-with-problems.js +++ /dev/null @@ -1,67 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -const fragment = ( - - - - - - - - - - - {Array.from(10).map(n => ( - - - - - ))} - -
- Column 1 - - Column 2 - - Column 3 -
- Plain text - - - Bolded text - - -
- - - Plain text - - - - - - -
-) - -module.exports.default = function(editor) { - editor.insertFragment(fragment) -} - -const value = ( - - - - Some initial text. - - - -) - -module.exports.input = function() { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/insert-fragment-large.js b/benchmark/slate/changes/insert-fragment-large.js deleted file mode 100644 index 9f88076709..0000000000 --- a/benchmark/slate/changes/insert-fragment-large.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -const fragment = ( - - {Array.from(Array(100)).map((v, i) => ( - - - This is editable rich text, much better than a textarea! - {i === 0 ? : null} - - - ))} - -) - -module.exports.default = function(editor) { - editor.insertFragment(fragment) -} - -const value = ( - - - - Some initial text. - - - -) - -module.exports.input = function() { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/insert-fragment.js b/benchmark/slate/changes/insert-fragment.js deleted file mode 100644 index 0df15b1c2b..0000000000 --- a/benchmark/slate/changes/insert-fragment.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -const fragment = ( - - {Array.from(Array(10)).map((v, i) => ( - - - This is editable rich text, much better than a textarea! - {i === 0 ? : null} - - - ))} - -) - -module.exports.default = function(editor) { - editor.insertFragment(fragment) -} - -const value = ( - - - - Some initial text. - - - -) - -module.exports.input = function() { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/insert-node-by-key.js b/benchmark/slate/changes/insert-node-by-key.js deleted file mode 100644 index 69f77b227e..0000000000 --- a/benchmark/slate/changes/insert-node-by-key.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .insertNodeByKey('a0', 0, Hello world) - .insertNodeByKey('a1', 1, Hello world) - .insertNodeByKey('a2', 0, Hello world) - .insertNodeByKey('a3', 1, Hello world) - .insertNodeByKey('a4', 0, Hello world) -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - This is editable rich text, much better than a - textarea! - {i === 0 ? : null} - - - ))} - - -) - -module.exports.input = function() { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/insert-text-by-key.js b/benchmark/slate/changes/insert-text-by-key.js deleted file mode 100644 index e6885a178a..0000000000 --- a/benchmark/slate/changes/insert-text-by-key.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .insertTextByKey('T1', 0, 'one') - .insertTextByKey('T2', 5, 'two') - .insertTextByKey('T3', 10, 'three') - .insertTextByKey('T4', 15, 'four') - .insertTextByKey('T5', 20, 'five') -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - - This is editable rich text, much better than a textarea! - {i === 0 ? : null} - - - - - ))} - - -) -// const text = value.document.getLastText() - -module.exports.input = () => { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/insert-text.js b/benchmark/slate/changes/insert-text.js deleted file mode 100644 index 8ae9c21f71..0000000000 --- a/benchmark/slate/changes/insert-text.js +++ /dev/null @@ -1,40 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .insertText('one') - .moveForward(5) - .insertText('two') - .moveForward(5) - .insertText('three') - .moveForward(5) - .insertText('four') - .moveForward(5) - .insertText('five') -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - {i === 0 ? : null} - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = () => { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/normalize-with-problems.js b/benchmark/slate/changes/normalize-with-problems.js deleted file mode 100644 index 0a5233cbc4..0000000000 --- a/benchmark/slate/changes/normalize-with-problems.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor.normalize().normalize() -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - - link text - - - - - - - link text - - more text after - - - - - - ))} - - -) - -module.exports.input = function() { - return new Editor({ value }, { normalize: false }) -} diff --git a/benchmark/slate/changes/normalize.js b/benchmark/slate/changes/normalize.js deleted file mode 100644 index e5e81062cb..0000000000 --- a/benchmark/slate/changes/normalize.js +++ /dev/null @@ -1,40 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .normalize() - .moveForward(5) - .normalize() - .moveForward(5) - .normalize() - .moveForward(5) - .normalize() - .moveForward(5) - .normalize() -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - {i === 0 ? : null} - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = function() { - return new Editor({ value }, { normalize: false }) -} diff --git a/benchmark/slate/changes/remove-node-by-key.js b/benchmark/slate/changes/remove-node-by-key.js deleted file mode 100644 index 3c8d1d5fb5..0000000000 --- a/benchmark/slate/changes/remove-node-by-key.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .removeNodeByKey('T1') - .removeNodeByKey('T2') - .removeNodeByKey('T3') - .removeNodeByKey('T4') - .removeNodeByKey('T5') -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - - {i === 0 ? : null} - This is editable rich text, much better than a textarea! - - - - - ))} - - -) -const text = value.document.getLastText() - -module.exports.input = function() { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/set-blocks.js b/benchmark/slate/changes/set-blocks.js deleted file mode 100644 index 9e3865793a..0000000000 --- a/benchmark/slate/changes/set-blocks.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .setBlocks('quote') - .setBlocks('paragraph') - .setBlocks('aside') - .setBlocks('code') - .setBlocks('heading') -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - This is editable rich text, much better than a - textarea! - {i === 0 ? : null} - - - - ))} - - -) - -module.exports.input = function() { - return new Editor({ value }) -} diff --git a/benchmark/slate/changes/split-block.js b/benchmark/slate/changes/split-block.js deleted file mode 100644 index eaf0f1adca..0000000000 --- a/benchmark/slate/changes/split-block.js +++ /dev/null @@ -1,40 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(editor) { - editor - .splitBlock() - .moveForward(5) - .splitBlock() - .moveForward(5) - .splitBlock() - .moveForward(5) - .splitBlock() - .moveForward(5) - .splitBlock() -} - -const value = ( - - - {Array.from(Array(10)).map((v, i) => ( - - - - This - {i === 0 ? : null} - is editable rich text, much better than a textarea! - - - - ))} - - -) - -module.exports.input = function() { - return new Editor({ value }) -} diff --git a/benchmark/slate/index.js b/benchmark/slate/index.js deleted file mode 100644 index 8b5db7943d..0000000000 --- a/benchmark/slate/index.js +++ /dev/null @@ -1,37 +0,0 @@ -const { readdirSync } = require('fs') -const { basename, extname, resolve } = require('path') -const { resetMemoization } = require('slate') -const { Suite, Bench } = require('slate-dev-benchmark') - -/** - * Benchmarks. - */ - -module.exports.run = function(include) { - const categoryDir = resolve(__dirname) - const categories = readdirSync(categoryDir).filter( - c => c[0] !== '.' && c !== 'index.js' - ) - - categories.forEach(category => { - const suite = new Suite(category, { minTries: 100, minTime: 1000 }) - const benchmarkDir = resolve(categoryDir, category) - const benchmarks = readdirSync(benchmarkDir) - .filter(b => b[0] !== '.' && !!~b.indexOf('.js')) - .map(b => basename(b, extname(b))) - - benchmarks.forEach(benchmark => { - if (include && !benchmark.match(include)) return - const bench = new Bench(suite, benchmark) - const dir = resolve(benchmarkDir, benchmark) - const module = require(dir) - const fn = module.default - bench.input(module.input) - - bench.run(input => { - fn(input) - resetMemoization() - }) - }) - }) -} diff --git a/benchmark/slate/models/from-json-big.js b/benchmark/slate/models/from-json-big.js deleted file mode 100644 index 7387fee41b..0000000000 --- a/benchmark/slate/models/from-json-big.js +++ /dev/null @@ -1,54 +0,0 @@ -/* eslint-disable react/jsx-key */ - -const { Value } = require('slate') - -module.exports.default = function(json) { - Value.fromJSON(json) -} - -const input = { - object: 'value', - document: { - object: 'document', - nodes: Array.from(Array(100)).map(() => ({ - object: 'block', - type: 'list', - data: {}, - nodes: Array.from(Array(10)).map(() => ({ - object: 'block', - type: 'list-item', - data: {}, - nodes: [ - { - object: 'text', - marks: [], - text: '', - }, - { - type: 'link', - object: 'inline', - data: { - id: 1, - }, - nodes: [ - { - object: 'text', - marks: [], - text: 'Some text for a link', - }, - ], - }, - { - object: 'text', - marks: [], - text: '', - }, - ], - })), - })), - }, -} - -module.exports.input = function() { - return input -} diff --git a/benchmark/slate/models/from-json.js b/benchmark/slate/models/from-json.js deleted file mode 100644 index c506b0689e..0000000000 --- a/benchmark/slate/models/from-json.js +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable react/jsx-key */ - -const { Value } = require('slate') - -module.exports.default = function(json) { - Value.fromJSON(json) -} - -const input = { - document: { - nodes: Array.from(Array(10)).map(() => ({ - object: 'block', - type: 'quote', - nodes: [ - { - object: 'block', - type: 'paragraph', - nodes: [ - { - object: 'text', - text: 'This is editable ', - }, - { - object: 'text', - text: 'rich', - marks: [{ type: 'bold' }], - }, - { - object: 'text', - text: ' text, ', - }, - { - object: 'text', - text: 'much', - marks: [{ type: 'italic' }], - }, - { - object: 'text', - text: ' better than a textarea!', - }, - ], - }, - ], - })), - }, -} - -module.exports.input = function() { - return input -} diff --git a/benchmark/slate/models/get-active-marks-at-range.js b/benchmark/slate/models/get-active-marks-at-range.js deleted file mode 100644 index 333636f791..0000000000 --- a/benchmark/slate/models/get-active-marks-at-range.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(value) { - value.document.getActiveMarksAtRange(value.selection) -} - -let value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -const editor = new Editor({ value }) - -editor.moveToRangeOfDocument() - -value = editor.value - -module.exports.input = function() { - return value -} diff --git a/benchmark/slate/models/get-ancestors.js b/benchmark/slate/models/get-ancestors.js deleted file mode 100644 index 22cc7acaec..0000000000 --- a/benchmark/slate/models/get-ancestors.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.getAncestors('T1') - document.getAncestors('T2') - document.getAncestors('T3') - document.getAncestors('T4') - document.getAncestors('T5') -} - -const value = ( - - - {Array.from(Array(10)).map((_, i) => ( - - - - - This is editable rich text, much better than a textarea! - - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/get-blocks.js b/benchmark/slate/models/get-blocks.js deleted file mode 100644 index 8dfe127808..0000000000 --- a/benchmark/slate/models/get-blocks.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.getBlocks() - document.getBlocks() - document.getBlocks() - document.getBlocks() - document.getBlocks() -} - -const value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/get-common-ancestor.js b/benchmark/slate/models/get-common-ancestor.js deleted file mode 100644 index df473e6eab..0000000000 --- a/benchmark/slate/models/get-common-ancestor.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.getCommonAncestor('T1', 'T2') - document.getCommonAncestor('T2', 'T3') - document.getCommonAncestor('T3', 'T4') - document.getCommonAncestor('T4', 'T5') - document.getCommonAncestor('T5', 'T6') -} - -const value = ( - - - {Array.from(Array(10)).map((_, i) => ( - - - - - This is editable rich text, much better than a textarea! - - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/get-descendant.js b/benchmark/slate/models/get-descendant.js deleted file mode 100644 index b682c50bcf..0000000000 --- a/benchmark/slate/models/get-descendant.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.getDescendant('T1') - document.getDescendant('T2') - document.getDescendant('T3') - document.getDescendant('T4') - document.getDescendant('T5') -} - -const value = ( - - - {Array.from(Array(10)).map((_, i) => ( - - - - - This is editable rich text, much better than a textarea! - - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/get-furthest-ancestor.js b/benchmark/slate/models/get-furthest-ancestor.js deleted file mode 100644 index 6067408ac5..0000000000 --- a/benchmark/slate/models/get-furthest-ancestor.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.getFurthestAncestor('T1') - document.getFurthestAncestor('T2') - document.getFurthestAncestor('T3') - document.getFurthestAncestor('T4') - document.getFurthestAncestor('T5') -} - -const value = ( - - - {Array.from(Array(10)).map((_, i) => ( - - - - - This is editable rich text, much better than a textarea! - - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/get-inlines.js b/benchmark/slate/models/get-inlines.js deleted file mode 100644 index 04bc7c4e15..0000000000 --- a/benchmark/slate/models/get-inlines.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(value) { - value.document.getInlines() -} - -const value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = function() { - return value -} diff --git a/benchmark/slate/models/get-leaf-blocks-at-range.js b/benchmark/slate/models/get-leaf-blocks-at-range.js deleted file mode 100644 index 1432e19416..0000000000 --- a/benchmark/slate/models/get-leaf-blocks-at-range.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(value) { - value.document.getLeafBlocksAtRange(value.selection) -} - -let value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -const editor = new Editor({ value }) -editor.moveToRangeOfDocument() -value = editor.value - -module.exports.input = () => { - return value -} diff --git a/benchmark/slate/models/get-leaf-inlines-at-range.js b/benchmark/slate/models/get-leaf-inlines-at-range.js deleted file mode 100644 index 62e232eecf..0000000000 --- a/benchmark/slate/models/get-leaf-inlines-at-range.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(value) { - value.document.getLeafInlinesAtRange(value.selection) -} - -let value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -const editor = new Editor({ value }) -editor.moveToRangeOfDocument() -value = editor.value - -module.exports.input = function() { - return value -} diff --git a/benchmark/slate/models/get-leaves.js b/benchmark/slate/models/get-leaves.js deleted file mode 100644 index d91ad2c1b7..0000000000 --- a/benchmark/slate/models/get-leaves.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(text) { - text.getLeaves() -} - -const value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) -const text = value.document.getFirstText() - -module.exports.input = function() { - return text -} diff --git a/benchmark/slate/models/get-marks-at-range.js b/benchmark/slate/models/get-marks-at-range.js deleted file mode 100644 index 5350b1ca6b..0000000000 --- a/benchmark/slate/models/get-marks-at-range.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(value) { - value.document.getMarksAtRange(value.selection) -} - -let value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -const editor = new Editor({ value }) -editor.moveToRangeOfDocument() -value = editor.value - -module.exports.input = function() { - return value -} diff --git a/benchmark/slate/models/get-marks.js b/benchmark/slate/models/get-marks.js deleted file mode 100644 index 530eda9bf2..0000000000 --- a/benchmark/slate/models/get-marks.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(value) { - value.document.getMarks() -} - -const value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = function() { - return value -} diff --git a/benchmark/slate/models/get-parent.js b/benchmark/slate/models/get-parent.js deleted file mode 100644 index a097b54518..0000000000 --- a/benchmark/slate/models/get-parent.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.getParent('T1') - document.getParent('T2') - document.getParent('T3') - document.getParent('T4') - document.getParent('T5') -} - -const value = ( - - - {Array.from(Array(10)).map((_, i) => ( - - - - - This is editable rich text, much better than a textarea! - - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/get-path.js b/benchmark/slate/models/get-path.js deleted file mode 100644 index 3297eac8c3..0000000000 --- a/benchmark/slate/models/get-path.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.getPath('T1') - document.getPath('T2') - document.getPath('T3') - document.getPath('T4') - document.getPath('T5') -} - -const value = ( - - - {Array.from(Array(10)).map((_, i) => ( - - - - - This is editable rich text, much better than a textarea! - - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/get-texts-at-range.js b/benchmark/slate/models/get-texts-at-range.js deleted file mode 100644 index e7595083ea..0000000000 --- a/benchmark/slate/models/get-texts-at-range.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') -const { Editor } = require('slate') - -module.exports.default = function(value) { - value.document.getTextsAtRange(value.selection) -} - -let value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -const editor = new Editor({ value }) -editor.moveToRangeOfDocument() -value = editor.value - -module.exports.input = function() { - return value -} diff --git a/benchmark/slate/models/get-texts.js b/benchmark/slate/models/get-texts.js deleted file mode 100644 index 223ae14210..0000000000 --- a/benchmark/slate/models/get-texts.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(value) { - value.document.getTexts() -} - -const value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = function() { - return value -} diff --git a/benchmark/slate/models/has-node-multiple.js b/benchmark/slate/models/has-node-multiple.js deleted file mode 100644 index fb9ad0f68f..0000000000 --- a/benchmark/slate/models/has-node-multiple.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function({ value, keys }) { - keys.forEach(key => { - value.document.hasNode(key) - }) -} - -const value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) -const keys = value.document - .getTexts() - .toArray() - .map(t => t.key) - -module.exports.input = function() { - return { value, keys } -} diff --git a/benchmark/slate/models/has-node.js b/benchmark/slate/models/has-node.js deleted file mode 100644 index cd0ba2f56a..0000000000 --- a/benchmark/slate/models/has-node.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(document) { - document.hasNode('T1') - document.hasNode('T2') - document.hasNode('T3') - document.hasNode('T4') - document.hasNode('T5') -} - -const value = ( - - - {Array.from(Array(10)).map((_, i) => ( - - - - - This is editable rich text, much better than a textarea! - - - - - ))} - - -) - -module.exports.input = function() { - return value.document -} diff --git a/benchmark/slate/models/to-json.js b/benchmark/slate/models/to-json.js deleted file mode 100644 index 9400b7552a..0000000000 --- a/benchmark/slate/models/to-json.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ -/* eslint-disable react/jsx-key */ - -const h = require('../../helpers/h') - -module.exports.default = function(value) { - value.toJSON() -} - -const value = ( - - - {Array.from(Array(10)).map(() => ( - - - - This is editable rich text, much better than a - textarea! - - - - ))} - - -) - -module.exports.input = function() { - return value -} diff --git a/support/rollup/factory.js b/config/rollup/factory.js similarity index 68% rename from support/rollup/factory.js rename to config/rollup/factory.js index 3b011c7e8c..03bfa2dad0 100644 --- a/support/rollup/factory.js +++ b/config/rollup/factory.js @@ -5,6 +5,7 @@ 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 typescript from 'rollup-plugin-typescript2' import uglify from 'rollup-plugin-uglify' import { startCase } from 'lodash' @@ -17,15 +18,22 @@ import { startCase } from 'lodash' * @return {Object} */ -function configure(pkg, env, target) { +function configure(pkg, env, target, { ts }) { const isProd = env === 'production' const isUmd = target === 'umd' const isModule = target === 'module' - const input = `packages/${pkg.name}/src/index.js` + const input = `packages/${pkg.name}/src/index.${ts ? 'ts' : 'js'}` const deps = [] .concat(pkg.dependencies ? Object.keys(pkg.dependencies) : []) .concat(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []) + // Stop Rollup from warning about circular dependencies. + const onwarn = warning => { + if (warning.code !== 'CIRCULAR_DEPENDENCY') { + console.warn(`(!) ${warning.message}`) // eslint-disable-line no-console + } + } + const plugins = [ // Allow Rollup to resolve modules from `node_modules`, since it only // resolves local modules by default. @@ -33,29 +41,34 @@ function configure(pkg, env, target) { browser: true, }), + ts && + typescript({ + abortOnError: false, + tsconfig: `./packages/${pkg.name}/tsconfig.json`, + }), + // 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'], - }, - }), + 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(), @@ -71,7 +84,10 @@ function configure(pkg, env, target) { // Use Babel to transpile the result, limiting it to the source code. babel({ + runtimeHelpers: true, include: [`packages/${pkg.name}/src/**`], + extensions: ['.js', '.ts'], + // configFile: '../../babel.config.js', }), // Register Node.js globals for browserify compatibility. @@ -86,6 +102,7 @@ function configure(pkg, env, target) { return { plugins, input, + // onwarn, output: { format: 'umd', file: `packages/${pkg.name}/${isProd ? pkg.umdMin : pkg.umd}`, @@ -101,6 +118,7 @@ function configure(pkg, env, target) { return { plugins, input, + // onwarn, output: [ { file: `packages/${pkg.name}/${pkg.module}`, @@ -130,12 +148,12 @@ function configure(pkg, env, target) { * @return {Array} */ -function factory(pkg) { +function factory(pkg, options = {}) { const isProd = process.env.NODE_ENV === 'production' return [ - configure(pkg, 'development', 'module'), - isProd && configure(pkg, 'development', 'umd'), - isProd && configure(pkg, 'production', 'umd'), + configure(pkg, 'development', 'module', options), + isProd && configure(pkg, 'development', 'umd', options), + isProd && configure(pkg, 'production', 'umd', options), ].filter(Boolean) } diff --git a/config/rollup/rollup.config.js b/config/rollup/rollup.config.js new file mode 100644 index 0000000000..abeaea5006 --- /dev/null +++ b/config/rollup/rollup.config.js @@ -0,0 +1,30 @@ +import factory from './factory' +import core from '../../packages/slate/package.json' +import base64Serializer from '../../packages/slate-base64-serializer/package.json' +import devEnvironment from '../../packages/slate-dev-environment/package.json' +import hotkeys from '../../packages/slate-hotkeys/package.json' +import htmlSerializer from '../../packages/slate-html-serializer/package.json' +import hyperscript from '../../packages/slate-hyperscript/package.json' +import parsePlaintext from '../../packages/slate-parse-plaintext/package.json' +import plainSerializer from '../../packages/slate-plain-serializer/package.json' +import propTypes from '../../packages/slate-prop-types/package.json' +import react from '../../packages/slate-react/package.json' +import reactPlaceholder from '../../packages/slate-react-placeholder/package.json' +import renderPlaintext from '../../packages/slate-render-plaintext/package.json' + +const configurations = [ + ...factory(core, { ts: true }), + ...factory(base64Serializer), + ...factory(devEnvironment), + ...factory(hotkeys), + ...factory(htmlSerializer), + ...factory(hyperscript, { ts: true }), + ...factory(plainSerializer), + ...factory(parsePlaintext, { ts: true }), + ...factory(propTypes), + ...factory(react), + ...factory(reactPlaceholder), + ...factory(renderPlaintext, { ts: true }), +] + +export default configurations diff --git a/config/typescript/tsconfig.json b/config/typescript/tsconfig.json new file mode 100644 index 0000000000..278abb318f --- /dev/null +++ b/config/typescript/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "composite": true, + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "sourceMap": true, + "strict": true, + "suppressImplicitAnyIndexErrors": true, + "target": "esnext" + } +} diff --git a/support/webpack/config.js b/config/webpack/config.js similarity index 100% rename from support/webpack/config.js rename to config/webpack/config.js diff --git a/package.json b/package.json index caf08ed7e1..5f2dc65a1c 100644 --- a/package.json +++ b/package.json @@ -4,26 +4,64 @@ "workspaces": [ "packages/*" ], + "scripts": { + "build": "rollup --config ./config/rollup/rollup.config.js", + "build:production": "cross-env NODE_ENV=production rollup --config ./support/rollup/config.js && cross-env NODE_ENV=production webpack --config support/webpack/config.js", + "build:clean-fork": "rm ./build/CNAME", + "clean": "rm -rf ./{build,node_modules,tmp} ./packages/*/{dist,lib,node_modules}", + "gh-pages": "gh-pages --dist ./build", + "gh-pages:fork": "npm-run-all build:production build:clean-fork gh-pages", + "lint": "yarn lint:eslint && yarn lint:prettier", + "lint:eslint": "eslint benchmark packages/*/src packages/*/test examples/*/*.js examples/dev/*/*.js", + "lint:prettier": "prettier --list-different '**/*.{md,json,css}'", + "open": "open http://localhost:8080", + "prettier": "prettier --write '**/*.{js,jsx,md,json,css}'", + "release": "yarn build:production && yarn test && yarn lint && lerna publish && yarn gh-pages", + "server": "webpack-dev-server --config ./support/webpack/config.js", + "start": "npm-run-all --parallel --print-label watch server", + "test": "cross-env BABEL_ENV=test FORBID_WARNINGS=true mocha --require @babel/register ./packages/*/test/index.js", + "test:debug": "cross-env BABEL_ENV=test FORBID_WARNINGS=true mocha debug --require @babel/register ./packages/*/test/index.js", + "watch": "yarn build --watch" + }, + "peerDependencies": { + "slate": "*", + "slate-dev-benchmark": "*", + "slate-dev-environment": "*", + "slate-dev-test-utils": "*", + "slate-html-serializer": "*", + "slate-parse-plaintext": "*", + "slate-plain-serializer": "*", + "slate-react": "*", + "slate-react-placeholder": "*", + "slate-render-plaintext": "*" + }, "devDependencies": { - "babel-cli": "^6.26.0", - "babel-core": "^6.26.0", + "@babel/cli": "^7.6.4", + "@babel/core": "^7.6.4", + "@babel/plugin-external-helpers": "^7.2.0", + "@babel/plugin-proposal-class-properties": "^7.5.5", + "@babel/plugin-transform-modules-commonjs": "^7.6.0", + "@babel/plugin-transform-runtime": "^7.6.2", + "@babel/polyfill": "^7.6.0", + "@babel/preset-env": "^7.6.3", + "@babel/preset-react": "^7.6.3", + "@babel/preset-typescript": "^7.6.0", + "@babel/register": "^7.6.2", + "@babel/runtime": "^7.6.3", + "@gnd/typedoc": "^0.15.0-0", + "@types/mocha": "^5.2.7", + "@types/node": "^12.7.12", + "@typescript-eslint/eslint-plugin": "^2.3.3", + "@typescript-eslint/parser": "^2.3.3", "babel-eslint": "^8.2.1", "babel-loader": "^7.1.2", - "babel-plugin-external-helpers": "^6.22.0", + "babel-plugin-dev-expression": "^0.2.2", "babel-plugin-module-resolver": "^3.1.1", - "babel-plugin-transform-runtime": "^6.23.0", - "babel-polyfill": "^6.26.0", - "babel-preset-env": "^1.6.1", - "babel-preset-react": "^6.24.1", - "babel-preset-stage-0": "^6.24.1", - "babel-runtime": "^6.26.0", - "blanket": "^1.2.3", "chalk": "^1.1.3", "commander": "^2.15.1", "copy-webpack-plugin": "^4.4.1", "cross-env": "^5.1.3", "css-loader": "^0.28.9", - "element-closest": "^2.0.2", "emojis": "^1.0.10", "emotion": "^10.0.9", "eslint": "^4.19.1", @@ -33,7 +71,6 @@ "eslint-plugin-react": "^7.6.0", "extract-text-webpack-plugin": "^3.0.2", "faker": "^3.1.0", - "figures": "^2.0.0", "fs-promise": "^1.0.0", "gh-pages": "^0.11.0", "html-webpack-plugin": "^2.30.1", @@ -45,10 +82,8 @@ "jsdom": "^11.5.1", "lerna": "^2.7.1", "lodash": "^4.17.4", - "matcha": "^0.7.0", "memoize-one": "^4.0.0", "mocha": "^6.2.0", - "mocha-lcov-reporter": "^1.3.0", "npm-run-all": "^4.1.2", "prettier": "^1.10.2", "prismjs": "^1.5.1", @@ -59,56 +94,26 @@ "react-router-dom": "^4.3.1", "react-values": "^0.3.0", "read-metadata": "^1.0.0", - "rollup": "^0.55.1", + "rollup": "^1.23.1", "rollup-plugin-alias": "^1.4.0", - "rollup-plugin-babel": "^3.0.3", - "rollup-plugin-commonjs": "^8.3.0", - "rollup-plugin-json": "^2.3.0", + "rollup-plugin-babel": "^4.3.3", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-json": "^4.0.0", "rollup-plugin-node-builtins": "^2.1.2", - "rollup-plugin-node-globals": "^1.1.0", - "rollup-plugin-node-resolve": "^3.0.2", - "rollup-plugin-replace": "^2.0.0", + "rollup-plugin-node-globals": "^1.4.0", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-replace": "^2.2.0", "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-uglify": "^3.0.0", + "rollup-plugin-typescript2": "^0.24.3", + "rollup-plugin-uglify": "^6.0.3", "source-map-loader": "^0.2.3", "source-map-support": "^0.4.0", "style-loader": "^0.20.2", "to-camel-case": "^1.0.0", "to-snake-case": "^1.0.0", + "typescript": "^3.6.4", "uglifyjs-webpack-plugin": "^1.1.8", "webpack": "^3.11.0", "webpack-dev-server": "^2.11.1" - }, - "peerDependencies": { - "slate": "*", - "slate-dev-benchmark": "*", - "slate-dev-environment": "*", - "slate-dev-test-utils": "*", - "slate-html-serializer": "*", - "slate-plain-serializer": "*", - "slate-react": "*", - "slate-react-placeholder": "*" - }, - "scripts": { - "benchmark": "cross-env COMPARE=compare node --expose-gc ./tmp/benchmark/index.js", - "benchmark:save": " yarn benchmark:prepare && node --expose-gc ./tmp/benchmark/index.js", - "benchmark:prepare": "mkdir -p ./tmp && cross-env BABEL_ENV=benchmark babel benchmark --out-dir tmp/benchmark/", - "bootstrap": "lerna bootstrap && yarn build", - "build": "rollup --config ./support/rollup/config.js", - "build:production": "cross-env NODE_ENV=production rollup --config ./support/rollup/config.js && cross-env NODE_ENV=production webpack --config support/webpack/config.js", - "build:clean-fork": "rm ./build/CNAME", - "clean": "lerna run clean && rm -rf ./node_modules ./dist ./build", - "gh-pages": "gh-pages --dist ./build", - "gh-pages:fork": "npm-run-all build:production build:clean-fork gh-pages", - "lint": "yarn lint:eslint && yarn lint:prettier", - "lint:eslint": "eslint benchmark packages/*/src packages/*/test examples/*/*.js examples/dev/*/*.js", - "lint:prettier": "prettier --list-different '**/*.{md,json,css}'", - "open": "open http://localhost:8080", - "prettier": "prettier --write '**/*.{js,jsx,md,json,css}'", - "release": "yarn build:production && yarn test && yarn lint && lerna publish && yarn gh-pages", - "server": "webpack-dev-server --config ./support/webpack/config.js", - "start": "npm-run-all --parallel --print-label watch server", - "test": "cross-env BABEL_ENV=test FORBID_WARNINGS=true mocha --require babel-core/register ./packages/*/test/index.js", - "watch": "rollup --config ./support/rollup/config.js --watch" } } diff --git a/packages/slate-dev-benchmark/Readme.md b/packages/slate-dev-benchmark/Readme.md deleted file mode 100644 index 46021a7cef..0000000000 --- a/packages/slate-dev-benchmark/Readme.md +++ /dev/null @@ -1 +0,0 @@ -This package contains 'Suite' and 'Bench' that Slate uses to compare computation efficiency under nodeJS. diff --git a/packages/slate-dev-benchmark/package.json b/packages/slate-dev-benchmark/package.json deleted file mode 100644 index f0c2aa88f6..0000000000 --- a/packages/slate-dev-benchmark/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "slate-dev-benchmark", - "description": "INTERNAL: A development-only benchmark tool for Slate's core.", - "version": "0.0.5", - "license": "MIT", - "repository": "git://github.com/ianstormtaylor/slate.git", - "main": "src/index.js", - "devDependencies": { - "mocha": "^2.5.3" - }, - "scripts": { - "clean": "rm -rf ./dist ./lib ./node_modules" - } -} diff --git a/packages/slate-dev-benchmark/src/Bench.js b/packages/slate-dev-benchmark/src/Bench.js deleted file mode 100644 index 997596449e..0000000000 --- a/packages/slate-dev-benchmark/src/Bench.js +++ /dev/null @@ -1,227 +0,0 @@ -/* global Promise */ -const { BenchType } = require('./types') -const { makeOptions } = require('./makeOptions') -const { Timer } = require('./Timer') -const { logger } = require('./logger') - -const errorReport = { - cycles: NaN, - user: NaN, - system: NaN, - all: NaN, -} - -/** - * Run a task and calculate the time consuming of tasks - */ - -class Bench { - /** - * Construct a bench and register it to a Suite - * @param {Suite} suite - * @param {string} name - * @param {Object} options - */ - - constructor(suite, name, options = {}) { - this.name = name - this.options = makeOptions({ ...suite.options, ...options }) - this.isFinished = false - this.inputter = () => undefined - this.runner = () => {} - this.report = { ...errorReport } - suite.addBench(this) - } - - /** - * Is a Bench? - * @param {any} obj - * @return {boolean} - */ - - isBench(obj) { - return obj && obj[BenchType] - } - - /** - * Set the method to generate (different} inputs for each run - * @param {Array|Function|Scalar} inputter - * @return {void} - */ - - input(inputter) { - if (Array.isArray(inputter)) { - this.inputter = index => inputter[index % inputter.length] - return - } - - if (typeof inputter === 'function') { - this.inputter = inputter - return - } - - this.inputter = () => inputter - } - - /** - * Set the task runner - * @param {Function} runner - * @return {void} - */ - - run(runner) { - this.runner = runner - } - - /** - * Tries to run tasks in `times`, if the time consuming excedes the max-time, then stop; - * After run, generate report and return - * If initial is the initial index to run the task, for continueing a task in adaptive mode - * @param {number} times - * @param {number} initial - */ - - async compose(times, initial) { - times = Math.floor(times) - const isAsync = this.options.async - const { runner, inputter } = this - - const { maxTime } = this.options - let seq = Number.isFinite(this.options.maxTries) ? 1 : NaN - let nextCheckIndex = seq - const hrStart = process.hrtime() - - if (global.gc) { - global.gc() - } - - const report = { user: 0, system: 0, all: 0, hr: 0, cycles: 0 } - - for ( - let initialIndex = initial; - initialIndex < times; - initialIndex += this.options.allocationTries - ) { - const tries = Math.min(times - initialIndex, this.options.allocationTries) - const thisTryReport = await runBundleTasks.call(this, tries, initialIndex) - - if (global.gc) { - global.gc() - } - - for (const key in report) { - report[key] += thisTryReport[key] - } - } - return report - - /** - * Run a bundle of tasks; - * the Bench estimate the time consuming of every `tries` tasks, then explictly run gc, and caculate the time consuming of next bundle tasks - * @param {number} tries - * @param {number} initialIndex - * @return {Promise< Object , *>} - */ - - function runBundleTasks(tries, initialIndex) { - const inputs = Array.from({ length: tries }).map(index => - inputter(index + initialIndex) - ) - const timer = new Timer() - timer.start() - return runFrom(0).then(cycles => { - timer.end() - const { elapsed } = timer - return { ...elapsed, cycles } - }) - - /** - * Run a single task run; If the task is end, return a Promise with the index when the task ends - * @param {number} index - * @return {Promise} - */ - - function runFrom(index) { - if (index === tries) return Promise.resolve(tries) - - if (index === nextCheckIndex) { - const hrEnd = process.hrtime(hrStart) - const elapsed = hrEnd[0] * 1e3 + hrEnd[1] / 1e6 - - if (elapsed > maxTime) { - return Promise.resolve(index) - } else { - if (elapsed < maxTime / 20) { - seq *= 2 - } - - nextCheckIndex = seq + nextCheckIndex - } - } - - if (!isAsync) { - const inputVar = inputs[index] - runner(inputVar) - return runFrom(index + 1) - } else { - return Promise.resolve(runner(inputs[index])).then(() => - runFrom(index + 1) - ) - } - } - } - } - - /* - * Run the bench - * @return {void} - */ - - makeRun() { - if (this.isFinished) return true - logger(this) - const { options } = this - const { minTries, maxTime, maxTries } = options - - let { minTime } = options - if (minTime > maxTime) minTime = maxTime - - return this.compose(minTries, 0) - .then(report => { - if (this.options.mode === 'static') return report - const { all } = report - if (all > minTime) return report - const times = (minTime / all - 1) * minTries - return this.compose(Math.min(times, maxTries), minTries).then( - newReport => { - return mergeResults(report, newReport) - } - ) - }) - .then(report => { - this.report = report - this.isFinished = true - logger(this) - return true - }) - } -} - -Bench.prototype[BenchType] = true - -/* - * Merge two different report - * @param {Object} res1 - * @param {Object} res2 - */ - -function mergeResults(res1, res2) { - const result = {} - - for (const key in res1) { - result[key] = res1[key] + res2[key] - } - return result -} - -module.exports = { Bench } diff --git a/packages/slate-dev-benchmark/src/Repository.js b/packages/slate-dev-benchmark/src/Repository.js deleted file mode 100644 index 729f199c8f..0000000000 --- a/packages/slate-dev-benchmark/src/Repository.js +++ /dev/null @@ -1,73 +0,0 @@ -/* global Promise */ -const { RepositoryType } = require('./types') -const { logger } = require('./logger') -const { compose } = require('./compose') - -/** - * Repository Class for holding Suite - */ - -class Repository { - /** - * Construct a Repository with a name - * @param {string} name - */ - - constructor(name = 'default') { - this.name = name - this.suites = [] - this.report = {} - this.isFinished = false - } - - /** - * Check whether {obj} is repository - * @param {any} obj - * @return {boolean} - */ - - isRepository(obj) { - return obj && obj[RepositoryType] - } - - /** - * Register a suite to the repository - * @param {Suite} suite - * @return {void} - */ - - addSuite(suite) { - this.isFinished = false - this.suites.push(suite) - } - - /** - * Run all suites (and all benches under suites) and generate a report - * @return {Promise} - */ - - run() { - if (this.isFinished) return Promise.resolve(this.report) - logger(this) - return compose(this.suites).then(() => { - this.isFinished = true - const report = {} - - for (const suite of this.suites) { - report[suite.name] = suite.report - } - - this.report = report - return report - }) - } -} -Repository.prototype[RepositoryType] = true - -/** - * By default, all suites are registers to the following {repo} - */ - -const repo = new Repository() - -module.exports = { Repository, repo } diff --git a/packages/slate-dev-benchmark/src/Suite.js b/packages/slate-dev-benchmark/src/Suite.js deleted file mode 100644 index ea44f637a4..0000000000 --- a/packages/slate-dev-benchmark/src/Suite.js +++ /dev/null @@ -1,85 +0,0 @@ -/* global Promise */ -const { repo } = require('./Repository.js') -const { SuiteType } = require('./types') -const { logger } = require('./logger') -const { compose } = require('./compose') -const { makeOptions } = require('./makeOptions') - -/** - * Suite is for holding Benches - */ - -class Suite { - /** - * Construct a Suite and regiester it to repository - * @param {string} name - * @param {Object} options - * @property {void|Repository} repository - * @property {any} ...rest - */ - - constructor(name, options = {}) { - const { repository = repo } = options - - if (repository[name]) { - throw Error(`The suite name ${name} has benn occupied in repository`) - } - - if (typeof name !== 'string') { - throw Error(`The suite name must be a string`) - } - - this.name = name - this.options = makeOptions(options) - this.isFinished = false - this.benches = [] - this.report = {} - repository.addSuite(this) - } - - /** - * Whether it is a Suite - * @param {any} obj - * @return {boolean} - */ - - isSuite(obj) { - return obj && obj[SuiteType] - } - - /** - * Register an bench to the repository - * @param {Bench} bench - * @return {void} - */ - - addBench(bench) { - this.isFinished = false - this.benches.push(bench) - } - - /** - * Run all benches, and generate report for consumed time - * @return {Promise - */ - - makeRun() { - if (this.isFinished) return Promise.resolve(this.report) - logger(this) - return compose(this.benches).then(() => { - this.isFinished = true - const report = {} - - for (const bench of this.benches) { - report[bench.name] = bench.report - } - - this.report = report - return report - }) - } -} - -Suite.prototype[SuiteType] = true - -module.exports = { Suite } diff --git a/packages/slate-dev-benchmark/src/Timer.js b/packages/slate-dev-benchmark/src/Timer.js deleted file mode 100644 index a3ae56cb89..0000000000 --- a/packages/slate-dev-benchmark/src/Timer.js +++ /dev/null @@ -1,66 +0,0 @@ -const { TimerType } = require('./types') - -class Timer { - constructor() { - this.cpuStartTime = {} - this.hrStartTime = null - this.isStopped = false - this.elapsed = {} - } - - /** - * Whether it is a Timer - * @param {any} obj - */ - - isTimer(obj) { - return obj && obj[TimerType] - } - - /** - * Start the timer - * @return {void} - */ - - start() { - this.isStopped = false - this.cpuStartTime = process.cpuUsage() - this.hrStartTime = process.hrtime() - this.elapsed = {} - } - - /** - * Stop the timer and store restore in this.elapsed - * @return {Object} - */ - - end() { - if (this.isStopped) return this.elapsed - const cpuElapsed = process.cpuUsage(this.cpuStartTime) - const hrElapsed = process.hrtime(this.hrStartTime) - const { user, system } = cpuElapsed - const hr = hrElapsed[0] * 1000 + hrElapsed[1] / 1e6 - - /** - * user: cpu time consumed in user space - * system: cpu time consumed in system space - * all: user+system - * hr: real world time - * (unit): ms - */ - - this.elapsed = { - user: user / 1000, - system: system / 1000, - all: (user + system) / 1000, - hr, - } - - this.isStopped = true - return this.elapsed - } -} - -Timer.prototype[TimerType] = true - -module.exports = { Timer } diff --git a/packages/slate-dev-benchmark/src/compose.js b/packages/slate-dev-benchmark/src/compose.js deleted file mode 100644 index 146026b8ce..0000000000 --- a/packages/slate-dev-benchmark/src/compose.js +++ /dev/null @@ -1,22 +0,0 @@ -/* global Promise */ -const { errorLog } = require('./logger') - -/** - * Run all benches/suites with Promise; Ensure an error would not block the whole process - * @param {Array|Array} - * @param {string} name; where to call the run method - */ - -function compose(list, name = 'makeRun') { - return dispatch(0) - - function dispatch(index) { - if (index === list.length) return Promise.resolve(true) - const node = list[index] - return new Promise(resolve => resolve(node[name]())) - .catch(err => errorLog(err)) - .then(() => dispatch(index + 1)) - } -} - -module.exports = { compose } diff --git a/packages/slate-dev-benchmark/src/index.js b/packages/slate-dev-benchmark/src/index.js deleted file mode 100644 index 4491bf79dc..0000000000 --- a/packages/slate-dev-benchmark/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const { Repository, repo } = require('./Repository') -const { Suite } = require('./Suite') -const { Bench } = require('./Bench') - -module.exports = { Repository, Suite, Bench, repo } diff --git a/packages/slate-dev-benchmark/src/logger.js b/packages/slate-dev-benchmark/src/logger.js deleted file mode 100644 index 57f1bdf628..0000000000 --- a/packages/slate-dev-benchmark/src/logger.js +++ /dev/null @@ -1,74 +0,0 @@ -/* eslint-disable no-console */ - -/** - * IS in test - */ - -const IS_TEST = - typeof process !== 'undefined' && - process.env && - process.env.BABEL_ENV === 'test' - -/** - * Log a `message` - * - * @param {String} message - * @param {Any} ...args - * @retrun {void} - */ - -function log(message, ...args) { - if (IS_TEST) return - - return console.log(message, ...args) -} - -/* - * Log a error `message` -*/ - -function errorLog(message, ...args) { - console.error(message, ...args) -} - -/** - * Logging benchmark result - */ - -function logger(obj) { - const prefix = ' ' - - if (obj.isRepository) { - return log(`Repository ${obj.name} is running`) - } - - if (obj.isSuite) { - return log(`${prefix}- Suite ${obj.name} is running`) - } - - if (obj.isBench) { - if (!obj.isFinished) { - return log(`${prefix + prefix}- Bench ${obj.name} is running`) - } - - const { report } = obj - const { cycles } = report - - const header = { - user: 'user:', - hr: 'real:', - } - - for (const key of ['user', 'hr']) { - log( - `${prefix + prefix + prefix}${header[key]} * ${cycles} cycles: ${ - report[key] - } ms; ( ${cycles * 1000 / report[key]} ops/sec)` - ) - } - return log(`${prefix + prefix + prefix}cycles: ${cycles}`) - } - return log(obj) -} - -module.exports = { logger, errorLog, log } diff --git a/packages/slate-dev-benchmark/src/makeOptions.js b/packages/slate-dev-benchmark/src/makeOptions.js deleted file mode 100644 index f9938fd90f..0000000000 --- a/packages/slate-dev-benchmark/src/makeOptions.js +++ /dev/null @@ -1,40 +0,0 @@ -const defaultOptions = { - minTime: 1000, - maxTime: 2000, - minTries: 100, - maxTries: Infinity, - allocationTries: 1000, - async: false, - mode: 'adaptive', -} - -/** - * Merge two options for configuring a bench run - * @param {Object} options - * @returns {Object} - * @property {number} minTime - * @property {number} maxTime - * @property {number} minTries - * @property {number} maxTries - * @property {number} allocationTries - * @property {boolean} async - * @property {"static"|"adaptive"} mode - */ - -function makeOptions(options) { - const result = { ...defaultOptions, ...options } - - for (const key in defaultOptions) { - const shallType = typeof defaultOptions[key] - const inputType = typeof result[key] - - if (shallType !== inputType) { - throw TypeError( - `Wrong Input in Config Suite, options[${key}] should be ${shallType}, but the input type is ${inputType}` - ) - } - } - return result -} - -module.exports = { makeOptions } diff --git a/packages/slate-dev-benchmark/src/types.js b/packages/slate-dev-benchmark/src/types.js deleted file mode 100644 index f99e12f705..0000000000 --- a/packages/slate-dev-benchmark/src/types.js +++ /dev/null @@ -1,11 +0,0 @@ -const RepositoryType = '@@__SLATE_REPOSITORY__@@' -const SuiteType = '@@__SLATE_SUITE__@@' -const BenchType = '@@__SLATE_BENCH__@@' -const TimerType = '@@__SLATE_BENCH_TIMER_@@' - -module.exports = { - RepositoryType, - SuiteType, - BenchType, - TimerType, -} diff --git a/packages/slate-dev-benchmark/test/index.js b/packages/slate-dev-benchmark/test/index.js deleted file mode 100644 index 08c77a1f18..0000000000 --- a/packages/slate-dev-benchmark/test/index.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Dependencies. - */ - -/** - * Tests. - */ - -describe('slate-dev-benchmark', () => { - // require('./tries/') - // require('./time/') -}) diff --git a/packages/slate-dev-benchmark/test/time/index.js b/packages/slate-dev-benchmark/test/time/index.js deleted file mode 100644 index 2c63270f5e..0000000000 --- a/packages/slate-dev-benchmark/test/time/index.js +++ /dev/null @@ -1,22 +0,0 @@ -import { repo, Suite } from '../..' -import fs from 'fs' -import { resolve } from 'path' - -describe('time', async () => { - const suite = new Suite('tries') - const testDir = resolve(__dirname) - const files = fs - .readdirSync(testDir) - .filter(x => x[0] !== '.' && x !== 'index.js') - - for (const file of files) { - const module = require(`./${file}`) - - it(module.experiment, () => { - module.default(suite) - const { expected } = module - repo.isFinished = false - return repo.run().then(() => expected()) - }) - } -}) diff --git a/packages/slate-dev-benchmark/test/time/max-time-async.js b/packages/slate-dev-benchmark/test/time/max-time-async.js deleted file mode 100644 index 519d321cdc..0000000000 --- a/packages/slate-dev-benchmark/test/time/max-time-async.js +++ /dev/null @@ -1,31 +0,0 @@ -/* global Promise */ -import { Bench } from '../..' -import assert from 'assert' - -export const experiment = 'max-time-async' - -let index = 0 - -// A wider range than sync, becuase Promise intialization, babel-node takes time -export function expected() { - assert( - index > 5 && index < 12, - `index should be 10, but is actually ${index}` - ) - return true -} - -export default function(suite) { - const bench = new Bench(suite, experiment, { - mode: 'adaptive', - minTries: 100, - maxTries: 200, - minTime: 1, - maxTime: 100, - async: true, - }) - - bench.run( - () => new Promise(resolve => setTimeout(() => resolve(index++), 10)) - ) -} diff --git a/packages/slate-dev-benchmark/test/time/max-time-with-small-step.js b/packages/slate-dev-benchmark/test/time/max-time-with-small-step.js deleted file mode 100644 index 86bda26c66..0000000000 --- a/packages/slate-dev-benchmark/test/time/max-time-with-small-step.js +++ /dev/null @@ -1,31 +0,0 @@ -import { Bench } from '../..' -import { syncSleep } from '../utils/sleep' -import assert from 'assert' - -export const experiment = 'max-time' - -let index = 0 - -export function expected() { - assert( - index > 85 && index < 115, - `index should be around 100, but is actually ${index}` - ) - return true -} - -export default function(suite) { - const bench = new Bench(suite, experiment, { - mode: 'adaptive', - minTries: 1000, - maxTries: 2000, - minTime: 1, - maxTime: 1000, - async: false, - }) - - bench.run(() => { - syncSleep(10) - index++ - }) -} diff --git a/packages/slate-dev-benchmark/test/time/max-time.js b/packages/slate-dev-benchmark/test/time/max-time.js deleted file mode 100644 index 3c9bb0639e..0000000000 --- a/packages/slate-dev-benchmark/test/time/max-time.js +++ /dev/null @@ -1,28 +0,0 @@ -import { Bench } from '../..' -import { syncSleep } from '../utils/sleep' -import assert from 'assert' - -export const experiment = 'max-time' - -let index = 0 - -export function expected() { - assert(index === 10, `index should be 10, but is actually ${index}`) - return true -} - -export default function(suite) { - const bench = new Bench(suite, experiment, { - mode: 'adaptive', - minTries: 100, - maxTries: 200, - minTime: 1, - maxTime: 100, - async: false, - }) - - bench.run(() => { - syncSleep(10) - index++ - }) -} diff --git a/packages/slate-dev-benchmark/test/tries/index.js b/packages/slate-dev-benchmark/test/tries/index.js deleted file mode 100644 index 801bb9c23b..0000000000 --- a/packages/slate-dev-benchmark/test/tries/index.js +++ /dev/null @@ -1,25 +0,0 @@ -import assert from 'assert' -import { repo, Suite } from '../..' -import fs from 'fs' -import { resolve } from 'path' - -describe('tries', async () => { - const suite = new Suite('tries') - const testDir = resolve(__dirname) - const files = fs - .readdirSync(testDir) - .filter(x => x[0] !== '.' && x !== 'index.js') - - for (const file of files) { - const module = require(`./${file}`) - - it(module.experiment, () => { - module.default(suite) - const { actual, expected } = module - repo.isFinished = false - return repo.run().then(() => { - assert.deepEqual(actual, expected) - }) - }) - } -}) diff --git a/packages/slate-dev-benchmark/test/tries/max-tries.js b/packages/slate-dev-benchmark/test/tries/max-tries.js deleted file mode 100644 index e7a434d457..0000000000 --- a/packages/slate-dev-benchmark/test/tries/max-tries.js +++ /dev/null @@ -1,19 +0,0 @@ -import { Bench } from '../..' - -export const experiment = 'max-tries adaptive mode' -export const actual = { index: 0 } -export const expected = { index: 200 } - -export default function(suite) { - const bench = new Bench(suite, experiment, { - mode: 'adaptive', - minTries: 100, - maxTries: 200, - minTime: 100, - maxTime: Infinity, - }) - - bench.run(() => { - actual.index++ - }) -} diff --git a/packages/slate-dev-benchmark/test/tries/min-tries.js b/packages/slate-dev-benchmark/test/tries/min-tries.js deleted file mode 100644 index ae1996f865..0000000000 --- a/packages/slate-dev-benchmark/test/tries/min-tries.js +++ /dev/null @@ -1,18 +0,0 @@ -import { Bench } from '../..' - -export const experiment = 'min-tries static mode' -export const actual = { index: 0 } -export const expected = { index: 100 } - -export default function(suite) { - const bench = new Bench(suite, experiment, { - mode: 'static', - minTries: 100, - maxTries: 200, - minTime: 100, - }) - - bench.run(() => { - actual.index++ - }) -} diff --git a/packages/slate-dev-benchmark/test/utils/sleep.js b/packages/slate-dev-benchmark/test/utils/sleep.js deleted file mode 100644 index 6cacce4c71..0000000000 --- a/packages/slate-dev-benchmark/test/utils/sleep.js +++ /dev/null @@ -1,10 +0,0 @@ -function syncSleep(ms) { - const start = process.hrtime() - - while (true) { - const end = process.hrtime(start) - if (end[0] * 1000 + end[1] / 1e6 > ms) return undefined - } -} - -export { syncSleep } diff --git a/packages/slate-dev-test-utils/Readme.md b/packages/slate-dev-test-utils/Readme.md deleted file mode 100644 index feda8fe15d..0000000000 --- a/packages/slate-dev-test-utils/Readme.md +++ /dev/null @@ -1 +0,0 @@ -This package contains a set of testing utilities used by Slate's other core packages for writing their tests. diff --git a/packages/slate-dev-test-utils/package.json b/packages/slate-dev-test-utils/package.json deleted file mode 100644 index 53903f9ffd..0000000000 --- a/packages/slate-dev-test-utils/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "slate-dev-test-utils", - "description": "INTERNAL: A set of utils for Slate's core tests.", - "version": "0.0.1", - "license": "MIT", - "repository": "git://github.com/ianstormtaylor/slate.git", - "main": "src/index.js", - "files": [ - "dist/", - "lib/" - ], - "peerDependencies": { - "slate": ">=0.35.0" - }, - "scripts": { - "clean": "rm -rf ./dist ./lib ./node_modules" - } -} diff --git a/packages/slate-dev-test-utils/test/index.js b/packages/slate-dev-test-utils/test/index.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/slate-html-serializer/test/index.js b/packages/slate-html-serializer/test/index.js index ff5f11f511..b39e30e4e3 100644 --- a/packages/slate-html-serializer/test/index.js +++ b/packages/slate-html-serializer/test/index.js @@ -2,7 +2,7 @@ import Html from 'slate-html-serializer' import assert from 'assert' import { JSDOM } from 'jsdom' import { Value } from 'slate' -import { fixtures } from 'slate-dev-test-utils' +import { fixtures } from '../../../support/fixtures' describe('slate-html-serializer', () => { fixtures(__dirname, 'deserialize', ({ module }) => { diff --git a/packages/slate-hyperscript/package.json b/packages/slate-hyperscript/package.json index 169325e412..67c12d696c 100644 --- a/packages/slate-hyperscript/package.json +++ b/packages/slate-hyperscript/package.json @@ -4,8 +4,9 @@ "version": "0.13.8", "license": "MIT", "repository": "git://github.com/ianstormtaylor/slate.git", - "main": "lib/slate-hyperscript.js", - "module": "lib/slate-hyperscript.es.js", + "main": "lib/index.js", + "module": "lib/index.es.js", + "types": "lib/index.d.ts", "umd": "dist/slate-hyperscript.js", "umdMin": "dist/slate-hyperscript.min.js", "files": [ @@ -19,12 +20,8 @@ "slate": ">=0.47.0" }, "devDependencies": { - "mocha": "^2.5.3", "slate": "^0.47.8" }, - "scripts": { - "clean": "rm -rf ./dist ./lib ./node_modules" - }, "umdGlobals": { "slate": "Slate" }, diff --git a/packages/slate-hyperscript/src/creators.js b/packages/slate-hyperscript/src/creators.js deleted file mode 100644 index dd6f15b231..0000000000 --- a/packages/slate-hyperscript/src/creators.js +++ /dev/null @@ -1,583 +0,0 @@ -import { - Annotation, - Document, - Mark, - Node, - Point, - Selection, - Text, - Value, -} from 'slate' - -/** - * Auto-incrementing ID to keep track of paired annotations. - * - * @type {Number} - */ - -let uid = 0 - -/** - * Create an anchor point. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {AnchorPoint} - */ - -export function createAnchor(tagName, attributes, children) { - return new AnchorPoint(attributes) -} - -/** - * Create a block. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {Block} - */ - -export function createBlock(tagName, attributes, children) { - const attrs = { ...attributes, object: 'block' } - const block = createNode(null, attrs, children) - return block -} - -/** - * Create a cursor point. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {CursorPoint} - */ - -export function createCursor(tagName, attributes, children) { - return new CursorPoint(attributes) -} - -/** - * Create a annotation point, or wrap a list of leaves and set the annotation - * point tracker on them. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {AnnotationPoint|List} - */ - -export function createAnnotation(tagName, attributes, children) { - const { key, data } = attributes - const type = tagName - - if (key) { - return new AnnotationPoint({ id: key, type, data }) - } - - const texts = createChildren(children) - const first = texts.first() - const last = texts.last() - const id = `${uid++}` - const start = new AnnotationPoint({ id, type, data }) - const end = new AnnotationPoint({ id, type, data }) - setPoint(first, start, 0) - setPoint(last, end, last.text.length) - return texts -} - -/** - * Create a document. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {Document} - */ - -export function createDocument(tagName, attributes, children) { - const attrs = { ...attributes, object: 'document' } - const document = createNode(null, attrs, children) - return document -} - -/** - * Create a focus point. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {FocusPoint} - */ - -export function createFocus(tagName, attributes, children) { - return new FocusPoint(attributes) -} - -/** - * Create an inline. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {Inline} - */ - -export function createInline(tagName, attributes, children) { - const attrs = { ...attributes, object: 'inline' } - const inline = createNode(null, attrs, children) - return inline -} - -/** - * Create a list of leaves from a mark. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {List} - */ - -export function createMark(tagName, attributes, children) { - const { key, ...mark } = attributes - const marks = Mark.createSet([mark]) - const list = createChildren(children) - let node - - if (list.size > 1) { - throw new Error( - `The hyperscript tag must only contain a single node's worth of children.` - ) - } else if (list.size === 0) { - node = Text.create({ key, marks }) - } else { - node = list.first() - - node = preservePoints(node, n => { - if (key) n = n.set('key', key) - if (marks) n = n.set('marks', n.marks.union(marks)) - return n - }) - } - - return node -} - -/** - * Create a node. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {Node} - */ - -export function createNode(tagName, attributes, children) { - const { object } = attributes - - if (object === 'text') { - const text = createText(null, attributes, children) - return text - } - - const nodes = createChildren(children) - const node = Node.create({ ...attributes, nodes }) - return node -} - -/** - * Create a selection. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {Selection} - */ - -export function createSelection(tagName, attributes, children) { - const anchor = children.find(c => c instanceof AnchorPoint) - const focus = children.find(c => c instanceof FocusPoint) - const { marks, focused } = attributes - const selection = Selection.create({ - marks, - isFocused: focused, - anchor: anchor && { - key: anchor.key, - offset: anchor.offset, - path: anchor.path, - }, - focus: focus && { - key: focus.key, - offset: focus.offset, - path: focus.path, - }, - }) - - return selection -} - -/** - * Create a text node. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {Text} - */ - -export function createText(tagName, attributes, children) { - const { key, marks } = attributes - const list = createChildren(children) - let node - - if (list.size > 1) { - throw new Error( - `The hyperscript tag must only contain a single node's worth of children.` - ) - } else if (list.size === 0) { - node = Text.create({ key }) - } else { - node = list.first() - - node = preservePoints(node, n => { - if (key) n = n.set('key', key) - if (marks) n = n.set('marks', Mark.createSet(marks)) - return n - }) - } - - return node -} - -/** - * Create a value. - * - * @param {String} tagName - * @param {Object} attributes - * @param {Array} children - * @return {Value} - */ - -export function createValue(tagName, attributes, children) { - const { data } = attributes - const document = children.find(Document.isDocument) - let selection = children.find(Selection.isSelection) - let anchor - let focus - let marks - let isFocused - let annotations = {} - const partials = {} - - // Search the document's texts to see if any of them have the anchor or - // focus information saved, or annotations applied. - if (document) { - for (const [node, path] of document.texts()) { - const { __anchor, __annotations, __focus } = node - - if (__anchor != null) { - anchor = Point.create({ path, key: node.key, offset: __anchor.offset }) - marks = __anchor.marks - isFocused = __anchor.isFocused - } - - if (__focus != null) { - focus = Point.create({ path, key: node.key, offset: __focus.offset }) - marks = __focus.marks - isFocused = __focus.isFocused - } - - if (__annotations != null) { - for (const ann of __annotations) { - const { id } = ann - const partial = partials[id] - delete partials[id] - - if (!partial) { - ann.key = node.key - ann.path = path - partials[id] = ann - continue - } - - const annotation = Annotation.create({ - key: id, - type: ann.type, - data: ann.data, - anchor: { - key: partial.key, - path: partial.path, - offset: partial.offset, - }, - focus: { - path, - key: node.key, - offset: ann.offset, - }, - }) - - annotations[id] = annotation - } - } - } - } - - if (Object.keys(partials).length > 0) { - throw new Error( - `Slate hyperscript must have both a start and an end defined for each annotation using the \`key=\` prop.` - ) - } - - if (anchor && !focus) { - throw new Error( - `Slate hyperscript ranges must have both \`\` and \`\` defined if one is defined, but you only defined \`\`. For collapsed selections, use \`\` instead.` - ) - } - - if (!anchor && focus) { - throw new Error( - `Slate hyperscript ranges must have both \`\` and \`\` defined if one is defined, but you only defined \`\`. For collapsed selections, use \`\` instead.` - ) - } - - if (anchor || focus) { - if (!selection) { - selection = Selection.create({ anchor, focus, isFocused, marks }) - } else { - selection = selection.setPoints([anchor, focus]) - } - } else if (!selection) { - selection = Selection.create() - } - - selection = selection.normalize(document) - - if (annotations.length > 0) { - annotations = annotations.map(a => a.normalize(document)) - } - - const value = Value.fromJSON({ - data, - annotations, - document, - selection, - ...attributes, - }) - - return value -} - -/** - * Create a list of text nodes. - * - * @param {Array} children - * @return {List} - */ - -export function createChildren(children) { - let nodes = Node.createList() - - const push = node => { - const last = nodes.last() - const isString = typeof node === 'string' - - if (last && last.__string && (isString || node.__string)) { - const text = isString ? node : node.text - const { length } = last.text - const next = preservePoints(last, l => l.insertText(length, text)) - incrementPoints(node, length) - copyPoints(node, next) - next.__string = true - nodes = nodes.pop().push(next) - } else if (isString) { - node = Text.create({ text: node }) - node.__string = true - nodes = nodes.push(node) - } else { - nodes = nodes.push(node) - } - } - - children.forEach(child => { - if (Node.isNodeList(child)) { - child.forEach(c => push(c)) - } - - if (Node.isNode(child)) { - push(child) - } - - if (typeof child === 'string') { - push(child) - } - - if (isPoint(child)) { - if (!nodes.size) { - push('') - } - - let last = nodes.last() - - if (last.object !== 'text') { - push('') - last = nodes.last() - } - - if (!last || !last.__string) { - push('') - last = nodes.last() - } - - setPoint(last, child, last.text.length) - } - }) - - return nodes -} - -/** - * Point classes that can be created at different points in the document and - * then searched for afterwards, for creating ranges. - * - * @type {Class} - */ - -class CursorPoint { - constructor(attrs = {}) { - const { isFocused = true, marks = null } = attrs - this.isFocused = isFocused - this.marks = marks - this.offset = null - } -} - -class AnchorPoint { - constructor(attrs = {}) { - const { - isFocused = true, - key = null, - marks = null, - offset = null, - path = null, - } = attrs - this.isFocused = isFocused - this.key = key - this.marks = marks - this.offset = offset - this.path = path - } -} - -class FocusPoint { - constructor(attrs = {}) { - const { - isFocused = true, - key = null, - marks = null, - offset = null, - path = null, - } = attrs - this.isFocused = isFocused - this.key = key - this.marks = marks - this.offset = offset - this.path = path - } -} - -class AnnotationPoint { - constructor(attrs) { - const { id = null, data = {}, type } = attrs - this.id = id - this.offset = null - this.type = type - this.data = data - } -} - -/** - * Increment any existing `point` on object by `n`. - * - * @param {Any} object - * @param {Number} n - */ - -function incrementPoints(object, n) { - const { __anchor, __focus, __annotations } = object - - if (__anchor != null) { - __anchor.offset += n - } - - if (__focus != null && __focus !== __anchor) { - __focus.offset += n - } - - if (__annotations != null) { - __annotations.forEach(a => (a.offset += n)) - } -} - -/** - * Check whether an `object` is a point. - * - * @param {Any} object - * @return {Boolean} - */ - -function isPoint(object) { - return ( - object instanceof AnchorPoint || - object instanceof CursorPoint || - object instanceof AnnotationPoint || - object instanceof FocusPoint - ) -} - -/** - * Preserve any point information on an object. - * - * @param {Any} object - * @param {Function} updator - * @return {Any} - */ - -function preservePoints(object, updator) { - const next = updator(object) - copyPoints(object, next) - return next -} - -function copyPoints(object, other) { - const { __anchor, __focus, __annotations } = object - if (__anchor != null) other.__anchor = __anchor - if (__focus != null) other.__focus = __focus - if (__annotations != null) other.__annotations = __annotations -} - -/** - * Set a `point` on an `object`. - * - * @param {Any} object - * @param {*Point} point - * @param {Number} offset - */ - -function setPoint(object, point, offset) { - if (point instanceof AnchorPoint || point instanceof CursorPoint) { - point.offset = offset - object.__anchor = point - } - - if (point instanceof FocusPoint || point instanceof CursorPoint) { - point.offset = offset - object.__focus = point - } - - if (point instanceof AnnotationPoint) { - point.offset = offset - object.__annotations = object.__annotations || [] - object.__annotations = object.__annotations.concat(point) - } -} diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts new file mode 100644 index 0000000000..29c1520e06 --- /dev/null +++ b/packages/slate-hyperscript/src/creators.ts @@ -0,0 +1,301 @@ +import { Element, Mark, Node, Path, Selection, Text, Value } from 'slate' +import { resolveDescendants } from './resolve-descendants' +import { + AnchorToken, + AnnotationToken, + FocusToken, + Token, + getAnchorOffset, + getFocusOffset, + getAnnotationOffsets, +} from './tokens' + +/** + * Create an anchor token. + */ + +export function createAnchor( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): AnchorToken { + return new AnchorToken(attributes) +} + +/** + * Create an annotation token, or two. + */ + +export function createAnnotation( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): (Node | Token)[] { + if (!('key' in attributes)) { + throw new Error( + `The tag must be passed a unique \`key\` string attribute to uniquely identify it.` + ) + } + + const { key, ...rest } = attributes + + if (children.length === 0) { + return [new AnnotationToken({ key, ...rest })] + } else { + const array: (Node | Token)[] = resolveDescendants(children) + const start = new AnnotationToken({ key, ...rest }) + const end = new AnnotationToken({ key, ...rest }) + array.unshift(start) + array.push(end) + return array + } +} + +/** + * Create an anchor and a focus token. + */ + +export function createCursor( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): Token[] { + return [new AnchorToken(attributes), new FocusToken(attributes)] +} + +/** + * Create an `Element` object. + */ + +export function createElement( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): Element { + return { ...attributes, nodes: resolveDescendants(children) } +} + +/** + * Create a focus token. + */ + +export function createFocus( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): FocusToken { + return new FocusToken(attributes) +} + +/** + * Create a `Text` object with a mark applied. + */ + +export function createMark( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): Text { + const mark = { ...attributes } + const nodes = resolveDescendants(children) + + if (nodes.length > 1) { + throw new Error( + `The hyperscript tag must only contain a single node's worth of children.` + ) + } + + if (nodes.length === 0) { + return { text: '', marks: [mark] } + } + + const [node] = nodes + + if (!Text.isText(node)) { + throw new Error( + `The hyperscript tag must only contain text content as children.` + ) + } + + if (!Mark.exists(mark, node.marks)) { + node.marks.push(mark) + } + + return node +} + +/** + * Create a `Selection` object. + */ + +export function createSelection( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): Selection { + const anchor: AnchorToken = children.find(c => c instanceof AnchorToken) + const focus: FocusToken = children.find(c => c instanceof FocusToken) + + if (!anchor || !anchor.offset || !anchor.path) { + throw new Error( + `The hyperscript tag must have an tag as a child with \`path\` and \`offset\` attributes defined.` + ) + } + + if (!focus || !focus.offset || !focus.path) { + throw new Error( + `The hyperscript tag must have a tag as a child with \`path\` and \`offset\` attributes defined.` + ) + } + + return { + anchor: { + offset: anchor.offset, + path: anchor.path, + }, + focus: { + offset: focus.offset, + path: focus.path, + }, + isFocused: 'focused' in attributes ? attributes.focused : false, + marks: 'marks' in attributes ? attributes.marks : null, + } +} + +/** + * Create a `Text` object. + */ + +export function createText( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): Text { + const nodes = resolveDescendants(children) + + if (nodes.length > 1) { + throw new Error( + `The hyperscript tag must only contain a single node's worth of children.` + ) + } + + let [node] = nodes + + if (node == null) { + node = { text: '', marks: [] } + } + + if (!Text.isText(node)) { + throw new Error(` + The hyperscript tag can only contain text content as children.`) + } + + Object.assign(node, attributes) + return node +} + +/** + * Create a top-level `Value` object. + */ + +export function createValue( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +) { + const otherChildren: any[] = [] + let selectionChild: Selection | undefined + + for (const child of children) { + if (Selection.isSelection(child)) { + selectionChild = child + } else { + otherChildren.push(child) + } + } + + const nodes = resolveDescendants(otherChildren) + const value: Value = { + nodes, + selection: null, + annotations: {}, + ...attributes, + } + + const selection: any = { + isFocused: false, + marks: null, + } + + const partials: Record = {} + + // Search the document's texts to see if any of them have tokens associated + // that need incorporated into the selection or annotations. + for (const [node, path] of Node.texts(value)) { + const anchor = getAnchorOffset(node) + const focus = getFocusOffset(node) + const anns = getAnnotationOffsets(node) + + if (anchor != null) { + const [offset, token] = anchor + debugger + selection.anchor = { path, offset } + selection.isFocused = token.focused + selection.marks = token.marks + } + + if (focus != null) { + const [offset, token] = focus + debugger + selection.focus = { path, offset } + selection.isFocused = token.focused + selection.marks = token.marks + } + + for (const o in anns) { + const offset = parseInt(o) + const token = anns[offset] + const { key } = token + const partial = partials[key] + + if (!partial) { + partials[key] = [path, offset, token] + } else { + const [pPath, pOffset, pToken] = partial + delete partials[key] + value.annotations[key] = { + anchor: { path: pPath, offset: pOffset }, + focus: { path, offset }, + ...pToken.props, + ...token.props, + } + } + } + } + + if (Object.keys(partials).length > 0) { + throw new Error( + `Slate hyperscript must have both a start and an end defined for each tag using the \`key=\` prop.` + ) + } + + if (selection.anchor && !selection.focus) { + throw new Error( + `Slate hyperscript ranges must have both \`\` and \`\` defined if one is defined, but you only defined \`\`. For collapsed selections, use \`\` instead.` + ) + } + + if (!selection.anchor && selection.focus) { + throw new Error( + `Slate hyperscript ranges must have both \`\` and \`\` defined if one is defined, but you only defined \`\`. For collapsed selections, use \`\` instead.` + ) + } + + if (selectionChild != null) { + value.selection = selectionChild + } else if (Selection.isSelection(selection)) { + value.selection = selection + } + + return value +} diff --git a/packages/slate-hyperscript/src/index.js b/packages/slate-hyperscript/src/index.js deleted file mode 100644 index d51ecd9d2b..0000000000 --- a/packages/slate-hyperscript/src/index.js +++ /dev/null @@ -1,132 +0,0 @@ -import isPlainObject from 'is-plain-object' - -import { - createAnchor, - createBlock, - createCursor, - createAnnotation, - createDocument, - createFocus, - createInline, - createMark, - createNode, - createSelection, - createText, - createValue, -} from './creators' - -/** - * Create a Slate hyperscript function with `options`. - * - * @param {Object} options - * @return {Function} - */ - -function createHyperscript(options = {}) { - const { blocks = {}, inlines = {}, marks = {}, annotations = {} } = options - - const creators = { - anchor: createAnchor, - annotation: createAnnotation, - block: createBlock, - cursor: createCursor, - document: createDocument, - focus: createFocus, - inline: createInline, - mark: createMark, - node: createNode, - selection: createSelection, - text: createText, - value: createValue, - ...(options.creators || {}), - } - - for (const key in blocks) { - creators[key] = normalizeCreator(blocks[key], createBlock) - } - - for (const key in inlines) { - creators[key] = normalizeCreator(inlines[key], createInline) - } - - for (const key in marks) { - creators[key] = normalizeCreator(marks[key], createMark) - } - - for (const key in annotations) { - creators[key] = normalizeCreator(annotations[key], createAnnotation) - } - - function create(tagName, attributes, ...children) { - const creator = creators[tagName] - - if (!creator) { - throw new Error(`No hyperscript creator found for tag: "${tagName}"`) - } - - if (attributes == null) { - attributes = {} - } - - if (!isPlainObject(attributes)) { - children = [attributes].concat(children) - attributes = {} - } - - children = children - .filter(child => Boolean(child)) - .reduce((memo, child) => memo.concat(child), []) - - const ret = creator(tagName, attributes, children) - return ret - } - - return create -} - -/** - * Normalize a `creator` of `value`. - * - * @param {Function|Object|String} value - * @param {Function} creator - * @return {Function} - */ - -function normalizeCreator(value, creator) { - if (typeof value === 'function') { - return value - } - - if (typeof value === 'string') { - value = { type: value } - } - - if (isPlainObject(value)) { - return (tagName, attributes, children) => { - const { key, ...rest } = attributes - const attrs = { - ...value, - key, - data: { - ...(value.data || {}), - ...rest, - }, - } - - return creator(tagName, attrs, children) - } - } - - throw new Error( - `Slate hyperscript creators can be either functions, objects or strings, but you passed: ${value}` - ) -} - -/** - * Export. - * - * @type {Function} - */ - -export default createHyperscript() -export { createHyperscript } diff --git a/packages/slate-hyperscript/src/index.ts b/packages/slate-hyperscript/src/index.ts new file mode 100644 index 0000000000..cf5e51f3a1 --- /dev/null +++ b/packages/slate-hyperscript/src/index.ts @@ -0,0 +1,205 @@ +import isPlainObject from 'is-plain-object' +import { Element, Mark } from 'slate' +import { Token } from './tokens' +import { + createAnchor, + createCursor, + createAnnotation, + createElement, + createFocus, + createMark, + createSelection, + createText, + createValue, +} from './creators' + +/** + * The default creators for Slate objects. + */ + +const DEFAULT_CREATORS = { + anchor: createAnchor, + annotation: createAnnotation, + cursor: createCursor, + element: createElement, + focus: createFocus, + mark: createMark, + selection: createSelection, + text: createText, + value: createValue, +} + +/** + * `HyperscriptCreators` are dictionaries of `HyperscriptCreator` functions + * keyed by tag name. + */ + +type HyperscriptCreators = Record< + string, + (tagName: string, attributes: { [key: string]: any }, children: any[]) => T +> + +/** + * `HyperscriptShorthands` are dictionaries of properties applied to specific + * kind of object, keyed by tag name. They allow you to easily define custom + * hyperscript tags for your schema. + */ + +type HyperscriptShorthands = Record> + +/** + * Create a Slate hyperscript function with `options`. + */ + +const createHyperscript = ( + options: { + creators?: HyperscriptCreators + elements?: HyperscriptShorthands + marks?: HyperscriptShorthands + annotations?: HyperscriptShorthands + } = {} +) => { + const { annotations = {}, elements = {}, marks = {} } = options + const annotationCreators = normalizeAnnotations(annotations) + const elementCreators = normalizeElements(elements) + const markCreators = normalizeMarks(marks) + const creators = { + ...DEFAULT_CREATORS, + ...annotationCreators, + ...elementCreators, + ...markCreators, + ...options.creators, + } + + const h = createFactory(creators) + return h +} + +/** + * Create a Slate hyperscript function with `options`. + */ + +const createFactory = (creators: T) => { + const h = ( + tagName: S, + attributes?: Object, + ...children: any[] + ): ReturnType => { + const creator = creators[tagName] + + if (!creator) { + throw new Error(`No hyperscript creator found for tag: <${tagName}>`) + } + + if (attributes == null) { + attributes = {} + } + + if (!isPlainObject(attributes)) { + children = [attributes].concat(children) + attributes = {} + } + + children = children.filter(child => Boolean(child)).flat() + const ret = creator(tagName, attributes, children) + return ret + } + + return h +} + +/** + * Normalize a dictionary of element shorthands into creator functions. + */ + +const normalizeElements = (elements: HyperscriptShorthands) => { + const creators: HyperscriptCreators = {} + + for (const tagName in elements) { + const props = elements[tagName] + + if (typeof props !== 'object') { + throw new Error( + `Properties specified for a hyperscript shorthand should be an object, but for the custom <${tagName}> tag you passed: ${props}` + ) + } + + creators[tagName] = ( + tagName: string, + attributes: { [key: string]: any }, + children: any[] + ) => { + return createElement('element', { ...props, ...attributes }, children) + } + } + + return creators +} + +/** + * Normalize a dictionary of mark shorthands into creator functions. + */ + +const normalizeMarks = (marks: HyperscriptShorthands) => { + const creators: HyperscriptCreators = {} + + for (const tagName in marks) { + const props = marks[tagName] + + if (typeof props !== 'object') { + throw new Error( + `Properties specified for a hyperscript shorthand should be an object, but for the custom <${tagName}> tag you passed: ${props}` + ) + } + + creators[tagName] = ( + tagName: string, + attributes: { [key: string]: any }, + children: any[] + ) => { + return createMark('mark', { ...props, ...attributes }, children) + } + } + + return creators +} + +/** + * Normalize a dictionary of annotation shorthands into creator functions. + */ + +const normalizeAnnotations = (annotations: HyperscriptShorthands) => { + const creators: HyperscriptCreators<(Node | Token)[]> = {} + + for (const tagName in annotations) { + const props = annotations[tagName] + + if (typeof props !== 'object') { + throw new Error( + `Properties specified for a hyperscript shorthand should be an object, but for the custom <${tagName}> tag you passed: ${props}` + ) + } + + creators[tagName] = ( + tagName: string, + attributes: { [key: string]: any }, + children: any[] + ) => { + return createAnnotation( + 'annotation', + { ...props, ...attributes }, + children + ) + } + } + + return creators +} + +/** + * The default hyperscript factory that ships with Slate, without custom tags. + */ + +const h = createHyperscript() +export default h +export { createHyperscript, HyperscriptCreators, HyperscriptShorthands } diff --git a/packages/slate-hyperscript/src/resolve-descendants.ts b/packages/slate-hyperscript/src/resolve-descendants.ts new file mode 100644 index 0000000000..5b8f16c0e5 --- /dev/null +++ b/packages/slate-hyperscript/src/resolve-descendants.ts @@ -0,0 +1,71 @@ +import { Descendant, Element, Mark, Node, Text } from 'slate' +import { + AnchorToken, + AnnotationToken, + FocusToken, + Token, + addAnchorToken, + addAnnotationToken, + addFocusToken, +} from './tokens' + +/** + * Resolve the descedants of a node by normalizing the children that can be + * passed into a hyperscript creator function. + */ + +const STRINGS: WeakSet = new WeakSet() + +export const resolveDescendants = (children: any[]): Descendant[] => { + const nodes: Node[] = [] + + const addChild = (child: Node | Token): void => { + const prev = nodes[nodes.length - 1] + + if (typeof child === 'string') { + const text = { text: child, marks: [] } + STRINGS.add(text) + child = text + } + + if (Text.isText(child)) { + const c = child // HACK: fix typescript complaining + if ( + Text.isText(prev) && + STRINGS.has(prev) && + STRINGS.has(c) && + c.marks.every(m => Mark.exists(m, prev.marks)) && + prev.marks.every(m => Mark.exists(m, c.marks)) + ) { + prev.text += c.text + } else { + nodes.push(c) + } + } else if (Element.isElement(child)) { + nodes.push(child) + } else if (child instanceof Token) { + let n = nodes[nodes.length - 1] + + if (!Text.isText(n)) { + addChild('') + n = nodes[nodes.length - 1] as Text + } + + if (child instanceof AnchorToken) { + addAnchorToken(n, child) + } else if (child instanceof FocusToken) { + addFocusToken(n, child) + } else if (child instanceof AnnotationToken) { + addAnnotationToken(n, child) + } + } else { + throw new Error(`Unexpected hyperscript child object: ${child}`) + } + } + + for (const child of children.flat()) { + addChild(child) + } + + return nodes +} diff --git a/packages/slate-hyperscript/src/tokens.ts b/packages/slate-hyperscript/src/tokens.ts new file mode 100644 index 0000000000..cdf26bb9fe --- /dev/null +++ b/packages/slate-hyperscript/src/tokens.ts @@ -0,0 +1,159 @@ +import { Mark, Node, Path, Text } from 'slate' + +/** + * A weak map to hold anchor tokens. + */ + +const ANCHOR: WeakMap = new WeakMap() + +/** + * A weak map to hold focus tokens. + */ + +const FOCUS: WeakMap = new WeakMap() + +/** + * A weak map to hold annotation tokens. + */ + +const ANNOTATION: WeakMap> = new WeakMap() + +/** + * All tokens inherit from a single constructor for `instanceof` checking. + */ + +export class Token {} + +/** + * Anchor tokens represent the selection's anchor point. + */ + +export class AnchorToken extends Token { + focused: boolean + marks: Mark[] | null + offset?: number + path?: Path + + constructor( + props: { + focused?: boolean + marks?: Mark[] | null + offset?: number + path?: Path + } = {} + ) { + super() + const { focused = true, marks = null, offset, path } = props + this.focused = focused + this.marks = marks + this.offset = offset + this.path = path + } +} + +/** + * Focus tokens represent the selection's focus point. + */ + +export class FocusToken extends Token { + focused: boolean + marks: Mark[] | null + offset?: number + path?: Path + + constructor( + props: { + focused?: boolean + marks?: Mark[] | null + offset?: number + path?: Path + } = {} + ) { + super() + const { focused = true, marks = null, offset, path } = props + this.focused = focused + this.marks = marks + this.offset = offset + this.path = path + } +} + +/** + * Annotation tokens represent an edge of an annotation range. + */ + +export class AnnotationToken extends Token { + key: string + props: {} + + constructor(props: { key: string }) { + super() + const { key, ...rest } = props + this.key = key + this.props = rest + } +} + +/** + * Add an anchor token to the end of a text node. + */ + +export const addAnchorToken = (text: Text, token: AnchorToken) => { + const offset = text.text.length + ANCHOR.set(text, [offset, token]) +} + +/** + * Get the offset if a text node has an associated anchor token. + */ + +export const getAnchorOffset = ( + text: Text +): [number, AnchorToken] | undefined => { + return ANCHOR.get(text) +} + +/** + * Add a focus token to the end of a text node. + */ + +export const addFocusToken = (text: Text, token: FocusToken) => { + const offset = text.text.length + FOCUS.set(text, [offset, token]) +} + +/** + * Get the offset if a text node has an associated focus token. + */ + +export const getFocusOffset = ( + text: Text +): [number, FocusToken] | undefined => { + return FOCUS.get(text) +} + +/** + * Add an annotation token to the end of a text node. + */ + +export const addAnnotationToken = (text: Text, token: AnnotationToken) => { + let map = ANNOTATION.get(text) + + if (map == null) { + map = {} + ANNOTATION.set(text, map) + } + + const offset = text.text.length + map[offset] = token +} + +/** + * Get the offset if a text node has an associated focus token. + */ + +export const getAnnotationOffsets = ( + text: Text +): Record | undefined => { + return ANNOTATION.get(text) +} diff --git a/packages/slate-hyperscript/test/annotations/across-blocks.js b/packages/slate-hyperscript/test/annotations/across-blocks.js deleted file mode 100644 index 5114aa7e90..0000000000 --- a/packages/slate-hyperscript/test/annotations/across-blocks.js +++ /dev/null @@ -1,80 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - annotations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - - - This is one block. - - - This is block two. - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is one block.', - marks: [], - }, - ], - }, - ], - }, - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is block two.', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} - -export const expectAnnotations = [ - { - type: 'highlight', - data: {}, - anchorOffset: 12, - focusOffset: 13, - anchorKey: input.document.nodes.get(0).getFirstText().key, - focusKey: input.document.nodes.get(1).getFirstText().key, - }, -] diff --git a/packages/slate-hyperscript/test/annotations/across-marks.js b/packages/slate-hyperscript/test/annotations/across-marks.js deleted file mode 100644 index edab064ff0..0000000000 --- a/packages/slate-hyperscript/test/annotations/across-marks.js +++ /dev/null @@ -1,88 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - marks: { - b: 'bold', - }, - decorations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - - - This is a{' '} - - paragraph with - {' '} - a cursor position (closed selection). - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is a paragraph ', - marks: [], - }, - { - object: 'leaf', - text: 'with', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'leaf', - text: ' a cursor position (closed selection).', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} - -export const expectDecorations = [ - { - anchorOffset: 10, - focusOffset: 24, - anchorKey: input.texts.get(0).key, - focusKey: input.texts.get(0).key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, -] diff --git a/packages/slate-hyperscript/test/annotations/deep-anchors.js b/packages/slate-hyperscript/test/annotations/deep-anchors.js deleted file mode 100644 index 0792363aa0..0000000000 --- a/packages/slate-hyperscript/test/annotations/deep-anchors.js +++ /dev/null @@ -1,101 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - ul: 'ul', - li: 'li', - }, - decorations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - -
    -
  • - Item one. -
  • -
  • - Item two. -
  • -
-
-
-) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'ul', - data: {}, - nodes: [ - { - object: 'block', - type: 'li', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'Item one.', - marks: [], - }, - ], - }, - ], - }, - { - object: 'block', - type: 'li', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'Item two.', - marks: [], - }, - ], - }, - ], - }, - ], - }, - ], - }, -} - -export const expectDecorations = [ - { - anchorOffset: 5, - focusOffset: 4, - anchorKey: input.document - .filterDescendants(n => n.type === 'li') - .get(0) - .getFirstText().key, - focusKey: input.document - .filterDescendants(n => n.type === 'li') - .get(1) - .getFirstText().key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, -] diff --git a/packages/slate-hyperscript/test/annotations/intersecting-marks.js b/packages/slate-hyperscript/test/annotations/intersecting-marks.js deleted file mode 100644 index 62ac8e3852..0000000000 --- a/packages/slate-hyperscript/test/annotations/intersecting-marks.js +++ /dev/null @@ -1,88 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - marks: { - b: 'bold', - }, - decorations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - - - This is a paragraph{' '} - - with - {' '} - a highlight. - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is a paragraph ', - marks: [], - }, - { - object: 'leaf', - text: 'with', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'leaf', - text: ' a highlight.', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} - -export const expectDecorations = [ - { - anchorOffset: 10, - focusOffset: 24, - anchorKey: input.texts.get(0).key, - focusKey: input.texts.get(0).key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, -] diff --git a/packages/slate-hyperscript/test/annotations/multiple.js b/packages/slate-hyperscript/test/annotations/multiple.js deleted file mode 100644 index 2826485217..0000000000 --- a/packages/slate-hyperscript/test/annotations/multiple.js +++ /dev/null @@ -1,80 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - decorations: { - highlight: 'highlight', - lowlight: 'lowlight', - }, -}) - -export const input = ( - - - - This is a paragraph with two{' '} - decorations. - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is a paragraph with two decorations.', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} - -export const expectDecorations = [ - { - anchorOffset: 10, - focusOffset: 24, - anchorKey: input.texts.get(0).key, - focusKey: input.texts.get(0).key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, - { - anchorOffset: 29, - focusOffset: 40, - anchorKey: input.texts.get(0).key, - focusKey: input.texts.get(0).key, - marks: [ - { - object: 'mark', - type: 'lowlight', - data: {}, - }, - ], - }, -] diff --git a/packages/slate-hyperscript/test/annotations/nested.js b/packages/slate-hyperscript/test/annotations/nested.js deleted file mode 100644 index e6c4ad2ae9..0000000000 --- a/packages/slate-hyperscript/test/annotations/nested.js +++ /dev/null @@ -1,98 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - decorations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - - - This is one block. - - - This is block two. - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is one block.', - marks: [], - }, - ], - }, - ], - }, - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is block two.', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} - -export const expectDecorations = [ - { - anchorOffset: 12, - focusOffset: 0, - anchorKey: input.document.nodes.get(0).getFirstText().key, - focusKey: input.document.nodes.get(1).getFirstText().key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, - { - anchorOffset: 0, - focusOffset: 13, - anchorKey: input.document.nodes.get(0).getFirstText().key, - focusKey: input.document.nodes.get(1).getFirstText().key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, -] diff --git a/packages/slate-hyperscript/test/annotations/overlapping.js b/packages/slate-hyperscript/test/annotations/overlapping.js deleted file mode 100644 index 89f03819da..0000000000 --- a/packages/slate-hyperscript/test/annotations/overlapping.js +++ /dev/null @@ -1,98 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - decorations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - - - This is one block. - - - This is block two. - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is one block.', - marks: [], - }, - ], - }, - ], - }, - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - leaves: [ - { - object: 'leaf', - text: 'This is block two.', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} - -export const expectDecorations = [ - { - anchorOffset: 0, - focusOffset: 0, - anchorKey: input.document.nodes.get(0).getFirstText().key, - focusKey: input.document.nodes.get(1).getFirstText().key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, - { - anchorOffset: 12, - focusOffset: 13, - anchorKey: input.document.nodes.get(0).getFirstText().key, - focusKey: input.document.nodes.get(1).getFirstText().key, - marks: [ - { - object: 'mark', - type: 'highlight', - data: {}, - }, - ], - }, -] diff --git a/packages/slate-hyperscript/test/fixtures/annotation-across-block.js b/packages/slate-hyperscript/test/fixtures/annotation-across-block.js deleted file mode 100644 index 50e070b31a..0000000000 --- a/packages/slate-hyperscript/test/fixtures/annotation-across-block.js +++ /dev/null @@ -1,72 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - annotations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - - - onetwothree - - - -) - -export const options = { - preserveAnnotations: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '3', - data: {}, - nodes: [ - { - object: 'block', - key: '2', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '1', - text: 'onetwothree', - marks: [], - }, - ], - }, - ], - }, - annotations: { - '0': { - key: '0', - object: 'annotation', - type: 'highlight', - data: {}, - anchor: { - object: 'point', - key: '1', - path: [0, 0], - offset: 3, - }, - focus: { - object: 'point', - key: '1', - path: [0, 0], - offset: 6, - }, - }, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-across-element.js b/packages/slate-hyperscript/test/fixtures/annotation-across-element.js new file mode 100644 index 0000000000..c36ac992aa --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/annotation-across-element.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + onetwothree + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'onetwothree', + marks: [], + }, + ], + }, + ], + selection: null, + annotations: { + a: { + anchor: { + path: [0, 0], + offset: 3, + }, + focus: { + path: [0, 0], + offset: 6, + }, + }, + }, +} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-across-elements.js b/packages/slate-hyperscript/test/fixtures/annotation-across-elements.js new file mode 100644 index 0000000000..05287c448e --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/annotation-across-elements.js @@ -0,0 +1,48 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: null, + annotations: { + a: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [1, 0], + offset: 2, + }, + }, + }, +} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-across-mark.js b/packages/slate-hyperscript/test/fixtures/annotation-across-mark.js new file mode 100644 index 0000000000..12f1d33867 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/annotation-across-mark.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + word + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'word', + marks: [{}], + }, + ], + }, + ], + selection: null, + annotations: { + a: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [0, 0], + offset: 3, + }, + }, + }, +} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-across-marks.js b/packages/slate-hyperscript/test/fixtures/annotation-across-marks.js new file mode 100644 index 0000000000..5aec8e0f43 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/annotation-across-marks.js @@ -0,0 +1,53 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + o + ne + + + + + two + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [{}], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [{}], + }, + ], + }, + ], + selection: null, + annotations: { + a: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [1, 0], + offset: 2, + }, + }, + }, +} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-across-multiple-blocks.js b/packages/slate-hyperscript/test/fixtures/annotation-across-multiple-blocks.js deleted file mode 100644 index 577de6e8e3..0000000000 --- a/packages/slate-hyperscript/test/fixtures/annotation-across-multiple-blocks.js +++ /dev/null @@ -1,89 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - annotations: { - highlight: 'highlight', - }, -}) - -export const input = ( - - - - one - - - two - - - -) - -export const options = { - preserveAnnotations: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '4', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'two', - marks: [], - }, - ], - }, - ], - }, - annotations: { - a: { - object: 'annotation', - key: 'a', - type: 'highlight', - data: {}, - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 1, - }, - focus: { - object: 'point', - key: '2', - path: [1, 0], - offset: 2, - }, - }, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-custom.js b/packages/slate-hyperscript/test/fixtures/annotation-custom.js new file mode 100644 index 0000000000..cf8239eceb --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/annotation-custom.js @@ -0,0 +1,55 @@ +/** @jsx h */ + +import { createHyperscript } from 'slate-hyperscript' + +const h = createHyperscript({ + annotations: { + highlight: { type: 'highlight' }, + }, +}) + +export const input = ( + + + one + + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: null, + annotations: { + a: { + type: 'highlight', + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [1, 0], + offset: 2, + }, + }, + }, +} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-nested.js b/packages/slate-hyperscript/test/fixtures/annotation-nested.js new file mode 100644 index 0000000000..c7627257ec --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/annotation-nested.js @@ -0,0 +1,58 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: null, + annotations: { + a: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [1, 0], + offset: 2, + }, + }, + b: { + anchor: { + path: [0, 0], + offset: 2, + }, + focus: { + path: [1, 0], + offset: 1, + }, + }, + }, +} diff --git a/packages/slate-hyperscript/test/fixtures/annotation-overlapping.js b/packages/slate-hyperscript/test/fixtures/annotation-overlapping.js new file mode 100644 index 0000000000..6943a14d0c --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/annotation-overlapping.js @@ -0,0 +1,58 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: null, + annotations: { + a: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [1, 0], + offset: 1, + }, + }, + b: { + anchor: { + path: [0, 0], + offset: 2, + }, + focus: { + path: [1, 0], + offset: 2, + }, + }, + }, +} diff --git a/packages/slate-hyperscript/test/fixtures/block-empty.js b/packages/slate-hyperscript/test/fixtures/block-empty.js deleted file mode 100644 index 5603ed6b8c..0000000000 --- a/packages/slate-hyperscript/test/fixtures/block-empty.js +++ /dev/null @@ -1,12 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = - -export const output = { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [], -} diff --git a/packages/slate-hyperscript/test/fixtures/block-inline-empty.js b/packages/slate-hyperscript/test/fixtures/block-inline-empty.js deleted file mode 100644 index 9c289230d9..0000000000 --- a/packages/slate-hyperscript/test/fixtures/block-inline-empty.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - -) - -export const output = { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'inline', - type: 'link', - data: {}, - nodes: [], - }, - ], -} diff --git a/packages/slate-hyperscript/test/fixtures/block-mark-empty.js b/packages/slate-hyperscript/test/fixtures/block-mark-empty.js deleted file mode 100644 index 2ddc985a47..0000000000 --- a/packages/slate-hyperscript/test/fixtures/block-mark-empty.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - -) - -export const output = { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - ], -} diff --git a/packages/slate-hyperscript/test/fixtures/block-mark-full.js b/packages/slate-hyperscript/test/fixtures/block-mark-full.js deleted file mode 100644 index dcf6e7ed81..0000000000 --- a/packages/slate-hyperscript/test/fixtures/block-mark-full.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - word - -) - -export const output = { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'word', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - ], -} diff --git a/packages/slate-hyperscript/test/fixtures/block-mark-multiple.js b/packages/slate-hyperscript/test/fixtures/block-mark-multiple.js deleted file mode 100644 index 9c23c2e172..0000000000 --- a/packages/slate-hyperscript/test/fixtures/block-mark-multiple.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - onetwothree - -) - -export const output = { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - text: 'two', - marks: [], - }, - { - object: 'text', - text: 'three', - marks: [ - { - object: 'mark', - type: 'italic', - data: {}, - }, - ], - }, - ], -} diff --git a/packages/slate-hyperscript/test/fixtures/block-mark-nested.js b/packages/slate-hyperscript/test/fixtures/block-mark-nested.js deleted file mode 100644 index 63499ee255..0000000000 --- a/packages/slate-hyperscript/test/fixtures/block-mark-nested.js +++ /dev/null @@ -1,59 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - w - - or - - d - -) - -export const output = { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'w', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - text: 'or', - marks: [ - { - object: 'mark', - type: 'italic', - data: {}, - }, - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - text: 'd', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - ], -} diff --git a/packages/slate-hyperscript/test/fixtures/block-string.js b/packages/slate-hyperscript/test/fixtures/block-string.js deleted file mode 100644 index 5c771c28f2..0000000000 --- a/packages/slate-hyperscript/test/fixtures/block-string.js +++ /dev/null @@ -1,18 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = word - -export const output = { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'word', - marks: [], - }, - ], -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-block.js b/packages/slate-hyperscript/test/fixtures/cursor-across-block.js deleted file mode 100644 index 81aac6ebc4..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-block.js +++ /dev/null @@ -1,60 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - word - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'word', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 1, - }, - focus: { - object: 'point', - key: '0', - path: [0, 0], - offset: 3, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-and-inlines.js b/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-and-inlines.js deleted file mode 100644 index c129cece98..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-and-inlines.js +++ /dev/null @@ -1,125 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - - - one - - - - - - - two - - - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '10', - data: {}, - nodes: [ - { - object: 'block', - key: '4', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: '', - marks: [], - }, - { - object: 'inline', - key: '2', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - key: '1', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'text', - key: '3', - text: '', - marks: [], - }, - ], - }, - { - object: 'block', - key: '9', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '5', - text: '', - marks: [], - }, - { - object: 'inline', - key: '7', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - key: '6', - text: 'two', - marks: [], - }, - ], - }, - { - object: 'text', - key: '8', - text: '', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '1', - path: [0, 1, 0], - offset: 2, - }, - focus: { - object: 'point', - key: '6', - path: [1, 1, 0], - offset: 1, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-end.js b/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-end.js deleted file mode 100644 index ff79e0f7cf..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-end.js +++ /dev/null @@ -1,77 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - - two - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '4', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'two', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 3, - }, - focus: { - object: 'point', - key: '2', - path: [1, 0], - offset: 3, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-middle.js deleted file mode 100644 index da35cc261a..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-middle.js +++ /dev/null @@ -1,77 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - - two - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '4', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'two', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 2, - }, - focus: { - object: 'point', - key: '2', - path: [1, 0], - offset: 1, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-start.js b/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-start.js deleted file mode 100644 index 57685d80fa..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-blocks-start.js +++ /dev/null @@ -1,77 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - - two - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '4', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'two', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - key: '2', - path: [1, 0], - offset: 0, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-element.js b/packages/slate-hyperscript/test/fixtures/cursor-across-element.js new file mode 100644 index 0000000000..58f95aef7d --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-element.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + word + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'word', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [0, 0], + offset: 3, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js new file mode 100644 index 0000000000..8674741ce7 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js @@ -0,0 +1,52 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + + + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: '', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: '', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 0, + }, + focus: { + path: [1, 0], + offset: 0, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js new file mode 100644 index 0000000000..411f4043b4 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js @@ -0,0 +1,48 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 3, + }, + focus: { + path: [1, 0], + offset: 3, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js new file mode 100644 index 0000000000..31b501e6b8 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js @@ -0,0 +1,48 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 2, + }, + focus: { + path: [1, 0], + offset: 1, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js new file mode 100644 index 0000000000..316ebe2f56 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js @@ -0,0 +1,48 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + { + nodes: [ + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 0, + }, + focus: { + path: [1, 0], + offset: 0, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-empty-blocks.js b/packages/slate-hyperscript/test/fixtures/cursor-across-empty-blocks.js deleted file mode 100644 index 84fde36fac..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-empty-blocks.js +++ /dev/null @@ -1,81 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - - - - - - - - - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '4', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: '', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: '', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - key: '2', - path: [1, 0], - offset: 0, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-end.js b/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-end.js deleted file mode 100644 index ca53d13976..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-end.js +++ /dev/null @@ -1,92 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - two - - three - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '6', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'two', - marks: [], - }, - ], - }, - { - object: 'block', - key: '5', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '4', - text: 'three', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 3, - }, - focus: { - object: 'point', - key: '4', - path: [2, 0], - offset: 5, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-middle.js deleted file mode 100644 index a0d3fa8d72..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-middle.js +++ /dev/null @@ -1,92 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - two - - three - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '6', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'two', - marks: [], - }, - ], - }, - { - object: 'block', - key: '5', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '4', - text: 'three', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 2, - }, - focus: { - object: 'point', - key: '4', - path: [2, 0], - offset: 1, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-start.js b/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-start.js deleted file mode 100644 index 7b890cc604..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-multiple-blocks-start.js +++ /dev/null @@ -1,92 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - two - - three - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '6', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'two', - marks: [], - }, - ], - }, - { - object: 'block', - key: '5', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '4', - text: 'three', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - key: '4', - path: [2, 0], - offset: 0, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-block-end.js b/packages/slate-hyperscript/test/fixtures/cursor-block-end.js deleted file mode 100644 index d058a81d79..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-block-end.js +++ /dev/null @@ -1,60 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 3, - }, - focus: { - object: 'point', - key: '0', - path: [0, 0], - offset: 3, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-block-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-block-middle.js deleted file mode 100644 index 4e549611b0..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-block-middle.js +++ /dev/null @@ -1,60 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 1, - }, - focus: { - object: 'point', - key: '0', - path: [0, 0], - offset: 1, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-block-start.js b/packages/slate-hyperscript/test/fixtures/cursor-block-start.js deleted file mode 100644 index 568ddbec0a..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-block-start.js +++ /dev/null @@ -1,60 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-custom-block-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-custom-block-middle.js deleted file mode 100644 index cc14ac199a..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-custom-block-middle.js +++ /dev/null @@ -1,66 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, -}) - -export const input = ( - - - - one - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 1, - }, - focus: { - object: 'point', - key: '0', - path: [0, 0], - offset: 1, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-element-empty.js new file mode 100644 index 0000000000..417718dd83 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-empty.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: '', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 0, + }, + focus: { + path: [0, 0], + offset: 0, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-end.js b/packages/slate-hyperscript/test/fixtures/cursor-element-end.js new file mode 100644 index 0000000000..f515bb5a75 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-end.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 3, + }, + focus: { + path: [0, 0], + offset: 3, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-element-middle.js new file mode 100644 index 0000000000..5457c1996a --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-middle.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [0, 0], + offset: 1, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js new file mode 100644 index 0000000000..639e0053ed --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + word + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + nodes: [ + { + text: 'word', + marks: [], + }, + ], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0, 0], + offset: 4, + }, + focus: { + path: [0, 0, 0], + offset: 4, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js new file mode 100644 index 0000000000..2410501549 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + word + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + nodes: [ + { + text: 'word', + marks: [], + }, + ], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0, 0], + offset: 2, + }, + focus: { + path: [0, 0, 0], + offset: 2, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js new file mode 100644 index 0000000000..1dce9da12a --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + word + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + nodes: [ + { + text: 'word', + marks: [], + }, + ], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0, 0], + offset: 0, + }, + focus: { + path: [0, 0, 0], + offset: 0, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-start.js b/packages/slate-hyperscript/test/fixtures/cursor-element-start.js new file mode 100644 index 0000000000..66304c6419 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-start.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 0, + }, + focus: { + path: [0, 0], + offset: 0, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-empty-text-with-key.js b/packages/slate-hyperscript/test/fixtures/cursor-empty-text-with-key.js deleted file mode 100644 index 47d25fd71c..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-empty-text-with-key.js +++ /dev/null @@ -1,62 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - - - - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: 'a', - text: '', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: 'a', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - key: 'a', - path: [0, 0], - offset: 0, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-empty-text.js b/packages/slate-hyperscript/test/fixtures/cursor-empty-text.js deleted file mode 100644 index 67966c0e18..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-empty-text.js +++ /dev/null @@ -1,62 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - - - - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: '', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-inline-end.js b/packages/slate-hyperscript/test/fixtures/cursor-inline-end.js deleted file mode 100644 index ccab4d847c..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-inline-end.js +++ /dev/null @@ -1,84 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - two - - three - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - key: '5', - nodes: [ - { - object: 'block', - key: '4', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'one', - marks: [], - }, - { - object: 'inline', - key: '1', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'two', - marks: [], - }, - ], - }, - { - object: 'text', - key: '3', - text: 'three', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 1, 0], - offset: 3, - }, - focus: { - object: 'point', - key: '0', - path: [0, 1, 0], - offset: 3, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-inline-start.js b/packages/slate-hyperscript/test/fixtures/cursor-inline-start.js deleted file mode 100644 index 4635cbce82..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-inline-start.js +++ /dev/null @@ -1,84 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - two - - three - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - key: '5', - nodes: [ - { - object: 'block', - key: '4', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'one', - marks: [], - }, - { - object: 'inline', - key: '1', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'two', - marks: [], - }, - ], - }, - { - object: 'text', - key: '3', - text: 'three', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 1, 0], - offset: 0, - }, - focus: { - object: 'point', - key: '0', - path: [0, 1, 0], - offset: 0, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-inline.js b/packages/slate-hyperscript/test/fixtures/cursor-inline.js deleted file mode 100644 index c61dd456f7..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-inline.js +++ /dev/null @@ -1,84 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - two - - three - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - key: '5', - nodes: [ - { - object: 'block', - key: '4', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '2', - text: 'one', - marks: [], - }, - { - object: 'inline', - key: '1', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'two', - marks: [], - }, - ], - }, - { - object: 'text', - key: '3', - text: 'three', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 1, 0], - offset: 1, - }, - focus: { - object: 'point', - key: '0', - path: [0, 1, 0], - offset: 1, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js b/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js index 5eadd20c60..73a761938a 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js @@ -4,57 +4,34 @@ import h from 'slate-hyperscript' export const input = ( - - - one - - + + + ) -export const options = { - preserveSelection: true, - preserveKeys: true, -} - export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, + nodes: [ + { + nodes: [ + { + text: '', + marks: [], + }, + ], + }, + ], selection: { - object: 'selection', anchor: { - object: 'point', - key: '0', path: [0, 0], offset: 0, }, focus: { - object: 'point', - key: '0', path: [0, 0], offset: 0, }, isFocused: false, marks: null, }, + annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js index 4866108825..34295d6b79 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js @@ -4,70 +4,39 @@ import h from 'slate-hyperscript' export const input = ( - - - one - two - - + + one + two + ) -export const options = { - preserveSelection: true, - preserveKeys: true, -} - export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - key: '3', - nodes: [ - { - object: 'block', - key: '2', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - key: '0', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - key: '1', - text: 'two', - marks: [], - }, - ], - }, - ], - }, + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [{}], + }, + { + text: 'two', + marks: [], + }, + ], + }, + ], selection: { - object: 'selection', anchor: { - object: 'point', - key: '1', - path: [0, 1], - offset: 0, + path: [0, 0], + offset: 3, }, focus: { - object: 'point', - key: '1', - path: [0, 1], - offset: 0, + path: [0, 0], + offset: 3, }, isFocused: true, marks: null, }, + annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js index e601a6ca0b..37ed995ed6 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js @@ -4,79 +4,41 @@ import h from 'slate-hyperscript' export const input = ( - - - one - - two - - three - - + + + one + + two + ) -export const options = { - preserveSelection: true, - preserveKeys: true, -} - export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - key: '4', - nodes: [ - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '1', - text: 'one', - marks: [], - }, - { - object: 'text', - text: 'two', - key: '0', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - key: '2', - text: 'three', - marks: [], - }, - ], - }, - ], - }, + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [{}], + }, + { + text: 'two', + marks: [], + }, + ], + }, + ], selection: { - object: 'selection', anchor: { - object: 'point', - key: '0', - path: [0, 1], + path: [0, 0], offset: 3, }, focus: { - object: 'point', - key: '0', - path: [0, 1], + path: [0, 0], offset: 3, }, isFocused: true, marks: null, }, + annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js new file mode 100644 index 0000000000..24cbb30bca --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js @@ -0,0 +1,44 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + one + + two + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [{}], + }, + { + text: 'two', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 1, + }, + focus: { + path: [0, 0], + offset: 1, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js index 922a8c8693..772689ae0f 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js @@ -4,79 +4,41 @@ import h from 'slate-hyperscript' export const input = ( - - - one - - two - - three - - + + + one + + two + ) -export const options = { - preserveSelection: true, - preserveKeys: true, -} - export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - key: '4', - nodes: [ - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '1', - text: 'one', - marks: [], - }, - { - object: 'text', - key: '0', - text: 'two', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - key: '2', - text: 'three', - marks: [], - }, - ], - }, - ], - }, + nodes: [ + { + nodes: [ + { + text: 'one', + marks: [{}], + }, + { + text: 'two', + marks: [], + }, + ], + }, + ], selection: { - object: 'selection', anchor: { - object: 'point', - key: '0', - path: [0, 1], + path: [0, 0], offset: 0, }, focus: { - object: 'point', - key: '0', - path: [0, 1], + path: [0, 0], offset: 0, }, isFocused: true, marks: null, }, + annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark.js b/packages/slate-hyperscript/test/fixtures/cursor-mark.js deleted file mode 100644 index 670b1f5635..0000000000 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark.js +++ /dev/null @@ -1,82 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - - - one - - two - - three - - - -) - -export const options = { - preserveSelection: true, - preserveKeys: true, -} - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - key: '4', - nodes: [ - { - object: 'block', - key: '3', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '1', - text: 'one', - marks: [], - }, - { - object: 'text', - key: '0', - text: 'two', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - key: '2', - text: 'three', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 1], - offset: 1, - }, - focus: { - object: 'point', - key: '0', - path: [0, 1], - offset: 1, - }, - isFocused: true, - marks: null, - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js index b2509bdb7b..503d26439a 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js @@ -4,57 +4,34 @@ import h from 'slate-hyperscript' export const input = ( - - - one - - + + + ) -export const options = { - preserveSelection: true, - preserveKeys: true, -} - export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, + nodes: [ + { + nodes: [ + { + text: '', + marks: [], + }, + ], + }, + ], selection: { - object: 'selection', anchor: { - object: 'point', - key: '0', path: [0, 0], offset: 0, }, focus: { - object: 'point', - key: '0', path: [0, 0], offset: 0, }, isFocused: true, marks: [], }, + annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-text-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-text-empty.js new file mode 100644 index 0000000000..7323b42d05 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/cursor-text-empty.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: '', + marks: [], + }, + ], + }, + ], + selection: { + anchor: { + path: [0, 0], + offset: 0, + }, + focus: { + path: [0, 0], + offset: 0, + }, + isFocused: true, + marks: null, + }, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/fixtures/custom-marks-with-text.js b/packages/slate-hyperscript/test/fixtures/custom-marks-with-text.js deleted file mode 100644 index 86d6f07f4f..0000000000 --- a/packages/slate-hyperscript/test/fixtures/custom-marks-with-text.js +++ /dev/null @@ -1,68 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - }, - marks: { - b: 'bold', - }, -}) - -export const input = ( - - - - one - two - three - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - { - object: 'text', - text: 'two', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - text: 'three', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - ], - }, - ], - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/custom-tags.js b/packages/slate-hyperscript/test/fixtures/custom-tags.js deleted file mode 100644 index ad4dc9e1ec..0000000000 --- a/packages/slate-hyperscript/test/fixtures/custom-tags.js +++ /dev/null @@ -1,93 +0,0 @@ -/** @jsx h */ - -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - paragraph: 'paragraph', - image: 'image', - }, - inlines: { - link: 'link', - }, - marks: { - b: 'bold', - }, -}) - -export const input = ( - - - - A string of bold in a Slate{' '} - editor! - - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'A string of ', - marks: [], - }, - { - object: 'text', - text: 'bold', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - text: ' in a ', - marks: [], - }, - { - object: 'inline', - type: 'link', - data: { - src: 'http://slatejs.org', - }, - nodes: [ - { - object: 'text', - text: 'Slate', - marks: [], - }, - ], - }, - { - object: 'text', - text: ' editor!', - marks: [], - }, - ], - }, - { - object: 'block', - type: 'image', - data: { - src: 'https://...', - }, - nodes: [], - }, - ], - }, -} diff --git a/packages/slate-hyperscript/test/fixtures/element-custom.js b/packages/slate-hyperscript/test/fixtures/element-custom.js new file mode 100644 index 0000000000..013fbba77b --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/element-custom.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { createHyperscript } from 'slate-hyperscript' + +const h = createHyperscript({ + elements: { + paragraph: { type: 'paragraph' }, + }, +}) + +export const input = word + +export const output = { + type: 'paragraph', + nodes: [ + { + text: 'word', + marks: [], + }, + ], +} diff --git a/packages/slate-hyperscript/test/fixtures/document-empty.js b/packages/slate-hyperscript/test/fixtures/element-empty.js similarity index 56% rename from packages/slate-hyperscript/test/fixtures/document-empty.js rename to packages/slate-hyperscript/test/fixtures/element-empty.js index 2620aa19b2..a3e0559b4d 100644 --- a/packages/slate-hyperscript/test/fixtures/document-empty.js +++ b/packages/slate-hyperscript/test/fixtures/element-empty.js @@ -2,10 +2,8 @@ import h from 'slate-hyperscript' -export const input = +export const input = export const output = { - object: 'document', - data: {}, nodes: [], } diff --git a/packages/slate-hyperscript/test/fixtures/element-nested-empty.js b/packages/slate-hyperscript/test/fixtures/element-nested-empty.js new file mode 100644 index 0000000000..483ce621ad --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/element-nested-empty.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + +) + +export const output = { + nodes: [ + { + nodes: [], + }, + ], +} diff --git a/packages/slate-hyperscript/test/fixtures/block-inline-full.js b/packages/slate-hyperscript/test/fixtures/element-nested-string.js similarity index 50% rename from packages/slate-hyperscript/test/fixtures/block-inline-full.js rename to packages/slate-hyperscript/test/fixtures/element-nested-string.js index 1725f2d287..42eb12b592 100644 --- a/packages/slate-hyperscript/test/fixtures/block-inline-full.js +++ b/packages/slate-hyperscript/test/fixtures/element-nested-string.js @@ -3,23 +3,16 @@ import h from 'slate-hyperscript' export const input = ( - - word - + + word + ) export const output = { - object: 'block', - type: 'paragraph', - data: {}, nodes: [ { - object: 'inline', - type: 'link', - data: {}, nodes: [ { - object: 'text', text: 'word', marks: [], }, diff --git a/packages/slate-hyperscript/test/fixtures/inline-full.js b/packages/slate-hyperscript/test/fixtures/element-string.js similarity index 53% rename from packages/slate-hyperscript/test/fixtures/inline-full.js rename to packages/slate-hyperscript/test/fixtures/element-string.js index 208159b5a3..4581557af6 100644 --- a/packages/slate-hyperscript/test/fixtures/inline-full.js +++ b/packages/slate-hyperscript/test/fixtures/element-string.js @@ -2,15 +2,11 @@ import h from 'slate-hyperscript' -export const input = word +export const input = word export const output = { - object: 'inline', - type: 'link', - data: {}, nodes: [ { - object: 'text', text: 'word', marks: [], }, diff --git a/packages/slate-hyperscript/test/fixtures/block-text-empty.js b/packages/slate-hyperscript/test/fixtures/element-text-empty.js similarity index 61% rename from packages/slate-hyperscript/test/fixtures/block-text-empty.js rename to packages/slate-hyperscript/test/fixtures/element-text-empty.js index db0d6ea089..6ead2129b3 100644 --- a/packages/slate-hyperscript/test/fixtures/block-text-empty.js +++ b/packages/slate-hyperscript/test/fixtures/element-text-empty.js @@ -3,18 +3,14 @@ import h from 'slate-hyperscript' export const input = ( - + - + ) export const output = { - object: 'block', - type: 'paragraph', - data: {}, nodes: [ { - object: 'text', text: '', marks: [], }, diff --git a/packages/slate-hyperscript/test/fixtures/block-text-full.js b/packages/slate-hyperscript/test/fixtures/element-text-string.js similarity index 62% rename from packages/slate-hyperscript/test/fixtures/block-text-full.js rename to packages/slate-hyperscript/test/fixtures/element-text-string.js index 523a38a689..f819de4254 100644 --- a/packages/slate-hyperscript/test/fixtures/block-text-full.js +++ b/packages/slate-hyperscript/test/fixtures/element-text-string.js @@ -3,18 +3,14 @@ import h from 'slate-hyperscript' export const input = ( - + word - + ) export const output = { - object: 'block', - type: 'paragraph', - data: {}, nodes: [ { - object: 'text', text: 'word', marks: [], }, diff --git a/packages/slate-hyperscript/test/fixtures/inline-empty.js b/packages/slate-hyperscript/test/fixtures/inline-empty.js deleted file mode 100644 index 4a2392f799..0000000000 --- a/packages/slate-hyperscript/test/fixtures/inline-empty.js +++ /dev/null @@ -1,12 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = - -export const output = { - object: 'inline', - type: 'link', - data: {}, - nodes: [], -} diff --git a/packages/slate-hyperscript/test/fixtures/mark-custom.js b/packages/slate-hyperscript/test/fixtures/mark-custom.js new file mode 100644 index 0000000000..d8e001f0b3 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/mark-custom.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { createHyperscript } from 'slate-hyperscript' + +const h = createHyperscript({ + marks: { + b: { type: 'bold' }, + }, +}) + +export const input = word + +export const output = { + text: 'word', + marks: [{ type: 'bold' }], +} diff --git a/packages/slate-hyperscript/test/fixtures/mark-nested-string.js b/packages/slate-hyperscript/test/fixtures/mark-nested-string.js new file mode 100644 index 0000000000..01e7d37020 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/mark-nested-string.js @@ -0,0 +1,14 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + word + +) + +export const output = { + text: 'word', + marks: [{ type: 'b' }, { type: 'a' }], +} diff --git a/packages/slate-hyperscript/test/fixtures/mark-string.js b/packages/slate-hyperscript/test/fixtures/mark-string.js new file mode 100644 index 0000000000..e2f6c0f6a3 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/mark-string.js @@ -0,0 +1,10 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = word + +export const output = { + text: 'word', + marks: [{}], +} diff --git a/packages/slate-hyperscript/test/fixtures/mark-text.js b/packages/slate-hyperscript/test/fixtures/mark-text.js new file mode 100644 index 0000000000..dc413e96c6 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/mark-text.js @@ -0,0 +1,14 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + word + +) + +export const output = { + text: 'word', + marks: [{}], +} diff --git a/packages/slate-hyperscript/test/fixtures/selection.js b/packages/slate-hyperscript/test/fixtures/selection.js index 2c29eb3c16..4ceee3a250 100644 --- a/packages/slate-hyperscript/test/fixtures/selection.js +++ b/packages/slate-hyperscript/test/fixtures/selection.js @@ -4,61 +4,36 @@ import h from 'slate-hyperscript' export const input = ( - - - two - - + word - - + + ) -export const options = { - preserveSelection: true, - preserveKeys: true, -} - export const output = { - object: 'value', - document: { - object: 'document', - key: '2', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: 'a', - text: 'two', - marks: [], - }, - ], - }, - ], - }, + nodes: [ + { + nodes: [ + { + text: 'word', + marks: [], + }, + ], + }, + ], selection: { - object: 'selection', anchor: { - object: 'point', - key: 'a', path: [0, 0], offset: 1, }, focus: { - object: 'point', - key: 'a', path: [0, 0], offset: 2, }, isFocused: false, marks: null, }, + annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/text-empty.js b/packages/slate-hyperscript/test/fixtures/text-empty.js index 4215b7b610..cc81280048 100644 --- a/packages/slate-hyperscript/test/fixtures/text-empty.js +++ b/packages/slate-hyperscript/test/fixtures/text-empty.js @@ -5,7 +5,6 @@ import h from 'slate-hyperscript' export const input = export const output = { - object: 'text', text: '', marks: [], } diff --git a/packages/slate-hyperscript/test/fixtures/text-full.js b/packages/slate-hyperscript/test/fixtures/text-full.js index a18a61060e..180aea5657 100644 --- a/packages/slate-hyperscript/test/fixtures/text-full.js +++ b/packages/slate-hyperscript/test/fixtures/text-full.js @@ -5,7 +5,6 @@ import h from 'slate-hyperscript' export const input = word export const output = { - object: 'text', text: 'word', marks: [], } diff --git a/packages/slate-hyperscript/test/fixtures/text-nested.js b/packages/slate-hyperscript/test/fixtures/text-nested.js index 75558c820a..e2611116e8 100644 --- a/packages/slate-hyperscript/test/fixtures/text-nested.js +++ b/packages/slate-hyperscript/test/fixtures/text-nested.js @@ -9,7 +9,6 @@ export const input = ( ) export const output = { - object: 'text', text: 'word', marks: [], } diff --git a/packages/slate-hyperscript/test/fixtures/text-with-key.js b/packages/slate-hyperscript/test/fixtures/text-with-key.js deleted file mode 100644 index 0fa2f64590..0000000000 --- a/packages/slate-hyperscript/test/fixtures/text-with-key.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = word - -export const options = { - preserveKeys: true, -} - -export const output = { - object: 'text', - key: 'a', - text: 'word', - marks: [], -} diff --git a/packages/slate-hyperscript/test/fixtures/value-empty.js b/packages/slate-hyperscript/test/fixtures/value-empty.js new file mode 100644 index 0000000000..2909b33dd5 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/value-empty.js @@ -0,0 +1,11 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = + +export const output = { + nodes: [], + selection: null, + annotations: {}, +} diff --git a/packages/slate-hyperscript/test/index.js b/packages/slate-hyperscript/test/index.js index f0a88f0c88..80bc0118de 100644 --- a/packages/slate-hyperscript/test/index.js +++ b/packages/slate-hyperscript/test/index.js @@ -1,12 +1,10 @@ import assert from 'assert' -import { Value } from 'slate' -import { fixtures } from 'slate-dev-test-utils' +import { resolve } from 'path' +import { fixtures } from '../../../support/fixtures' describe('slate-hyperscript', () => { - fixtures(__dirname, 'fixtures', ({ module }) => { - const { input, output, options } = module - const actual = input.toJSON(options) - const expected = Value.isValue(output) ? output.toJSON() : output - assert.deepEqual(actual, expected) + fixtures(resolve(__dirname, 'fixtures'), ({ module }) => { + const { input, output } = module + assert.deepEqual(input, output) }) }) diff --git a/packages/slate-hyperscript/tsconfig.json b/packages/slate-hyperscript/tsconfig.json new file mode 100644 index 0000000000..4463c7357c --- /dev/null +++ b/packages/slate-hyperscript/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../config/typescript/tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib", + "composite": true + }, + "references": [] +} diff --git a/packages/slate-parse-plaintext/Changelog.md b/packages/slate-parse-plaintext/Changelog.md new file mode 100644 index 0000000000..c75126645c --- /dev/null +++ b/packages/slate-parse-plaintext/Changelog.md @@ -0,0 +1,57 @@ +# Changelog + +This document maintains a list of changes to the `slate-plain-serializer` package with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and smaller changes won't be accounted for since the library is moving quickly. + +--- + +### `0.7.0` — May 1, 2019 + +###### BREAKING + +**Updated to work with `slate@0.46`.** The plain serializer has been updated to work alongside the new text data model in the latest version of slate. For serializing it requires you pass in the new format for text nodes. And for deserializing it will return the new format. + +--- + +### `0.6.0` — August 22, 2018 + +###### BREAKING + +**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version. + +--- + +### `0.5.0` — January 4, 2018 + +###### BREAKING + +**The `kind` property of Slate objects has been renamed to `object`.** This is to reduce the confusion over the difference between "kind" and "type" which are practically synonyms. The "object" name was chosen to match the Stripe API, since it seems like a sensible choice and reads much more nicely when looking through JSON. + +--- + +### `0.4.0` — October 27, 2017 + +###### BREAKING + +**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version. + +--- + +### `0.3.0` — October 27, 2017 + +###### BREAKING + +**Updated to work with `slate@0.29.0`.** This is required because `slate-plain-serializer` needs access to the new `Value` model. + +--- + +### `0.2.0` — October 14, 2017 + +###### BREAKING + +**Updated work with `slate@0.27.0`.** The new version of Slate renames the old `Range` model to `Leaf`, and the old `Selection` model to `Range`. + +--- + +### `0.1.0` — September 17, 2017 + +:tada: diff --git a/packages/slate-parse-plaintext/Readme.md b/packages/slate-parse-plaintext/Readme.md new file mode 100644 index 0000000000..feb2245892 --- /dev/null +++ b/packages/slate-parse-plaintext/Readme.md @@ -0,0 +1 @@ +This package contains a plain-text serializer for Slate documents. diff --git a/packages/slate-parse-plaintext/package.json b/packages/slate-parse-plaintext/package.json new file mode 100644 index 0000000000..c876691486 --- /dev/null +++ b/packages/slate-parse-plaintext/package.json @@ -0,0 +1,35 @@ +{ + "name": "slate-parse-plaintext", + "description": "Parse a plaintext string into a Slate value.", + "version": "0.7.10", + "license": "MIT", + "repository": "git://github.com/ianstormtaylor/slate.git", + "main": "lib/index.js", + "module": "lib/index.es.js", + "types": "list/index.d.ts", + "umd": "dist/slate-parse-plaintext.js", + "umdMin": "dist/slate-parse-plaintext.min.js", + "files": [ + "dist/", + "lib/" + ], + "peerDependencies": { + "slate": ">=0.46.0" + }, + "devDependencies": { + "slate": "^0.47.8", + "slate-hyperscript": "^0.13.8" + }, + "keywords": [ + "deserialize", + "drop", + "editor", + "parse", + "paste", + "plain", + "plaintext", + "slate", + "string", + "text" + ] +} diff --git a/packages/slate-parse-plaintext/src/index.ts b/packages/slate-parse-plaintext/src/index.ts new file mode 100644 index 0000000000..0954b81ea5 --- /dev/null +++ b/packages/slate-parse-plaintext/src/index.ts @@ -0,0 +1,40 @@ +import { Element, Text, Value } from 'slate' + +/** + * Parse a plaintext string into a Slate `Value` object. + * + * By default, it will use `\n` as the delimiter, splitting each line into a + * separate element node. + * + * Note: You can pass `elementProps` or `textProps` to merge default properties + * into the resulting element or text nodes. For adding default marks to each + * text node, use `textProps` with a `marks` property. + */ + +export const parsePlaintext = ( + plaintext: string, + options: { + delimiter?: string + elementProps?: Partial + textProps?: Partial + } = {} +): Value => { + const { elementProps = {}, textProps = {}, delimiter = '\n' } = options + + return { + selection: null, + annotations: {}, + nodes: plaintext.split(delimiter).map(line => { + return { + ...elementProps, + nodes: [ + { + marks: [], + ...textProps, + text: line, + }, + ], + } + }), + } +} diff --git a/packages/slate-parse-plaintext/test/fixtures/delimiter.js b/packages/slate-parse-plaintext/test/fixtures/delimiter.js new file mode 100644 index 0000000000..2c4cf83465 --- /dev/null +++ b/packages/slate-parse-plaintext/test/fixtures/delimiter.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ` +one +same paragraph + +two +`.trim() + +export const options = { + delimiter: '\n\n', +} + +export const output = ( + + one{'\n'}same paragraph + two + +) diff --git a/packages/slate-parse-plaintext/test/fixtures/element-props.js b/packages/slate-parse-plaintext/test/fixtures/element-props.js new file mode 100644 index 0000000000..d0c233d71a --- /dev/null +++ b/packages/slate-parse-plaintext/test/fixtures/element-props.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ` +one +two +`.trim() + +export const options = { + elementProps: { type: 'paragraph' }, +} + +export const output = ( + + one + two + +) diff --git a/packages/slate-parse-plaintext/test/fixtures/line-multiple.js b/packages/slate-parse-plaintext/test/fixtures/line-multiple.js new file mode 100644 index 0000000000..c00ea1a84b --- /dev/null +++ b/packages/slate-parse-plaintext/test/fixtures/line-multiple.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ` +one +two +`.trim() + +export const output = ( + + one + two + +) diff --git a/packages/slate-parse-plaintext/test/fixtures/line-single.js b/packages/slate-parse-plaintext/test/fixtures/line-single.js new file mode 100644 index 0000000000..ffe2f0003f --- /dev/null +++ b/packages/slate-parse-plaintext/test/fixtures/line-single.js @@ -0,0 +1,13 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ` +one +`.trim() + +export const output = ( + + one + +) diff --git a/packages/slate-parse-plaintext/test/fixtures/text-props.js b/packages/slate-parse-plaintext/test/fixtures/text-props.js new file mode 100644 index 0000000000..7f54c45afa --- /dev/null +++ b/packages/slate-parse-plaintext/test/fixtures/text-props.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ` +one +two +`.trim() + +export const options = { + textProps: { marks: [{ type: 'bold' }] }, +} + +export const output = ( + + + one + + + two + + +) diff --git a/packages/slate-parse-plaintext/test/index.js b/packages/slate-parse-plaintext/test/index.js new file mode 100644 index 0000000000..91ef7cd31f --- /dev/null +++ b/packages/slate-parse-plaintext/test/index.js @@ -0,0 +1,11 @@ +import { parsePlaintext } from 'slate-parse-plaintext' +import assert from 'assert' +import { fixtures } from '../../../support/fixtures' + +describe('slate-parse-plaintext', () => { + fixtures(__dirname, 'fixtures', ({ module }) => { + const { input, output, options } = module + const actual = parsePlaintext(input, options) + assert.deepEqual(actual, output) + }) +}) diff --git a/packages/slate-parse-plaintext/tsconfig.json b/packages/slate-parse-plaintext/tsconfig.json new file mode 100644 index 0000000000..4463c7357c --- /dev/null +++ b/packages/slate-parse-plaintext/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../config/typescript/tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib", + "composite": true + }, + "references": [] +} diff --git a/packages/slate-plain-serializer/test/index.js b/packages/slate-plain-serializer/test/index.js index 562874f81c..f81c7292e8 100644 --- a/packages/slate-plain-serializer/test/index.js +++ b/packages/slate-plain-serializer/test/index.js @@ -1,7 +1,7 @@ import Plain from 'slate-plain-serializer' import assert from 'assert' import { Value } from 'slate' -import { fixtures } from 'slate-dev-test-utils' +import { fixtures } from '../../../support/fixtures' describe('slate-plain-serializer', () => { fixtures(__dirname, 'deserialize', ({ module }) => { diff --git a/packages/slate-react/test/index.js b/packages/slate-react/test/index.js index ba80ecb9f5..0ced384049 100644 --- a/packages/slate-react/test/index.js +++ b/packages/slate-react/test/index.js @@ -4,7 +4,7 @@ import React from 'react' import ReactDOM from 'react-dom/server' import ShallowRenderer from 'react-test-renderer/shallow' import { Editor } from 'slate-react' -import { fixtures } from 'slate-dev-test-utils' +import { fixtures } from '../../../support/fixtures' import { JSDOM } from 'jsdom' describe('slate-react', () => { diff --git a/packages/slate-render-plaintext/Changelog.md b/packages/slate-render-plaintext/Changelog.md new file mode 100644 index 0000000000..c75126645c --- /dev/null +++ b/packages/slate-render-plaintext/Changelog.md @@ -0,0 +1,57 @@ +# Changelog + +This document maintains a list of changes to the `slate-plain-serializer` package with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and smaller changes won't be accounted for since the library is moving quickly. + +--- + +### `0.7.0` — May 1, 2019 + +###### BREAKING + +**Updated to work with `slate@0.46`.** The plain serializer has been updated to work alongside the new text data model in the latest version of slate. For serializing it requires you pass in the new format for text nodes. And for deserializing it will return the new format. + +--- + +### `0.6.0` — August 22, 2018 + +###### BREAKING + +**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version. + +--- + +### `0.5.0` — January 4, 2018 + +###### BREAKING + +**The `kind` property of Slate objects has been renamed to `object`.** This is to reduce the confusion over the difference between "kind" and "type" which are practically synonyms. The "object" name was chosen to match the Stripe API, since it seems like a sensible choice and reads much more nicely when looking through JSON. + +--- + +### `0.4.0` — October 27, 2017 + +###### BREAKING + +**Remove all previously deprecated code paths.** This helps to reduce some of the complexity in Slate by not having to handle these code paths anymore. And it helps to reduce file size. When upgrading, it's _highly_ recommended that you upgrade to the previous version first and ensure there are no deprecation warnings being logged, then upgrade to this version. + +--- + +### `0.3.0` — October 27, 2017 + +###### BREAKING + +**Updated to work with `slate@0.29.0`.** This is required because `slate-plain-serializer` needs access to the new `Value` model. + +--- + +### `0.2.0` — October 14, 2017 + +###### BREAKING + +**Updated work with `slate@0.27.0`.** The new version of Slate renames the old `Range` model to `Leaf`, and the old `Selection` model to `Range`. + +--- + +### `0.1.0` — September 17, 2017 + +:tada: diff --git a/packages/slate-render-plaintext/Readme.md b/packages/slate-render-plaintext/Readme.md new file mode 100644 index 0000000000..feb2245892 --- /dev/null +++ b/packages/slate-render-plaintext/Readme.md @@ -0,0 +1 @@ +This package contains a plain-text serializer for Slate documents. diff --git a/packages/slate-render-plaintext/package.json b/packages/slate-render-plaintext/package.json new file mode 100644 index 0000000000..ea3f3dd8f6 --- /dev/null +++ b/packages/slate-render-plaintext/package.json @@ -0,0 +1,35 @@ +{ + "name": "slate-render-plaintext", + "description": "Render a Slate value to a plaintext string.", + "version": "0.7.10", + "license": "MIT", + "repository": "git://github.com/ianstormtaylor/slate.git", + "main": "lib/index.js", + "module": "lib/index.es.js", + "types": "list/index.d.ts", + "umd": "dist/slate-render-plaintext.js", + "umdMin": "dist/slate-render-plaintext.min.js", + "files": [ + "dist/", + "lib/" + ], + "peerDependencies": { + "slate": ">=0.46.0" + }, + "devDependencies": { + "slate": "^0.47.8", + "slate-hyperscript": "^0.13.8" + }, + "keywords": [ + "deserialize", + "drop", + "editor", + "parse", + "paste", + "plain", + "plaintext", + "slate", + "string", + "text" + ] +} diff --git a/packages/slate-render-plaintext/src/index.ts b/packages/slate-render-plaintext/src/index.ts new file mode 100644 index 0000000000..dd53c59387 --- /dev/null +++ b/packages/slate-render-plaintext/src/index.ts @@ -0,0 +1,23 @@ +import { Node, Text } from 'slate' + +/** + * Render a Slate `Node` to a plaintext string. + * + * By default, it will use `\n` as the delimiter, separating each block-level + * element with a line break. + */ + +export const renderPlaintext = ( + node: Node, + options: { + delimiter?: string + } = {} +): string => { + const { delimiter = '\n' } = options + + if (Text.isText(node) || node.nodes.some(n => Text.isText(n))) { + return Node.text(node) + } else { + return node.nodes.map(n => renderPlaintext(n, options)).join(delimiter) + } +} diff --git a/packages/slate-render-plaintext/test/fixtures/block-custom-property.js b/packages/slate-render-plaintext/test/fixtures/block-custom-property.js new file mode 100644 index 0000000000..eb0ccbcfab --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-custom-property.js @@ -0,0 +1,13 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + one + +) + +export const output = ` +one +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block-mark.js b/packages/slate-render-plaintext/test/fixtures/block-mark.js new file mode 100644 index 0000000000..eb49afb794 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-mark.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + +) + +export const output = ` +one +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block-multiple-empty.js b/packages/slate-render-plaintext/test/fixtures/block-multiple-empty.js new file mode 100644 index 0000000000..ed7d4a8585 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-multiple-empty.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + one + + + four + +) + +export const output = ` +one + + +four +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block-multiple.js b/packages/slate-render-plaintext/test/fixtures/block-multiple.js new file mode 100644 index 0000000000..92b6c4bc01 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-multiple.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + one + two + three + +) + +export const output = ` +one +two +three +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block-nested-inline-nested.js b/packages/slate-render-plaintext/test/fixtures/block-nested-inline-nested.js new file mode 100644 index 0000000000..68683d87d7 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-nested-inline-nested.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + + + + + two + + + + + + +) + +export const output = ` +one +two +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block-nested-inline.js b/packages/slate-render-plaintext/test/fixtures/block-nested-inline.js new file mode 100644 index 0000000000..80851dd87b --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-nested-inline.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + + one + + + + + two + + + + +) + +export const output = ` +one +two +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block-nested-nested.js b/packages/slate-render-plaintext/test/fixtures/block-nested-nested.js new file mode 100644 index 0000000000..babd0c6f60 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-nested-nested.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + one + two + + + three + four + + + +) + +export const output = ` +one +two +three +four +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block-nested.js b/packages/slate-render-plaintext/test/fixtures/block-nested.js new file mode 100644 index 0000000000..22e9a3750f --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block-nested.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + + + three + four + + +) + +export const output = ` +one +two +three +four +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/block.js b/packages/slate-render-plaintext/test/fixtures/block.js new file mode 100644 index 0000000000..6f0b739191 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/block.js @@ -0,0 +1,13 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + one + +) + +export const output = ` +one +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/custom-delimiter.js b/packages/slate-render-plaintext/test/fixtures/custom-delimiter.js new file mode 100644 index 0000000000..176510f5f8 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/custom-delimiter.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + one{'\n'}same paragraph + two + three + +) + +export const options = { + delimiter: '\n\n', +} + +export const output = ` +one +same paragraph + +two + +three +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/inline-custom-property.js b/packages/slate-render-plaintext/test/fixtures/inline-custom-property.js new file mode 100644 index 0000000000..1cb4731393 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/inline-custom-property.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + one + + + +) + +export const output = ` +one +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/inline-mark.js b/packages/slate-render-plaintext/test/fixtures/inline-mark.js new file mode 100644 index 0000000000..65da0a92f3 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/inline-mark.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + + one + + + + +) + +export const output = ` +one +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/inline-nested.js b/packages/slate-render-plaintext/test/fixtures/inline-nested.js new file mode 100644 index 0000000000..bcfb44df47 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/inline-nested.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + + + one + + + + + +) + +export const output = ` +one +`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/inline.js b/packages/slate-render-plaintext/test/fixtures/inline.js new file mode 100644 index 0000000000..48290a69fe --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/inline.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + + + one + + + +) + +export const output = ` +one +`.trim() diff --git a/packages/slate-render-plaintext/test/index.js b/packages/slate-render-plaintext/test/index.js new file mode 100644 index 0000000000..8235f044d7 --- /dev/null +++ b/packages/slate-render-plaintext/test/index.js @@ -0,0 +1,11 @@ +import { renderPlaintext } from 'slate-render-plaintext' +import assert from 'assert' +import { fixtures } from '../../../support/fixtures' + +describe('slate-render-plaintext', () => { + fixtures(__dirname, 'fixtures', ({ module }) => { + const { input, output, options } = module + const actual = renderPlaintext(input, options) + assert.deepEqual(actual, output) + }) +}) diff --git a/packages/slate-render-plaintext/tsconfig.json b/packages/slate-render-plaintext/tsconfig.json new file mode 100644 index 0000000000..4463c7357c --- /dev/null +++ b/packages/slate-render-plaintext/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../config/typescript/tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib", + "composite": true + }, + "references": [] +} diff --git a/packages/slate/package.json b/packages/slate/package.json index 6eac5f0973..effeedc271 100644 --- a/packages/slate/package.json +++ b/packages/slate/package.json @@ -4,8 +4,9 @@ "version": "0.47.8", "license": "MIT", "repository": "git://github.com/ianstormtaylor/slate.git", - "main": "lib/slate.js", - "module": "lib/slate.es.js", + "main": "lib/index.js", + "module": "lib/index.es.js", + "types": "lib/index.d.ts", "umd": "dist/slate.js", "umdMin": "dist/slate.min.js", "files": [ @@ -13,28 +14,18 @@ "lib/" ], "dependencies": { + "@types/esrever": "^0.2.0", "debug": "^3.1.0", - "direction": "^0.1.5", "esrever": "^0.2.0", + "immer": "^4.0.1", "is-plain-object": "^2.0.4", - "lodash": "^4.17.4", "tiny-invariant": "^1.0.1", - "tiny-warning": "^0.0.3", - "type-of": "^2.0.1" - }, - "peerDependencies": { - "immutable": ">=3.8.1 || >4.0.0-rc" + "tiny-warning": "^0.0.3" }, "devDependencies": { "slate-dev-test-utils": "^0.0.1", "slate-hyperscript": "^0.13.8" }, - "scripts": { - "clean": "rm -rf ./dist ./lib ./node_modules" - }, - "umdGlobals": { - "immutable": "Immutable" - }, "keywords": [ "canvas", "contenteditable", diff --git a/packages/slate/src/classes/commands/annotation.ts b/packages/slate/src/classes/commands/annotation.ts new file mode 100755 index 0000000000..94963b4333 --- /dev/null +++ b/packages/slate/src/classes/commands/annotation.ts @@ -0,0 +1,84 @@ +import { Editor, Point, Annotation } from '../..' + +class AnnotationCommands { + /** + * Add a new `annotation` object with a `key`. + */ + + addAnnotation(this: Editor, key: string, annotation: Annotation) { + this.apply({ + type: 'add_annotation', + key, + annotation, + }) + } + + /** + * Remove an existing annotation object by `key`. + */ + + removeAnnotation(this: Editor, key: string) { + const { annotations } = this.value + + if (!(key in annotations)) { + throw new Error( + `Unable to remove annotation by ${key} because it does not exist.` + ) + } + + const annotation = annotations[key] + + this.apply({ + type: 'remove_annotation', + key, + annotation, + }) + } + + /** + * Set new properties on an annotation object with `key`. + */ + + setAnnotation(this: Editor, key: string, props: Partial) { + const { annotations } = this.value + + if (!(key in annotations)) { + throw new Error( + `Unable to set new properties on annotation by ${key} because it does not exist.` + ) + } + + const annotation = annotations[key] + const newProps = {} + const prevProps = {} + let isChange = false + + // Dedupe new and old properties to avoid unnecessary sets. + for (const k in props) { + const isPoint = k === 'anchor' || k === 'focus' + + if ( + (isPoint && !Point.equals(props[k], annotation[k])) || + (!isPoint && props[k] !== annotation[k]) + ) { + isChange = true + newProps[k] = props[k] + prevProps[k] = annotation[k] + } + } + + // If no properties have actually changed, don't apply an operation at all. + if (!isChange) { + return + } + + this.apply({ + type: 'set_annotation', + key, + properties: prevProps, + newProperties: newProps, + }) + } +} + +export default AnnotationCommands diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts new file mode 100755 index 0000000000..a2dc3a2bac --- /dev/null +++ b/packages/slate/src/classes/commands/path.ts @@ -0,0 +1,494 @@ +import { produce } from 'immer' +import { Editor, Fragment, Mark, Element, Text, Node, Path } from '../..' + +class PathCommands { + /** + * Add a mark to the node at a path. + */ + + addMarkAtPath(this: Editor, path: Path, mark: Mark): void { + const { value } = this + const leaf = Node.leaf(value, path) + + if (!Mark.exists(mark, leaf.marks)) { + this.apply({ type: 'add_mark', path, mark }) + } + } + + /** + * Insert a fragment starting at a path. + */ + + insertFragmentAtPath(this: Editor, path: Path, fragment: Fragment): void { + const parentPath = path.slice(0, -1) + let i = path[path.length - 1] + + this.withoutNormalizing(() => { + for (const node of fragment.nodes) { + const childPath = parentPath.concat(i) + i++ + this.insertNodeAtPath(childPath, node) + } + }) + } + + /** + * Insert a node at a path. + */ + + insertNodeAtPath(this: Editor, path: Path, node: Node): void { + this.apply({ type: 'insert_node', path, node }) + } + + /** + * Merge the leaf block at a path with the previous leaf block. + */ + + mergeBlockAtPath(this: Editor, path: Path): void { + this.withoutNormalizing(() => { + const { value } = this + const closestBlock = this.getClosestBlock(path) + const prevBlock = this.getPreviousLeafBlock(path) + + if (!closestBlock) { + throw new Error( + `Cannot merge the leaf block above path ${path} because there isn't one.` + ) + } + + if (!prevBlock) { + throw new Error( + `Cannot merge the block above path ${path} with the previous leaf block because there isn't one.` + ) + } + + const [, blockPath] = closestBlock + const [, prevPath] = prevBlock + const newPath = Path.next(prevPath) + const commonAncestorPath = Path.common(blockPath, prevPath) + + this.moveNodeAtPath(blockPath, newPath) + this.mergeNodeAtPath(newPath) + + for (const [ancestor, ancestorPath] of Node.ancestors(value, blockPath)) { + if ( + Path.equals(ancestorPath, commonAncestorPath) || + ancestor.nodes.length !== 1 + ) { + break + } + + this.removeNodeAtPath(ancestorPath) + } + }) + } + + /** + * Merge the node at a path with the previous node. + */ + + mergeNodeAtPath(this: Editor, path: Path): void { + if (path.length === 0) { + throw new Error(`Cannot perform a merge on the top-level node.`) + } + + if (path[path.length - 1] === 0) { + throw new Error( + `Cannot merge the node at path ${path} with the previous sibling because there isn't one.` + ) + } + + const { value } = this + const prevPath = Path.previous(path) + const node = Node.get(value, path) + const prevNode = Node.get(value, prevPath) + + if (Text.isText(node) && Text.isText(prevNode)) { + const { text, marks, ...properties } = node + const position = prevNode.text.length + this.apply({ + type: 'merge_node', + path, + position, + target: null, + properties, + }) + } else if (Element.isElement(node) && Element.isElement(prevNode)) { + const { nodes, ...properties } = node + const position = prevNode.nodes.length + this.apply({ + type: 'merge_node', + path, + position, + target: null, + properties, + }) + } else { + throw new Error( + `Cannot merge the node at path ${path} with the previous sibling because it is not the same kind: ${node} ${prevNode}` + ) + } + } + + /** + * Move a node at a path to a new path. + */ + + moveNodeAtPath(this: Editor, path: Path, newPath: Path): void { + const { value } = this + const prevPath = Path.previous(path) + const parentPath = Path.parent(path) + const newIndex = newPath[newPath.length - 1] + + if (!Node.has(value, path)) { + throw new Error( + `Cannot move the node at path ${path} because it does not exist.` + ) + } + + if (!Node.has(value, parentPath)) { + throw new Error( + `Cannot move the node at path ${path} to the new parent at path ${parentPath} because the parent does not exist.` + ) + } + + if (newIndex !== 0 && !Node.has(value, prevPath)) { + throw new Error( + `Cannot move the node at path ${path} to ${newPath} because the index is out of range.` + ) + } + + this.apply({ + type: 'move_node', + path, + newPath, + }) + } + + /** + * Normalize a node at a path, returning it to a valid state if it is + * currently invalid. + */ + + normalizeNodeAtPath(this: Editor, path: Path): void {} + + /** + * Remove all of the children from the node at a path. + */ + + removeChildrenAtPath(this: Editor, path: Path): void { + const { value } = this + const parent = Node.ancestor(value, path) + + this.withoutNormalizing(() => { + const childPath = path.concat([0]) + + for (let i = 0; i < parent.nodes.length; i++) { + this.removeNodeAtPath(childPath) + } + }) + } + + /** + * Remove a mark on the node at a path. + */ + + removeMarkAtPath(this: Editor, path: Path, mark: Mark): void { + const { value } = this + const leaf = Node.leaf(value, path) + + if (Mark.exists(mark, leaf.marks)) { + this.apply({ type: 'remove_mark', path, mark }) + } + } + + /** + * Remove the node at a path. + */ + + removeNodeAtPath(this: Editor, path: Path): void { + const { value } = this + const node = Node.get(value, path) + this.apply({ type: 'remove_node', path, node }) + } + + /** + * Remove the parent node of a path. + */ + + removeParentAtPath(this: Editor, path: Path): void { + const { value } = this + const parent = Node.parent(value, path) + const parentPath = Path.parent(path) + this.apply({ type: 'remove_node', path: parentPath, node: parent }) + } + + /** + * Replace the node at a path with a new node. + */ + + replaceNodeAtPath(this: Editor, path: Path, node: Node): void { + this.withoutNormalizing(() => { + this.removeNodeAtPath(path) + this.insertNodeAtPath(path, node) + }) + } + + /** + * Set new properties on the node at a path. + */ + + setNodeAtPath(this: Editor, path: Path, props: {}): void { + if (path.length === 0) { + this.setValue(props) + return + } + + const { value } = this + const node = Node.get(value, path) + const newProps = {} + const oldProps = {} + let isChange = true + + for (const k in props) { + // Disallow setting restricted properties that should use the editor + // methods that result in more semantic operations being applied. + if (Element.isElement(node) && k === 'nodes') { + throw new Error( + `Cannot set the \`nodes\` property of an element node at path ${path}. You must use the node-specific editor methods instead like \`editor.insertNodeAtPath\`, \`editor.removeNodeAtPath\`, etc.` + ) + } + + if (Text.isText(node) && k === 'text') { + throw new Error( + `Cannot set the \`text\` property of a text node at path ${path}. You must use the text-specific editor methods instead like \`editor.insertTextAtPath\`, \`editor.removeTextAtPath\`, etc.` + ) + } + + if (Text.isText(node) && k === 'marks') { + throw new Error( + `Cannot set the \`marks\` property of a text node at path ${path}. You must use the text-specific editor methods instead like \`editor.addMarkAtPath\`, \`editor.removeMarkAtPath\`, etc.` + ) + } + + if (props[k] !== node[k]) { + isChange = true + newProps[k] = props[k] + oldProps[k] = node[k] + } + } + + // PERF: If no properties have changed don't apply an operation at all. + if (!isChange) { + return + } + + this.apply({ + type: 'set_node', + path, + properties: oldProps, + newProperties: newProps, + }) + } + + /** + * Set new properties on the node at a path. + */ + + setMarkAtPath( + this: Editor, + path: Path, + mark: Partial, + props: {} + ): void { + const { value } = this + const node = Node.leaf(value, path) + const match = node.marks.find(m => Mark.matches(m, mark)) + + if (match == null) { + throw new Error( + `Cannot set new properties on mark ${mark} at path ${path} because the mark does not exist.` + ) + } + + const newProps = {} + let isChange = true + + for (const k in props) { + if (props[k] !== match[k]) { + isChange = true + newProps[k] = props[k] + } + } + + // PERF: If no properties have changed don't apply an operation at all. + if (!isChange) { + return + } + + this.apply({ + type: 'set_mark', + path, + properties: match, + newProperties: newProps, + }) + } + + /** + * Replace a mark on the text node at a path. + */ + + replaceMarkAtPath(this: Editor, path: Path, before: Mark, after: Mark): void { + this.withoutNormalizing(() => { + this.removeMarkAtPath(path, before) + this.addMarkAtPath(path, after) + }) + } + + /** + * Replace all of the text in a node at a path. + */ + + replaceTextAtPath(this: Editor, path: Path, text: string): void { + this.withoutNormalizing(() => { + const { value } = this + const node = Node.leaf(value, path) + const point = { path, offset: 0 } + this.removeTextAtPoint(point, node.text.length) + this.insertTextAtPoint(point, text) + }) + } + + /** + * Split the node at a path at a specific position in the node. If the node is + * a text node, `position` refers to a string offset. If the node is an + * element node, `position` refers to the index of its children. + * + * If you're looking to split from an ancestor all the way down to a leaf text + * node, you likely want `splitNodeAtPoint` instead. + */ + + splitNodeAtPath( + this: Editor, + path: Path, + position: number, + options: { target?: number } = {} + ): void { + if (path.length === 0) { + throw new Error(`Cannot split the top-level node in the document.`) + } + + const { target = null } = options + const { value } = this + const node = Node.get(value, path) + let properties + + if (Text.isText(node)) { + const { text, marks, ...rest } = node + properties = rest + } else { + const { nodes, ...rest } = node + properties = rest + } + + this.apply({ + type: 'split_node', + path, + position, + target, + properties, + }) + } + + /** + * Unwrap all of the children of a node, by removing the node and replacing it + * in the tree with its children. + */ + + unwrapChildrenAtPath(this: Editor, path: Path): void { + const { value } = this + const node = Node.get(value, path) + + if (Text.isText(node)) { + throw new Error( + `Cannot unwrap children from the node at ${path} because it is a text node and has no children.` + ) + } + + this.withoutNormalizing(() => { + const parentPath = Path.parent(path) + const index = path[path.length - 1] + + for (let i = 0; i < node.nodes.length; i++) { + const targetPath = path.concat(i) + const newPath = parentPath.concat(index + i) + this.moveNodeAtPath(targetPath, newPath) + } + + this.removeNodeAtPath(path) + }) + } + + /** + * Unwrap a single node from its parent. + * + * If the node is surrounded with siblings, its parent will be split. If the + * node is the only child, the parent is removed, and simply replaced by the + * node itself. + */ + + unwrapNodeAtPath(this: Editor, path: Path): void { + const { value } = this + const parent = Node.parent(value, path) + const parentPath = Path.parent(path) + const index = path[path.length - 1] + const parentIndex = parentPath[parentPath.length - 1] + const grandPath = Path.parent(parentPath) + const isFirst = index === 0 + const isLast = index === parent.nodes.length - 1 + + this.withoutNormalizing(() => { + let targetPath = path + let newPath = grandPath.concat(parentIndex + 1) + + // If the parent has multiple nodes and we're unwrapping the first one, we + // will just move it before the parent instead. + if (parent.nodes.length > 1 && isFirst) { + newPath = grandPath.concat(parentIndex) + } + + // If there are multiple children, and we're unwrapping one of the middle + // children, we need to split the parent in half first. + if (parent.nodes.length > 1 && !isFirst && !isLast) { + targetPath = produce(path, p => { + p[parentPath.length - 1] += 1 + p[targetPath.length - 1] = 0 + }) + + this.splitNodeAtPath(parentPath, index) + } + + this.moveNodeAtPath(targetPath, newPath) + + // If there was only one child, the parent gets removed. + if (parent.nodes.length === 1) { + this.removeNodeAtPath(parentPath) + } + }) + } + + /** + * Wrap the node at a path in a new parent node. + */ + + wrapNodeAtPath(this: Editor, path: Path, element: Element): void { + this.withoutNormalizing(() => { + this.insertNodeAtPath(path, element) + const nextPath = Path.next(path) + const childPath = path.concat(0) + this.moveNodeAtPath(nextPath, childPath) + }) + } +} + +export default PathCommands diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts new file mode 100755 index 0000000000..f91d9a5be7 --- /dev/null +++ b/packages/slate/src/classes/commands/point.ts @@ -0,0 +1,305 @@ +import { produce } from 'immer' +import { Editor, Element, Fragment, Node, Path, Point, Range } from '../..' + +class PointCommands { + /** + * Delete a span of content starting from a point. + */ + + deleteAtPoint( + this: Editor, + point: Point, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + } = {} + ): void { + const { reverse = false, ...rest } = options + const target = reverse + ? this.getPreviousPoint(point, rest) + : this.getNextPoint(point, rest) + + if (target) { + this.deleteAtRange({ anchor: point, focus: target }) + } + } + + /** + * Insert a block node at a point. + */ + + insertBlockAtPoint(this: Editor, point: Point, block: Element): void { + this.withoutNormalizing(() => { + const pointRef = this.createPointRef(point) + this.splitBlockAtPoint(point, { always: false }) + + if (pointRef.current != null) { + this.insertNodeAtPath(pointRef.current.path, block) + pointRef.unref() + } + }) + } + + /** + * Insert a fragment of nodes at a point. + */ + + insertFragmentAtPoint(this: Editor, point: Point, fragment: Fragment): void { + if (fragment.nodes.length === 0) { + return + } + + this.withoutNormalizing(() => { + const pointRef = this.createPointRef(point) + this.splitBlockAtPoint(point) + + if (pointRef.current != null) { + const insertClosest = this.getClosestBlock(pointRef.current.path) + + if (insertClosest != null) { + const [, insertPath] = insertClosest + this.insertFragmentAtPath(insertPath, fragment) + + const afterClosest = this.getClosestBlock(pointRef.current.path) + const beforeClosest = this.getClosestBlock(point.path) + + if (afterClosest != null && beforeClosest != null) { + const [, afterPath] = afterClosest + const [, beforePath] = beforeClosest + const startPath = Path.next(beforePath) + this.mergeBlockAtPath(afterPath) + this.mergeBlockAtPath(startPath) + } + } + } + }) + } + + /** + * Insert an inline node at a point. + */ + + insertInlineAtPoint(this: Editor, point: Point, inline: Element): void { + this.withoutNormalizing(() => { + const pointRef = this.createPointRef(point) + this.splitInlineAtPoint(point, { always: false }) + + if (pointRef.current != null) { + this.insertNodeAtPath(pointRef.current.path, inline) + pointRef.unref() + } + }) + } + + /** + * Insert a string of text at a specific point in the document. + */ + + insertTextAtPoint(this: Editor, point: Point, text: string): Point { + const { value } = this + const { annotations } = value + const { path, offset } = point + + this.withoutNormalizing(() => { + for (const key in annotations) { + const annotation = annotations[key] + + if (this.isAtomic(annotation)) { + const [start] = Range.points(annotation) + const [, end] = Range.points(annotation) + + if ( + start.offset < offset && + Path.equals(start.path, path) && + (!Path.equals(end.path, path) || offset < end.offset) + ) { + this.removeAnnotation(key) + } + } + } + + this.apply({ + type: 'insert_text', + path, + offset, + text, + }) + }) + + return produce(point, p => { + p.offset += text.length + }) + } + + /** + * Remove a string of text by length from a specific point in the document. + */ + + removeTextAtPoint(this: Editor, point: Point, length: number): Point { + const { value } = this + const { annotations } = value + const { path, offset } = point + const node = Node.leaf(value, path) + const text = node.text.slice(offset, offset + length) + + this.withoutNormalizing(() => { + for (const key in annotations) { + const annotation = annotations[key] + + if (this.isAtomic(annotation)) { + const [start] = Range.points(annotation) + const [, end] = Range.points(annotation) + + if ( + start.offset < offset && + Path.equals(start.path, path) && + (!Path.equals(end.path, path) || offset < end.offset) + ) { + this.removeAnnotation(key) + } + } + } + + this.apply({ + type: 'insert_text', + path, + offset, + text, + }) + }) + + return point + } + + /** + * Split the block node at a specific point, up to a certain block height. + */ + + splitBlockAtPoint( + this: Editor, + point: Point, + options: { + always?: boolean + height?: number + } = {} + ): void { + const { height = 0, ...rest } = options + const { path } = point + const closestBlock = this.getClosestBlock(path) + let totalHeight: number + + if (closestBlock) { + const [, blockPath] = closestBlock + const relPath = Path.relative(path, blockPath) + totalHeight = relPath.length + height + } else { + totalHeight = path.length + } + + this.splitNodeAtPoint(point, { height: totalHeight, ...rest }) + } + + /** + * Split the inline node at a specific point, up to a certain inline height. + */ + + splitInlineAtPoint( + this: Editor, + point: Point, + options: { + always?: boolean + height?: number + } = {} + ): void { + const { height = 0, ...rest } = options + const { path } = point + const furthestInline = this.getFurthestInline(path) + let totalHeight: number + + if (furthestInline) { + const [, furthestPath] = furthestInline + const furthestRelPath = Path.relative(path, furthestPath) + // Ensure that the height isn't higher than the furthest inline, since + // this command should never split any block nodes. + const h = Math.max(furthestRelPath.length, height) + totalHeight = h + 1 + } else { + // If there are no inline ancestors, just split the text node. + totalHeight = 1 + } + + this.splitNodeAtPoint(point, { height: totalHeight, ...rest }) + } + + /** + * Split nodes in the document at a specific point, up to a certain height. + * + * If the `always: false` option is passed, nodes will only be split if the + * point is not already at one of their edges. + */ + + splitNodeAtPoint( + this: Editor, + point: Point, + options: { + always?: boolean + height?: number + } = {} + ): void { + const { path, offset } = point + const { height = 0, always = true } = options + + if (height < path.length) { + throw new Error( + `Cannot split the leaf node at path ${path} to a height of ${height} because it does not have that many ancestors.` + ) + } + + this.withoutNormalizing(() => { + let position = offset + let h = 0 + + // Create a ref that tracks the split point as we move up the ancestors. + // Stick backwards because we're splitting and we want to remain inside + // the ancestor branch. + const pointRef = this.createPointRef(point, { stick: 'backward' }) + + // Iterate up the ancestors, splitting each until the right depth. + while (h < height) { + const depth = path.length - h + const index = depth - 1 + const parentPath = path.slice(0, index) + const target = position + position = path[index] + h++ + + // With the `always: false` option, we will instead split the nodes only + // when the point isn't already at it's edge. + if ( + !always && + pointRef.current != null && + this.isAtEdgeOfPath(pointRef.current, parentPath) + ) { + continue + } + + this.splitNodeAtPath(parentPath, position, { target }) + } + }) + } + + /** + * Split the text node at a point. + */ + + splitTextAtPoint( + this: Editor, + point: Point, + options: { always?: boolean } = {} + ): void { + this.splitNodeAtPoint(point, { height: 0, ...options }) + } +} + +export default PointCommands diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts new file mode 100755 index 0000000000..2c1b1b71bb --- /dev/null +++ b/packages/slate/src/classes/commands/range.ts @@ -0,0 +1,409 @@ +import { Editor, Fragment, Mark, Element, Node, Path, Range } from '../..' + +class RangeCommands { + /** + * Add a mark to all of the spans of text in a range, splitting the individual + * text nodes if the range intersects them. + */ + + addMarkAtRange(this: Editor, range: Range, mark: Mark): void { + this.withoutNormalizing(() => { + const rangeRef = this.createRangeRef(range, { stick: 'inward' }) + const [start, end] = Range.points(range) + this.splitTextAtPoint(end, { always: false }) + this.splitTextAtPoint(start, { always: false }) + range = rangeRef.unref()! + + for (const [node, path] of this.texts({ range })) { + if (!Mark.exists(mark, node.marks)) { + this.apply({ type: 'add_mark', path, mark }) + } + } + }) + } + + /** + * Delete the content in a range. + */ + + deleteAtRange( + this: Editor, + range: Range, + options: { + amount?: number + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + hanging?: boolean + } = {} + ): void { + const { hanging = false } = options + + // If the range is collapsed, the delete functions like a backspace button + // or delete button would, by deleting in a direction. + if (Range.isCollapsed(range)) { + this.deleteAtPoint(range.anchor, options) + return + } + + this.withoutNormalizing(() => { + if (hanging === false) { + // To obey common rich text editor behavior, if the range is "hanging" + // into the end block, we move it backwards so that it's not. + range = this.getNonHangingRange(range) + } + + const [start, end] = Range.points(range) + const startRef = this.createPointRef(start) + const endRef = this.createPointRef(end, { stick: 'backward' }) + const afterRef = this.createPointRef(end) + + this.splitBlockAtRange(range, { height: Infinity }) + + const startIndex = startRef.current!.path[0] + const endIndex = endRef.current!.path[0] + + for (let i = endIndex; i <= startIndex; i--) { + this.removeNodeAtPath([i]) + } + + const afterClosest = this.getClosestBlock(afterRef.current!.path) + + if (afterClosest) { + const [, afterBlockPath] = afterClosest + this.mergeBlockAtPath(afterBlockPath) + } + }) + } + + /** + * Insert a block node at a range. + */ + + insertBlockAtRange(this: Editor, range: Range, block: Element): void { + this.withoutNormalizing(() => { + const [start] = Range.points(range) + const pointRef = this.createPointRef(start) + this.deleteAtRange(range) + this.insertBlockAtPoint(pointRef.current!, block) + pointRef.unref() + }) + } + + /** + * Insert a fragment of nodes at a range. + */ + + insertFragmentAtRange(this: Editor, range: Range, fragment: Fragment): void { + this.withoutNormalizing(() => { + const [start] = Range.points(range) + const pointRef = this.createPointRef(start) + this.deleteAtRange(range) + this.insertFragmentAtPoint(pointRef.current!, fragment) + pointRef.unref() + }) + } + + /** + * Insert an inline node at a range. + */ + + insertInlineAtRange(this: Editor, range: Range, inline: Element): void { + this.withoutNormalizing(() => { + const [start] = Range.points(range) + const pointRef = this.createPointRef(start) + this.deleteAtRange(range) + this.insertInlineAtPoint(pointRef.current!, inline) + pointRef.unref() + }) + } + + /** + * Insert a string of text at a range. + */ + + insertTextAtRange(this: Editor, range: Range, text: string): void { + this.withoutNormalizing(() => { + const [start] = Range.points(range) + const pointRef = this.createPointRef(start) + this.deleteAtRange(range) + this.insertTextAtPoint(pointRef.current!, text) + pointRef.unref() + }) + } + + /** + * Remove a mark from all of the spans of text in a range. + */ + + removeMarkAtRange(this: Editor, range: Range, mark: Mark): void { + this.withoutNormalizing(() => { + for (const [node, path] of this.texts({ range })) { + if (Mark.exists(mark, node.marks)) { + this.apply({ type: 'remove_mark', path, mark }) + } + } + }) + } + + /** + * Set new properties on all of the leaf blocks in a range. + */ + + setLeafBlocksAtRange( + this: Editor, + range: Range, + props: {}, + options: { + hanging?: boolean + } = {} + ): void { + const { hanging = false } = options + + this.withoutNormalizing(() => { + if (hanging === false) { + // To obey common rich text editor behavior, if the range is "hanging" + // into the end block, we move it backwards so that it's not. + range = this.getNonHangingRange(range) + } + + for (const [, path] of this.leafBlocks({ range })) { + this.setNodeAtPath(path, props) + } + }) + } + + /** + * Set new properties on all of the leaf inlines in a range. + */ + + setLeafInlinesAtRange( + this: Editor, + range: Range, + props: {}, + options: { + hanging?: boolean + } = {} + ): void { + const { hanging = false } = options + + this.withoutNormalizing(() => { + if (hanging === false) { + // To obey common rich text editor behavior, if the range is "hanging" + // into the end block, we move it backwards so that it's not. + range = this.getNonHangingRange(range) + } + + for (const [, path] of this.leafInlines({ range })) { + this.setNodeAtPath(path, props) + } + }) + } + + /** + * Set new properties on all of the root blocks in a range. + */ + + setRootBlocksAtRange( + this: Editor, + range: Range, + props: {}, + options: { + hanging?: boolean + } = {} + ): void { + const { hanging = false } = options + + this.withoutNormalizing(() => { + if (hanging === false) { + // To obey common rich text editor behavior, if the range is "hanging" + // into the end block, we move it backwards so that it's not. + range = this.getNonHangingRange(range) + } + + for (const [, path] of this.rootBlocks({ range })) { + this.setNodeAtPath(path, props) + } + }) + } + + /** + * Set new properties on all of the root inlines in a range. + */ + + setRootInlinesAtRange( + this: Editor, + range: Range, + props: {}, + options: { + hanging?: boolean + } = {} + ): void { + const { hanging = false } = options + + this.withoutNormalizing(() => { + if (hanging === false) { + // To obey common rich text editor behavior, if the range is "hanging" + // into the end block, we move it backwards so that it's not. + range = this.getNonHangingRange(range) + } + + for (const [, path] of this.rootInlines({ range })) { + this.setNodeAtPath(path, props) + } + }) + } + + /** + * Split the block at a range, up to a height. + */ + + splitBlockAtRange( + this: Editor, + range: Range, + options: { + always?: boolean + height?: number + } = {} + ) { + this.withoutNormalizing(() => { + const [, end] = Range.points(range) + const pointRef = this.createPointRef(end) + this.deleteAtRange(range) + const point = pointRef.unref() + this.splitBlockAtPoint(point!, options) + }) + } + + /** + * Split the inline at a range, up to a height. + */ + + splitInlineAtRange( + this: Editor, + range: Range, + options: { + always?: boolean + height?: number + } = {} + ) { + this.withoutNormalizing(() => { + const [, end] = Range.points(range) + const pointRef = this.createPointRef(end) + this.deleteAtRange(range) + const point = pointRef.unref() + this.splitInlineAtPoint(point!, options) + }) + } + + /** + * Toggle a mark on or off for all of the spans of text in a range. + */ + + toggleMarkAtRange(this: Editor, range: Range, mark: Mark): void { + this.withoutNormalizing(() => { + for (const [node, path] of this.texts({ range })) { + this.apply({ + type: Mark.exists(mark, node.marks) ? 'remove_mark' : 'add_mark', + path, + mark, + }) + } + }) + } + + /** + * Unwrap the block nodes in a range that match a set of properties. + */ + + unwrapBlockAtRange(this: Editor, range: Range, props: {}) { + this.withoutNormalizing(() => { + // Iterate in reverse to ensure unwrapping doesn't affect path lookups. + for (const [node, path] of this.blocks({ range, reverse: true })) { + if (Node.matches(node, props)) { + this.unwrapChildrenAtPath(path) + } + } + }) + } + + /** + * Unwrap the inline nodes in a range that match a set of properties. + */ + + unwrapInlineAtRange(this: Editor, range: Range, props: {}) { + this.withoutNormalizing(() => { + // Iterate in reverse to ensure unwrapping doesn't affect path lookups. + for (const [node, path] of this.inlines({ range, reverse: true })) { + if (Node.matches(node, props)) { + this.unwrapChildrenAtPath(path) + } + } + }) + } + + /** + * Wrap the blocks in a range in a new block parent. + */ + + wrapBlockAtRange(this: Editor, range: Range, block: Element) { + this.withoutNormalizing(() => { + const [start] = Range.points(range) + const [, end] = Range.points(range) + + const startClosest = this.getClosestBlock(start.path) + const endClosest = this.getClosestBlock(end.path) + + if (startClosest && endClosest) { + const [, startPath] = startClosest + const [, endPath] = endClosest + const ancestorPath = Path.common(startPath, endPath) + const startIndex = startPath[ancestorPath.length] + const endIndex = endPath[ancestorPath.length] + const targetPath = ancestorPath.concat([startIndex]) + this.insertNodeAtPath(targetPath, block) + + for (let i = 0; i <= endIndex - startIndex; i++) { + const path = ancestorPath.concat(startIndex + 1) + const newPath = ancestorPath.concat([startIndex, i]) + this.moveNodeAtPath(path, newPath) + } + } + }) + } + + /** + * Wrap the text and inline nodes in a range in a new inline parent. + */ + + wrapInlineAtRange(this: Editor, range: Range, inline: Element) { + this.withoutNormalizing(() => { + const rangeRef = this.createRangeRef(range, { stick: 'inward' }) + const [splitStart, splitEnd] = Range.points(range) + this.splitInlineAtPoint(splitStart, { always: false }) + this.splitInlineAtPoint(splitEnd, { always: false }) + + range = rangeRef.current! + const [start, end] = Range.points(range) + + for (const [block, blockPath] of this.leafBlocks({ range })) { + const isStart = Path.isAncestor(blockPath, start.path) + const isEnd = Path.isAncestor(blockPath, end.path) + const startIndex = isStart ? start.path[blockPath.length] : 0 + const endIndex = isEnd + ? end.path[blockPath.length] + : block.nodes.length - 1 + + const targetPath = blockPath.concat([startIndex]) + this.insertNodeAtPath(targetPath, inline) + + for (let i = 0; i <= endIndex - startIndex; i++) { + const path = blockPath.concat(startIndex + 1) + const newPath = blockPath.concat([startIndex, i]) + this.moveNodeAtPath(path, newPath) + } + } + }) + } +} + +export default RangeCommands diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts new file mode 100755 index 0000000000..b656055460 --- /dev/null +++ b/packages/slate/src/classes/commands/selection.ts @@ -0,0 +1,290 @@ +import { Editor, Point, Range, Selection } from '../..' + +class SelectionCommands { + /** + * Blur the selection. + */ + + blur(this: Editor) { + this.select({ isFocused: false }) + } + + /** + * Deselect the selection. + */ + + deselect(this: Editor) { + this.select(null) + } + + /** + * Focus the selection. + */ + + focus(this: Editor) { + this.select({ isFocused: true }) + } + + /** + * Flip the selection's anchor and focus points. + */ + + flip(this: Editor) { + const { selection } = this.value + + if (selection == null) { + return + } + + const { anchor, focus } = selection + this.select({ anchor: focus, focus: anchor }) + } + + /** + * Move the selection. + * + * @param {Number} n + */ + + move( + this: Editor, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + } = {} + ) { + this.moveAnchor(options) + this.moveFocus(options) + } + + /** + * Move the selection's anchor point. + * + * @param {Number} n + */ + + moveAnchor( + this: Editor, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + } = {} + ) { + const { selection } = this.value + + if (selection == null) { + return + } + + const { anchor } = selection + const { reverse = false, ...rest } = options + const point = reverse + ? this.getPreviousPoint(anchor, rest) + : this.getNextPoint(anchor, rest) + + if (point) { + this.moveAnchorTo(point) + } + } + + /** + * Move the selection's anchor point to a new point. + */ + + moveAnchorTo(this: Editor, point: Point) { + this.select({ anchor: point }) + } + + /** + * Move the selection's end point. + */ + + moveEnd( + this: Editor, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + allowZeroWidth?: boolean + } = {} + ) { + const { selection } = this.value + + if (selection == null) { + return + } else if (Range.isForward(selection)) { + this.moveFocus(options) + } else { + this.moveAnchor(options) + } + } + + /** + * Move the selection's end point to a new point. + */ + + moveEndTo(this: Editor, point: Point) { + const { selection } = this.value + + if (selection == null) { + return + } else if (Range.isForward(selection)) { + this.moveFocusTo(point) + } else { + this.moveAnchorTo(point) + } + } + + /** + * Move the selection's focus point. + * + * @param {Number} n + */ + + moveFocus( + this: Editor, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + } = {} + ) { + const { selection } = this.value + + if (selection == null) { + return + } + + const { focus } = selection + const { reverse = false, ...rest } = options + const point = reverse + ? this.getPreviousPoint(focus, rest) + : this.getNextPoint(focus, rest) + + if (point) { + this.moveFocusTo(point) + } + } + + /** + * Move the selection's focus point to a new point. + */ + + moveFocusTo(this: Editor, point: Point) { + this.select({ anchor: point }) + } + + /** + * Move the selection's start point. + */ + + moveStart( + this: Editor, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + } = {} + ) { + const { selection } = this.value + + if (selection == null) { + return + } else if (Range.isForward(selection)) { + this.moveAnchor(options) + } else { + this.moveFocus(options) + } + } + + /** + * Move the selection's start point to a new point. + */ + + moveStartTo(this: Editor, point: Point) { + const { selection } = this.value + + if (selection == null) { + return + } else if (Range.isForward(selection)) { + this.moveAnchorTo(point) + } else { + this.moveFocusTo(point) + } + } + + /** + * Move the cursor to a specific point. + */ + + moveTo(this: Editor, point: Point) { + this.select({ anchor: point, focus: point }) + } + + /** + * Set new properties on the selection. + */ + + select(this: Editor, properties: Partial | null) { + const { selection } = this.value + let prevProps: Partial | null = {} + let newProps: Partial | null = {} + + if (selection == null && properties == null) { + return + } else if (properties == null) { + newProps = null + prevProps = selection + } else if (selection == null) { + newProps = { isFocused: false, ...properties } + prevProps = null + + if (!Selection.isSelection(newProps)) { + throw new Error( + `When setting new selection properties and the current selection is \`null\` you must provide a full selection, but you passed: ${properties}` + ) + } + } else { + let isChange = false + + // Remove any properties that aren't different from the existing selection. + for (const k in properties) { + const isPoint = k === 'anchor' || k === 'focus' + + if ( + (isPoint && !Point.equals(properties[k], selection[k])) || + (!isPoint && properties[k] !== selection[k]) + ) { + isChange = true + newProps[k] = properties[k] + prevProps[k] = selection[k] + } + } + + // If the selection moves, clear any marks, unless the new selection + // properties change the marks in some way. + if ( + selection.marks && + !newProps.marks && + (newProps.anchor || newProps.focus) + ) { + isChange = true + newProps.marks = null + prevProps.marks = selection.marks + } + + if (!isChange) { + return + } + } + + this.apply({ + type: 'set_selection', + properties: prevProps, + newProperties: newProps, + }) + } +} + +export default SelectionCommands diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts new file mode 100755 index 0000000000..53814b8b72 --- /dev/null +++ b/packages/slate/src/classes/commands/value.ts @@ -0,0 +1,608 @@ +import { + Change, + Editor, + Element, + Fragment, + Mark, + Node, + Operation, + Path, + Text, + Range, + Value, +} from '../..' +import { + DIRTY_PATHS, + PATH_REFS, + POINT_REFS, + RANGE_REFS, + FLUSHING, + NORMALIZING, +} from '../../symbols' + +// Properties that are restricted, and that can't be set directly on a `Value`. +const RESTRICTED_PROPERTIES = ['annotations', 'history', 'nodes', 'selection'] + +class ValueCommands { + /** + * Add a mark to the span of text that is currently selected. + */ + + addMark(this: Editor, mark: Mark): void { + const { selection } = this.value + + if (selection == null) { + return + } else if (Range.isExpanded(selection)) { + this.addMarkAtRange(selection, mark) + } else { + const activeMarks = this.getActiveMarks() + + if (!Mark.exists(mark, activeMarks)) { + const marks = activeMarks.concat(mark) + this.select({ marks }) + } + } + } + + /** + * Apply an operation to the editor, updating its current value. + */ + + apply(this: Editor, op: Operation): void { + this.value = Value.transform(this.value, op) + this.operations.push(op) + + for (const ref of Object.values(this[PATH_REFS])) { + ref.transform(op) + } + + for (const ref of Object.values(this[POINT_REFS])) { + ref.transform(op) + } + + for (const ref of Object.values(this[RANGE_REFS])) { + ref.transform(op) + } + + const pathCache = {} + const dirtyPaths: Path[] = [] + const add = (path: Path | null) => { + if (path == null) { + return + } + + const key = path.join(',') + + if (key in pathCache) { + return + } + + pathCache[key] = true + dirtyPaths.push(path) + } + + for (const path of this[DIRTY_PATHS]) { + add(Path.transform(path, op)) + } + + for (const path of getDirtyPaths(op)) { + add(path) + } + + this[DIRTY_PATHS] = dirtyPaths + this.normalize() + + if (!this[FLUSHING]) { + this[FLUSHING] = true + Promise.resolve().then(() => this.flush()) + } + } + + /** + * Delete the content in the selection, or starting from the cursor. + */ + + delete( + this: Editor, + options: { + amount?: number + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + } = {} + ) { + const { selection } = this.value + + if (selection == null) { + return + } + + const [start] = Range.points(selection) + const pointRef = this.createPointRef(start) + this.deleteAtRange(selection, options) + this.moveTo(pointRef.current!) + pointRef.unref() + } + + /** + * Flush the editor's current changes. + */ + + flush(this: Editor): void { + this[FLUSHING] = false + const { value, operations } = this + + if (operations.length !== 0) { + const change: Change = { value, operations } + this.operations = [] + this.onChange(change) + } + } + + /** + * Insert a block node at the cursor. + */ + + insertBlock(this: Editor, block: Element) { + const { selection } = this.value + + if (selection == null) { + return + } + + const [start] = Range.points(selection) + const pointRef = this.createPointRef(start) + this.insertBlockAtRange(selection, block) + this.moveTo(pointRef.current!) + pointRef.unref() + } + + /** + * Insert a fragment of nodes at the cursor. + */ + + insertFragment(this: Editor, fragment: Fragment) { + const { selection } = this.value + + if (selection == null) { + return + } + + const [start] = Range.points(selection) + const pointRef = this.createPointRef(start) + this.insertFragmentAtRange(selection, fragment) + this.moveTo(pointRef.current!) + pointRef.unref() + } + + /** + * Insert an inline node at the cursor. + */ + + insertInline(this: Editor, inline: Element) { + const { selection } = this.value + + if (selection == null) { + return + } + + const [start] = Range.points(selection) + const pointRef = this.createPointRef(start) + this.insertInlineAtRange(selection, inline) + this.moveTo(pointRef.current!) + pointRef.unref() + } + + /** + * Insert a string of text at the current selection. + */ + + insertText(this: Editor, text: string) { + const { selection } = this.value + + if (selection == null) { + return + } + + const [start] = Range.points(selection) + const pointRef = this.createPointRef(start) + this.insertTextAtRange(selection, text) + this.moveTo(pointRef.current!) + pointRef.unref() + } + + /** + * Normalize any paths that are considered "dirty", meaning they have recently + * been changed by an operation. + */ + + normalize( + this: Editor, + options: { + force?: boolean + } = {} + ): void { + const { force = false } = options + + if (!this[NORMALIZING]) { + return + } + + if (force) { + const allPaths = Array.from(Node.entries(this.value), ([, p]) => p) + this[DIRTY_PATHS] = allPaths + } + + if (this[DIRTY_PATHS].length === 0) { + return + } + + this.withoutNormalizing(() => { + const max = this[DIRTY_PATHS].length * 42 // HACK: better way to do this? + let m = 0 + + while (this[DIRTY_PATHS].length !== 0) { + if (m > max) { + throw new Error(` + Could not completely normalize the value after ${max} iterations! This is usually due to incorrect normalization logic that leaves a node in an invalid state. + `) + } + + const path = this[DIRTY_PATHS].pop() + this.normalizeNodeAtPath(path!) + m++ + } + }) + } + + /** + * Remove a mark from all of the spans of text in the current selection. + */ + + removeMark(this: Editor, mark: Mark): void { + const { value } = this + const { selection } = value + + if (selection == null) { + return + } else if (Range.isExpanded(selection)) { + this.removeMarkAtRange(selection, mark) + } else { + const activeMarks = this.getActiveMarks() + + if (Mark.exists(mark, activeMarks)) { + const marks = activeMarks.filter(m => !Mark.matches(m, mark)) + this.select({ marks }) + } + } + } + + /** + * Replace a mark on all of the spans of text in the selection with a new one. + */ + + replaceMark(this: Editor, oldMark: Mark, newMark: Mark): void { + this.withoutNormalizing(() => { + this.removeMark(oldMark) + this.addMark(newMark) + }) + } + + /** + * Set new properties on the leaf block nodes in the current selection. + */ + + setLeafBlocks(this: Editor, props: {}) { + const { selection } = this.value + + if (selection == null) { + return + } + + this.setLeafBlocksAtRange(selection, props) + } + + /** + * Set new properties on the leaf inline nodes in the current selection. + */ + + setLeafInlines(this: Editor, props: {}) { + const { selection } = this.value + + if (selection == null) { + return + } + + this.setLeafInlinesAtRange(selection, props) + } + + /** + * Set new properties on the root block nodes in the current selection. + */ + + setRootBlocks(this: Editor, props: {}) { + const { selection } = this.value + + if (selection == null) { + return + } + + this.setRootBlocksAtRange(selection, props) + } + + /** + * Set new properties on the root inline nodes in the current selection. + */ + + setRootInlines(this: Editor, props: {}) { + const { selection } = this.value + + if (selection == null) { + return + } + + this.setRootInlinesAtRange(selection, props) + } + + /** + * Set new properties on the top-level `Value` object. + */ + + setValue(this: Editor, props: {}) { + const { value } = this + const newProps = {} + const oldProps = {} + let isChange = false + + // Dedupe new and old properties to avoid unnecessary sets. + for (const k in props) { + if (RESTRICTED_PROPERTIES.includes(k)) { + throw new Error( + `Cannot set the restricted property "${k}" on a value. You must use one of the purpose-built editor methods instead.` + ) + } + + if (props[k] !== value[k]) { + isChange = true + newProps[k] = props[k] + oldProps[k] = value[k] + } + } + + // PERF: If no properties have changed don't apply an operation at all. + if (!isChange) { + return + } + + this.apply({ + type: 'set_value', + properties: oldProps, + newProperties: newProps, + }) + } + + /** + * Split the block at the cursor, up to a height. + */ + + splitBlock( + this: Editor, + options: { + always?: boolean + height?: number + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + + if (selection == null) { + return + } + + const [, end] = Range.points(selection) + const pointRef = this.createPointRef(end) + this.splitBlockAtRange(selection, options) + this.moveTo(pointRef.current!) + pointRef.unref() + }) + } + + /** + * Split the inline at the cursor, up to a height. + */ + + splitInline( + this: Editor, + options: { + always?: boolean + height?: number + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + + if (selection == null) { + return + } + + const [, end] = Range.points(selection) + const pointRef = this.createPointRef(end) + this.splitInlineAtRange(selection, options) + this.moveTo(pointRef.current!) + pointRef.unref() + }) + } + + /** + * Toggle a mark on or off for all the spans of text in the selection. + */ + + toggleMark(this: Editor, mark: Mark): void { + const activeMarks = this.getActiveMarks() + + if (Mark.exists(mark, activeMarks)) { + this.removeMark(mark) + } else { + this.addMark(mark) + } + } + + /** + * Unwrap the block nodes in the selection that match a set of properties. + */ + + unwrapBlock(this: Editor, props: {}): void { + const { selection } = this.value + + if (selection == null) { + return + } + + const rangeRef = this.createRangeRef(selection) + this.unwrapBlockAtRange(selection, props) + this.select(rangeRef.current) + rangeRef.unref() + } + + /** + * Unwrap the inline nodes in the selection that match a set of properties. + */ + + unwrapInline(this: Editor, props: {}): void { + const { selection } = this.value + + if (selection == null) { + return + } + + const rangeRef = this.createRangeRef(selection) + this.unwrapInlineAtRange(selection, props) + this.select(rangeRef.current) + rangeRef.unref() + } + + /** + * Apply a series of changes inside a synchronous callback, deferring + * normalization until after the callback has finished executing. + */ + + withoutNormalizing(this: Editor, fn: () => void): void { + const value = this[NORMALIZING] + this[NORMALIZING] = false + fn() + this[NORMALIZING] = value + this.normalize() + } + + /** + * Wrap the block nodes in the selection in a new block. + */ + + wrapBlock(this: Editor, block: Element): void { + const { selection } = this.value + + if (selection == null) { + return + } + + const rangeRef = this.createRangeRef(selection) + this.wrapBlockAtRange(selection, block) + this.select(rangeRef.current) + rangeRef.unref() + } + + /** + * Wrap the inline nodes in the selection in a new inline. + */ + + wrapInline(this: Editor, inline: Element): void { + const { selection } = this.value + + if (selection == null) { + return + } + + const rangeRef = this.createRangeRef(selection) + this.wrapInlineAtRange(selection, inline) + this.select(rangeRef.current) + rangeRef.unref() + } +} + +/** + * Get the "dirty" paths generated from an operation. + */ + +const getDirtyPaths = (op: Operation) => { + switch (op.type) { + case 'add_mark': + case 'insert_text': + case 'remove_mark': + case 'remove_text': + case 'set_mark': + case 'set_node': { + const { path } = op + const ancestors = Path.ancestors(path) + return [...ancestors, path] + } + + case 'insert_node': { + const { node, path } = op + const descendants = Text.isText(node) + ? [] + : Array.from(Node.entries(node), ([, p]) => path.concat(p)) + + const ancestors = Path.ancestors(path) + return [...ancestors, path, ...descendants] + } + + case 'split_node': { + const { path } = op + const ancestors = Path.ancestors(path) + const nextPath = Path.next(path) + return [...ancestors, path, nextPath] + } + + case 'merge_node': { + const { path } = op + const ancestors = Path.ancestors(path) + const previousPath = Path.previous(path) + return [...ancestors, previousPath] + } + + case 'move_node': { + const { path, newPath } = op + + if (Path.equals(path, newPath)) { + return [] + } + + const oldAncestors: Path[] = [] + const newAncestors: Path[] = [] + + for (const ancestor of Path.ancestors(path)) { + const path = Path.transform(ancestor, op) + oldAncestors.push(path!) + } + + for (const ancestor of Path.ancestors(newPath)) { + const path = Path.transform(ancestor, op) + newAncestors.push(path!) + } + + return [...oldAncestors, ...newAncestors] + } + + case 'remove_node': { + const { path } = op + const ancestors = Path.ancestors(path) + return [...ancestors] + } + + default: { + return [] + } + } +} + +export default ValueCommands diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts new file mode 100755 index 0000000000..1c14c4f8b1 --- /dev/null +++ b/packages/slate/src/classes/editor.ts @@ -0,0 +1,105 @@ +import { produce } from 'immer' +import { Change, Path, PathRef, PointRef, RangeRef, Operation, Value } from '..' +import { + DIRTY_PATHS, + NORMALIZING, + FLUSHING, + PATH_REFS, + POINT_REFS, + RANGE_REFS, +} from '../symbols' +import AnnotationCommands from './commands/annotation' +import PathCommands from './commands/path' +import PointCommands from './commands/point' +import RangeCommands from './commands/range' +import SelectionCommands from './commands/selection' +import ValueCommands from './commands/value' +import MarkQueries from './queries/mark' +import NodeQueries from './queries/node' +import PathQueries from './queries/path' +import PointQueries from './queries/point' +import RangeQueries from './queries/range' +import ValueQueries from './queries/value' + +/** + * The `EditorConstructor` interface is provided as a convenience for plugins + * who can use it when writing the typings for extending the `Editor` class. + */ + +type EditorConstructor = new (...args: any[]) => Editor + +/** + * The `Editor` class stores all the state of a Slate editor. It is extended by + * plugins that wish to add their own methods that implement new behaviors. + */ + +class Editor { + onChange: (change: Change) => void + operations: Operation[] + readOnly: boolean + value: Value; + [DIRTY_PATHS]: Path[]; + [FLUSHING]: boolean; + [NORMALIZING]: boolean; + [PATH_REFS]: { [key: number]: PathRef }; + [POINT_REFS]: { [key: number]: PointRef }; + [RANGE_REFS]: { [key: number]: RangeRef } + + constructor(props: { + onChange?(change: Change): void + readOnly?: boolean + value?: Value + }) { + const { + onChange = () => {}, + readOnly = false, + value = produce( + { nodes: [], selection: null, annotations: {} }, + () => {} + ), + } = props + + this.onChange = onChange + this.operations = [] + this.readOnly = readOnly + this.value = value + this[DIRTY_PATHS] = [] + this[FLUSHING] = false + this[NORMALIZING] = true + this[PATH_REFS] = {} + this[POINT_REFS] = {} + this[RANGE_REFS] = {} + } +} + +interface Editor + extends AnnotationCommands, + PathCommands, + PointCommands, + RangeCommands, + SelectionCommands, + ValueCommands, + MarkQueries, + NodeQueries, + PathQueries, + PointQueries, + RangeQueries, + ValueQueries {} + +Object.assign( + Editor.prototype, + AnnotationCommands.prototype, + PathCommands.prototype, + PointCommands.prototype, + RangeCommands.prototype, + SelectionCommands.prototype, + ValueCommands.prototype, + MarkQueries.prototype, + NodeQueries.prototype, + PathQueries.prototype, + PointQueries.prototype, + RangeQueries.prototype, + ValueQueries.prototype +) + +export { Editor, EditorConstructor } diff --git a/packages/slate/src/classes/path-ref.ts b/packages/slate/src/classes/path-ref.ts new file mode 100644 index 0000000000..ece3207410 --- /dev/null +++ b/packages/slate/src/classes/path-ref.ts @@ -0,0 +1,62 @@ +import { Operation, Path } from '..' + +/** + * An auto-incrementing number to identify `PathRef` objects. + */ + +let id = 0 + +/** + * `PathRef` objects keep a specific path in a document synced over time as new + * operations are applied to the editor. You can access their `current` property + * at any time for the up-to-date path value. + */ + +class PathRef { + id: number + current: Path | null + private stick: 'forward' | 'backward' | null + private onUnref: () => void + + constructor(props: { + path: Path | null + stick: 'forward' | 'backward' | null + onUnref: () => void + }) { + const { path, stick, onUnref } = props + this.id = id++ + this.current = path + this.stick = stick + this.onUnref = onUnref + } + + /** + * Transform the path ref's current value by an operation. + */ + + transform(op: Operation): void { + const { current, stick } = this + + if (current == null) { + return + } + + const path = Path.transform(current, op, { stick }) + this.current = path + + if (path == null) { + this.unref() + } + } + + /** + * Unreference the ref, allowing the editor to stop updating its value. + */ + + unref(): Path | null { + this.onUnref() + return this.current + } +} + +export { PathRef } diff --git a/packages/slate/src/classes/point-ref.ts b/packages/slate/src/classes/point-ref.ts new file mode 100644 index 0000000000..caaf282c00 --- /dev/null +++ b/packages/slate/src/classes/point-ref.ts @@ -0,0 +1,62 @@ +import { Operation, Point } from '..' + +/** + * An auto-incrementing number to identify `PointRef` objects. + */ + +let id = 0 + +/** + * `PointRef` objects keep a specific point in a document synced over time as new + * operations are applied to the editor. You can access their `current` property + * at any time for the up-to-date point value. + */ + +class PointRef { + id: number + current: Point | null + private stick: 'forward' | 'backward' | null + private onUnref: () => void + + constructor(props: { + point: Point | null + stick: 'forward' | 'backward' | null + onUnref: () => void + }) { + const { point, stick, onUnref } = props + this.id = id++ + this.current = point + this.stick = stick + this.onUnref = onUnref + } + + /** + * Transform the point ref's current value by an operation. + */ + + transform(op: Operation): void { + const { current, stick } = this + + if (current == null) { + return + } + + const point = Point.transform(current, op, { stick }) + this.current = point + + if (point == null) { + this.unref() + } + } + + /** + * Unreference the ref, allowing the editor to stop updating its value. + */ + + unref(): Point | null { + this.onUnref() + return this.current + } +} + +export { PointRef } diff --git a/packages/slate/src/classes/queries/mark.ts b/packages/slate/src/classes/queries/mark.ts new file mode 100644 index 0000000000..a5e7ab1ecb --- /dev/null +++ b/packages/slate/src/classes/queries/mark.ts @@ -0,0 +1,14 @@ +import { Editor, Mark } from '../..' + +class MarkQueries { + /** + * Determine is a mark is atomic, meaning that removing any text inside the + * mark should remove the mark entirely. + */ + + isAtomic(this: Editor, mark: Mark): boolean { + return false + } +} + +export default MarkQueries diff --git a/packages/slate/src/classes/queries/node.ts b/packages/slate/src/classes/queries/node.ts new file mode 100644 index 0000000000..dc6e41f94e --- /dev/null +++ b/packages/slate/src/classes/queries/node.ts @@ -0,0 +1,48 @@ +import { Editor, Node, Element, Text } from '../..' + +class NodeQueries { + /** + * Check if a node is a block, meaning it lives at the level above text nodes + * in the document tree. + */ + + isBlock(this: Editor, node: Node): node is Element { + return Element.isElement(node) + } + + /** + * Check if a node is an inline, meaning that it lives intermixed with text + * nodes in the document tree. + */ + + isInline(this: Editor, node: Node): node is Element { + return false + } + + /** + * Check if a node is a leaf block node. + */ + + isLeafBlock(this: Editor, node: Node): node is Element { + return this.isBlock(node) && !this.isBlock(node.nodes[0]) + } + + /** + * Check if a node is a leaf inline node. + */ + + isLeafInline(this: Editor, node: Node): node is Element { + return this.isInline(node) && node.nodes.every(n => Text.isText(n)) + } + + /** + * Check if a node is a void, meaning that Slate considers its content a black + * box. It will be edited as if it has no content. + */ + + isVoid(this: Editor, node: Node): node is Element { + return false + } +} + +export default NodeQueries diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts new file mode 100644 index 0000000000..bb6a817ca6 --- /dev/null +++ b/packages/slate/src/classes/queries/path.ts @@ -0,0 +1,324 @@ +import { produce } from 'immer' +import { + Editor, + ElementEntry, + Node, + Operation, + Point, + Path, + PathRef, + Range, + Text, + TextEntry, +} from '../..' +import { PATH_REFS } from '../../symbols' + +class PathQueries { + /** + * Create a mutable ref for a `Path` object, which will stay in sync as new + * operations are applied to the this. + */ + + createPathRef( + this: Editor, + path: Path, + options: { stick?: 'backward' | 'forward' | null } = {} + ): PathRef { + const { stick = 'forward' } = options + const ref: PathRef = new PathRef({ + path, + stick, + onUnref: () => delete this[PATH_REFS][ref.id], + }) + + this[PATH_REFS][ref.id] = ref + return ref + } + + /** + * Get the closest block node at a path. + */ + + getClosestBlock(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.levels(this.value, path)) { + if (this.isBlock(n)) { + return [n, p] + } + } + } + + /** + * Get the closest inline node entry at a path. + */ + + getClosestInline(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.levels(this.value, path)) { + if (this.isInline(n)) { + return [n, p] + } + } + } + + /** + * Get the closest void node entry at a path. + */ + + getClosestVoid(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.levels(this.value, path)) { + if (this.isVoid(n)) { + return [n, p] + } + } + } + + /** + * Get the end point of the node at path. + */ + + getEnd(this: Editor, path: Path): Point { + const [lastNode, lastPath] = this.getLastText(path) + const point = { path: lastPath, offset: lastNode.text.length } + return point + } + + /** + * Get the first text node from a node at path. + */ + + getFirstText(this: Editor, path: Path): TextEntry { + const { value } = this + const node = Node.get(value, path) + + if (Text.isText(node)) { + return [node, path] + } + + const [first] = Node.texts(value, { path }) + + if (!first) { + throw new Error( + `Unable to get the first text node of a node at path ${path} because it has no text nodes.` + ) + } + + return first + } + + /** + * Get the furthest block node at a path. + */ + + getFurthestBlock(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { + if (this.isBlock(n)) { + return [n, p] + } + } + } + + /** + * Get the furthest inline node entry at a path. + */ + + getFurthestInline(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { + if (this.isInline(n)) { + return [n, p] + } + } + } + + /** + * Get the furthest void node entry at a path. + */ + + getFurthestVoid(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { + if (this.isVoid(n)) { + return [n, p] + } + } + } + + /** + * Get the last text node from a node at path. + */ + + getLastText(this: Editor, path: Path): TextEntry { + const { value } = this + const node = Node.get(value, path) + + if (Text.isText(node)) { + return [node, path] + } + + const [last] = Node.texts(value, { path, reverse: true }) + + if (!last) { + throw new Error( + `Unable to get the last text node of a node at path ${path} because it has no text nodes.` + ) + } + + return last + } + + /** + * Get the next leaf block node entry starting from a path. + */ + + getNextLeafBlock(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path })) { + if (this.isLeafBlock(n)) { + return [n, p] + } + } + } + + /** + * Get the next leaf inline node entry starting from a path. + */ + + getNextLeafInline(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path })) { + if (this.isLeafInline(n)) { + return [n, p] + } + } + } + + /** + * Get the next root block node entry starting from a path. + */ + + getNextRootBlock(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path })) { + if (this.isBlock(n) && p.length === 1) { + return [n, p] + } + } + } + + /** + * Get the next root inline node entry starting from a path. + */ + + getNextRootInline(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path })) { + if (this.isInline(n)) { + const parent = Node.parent(this.value, p) + + if (this.isBlock(parent)) { + return [n, p] + } + } + } + } + + /** + * Get the next text node entry starting from a path. + */ + + getNextText(this: Editor, path: Path): TextEntry | undefined { + const { value } = this + const [entry] = Node.texts(value, { path }) + return entry + } + + /** + * Get the previous leaf block node entry starting from a path. + */ + + getPreviousLeafBlock(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { + if (this.isLeafBlock(n)) { + return [n, p] + } + } + } + + /** + * Get the previous leaf inline node entry starting from a path. + */ + + getPreviousLeafInline(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { + if (this.isLeafInline(n)) { + return [n, p] + } + } + } + + /** + * Get the previous root block node entry starting from a path. + */ + + getPreviousRootBlock(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { + if (this.isBlock(n) && p.length === 1) { + return [n, p] + } + } + } + + /** + * Get the previous root inline node entry starting from a path. + */ + + getPreviousRootInline(this: Editor, path: Path): ElementEntry | undefined { + for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { + if (this.isInline(n)) { + const parent = Node.parent(this.value, p) + + if (this.isBlock(parent)) { + return [n, p] + } + } + } + } + + /** + * Get the previous text node entry starting from a path. + */ + + getPreviousText(this: Editor, path: Path): TextEntry | undefined { + const { value } = this + const [entry] = Node.texts(value, { path, reverse: true }) + return entry + } + + /** + * Get the full range of a node at path. + */ + + getRange(this: Editor, path: Path): Range { + const { value } = this + const [first] = Node.texts(value, { path }) + const [last] = Node.texts(value, { path, reverse: true }) + + if (!first || !last) { + throw new Error( + `Unable to get a range for the node at path ${path} because it has not text nodes.` + ) + } + + const [, firstPath] = first + const [lastNode, lastPath] = last + const anchor = { path: firstPath, offset: 0 } + const focus = { path: lastPath, offset: lastNode.text.length } + const range = produce({ anchor, focus }, () => {}) + return range + } + + /** + * Get the start point of the node at path. + */ + + getStart(this: Editor, path: Path): Point { + const [firstNode, firstPath] = this.getFirstText(path) + const point = { path: firstPath, offset: firstNode.text.length } + return point + } +} + +export default PathQueries diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts new file mode 100644 index 0000000000..eeb2c08953 --- /dev/null +++ b/packages/slate/src/classes/queries/point.ts @@ -0,0 +1,163 @@ +import { Editor, Node, Operation, Path, Point, PointRef } from '../..' +import { POINT_REFS } from '../../symbols' + +class PointQueries { + /** + * Create a mutable ref for a `Point` object, which will stay in sync as new + * operations are applied to the this. + */ + + createPointRef( + this: Editor, + point: Point, + options: { stick?: 'backward' | 'forward' | null } = {} + ): PointRef { + const { stick = 'forward' } = options + const ref: PointRef = new PointRef({ + point, + stick, + onUnref: () => delete this[POINT_REFS][ref.id], + }) + + this[POINT_REFS][ref.id] = ref + return ref + } + + /** + * Check if a point is at the start of a path. + */ + + isAtStartOfPath(this: Editor, point: Point, path: Path): boolean { + const { value } = this + const [first] = Node.texts(value, { path }) + + if (!first) { + return false + } + + const [, firstPath] = first + return point.offset === 0 && Path.equals(point.path, firstPath) + } + + /** + * Check if a point is at the end of a path. + */ + + isAtEndOfPath(this: Editor, point: Point, path: Path): boolean { + const { value } = this + const [last] = Node.texts(value, { path, reverse: true }) + + if (!last) { + return false + } + + const [lastNode, lastPath] = last + return ( + point.offset === lastNode.text.length && Path.equals(point.path, lastPath) + ) + } + + /** + * Check if a point is at either edge of a path. + */ + + isAtEdgeOfPath(this: Editor, point: Point, path: Path): boolean { + return this.isAtStartOfPath(point, path) || this.isAtEndOfPath(point, path) + } + + /** + * Calculate the next point forward in the document from a starting point. + */ + + getNextPoint( + this: Editor, + point: Point, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + allowZeroWidth?: boolean + } = {} + ): Point | undefined { + const { distance = 1 } = options + let d = 0 + let target: Point | undefined + + for (const p of this.positions({ ...options, point })) { + if (d >= distance) { + break + } + + target = p + d++ + } + + return target + } + + /** + * Get the next point in the document that is not inside a void node. + */ + + getNextNonVoidPoint(this: Editor, point: Point): Point | undefined { + let next: Point | undefined = point + + while (next) { + const closestVoid = this.getClosestVoid(next.path) + + if (closestVoid) { + next = this.getNextPoint(next, { allowZeroWidth: true }) + } else { + return next + } + } + } + + /** + * Calculate the previous point backward from a starting point. + */ + + getPreviousPoint( + this: Editor, + point: Point, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' + allowZeroWidth?: boolean + } = {} + ): Point | undefined { + const { distance = 1 } = options + let d = 0 + let target: Point | undefined + + for (const p of this.positions({ ...options, point, reverse: true })) { + if (d >= distance) { + break + } + + target = p + d++ + } + + return target + } + + /** + * Get the previous point in the document that is not inside a void node. + */ + + getPreviousNonVoidPoint(this: Editor, point: Point): Point | undefined { + let prev: Point | undefined = point + + while (prev) { + const closestVoid = this.getClosestVoid(prev.path) + + if (closestVoid) { + prev = this.getPreviousPoint(prev, { allowZeroWidth: true }) + } else { + return prev + } + } + } +} + +export default PointQueries diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts new file mode 100644 index 0000000000..2ec842ddbb --- /dev/null +++ b/packages/slate/src/classes/queries/range.ts @@ -0,0 +1,142 @@ +import { produce } from 'immer' +import { Editor, Path, Operation, Range, RangeRef } from '../..' +import { RANGE_REFS } from '../../symbols' + +let rangeRefIds = 0 + +class RangeQueries { + /** + * Create a mutable ref for a `Range` object, which will stay in sync as new + * operations are applied to the this. + */ + + createRangeRef( + this: Editor, + range: Range, + options: { + stick?: 'backward' | 'forward' | 'outward' | 'inward' | null + } = {} + ): RangeRef { + const { stick = 'forward' } = options + const ref: RangeRef = new RangeRef({ + range, + stick, + onUnref: () => delete this[RANGE_REFS][ref.id], + }) + + this[RANGE_REFS][ref.id] = ref + return ref + } + + /** + * Get a range, ensuring that it is not hanging into a block node. + * + * @param {Range} range + * @return {Range} + */ + + getNonBlockHangingRange(this: Editor, range: Range): Range { + if (this.isBlockHanging(range)) { + range = produce(range, r => { + const [, end] = Range.points(r) + const prev = this.getPreviousText(end.path) + + if (prev) { + const [prevText, prevPath] = prev + end.path = prevPath + end.offset = prevText.text.length + } + }) + } + + return range + } + + /** + * Get a range, ensuring that it is not hanging into an inline node. + * + * @param {Range} range + * @return {Range} + */ + + getNonInlineHangingRange(this: Editor, range: Range): Range { + if (this.isInlineHanging(range)) { + range = produce(range, r => { + const [, end] = Range.points(r) + const prev = this.getPreviousText(end.path) + + if (prev) { + const [prevText, prevPath] = prev + end.path = prevPath + end.offset = prevText.text.length + } + }) + } + + return range + } + + /** + * Get a range, ensuring that it is not hanging into the next leaf inline or + * block node. + * + * @param {Range} range + * @return {Range} + */ + + getNonHangingRange(this: Editor, range: Range): Range { + range = this.getNonInlineHangingRange(range) + range = this.getNonBlockHangingRange(range) + return range + } + + /** + * Check whether a range is hanging in a block. + */ + + isBlockHanging(this: Editor, range: Range): boolean { + if (!Range.isExpanded(range)) { + return false + } + + const [, end] = Range.points(range) + const closestBlock = this.getClosestBlock(end.path) + + if (!closestBlock) { + return false + } + + const [, endBlockPath] = closestBlock + return this.isAtStartOfPath(end, endBlockPath) + } + + /** + * Check whether a range is hanging in an inline. + */ + + isInlineHanging(this: Editor, range: Range): boolean { + if (!Range.isExpanded(range)) { + return false + } + + const [, end] = Range.points(range) + const closestInline = this.getClosestInline(end.path) + + if (!closestInline) { + return false + } + + const [, endInlinePath] = closestInline + return this.isAtStartOfPath(end, endInlinePath) + } + + /** + * Check whether a range is hanging into the next leaf inline or block node. + */ + + isHanging(this: Editor, range: Range): boolean { + return this.isInlineHanging(range) || this.isBlockHanging(range) + } +} + +export default RangeQueries diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts new file mode 100644 index 0000000000..59ece20576 --- /dev/null +++ b/packages/slate/src/classes/queries/value.ts @@ -0,0 +1,328 @@ +import { produce } from 'immer' +import { reverse as reverseText } from 'esrever' +import { + Ancestor, + Editor, + ElementEntry, + Mark, + Node, + Path, + Point, + Range, + String, + TextEntry, +} from '../..' + +class ValueQueries { + /** + * Iterate through all of the block nodes in the editor. + */ + + *blocks(this: Editor, options: {} = {}): Iterable { + for (const [n, p] of Node.elements(this.value, options)) { + if (this.isBlock(n)) { + yield [n, p] + } + } + } + + /** + * Get the marks that are "active" in the current selection. These are the + * marks that will be added to any text that is inserted. + * + * The `union: true` option can be passed to create a union of marks across + * the text nodes in the selection, instead of creating an intersection, which + * is the default. + * + * Note: to obey common rich text behavior, if the selection is collapsed at + * the start of a text node and there are previous text nodes in the same + * block, it will carry those marks forward from the previous text node. This + * allows for continuation of marks from previous words. + * + * Note: when `selection.marks` is not null, it is always returned. + */ + + getActiveMarks(this: Editor, options: { union?: boolean } = {}): Mark[] { + const { union = false } = options + const { value } = this + const { selection } = value + + if (selection == null) { + return [] + } + + // If the selection has explicitly defined marks, those override everything. + if (selection.marks != null) { + return selection.marks + } + + let range: Range = selection + let result: Mark[] = [] + let first = true + + // If the range is collapsed at the start of a text node, it should carry + // over the marks from the previous text node in the same block. + if ( + Range.isCollapsed(range) && + // PERF: If the offset isn't zero we know it's not at the start. + range.anchor.offset === 0 + ) { + const { anchor } = range + const closestBlock = this.getClosestBlock(anchor.path) + const prevText = this.getPreviousText(anchor.path) + + if (closestBlock && prevText) { + const [, blockPath] = closestBlock + const [, prevPath] = prevText + + if (Path.isAncestor(blockPath, prevPath)) { + range = this.getRange(prevPath) + } + } + } + + for (const [node] of Node.texts(value, { range })) { + const { marks } = node + + if (first) { + result = marks + first = false + continue + } + + // PERF: If we're doing an intersection and the result hits zero it can + // never increase again, so we can exit early. + if (!union && result.length === 0) { + break + } + + if (union) { + for (const mark of marks) { + if (!Mark.exists(mark, marks)) { + result.push(mark) + } + } + } else { + // When intersecting, iterate backwards so that removing marks doesn't + // impact indexing. + for (let i = result.length - 1; i >= 0; i--) { + const existing = result[i] + + if (!Mark.exists(existing, marks)) { + result.splice(i, 1) + } + } + } + } + + return result + } + + /** + * Iterate through all of the inline nodes in the editor. + */ + + *inlines(this: Editor, options: {} = {}): Iterable { + for (const [n, p] of Node.elements(this.value, options)) { + if (this.isInline(n)) { + yield [n, p] + } + } + } + + /** + * Iterate through all of the leaf block nodes in the editor. + */ + + *leafBlocks(this: Editor, options: {} = {}): Iterable { + for (const [n, p] of this.blocks(options)) { + if (this.isLeafBlock(n)) { + yield [n, p] + } + } + } + + /** + * Iterate through all of the leaf inline nodes in the editor. + */ + + *leafInlines(this: Editor, options: {} = {}): Iterable { + for (const [n, p] of this.inlines(options)) { + if (this.isLeafInline(n)) { + yield [n, p] + } + } + } + + /** + * Iterate through all of the positions in the document where a `Point` can be + * placed. + * + * By default it will move forward by individual offsets at a time, but you + * can pass the `unit: 'character'` option to moved forward one character, word, + * or line at at time. + * + * Note: void nodes are treated as a single point, and iteration will not + * happen inside their content. + */ + + *positions( + this: Editor, + options: { + point?: Point + unit?: 'offset' | 'character' | 'word' | 'line' + reverse?: boolean + allowZeroWidth?: boolean + } = {} + ): Iterable { + const { unit = 'offset', reverse = false } = options + const { value } = this + let { point } = options + + if (point == null) { + const [entry] = Node.texts(value, { reverse }) + const [textNode, textPath] = entry + const textOffset = reverse ? textNode.text.length : 0 + point = { path: textPath, offset: textOffset } + } + + while (true) { + const { path, offset } = point + const furthestVoid = this.getFurthestVoid(path) + const closestBlock = this.getClosestBlock(path) + let skipPath: Path | void + + if (furthestVoid) { + const [, voidPath] = furthestVoid + skipPath = voidPath + } else if (closestBlock) { + const [, blockPath] = closestBlock + + if ( + (!reverse && this.isAtEndOfPath(point, blockPath)) || + (reverse && this.isAtStartOfPath(point, blockPath)) + ) { + skipPath = blockPath + } + } + + if (skipPath) { + const textEntry = reverse + ? this.getPreviousText(skipPath) + : this.getNextText(skipPath) + + if (!textEntry) { + break + } + + const [textNode, textPath] = textEntry + const textOffset = reverse ? textNode.text.length : 0 + point = produce(point, p => { + p.path = textPath + p.offset = textOffset + }) + + yield point + } + + const node = Node.leaf(value, path) + let root: Ancestor = value + let rootPath: Path = [] + + if (closestBlock) { + const [block, blockPath] = closestBlock + root = block + rootPath = blockPath + } + + const rootText = Node.text(root) + const relPath = Path.relative(path, rootPath) + const relOffset = Node.offset(root, relPath) + const rootOffset = relOffset + offset + const remainingText = reverse + ? reverseText(rootText.slice(0, rootOffset)) + : rootText.slice(rootOffset) + + let d = 1 + + if (unit === 'character') { + d = String.getCharacterDistance(remainingText) + } else if (unit === 'word') { + d = String.getWordDistance(remainingText) + } else if (unit === 'line') { + // COMPAT: If we're moving by line, we approximate it in core by moving + // by the entire block. This can be overriden in environments where you + // have rendered lines that can be calculated. + d = remainingText.length + } + + const newOffset = reverse ? offset - d : offset + d + + // If the travel distance is all inside the current text node, just + // move the existing point's offset. + if ( + (!reverse && newOffset <= node.text.length) || + (reverse && newOffset >= 0) + ) { + point = produce(point, p => { + p.offset = newOffset + }) + + yield point + } + + let t = reverse ? offset : node.text.length - offset + + // Otherwise, we need to iterate the text nodes of the block until we've + // traveled the correct offset amount. + for (const [textNode, textPath] of this.texts({ path, reverse })) { + const { length } = textNode.text + + if (t + length >= d) { + point = produce(point, p => { + p.path = textPath + p.offset = reverse ? length - (d - t) : d - t + }) + + yield point + } + } + } + } + + /** + * Iterate through all of the root block nodes in the editor. + */ + + *rootBlocks(this: Editor, options: {} = {}): Iterable { + for (const [n, p] of this.blocks(options)) { + if (p.length === 1) { + yield [n, p] + } + } + } + + /** + * Iterate through all of the root inline nodes in the editor. + */ + + *rootInlines(this: Editor, options: {} = {}): Iterable { + for (const [n, p] of this.inlines(options)) { + const parent = Node.parent(this.value, p) + + if (this.isBlock(parent)) { + yield [n, p] + } + } + } + + /** + * Iterate through all of the text nodes in the editor. + */ + + *texts(this: Editor, options: {} = {}): Iterable { + yield* Node.texts(this.value, options) + } +} + +export default ValueQueries diff --git a/packages/slate/src/classes/range-ref.ts b/packages/slate/src/classes/range-ref.ts new file mode 100644 index 0000000000..59be4bad1b --- /dev/null +++ b/packages/slate/src/classes/range-ref.ts @@ -0,0 +1,62 @@ +import { Operation, Range } from '..' + +/** + * An auto-incrementing number to identify `RangeRef` objects. + */ + +let id = 0 + +/** + * `RangeRef` objects keep a specific range in a document synced over time as new + * operations are applied to the editor. You can access their `current` property + * at any time for the up-to-date range value. + */ + +class RangeRef { + id: number + current: Range | null + private stick: 'forward' | 'backward' | 'outward' | 'inward' | null + private onUnref: () => void + + constructor(props: { + range: Range | null + stick: 'forward' | 'backward' | 'outward' | 'inward' | null + onUnref: () => void + }) { + const { range, stick, onUnref } = props + this.id = id++ + this.current = range + this.stick = stick + this.onUnref = onUnref + } + + /** + * Transform the range ref's current value by an operation. + */ + + transform(op: Operation): void { + const { current, stick } = this + + if (current == null) { + return + } + + const range = Range.transform(current, op, { stick }) + this.current = range + + if (range == null) { + this.unref() + } + } + + /** + * Unreference the ref, allowing the editor to stop updating its value. + */ + + unref(): Range | null { + this.onUnref() + return this.current + } +} + +export { RangeRef } diff --git a/packages/slate/src/commands/at-point.js b/packages/slate/src/commands/at-point.js deleted file mode 100644 index 4368eb200c..0000000000 --- a/packages/slate/src/commands/at-point.js +++ /dev/null @@ -1,82 +0,0 @@ -import Path from '../utils/path-utils' - -/** - * Commands. - * - * @type {Object} - */ - -const Commands = {} - -/** - * Split at a `point` and up to a `parentPath`. - * - * @param {Point} point - * @param {Path} path - */ - -Commands.splitNodeAtPoint = (fn, editor) => (point, parentPath) => { - parentPath = Path.create(parentPath) - - editor.withoutNormalizing(() => { - const { value: { document } } = editor - const { path, offset } = point - editor.splitNodeByPath(path, offset) - - // If the parent path is the same as the text node, we're done. - if (parentPath.equals(path)) { - return - } - - let position = offset - let prevPath = path - - // Iterate up the ancestors, splitting each node until `parentPath` is met. - for (const [, ancestorPath] of document.ancestors(path)) { - const target = position - position = prevPath.last() + 1 - prevPath = ancestorPath - editor.splitNodeByPath(ancestorPath, position, { target }) - - if (ancestorPath.equals(parentPath)) { - break - } - } - }) -} - -/** - * Split at a `point` and up to blocks of `height`. - * - * @param {Point} point - * @param {number} height - */ - -Commands.splitBlockAtPoint = (fn, editor) => (point, height = 1) => { - editor.withoutNormalizing(() => { - const { value: { document } } = editor - let h = 0 - let blockPath - - for (const [node, path] of document.ancestors(point.path)) { - if (h >= height) { - break - } else if (node.object === 'block') { - blockPath = path - h++ - } - } - - if (blockPath) { - editor.splitNodeAtPoint(point, blockPath) - } - }) -} - -/** - * Export. - * - * @type {Object} - */ - -export default Commands diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js deleted file mode 100644 index 3102084ecf..0000000000 --- a/packages/slate/src/commands/at-range.js +++ /dev/null @@ -1,956 +0,0 @@ -import Block from '../models/block' -import Inline from '../models/inline' -import Mark from '../models/mark' -import Path from '../utils/path-utils' - -/** - * Ensure that an expanded selection is deleted first, and return the updated - * range to account for the deleted part. - * - * @param {Editor} - */ - -function deleteExpandedAtRange(editor, range) { - if (range.isExpanded) { - editor.deleteAtRange(range) - } - - const { value } = editor - const { document } = value - const { start, end } = range - - if (document.hasDescendant(start.path)) { - range = range.moveToStart() - } else { - range = range.moveTo(end.path, 0).normalize(document) - } - - return range -} - -/** - * Commands. - * - * @type {Object} - */ - -const Commands = {} - -/** - * Add a new `mark` to the characters at `range`. - * - * @param {Range} range - * @param {Mixed} mark - */ - -Commands.addMarkAtRange = (fn, editor) => (range, mark) => { - if (range.isCollapsed) { - return - } - - const { value } = editor - const { document } = value - const { start, end } = range - - editor.withoutNormalizing(() => { - for (const [node, path] of document.texts({ range })) { - let index = 0 - let length = node.text.length - - if (path.equals(start.path)) { - index = start.offset - } - - if (path.equals(end.path)) { - length = end.offset - } - - if (path.equals(start.path) && path.equals(end.path)) { - length = end.offset - start.offset - } - - editor.addMarkByPath(path, index, length, mark) - } - }) -} - -/** - * Add a list of `marks` to the characters at `range`. - * - * @param {Range} range - * @param {Array} mark - */ - -Commands.addMarksAtRange = (fn, editor) => (range, marks) => { - marks.forEach(mark => editor.addMarkAtRange(range, mark)) -} - -/** - * Delete everything in a `range`. - * - * @param {Range} range - */ - -Commands.deleteAtRange = (fn, editor) => range => { - editor.withoutNormalizing(() => { - // HACK: Snapshot the selection, which creates an extra undo save point, so - // that when you undo a delete, the expanded selection will be retained. We - // should find a better way to do this... - editor.snapshotSelection() - - const { value: { document } } = editor - const iterable = document.descendants({ range }) - const { start, end } = range - const [startBlock, startBlockPath] = document.closestBlock(start.path) - const [endBlock, endBlockPath] = document.closestBlock(end.path) - const isAcrossBlocks = !startBlockPath.equals(endBlockPath) - const isAcrossTexts = !start.path.equals(end.path) - const entries = Array.from(iterable).reverse() - let mergePath = endBlockPath - - // COMPAT: Rich text editors have a special behavior when triple-clicking - // which results in the end point being at the start of the next block. In - // this case, they preserve the end block instead of merging it. - const isHanging = - range.isExpanded && - editor.isAtStartOfBlock(range.start) && - editor.isAtStartOfBlock(range.end) - - const isStartVoid = !!document.closest( - start.path, - n => n.object === 'block' && editor.isVoid(n) - ) - - const isEndVoid = !!document.closest( - end.path, - n => n.object === 'block' && editor.isVoid(n) - ) - - for (const [node, path] of entries) { - if (isHanging && Path.isIn(path, endBlockPath)) { - // Don't remove the end block's nodes if it's hanging. - } else if (editor.isVoid(node)) { - editor.removeNodeByPath(path) - } else if (document.closest(path, editor.isVoid)) { - // Don't bother removing children of voides. - } else if ( - Path.isChild(path, startBlockPath) || - Path.isChild(path, endBlockPath) || - (!isAcrossTexts && path.equals(start.path)) - ) { - const isAtStart = Path.isAt(path, start.path) - const isAtEnd = Path.isAt(path, end.path) - const splitEnd = isAtEnd && !editor.isAtEndOfPath(end, path) - const splitStart = isAtStart && !editor.isAtStartOfPath(start, path) - const splitLater = !isAcrossTexts && !path.equals(start.path) - - if ( - (isAtEnd && editor.isAtStartOfPath(end, path)) || - (isAtStart && editor.isAtEndOfPath(start, path)) - ) { - // Do nothing, since it's before/after. - } else if (splitLater) { - // Don't split yet, since we're too high up. - } else if (splitEnd && splitStart) { - const newPath = Path.increment(path) - editor.splitNodeAtPoint(end, path) - editor.splitNodeAtPoint(start, path) - editor.removeNodeByPath(newPath) - } else if ( - splitEnd || - (isAtEnd && !splitStart && endBlock.nodes.size === 1) - ) { - editor.splitNodeAtPoint(end, path) - editor.removeNodeByPath(path) - } else if ( - splitStart || - (isAtStart && !splitEnd && startBlock.nodes.size === 1) - ) { - const newPath = Path.increment(path) - editor.splitNodeAtPoint(start, path) - editor.removeNodeByPath(newPath) - } else if ( - isAtStart || - isAtEnd || - Path.isBetween(path, start.path, end.path) - ) { - editor.removeNodeByPath(path) - } - } else if (Path.isBetween(path, startBlockPath, endBlockPath)) { - editor.removeNodeByPath(path) - - if (Path.isYounger(path, mergePath)) { - mergePath = Path.decrement(mergePath, 1, path.size - 1) - } - } - } - - // TODO: this `isHanging` logic could probably be simplified by editing the - // range before iterating, instead of trying to handle each edge case here. - if (isHanging && isStartVoid && !isEndVoid) { - // If the selection is hanging, and the start block was a void, it will - // have already been removed, so we do nothing. - } else if (isHanging && (isStartVoid || isEndVoid)) { - editor.removeNodeByPath(startBlockPath) - } else if (isStartVoid || isEndVoid) { - // If the selection wasn't hanging, and it started or ended in a void node - // they will have already been removed, so we're done. - } else if (isHanging) { - // If the selection was hanging, we want to remove the start block - // entirely instead of merging it with the end block. This is a rich text - // editor behavior that's fairly standard. - const newPath = Path.increment(startBlockPath) - editor.moveNodeByPath(mergePath, newPath) - editor.removeNodeByPath(startBlockPath) - } else if (isAcrossBlocks) { - // If the selection wasn't hanging, but we were across blocks, we need to - // merge the block into the previous one. - editor.mergeBlockByPath(mergePath) - } - }) -} - -/** - * Delete backward `n` characters at a `range`. - * - * @param {Range} range - * @param {Number} n (optional) - */ - -Commands.deleteBackwardAtRange = (fn, editor) => (range, n = 1) => { - if (range.isExpanded) { - return editor.deleteAtRange(range) - } - - let point = range.start - - for (let i = 0; i < n; i++) { - const next = editor.getPreviousPoint(point) - - if (!next) { - break - } else { - point = next - } - } - - range = range.setStart(point) - return editor.deleteAtRange(range) -} - -/** - * Delete backward until the character boundary at a `range`. - * - * @param {Range} range - */ - -Commands.deleteCharBackwardAtRange = (fn, editor) => range => { - if (range.isExpanded) { - editor.deleteAtRange(range) - } else { - const prev = editor.getPreviousCharacterPoint(range.end) - - if (prev) { - range = range.setStart(prev) - editor.deleteAtRange(range) - } - } -} - -/** - * Delete forward until the character boundary at a `range`. - * - * @param {Range} range - */ - -Commands.deleteCharForwardAtRange = (fn, editor) => range => { - if (range.isExpanded) { - editor.deleteAtRange(range) - } else { - const next = editor.getNextCharacterPoint(range.end) - - if (next) { - range = range.setStart(next) - editor.deleteAtRange(range) - } - } -} - -/** - * Delete forward `n` characters at a `range`. - * - * @param {Range} range - * @param {Number} n (optional) - */ - -Commands.deleteForwardAtRange = (fn, editor) => (range, n = 1) => { - if (range.isExpanded) { - return editor.deleteAtRange(range) - } - - let point = range.start - - for (let i = 0; i < n; i++) { - const next = editor.getNextPoint(point) - - if (!next) { - break - } else { - point = next - } - } - - range = range.setStart(point) - return editor.deleteAtRange(range) -} - -/** - * Delete backward until the line boundary at a `range`. - * - * @param {Range} range - */ - -Commands.deleteLineBackwardAtRange = (fn, editor) => range => { - if (range.isExpanded) { - editor.deleteAtRange(range) - return - } - - const { value } = editor - const { document } = value - const { start } = range - const [block, path] = document.closestBlock(start.path) - const relativePath = start.path.slice(path.size) - const offset = block.getOffset(relativePath) - const o = offset + start.offset - editor.deleteBackwardAtRange(range, o) -} - -/** - * Delete forward until the line boundary at a `range`. - * - * @param {Range} range - */ - -Commands.deleteLineForwardAtRange = (fn, editor) => range => { - if (range.isExpanded) { - editor.deleteAtRange(range) - return - } - - const { value } = editor - const { document } = value - const { start } = range - const [block, path] = document.closestBlock(start.path) - const relativePath = start.path.slice(path.size) - const offset = block.getOffset(relativePath) - const o = offset + start.offset - editor.deleteForwardAtRange(range, block.text.length - o) -} - -/** - * Delete backward until the word boundary at a `range`. - * - * @param {Range} range - */ - -Commands.deleteWordBackwardAtRange = (fn, editor) => range => { - if (range.isExpanded) { - editor.deleteAtRange(range) - } else { - const previous = editor.getPreviousWordPoint(range.end) - - if (previous) { - range = range.setStart(previous) - editor.deleteAtRange(range) - } - } -} - -/** - * Delete forward until the word boundary at a `range`. - * - * @param {Range} range - */ - -Commands.deleteWordForwardAtRange = (fn, editor) => range => { - if (range.isExpanded) { - editor.deleteAtRange(range) - } else { - const next = editor.getNextWordPoint(range.start) - - if (next) { - range = range.setEnd(next) - editor.deleteAtRange(range) - } - } -} - -/** - * Insert a `block` node at `range`. - * - * @param {Range} range - * @param {Block|String|Object} block - */ - -Commands.insertBlockAtRange = (fn, editor) => (range, block) => { - range = deleteExpandedAtRange(editor, range) - block = Block.create(block) - const { value: { document } } = editor - const { start } = range - const [closestBlock, closestBlockPath] = document.closestBlock(start.path) - const closestInline = document.closestInline(start.path) - let targetPath - let pathRef - - editor.withoutNormalizing(() => { - if ( - (!closestInline && closestBlock.text === '') || - editor.isAtEndOfPath(start, closestBlockPath) - ) { - targetPath = Path.increment(closestBlockPath) - } else if ( - editor.isAtStartOfPath(start, closestBlockPath) || - editor.isVoid(closestBlock) - ) { - targetPath = closestBlockPath - } else { - const splitPoint = - editor.getNextNonVoidPoint(start) || - editor.getPreviousNonVoidPoint(start) - - editor.splitNodeAtPoint(splitPoint, closestBlockPath) - targetPath = Path.increment(closestBlockPath) - } - - editor.insertNodeByPath(targetPath, block) - pathRef = editor.createPathRef(targetPath) - }) - - pathRef.unref() - return pathRef.path -} - -/** - * Insert a `fragment` at a `range`. - * - * @param {Range} range - * @param {Document} fragment - */ - -Commands.insertFragmentAtRange = (fn, editor) => (range, fragment) => { - let startPointRef - let endPointRef - let afterPathRef - - editor.withoutNormalizing(() => { - range = deleteExpandedAtRange(editor, range) - - if (!fragment.nodes.size) { - return - } - - const point = range.start - const { value: { document } } = editor - const [, splitPath] = document.closestBlock(point.path) - - editor.splitBlockAtPoint(point, 1) - - const startPath = Path.increment(splitPath) - afterPathRef = editor.createPathRef(startPath) - editor.insertFragmentByPath(startPath, fragment) - - const afterPath = afterPathRef.path - const endPath = Path.decrement(afterPath) - const startPoint = editor.getStartOfPath(startPath) - const endPoint = editor.getEndOfPath(endPath) - const afterPoint = editor.getStartOfPath(afterPath) - startPointRef = editor.createPointRef(startPoint) - endPointRef = editor.createPointRef(endPoint) - editor.mergeBlockByPath(afterPoint.path) - editor.mergeBlockByPath(startPoint.path) - }) - - startPointRef.unref() - endPointRef.unref() - afterPathRef.unref() - - range = range.setPoints([startPointRef.point, endPointRef.point]) - return range -} - -/** - * Insert an `inline` node at `range`. - * - * @param {Range} range - * @param {Inline|String|Object} inline - */ - -Commands.insertInlineAtRange = (fn, editor) => (range, inline) => { - inline = Inline.create(inline) - let pathRef - - editor.withoutNormalizing(() => { - range = deleteExpandedAtRange(editor, range) - const { value: { document } } = editor - let { start: { path, offset } } = range - const closestVoid = document.closest(path, editor.isVoid) - - if (closestVoid) { - return - } - - path = editor.splitNodeByPath(path, offset) - path = editor.insertNodeByPath(path, inline) - pathRef = editor.createPathRef(path) - }) - - if (!pathRef) { - return null - } - - pathRef.unref() - return pathRef.path -} - -/** - * Insert `text` at a `range`, with optional `marks`. - * - * @param {Range} range - * @param {String} text - * @param {Set} marks (optional) - */ - -Commands.insertTextAtRange = (fn, editor) => (range, text, marks) => { - editor.withoutNormalizing(() => { - range = deleteExpandedAtRange(editor, range) - const { value: { document } } = editor - const { start } = range - const closestVoid = document.closest(start.path, editor.isVoid) - - if (closestVoid) { - return - } - - editor.insertTextByPath(start.path, start.offset, text, marks) - }) -} - -/** - * Remove an existing `mark` to the characters at `range`. - * - * @param {Range} range - * @param {Mark|String} mark (optional) - */ - -Commands.removeMarkAtRange = (fn, editor) => (range, mark) => { - if (range.isCollapsed) { - return - } - - const { value } = editor - const { document } = value - const { start, end } = range - - editor.withoutNormalizing(() => { - for (const [node, path] of document.texts({ range })) { - const isStart = path.equals(start.path) - const isEnd = path.equals(end.path) - let index - let length - - if (isStart && isEnd) { - index = start.offset - length = end.offset - start.offset - } else if (isStart) { - index = start.offset - length = node.text.length - start.offset - } else if (isEnd) { - index = 0 - length = end.offset - } else { - index = 0 - length = node.text.length - } - - editor.removeMarkByPath(path, index, length, mark) - } - }) -} - -/** - * Set the `properties` of block nodes in a `range`. - * - * @param {Range} range - * @param {Object|String} properties - */ - -Commands.setBlocksAtRange = (fn, editor) => (range, properties) => { - editor.withoutNormalizing(() => { - const { value: { document } } = editor - const iterable = document.blocks({ - range, - includeHanging: false, - onlyLeaves: true, - }) - - for (const [, path] of iterable) { - editor.setNodeByPath(path, properties) - } - }) -} - -/** - * Set the `properties` of inline nodes in a `range`. - * - * @param {Range} range - * @param {Object|String} properties - */ - -Commands.setInlinesAtRange = (fn, editor) => (range, properties) => { - editor.withoutNormalizing(() => { - const { value: { document } } = editor - const iterable = document.inlines({ range, onlyLeaves: true }) - - for (const [, path] of iterable) { - editor.setNodeByPath(path, properties) - } - }) -} - -/** - * Split the block nodes at a `range`, to optional `height`. - * - * @param {Range} range - * @param {Number} height (optional) - */ - -Commands.splitBlockAtRange = (fn, editor) => (range, height = 1) => { - editor.withoutNormalizing(() => { - range = deleteExpandedAtRange(editor, range) - const { start } = range - const { value: { document } } = editor - let h = 0 - let targetPath - - for (const [node, path] of document.ancestors(start.path)) { - if (h >= height) { - break - } else if (node.object === 'block') { - targetPath = path - h++ - } - } - - if (targetPath) { - editor.splitNodeAtPoint(start, targetPath) - } - }) -} - -/** - * Split the inline nodes at a `range`, to optional `height`. - * - * @param {Range} range - * @param {Number} height (optional) - */ - -Commands.splitInlineAtRange = (fn, editor) => (range, height = Infinity) => { - editor.withoutNormalizing(() => { - range = deleteExpandedAtRange(editor, range) - const { start } = range - const { value: { document } } = editor - let h = 0 - let targetPath - - for (const [node, path] of document.ancestors(start.path)) { - if (h >= height) { - break - } else if (node.object === 'inline') { - targetPath = path - h++ - } - } - - if (targetPath) { - editor.splitNodeAtPoint(start, targetPath) - } - }) -} - -Commands.splitInlineEdgesAtRange = (fn, editor) => range => { - editor.withoutNormalizing(() => { - const { value: { document } } = editor - let start = editor.getPreviousNonVoidPoint(range.start) - let end = editor.getNextNonVoidPoint(range.end) - const startText = document.getNode(start.path) - const endText = document.getNode(end.path) - const startFurthest = document.furthestInline(start.path) - const endFurthest = document.furthestInline(end.path) - - if (endFurthest) { - const [furthestNode, furthestPath] = endFurthest - const [lastText, lastPath] = furthestNode.lastText() - const relativePath = end.path.slice(furthestPath.size) - - if ( - end.offset !== lastText.text.length || - !relativePath.equals(lastPath) - ) { - editor.splitNodeAtPoint(end, furthestPath) - } - } else if (end.offset !== 0 && end.offset !== endText.text.length) { - editor.splitNodeByPath(end.path, end.offset) - - end = end - .setPath(Path.increment(end.path)) - .setOffset(0) - .setKey(null) - .normalize(editor.value.document) - } - - if (startFurthest) { - const [furthestNode, furthestPath] = startFurthest - const [, firstPath] = furthestNode.firstText() - const relativePath = start.path.slice(furthestPath.size) - - if (start.offset !== 0 || !relativePath.equals(firstPath)) { - editor.splitNodeAtPoint(start, furthestPath) - - if ( - Path.isYounger(furthestPath, end.path) || - Path.isAbove(furthestPath, end.path) || - Path.isEqual(furthestPath, end.path) - ) { - end = end - .setPath(Path.increment(end.path, 1, furthestPath.size - 1)) - .setKey(null) - .normalize(editor.value.document) - } - - start = start - .setPath( - Path.increment(furthestPath).concat(relativePath.map(() => 0)) - ) - .setOffset(0) - .setKey(null) - .normalize(editor.value.document) - } - } else if (start.offset !== 0 && start.offset !== startText.text.length) { - editor.splitNodeByPath(start.path, start.offset) - - if ( - Path.isYounger(start.path, end.path) || - Path.isAbove(start.path, end.path) || - Path.isEqual(start.path, end.path) - ) { - end = end - .setPath(Path.increment(end.path, 1, start.path.size - 1)) - .setKey(null) - .normalize(editor.value.document) - } - - start = start - .setPath(Path.increment(start.path)) - .setOffset(0) - .setKey(null) - .normalize(editor.value.document) - } - - range = range.setAnchor(start).setFocus(end) - }) - - return range -} - -/** - * Add or remove a `mark` from the characters at `range`, depending on whether - * it's already there. - * - * @param {Range} range - * @param {Mixed} mark - */ - -Commands.toggleMarkAtRange = (fn, editor) => (range, mark) => { - if (range.isCollapsed) return - - mark = Mark.create(mark) - - const { value } = editor - const { document } = value - const marks = document.getActiveMarksAtRange(range) - const exists = marks.some(m => m.equals(mark)) - - if (exists) { - editor.removeMarkAtRange(range, mark) - } else { - editor.addMarkAtRange(range, mark) - } -} - -/** - * Unwrap all of the block nodes in a `range` from a block with `properties`. - * - * TODO: This should be aligned with `unwrapInlineAtRange`, which currently does - * not split parent nodes in the ranges, and instead removes any matching inline - * parent nodes in the range. I think we probably need to different concepts, - * and then to allow each for blocks and inlines. - * - * @param {Range} range - * @param {String|Object} properties - */ - -Commands.unwrapBlockAtRange = (fn, editor) => (range, properties) => { - editor.withoutNormalizing(() => { - const { value: { document } } = editor - const iterable = document.blocks({ - range, - match: (block, path) => { - if (block.hasProperties(properties)) { - return false - } else { - const parentPath = Path.lift(path) - const parent = document.getNode(parentPath) - return parent && parent.hasProperties(properties) - } - }, - }) - - // We need to reverse the paths here, because unwrapping each inline will - // affect the paths of the inlines after it, so we go backwards instead. - const paths = Array.from(iterable, ([, path]) => path).reverse() - - for (const path of paths) { - editor.unwrapNodeByPath(path) - } - }) -} - -/** - * Unwrap the inline nodes in a `range` from an inline with `properties`. - * - * @param {Range} range - * @param {String|Object} properties - */ - -Commands.unwrapInlineAtRange = (fn, editor) => (range, properties) => { - editor.withoutNormalizing(() => { - const { value: { document } } = editor - const iterable = document.inlines({ - range, - match: inline => inline.hasProperties(properties), - }) - - // We need to reverse the paths here, because unwrapping each inline will - // affect the paths of the inlines after it, so we go backwards instead. - const paths = Array.from(iterable, ([, path]) => path).reverse() - - for (const path of paths) { - editor.unwrapChildrenByPath(path) - } - }) -} - -/** - * Wrap all of the blocks in a `range` in a new `block`. - * - * @param {Range} range - * @param {Block|Object|String} block - */ - -Commands.wrapBlockAtRange = (fn, editor) => (range, block) => { - block = Block.create(block) - block = block.set('nodes', block.nodes.clear()) - - const { value: { document } } = editor - const { start, end } = range - const [, firstPath] = document.closestBlock(start.path) - const [, lastPath] = document.closestBlock(end.path) - const ancestorPath = firstPath.equals(lastPath) - ? Path.lift(firstPath) - : Path.relate(firstPath, lastPath) - - const startIndex = firstPath.get(ancestorPath.size) - const endIndex = lastPath.get(ancestorPath.size) - - editor.withoutNormalizing(() => { - const targetPath = ancestorPath.concat([startIndex]) - editor.insertNodeByPath(targetPath, block) - - for (let i = 0; i <= endIndex - startIndex; i++) { - const path = ancestorPath.concat(startIndex + 1) - const newPath = ancestorPath.concat([startIndex, i]) - editor.moveNodeByPath(path, newPath) - } - }) -} - -/** - * Wrap the text and inlines in a `range` in a new `inline`. - * - * @param {Range} range - * @param {Inline|Object|String} inline - */ - -Commands.wrapInlineAtRange = (fn, editor) => (range, inline) => { - inline = Inline.create(inline) - inline = inline.set('nodes', inline.nodes.clear()) - - editor.withoutNormalizing(() => { - range = editor.splitInlineEdgesAtRange(range) - range = editor.getNonHangingRange(range) - const iterable = editor.value.document.blocks({ range, onlyLeaves: true }) - - for (const [block, blockPath] of iterable) { - const isStart = Path.isAbove(blockPath, range.start.path) - const isEnd = Path.isAbove(blockPath, range.end.path) - const startIndex = isStart ? range.start.path.get(blockPath.size) : 0 - const endIndex = isEnd - ? range.end.path.get(blockPath.size) - : block.nodes.size - 1 - - const targetPath = blockPath.concat([startIndex]) - editor.insertNodeByPath(targetPath, inline) - // HACK: need to regenerate the key to ensure that subsequent inserts - // don't re-use the same key. - inline = inline.regenerateKey() - - for (let i = 0; i <= endIndex - startIndex; i++) { - const path = blockPath.concat(startIndex + 1) - const newPath = blockPath.concat([startIndex, i]) - editor.moveNodeByPath(path, newPath) - } - } - }) -} - -/** - * Wrap the text in a `range` in a prefix/suffix. - * - * @param {Range} range - * @param {String} prefix - * @param {String} suffix (optional) - */ - -Commands.wrapTextAtRange = (fn, editor) => (range, prefix, suffix = prefix) => { - const { start, end } = range - const startRange = range.moveToStart() - let endRange = range.moveToEnd() - - if (start.path.equals(end.path)) { - endRange = endRange.moveForward(prefix.length) - } - - editor.withoutNormalizing(() => { - editor.insertTextAtRange(startRange, prefix) - editor.insertTextAtRange(endRange, suffix) - }) -} - -/** - * Export. - * - * @type {Object} - */ - -export default Commands diff --git a/packages/slate/src/commands/by-path.js b/packages/slate/src/commands/by-path.js deleted file mode 100644 index d6ee945acd..0000000000 --- a/packages/slate/src/commands/by-path.js +++ /dev/null @@ -1,962 +0,0 @@ -import pick from 'lodash/pick' -import warning from 'tiny-warning' - -import Block from '../models/block' -import Inline from '../models/inline' -import Mark from '../models/mark' -import Node from '../models/node' -import Path from '../utils/path-utils' - -/** - * Commands. - * - * @type {Object} - */ - -const Commands = {} - -/** - * Add mark to text at `offset` and `length` in node by `path`. - * - * @param {Array} path - * @param {Number} offset - * @param {Number} length - * @param {Mixed} mark - */ - -Commands.addMarkByPath = (fn, editor) => (path, offset, length, mark) => { - path = Path.create(path) - mark = Mark.create(mark) - editor.addMarksByPath(path, offset, length, [mark]) -} - -Commands.addMarksByPath = (fn, editor) => (path, offset, length, marks) => { - path = Path.create(path) - marks = Mark.createSet(marks) - - if (!marks.size) { - return - } - - const { value } = editor - const { document } = value - const node = document.assertNode(path) - marks = marks.subtract(node.marks) - - if (!marks.size) { - return - } - - editor.withoutNormalizing(() => { - // If it ends before the end of the node, we'll need to split to create a new - // text with different marks. - if (offset + length < node.text.length) { - editor.splitNodeByPath(path, offset + length) - } - - // Same thing if it starts after the start. But in that case, we need to - // update our path and offset to point to the new start. - if (offset > 0) { - editor.splitNodeByPath(path, offset) - path = Path.increment(path) - offset = 0 - } - - marks.forEach(mark => { - editor.applyOperation({ - type: 'add_mark', - path, - mark: Mark.create(mark), - }) - }) - }) -} - -/** - * Sets specific set of marks on the path - * @param {Editor} editor - * @param {Array} path - * @param {Number} offset - * @param {Number} length - * @param {Array} marks - */ - -Commands.replaceMarksByPath = (fn, editor) => (path, offset, length, marks) => { - const marksSet = Mark.createSet(marks) - - const { value } = editor - const { document } = value - const node = document.assertNode(path) - - if (node.marks.equals(marksSet)) { - return - } - - editor.withoutNormalizing(() => { - // If it ends before the end of the node, we'll need to split to create a new - // text with different marks. - if (offset + length < node.text.length) { - editor.splitNodeByPath(path, offset + length) - } - - // Same thing if it starts after the start. But in that case, we need to - // update our path and offset to point to the new start. - if (offset > 0) { - editor.splitNodeByPath(path, offset) - path = Path.increment(path) - offset = 0 - } - - const marksToApply = marksSet.subtract(node.marks) - const marksToRemove = node.marks.subtract(marksSet) - - marksToRemove.forEach(mark => { - editor.applyOperation({ - type: 'remove_mark', - path, - mark: Mark.create(mark), - }) - }) - - marksToApply.forEach(mark => { - editor.applyOperation({ - type: 'add_mark', - path, - mark: Mark.create(mark), - }) - }) - }) -} - -/** - * Insert a `fragment` at `index` in a node by `path`. - * - * @param {Array} path - * @param {Number} index - * @param {Fragment} fragment - */ - -Commands.insertFragmentByPath = (fn, editor) => (path, index, fragment) => { - path = Path.create(path) - - if (typeof index === 'number' && fragment) { - warning( - false, - `As of slate@0.48 the \`editor.insertFragmentByPath\` command takes \`(targetPath, fragment)\`, instead of a \`(parentPath, index, fragment)\`.` - ) - - path = path.concat(index) - index = null - } else { - fragment = index - index = null - } - - const parentPath = Path.lift(path) - const start = path.last() - - fragment = fragment.mapDescendants(child => child.regenerateKey()) - - fragment.nodes.forEach((node, i) => { - const targetPath = parentPath.concat([start + i]) - editor.insertNodeByPath(targetPath, node) - }) -} - -/** - * Insert a `node` at `index` in a node by `path`. - * - * @param {Array} path - * @param {Number} index - * @param {Node} node - */ - -Commands.insertNodeByPath = (fn, editor) => (path, index, node) => { - path = Path.create(path) - - if (typeof index === 'number' && node) { - warning( - false, - `As of slate@0.48 the \`editor.insertNodeByPath\` command takes \`(targetPath, node)\`, instead of a \`(parentPath, index, node)\`.` - ) - - path = path.concat(index) - index = null - } else { - node = index - index = null - } - - editor.applyOperation({ - type: 'insert_node', - path, - node, - }) - - return path -} - -/** - * Insert `text` at `offset` in node by `path`. - * - * @param {Array} path - * @param {Number} offset - * @param {String} text - * @param {Set} marks (optional) - */ - -Commands.insertTextByPath = (fn, editor) => (path, offset, text, marks) => { - path = Path.create(path) - marks = Mark.createSet(marks) - const { value } = editor - const { annotations, document } = value - document.assertNode(path) - - editor.withoutNormalizing(() => { - for (const annotation of annotations.values()) { - const { start, end } = annotation - const isAtomic = editor.isAtomic(annotation) - - if (!isAtomic) { - continue - } - - if (!start.path.equals(path)) { - continue - } - - if ( - start.offset < offset && - (!end.path.equals(path) || end.offset > offset) - ) { - editor.removeAnnotation(annotation) - } - } - - editor.applyOperation({ - type: 'insert_text', - path, - offset, - text, - }) - - if (marks) { - editor.replaceMarksByPath(path, offset, text.length, marks) - } - }) -} - -/** - * Merge a node by `path` with the previous node. - * - * @param {Array} path - * @return {List} - */ - -Commands.mergeNodeByPath = (fn, editor) => path => { - path = Path.create(path) - const { value: { document } } = editor - const node = document.assertNode(path) - const prevPath = Path.decrement(path) - const prev = document.assertNode(prevPath) - const position = prev.object === 'text' ? prev.text.length : prev.nodes.size - - editor.applyOperation({ - type: 'merge_node', - path, - position, - target: null, - properties: { - type: node.type, - data: node.data, - }, - }) - - return prevPath -} - -Commands.mergeBlockByPath = (fn, editor) => path => { - path = Path.create(path) - - editor.withoutNormalizing(() => { - const { value: { document } } = editor - const node = document.assertNode(path) - let blockPath - - // HACK: this should not be required, but since `closest` doesn't match the - // current node first, we have to do this, since people can pass in the path - // of the block to merge. - if (node.object === 'block') { - blockPath = path - } else { - ;[, blockPath] = document.closestBlock(path) - } - - const prevBlock = document.previousBlock(path, { onlyLeaves: true }) - - if (!prevBlock) { - return - } - - const [, prevPath] = prevBlock - const newPath = Path.increment(prevPath) - const commonAncestorPath = Path.relate(blockPath, prevPath) - - editor.moveNodeByPath(blockPath, newPath) - path = editor.mergeNodeByPath(newPath) - - for (const [ancestor, ancestorPath] of document.ancestors(blockPath)) { - if (ancestor.object === 'block') { - if ( - ancestorPath.equals(commonAncestorPath) || - ancestor.nodes.size !== 1 - ) { - break - } - - editor.removeNodeByPath(ancestorPath) - } - } - }) - - return path -} - -/** - * Move a node by `path` to a new parent by `newParentPath` and `newIndex`. - * - * @param {Array} path - * @param {String} newParentPath - * @param {Number} newIndex - */ - -Commands.moveNodeByPath = (fn, editor) => (path, newPath, index) => { - path = Path.create(path) - newPath = Path.create(newPath) - - if (typeof index === 'number') { - warning( - false, - `As of slate@0.48 the \`editor.moveNodeByPath\` command takes \`(oldPath, newPath)\`, instead of a \`(oldPath, newParentPath, index)\`.` - ) - - newPath = newPath.concat(index) - index = null - } - - // It doesn't make sense to move a node into itself, so abort. - // TODO: This should probably throw an error instead? - if (Path.isAbove(path, newPath)) { - return editor - } - - if (Path.isEqual(path, newPath)) { - return editor - } - - editor.applyOperation({ - type: 'move_node', - path, - newPath, - }) -} - -/** - * Remove mark from text at `offset` and `length` in node by `path`. - * - * @param {Array} path - * @param {Number} offset - * @param {Number} length - * @param {Mark} mark - */ - -Commands.removeMarkByPath = (fn, editor) => (path, offset, length, mark) => { - path = Path.create(path) - mark = Mark.create(mark) - editor.removeMarksByPath(path, offset, length, [mark]) -} - -Commands.removeMarksByPath = (fn, editor) => (path, offset, length, marks) => { - path = Path.create(path) - marks = Mark.createSet(marks) - - if (!marks.size) { - return - } - - const { value } = editor - const { document } = value - const node = document.assertNode(path) - marks = marks.intersect(node.marks) - - if (!marks.size) { - return - } - - if (marks.intersect(node.marks).isEmpty()) { - return - } - - editor.withoutNormalizing(() => { - // If it ends before the end of the node, we'll need to split to create a new - // text with different marks. - if (offset + length < node.text.length) { - editor.splitNodeByPath(path, offset + length) - } - - // Same thing if it starts after the start. But in that case, we need to - // update our path and offset to point to the new start. - if (offset > 0) { - editor.splitNodeByPath(path, offset) - path = Path.increment(path) - offset = 0 - } - - marks.forEach(mark => { - editor.applyOperation({ - type: 'remove_mark', - path, - offset, - length, - mark, - }) - }) - }) -} - -/** - * Remove all `marks` from node by `path`. - * - * @param {Array} path - */ - -Commands.removeAllMarksByPath = (fn, editor) => path => { - path = Path.create(path) - const { state } = editor - const { document } = state - const node = document.assertNode(path) - - editor.withoutNormalizing(() => { - if (node.object === 'text') { - editor.removeMarksByPath(path, 0, node.text.length, node.marks) - return - } - - for (const [n, p] of node.texts()) { - const pth = path.concat(p) - editor.removeMarksByPath(pth, 0, n.text.length, n.marks) - } - }) -} - -/** - * Remove a node by `path`. - * - * @param {Array} path - */ - -Commands.removeNodeByPath = (fn, editor) => path => { - path = Path.create(path) - const { value } = editor - const { document } = value - const node = document.assertNode(path) - - editor.applyOperation({ - type: 'remove_node', - path, - node, - }) -} - -Commands.removeChildrenByPath = (fn, editor) => path => { - path = Path.create(path) - const { value: { document } } = editor - const node = document.assertNode(path) - - editor.withoutNormalizing(() => { - const { size } = node.nodes - const childPath = path.concat([0]) - - for (let i = 0; i < size; i++) { - editor.removeNodeByPath(childPath) - } - }) -} - -/** - * Remove text at `offset` and `length` in node by `path`. - * - * @param {Array} path - * @param {Number} offset - * @param {Number} length - */ - -Commands.removeTextByPath = (fn, editor) => (path, offset, length) => { - path = Path.create(path) - const { value } = editor - const { document, annotations } = value - const node = document.assertNode(path) - const text = node.text.slice(offset, offset + length) - - editor.withoutNormalizing(() => { - for (const annotation of annotations.values()) { - const { start, end } = annotation - const isAtomic = editor.isAtomic(annotation) - - if (!isAtomic) { - continue - } - - if (!start.path.equals(path)) { - continue - } - - if ( - start.offset < offset && - (!end.path.equals(path) || end.offset > offset) - ) { - editor.removeAnnotation(annotation) - } - } - - editor.applyOperation({ - type: 'remove_text', - path, - offset, - text, - }) - }) -} - -/** -`* Replace a `node` with another `node` - * - * @param {Array} path - * @param {Object|Node} node - */ - -Commands.replaceNodeByPath = (fn, editor) => (path, node) => { - path = Path.create(path) - node = Node.create(node) - - editor.withoutNormalizing(() => { - editor.removeNodeByPath(path) - editor.insertNodeByPath(path, node) - }) -} - -/** - * Replace a `length` of text at `offset` with new `text` and optional `marks`. - * - * @param {Array} path - * @param {Number} offset - * @param {Number} length - * @param {string} text - * @param {Set} marks (optional) - */ - -Commands.replaceTextByPath = (fn, editor) => ( - path, - offset, - length, - text, - marks -) => { - editor.withoutNormalizing(() => { - editor.removeTextByPath(path, offset, length) - editor.insertTextByPath(path, offset, text, marks) - }) -} - -/** - * Set `newProperties` on mark on text at `offset` and `length` in node by `path`. - * - * @param {Array} path - * @param {Number} offset - * @param {Number} length - * @param {Object|Mark} properties - * @param {Object} newProperties - */ - -Commands.setMarkByPath = (fn, editor) => ( - path, - offset, - length, - properties, - newProperties -) => { - path = Path.create(path) - properties = Mark.create(properties) - newProperties = Mark.createProperties(newProperties) - - const { value } = editor - const { document } = value - const node = document.assertNode(path) - - editor.withoutNormalizing(() => { - // If it ends before the end of the node, we'll need to split to create a new - // text with different marks. - if (offset + length < node.text.length) { - editor.splitNodeByPath(path, offset + length) - } - - // Same thing if it starts after the start. But in that case, we need to - // update our path and offset to point to the new start. - if (offset > 0) { - editor.splitNodeByPath(path, offset) - path = Path.increment(path) - offset = 0 - } - - editor.applyOperation({ - type: 'set_mark', - path, - properties, - newProperties, - }) - }) -} - -/** - * Set `properties` on a node by `path`. - * - * @param {Array} path - * @param {Object|String} newProperties - */ - -Commands.setNodeByPath = (fn, editor) => (path, newProperties) => { - path = Path.create(path) - newProperties = Node.createProperties(newProperties) - const { value } = editor - const { document } = value - const node = document.assertNode(path) - const prevProperties = pick(node, Object.keys(newProperties)) - - editor.applyOperation({ - type: 'set_node', - path, - properties: prevProperties, - newProperties, - }) -} - -/** - * Insert `text` at `offset` in node by `path`. - * - * @param {Array} path - * @param {String} text - * @param {Set} marks (optional) - */ - -Commands.setTextByPath = (fn, editor) => (path, text, marks) => { - path = Path.create(path) - const { value } = editor - const { document } = value - const node = document.assertNode(path) - const end = node.text.length - editor.replaceTextByPath(path, 0, end, text, marks) -} - -/** - * Split a node by `path` at `position`. - * - * @param {Array} path - * @param {Number} position - * @param {Object} options - */ - -Commands.splitNodeByPath = (fn, editor) => (path, position, options = {}) => { - path = Path.create(path) - const { target = null } = options - const { value } = editor - const { document } = value - const node = document.getDescendant(path) - - editor.applyOperation({ - type: 'split_node', - path, - position, - target, - properties: { - type: node.type, - data: node.data, - }, - }) - - return Path.increment(path) -} - -/** - * Split a node deeply down the tree by `path`, `textPath` and `textOffset`. - * - * @param {Array} path - * @param {Array} textPath - * @param {Number} textOffset - */ - -Commands.splitDescendantsByPath = (fn, editor) => ( - path, - textPath, - textOffset -) => { - warning( - false, - 'As of slate@0.48, the `editor.splitDescendantsByPath` command is deprecated. Use `editor.splitNodeAtPoint` instead.' - ) - - path = Path.create(path) - textPath = Path.create(textPath) - - if (path.equals(textPath)) { - return editor.splitNodeByPath(textPath, textOffset) - } - - const { value } = editor - const { document } = value - let index = textOffset - let lastPath = textPath - - editor.withoutNormalizing(() => { - editor.splitNodeByPath(textPath, textOffset) - - for (const [, ancestorPath] of document.ancestors(textPath)) { - const target = index - index = lastPath.last() + 1 - lastPath = ancestorPath - editor.splitNodeByPath(ancestorPath, index, { target }) - - if (ancestorPath.equals(path)) { - break - } - } - }) -} - -/** - * Unwrap content from an inline parent with `properties`. - * - * @param {Array} path - * @param {Object|String} properties - */ - -Commands.unwrapInlineByPath = (fn, editor) => (path, properties) => { - path = Path.create(path) - const range = editor.getRangeOfPath(path) - editor.unwrapInlineAtRange(range, properties) -} - -/** - * Unwrap content from a block parent with `properties`. - * - * @param {Array} path - * @param {Object|String} properties - */ - -Commands.unwrapBlockByPath = (fn, editor) => (path, properties) => { - path = Path.create(path) - const range = editor.getRangeOfPath(path) - editor.unwrapBlockAtRange(range, properties) -} - -/** - * Unwrap a single node from its parent. - * - * If the node is surrounded with siblings, its parent will be - * split. If the node is the only child, the parent is removed, and - * simply replaced by the node itself. Cannot unwrap a root node. - * - * @param {Array} path - */ - -Commands.unwrapNodeByPath = (fn, editor) => path => { - path = Path.create(path) - const { value } = editor - const { document } = value - document.assertNode(path) - - const parentPath = Path.lift(path) - const parent = document.assertNode(parentPath) - const index = path.last() - const parentIndex = parentPath.last() - const grandPath = Path.lift(parentPath) - const isFirst = index === 0 - const isLast = index === parent.nodes.size - 1 - - editor.withoutNormalizing(() => { - if (parent.nodes.size === 1) { - editor.moveNodeByPath(path, grandPath.concat(parentIndex + 1)) - editor.removeNodeByPath(parentPath) - } else if (isFirst) { - editor.moveNodeByPath(path, grandPath.concat(parentIndex)) - } else if (isLast) { - editor.moveNodeByPath(path, grandPath.concat(parentIndex + 1)) - } else { - let updatedPath = Path.increment(path, 1, parentPath.size - 1) - updatedPath = updatedPath.set(updatedPath.size - 1, 0) - editor.splitNodeByPath(parentPath, index) - editor.moveNodeByPath(updatedPath, grandPath.concat(parentIndex + 1)) - } - }) -} - -/** - * Unwrap all of the children of a node, by removing the node and replacing it - * with the children in the tree. - * - * @param {Array} path - */ - -Commands.unwrapChildrenByPath = (fn, editor) => path => { - path = Path.create(path) - const { value } = editor - const { document } = value - const node = document.assertNode(path) - const newPath = Path.increment(path) - const { nodes } = node - - editor.withoutNormalizing(() => { - nodes.reverse().forEach((child, i) => { - const childIndex = nodes.size - i - 1 - const childPath = path.push(childIndex) - editor.moveNodeByPath(childPath, newPath) - }) - - editor.removeNodeByPath(path) - }) -} - -/** - * Wrap a node in a block with `properties`. - * - * @param {Array} path - * @param {Block|Object|String} block - */ - -Commands.wrapBlockByPath = (fn, editor) => (path, block) => { - path = Path.create(path) - block = Block.create(block) - block = block.set('nodes', block.nodes.clear()) - const newPath = Path.increment(path) - - editor.withoutNormalizing(() => { - editor.insertNodeByPath(path, block) - editor.moveNodeByPath(newPath, path.concat(0)) - }) -} - -/** - * Wrap a node in an inline with `properties`. - * - * @param {Array} path - * @param {Block|Object|String} inline - */ - -Commands.wrapInlineByPath = (fn, editor) => (path, inline) => { - path = Path.create(path) - inline = Inline.create(inline) - inline = inline.set('nodes', inline.nodes.clear()) - const newPath = Path.increment(path) - - editor.withoutNormalizing(() => { - editor.insertNodeByPath(path, inline) - editor.moveNodeByPath(newPath, path.concat(0)) - }) -} - -/** - * Wrap a node by `path` with `node`. - * - * @param {Array} path - * @param {Node|Object} node - */ - -Commands.wrapNodeByPath = (fn, editor) => (path, node) => { - path = Path.create(path) - node = Node.create(node) - - if (node.object === 'block') { - editor.wrapBlockByPath(path, node) - } else if (node.object === 'inline') { - editor.wrapInlineByPath(path, node) - } -} - -/** - * Mix in `*ByKey` variants. - */ - -const COMMANDS = [ - 'addMark', - 'insertFragment', - 'insertNode', - 'insertText', - 'mergeNode', - 'removeAllMarks', - 'removeMark', - 'removeNode', - 'removeText', - 'replaceMarks', - 'replaceNode', - 'replaceText', - 'setMark', - 'setNode', - 'setText', - 'splitNode', - 'unwrapBlock', - 'unwrapChildren', - 'unwrapInline', - 'unwrapNode', - 'wrapBlock', - 'wrapInline', - 'wrapNode', -] - -for (const method of COMMANDS) { - Commands[`${method}ByKey`] = (fn, editor) => (key, ...args) => { - warning( - false, - `As of slate@0.48 the \`editor.${method}ByKey\` command is deprecated. Use the \`editor.${method}ByPath\` command instead.` - ) - - const { value } = editor - const { document } = value - const path = document.assertPath(key) - editor[`${method}ByPath`](path, ...args) - } -} - -// Moving nodes takes two keys, so it's slightly different. -Commands.moveNodeByKey = (fn, editor) => (key, newKey, ...args) => { - warning( - false, - `As of slate@0.48 the \`editor.moveNodeByKey\` command is deprecated. Use the \`editor.moveNodeByPath\` command instead.` - ) - - const { value } = editor - const { document } = value - const path = document.assertPath(key) - const newPath = document.assertPath(newKey) - editor.moveNodeByPath(path, newPath, ...args) -} - -// Splitting descendants takes two keys, so it's slightly different. -Commands.splitDescendantsByKey = (fn, editor) => (key, textKey, ...args) => { - warning( - false, - `As of slate@0.48 the \`editor.splitDescendantsByKey\` command is deprecated. Use the \`editor.splitDescendantsByPath\` command instead.` - ) - - const { value } = editor - const { document } = value - const path = document.assertPath(key) - const textPath = document.assertPath(textKey) - editor.splitDescendantsByPath(path, textPath, ...args) -} - -/** - * Export. - * - * @type {Object} - */ - -export default Commands diff --git a/packages/slate/src/commands/on-history.js b/packages/slate/src/commands/on-history.js deleted file mode 100644 index 59b3be93fc..0000000000 --- a/packages/slate/src/commands/on-history.js +++ /dev/null @@ -1,220 +0,0 @@ -import omit from 'lodash/omit' -import { List } from 'immutable' - -/** - * Commands. - * - * @type {Object} - */ - -const Commands = {} - -/** - * Save an `operation` into the history. - * - * @param {Object} operation - */ - -Commands.save = (fn, editor) => operation => { - const { operations, value } = editor - const { data } = value - let { save, merge } = editor.tmp - if (save === false || !isValidOperation(operation)) return - - let undos = data.get('undos') || List() - const lastBatch = undos.last() - const lastOperation = lastBatch && lastBatch.last() - - // If `merge` is non-commital, and this is not the first operation in a new - // editor, then merge, otherwise merge based on the last operation. - if (merge == null) { - if (operations.size !== 0) { - merge = true - } else { - merge = shouldMerge(operation, lastOperation) - } - } - - // If the `merge` flag is true, add the operation to the last batch. - if (merge && lastBatch) { - const batch = lastBatch.push(operation) - undos = undos.pop() - undos = undos.push(batch) - } else { - // Otherwise, create a new batch with the operation. - const batch = List([operation]) - undos = undos.push(batch) - } - - // Constrain the history to 100 entries for memory's sake. - if (undos.size > 100) { - undos = undos.takeLast(100) - } - - // Clear the redos and update the history. - editor.withoutSaving(() => { - const redos = List() - const newData = data.set('undos', undos).set('redos', redos) - editor.setData(newData) - }) -} - -/** - * Redo to the next value in the history. - * - */ - -Commands.redo = (fn, editor) => () => { - const { value } = editor - const { data } = value - let redos = data.get('redos') || List() - let undos = data.get('undos') || List() - const batch = redos.last() - if (!batch) return - - editor.withoutSaving(() => { - editor.withoutNormalizing(() => { - // Replay the batch of operations. - batch.forEach(op => { - const { type, newProperties } = op - - // When the operation mutates the selection, omit its `isFocused` value to - // prevent the editor focus from changing during redoing. - if (type === 'set_selection') { - op = op.set('newProperties', omit(newProperties, 'isFocused')) - } - - editor.applyOperation(op) - }) - - // Shift the next value into the undo stack. - redos = redos.pop() - undos = undos.push(batch) - const newData = data.set('undos', undos).set('redos', redos) - editor.setData(newData) - }) - }) -} - -/** - * Undo the previous operations in the history. - * - */ - -Commands.undo = (fn, editor) => () => { - const { value } = editor - const { data } = value - let redos = data.get('redos') || List() - let undos = data.get('undos') || List() - const batch = undos.last() - if (!batch) return - - editor.withoutSaving(() => { - editor.withoutNormalizing(() => { - // Replay the inverse of the previous operations. - batch - .slice() - .reverse() - .map(op => op.invert()) - .forEach(inverse => { - const { type, newProperties } = inverse - - // When the operation mutates the selection, omit its `isFocused` value to - // prevent the editor focus from changing during undoing. - if (type === 'set_selection') { - inverse = inverse.set( - 'newProperties', - omit(newProperties, 'isFocused') - ) - } - - editor.applyOperation(inverse) - }) - - // Shift the previous operations into the redo stack. - redos = redos.push(batch) - undos = undos.pop() - const newData = data.set('undos', undos).set('redos', redos) - editor.setData(newData) - }) - }) -} - -/** - * Apply a series of changes inside a synchronous `fn`, without merging any of - * the new operations into previous save point in the history. - * - * @param {Function} run - */ - -Commands.withoutMerging = (fn, editor) => run => { - const value = editor.tmp.merge - editor.tmp.merge = false - run(editor) - editor.tmp.merge = value -} - -/** - * Apply a series of changes inside a synchronous `fn`, without saving any of - * their operations into the history. - * - * @param {Function} run - */ - -Commands.withoutSaving = (fn, editor) => run => { - const value = editor.tmp.save - editor.tmp.save = false - run(editor) - editor.tmp.save = value -} - -/** - * Check whether to merge a new operation `o` into the previous operation `p`. - * - * @param {Object} o - * @param {Object} p - * @return {Boolean} - */ - -function shouldMerge(o, p) { - if (!p) return false - - const merge = - (o.type === 'set_selection' && p.type === 'set_selection') || - (o.type === 'insert_text' && - p.type === 'insert_text' && - o.offset === p.offset + p.text.length && - o.path.equals(p.path)) || - (o.type === 'remove_text' && - p.type === 'remove_text' && - o.offset + o.text.length === p.offset && - o.path.equals(p.path)) - - return merge -} - -/** - * Check weather an operation needs to be saved to the history - * @param {Object} o - operation - * @returns {Boolean} - */ - -function isValidOperation(o) { - if (o.type === 'set_selection') { - const { isFocused, anchor, focus } = o.newProperties - - // this is blur/focus operation, dont need to store it into the history - if (isFocused !== undefined && !anchor && !focus) { - return false - } - } - return true -} - -/** - * Export. - * - * @type {Object} - */ - -export default Commands diff --git a/packages/slate/src/commands/on-selection.js b/packages/slate/src/commands/on-selection.js deleted file mode 100644 index f4f28cb1ee..0000000000 --- a/packages/slate/src/commands/on-selection.js +++ /dev/null @@ -1,2044 +0,0 @@ -import { is } from 'immutable' -import warning from 'tiny-warning' -import pick from 'lodash/pick' - -import Selection from '../models/selection' -import TextUtils from '../utils/text-utils' - -const Commands = {} - -/** - * Get the next point by `n`. - * - * @param {Point} point - * @param {Number} n - * @return {Point} - */ - -function getNextPoint(editor, point, n) { - for (let i = 0; i < n; i++) { - point = editor.getNextPoint(point) - } - - return point -} - -/** - * Get the previous point by `n`. - * - * @param {Point} point - * @param {Number} n - * @return {Point} - */ - -function getPreviousPoint(editor, point, n) { - for (let i = 0; i < n; i++) { - point = editor.getPreviousPoint(point) - } - - return point -} - -/** - * Blur the selection. - */ - -Commands.blur = (fn, editor) => () => { - editor.select({ isFocused: false }) -} - -/** - * Deselect the selection. - */ - -Commands.deselect = (fn, editor) => () => { - editor.select(Selection.create()) -} - -/** - * Focus the selection. - */ - -Commands.focus = (fn, editor) => () => { - editor.select({ isFocused: true }) -} - -/** - * Flip the selection's anchor and focus points. - */ - -Commands.flip = (fn, editor) => () => { - const { value: { selection } } = editor - const range = selection.flip() - editor.select(range) -} - -/** - * Move the selection's anchor point backwards by `n`. - * - * @param {Number} n - */ - -Commands.moveAnchorBackward = (fn, editor) => (n = 1) => { - const { value: { selection } } = editor - const point = getPreviousPoint(editor, selection.anchor, n) - editor.setAnchor(point) -} - -/** - * Move the selection's anchor point forwards by `n`. - * - * @param {Number} n - */ - -Commands.moveAnchorForward = (fn, editor) => (n = 1) => { - const { value: { selection } } = editor - const point = getNextPoint(editor, selection.anchor, n) - editor.setAnchor(point) -} - -/** - * Move the selection's anchor point to a specific `path` and `offset`. - * - * @param {Path} path - * @param {Number} offset - */ - -Commands.moveAnchorTo = (fn, editor) => (path, offset) => { - const { value: { selection } } = editor - const range = selection.moveAnchorTo(path, offset) - editor.select(range) -} - -/** - * Move the selection's anchor point to the end of the block it's in. - */ - -Commands.moveAnchorToEndOfBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestBlock(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the node at `path`. - */ - -Commands.moveAnchorToEndOfPath = (fn, editor) => path => { - const { value: { document } } = editor - const entry = document.lastText({ path }) - - if (entry) { - const [targetNode, targetPath] = entry - editor.moveAnchorTo(targetPath, targetNode.text.length) - } -} - -/** - * Move the selection's anchor point to the end of the nearest inline. - */ - -Commands.moveAnchorToEndOfInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestInline(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the document. - */ - -Commands.moveAnchorToEndOfDocument = (fn, editor) => () => { - const { value: { document } } = editor - const entry = document.lastText() - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the next block. - */ - -Commands.moveAnchorToEndOfNextBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextBlock(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the next inline. - */ - -Commands.moveAnchorToEndOfNextInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextInline(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the next text node. - */ - -Commands.moveAnchorToEndOfNextText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextText(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the previous block. - */ - -Commands.moveAnchorToEndOfPreviousBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousBlock(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the previous inline. - */ - -Commands.moveAnchorToEndOfPreviousInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousInline(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the previous text node. - */ - -Commands.moveAnchorToEndOfPreviousText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousText(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's anchor point to the end of the text node it's in. - */ - -Commands.moveAnchorToEndOfText = (fn, editor) => () => { - const { value: { selection } } = editor - editor.moveAnchorToEndOfPath(selection.anchor.path) -} - -/** - * Move the selection's anchor point to the start of the block it's in. - */ - -Commands.moveAnchorToStartOfBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestBlock(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the node at `path`. - */ - -Commands.moveAnchorToStartOfPath = (fn, editor) => path => { - const { value: { document } } = editor - const entry = document.lastText({ path }) - - if (entry) { - const [, targetPath] = entry - editor.moveAnchorTo(targetPath, 0) - } -} - -/** - * Move the selection's anchor point to the start of the nearest inline. - */ - -Commands.moveAnchorToStartOfInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestInline(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the document. - */ - -Commands.moveAnchorToStartOfDocument = (fn, editor) => () => { - const { value: { document } } = editor - const entry = document.firstText() - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the next block. - */ - -Commands.moveAnchorToStartOfNextBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextBlock(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the next inline. - */ - -Commands.moveAnchorToStartOfNextInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextInline(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the next text node. - */ - -Commands.moveAnchorToStartOfNextText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextText(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the previous block. - */ - -Commands.moveAnchorToStartOfPreviousBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousBlock(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the previous inline. - */ - -Commands.moveAnchorToStartOfPreviousInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousInline(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the previous text node. - */ - -Commands.moveAnchorToStartOfPreviousText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousText(selection.anchor.path) - - if (entry) { - const [, path] = entry - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's anchor point to the start of the text node it's in. - */ - -Commands.moveAnchorToStartOfText = (fn, editor) => () => { - const { value: { selection } } = editor - editor.moveAnchorToStartOfPath(selection.anchor.path) -} - -/** - * Move the selection's anchor point backward to the edge of the nearest word. - */ - -Commands.moveAnchorWordBackward = (fn, editor) => () => { - const { value: { selection } } = editor - const point = editor.getPreviousWordPoint(selection.anchor) - editor.setAnchor(point) -} - -/** - * Move the selection's anchor point forward to the edge of the nearest word. - */ - -Commands.moveAnchorWordForward = (fn, editor) => () => { - const { value: { selection } } = editor - const point = editor.getNextWordPoint(selection.anchor) - editor.setAnchor(point) -} - -/** - * Move the selection backward by `n`. - * - * @param {Number} n - */ - -Commands.moveBackward = (fn, editor) => (n = 1) => { - if (n === 0) return - const { value } = editor - const { document, selection } = value - const { start } = selection - const startBlock = document.getClosestBlock(start.key) - const o = startBlock.getOffset(start.key) - const offset = o + start.offset - const { text } = startBlock - const charsOffset = TextUtils.getCharOffsetBackward(text, offset, n) - editor.moveAnchorBackward(charsOffset) - editor.moveFocusBackward(charsOffset) -} - -/** - * Move the selection's end point backwards by `n`. - * - * @param {Number} n - */ - -Commands.moveEndBackward = (fn, editor) => (n = 1) => { - if (editor.value.selection.isForward) { - editor.moveFocusBackward(n) - } else { - editor.moveAnchorBackward(n) - } -} - -/** - * Move the selection's end point forwards by `n`. - * - * @param {Number} n - */ - -Commands.moveEndForward = (fn, editor) => (n = 1) => { - if (editor.value.selection.isForward) { - editor.moveFocusForward(n) - } else { - editor.moveAnchorForward() - } -} - -/** - * Move the selection's end point to a specific `path` and `offset`. - * - * @param {Array} path - * @param {Number} offset - */ - -Commands.moveEndTo = (fn, editor) => (path, offset) => { - const { value: { selection } } = editor - const range = selection.moveEndTo(path, offset) - editor.select(range) -} - -/** - * Move the selection's end point to the end of the block it's in. - */ - -Commands.moveEndToEndOfBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfBlock() - } else { - editor.moveAnchorToEndOfBlock() - } -} - -/** - * Move the selection's end point to the end of the document. - */ - -Commands.moveEndToEndOfDocument = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfDocument() - } else { - editor.moveAnchorToEndOfDocument() - } -} - -/** - * Move the selection's end point to the end of the nearest inline. - */ - -Commands.moveEndToEndOfInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfInline() - } else { - editor.moveAnchorToEndOfInline() - } -} - -/** - * Move the selection's end point to the end of the next block. - */ - -Commands.moveEndToEndOfNextBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfNextBlock() - } else { - editor.moveAnchorToEndOfNextBlock() - } -} - -/** - * Move the selection's end point to the end of the next inline. - */ - -Commands.moveEndToEndOfNextInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfNextInline() - } else { - editor.moveAnchorToEndOfNextInline() - } -} - -/** - * Move the selection's end point to the end of the next text node. - */ - -Commands.moveEndToEndOfNextText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfNextText() - } else { - editor.moveAnchorToEndOfNextText() - } -} - -/** - * Move the selection's end point to the end of the node at `path`. - */ - -Commands.moveEndToEndOfPath = (fn, editor) => path => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfPath(path) - } else { - editor.moveAnchorToEndOfPath(path) - } -} - -/** - * Move the selection's end point to the end of the previous block. - */ - -Commands.moveEndToEndOfPreviousBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfPreviousBlock() - } else { - editor.moveAnchorToEndOfPreviousBlock() - } -} - -/** - * Move the selection's end point to the end of the previous inline. - */ - -Commands.moveEndToEndOfPreviousInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfPreviousInline() - } else { - editor.moveAnchorToEndOfPreviousInline() - } -} - -/** - * Move the selection's end point to the end of the previous text node. - */ - -Commands.moveEndToEndOfPreviousText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfPreviousText() - } else { - editor.moveAnchorToEndOfPreviousText() - } -} - -/** - * Move the selection's end point to the end of the text node it's in. - */ - -Commands.moveEndToEndOfText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToEndOfText() - } else { - editor.moveAnchorToEndOfText() - } -} - -/** - * Move the selection's end point to the start of the block it's in. - */ - -Commands.moveEndToStartOfBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfBlock() - } else { - editor.moveAnchorToStartOfBlock() - } -} - -/** - * Move the selection's end point to the start of the document. - */ - -Commands.moveEndToStartOfDocument = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfDocument() - } else { - editor.moveAnchorToStartOfDocument() - } -} - -/** - * Move the selection's end point to the start of the nearest inline. - */ - -Commands.moveEndToStartOfInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfInline() - } else { - editor.moveAnchorToStartOfInline() - } -} - -/** - * Move the selection's end point to the start of the next block. - */ - -Commands.moveEndToStartOfNextBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfNextBlock() - } else { - editor.moveAnchorToStartOfNextBlock() - } -} - -/** - * Move the selection's end point to the start of the next inline. - */ - -Commands.moveEndToStartOfNextInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfNextInline() - } else { - editor.moveAnchorToStartOfNextInline() - } -} - -/** - * Move the selection's end point to the start of the next text node. - */ - -Commands.moveEndToStartOfNextText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfNextText() - } else { - editor.moveAnchorToStartOfNextText() - } -} - -/** - * Move the selection's end point to the start of the node at `path`. - */ - -Commands.moveEndToStartOfPath = (fn, editor) => path => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfPath(path) - } else { - editor.moveAnchorToStartOfPath(path) - } -} - -/** - * Move the selection's end point to the start of the previous block. - */ - -Commands.moveEndToStartOfPreviousBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfPreviousBlock() - } else { - editor.moveAnchorToStartOfPreviousBlock() - } -} - -/** - * Move the selection's end point to the start of the previous inline. - */ - -Commands.moveEndToStartOfPreviousInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfPreviousInline() - } else { - editor.moveAnchorToStartOfPreviousInline() - } -} - -/** - * Move the selection's end point to the start of the previous text node. - */ - -Commands.moveEndToStartOfPreviousText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfPreviousText() - } else { - editor.moveAnchorToStartOfPreviousText() - } -} - -/** - * Move the selection's end point to the start of the text node it's in. - */ - -Commands.moveEndToStartOfText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveFocusToStartOfText() - } else { - editor.moveAnchorToStartOfText() - } -} - -/** - * Move the selection's end point backward to the edge of the nearest word. - */ - -Commands.moveEndWordBackward = (fn, editor) => (...args) => { - if (editor.value.selection.isForward) { - editor.moveFocusWordBackward() - } else { - editor.moveAnchorWordBackward() - } -} - -/** - * Move the selection's end point forward to the edge of the nearest word. - */ - -Commands.moveEndWordForward = (fn, editor) => (...args) => { - if (editor.value.selection.isForward) { - editor.moveFocusWordForward() - } else { - editor.moveAnchorWordForward() - } -} - -/** - * Move the selection's focus point backwards by `n`. - * - * @param {Number} n - */ - -Commands.moveFocusBackward = (fn, editor) => (n = 1) => { - const { value: { selection } } = editor - const point = getPreviousPoint(editor, selection.focus, n) - editor.setFocus(point) -} - -/** - * Move the selection's focus point forwards by `n`. - * - * @param {Number} n - */ - -Commands.moveFocusForward = (fn, editor) => (n = 1) => { - const { value: { selection } } = editor - const point = getNextPoint(editor, selection.focus, n) - editor.setFocus(point) -} - -/** - * Move the selection's focus point to a specific `path` and `offset`. - * - * @param {Path} path - * @param {Number} offset - */ - -Commands.moveFocusTo = (fn, editor) => (path, offset) => { - const { value: { selection } } = editor - const range = selection.moveFocusTo(path, offset) - editor.select(range) -} - -/** - * Move the selection's focus point to the end of the block it's in. - */ - -Commands.moveFocusToEndOfBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestBlock(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the node at `path`. - */ - -Commands.moveFocusToEndOfPath = (fn, editor) => path => { - const { value: { document } } = editor - const entry = document.lastText({ path }) - - if (entry) { - const [targetNode, targetPath] = entry - editor.moveFocusTo(targetPath, targetNode.text.length) - } -} - -/** - * Move the selection's focus point to the end of the nearest inline. - */ - -Commands.moveFocusToEndOfInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestInline(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the document. - */ - -Commands.moveFocusToEndOfDocument = (fn, editor) => () => { - const { value: { document } } = editor - const entry = document.lastText() - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the next block. - */ - -Commands.moveFocusToEndOfNextBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextBlock(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the next inline. - */ - -Commands.moveFocusToEndOfNextInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextInline(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the next text node. - */ - -Commands.moveFocusToEndOfNextText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextText(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the previous block. - */ - -Commands.moveFocusToEndOfPreviousBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousBlock(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the previous inline. - */ - -Commands.moveFocusToEndOfPreviousInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousInline(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the previous text node. - */ - -Commands.moveFocusToEndOfPreviousText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousText(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's focus point to the end of the text node it's in. - */ - -Commands.moveFocusToEndOfText = (fn, editor) => () => { - const { value: { selection } } = editor - editor.moveFocusToEndOfPath(selection.focus.path) -} - -/** - * Move the selection's focus point to the start of the block it's in. - */ - -Commands.moveFocusToStartOfBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestBlock(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the node at `path`. - */ - -Commands.moveFocusToStartOfPath = (fn, editor) => path => { - const { value: { document } } = editor - const entry = document.lastText({ path }) - - if (entry) { - const [, targetPath] = entry - editor.moveFocusTo(targetPath, 0) - } -} - -/** - * Move the selection's focus point to the start of the nearest inline. - */ - -Commands.moveFocusToStartOfInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.closestInline(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the document. - */ - -Commands.moveFocusToStartOfDocument = (fn, editor) => () => { - const { value: { document } } = editor - const entry = document.firstText() - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the next block. - */ - -Commands.moveFocusToStartOfNextBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextBlock(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the next inline. - */ - -Commands.moveFocusToStartOfNextInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextInline(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the next text node. - */ - -Commands.moveFocusToStartOfNextText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.nextText(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the previous block. - */ - -Commands.moveFocusToStartOfPreviousBlock = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousBlock(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the previous inline. - */ - -Commands.moveFocusToStartOfPreviousInline = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousInline(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the previous text node. - */ - -Commands.moveFocusToStartOfPreviousText = (fn, editor) => () => { - const { value: { document, selection } } = editor - const entry = document.previousText(selection.focus.path) - - if (entry) { - const [, path] = entry - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's focus point to the start of the text node it's in. - */ - -Commands.moveFocusToStartOfText = (fn, editor) => () => { - const { value: { selection } } = editor - editor.moveFocusToStartOfPath(selection.focus.path) -} - -/** - * Move the selection's focus point backward to the edge of the nearest word. - */ - -Commands.moveFocusWordBackward = (fn, editor) => () => { - const { value: { selection } } = editor - const point = editor.getPreviousWordPoint(selection.focus) - editor.setFocus(point) -} - -/** - * Move the selection's focus point forward to the edge of the nearest word. - */ - -Commands.moveFocusWordForward = (fn, editor) => () => { - const { value: { selection } } = editor - const point = editor.getNextWordPoint(selection.focus) - editor.setFocus(point) -} - -/** - * Move the selection's points each forward by one character. - */ - -Commands.moveForward = (fn, editor) => (n = 1) => { - if (n === 0) return - const { value } = editor - const { document, selection } = value - const { start } = selection - const startBlock = document.getClosestBlock(start.path) - const o = startBlock.getOffset(start.key) - const offset = o + start.offset - const { text } = startBlock - const charsOffset = TextUtils.getCharOffsetForward(text, offset, n) - editor.moveAnchorForward(charsOffset) - editor.moveFocusForward(charsOffset) -} - -/** - * Move the selection's start point backwards by `n`. - * - * @param {Number} n - */ - -Commands.moveStartBackward = (fn, editor) => (n = 1) => { - if (editor.value.selection.isForward) { - editor.moveAnchorBackward(n) - } else { - editor.moveFocusBackward(n) - } -} - -/** - * Move the selection's start point forwards by `n`. - * - * @param {Number} n - */ - -Commands.moveStartForward = (fn, editor) => (n = 1) => { - if (editor.value.selection.isForward) { - editor.moveAnchorForward(n) - } else { - editor.moveFocusForward(n) - } -} - -/** - * Move the selection's start point to a specific `path` and `offset`. - * - * @param {Array} path - * @param {Number} offset - */ - -Commands.moveStartTo = (fn, editor) => (path, offset) => { - const { value: { selection } } = editor - const range = selection.moveStartTo(path, offset) - editor.select(range) -} - -/** - * Move the selection's start point to the end of the block it's in. - */ - -Commands.moveStartToEndOfBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfBlock() - } else { - editor.moveFocusToEndOfBlock() - } -} - -/** - * Move the selection's start point to the end of the document. - */ - -Commands.moveStartToEndOfDocument = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfDocument() - } else { - editor.moveFocusToEndOfDocument() - } -} - -/** - * Move the selection's start point to the end of the nearest inline. - */ - -Commands.moveStartToEndOfInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfInline() - } else { - editor.moveFocusToEndOfInline() - } -} - -/** - * Move the selection's start point to the end of the next block. - */ - -Commands.moveStartToEndOfNextBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfNextBlock() - } else { - editor.moveFocusToEndOfNextBlock() - } -} - -/** - * Move the selection's start point to the end of the next inline. - */ - -Commands.moveStartToEndOfNextInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfNextInline() - } else { - editor.moveFocusToEndOfNextInline() - } -} - -/** - * Move the selection's start point to the end of the next text node. - */ - -Commands.moveStartToEndOfNextText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfNextText() - } else { - editor.moveFocusToEndOfNextText() - } -} - -/** - * Move the selection's start point to the end of the node at `path`. - */ - -Commands.moveStartToEndOfPath = (fn, editor) => path => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfPath(path) - } else { - editor.moveFocusToEndOfPath(path) - } -} - -/** - * Move the selection's start point to the end of the previous block. - */ - -Commands.moveStartToEndOfPreviousBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfPreviousBlock() - } else { - editor.moveFocusToEndOfPreviousBlock() - } -} - -/** - * Move the selection's start point to the end of the previous inline. - */ - -Commands.moveStartToEndOfPreviousInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfPreviousInline() - } else { - editor.moveFocusToEndOfPreviousInline() - } -} - -/** - * Move the selection's start point to the end of the previous text node. - */ - -Commands.moveStartToEndOfPreviousText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfPreviousText() - } else { - editor.moveFocusToEndOfPreviousText() - } -} - -/** - * Move the selection's start point to the end of the text node it's in. - */ - -Commands.moveStartToEndOfText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToEndOfText() - } else { - editor.moveFocusToEndOfText() - } -} - -/** - * Move the selection's start point to the start of the block it's in. - */ - -Commands.moveStartToStartOfBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfBlock() - } else { - editor.moveFocusToStartOfBlock() - } -} - -/** - * Move the selection's start point to the start of the document. - */ - -Commands.moveStartToStartOfDocument = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfDocument() - } else { - editor.moveFocusToStartOfDocument() - } -} - -/** - * Move the selection's start point to the start of the nearest inline. - */ - -Commands.moveStartToStartOfInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfInline() - } else { - editor.moveFocusToStartOfInline() - } -} - -/** - * Move the selection's start point to the start of the next block. - */ - -Commands.moveStartToStartOfNextBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfNextBlock() - } else { - editor.moveFocusToStartOfNextBlock() - } -} - -/** - * Move the selection's start point to the start of the next inline. - */ - -Commands.moveStartToStartOfNextInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfNextInline() - } else { - editor.moveFocusToStartOfNextInline() - } -} - -/** - * Move the selection's start point to the start of the next text node. - */ - -Commands.moveStartToStartOfNextText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfNextText() - } else { - editor.moveFocusToStartOfNextText() - } -} - -/** - * Move the selection's start point to the start of the node at `path`. - */ - -Commands.moveStartToStartOfPath = (fn, editor) => path => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfPath(path) - } else { - editor.moveFocusToStartOfPath(path) - } -} - -/** - * Move the selection's start point to the start of the previous block. - */ - -Commands.moveStartToStartOfPreviousBlock = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfPreviousBlock() - } else { - editor.moveFocusToStartOfPreviousBlock() - } -} - -/** - * Move the selection's start point to the start of the previous inline. - */ - -Commands.moveStartToStartOfPreviousInline = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfPreviousInline() - } else { - editor.moveFocusToStartOfPreviousInline() - } -} - -/** - * Move the selection's start point to the start of the previous text node. - */ - -Commands.moveStartToStartOfPreviousText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfPreviousText() - } else { - editor.moveFocusToStartOfPreviousText() - } -} - -/** - * Move the selection's start point to the start of the text node it's in. - */ - -Commands.moveStartToStartOfText = (fn, editor) => () => { - if (editor.value.selection.isForward) { - editor.moveAnchorToStartOfText() - } else { - editor.moveFocusToStartOfText() - } -} - -/** - * Move the selection's start point backward to the edge of the nearest word. - */ - -Commands.moveStartWordBackward = (fn, editor) => (...args) => { - if (editor.value.selection.isForward) { - editor.moveAnchorWordBackward() - } else { - editor.moveFocusWordBackward() - } -} - -/** - * Move the selection's start point forward to the edge of the nearest word. - */ - -Commands.moveStartWordForward = (fn, editor) => (...args) => { - if (editor.value.selection.isForward) { - editor.moveAnchorWordForward() - } else { - editor.moveFocusWordForward() - } -} - -/** - * Move the cursor to a specific `path` and `offset`. - * - * @param {Array} path - * @param {Number} offset - */ - -Commands.moveTo = (fn, editor) => (path, offset) => { - const { value: { selection } } = editor - const range = selection.moveTo(path, offset) - editor.select(range) -} - -/** - * Collapse the cursor to the selection's anchor point. - */ - -Commands.moveToAnchor = (fn, editor) => () => { - const { value: { selection } } = editor - const range = selection.moveToAnchor() - editor.select(range) -} - -/** - * Collapse the cursor to the selection's end point. - */ - -Commands.moveToEnd = (fn, editor) => () => { - const { value: { selection } } = editor - const range = selection.moveToEnd() - editor.select(range) -} - -/** - * Collapse the cursor to the end of the current block. - */ - -Commands.moveToEndOfBlock = (fn, editor) => () => { - editor.moveEndToEndOfBlock() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the end of the document. - */ - -Commands.moveToEndOfDocument = (fn, editor) => () => { - editor.moveEndToEndOfDocument() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the end of the current inline. - */ - -Commands.moveToEndOfInline = (fn, editor) => () => { - editor.moveEndToEndOfInline() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the end of the next block. - */ - -Commands.moveToEndOfNextBlock = (fn, editor) => () => { - editor.moveEndToEndOfNextBlock() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the end of the next inline. - */ - -Commands.moveToEndOfNextInline = (fn, editor) => () => { - editor.moveEndToEndOfNextInline() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the end of the next text node. - */ - -Commands.moveToEndOfNextText = (fn, editor) => () => { - editor.moveEndToEndOfNextText() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the end of the node at `path`. - * - * @param {Editor} - * @param {Array} path - */ - -Commands.moveToEndOfPath = (fn, editor) => path => { - editor.moveAnchorToEndOfPath(path) - editor.moveToAnchor() -} - -/** - * Collapse the cursor to the end of the previous block. - */ - -Commands.moveToEndOfPreviousBlock = (fn, editor) => () => { - editor.moveStartToEndOfPreviousBlock() - editor.moveToStart() -} - -/** - * Collapse the cursor to the end of the previous inline. - */ - -Commands.moveToEndOfPreviousInline = (fn, editor) => () => { - editor.moveStartToEndOfPreviousInline() - editor.moveToStart() -} - -/** - * Collapse the cursor to the end of the previous text node. - */ - -Commands.moveToEndOfPreviousText = (fn, editor) => () => { - editor.moveStartToEndOfPreviousText() - editor.moveToStart() -} - -/** - * Collapse the cursor to the end of the current text node. - */ - -Commands.moveToEndOfText = (fn, editor) => () => { - editor.moveEndToEndOfText() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the selection's focus point. - */ - -Commands.moveToFocus = (fn, editor) => () => { - const { value: { selection } } = editor - const range = selection.moveToFocus() - editor.select(range) -} - -/** - * Move the selection's anchor and focus points to the start and end of the - * document, respectively. - */ - -Commands.moveToRangeOfDocument = (fn, editor) => () => { - editor.moveAnchorToStartOfDocument() - editor.moveFocusToEndOfDocument() -} - -/** - * Move the selection's anchor and focus points to the start and end of the - * current block, respectively. - */ - -Commands.moveToRangeOfBlock = (fn, editor) => () => { - editor.moveToStart() - editor.moveAnchorToStartOfBlock() - editor.moveFocusToEndOfBlock() -} - -/** - * Move the selection's anchor and focus points to the start and end of the - * current text node, respectively. - */ - -Commands.moveToRangeOfInline = (fn, editor) => () => { - editor.moveToStart() - editor.moveAnchorToStartOfText() - editor.moveFocusToEndOfText() -} - -/** - * Collapse the cursor to the end of the node at `path`. - * - * @param {Editor} - * @param {Array} path - */ - -Commands.moveToRangeOfPath = (fn, editor) => path => { - editor.moveAnchorToStartOfPath(path) - editor.moveFocusToEndOfPath(path) -} - -/** - * Collapse the cursor to the selection's start point. - */ - -Commands.moveToStart = (fn, editor) => () => { - const { value: { selection } } = editor - const range = selection.moveToStart() - editor.select(range) -} - -/** - * Collapse the cursor to the start of the current block. - */ - -Commands.moveToStartOfBlock = (fn, editor) => () => { - editor.moveStartToStartOfBlock() - editor.moveToStart() -} - -/** - * Collapse the cursor to the start of the document. - */ - -Commands.moveToStartOfDocument = (fn, editor) => () => { - editor.moveStartToStartOfDocument() - editor.moveToStart() -} - -/** - * Collapse the cursor to the start of the current inline. - */ - -Commands.moveToStartOfInline = (fn, editor) => () => { - editor.moveStartToStartOfInline() - editor.moveToStart() -} - -/** - * Collapse the cursor to the start of the next block. - */ - -Commands.moveToStartOfNextBlock = (fn, editor) => () => { - editor.moveEndToStartOfNextBlock() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the start of the next inline. - */ - -Commands.moveToStartOfNextInline = (fn, editor) => () => { - editor.moveEndToStartOfNextInline() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the start of the next text node. - */ - -Commands.moveToStartOfNextText = (fn, editor) => () => { - editor.moveEndToStartOfNextText() - editor.moveToEnd() -} - -/** - * Collapse the cursor to the start of the node at `path`. - * - * @param {Array} path - */ - -Commands.moveToStartOfPath = (fn, editor) => path => { - editor.moveAnchorToStartOfPath(path) - editor.moveToAnchor() -} - -/** - * Collapse the cursor to the start of the previous block. - */ - -Commands.moveToStartOfPreviousBlock = (fn, editor) => () => { - editor.moveStartToStartOfPreviousBlock() - editor.moveToStart() -} - -/** - * Collapse the cursor to the start of the previous inline. - */ - -Commands.moveToStartOfPreviousInline = (fn, editor) => () => { - editor.moveStartToStartOfPreviousInline() - editor.moveToStart() -} - -/** - * Collapse the cursor to the start of the previous text node. - */ - -Commands.moveToStartOfPreviousText = (fn, editor) => () => { - editor.moveStartToStartOfPreviousText() - editor.moveToStart() -} - -/** - * Collapse the cursor to the start of the current text node. - */ - -Commands.moveToStartOfText = (fn, editor) => () => { - editor.moveStartToStartOfText() - editor.moveToStart() -} - -/** - * Move the selection's points each backward by `n` words. - * - * @param {Number} n - */ - -Commands.moveWordBackward = (fn, editor) => n => { - editor.moveAnchorWordBackward(n) - editor.moveFocusWordBackward(n) -} - -/** - * Move the selection's points each forward by `n` words. - * - * @param {Number} n - */ - -Commands.moveWordForward = (fn, editor) => n => { - editor.moveAnchorWordForward(n) - editor.moveFocusWordForward(n) -} - -/** - * Set new `properties` on the selection. - * - * @param {Object} properties - * @param {Object} options - */ - -Commands.select = (fn, editor) => (properties, options = {}) => { - properties = Selection.createProperties(properties) - const { snapshot = false } = options - const { value } = editor - const { document, selection } = value - const newProperties = {} - let next = selection.setProperties(properties) - next = document.resolveSelection(next) - - // Re-compute the properties, to ensure that we get their normalized values. - properties = pick(next, Object.keys(properties)) - - // Remove any properties that are already equal to the current selection. And - // create a dictionary of the previous values for all of the properties that - // are being changed, for the inverse operation. - for (const k in properties) { - if (snapshot === true || !is(properties[k], selection[k])) { - newProperties[k] = properties[k] - } - } - - // If the selection moves, clear any marks, unless the new selection - // properties change the marks in some way. - if ( - selection.marks && - !newProperties.marks && - (newProperties.anchor || newProperties.focus) - ) { - newProperties.marks = null - } - - // If there are no new properties to set, abort to avoid extra operations. - if (Object.keys(newProperties).length === 0) { - return - } - - // TODO: for some reason toJSON() is required here (it breaks selections between blocks)? - 2018-10-10 - const prevProperties = pick(selection.toJSON(), Object.keys(newProperties)) - - editor.applyOperation( - { - type: 'set_selection', - value, - properties: prevProperties, - newProperties, - }, - snapshot ? { skip: false, merge: false } : {} - ) -} - -/** - * Set the selection's anchor point to the return value of `fn`. - * - * @param {Function} fn - */ - -Commands.setAnchor = (fn, editor) => value => { - const { value: { selection } } = editor - const range = selection.setAnchor(value) - editor.select(range) -} - -/** - * Set the selection's end point to the return value of `fn`. - * - * @param {Function} fn - */ - -Commands.setEnd = (fn, editor) => value => { - const { value: { selection } } = editor - const range = selection.setEnd(value) - editor.select(range) -} - -/** - * Set the selection's focus point to the return value of `fn`. - * - * @param {Function} fn - */ - -Commands.setFocus = (fn, editor) => value => { - const { value: { selection } } = editor - const range = selection.setFocus(value) - editor.select(range) -} - -/** - * Set the selection's start point to the return value of `fn`. - * - * @param {Function} fn - */ - -Commands.setStart = (fn, editor) => value => { - const { value: { selection } } = editor - const range = selection.setStart(value) - editor.select(range) -} - -/** - * HACK: Snapshot the selection, saving an entry in the history. - */ - -Commands.snapshotSelection = (fn, editor) => () => { - editor.withoutMerging(() => { - editor.select(editor.value.selection, { snapshot: true }) - }) -} - -/** - * Deprecated. - */ - -Commands.moveAnchorToEndOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveAnchorToEndOfNode(node) command is deprecated. Use the `editor.moveAnchorToEndOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveAnchorToEndOfNode(...args) - editor.select(range) -} - -Commands.moveAnchorToStartOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveAnchorToStartOfNode(node) command is deprecated. Use the `editor.moveAnchorToStartOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveAnchorToStartOfNode(...args) - editor.select(range) -} - -Commands.moveEndToEndOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveEndToEndOfNode(node) command is deprecated. Use the `editor.moveEndToEndOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveEndToEndOfNode(...args) - editor.select(range) -} - -Commands.moveEndToStartOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveEndToStartOfNode(node) command is deprecated. Use the `editor.moveEndToStartOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveEndToStartOfNode(...args) - editor.select(range) -} - -Commands.moveFocusToEndOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveFocusToEndOfNode(node) command is deprecated. Use the `editor.moveFocusToEndOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveFocusToEndOfNode(...args) - editor.select(range) -} - -Commands.moveFocusToStartOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveFocusToStartOfNode(node) command is deprecated. Use the `editor.moveFocusToStartOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveFocusToStartOfNode(...args) - editor.select(range) -} - -Commands.moveStartToEndOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveStartToEndOfNode(node) command is deprecated. Use the `editor.moveStartToEndOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveStartToEndOfNode(...args) - editor.select(range) -} - -Commands.moveStartToStartOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveStartToStartOfNode(node) command is deprecated. Use the `editor.moveStartToStartOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveStartToStartOfNode(...args) - editor.select(range) -} - -Commands.moveToEndOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveToEndOfNode(node) command is deprecated. Use the `editor.moveToEndOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveToEndOfNode(...args) - editor.select(range) -} - -Commands.moveToRangeOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveToRangeOfNode(node) command is deprecated. Use the `editor.moveToRangeOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveToRangeOfNode(...args) - editor.select(range) -} - -Commands.moveToStartOfNode = (fn, editor) => (...args) => { - warning( - false, - 'As of slate@0.48 the `editor.moveToStartOfNode(node) command is deprecated. Use the `editor.moveToStartOfPath(path)` command instead.' - ) - - const { value: { selection } } = editor - const range = selection.moveToStartOfNode(...args) - editor.select(range) -} - -export default Commands diff --git a/packages/slate/src/commands/on-value.js b/packages/slate/src/commands/on-value.js deleted file mode 100644 index 01f1672f43..0000000000 --- a/packages/slate/src/commands/on-value.js +++ /dev/null @@ -1,78 +0,0 @@ -import pick from 'lodash/pick' -import Annotation from '../models/annotation' -import Value from '../models/value' - -/** - * Commands. - * - * @type {Object} - */ - -const Commands = {} - -/** - * Set `properties` on the value. - * - * @param {Object|Value} properties - */ - -Commands.setData = (fn, editor) => (data = {}) => { - const { value } = editor - const newProperties = Value.createProperties({ data }) - const prevProperties = pick(value, Object.keys(newProperties)) - - editor.applyOperation({ - type: 'set_value', - properties: prevProperties, - newProperties, - }) -} - -Commands.addAnnotation = (fn, editor) => annotation => { - annotation = Annotation.create(annotation) - - editor.applyOperation({ - type: 'add_annotation', - annotation, - }) -} - -Commands.removeAnnotation = (fn, editor) => annotation => { - annotation = Annotation.create(annotation) - - editor.applyOperation({ - type: 'remove_annotation', - annotation, - }) -} - -Commands.setAnnotation = (fn, editor) => (annotation, newProperties) => { - annotation = Annotation.create(annotation) - newProperties = Annotation.createProperties(newProperties) - - editor.applyOperation({ - type: 'set_annotation', - properties: annotation, - newProperties, - }) -} - -Commands.setAnnotations = (fn, editor) => (annotations = []) => { - const { value } = editor - const newProperties = Value.createProperties({ annotations }) - const prevProperties = pick(value, Object.keys(newProperties)) - - editor.applyOperation({ - type: 'set_value', - properties: prevProperties, - newProperties, - }) -} - -/** - * Export. - * - * @type {Object} - */ - -export default Commands diff --git a/packages/slate/src/commands/with-intent.js b/packages/slate/src/commands/with-intent.js deleted file mode 100644 index 00e6af9bdc..0000000000 --- a/packages/slate/src/commands/with-intent.js +++ /dev/null @@ -1,481 +0,0 @@ -import { Set } from 'immutable' - -import Block from '../models/block' -import Inline from '../models/inline' -import Mark from '../models/mark' - -/** - * Ensure that an expanded selection is deleted first using the `editor.delete` - * command. This guarantees that it uses the proper semantic "intent" instead of - * using `deleteAtRange` under the covers and skipping `delete`. - * - * @param {Editor} - */ - -function deleteExpanded(editor) { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } -} - -/** - * Commands. - * - * @type {Object} - */ - -const Commands = {} - -/** - * Add a `mark` to the characters in the current selection. - * - * @param {Mark} mark - */ - -Commands.addMark = (fn, editor) => mark => { - mark = Mark.create(mark) - const { value } = editor - const { document, selection } = value - - if (selection.isExpanded) { - editor.addMarkAtRange(selection, mark) - } else if (selection.marks) { - const marks = selection.marks.add(mark) - const sel = selection.set('marks', marks) - editor.select(sel) - } else { - const marks = document.getActiveMarksAtRange(selection).add(mark) - const sel = selection.set('marks', marks) - editor.select(sel) - } -} - -/** - * Add a list of `marks` to the characters in the current selection. - * - * @param {Set|Array} marks - */ - -Commands.addMarks = (fn, editor) => marks => { - marks.forEach(mark => editor.addMark(mark)) -} - -/** - * Delete at the current selection. - * - */ - -Commands.delete = (fn, editor) => () => { - const { value } = editor - const { selection } = value - editor.deleteAtRange(selection) - - // COMPAT: Ensure that the selection is collapsed, because in certain cases - // when deleting across inline nodes, when splitting the inline node the end - // point of the selection will end up after the split point. - editor.moveToFocus() -} - -/** - * Delete backward `n` characters. - * - * @param {Number} n (optional) - */ - -Commands.deleteBackward = (fn, editor) => (n = 1) => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteBackwardAtRange(selection, n) - } -} - -/** - * Delete backward one character. - * - */ - -Commands.deleteCharBackward = (fn, editor) => () => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteCharBackwardAtRange(selection) - } -} - -/** - * Delete backward one line. - * - */ - -Commands.deleteLineBackward = (fn, editor) => () => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteLineBackwardAtRange(selection) - } -} - -/** - * Delete backward one word. - * - */ - -Commands.deleteWordBackward = (fn, editor) => () => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteWordBackwardAtRange(selection) - } -} - -/** - * Delete backward `n` characters. - * - * @param {Number} n (optional) - */ - -Commands.deleteForward = (fn, editor) => (n = 1) => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteForwardAtRange(selection, n) - } -} - -/** - * Delete backward one character. - * - */ - -Commands.deleteCharForward = (fn, editor) => () => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteCharForwardAtRange(selection) - } -} - -/** - * Delete backward one line. - * - */ - -Commands.deleteLineForward = (fn, editor) => () => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteLineForwardAtRange(selection) - } -} - -/** - * Delete backward one word. - * - */ - -Commands.deleteWordForward = (fn, editor) => () => { - const { value } = editor - const { selection } = value - - if (selection.isExpanded) { - editor.delete() - } else { - editor.deleteWordForwardAtRange(selection) - } -} - -/** - * Insert a `block` at the current selection. - * - * @param {String|Object|Block} block - */ - -Commands.insertBlock = (fn, editor) => block => { - deleteExpanded(editor) - block = Block.create(block) - const { value } = editor - const { selection } = value - const blockPath = editor.insertBlockAtRange(selection, block) - editor.moveToEndOfPath(blockPath) -} - -/** - * Insert a `fragment` at the current selection. - * - * @param {Document} fragment - */ - -Commands.insertFragment = (fn, editor) => fragment => { - editor.withoutNormalizing(() => { - const { value: { selection } } = editor - const range = editor.insertFragmentAtRange(selection, fragment) - editor.select(range) - editor.moveToEnd() - }) -} - -/** - * Insert an `inline` at the current selection. - * - * @param {String|Object|Inline} inline - */ - -Commands.insertInline = (fn, editor) => inline => { - deleteExpanded(editor) - inline = Inline.create(inline) - const { value } = editor - const { selection } = value - const path = editor.insertInlineAtRange(selection, inline) - - if (path) { - editor.moveToEndOfPath(path) - } -} - -/** - * Insert a string of `text` with optional `marks` at the current selection. - * - * @param {String} text - * @param {Set} marks (optional) - */ - -Commands.insertText = (fn, editor) => (text, marks) => { - deleteExpanded(editor) - - const { value } = editor - const { document, selection } = value - marks = marks || selection.marks || document.getInsertMarksAtRange(selection) - - editor.withoutNormalizing(() => { - editor.insertTextAtRange(selection, text, marks) - - // If the text was successfully inserted, and the selection had marks on it, - // unset the selection's marks. - if (selection.marks && document !== editor.value.document) { - editor.select({ marks: null }) - } - }) -} - -/** - * Remove a `mark` from the characters in the current selection. - * - * @param {Mark} mark - */ - -Commands.removeMark = (fn, editor) => mark => { - mark = Mark.create(mark) - const { value } = editor - const { document, selection } = value - - if (selection.isExpanded) { - editor.removeMarkAtRange(selection, mark) - } else if (selection.marks) { - const marks = selection.marks.remove(mark) - const sel = selection.set('marks', marks) - editor.select(sel) - } else { - const marks = document.getActiveMarksAtRange(selection).remove(mark) - const sel = selection.set('marks', marks) - editor.select(sel) - } -} - -/** - * Replace an `oldMark` with a `newMark` in the characters in the current selection. - * - * @param {Mark} oldMark - * @param {Mark} newMark - */ - -Commands.replaceMark = (fn, editor) => (oldMark, newMark) => { - editor.removeMark(oldMark) - editor.addMark(newMark) -} - -/** - * Set the `properties` of block nodes. - * - * @param {Object|String} properties - */ - -Commands.setBlocks = (fn, editor) => properties => { - const { value } = editor - const { selection } = value - editor.setBlocksAtRange(selection, properties) -} - -/** - * Set the `properties` of inline nodes. - * - * @param {Object|String} properties - */ - -Commands.setInlines = (fn, editor) => properties => { - const { value } = editor - const { selection } = value - editor.setInlinesAtRange(selection, properties) -} - -/** - * Split the block node at the current selection, to optional `depth`. - * - * @param {Number} depth (optional) - */ - -Commands.splitBlock = (fn, editor) => (depth = 1) => { - deleteExpanded(editor) - - const { value } = editor - const { selection, document } = value - const marks = selection.marks || document.getInsertMarksAtRange(selection) - editor.splitBlockAtRange(selection, depth) - editor.moveToEnd() - - if (marks && marks.size !== 0) { - editor.select({ marks }) - } -} - -/** - * Split the inline nodes to optional `height`. - * - * @param {Number} height (optional) - */ - -Commands.splitInline = (fn, editor) => height => { - deleteExpanded(editor) - const { value } = editor - const { selection } = value - editor.splitInlineAtRange(selection, height) -} - -/** - * Add or remove a `mark` from the characters in the current selection, - * depending on whether it's already there. - * - * @param {Mark} mark - */ - -Commands.toggleMark = (fn, editor) => mark => { - mark = Mark.create(mark) - const { value: { document, selection } } = editor - const activeMarks = selection.isUnset - ? new Set() - : selection.marks || document.getActiveMarksAtRange(selection) - - if (activeMarks.has(mark)) { - editor.removeMark(mark) - } else { - editor.addMark(mark) - } -} - -/** - * Unwrap nodes from a block with `properties`. - * - * @param {String|Object} properties - */ - -Commands.unwrapBlock = (fn, editor) => properties => { - const { value } = editor - const { selection } = value - editor.unwrapBlockAtRange(selection, properties) -} - -/** - * Unwrap nodes from an inline with `properties`. - * - * @param {String|Object} properties - */ - -Commands.unwrapInline = (fn, editor) => properties => { - const { value } = editor - const { selection } = value - editor.unwrapInlineAtRange(selection, properties) -} - -/** - * Wrap nodes in a new `block`. - * - * @param {Block|Object|String} block - */ - -Commands.wrapBlock = (fn, editor) => block => { - const { value } = editor - const { selection } = value - editor.wrapBlockAtRange(selection, block) -} - -/** - * Wrap nodes in a new `inline`. - * - * @param {Inline|Object|String} inline - */ - -Commands.wrapInline = (fn, editor) => inline => { - const { value } = editor - const { selection } = value - editor.wrapInlineAtRange(selection, inline) -} - -/** - * Wrap the current selection with prefix/suffix. - * - * @param {String} prefix - * @param {String} suffix - */ - -Commands.wrapText = (fn, editor) => (prefix, suffix = prefix) => { - const { value } = editor - const { selection } = value - editor.wrapTextAtRange(selection, prefix, suffix) - - // If the selection was collapsed, it will have moved the start offset too. - if (selection.isCollapsed) { - editor.moveStartBackward(prefix.length) - } - - // Adding the suffix will have pushed the end of the selection further on, so - // we need to move it back to account for this. - editor.moveEndBackward(suffix.length) - - // There's a chance that the selection points moved "through" each other, - // resulting in a now-incorrect selection direction. - if (selection.isForward !== editor.value.selection.isForward) { - editor.flip() - } -} - -/** - * Export. - * - * @type {Object} - */ - -export default Commands diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js deleted file mode 100644 index 9f9aa6b012..0000000000 --- a/packages/slate/src/controllers/editor.js +++ /dev/null @@ -1,700 +0,0 @@ -import Debug from 'debug' -import invariant from 'tiny-invariant' -import isPlainObject from 'is-plain-object' -import warning from 'tiny-warning' -import { List } from 'immutable' - -import CorePlugin from '../plugins/core' -import Operation from '../models/operation' -import PathUtils from '../utils/path-utils' -import SchemaPlugin from '../plugins/schema' -import Value from '../models/value' - -let refIds = 0 - -/** - * Debug. - * - * @type {Function} - */ - -const debug = Debug('slate:editor') - -/** - * Editor. - * - * @type {Editor} - */ - -class Editor { - /** - * Create a new `Editor` with `attrs`. - * - * @param {Object} attrs - * @param {Object} options - */ - - constructor(attrs = {}, options = {}) { - const { controller = this, construct = true } = options - const { - onChange = () => {}, - plugins = [], - readOnly = false, - value = Value.create(), - } = attrs - - this.controller = controller - this.onChange = onChange - this.operations = List() - this.readOnly = null - this.value = null - this.handlers = {} - - this.tmp = { - dirty: [], - pathRefs: [], - pointRefs: [], - flushing: false, - merge: null, - normalize: true, - save: true, - } - - const core = CorePlugin({ plugins }) - registerPlugin(this, controller, core) - - if (construct) { - this.exec('onConstruct') - this.setReadOnly(readOnly) - this.setValue(value, options) - } - } - - /** - * Apply an `operation` to the editor, updating its value. - * - * @param {Operation|Object} operation - * @return {Editor} - */ - - applyOperation(operation) { - const { operations } = this - let value = this.value - - // Add in the current `value` in case the operation was serialized. - if (isPlainObject(operation)) { - operation = { ...operation, value } - } - - operation = Operation.create(operation) - - // Save the operation into the history. Since `save` is a command, we need - // to do it without normalizing, since it would have side effects. - this.withoutNormalizing(() => { - this.save(operation) - value = this.value - }) - - // Apply the operation to the value. - debug('apply', { operation }) - this.value = operation.apply(value) - this.operations = operations.push(operation) - - // Get the paths of the affected nodes, and mark them as dirty. - const newDirtyPaths = getDirtyPaths(operation) - - const dirty = this.tmp.dirty.map(path => { - path = PathUtils.create(path) - const transformed = PathUtils.transform(path, operation) - return transformed.toArray() - }) - - const pathIndex = {} - const dirtyPaths = Array.prototype.concat.apply(newDirtyPaths, dirty) - this.tmp.dirty = [] - - // PERF: De-dupe the paths so we don't do extra normalization. - dirtyPaths.forEach(dirtyPath => { - const key = dirtyPath.join(',') - - if (!pathIndex[key]) { - this.tmp.dirty.push(dirtyPath) - } - - pathIndex[key] = true - }) - - // Iterate all of the path refs to update them. If the operation results in - // the path being destroyed, unref them since they'll never change. - for (const id in this.tmp.pathRefs) { - const ref = this.tmp.pathRefs[id] - const path = PathUtils.transform(ref.path, operation).last() - - if (!path) { - ref.path = null - ref.unref() - } else { - ref.path = path - } - } - - // Do the same with any point refs. - for (const id in this.tmp.pointRefs) { - const ref = this.tmp.pointRefs[id] - const point = ref.point.transform(operation) - - if (!point) { - ref.point = null - ref.unref() - } else { - ref.point = point.normalize(this.value.document) - } - } - - // If we're not already, queue the flushing process on the next tick. - if (!this.tmp.flushing) { - this.tmp.flushing = true - Promise.resolve().then(() => this.flush()) - } - } - - createPathRef(path) { - const id = refIds++ - const ref = { - path, - unref: () => delete this.tmp.pathRefs[id], - } - - if (path) { - this.tmp.pathRefs[id] = ref - } - - return ref - } - - createPointRef(point) { - const id = refIds++ - const ref = { - point, - unref: () => delete this.tmp.pointRefs[id], - } - - if (point) { - this.tmp.pointRefs[id] = ref - } - - return ref - } - - /** - * Exec a handler of the editor by `name` with `...args`. - * - * @param {String} name - * @param {Any} ...args - * @return {Any} - */ - - exec(name, ...args) { - invariant( - typeof name === 'string', - 'As of slate@0.48 the `editor.exec` method must take a name string, not a function.' - ) - - invariant(this.has(name), `No editor middleware found named "${name}"!`) - - const fn = this.handlers[name] - const ret = fn(...args) - normalizeDirtyPaths(this) - return ret - } - - /** - * Flush the editor's current change. - * - * @return {Editor} - */ - - flush() { - this.exec('onChange') - const { value, operations } = this - const change = { value, operations } - this.operations = List() - this.tmp.flushing = false - this.onChange(change) - } - - /** - * Check if the editor has a handler by `name`. - * - * @param {String} name - * @return {Boolean} - */ - - has(name) { - return name in this.handlers - } - - /** - * Normalize all of the nodes in the document from scratch. - * - * @return {Editor} - */ - - normalize() { - const { value } = this - let { document } = value - const paths = Array.from( - document.descendants({ includeTarget: true, includeRoot: true }), - ([, path]) => path - ) - - this.tmp.dirty = this.tmp.dirty.concat(paths) - normalizeDirtyPaths(this) - - const { selection } = value - document = value.document - - if (selection.isUnset && document.nodes.size) { - this.moveToStartOfDocument() - } - } - - /** - * Set the `readOnly` flag. - * - * @param {Boolean} readOnly - * @return {Editor} - */ - - setReadOnly(readOnly) { - this.readOnly = readOnly - return this - } - - /** - * Set the editor's `value`. - * - * @param {Value} value - * @param {Options} options - * @return {Editor} - */ - - setValue(value, options = {}) { - const { normalize = value !== this.value } = options - this.value = value - - if (normalize) { - this.normalize() - } - - return this - } - - /** - * Apply a series of changes inside a synchronous `fn`, deferring - * normalization until after the function has finished executing. - * - * @param {Function} fn - * @return {Editor} - */ - - withoutNormalizing(fn) { - const value = this.tmp.normalize - this.tmp.normalize = false - fn() - this.tmp.normalize = value - normalizeDirtyPaths(this) - } - - /** - * Deprecated. - */ - - get editor() { - warning( - false, - "As of Slate 0.43 the `change` object has been replaced with `editor`, so you don't need to access `change.editor`." - ) - - return this.controller - } - - change(fn, ...args) { - warning( - false, - 'As of Slate 0.43 the `change` object has been replaced with `editor`, so the `editor.change()` method is deprecated.`' - ) - - fn(this.controller, ...args) - } - - call(fn, ...args) { - warning( - false, - 'As of Slate 0.43 the `editor.call(fn)` method has been deprecated, please use `editor.command(fn)` instead.' - ) - - fn(this.controller, ...args) - return this.controller - } - - applyOperations(operations) { - warning( - false, - 'As of Slate 0.43 the `applyOperations` method is deprecated, please apply each operation in a loop instead.' - ) - - operations.forEach(op => this.applyOperation(op)) - return this.controller - } - - setOperationFlag(key, value) { - warning( - false, - 'As of slate@0.41 the `change.setOperationFlag` method has been deprecated.' - ) - - this.tmp[key] = value - return this - } - - getFlag(key, options = {}) { - warning( - false, - 'As of slate@0.41 the `change.getFlag` method has been deprecated.' - ) - - return options[key] !== undefined ? options[key] : this.tmp[key] - } - - unsetOperationFlag(key) { - warning( - false, - 'As of slate@0.41 the `change.unsetOperationFlag` method has been deprecated.' - ) - - delete this.tmp[key] - return this - } - - withoutNormalization(fn) { - warning( - false, - 'As of slate@0.41 the `change.withoutNormalization` helper has been renamed to `change.withoutNormalizing`.' - ) - - return this.withoutNormalizing(fn) - } - - run(fn, ...args) { - warning( - false, - 'As of slate@0.48 the `editor.run` method has been renamed to `editor.exec`.' - ) - - invariant( - typeof fn === 'string', - 'As of slate@0.48 the `editor.run` method must take a middleware name string, not a function.' - ) - - return this.exec(fn, ...args) - } - - command(type, ...args) { - warning( - false, - 'As of slate@0.48 the `editor.command` method is deprecated. Please use `editor.exec` instead.' - ) - - return this.exec(type, ...args) - } - - hasCommand(type) { - warning( - false, - 'As of slate@0.48 the `editor.hasCommand` method is deprecated. Please use `editor.has` instead.' - ) - - return this.has(type) - } - - hasQuery(type) { - warning( - false, - 'As of slate@0.48 the `editor.hasQuery` method is deprecated. Please use `editor.has` instead.' - ) - - return this.has(type) - } - - query(type, ...args) { - warning( - false, - 'As of slate@0.48 the `editor.query` method is deprecated. Please use `editor.exec` instead.' - ) - - return this.exec(type, ...args) - } - - registerCommand(type) { - invariant( - false, - 'As of slate@0.48 the `editor.registerCommand` method has been removed.' - ) - } - - registerQuery(type) { - invariant( - false, - 'As of slate@0.48 the `editor.registerQuery` method has been removed.' - ) - } -} - -/** - * Get the "dirty" paths for a given `operation`. - * - * @param {Operation} operation - * @return {Array} - */ - -function getDirtyPaths(operation) { - const { type, node, path, newPath } = operation - - switch (type) { - case 'add_mark': - case 'insert_text': - case 'remove_mark': - case 'remove_text': - case 'set_mark': - case 'set_node': { - const ancestors = PathUtils.getAncestors(path).toArray() - return [...ancestors, path] - } - - case 'insert_node': { - const paths = - node.object === 'text' - ? [] - : Array.from( - node.descendants({ includeTarget: true, includeRoot: true }), - ([, p]) => path.concat(p) - ) - - const ancestors = PathUtils.getAncestors(path).toArray() - return [...ancestors, path, ...paths] - } - - case 'split_node': { - const ancestors = PathUtils.getAncestors(path).toArray() - const nextPath = PathUtils.increment(path) - return [...ancestors, path, nextPath] - } - - case 'merge_node': { - const ancestors = PathUtils.getAncestors(path).toArray() - const previousPath = PathUtils.decrement(path) - return [...ancestors, previousPath] - } - - case 'move_node': { - if (PathUtils.isEqual(path, newPath)) { - return [] - } - - const oldAncestors = PathUtils.getAncestors(path).reduce((arr, p) => { - arr.push(...PathUtils.transform(p, operation).toArray()) - return arr - }, []) - - const newAncestors = PathUtils.getAncestors(newPath).reduce((arr, p) => { - arr.push(...PathUtils.transform(p, operation).toArray()) - return arr - }, []) - - return [...oldAncestors, ...newAncestors] - } - - case 'remove_node': { - const ancestors = PathUtils.getAncestors(path).toArray() - return [...ancestors] - } - - default: { - return [] - } - } -} - -/** - * Normalize any new "dirty" paths that have been added to the change. - * - * @param {Editor} - */ - -function normalizeDirtyPaths(editor) { - if (!editor.tmp.normalize) { - return - } - - if (!editor.tmp.dirty.length) { - return - } - - editor.withoutNormalizing(() => { - while (editor.tmp.dirty.length) { - const path = editor.tmp.dirty.pop() - normalizeNodeByPath(editor, path) - } - }) -} - -/** - * Normalize the node at a specific `path`. - * - * @param {Editor} editor - * @param {Array} path - * @param {Number} iteration - */ - -function normalizeNodeByPath( - editor, - path, - iteration = 0, - maxIterations = null -) { - const { controller } = editor - const { value } = editor - const { document } = value - const node = document.assertNode(path) - - // Set a best estimate for maximum iterations. - if (!maxIterations) { - maxIterations = 100 + (node.object === 'text' ? 1 : node.nodes.size) - } - - // Check to make sure that we haven't exceeded the max. Without this check, - // it's easy for a `normalize` function of a schema rule to be written - // incorrectly and for an infinite invalid loop to occur. - if (iteration > maxIterations) { - throw new Error( - 'A schema rule could not be normalized after sufficient iterations. This is usually due to a `rule.normalize` or `plugin.normalizeNode` function of a schema being incorrectly written, causing an infinite loop.' - ) - } - - const fn = node.normalize(controller) - - // A normalizing function is only returned when the node is invalid. - if (!fn) { - return - } - - // Run the normalize `fn` to fix the node. - const opCount = editor.operations.size - fn() - - // Now that normalizing operations have been applied, we need to refind the - // path, transformed by all the new operations. - const newOps = editor.operations.slice(opCount) - let paths = [path] - - for (const op of newOps) { - let next = [] - - // Transforming paths can sometimes result in multiple new paths, so we - // have to accoutn for that by collecting an array. - for (const p of paths) { - const transformed = PathUtils.transform(p, op) - next = next.concat(transformed.toArray()) - } - - paths = next - } - - // For every updated path, we want to continue iterating to ensure that the - // node is fully normalized by all rules. - for (const p of paths) { - normalizeNodeByPath(editor, p, iteration + 1, maxIterations) - } -} - -/** - * Register a `plugin` with the editor. - * - * @param {Editor} editor - * @param {Object|Array|Null} plugin - */ - -function registerPlugin(editor, controller, plugin) { - if (Array.isArray(plugin)) { - plugin - .slice() - .reverse() - .forEach(p => registerPlugin(editor, controller, p)) - - return - } - - if (plugin == null) { - return - } - - const { commands, queries, schema, ...rest } = plugin - - if (commands) { - warning( - false, - 'As of slate@0.48 the `plugin.commands` dictionary is deprecated. Register the commands as top-level functions in the plugin instead.' - ) - - for (const key in commands) { - const command = commands[key] - - registerHandler(editor, controller, key, () => (...args) => - command(editor, ...args) - ) - } - } - - if (queries) { - warning( - false, - 'As of slate@0.48 the `plugin.queries` dictionary is deprecated. Register the queries as top-level functions in the plugin instead.' - ) - - for (const key in queries) { - const query = queries[key] - - registerHandler(editor, controller, key, () => (...args) => - query(editor, ...args) - ) - } - } - - if (schema) { - const schemaPlugin = SchemaPlugin(schema) - registerPlugin(editor, controller, schemaPlugin) - } - - for (const key in rest) { - const fn = rest[key] - registerHandler(editor, controller, key, fn) - } -} - -function registerHandler(editor, controller, name, fn) { - const existing = editor.handlers[name] || noop - editor.handlers[name] = fn(existing, controller) - editor[name] = editor[name] || ((...args) => editor.exec(name, ...args)) - controller[name] = editor[name] -} - -function noop() {} - -/** - * Export. - * - * @type {Editor} - */ - -export default Editor diff --git a/packages/slate/src/index.js b/packages/slate/src/index.js deleted file mode 100644 index 23531b0c7c..0000000000 --- a/packages/slate/src/index.js +++ /dev/null @@ -1,83 +0,0 @@ -import './interfaces/object' -import './interfaces/model' -import './interfaces/node' -import './interfaces/element' -import './interfaces/range' - -import Annotation from './models/annotation' -import Block from './models/block' -import Change from './models/change' -import Data from './models/data' -import Decoration from './models/decoration' -import Document from './models/document' -import Editor from './controllers/editor' -import Inline from './models/inline' -import KeyUtils from './utils/key-utils' -import Leaf from './models/leaf' -import Mark from './models/mark' -import Node from './models/node' -import Operation from './models/operation' -import PathUtils from './utils/path-utils' -import Point from './models/point' -import Range from './models/range' -import Selection from './models/selection' -import Text from './models/text' -import TextUtils from './utils/text-utils' -import Value from './models/value' -import { resetMemoization, useMemoization } from './utils/memoize' - -/** - * Export. - * - * @type {Object} - */ - -export { - Annotation, - Block, - Change, - Data, - Decoration, - Document, - Editor, - Inline, - KeyUtils, - Leaf, - Mark, - Node, - Operation, - PathUtils, - Point, - Range, - resetMemoization, - Selection, - Text, - TextUtils, - useMemoization, - Value, -} - -export default { - Annotation, - Block, - Change, - Data, - Decoration, - Document, - Editor, - Inline, - KeyUtils, - Leaf, - Mark, - Node, - Operation, - PathUtils, - Point, - Range, - resetMemoization, - Selection, - Text, - TextUtils, - useMemoization, - Value, -} diff --git a/packages/slate/src/index.ts b/packages/slate/src/index.ts new file mode 100755 index 0000000000..df5ba8a15d --- /dev/null +++ b/packages/slate/src/index.ts @@ -0,0 +1,19 @@ +export { Editor, EditorConstructor } from './classes/editor' +export { PathRef } from './classes/path-ref' +export { PointRef } from './classes/point-ref' +export { RangeRef } from './classes/range-ref' + +export { Annotation, AnnotationPointEntry } from './interfaces/annotation' +export * from './interfaces/change' +export * from './interfaces/element' +export * from './interfaces/fragment' +export * from './interfaces/mark' +export * from './interfaces/node' +export * from './interfaces/operation' +export * from './interfaces/path' +export * from './interfaces/point' +export * from './interfaces/range' +export * from './interfaces/selection' +export * from './interfaces/string' +export * from './interfaces/text' +export * from './interfaces/value' diff --git a/packages/slate/src/interfaces/annotation.ts b/packages/slate/src/interfaces/annotation.ts new file mode 100755 index 0000000000..4e52cd5af1 --- /dev/null +++ b/packages/slate/src/interfaces/annotation.ts @@ -0,0 +1,48 @@ +import isPlainObject from 'is-plain-object' +import { Mark, Point, Range } from '..' + +/** + * `Annotation` objects are a type of formatting that are applied at the + * top-level of a Slate value. They implement both the `Mark` and `Range` + * interfaces, such that a single annotation can describe formatting that spans + * across multiple nodes in the document. + */ + +interface Annotation extends Mark, Range {} + +/** + * `AnnotationPointEntry` objects are returned when iterating over `Point` + * objects that belong to an `Annotation`. + */ + +type AnnotationPointEntry = [Point, Annotation, string] + +namespace Annotation { + /** + * Check if a value implements the `Annotation` interface. + */ + + export const isAnnotation = (value: any): value is Annotation => { + return Range.isRange(value) && Mark.isMark(value) + } + + /** + * Check if a value is a map of `Annotation` objects. + */ + + export const isAnnotationRecord = ( + value: any + ): value is Record => { + if (!isPlainObject(value)) { + return false + } + + for (const key in value) { + return Annotation.isAnnotation(value[key]) + } + + return true + } +} + +export { Annotation, AnnotationPointEntry } diff --git a/packages/slate/src/interfaces/change.ts b/packages/slate/src/interfaces/change.ts new file mode 100644 index 0000000000..4b69baee42 --- /dev/null +++ b/packages/slate/src/interfaces/change.ts @@ -0,0 +1,29 @@ +import isPlainObject from 'is-plain-object' +import { Value, Operation } from '..' + +/** + * `Change` objects are emited when a Slate editor is flushed. They contain the + * latest `Value` and the list of `Operation` objects that have been applied + * since the previous change. + */ + +interface Change { + value: Value + operations: Operation[] +} + +namespace Change { + /** + * Check if a value implements the `Change` interface. + */ + + export const isChange = (value: any): value is Change => { + return ( + isPlainObject(value) && + Value.isValue(value.value) && + Operation.isOperationList(value.operations) + ) + } +} + +export { Change } diff --git a/packages/slate/src/interfaces/element.js b/packages/slate/src/interfaces/element.js deleted file mode 100644 index bf8df9ccc9..0000000000 --- a/packages/slate/src/interfaces/element.js +++ /dev/null @@ -1,2793 +0,0 @@ -import getDirection from 'direction' -import invariant from 'tiny-invariant' -import warning from 'tiny-warning' -import { List, OrderedSet, Set } from 'immutable' - -import Annotation from '../models/annotation' -import Block from '../models/block' -import Decoration from '../models/decoration' -import Document from '../models/document' -import Inline from '../models/inline' -import Node from '../models/node' -import Operation from '../models/operation' -import PathUtils from '../utils/path-utils' -import Point from '../models/point' -import Range from '../models/range' -import Selection from '../models/selection' -import Value from '../models/value' -import identity from '../utils/identity' -import memoize from '../utils/memoize' -import mixin from '../utils/mixin' - -/** - * The interface that `Document`, `Block` and `Inline` all implement, to make - * working with the recursive node tree easier. - * - * @type {Class} - */ - -class ElementInterface { - /** - * Get the concatenated text of the node. - * - * @return {String} - */ - - get text() { - return this.getText() - } - - /** - * Create an iteratable for all of the ancestors of the node. - * - * @return {Iterable} - */ - - ancestors(path) { - const iterable = this.createIterable({ - path, - direction: null, - downward: false, - includeTargetAncestors: true, - includeRoot: true, - }) - - return iterable - } - - /** - * Create an iteratable for all of the blocks of a node with `options`. - * - * @param {Options} - * @return {Iterable} - */ - - blocks(options = {}) { - const { onlyLeaves, onlyRoots, onlyTypes, match, ...rest } = options - const iterable = this.descendants({ - includeDocument: false, - includeInlines: false, - includeTexts: false, - ...rest, - match: (node, path) => { - if (onlyTypes && !onlyTypes.includes(node.type)) { - return false - } else if (onlyRoots && path.size !== 1) { - return false - } else if (onlyLeaves && !node.isLeafBlock()) { - return false - } else if (match && !match(node, path)) { - return false - } else { - return true - } - }, - }) - - return iterable - } - - /** - * Create an annotation with `properties` relative to the node. - * - * @param {Object|Annotation} properties - * @return {Annotation} - */ - - createAnnotation(properties) { - properties = Annotation.createProperties(properties) - const annotation = this.resolveAnnotation(properties) - return annotation - } - - /** - * Create a decoration with `properties` relative to the node. - * - * @param {Object|Decoration} properties - * @return {Decoration} - */ - - createDecoration(properties) { - properties = Decoration.createProperties(properties) - const decoration = this.resolveDecoration(properties) - return decoration - } - - /** - * Create an iteratable function starting at `target` path with `options`. - * - * @param {Object} options (optional) - * @return {Function} - */ - - createIterable(options = {}) { - const { - direction = 'forward', - downward = true, - upward = true, - includeBlocks = true, - includeDocument = true, - includeHanging = true, - includeInlines = true, - includeRoot = false, - includeTarget = !!options.range, - includeTargetAncestors = false, - includeTexts = true, - match = null, - } = options - - const root = this - let targetPath = null - let targetRange = null - - // You can iterate over either a range or a path, but not both. - if (options.range) { - targetRange = root.resolveRange(options.range) - targetPath = root.resolvePath(targetRange.start.path) - } else if (options.path) { - targetPath = root.resolvePath(options.path) - } - - const targetNode = targetPath && root.assertNode(targetPath) - const NativeSet = typeof window === 'undefined' ? global.Set : window.Set - - // Return an object that implements the iterable interface. - return { - [Symbol.iterator]() { - const visited = new NativeSet() - const startPath = targetRange && targetRange.start.path - const endPath = targetRange && targetRange.end.path - let path = targetPath - let node = targetNode - let includedTarget = false - let includedStart = false - let includingStart = false - - const result = () => { - // When these are nulled out we've finished iterating. - if (!path || !node) { - return { done: true } - } - - // We often don't want to include the root node itself. - if (!includeRoot && node === root) { - return next() - } - - if (!includeBlocks && node.object === 'block') { - return next() - } - - if (!includeDocument && node.object === 'document') { - return next() - } - - if (!includeInlines && node.object === 'inline') { - return next() - } - - if (!includeTexts && node.object === 'text') { - return next() - } - - if ( - !includeHanging && - targetRange && - targetRange.isExpanded && - targetRange.end.offset === 0 && - (PathUtils.isAbove(path, targetRange.end.path) || - PathUtils.isEqual(path, targetRange.end.path)) - ) { - const closestBlock = root.closestBlock(targetRange.end.path) - - // We also need to ensure that not only is the point's offset zero, - // but that the point refers to the zero offset in the block itself. - // Otherwise it could be inside a nested inline, in which case it - // should not be considered hanging. - if (closestBlock) { - const [blockNode, blockPath] = closestBlock - const relativePath = targetRange.end.path.slice(blockPath.size) - const offset = blockNode.getOffset(relativePath) - - if (offset === 0) { - return next() - } - } - } - - if (match && !match(node, path)) { - return next() - } - - return { value: [node, path], done: false } - } - - const next = () => { - if (!path || !node) { - return result() - } - - // When iterating over a range, we need to include the specific - // ancestors in the start path of the range manually. - if (startPath && !includedStart) { - if (!includingStart) { - includingStart = true - path = PathUtils.create([]) - node = root - return result() - } - - if (path.size === startPath.size - 1) { - includedStart = true - path = targetPath - node = targetNode - return next() - } - - path = startPath.slice(0, path.size + 1) - node = root.assertNode(path) - return result() - } - - // Sometimes we want to include the target itself. - if (includeTarget && !includedTarget) { - includedTarget = true - return result() - } - - // When iterating over a range, if we get to the end path then exit. - if (endPath && path.equals(endPath)) { - node = null - path = null - return next() - } - - // If we're allowed to go downward, and we haven't decsended yet, do so. - if (downward && node.nodes && node.nodes.size && !visited.has(node)) { - visited.add(node) - const nextIndex = direction === 'forward' ? 0 : node.nodes.size - 1 - path = path.push(nextIndex) - node = root.assertNode(path) - return result() - } - - // If we're going forward... - if (direction === 'forward') { - const newPath = PathUtils.increment(path) - const newNode = root.getNode(newPath) - - if (newNode) { - path = newPath - node = newNode - return result() - } - } - - // If we're going backward... - if (direction === 'backward' && path.last() !== 0) { - const newPath = PathUtils.decrement(path) - const newNode = root.getNode(newPath) - - if (newNode) { - path = newPath - node = newNode - return result() - } - } - - // If we're going upward... - if (upward && path.size) { - path = PathUtils.lift(path) - node = root.assertNode(path) - - // Sometimes we'll have already visited the node on the way down - // so we don't want to double count it. - if (visited.has(node)) { - return next() - } - - visited.add(node) - - // If ancestors of the target node shouldn't be included, skip them. - if (!includeTargetAncestors) { - return next() - } else { - return result() - } - } - - path = null - node = null - return next() - } - - return { next } - }, - } - } - - /** - * Create a point with `properties` relative to the node. - * - * @param {Object|Point} properties - * @return {Range} - */ - - createPoint(properties) { - properties = Point.createProperties(properties) - const point = this.resolvePoint(properties) - return point - } - - /** - * Create a range with `properties` relative to the node. - * - * @param {Object|Range} properties - * @return {Range} - */ - - createRange(properties) { - properties = Range.createProperties(properties) - const range = this.resolveRange(properties) - return range - } - - /** - * Create a selection with `properties` relative to the node. - * - * @param {Object|Selection} properties - * @return {Selection} - */ - - createSelection(properties) { - properties = Selection.createProperties(properties) - const selection = this.resolveSelection(properties) - return selection - } - - /** - * Create an iteratable for all of the descendants of the node. - * - * @param {Object} options - * @return {Iterable} - */ - - descendants(options) { - const iterable = this.createIterable({ path: [], ...options }) - return iterable - } - - /** - * Find all of the descendants that match a `predicate`. - * - * @param {Function} predicate - * @return {List} - */ - - filterDescendants(predicate = identity) { - const matches = [] - - for (const [node, path] of this.descendants()) { - if (predicate(node, path)) { - matches.push(node) - } - } - - return List(matches) - } - - /** - * Find the first descendant that matches a `predicate`. - * - * @param {Function} predicate - * @return {Node|Null} - */ - - findDescendant(predicate = identity) { - for (const [node, path] of this.descendants()) { - if (predicate(node, path)) { - return node - } - } - - return null - } - - /** - * Iterate over all descendants, breaking if `predicate` returns false. - * - * @param {Function} predicate - */ - - forEachDescendant(predicate = identity) { - for (const next of this.descendants()) { - const ret = predicate(...next) - - if (ret === false) { - return - } - } - } - - /** - * Get a set of the active marks in a `range`. Active marks are marks that are - * on every text node in a given range. This is a common distinction for - * highlighting toolbar buttons for example. - * - * TODO: this method needs to be cleaned up, it's very hard to follow and - * probably doing unnecessary work. - * - * @param {Range} range - * @return {Set} - */ - - getActiveMarksAtRange(range) { - range = this.resolveRange(range) - - if (range.isUnset) { - return Set() - } - - if (range.isCollapsed) { - const { start } = range - return this.getInsertMarksAtPoint(start) - } - - const { start, end } = range - let startPath = start.path - let startOffset = start.offset - let endPath = end.path - let endOffset = end.offset - let startText = this.getDescendant(startPath) - let endText = this.getDescendant(endPath) - - if (!startPath.equals(endPath)) { - while (!startPath.equals(endPath) && endOffset === 0) { - ;[[endText, endPath]] = this.texts({ - path: endPath, - direction: 'backward', - }) - - endOffset = endText.text.length - } - - while ( - !startPath.equals(endPath) && - startOffset === startText.text.length - ) { - ;[[startText, startPath]] = this.texts({ path: startPath }) - startOffset = 0 - } - } - - if (startPath.equals(endPath)) { - return startText.marks - } - - const startMarks = startText.marks - - // PERF: if start marks is empty we can return early. - if (startMarks.size === 0) { - return Set() - } - - const endMarks = endText.marks - let marks = startMarks.intersect(endMarks) - - // If marks is already empty, the active marks is empty - if (marks.size === 0) { - return marks - } - - ;[[startText, startPath]] = this.texts({ path: startPath }) - - while (!startPath.equals(endPath)) { - if (startText.text.length !== 0) { - marks = marks.intersect(startText.marks) - - if (marks.size === 0) { - return Set() - } - } - - ;[[startText, startPath]] = this.texts({ path: startPath }) - } - - return marks - } - - /** - * Get a list of the ancestors of a descendant. - * - * @param {List|String} path - * @return {List|Null} - */ - - getAncestors(path) { - const iterable = this.ancestors(path) - const array = Array.from(iterable, ([node]) => node).reverse() - const list = List(array) - return list - } - - /** - * Get the leaf block descendants of the node. - * - * @return {List} - */ - - getBlocks() { - const iterable = this.blocks({ onlyLeaves: true }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get all of the leaf blocks that match a `type`. - * - * @param {String} type - * @return {List} - */ - - getBlocksByType(type) { - const iterable = this.blocks({ onlyLeaves: true, onlyTypes: [type] }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get a child node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getChild(path) { - path = this.resolvePath(path) - - if (!path || path.size > 1) { - return null - } - - const child = this.nodes.get(path.first()) - return child - } - - /** - * Get closest parent of node that matches a `predicate`. - * - * @param {List|String} path - * @param {Function} predicate - * @return {Node|Null} - */ - - getClosest(path, predicate) { - for (const [n, p] of this.ancestors(path)) { - if (predicate(n, p)) { - return n - } - } - - return null - } - - /** - * Get the closest block parent of a node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getClosestBlock(path) { - const closest = this.getClosest(path, n => n.object === 'block') - return closest - } - - /** - * Get the closest inline parent of a node by `path`. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getClosestInline(path) { - const closest = this.getClosest(path, n => n.object === 'inline') - return closest - } - - /** - * Get the closest void parent of a node by `path`. - * - * @param {List|String} path - * @param {Editor} editor - * @return {Node|Null} - */ - - getClosestVoid(path, editor) { - invariant( - !Value.isValue(editor), - 'As of Slate 0.42.0, the `node.getClosestVoid` method takes an `editor` instead of a `value`.' - ) - - const closest = this.getClosest(path, n => editor.isVoid(n)) - return closest - } - - /** - * Get the common ancestor of nodes `a` and `b`. - * - * @param {List} a - * @param {List} b - * @return {Node} - */ - - getCommonAncestor(a, b) { - a = this.resolvePath(a) - b = this.resolvePath(b) - - if (!a || !b) { - return null - } - - const path = PathUtils.relate(a, b) - const node = this.getNode(path) - return node - } - - /** - * Get the decorations for the node from an `editor`. - * - * @param {Editor} editor - * @return {List} - */ - - getDecorations(editor) { - let decorations = editor.exec('decorateNode', this) - decorations = Decoration.createList(decorations) - return decorations - } - - /** - * Get the depth of a descendant, with optional `startAt`. - * - * @param {List|String} path - * @param {Number} startAt - * @return {Number|Null} - */ - - getDepth(path, startAt = 1) { - path = this.resolvePath(path) - - if (!path) { - return null - } - - const node = this.getNode(path) - const depth = node ? path.size - 1 + startAt : null - return depth - } - - /** - * Get a descendant node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getDescendant(path) { - path = this.resolvePath(path) - - if (!path || !path.size) { - return null - } - - let node = this - - path.forEach(index => { - node = node.getIn(['nodes', index]) - return !!node - }) - - return node - } - - /** - * Get all of the descendant nodes in a `range`. - * - * @param {Range} range - * @return {List} - */ - - getDescendantsAtRange(range) { - const iterable = this.descendants({ range }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get a fragment of the node at a `range`. - * - * @param {Range} range - * @return {Document} - */ - - getFragmentAtRange(range) { - range = this.resolveRange(range) - - if (range.isUnset) { - return Document.create() - } - - const { start, end } = range - let node = this - let target = end - let path = target.path - let position = target.offset - - while (path.size) { - const index = path.last() - const child = node.assertNode(path) - const parentPath = PathUtils.lift(path) - const parent = node.assertNode(parentPath) - let a - let b - - if (child.object === 'text') { - ;[a, b] = child.splitText(position) - } else { - const befores = child.nodes.take(position) - const afters = child.nodes.skip(position) - a = child.set('nodes', befores) - b = child.set('nodes', afters).regenerateKey() - } - - const newParentNodes = parent.nodes.splice(index, 1, a, b) - const newParent = parent.set('nodes', newParentNodes) - node = node.replaceNode(parentPath, newParent) - position = index + 1 - path = PathUtils.lift(path) - - if (!path.size && target === end) { - target = start - path = target.path - position = target.offset - } - } - - const startIndex = start.path.first() + 1 - const endIndex = end.path.first() + 2 - const nodes = node.nodes.slice(startIndex, endIndex) - const fragment = Document.create({ nodes }) - return fragment - } - - /** - * Get the furthest ancestors of a node that matches a `predicate`. - * - * @param {Path} path - * @param {Function} predicate - * @return {Node|Null} - */ - - getFurthest(path, predicate = identity) { - const iterable = this.ancestors(path) - const results = Array.from(iterable).reverse() - - for (const [n, p] of results) { - if (predicate(n, p)) { - return n - } - } - - return null - } - - /** - * Get the furthest block parent of a node. - * - * @param {Path} path - * @return {Node|Null} - */ - - getFurthestBlock(path) { - const furthest = this.getFurthest(path, n => n.object === 'block') - return furthest - } - - /** - * Get the furthest child ancestor of a node at `path`. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getFurthestChild(path) { - path = this.resolvePath(path) - - if (!path || !path.size) { - return null - } - - const furthest = this.nodes.get(path.first()) - return furthest - } - - /** - * Get the furthest inline parent of a node. - * - * @param {Path} path - * @return {Node|Null} - */ - - getFurthestInline(path) { - const furthest = this.getFurthest(path, n => n.object === 'inline') - return furthest - } - - /** - * Get the closest inline nodes for each text node in the node. - * - * @return {List} - */ - - getInlines() { - const iterable = this.inlines({ onlyLeaves: true }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get all of the leaf inline nodes that match a `type`. - * - * @param {String} type - * @return {List} - */ - - getInlinesByType(type) { - const iterable = this.inlines({ onlyLeaves: true, onlyTypes: [type] }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get a set of marks that would occur on the next insert at a `point` in the - * node. This mimics expected rich text editing behaviors of mark contiuation. - * - * @param {Point} point - * @return {Set} - */ - - getInsertMarksAtPoint(point) { - point = this.resolvePoint(point) - const { path, offset } = point - const text = this.getDescendant(path) - - // PERF: we can exit early if the offset isn't at the start of the node. - if (offset !== 0) { - return text.marks - } - - let blockNode - let blockPath - - for (const entry of this.ancestors(path)) { - const [n, p] = entry - - if (n.object === 'block') { - blockNode = n - blockPath = p - } - } - - const relativePath = PathUtils.drop(path, blockPath.size) - const [previous] = blockNode.texts({ - path: relativePath, - direction: 'backward', - }) - - // If there's no previous text, we're at the start of the block, so use - // the current text nodes marks. - if (!previous) { - return text.marks - } - - // Otherwise, continue with the previous text node's marks instead. - const [previousText] = previous - return previousText.marks - } - - /** - * Get a set of marks that would occur on the next insert at a `range`. - * This mimics expected rich text editing behaviors of mark contiuation. - * - * @param {Range} range - * @return {Set} - */ - - getInsertMarksAtRange(range) { - range = this.resolveRange(range) - const { start } = range - - if (range.isUnset) { - return Set() - } - - if (range.isCollapsed) { - return this.getInsertMarksAtPoint(start) - } - - const text = this.getDescendant(start.path) - return text.marks - } - - /** - * Get the bottom-most block descendants in a `range`. - * - * @param {Range} range - * @return {List} - */ - - getLeafBlocksAtRange(range) { - const iterable = this.blocks({ range, onlyLeaves: true }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get the bottom-most inline nodes for each text node in a `range`. - * - * @param {Range} range - * @return {List} - */ - - getLeafInlinesAtRange(range) { - const iterable = this.inlines({ range, onlyLeaves: true }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get an object mapping all the keys in the node to their paths. - * - * @return {Map} - */ - - getNodesToPathsMap() { - const root = this - const map = - typeof window === 'undefined' ? new global.Map() : new window.Map() - - map.set(root, PathUtils.create([])) - - root.forEachDescendant((node, path) => { - map.set(node, path) - }) - - return map - } - - /** - * Get all of the marks for all of the characters of every text node. - * - * @return {OrderedSet} - */ - - getMarks() { - const iterable = this.marks() - const array = Array.from(iterable, ([mark]) => mark) - return OrderedSet(array) - } - - /** - * Get a set of the marks in a `range`. - * - * @param {Range} range - * @return {OrderedSet} - */ - - getMarksAtRange(range) { - const iterable = this.marks({ range }) - const array = Array.from(iterable, ([mark]) => mark) - return OrderedSet(array) - } - - /** - * Get all of the marks that match a `type`. - * - * @param {String} type - * @return {OrderedSet} - */ - - getMarksByType(type) { - const iterable = this.marks({ onlyTypes: [type] }) - const array = Array.from(iterable, ([mark]) => mark) - return OrderedSet(array) - } - - /** - * Get the block node after a descendant text node by `path`. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getNextBlock(path) { - const [entry] = this.blocks({ path, onlyLeaves: true }) - const block = entry ? entry[0] : null - return block - } - - /** - * Get the next node in the tree, returning siblings or ancestor siblings. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getNextNode(path) { - const iterable = this.createIterable({ path, downward: false }) - const [entry] = iterable - const node = entry ? entry[0] : null - return node - } - - /** - * Get the next sibling of a node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getNextSibling(path) { - const [entry] = this.siblings(path) - const node = entry ? entry[0] : null - return node - } - - /** - * Get the text node after a descendant text node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getNextText(path) { - const [entry] = this.texts({ path }) - const node = entry ? entry[0] : null - return node - } - - /** - * Get the offset for a descendant text node by `path` or `key`. - * - * @param {List|string} path - * @return {Number} - */ - - getOffset(path) { - path = this.resolvePath(path) - this.assertDescendant(path) - - // Calculate the offset of the nodes before the highest child. - const index = path.first() - - const offset = this.nodes - .slice(0, index) - .reduce((memo, n) => memo + n.text.length, 0) - - // Recurse if need be. - const ret = - path.size === 1 - ? offset - : offset + this.nodes.get(index).getOffset(PathUtils.drop(path)) - - return ret - } - - /** - * Get the offset from a `range`. - * - * @param {Range} range - * @return {Number} - */ - - getOffsetAtRange(range) { - range = this.resolveRange(range) - - if (range.isUnset) { - throw new Error('The range cannot be unset to calculcate its offset.') - } - - if (range.isExpanded) { - throw new Error('The range must be collapsed to calculcate its offset.') - } - - const { start } = range - const offset = this.getOffset(start.path) + start.offset - return offset - } - - /** - * Get the parent of a descendant node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getParent(path) { - path = this.resolvePath(path) - if (!path) return null - if (!path.size) return null - const parentPath = PathUtils.lift(path) - const parent = this.getNode(parentPath) - return parent - } - - /** - * Get the block node before a descendant text node by `path`. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getPreviousBlock(path) { - const [entry] = this.blocks({ - path, - onlyLeaves: true, - direction: 'backward', - }) - const block = entry ? entry[0] : null - return block - } - - /** - * Get the previous node from a node in the tree. - * - * This will not only check for siblings but instead move up the tree - * returning the previous ancestor if no sibling is found. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getPreviousNode(path) { - const iterable = this.createIterable({ - path, - downward: false, - direction: 'backward', - }) - - const [entry] = iterable - const node = entry ? entry[0] : null - return node - } - - /** - * Get the previous sibling of a node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getPreviousSibling(path) { - const [entry] = this.siblings(path, { direction: 'backward' }) - const node = entry ? entry[0] : null - return node - } - - /** - * Get the text node before a descendant text node. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getPreviousText(path) { - const [entry] = this.texts({ path, direction: 'backward' }) - const node = entry ? entry[0] : null - return node - } - - /** - * Get only the root block nodes in a `range`. - * - * @param {Range} range - * @return {List} - */ - - getRootBlocksAtRange(range) { - const iterable = this.blocks({ range, onlyRoots: true }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get only the root inline nodes in a `range`. - * - * @param {Range} range - * @return {List} - */ - - getRootInlinesAtRange(range) { - const iterable = this.inlines({ range, onlyRoots: true }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get the descendent text node at an `offset`. - * - * @param {String} offset - * @return {Node|Null} - */ - - getTextAtOffset(offset) { - // PERF: Add a few shortcuts for the obvious cases. - if (offset === 0) return this.getFirstText() - if (offset === this.text.length) return this.getLastText() - if (offset < 0 || offset > this.text.length) return null - - let length = 0 - - for (const [node] of this.texts()) { - length += node.text.length - - if (length > offset) { - return node - } - } - - return null - } - - /** - * Get the direction of the node's text. - * - * @return {String} - */ - - getTextDirection() { - const dir = getDirection(this.text) - return dir === 'neutral' ? null : dir - } - - /** - * Recursively get all of the child text nodes in order of appearance. - * - * @return {List} - */ - - getTexts() { - const iterable = this.texts() - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Get all of the text nodes in a `range` as a List. - * - * @param {Range} range - * @return {List} - */ - - getTextsAtRange(range) { - const iterable = this.texts({ range }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - /** - * Check if the node has block children. - * - * @return {Boolean} - */ - - hasBlockChildren() { - return !!(this.nodes && this.nodes.find(n => n.object === 'block')) - } - - /** - * Check if a child node exists. - * - * @param {List|String} path - * @return {Boolean} - */ - - hasChild(path) { - const child = this.getChild(path) - return !!child - } - - /** - * Check if a node has inline children. - * - * @return {Boolean} - */ - - hasInlineChildren() { - return !!( - this.nodes && - this.nodes.find(n => n.object === 'inline' || n.object === 'text') - ) - } - - /** - * Recursively check if a child node exists. - * - * @param {List|String} path - * @return {Boolean} - */ - - hasDescendant(path) { - const descendant = this.getDescendant(path) - return !!descendant - } - - /** - * Check if a node has `properties`. - * - * @param {Object} properties - * @return {Boolean} - */ - - hasProperties(properties) { - const node = this - - if (node.object === 'text') { - return false - } - - properties = Node.createProperties(properties) - - return ( - (properties.type == null || node.type === properties.type) && - (properties.data == null || node.data.isSuperset(properties.data)) - ) - } - - isSimilar(other) { - // HACK: this shouldn't need to be special-cased. - if (other.object === 'document' && this.object === 'document') { - return true - } else if (other.object === 'document' || this.object === 'document') { - return false - } - - const props = Node.createProperties(this) - return other.hasProperties(props) - } - - /** - * Check if a node has a void parent. - * - * @param {List|String} path - * @param {Editor} editor - * @return {Boolean} - */ - - hasVoidParent(path, editor) { - invariant( - !Value.isValue(editor), - 'As of Slate 0.42.0, the `node.hasVoidParent` method takes an `editor` instead of a `value`.' - ) - - const closest = this.getClosestVoid(path, editor) - return !!closest - } - - /** - * Create an iteratable for all of the inlines of a node with `options`. - * - * @param {Options} - * @return {Iterable} - */ - - inlines(options = {}) { - const { onlyLeaves, onlyRoots, onlyTypes, match, ...rest } = options - const iterable = this.descendants({ - includeBlocks: false, - includeTexts: false, - includeDocument: false, - ...rest, - match: (node, path) => { - if (onlyTypes && !onlyTypes.includes(node.type)) { - return false - } else if (onlyLeaves && !node.isLeafInline()) { - return false - } else if (onlyRoots && this.getParent(path).object !== 'block') { - return false - } else if (match && !match(node, path)) { - return false - } else { - return true - } - }, - }) - - return iterable - } - - /** - * Check whether the node is a leaf block. - * - * @return {Boolean} - */ - - isLeafBlock() { - if (this.object !== 'block') { - return false - } - - if (this.nodes.some(n => n.object === 'block')) { - return false - } - - return true - } - - /** - * Check whether the node is a leaf inline. - * - * @return {Boolean} - */ - - isLeafInline() { - if (this.object !== 'inline') { - return false - } - - if (this.nodes.some(n => n.object === 'inline')) { - return false - } - - return true - } - - /** - * Check whether a descendant node is inside a `range` by `path`. - * - * @param {List|String} path - * @param {Range} range - * @return {Node} - */ - - isInRange(path, range) { - path = this.resolvePath(path) - range = this.resolveRange(range) - - if (range.isUnset) { - return false - } - - const toStart = PathUtils.compare(path, range.start.path) - const toEnd = PathUtils.compare(path, range.end.path) - const isInRange = toStart !== -1 && toEnd !== 1 - return isInRange - } - - /** - * Map all child nodes, updating them in their parents. This method is - * optimized to not return a new node if no changes are made. - * - * @param {Function} predicate - * @return {Node} - */ - - mapChildren(predicate = identity) { - let { nodes } = this - - nodes.forEach((node, i) => { - const ret = predicate(node, i, this.nodes) - if (ret !== node) nodes = nodes.set(i, ret) - }) - - const ret = this.set('nodes', nodes) - return ret - } - - /** - * Map all descendant nodes, updating them in their parents. This method is - * optimized to not return a new node if no changes are made. - * - * @param {Function} predicate - * @return {Node} - */ - - mapDescendants(predicate = identity) { - let { nodes } = this - - nodes.forEach((node, index) => { - let ret = node - if (ret.object !== 'text') ret = ret.mapDescendants(predicate) - ret = predicate(ret, index, this.nodes) - if (ret === node) return - - nodes = nodes.set(index, ret) - }) - - const ret = this.set('nodes', nodes) - return ret - } - - /** - * Create an iteratable for all the marks in text nodes with `options`. - * - * @param {Options} - * @return {Iterable} - */ - - marks(options = {}) { - const { onlyTypes = null, match, ...rest } = options - const texts = this.texts(rest) - - return { - [Symbol.iterator]() { - const iterator = texts[Symbol.iterator]() - let node = null - let path = null - let remaining = [] - - const next = () => { - if (remaining.length) { - const mark = remaining.shift() - - if (onlyTypes && !onlyTypes.includes(mark.type)) { - return next() - } else if (match && !match(mark, node, path)) { - return next() - } - - return { value: [mark, node, path], done: false } - } - - const { value, done } = iterator.next() - - if (done) { - return { done: true } - } - - ;[node, path] = value - remaining = node.marks.toArray() - return next() - } - - return { next } - }, - } - } - - /** - * Replace a `node` in the tree. - * - * @param {List|Key} path - * @param {Node} node - * @return {Node} - */ - - replaceNode(path, node) { - path = this.resolvePath(path) - - if (!path) { - throw new Error( - `Unable to replace a node because it could not be found in the first place: ${path}` - ) - } - - if (!path.size) return node - this.assertNode(path) - const deep = path.flatMap(x => ['nodes', x]) - const ret = this.setIn(deep, node) - return ret - } - - /** - * Resolve a `annotation`, relative to the node, ensuring that the keys and - * offsets in the annotation exist and that they are synced with the paths. - * - * @param {Annotation|Object} annotation - * @return {Annotation} - */ - - resolveAnnotation(annotation) { - annotation = Annotation.create(annotation) - annotation = annotation.normalize(this) - return annotation - } - - /** - * Resolve a `decoration`, relative to the node, ensuring that the keys and - * offsets in the decoration exist and that they are synced with the paths. - * - * @param {Decoration|Object} decoration - * @return {Decoration} - */ - - resolveDecoration(decoration) { - decoration = Decoration.create(decoration) - decoration = decoration.normalize(this) - return decoration - } - - /** - * Resolve a `point`, relative to the node, ensuring that the keys and - * offsets in the point exist and that they are synced with the paths. - * - * @param {Point|Object} point - * @return {Point} - */ - - resolvePoint(point) { - point = Point.create(point) - point = point.normalize(this) - return point - } - - /** - * Resolve a `range`, relative to the node, ensuring that the keys and - * offsets in the range exist and that they are synced with the paths. - * - * @param {Range|Object} range - * @return {Range} - */ - - resolveRange(range) { - range = Range.create(range) - range = range.normalize(this) - return range - } - - /** - * Resolve a `selection`, relative to the node, ensuring that the keys and - * offsets in the selection exist and that they are synced with the paths. - * - * @param {Selection|Object} selection - * @return {Selection} - */ - - resolveSelection(selection) { - selection = Selection.create(selection) - selection = selection.normalize(this) - return selection - } - - /** - * Create an iteratable for the siblings in the tree at `path`. - * - * @param {List|Array} path - * @return {Iterable} - */ - - siblings(path, options) { - const iterable = this.createIterable({ - path, - upward: false, - downward: false, - ...options, - }) - - return iterable - } - - /** - * Create an iteratable for all the text node descendants. - * - * @param {Object} options - * @return {Iterable} - */ - - texts(options) { - const iterable = this.descendants({ - includeBlocks: false, - includeInlines: false, - includeDocument: false, - ...options, - }) - - return iterable - } - - previousBlock(path) { - const node = this.assertNode(path) - - if (node.object !== 'text') { - const entry = node.firstText() - - if (entry) { - const [, entryPath] = entry - path = path.concat(entryPath) - } - } - - const [prev] = this.blocks({ - path, - direction: 'backward', - onlyLeaves: true, - }) - - return prev - } - - previousInline(path) { - const node = this.assertNode(path) - - if (node.object !== 'text') { - const entry = node.firstText() - - if (entry) { - const [, entryPath] = entry - path = path.concat(entryPath) - } - } - - const [prev] = this.inlines({ - path, - direction: 'backward', - onlyLeaves: true, - }) - - return prev - } - - previousText(path) { - const node = this.assertNode(path) - - if (node.object !== 'text') { - const entry = node.firstText() - - if (entry) { - const [, entryPath] = entry - path = path.concat(entryPath) - } - } - - const [prev] = this.texts({ path, direction: 'backward' }) - return prev - } - - nextBlock(path) { - const node = this.assertNode(path) - - if (node.object !== 'text') { - const entry = node.lastText() - - if (entry) { - const [, entryPath] = entry - path = path.concat(entryPath) - } - } - - const [next] = this.blocks({ path, onlyLeaves: true }) - return next - } - - nextInline(path) { - const node = this.assertNode(path) - - if (node.object !== 'text') { - const entry = node.lastText() - - if (entry) { - const [, entryPath] = entry - path = path.concat(entryPath) - } - } - - const [next] = this.inlines({ path, onlyLeaves: true }) - return next - } - - nextText(path) { - const node = this.assertNode(path) - - if (node.object !== 'text') { - const entry = node.lastText() - - if (entry) { - const [, entryPath] = entry - path = path.concat(entryPath) - } - } - - const [next] = this.texts({ path }) - return next - } - - firstText(options) { - const [first] = this.texts({ includeTarget: true, ...options }) - return first - } - - firstBlock(options) { - const [first] = this.blocks(options) - return first - } - - lastText(options) { - const [last] = this.texts({ - direction: 'backward', - includeTarget: true, - ...options, - }) - - return last - } - - lastBlock(options) { - const [last] = this.blocks({ - direction: 'backward', - ...options, - }) - - return last - } - - closest(path, predicate) { - for (const [n, p] of this.ancestors(path)) { - if (predicate(n, p)) { - return [n, p] - } - } - - return null - } - - closestBlock(path) { - const closest = this.closest(path, n => n.object === 'block') - return closest - } - - closestInline(path) { - const closest = this.closest(path, n => n.object === 'inline') - return closest - } - - closestVoid(path, editor) { - const closest = this.closest(path, n => editor.isVoid(n)) - return closest - } - - furthest(path, predicate = identity) { - const iterable = this.ancestors(path) - const results = Array.from(iterable).reverse() - - for (const [n, p] of results) { - if (predicate(n, p)) { - return [n, p] - } - } - - return null - } - - furthestBlock(path) { - const furthest = this.furthest(path, n => n.object === 'block') - return furthest - } - - furthestInline(path) { - const furthest = this.furthest(path, n => n.object === 'inline') - return furthest - } - - addMark(path, mark) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.addMark(mark) - const ret = this.replaceNode(path, node) - return ret - } - - setNode(path, properties) { - let node = this.assertNode(path) - node = node.merge(properties) - const ret = this.replaceNode(path, node) - return ret - } - - setMark(path, properties, newProperties) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.setMark(properties, newProperties) - const ret = this.replaceNode(path, node) - return ret - } - - splitNode(path, position, properties) { - const child = this.assertNode(path) - path = this.resolvePath(path) - let a - let b - - if (child.object === 'text') { - ;[a, b] = child.splitText(position) - } else { - const befores = child.nodes.take(position) - const afters = child.nodes.skip(position) - a = child.set('nodes', befores) - b = child.set('nodes', afters).regenerateKey() - } - - if (properties && child.object !== 'text') { - b = b.merge(properties) - } - - let ret = this - ret = ret.removeNode(path) - ret = ret.insertNode(path, b) - ret = ret.insertNode(path, a) - return ret - } - - insertNode(path, node) { - path = this.resolvePath(path) - const index = path.last() - const parentPath = PathUtils.lift(path) - let parent = this.assertNode(parentPath) - const nodes = parent.nodes.splice(index, 0, node) - parent = parent.set('nodes', nodes) - const ret = this.replaceNode(parentPath, parent) - return ret - } - - insertText(path, offset, text) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.insertText(offset, text) - const ret = this.replaceNode(path, node) - return ret - } - - mergeNode(path) { - const b = this.assertNode(path) - path = this.resolvePath(path) - - if (path.last() === 0) { - throw new Error( - `Unable to merge node because it has no previous sibling: ${b}` - ) - } - - const withPath = PathUtils.decrement(path) - const a = this.assertNode(withPath) - - if (a.object !== b.object) { - throw new Error( - `Unable to merge two different kinds of nodes: ${a} and ${b}` - ) - } - - const newNode = - a.object === 'text' - ? a.mergeText(b) - : a.set('nodes', a.nodes.concat(b.nodes)) - - let ret = this - ret = ret.removeNode(path) - ret = ret.removeNode(withPath) - ret = ret.insertNode(withPath, newNode) - return ret - } - - moveNode(path, newPath, newIndex = 0) { - const node = this.assertNode(path) - path = this.resolvePath(path) - newPath = this.resolvePath(newPath, newIndex) - - const newParentPath = PathUtils.lift(newPath) - this.assertNode(newParentPath) - - // TODO: this is a bit hacky, re-creating the operation that led to this method being called - // Alternative 1: pass the operation through from apply -> value.moveNode - // Alternative 2: add a third property to the operation called "transformedNewPath", pass that through - const op = Operation.create({ - type: 'move_node', - path, - newPath, - }) - newPath = PathUtils.transform(path, op).first() - - let ret = this - ret = ret.removeNode(path) - ret = ret.insertNode(newPath, node) - return ret - } - - removeMark(path, mark) { - path = this.resolvePath(path) - let node = this.assertDescendant(path) - node = node.removeMark(mark) - const ret = this.replaceNode(path, node) - return ret - } - - removeNode(path) { - this.assertDescendant(path) - path = this.resolvePath(path) - const deep = path.flatMap(x => ['nodes', x]) - const ret = this.deleteIn(deep) - return ret - } - - removeText(path, offset, text) { - let node = this.assertDescendant(path) - node = node.removeText(offset, text.length) - const ret = this.replaceNode(path, node) - return ret - } - - /** - * Deprecated. - */ - - getBlocksAtRange(range) { - warning( - false, - 'As of slate@0.44 the `node.getBlocksAtRange` method has been renamed to `getLeafBlocksAtRange`.' - ) - - return this.getLeafBlocksAtRange(range) - } - - getBlocksAtRangeAsArray(range) { - warning( - false, - 'As of slate@0.44 the `node.getBlocksAtRangeAsArray` method has been renamed to `getLeafBlocksAtRangeAsArray`.' - ) - - return this.getLeafBlocksAtRangeAsArray(range) - } - - getInlinesAtRange(range) { - warning( - false, - 'As of slate@0.44 the `node.getInlinesAtRange` method has been renamed to `getLeafInlinesAtRange`.' - ) - - return this.getLeafInlinesAtRange(range) - } - - getInlinesAtRangeAsArray(range) { - warning( - false, - 'As of slate@0.44 the `node.getInlinesAtRangeAsArray` method has been renamed to `getLeafInlinesAtRangeAsArray`.' - ) - - return this.getLeafInlinesAtRangeAsArray(range) - } - - getNextTextAndPath(path) { - warning( - false, - 'As of slate@0.47, the `getNextTextAndPath` method has been renamed to `getNextTextEntry`.' - ) - - return this.getNextTextEntry(path) - } - - getNextDeepMatchingNodeAndPath(path, iterator = () => true) { - warning( - false, - 'As of slate@0.47, the `getNextDeepMatchingNodeAndPath` method is deprecated.' - ) - - const match = this.getNextMatchingNodeAndPath(path) - - if (!match) return null - - let [nextNode, nextPath] = match - - let childMatch - - const assign = () => { - childMatch = - nextNode.object !== 'text' && - nextNode.findFirstDescendantAndPath(iterator, nextPath) - return childMatch - } - - while (assign(childMatch)) { - ;[nextNode, nextPath] = childMatch - } - - if (!nextNode) return null - - return iterator(nextNode) - ? [nextNode, nextPath] - : this.getNextDeepMatchingNodeAndPath(match[1], iterator) - } - - getPreviousTextAndPath(path) { - warning( - false, - 'As of slate@0.47, the `getPreviousTextAndPath` method has been renamed to `getPreviousTextEntry`.' - ) - - return this.getPreviousTextEntry(path) - } - - findFirstDescendantAndPath(iterator, pathToThisNode) { - warning( - false, - 'As of slate@0.47, the `findFirstDescendantAndPath` method is deprecated.' - ) - - return this.findDescendantAndPath(iterator, pathToThisNode, false) - } - - getPreviousMatchingNodeAndPath(path, iterator = () => true) { - warning( - false, - 'As of slate@0.47, the `getPreviousMatchingNodeAndPath` method is deprecated.' - ) - - if (!path) return null - - for (let i = path.size; i > 0; i--) { - const p = path.slice(0, i) - if (p.last() === 0) continue - - let previousPath = PathUtils.decrement(p) - let previousNode = this.getNode(previousPath) - - while (previousNode && !iterator(previousNode)) { - previousPath = PathUtils.decrement(previousPath) - previousNode = this.getNode(previousPath) - } - - if (previousNode) return [previousNode, previousPath] - } - - return null - } - - getPreviousDeepMatchingNodeAndPath(path, iterator = () => true) { - warning( - false, - 'As of slate@0.47, the `getPreviousDeepMatchingNodeAndPath` method is deprecated.' - ) - - const match = this.getPreviousMatchingNodeAndPath(path) - - if (!match) return null - - let [previousNode, previousPath] = match - - let childMatch - - const assign = () => { - childMatch = - previousNode.object !== 'text' && - previousNode.findLastDescendantAndPath(iterator, previousPath) - return childMatch - } - - while (assign(childMatch)) { - ;[previousNode, previousPath] = childMatch - } - - if (!previousNode) return null - - return iterator(previousNode) - ? [previousNode, previousPath] - : this.getPreviousDeepMatchingNodeAndPath(match[1], iterator) - } - - findLastDescendantAndPath(iterator, pathToThisNode) { - warning( - false, - 'As of slate@0.47, the `findLastDescendantAndPath` method is deprecated.' - ) - - return this.findDescendantAndPath(iterator, pathToThisNode, true) - } - - findDescendantAndPath( - iterator, - pathToThisNode = PathUtils.create([]), - findLast = false - ) { - warning( - false, - 'As of slate@0.47, the `findDescendantAndPath` method is deprecated.' - ) - - let found - let foundPath - - this.forEachDescendantWithPath( - (node, path, nodes) => { - if (iterator(node, path, nodes)) { - found = node - foundPath = path - return false - } - }, - pathToThisNode, - findLast - ) - - return found ? [found, foundPath] : null - } - - forEachDescendantWithPath(iterator, path = PathUtils.create([]), findLast) { - warning( - false, - 'As of slate@0.47, the `forEachDescendantWithPath` method is deprecated.' - ) - - let nodes = this.nodes - let ret - - if (findLast) nodes = nodes.reverse() - - nodes.forEach((child, i) => { - const childPath = path.concat(i) - - if (iterator(child, childPath, nodes) === false) { - ret = false - return false - } - - if (child.object !== 'text') { - ret = child.forEachDescendantWithPath(iterator, childPath, findLast) - return ret - } - }) - - return ret - } - - getNextMatchingNodeAndPath(path, iterator = () => true) { - warning( - false, - 'As of slate@0.47, the `getNextMatchingNodeAndPath` method is deprecated.' - ) - - if (!path) return null - - for (let i = path.size; i > 0; i--) { - const p = path.slice(0, i) - - let nextPath = PathUtils.increment(p) - let nextNode = this.getNode(nextPath) - - while (nextNode && !iterator(nextNode)) { - nextPath = PathUtils.increment(nextPath) - nextNode = this.getNode(nextPath) - } - - if (nextNode) return [nextNode, nextPath] - } - - return null - } - - getSelectionIndexes(range, isSelected = true) { - warning( - false, - 'As of slate@0.47, the `getSelectionIndexes` method is deprecated.' - ) - - const { start, end } = range - - // PERF: if we're not selected, we can exit early. - if (!isSelected) { - return null - } - - // PERF: if we've been given an invalid selection we can exit early. - if (range.isUnset) { - return null - } - - // PERF: if the start and end keys are the same, just check for the child - // that contains that single key. - if (start.path.equals(end.path)) { - const child = this.getFurthestAncestor(start.path) - const index = child ? this.nodes.indexOf(child) : null - return { start: index, end: index + 1 } - } - - // Otherwise, check all of the children... - let startIndex = null - let endIndex = null - - this.nodes.forEach((child, i) => { - if (child.object === 'text') { - if (startIndex == null && child.key === start.key) startIndex = i - if (endIndex == null && child.key === end.key) endIndex = i + 1 - } else { - if (startIndex == null && child.hasDescendant(start.key)) startIndex = i - if (endIndex == null && child.hasDescendant(end.key)) endIndex = i + 1 - } - - // PERF: exit early if both start and end have been found. - return startIndex == null || endIndex == null - }) - - if (isSelected && startIndex == null) { - startIndex = 0 - } - - if (isSelected && endIndex == null) { - endIndex = this.nodes.size - } - - if (startIndex == null) { - return null - } - - return { start: startIndex, end: endIndex } - } - - getTextsBetweenPositionsAsArray(startPath, endPath) { - warning( - false, - 'As of slate@0.47, the `getTextsBetweenPositionsAsArray` method is deprecated.' - ) - - startPath = this.resolvePath(startPath) - endPath = this.resolvePath(endPath) - - return this.getTextsBetweenPathPositionsAsArray(startPath, endPath) - } - - getOrderedMarksBetweenPositions(startPath, startOffset, endPath, endOffset) { - warning( - false, - 'As of slate@0.47, the `getOrderedMarksBetweenPositions` method is deprecated.' - ) - - startPath = this.resolvePath(startPath) - endPath = this.resolvePath(endPath) - const startText = this.getDescendant(startPath) - - // PERF: if the paths are equal, we can just use the start. - if (PathUtils.isEqual(startPath, endPath)) { - return startText.marks - } - - const texts = this.getTextsBetweenPathPositionsAsArray(startPath, endPath) - - return OrderedSet().withMutations(result => { - texts.forEach(text => { - result.union(text.marks) - }) - }) - } - - getTextsBetweenPathPositionsAsArray(startPath, endPath) { - warning( - false, - 'As of slate@0.47, the `getTextsBetweenPathPositionsAsArray` method is deprecated.' - ) - - // PERF: the most common case is when the range is in a single text node, - // where we can avoid a lot of iterating of the tree. - if (startPath && endPath && PathUtils.isEqual(startPath, endPath)) { - return [this.getDescendant(startPath)] - } else if (!startPath && !endPath) { - return this.getTextsAsArray() - } - - const startIndex = startPath ? startPath.get(0, 0) : 0 - const endIndex = endPath - ? endPath.get(0, this.nodes.size - 1) - : this.nodes.size - 1 - - let array = [] - - this.nodes.slice(startIndex, endIndex + 1).forEach((node, i) => { - if (node.object === 'text') { - array.push(node) - } else { - // For the node at start and end of this list, we want to provide a start and end path - // For other nodes, we can just get all their text nodes, they are between the paths - const childStartPath = - startPath && i === 0 ? PathUtils.drop(startPath) : null - const childEndPath = - endPath && i === endIndex - startIndex - ? PathUtils.drop(endPath) - : null - - array = array.concat( - node.getTextsBetweenPathPositionsAsArray(childStartPath, childEndPath) - ) - } - }) - - return array - } - - getFurthestAncestor(path) { - warning( - false, - 'As of slate@0.47, the `getFurthestAncestor` method has been renamed to `getFurthestChild`.' - ) - - return this.getFurthestChild(path) - } - - getLeafBlocksAtRangeAsArray(range) { - warning( - false, - 'As of slate@0.47, the `getLeafBlocksAtRangeAsArray` method is deprecated.' - ) - - range = this.resolveRange(range) - if (range.isUnset) return [] - - const { start, end } = range - - return this.getLeafBlocksBetweenPathPositionsAsArray(start.path, end.path) - } - - getLeafBlocksBetweenPathPositionsAsArray(startPath, endPath) { - warning( - false, - 'As of slate@0.47, the `getLeafBlocksBetweenPathPositionsAsArray` method is deprecated.' - ) - - // PERF: the most common case is when the range is in a single block node, - // where we can avoid a lot of iterating of the tree. - if (startPath && endPath && PathUtils.isEqual(startPath, endPath)) { - return [this.getClosestBlock(startPath)] - } else if (!startPath && !endPath) { - return this.getBlocksAsArray() - } - - const startIndex = startPath ? startPath.get(0, 0) : 0 - const endIndex = endPath - ? endPath.get(0, this.nodes.size - 1) - : this.nodes.size - 1 - - let array = [] - - this.nodes.slice(startIndex, endIndex + 1).forEach((node, i) => { - if (node.object !== 'block') { - return - } else if (node.isLeafBlock()) { - array.push(node) - } else { - const childStartPath = - startPath && i === 0 ? PathUtils.drop(startPath) : null - const childEndPath = - endPath && i === endIndex - startIndex - ? PathUtils.drop(endPath) - : null - - array = array.concat( - node.getLeafBlocksBetweenPathPositionsAsArray( - childStartPath, - childEndPath - ) - ) - } - }) - - return array - } - - getBlocksAsArray() { - warning( - false, - 'As of slate@0.47, the `getBlocksAsArray` method is deprecated.' - ) - - const iterable = this.blocks({ onlyLeaves: true }) - const array = Array.from(iterable, ([node]) => node) - return array - } - - getBlocksByTypeAsArray(type) { - warning( - false, - 'As of slate@0.47, the `getBlocksByTypeAsArray` method is deprecated.' - ) - - const iterable = this.blocks({ onlyLeaves: true, onlyTypes: [type] }) - const array = Array.from(iterable, ([node]) => node) - return array - } - - getFurthestOnlyChildAncestor(path) { - warning( - false, - 'As of slate@0.47, the `getFurthestOnlyChildAncestor` method is deprecated.' - ) - - const ancestors = this.getAncestors(path) - if (!ancestors) return null - - const furthest = ancestors - .rest() - .reverse() - .takeUntil(p => p.nodes.size > 1) - .last() - - return furthest || null - } - - getInlinesAsArray() { - warning( - false, - 'As of slate@0.47, the `getInlinesAsArray` method is deprecated.' - ) - - const array = Array.from( - this.inlines({ onlyLeaves: true }), - ([node]) => node - ) - return array - } - - getInlinesByTypeAsArray(type) { - warning( - false, - 'As of slate@0.47, the `getInlinesByTypeAsArray` method is deprecated.' - ) - - const array = Array.from( - this.inlines({ onlyLeaves: true, onlyTypes: [type] }), - ([node]) => node - ) - return array - } - - getLeafInlinesAtRangeAsArray(range) { - warning( - false, - 'As of slate@0.47, the `getLeafInlinesAtRangeAsArray` method is deprecated.' - ) - - range = this.resolveRange(range) - if (range.isUnset) return [] - - const array = this.getTextsAtRangeAsArray(range) - .map(text => this.getClosestInline(text.key)) - .filter(exists => exists) - - return array - } - - getOrderedMarks() { - warning( - false, - 'As of slate@0.47, the `getOrderedMarks` method has been folded into `getMarks`, which will now return an ordered set.' - ) - return this.getMarks() - } - - getOrderedMarksAtRange(range) { - warning( - false, - 'As of slate@0.47, the `getOrderedMarksAtRange` method has been folded into `getMarksAtRange`, which will now return an ordered set.' - ) - return this.getMarksAtRange(range) - } - - getOrderedMarksByType(type) { - warning( - false, - 'As of slate@0.47, the `getOrderedMarksByType` method has been folded into `getMarksByType`, which will now return an ordered set.' - ) - return this.getMarksByType(type) - } - - getMarksByTypeAsArray(type) { - warning( - false, - 'As of slate@0.47, the `getMarksByTypeAsArray` method is deprecated.' - ) - - const array = this.nodes.reduce((memo, node) => { - return node.object === 'text' - ? memo.concat(node.marks.filter(m => m.type === type)) - : memo.concat(node.getMarksByTypeAsArray(type)) - }, []) - - return array - } - - getMarksAsArray() { - warning( - false, - 'As of slate@0.47, the `getMarksAsArray` method is deprecated.' - ) - - const result = [] - - for (const [node] of this.texts()) { - result.push(node.marks.toArray()) - } - - // PERF: use only one concat rather than multiple for speed. - const array = [].concat(...result) - return array - } - - getRootInlinesAtRangeAsArray(range) { - warning( - false, - 'As of slate@0.47, the `getRootInlinesAtRangeAsArray` method is deprecated.' - ) - - range = this.resolveRange(range) - if (range.isUnset) return List() - - const array = this.getTextsAtRangeAsArray(range) - .map(text => this.getFurthestInline(text.key)) - .filter(exists => exists) - - return array - } - - getTextsAsArray() { - warning( - false, - 'As of slate@0.47, the `getTextsAsArray` method is deprecated.' - ) - - const iterable = this.texts() - const array = Array.from(iterable, ([node]) => node) - return array - } - - getTextsAtRangeAsArray(range) { - warning( - false, - 'As of slate@0.47, the `getTextsAtRangeAsArray` method is deprecated.' - ) - - const iterable = this.texts({ range }) - const array = Array.from(iterable, ([node]) => node) - return array - } - - getMarksAtPosition(path, offset) { - warning( - false, - 'As of slate@0.47, the `getMarksAtPosition` method is deprecated.' - ) - - path = this.resolvePath(path) - const text = this.getDescendant(path) - const currentMarks = text.marks - - if (offset !== 0) { - return OrderedSet(currentMarks) - } - - const closestBlock = this.getClosestBlock(path) - - // insert mark for empty block; the empty block are often created by split node or add marks in a range including empty blocks - if (closestBlock.text === '') { - return OrderedSet(currentMarks) - } - - const [previous] = this.texts({ path, direction: 'backward' }) - - if (!previous) { - return OrderedSet() - } - - const [previousText, previousPath] = previous - - if (closestBlock.hasDescendant(previousPath)) { - return OrderedSet(previousText.marks) - } - - return OrderedSet(currentMarks) - } - - getNodesAtRange(range) { - warning( - false, - 'As of slate@0.47, the `getNodesAtRange` method has been renamed to `getDescendantsAtRange`.' - ) - - const iterable = this.descendants({ range }) - const array = Array.from(iterable, ([node]) => node) - const list = List(array) - return list - } - - isNodeInRange(path, range) { - warning( - false, - 'As of slate@0.47, the `isNodeInRange` method has been renamed to `isInRange`.' - ) - - return this.isInRange(path, range) - } -} - -/** - * Mix in assertion variants. - */ - -const ASSERTS = ['Child', 'Depth', 'Descendant', 'Node', 'Parent', 'Path'] - -for (const method of ASSERTS) { - ElementInterface.prototype[`assert${method}`] = function(path, ...args) { - const ret = this[`get${method}`](path, ...args) - - if (ret == null) { - throw new Error( - `\`Node.assert${method}\` could not find node with path or key: ${path}` - ) - } - - return ret - } -} - -/** - * Memoize read methods. - */ - -memoize(ElementInterface.prototype, [ - 'getBlocksAsArray', - 'getBlocksByTypeAsArray', - 'getDecorations', - 'getFragmentAtRange', - 'getInlinesAsArray', - 'getInlinesByTypeAsArray', - 'getInsertMarksAtRange', - 'getLeafBlocksAtRangeAsArray', - 'getLeafBlocksAtRangeAsArray', - 'getLeafInlinesAtRangeAsArray', - 'getMarksAsArray', - 'getMarksAtPosition', - 'getMarksByTypeAsArray', - 'getNextBlock', - 'getNodesAtRange', - 'getNodesToPathsMap', - 'getOffset', - 'getOffsetAtRange', - 'getOrderedMarksBetweenPositions', - 'getPreviousBlock', - 'getRootBlocksAtRange', - 'getRootInlinesAtRangeAsArray', - 'getTextAtOffset', - 'getTextDirection', - 'getTextsAsArray', - 'getTextsBetweenPathPositionsAsArray', -]) - -/** - * Mix in the element interface. - */ - -mixin(ElementInterface, [Block, Document, Inline]) diff --git a/packages/slate/src/interfaces/element.ts b/packages/slate/src/interfaces/element.ts new file mode 100755 index 0000000000..83216e5253 --- /dev/null +++ b/packages/slate/src/interfaces/element.ts @@ -0,0 +1,43 @@ +import { produce } from 'immer' +import isPlainObject from 'is-plain-object' +import { Node, Path, Text } from '..' + +/** + * `Element` objects are a type of node in a Slate document that contain other + * element nodes or text nodes. They can be either "blocks" or "inlines" + * depending on the Slate editor's schema. + */ + +interface Element { + nodes: Node[] +} + +/** + * `ElementEntry` objects refer to an `Element` and the `Path` where it can be + * found inside a root node. + */ + +type ElementEntry = [Element, Path] + +namespace Element { + /** + * Check if a value implements the `Element` interface. + */ + + export const isElement = (value: any): value is Element => { + return isPlainObject(value) && Node.isNodeList(value.nodes) + } + + /** + * Check if a value is an array of `Element` objects. + */ + + export const isElementList = (value: any): value is Element[] => { + return ( + Array.isArray(value) && + (value.length === 0 || Element.isElement(value[0])) + ) + } +} + +export { Element, ElementEntry } diff --git a/packages/slate/src/interfaces/fragment.ts b/packages/slate/src/interfaces/fragment.ts new file mode 100755 index 0000000000..aebb913536 --- /dev/null +++ b/packages/slate/src/interfaces/fragment.ts @@ -0,0 +1,23 @@ +import isPlainObject from 'is-plain-object' +import { Node } from '..' + +/** + * The `Fragment` interface describes a tree of nodes that exist independent of + * a Slate document. + */ + +interface Fragment { + nodes: Node[] +} + +namespace Fragment { + /** + * Check if a value implements the `Fragment` interface. + */ + + export const isFragment = (value: any): value is Fragment => { + return isPlainObject(value) && Node.isNodeList(value.nodes) + } +} + +export { Fragment } diff --git a/packages/slate/src/interfaces/mark.ts b/packages/slate/src/interfaces/mark.ts new file mode 100755 index 0000000000..48550400c3 --- /dev/null +++ b/packages/slate/src/interfaces/mark.ts @@ -0,0 +1,65 @@ +import isPlainObject from 'is-plain-object' +import { Path, Text } from '..' + +/** + * `Mark` objects represent formatting that is applied to text in a Slate + * document. They appear in leaf text nodes in the document, as well as in + * annotations on the root value object. + */ + +interface Mark {} + +/** + * `MarkEntry` tuples are returned when iterating through the marks in a text + * node. They include the index of the mark in the text node's marks array, as + * well as the text node and its path in the root node. + */ + +type MarkEntry = [Mark, number, Text, Path] + +namespace Mark { + /** + * Check if a mark exists in a set of marks. + */ + + export const exists = (mark: Mark, marks: Mark[]): boolean => { + return !!marks.find(f => Mark.matches(f, mark)) + } + + /** + * Check if a value implements the `Mark` interface. + */ + + export const isMark = (value: any): value is Mark => { + return ( + isPlainObject(value) && + value.key == null && // not an `Annotation` + (value.anchor == null && value.focus == null) && // not a `Decoration` + typeof value.type === 'string' + ) + } + + /** + * Check if a value is an array of `Mark` objects. + */ + + export const isMarkList = (value: any): value is Mark[] => { + return Array.isArray(value) && (value.length === 0 || Mark.isMark(value[0])) + } + + /** + * Check if a mark matches set of properties. + */ + + export const matches = (mark: Mark, props: Partial): boolean => { + for (const key in props) { + if (mark[key] !== props[key]) { + return false + } + } + + return true + } +} + +export { Mark, MarkEntry } diff --git a/packages/slate/src/interfaces/model.js b/packages/slate/src/interfaces/model.js deleted file mode 100644 index 02ddc53bb4..0000000000 --- a/packages/slate/src/interfaces/model.js +++ /dev/null @@ -1,62 +0,0 @@ -import mixin from '../utils/mixin' -import Annotation from '../models/annotation' -import Block from '../models/block' -import Decoration from '../models/decoration' -import Document from '../models/document' -import Inline from '../models/inline' -import Leaf from '../models/leaf' -import Mark from '../models/mark' -import Node from '../models/node' -import Operation from '../models/operation' -import Point from '../models/point' -import Range from '../models/range' -import Selection from '../models/selection' -import Text from '../models/text' -import Value from '../models/value' - -/** - * The interface that all Slate models implement. - * - * @type {Class} - */ - -class ModelInterface { - /** - * Alias `fromJS`. - */ - - static fromJS(...args) { - return this.fromJSON(...args) - } - - /** - * Alias `toJS`. - */ - - toJS(...args) { - return this.toJSON(...args) - } -} - -/** - * Mix in the common interface. - * - * @param {Record} - */ - -mixin(ModelInterface, [ - Annotation, - Block, - Decoration, - Document, - Inline, - Leaf, - Mark, - Node, - Operation, - Point, - Range, - Selection, - Text, - Value, -]) diff --git a/packages/slate/src/interfaces/node.js b/packages/slate/src/interfaces/node.js deleted file mode 100644 index 19b377899c..0000000000 --- a/packages/slate/src/interfaces/node.js +++ /dev/null @@ -1,262 +0,0 @@ -import warning from 'tiny-warning' -import { List } from 'immutable' - -import mixin from '../utils/mixin' -import Block from '../models/block' -import Document from '../models/document' -import Inline from '../models/inline' -import Node from '../models/node' -import KeyUtils from '../utils/key-utils' -import memoize from '../utils/memoize' -import PathUtils from '../utils/path-utils' -import Text from '../models/text' - -/** - * The interface that `Document`, `Block` and `Inline` all implement, to make - * working with the recursive node tree easier. - * - * @type {Class} - */ - -class NodeInterface { - /** - * Get the first text node of a node, or the node itself. - * - * @return {Node|Null} - */ - - getFirstText() { - if (this.object === 'text') { - return this - } - - let descendant = null - - const found = this.nodes.find(node => { - if (node.object === 'text') return true - descendant = node.getFirstText() - return !!descendant - }) - - return descendant || found - } - - /** - * Get an object mapping all the keys in the node to their paths. - * - * @return {Object} - */ - - getKeysToPathsTable() { - const ret = { - [this.key]: [], - } - - if (this.nodes) { - this.nodes.forEach((node, i) => { - const nested = node.getKeysToPathsTable() - - for (const key in nested) { - const path = nested[key] - - warning( - !(key in ret), - `A node with a duplicate key of "${key}" was found! Duplicate keys are not allowed, you should use \`node.regenerateKey\` before inserting if you are reusing an existing node.` - ) - - ret[key] = [i, ...path] - } - }) - } - - return ret - } - - /** - * Get the last text node of a node, or the node itself. - * - * @return {Node|Null} - */ - - getLastText() { - if (this.object === 'text') { - return this - } - - let descendant = null - - const found = this.nodes.findLast(node => { - if (node.object === 'text') return true - descendant = node.getLastText() - return descendant - }) - - return descendant || found - } - - /** - * Get a node in the tree, or the node itself. - * - * @param {List|String} path - * @return {Node|Null} - */ - - getNode(path) { - path = this.resolvePath(path) - if (!path) return null - if (this.object === 'text' && path.size) return null - const node = path.size ? this.getDescendant(path) : this - return node - } - - /** - * Find the path to a node. - * - * @param {String|List} key - * @return {List} - */ - - getPath(key) { - // COMPAT: Handle passing in a path, to match other methods. - if (List.isList(key)) { - return key - } - - // COMPAT: Handle a node object by iterating the descendants tree, so that - // we avoid using keys for the future. - if (Node.isNode(key)) { - if (key === this) { - return List([]) - } - - if (this.descendants) { - for (const [node, path] of this.descendants()) { - if (key === node) { - return path - } - } - } - - return null - } - - // console.trace() - warning( - false, - 'As of slate@0.48 passing a `key` string to `node.getPath` is deprecated. You can pass in a `node` instance instead to iterate the entire tree for a specific node.' - ) - - const dict = this.getKeysToPathsTable() - const path = dict[key] - return path ? List(path) : null - } - - /** - * Get the concatenated text string of a node. - * - * @return {String} - */ - - getText() { - if (this.object === 'text') { - return this.text - } - - const text = this.nodes.reduce((memo, c) => memo + c.text, '') - return text - } - - /** - * Check if a node exists. - * - * @param {List|String} path - * @return {Boolean} - */ - - hasNode(path) { - const node = this.getNode(path) - return !!node - } - - /** - * Normalize the text node with an `editor`. - * - * @param {Editor} editor - * @return {Function|Void} - */ - - normalize(editor) { - const normalizer = editor.exec('normalizeNode', this) - return normalizer - } - - /** - * Regenerate the node's key. - * - * @return {Node} - */ - - regenerateKey() { - const key = KeyUtils.create() - const node = this.set('key', key) - return node - } - - /** - * Resolve a path from a path list or key string. - * - * An `index` can be provided, in which case paths created from a key string - * will have the index pushed onto them. This is helpful in cases where you - * want to accept either a `path` or a `key, index` combination for targeting - * a location in the tree that doesn't exist yet, like when inserting. - * - * @param {List|String} value - * @param {Number} index - * @return {List} - */ - - resolvePath(path, index) { - if (typeof path === 'string') { - path = this.getPath(path) - - if (index != null) { - path = path.concat(index) - } - } else { - path = PathUtils.create(path) - } - - return path - } - - /** - * Validate the node with an `editor`. - * - * @param {Editor} editor - * @return {Error|Void} - */ - - validate(editor) { - const error = editor.exec('validateNode', this) - return error - } -} - -/** - * Memoize read methods. - */ - -memoize(NodeInterface.prototype, [ - 'getFirstText', - 'getKeysToPathsTable', - 'getLastText', - 'getText', - 'normalize', - 'validate', -]) - -/** - * Mix in the node interface. - */ - -mixin(NodeInterface, [Block, Document, Inline, Text]) diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts new file mode 100755 index 0000000000..9adb443a2b --- /dev/null +++ b/packages/slate/src/interfaces/node.ts @@ -0,0 +1,578 @@ +import { produce } from 'immer' +import { + Element, + ElementEntry, + Fragment, + MarkEntry, + Path, + Range, + Text, + TextEntry, + Value, +} from '..' + +/** + * The `Node` union type represents all of the different types of nodes that + * occur in a Slate document tree. + */ + +type Node = Value | Element | Text + +/** + * The `Descendant` union type represents nodes that are descendants in the + * tree. It is returned as a convenience in certain cases to narrow a value + * further than the more generic `Node` union. + */ + +type Descendant = Element | Text + +/** + * The `Ancestor` union type represents nodes that are ancestors in the tree. + * It is returned as a convenience in certain cases to narrow a value further + * than the more generic `Node` union. + */ + +type Ancestor = Value | Element + +/** + * `NodeEntry` objects are returned when iterating over the nodes in a Slate + * document tree. They consist of the node and its `Path` relative to the root + * node in the document. + */ + +type NodeEntry = [Node, Path] + +/** + * `DescendantEntry` objects are returned when iterating over the descendants in + * a Slate document tree. + */ + +type DescendantEntry = [Descendant, Path] + +/** + * `AncestorEntry` objects are returned when iterating over the ancestors in a + * Slate document tree. + */ + +type AncestorEntry = [Ancestor, Path] + +namespace Node { + /** + * Get the node at a specific path, asserting that it's an ancestor node. + */ + + export const ancestor = (root: Node, path: Path): Ancestor => { + const node = Node.get(root, path) + + if (Text.isText(node)) { + throw new Error( + `Cannot get the ancestor node at ${path} because it refers to a text node instead: ${node}` + ) + } + + return node + } + + /** + * Return an iterable of all the ancestor nodes above a specific path. + * + * By default the order is bottom-up, from lowest to highest ancestor in + * the tree, but you can pass the `reverse: true` option to go top-down. + */ + + export function* ancestors( + root: Node, + path: Path, + options: { + reverse?: boolean + } = {} + ): Iterable { + for (const p of Path.ancestors(path, options)) { + const n = Node.ancestor(root, p) + const entry: AncestorEntry = [n, p] + yield entry + } + } + + /** + * Get the child of a node at a specific index. + */ + + export const child = (root: Node, index: number): Descendant => { + if (Text.isText(root)) { + throw new Error(`Cannot get the child of a text node: ${root}`) + } + + const c = root.nodes[index] as Descendant + + if (c == null) { + throw new Error(`Cannot get child at index ${index} in node: ${root}`) + } + + return c + } + + /** + * Find the closest matching node entry starting from a specific path. + */ + + export const closest = ( + root: Node, + path: Path, + predicate: (entry: NodeEntry) => boolean + ): NodeEntry | undefined => { + for (const entry of Node.levels(root, path)) { + if (predicate(entry)) { + return entry + } + } + } + + /** + * Get the node at a specific path, asserting that it's a descendant node. + */ + + export const descendant = (root: Node, path: Path): Descendant => { + const node = Node.get(root, path) + + if (Value.isValue(node)) { + throw new Error( + `Cannot get the descendant node at ${path} because it refers to a value node instead: ${node}` + ) + } + + return node + } + + /** + * Return an iterable of all the descendant node entries inside a root node. + */ + + export function* descendants( + root: Node, + options: { + path?: Path + range?: Range + reverse?: boolean + inclusive?: boolean + } = {} + ): Iterable { + for (const [node, path] of Node.entries(root, options)) { + if (path.length !== 0) { + // NOTE: we have to coerce here because checking the path's length does + // guarantee that `node` is not a `Value`, but TypeScript doesn't know. + yield [node, path] as DescendantEntry + } + } + } + + /** + * Return an iterable of all the element nodes inside a root node. Each iteration + * will return an `ElementEntry` tuple consisting of `[Element, Path]`. If the + * root node is an element it will be included in the iteration as well. + */ + + export function* elements( + root: Node, + options: { + path?: Path + range?: Range + reverse?: boolean + inclusive?: boolean + } = {} + ): Iterable { + for (const [node, path] of Node.entries(root, options)) { + if (Element.isElement(node)) { + yield [node, path] + } + } + } + + /** + * Return an iterable of all the node entries of a root node. Each entry is + * returned as a `[Node, Path]` tuple, with the path referring to the node's + * position inside the root node. + */ + + export function* entries( + root: Node, + options: { + path?: Path + range?: Range + reverse?: boolean + inclusive?: boolean + } = {} + ): Iterable { + const { path, range, reverse = false, inclusive = true } = options + let startPath: Path = [] + let endPath: Path | null = null + + if (range != null) { + const [start, end] = Range.points(range) + startPath = start.path + endPath = end.path + } else if (path != null) { + startPath = path + } + + const startNode = Node.get(root, startPath) + const visited = new Set() + let p = startPath + let n = startNode + let includedStart = false + let includingStart = false + + while (true) { + // When iterating over a range, we need to include the specific + // ancestors in the start path of the range manually. + if (!includedStart) { + if (!inclusive) { + visited.add(n) + continue + } + + if (!includingStart) { + includingStart = true + p = [] + n = root + yield [n, p] + continue + } + + if (p.length === startPath.length) { + includedStart = true + continue + } + + p = startPath.slice(0, p.length + 1) + n = Node.get(root, p) + yield [n, p] + continue + } + + // When iterating over a range, if we get to the end path then exit. + if (endPath && Path.equals(p, endPath)) { + break + } + + // If we're allowed to go downward and we haven't decsended yet, do. + if (!Text.isText(n) && n.nodes.length && !visited.has(n)) { + visited.add(n) + const nextIndex = reverse ? n.nodes.length - 1 : 0 + p = p.concat(nextIndex) + n = Node.get(root, p) + yield [n, p] + continue + } + + // To go forward, backward or upward we can't be at the root already. + if (p.length !== 0) { + // If we're going forward... + if (!reverse) { + const newPath = Path.next(p) + + if (Node.has(root, newPath)) { + p = newPath + n = Node.get(root, newPath) + yield [n, p] + continue + } + } + + // If we're going backward... + if (reverse && p[p.length - 1] !== 0) { + const newPath = Path.previous(p) + + if (Node.has(root, newPath)) { + p = newPath + n = Node.get(root, newPath) + yield [n, p] + continue + } + } + + // Otherwise we're going upward... + p = Path.parent(p) + n = Node.get(root, p) + visited.add(n) + continue + } + + break + } + } + + /** + * Get the sliced fragment represented by a range inside a root node. + */ + + export const fragment = (root: Node, range: Range): Fragment => { + if (Text.isText(root)) { + throw new Error( + `Cannot get a fragment start from a root text node: ${root}` + ) + } + + return produce(root, r => { + const [start, end] = Range.points(range) + + for (const [, path] of Node.entries(r, { reverse: true })) { + if (!Range.includes(range, path)) { + const parent = Node.parent(r, path) + const index = path[path.length - 1] + parent.nodes.splice(index, 1) + } + + if (Path.equals(path, end.path)) { + const leaf = Node.leaf(r, path) + leaf.text = leaf.text.slice(0, end.offset) + } + + if (Path.equals(path, start.path)) { + const leaf = Node.leaf(r, path) + leaf.text = leaf.text.slice(start.offset) + } + } + }) + } + + /** + * Find the furthest matching node entry starting from a specific path. + */ + + export const furthest = ( + root: Node, + path: Path, + predicate: (entry: NodeEntry) => boolean + ): NodeEntry | undefined => { + for (const entry of Node.levels(root, path, { reverse: true })) { + if (predicate(entry)) { + return entry + } + } + } + + /** + * Get the descendant node referred to by a specific path. If the path is an + * empty array, it refers to the root node itself. + */ + + export const get = (root: Node, path: Path): Node => { + let node = root + + for (let i = 0; i < path.length; i++) { + const p = path[i] + + if (Text.isText(node) || !node.nodes[p]) { + throw new Error( + `Could not find a descedant at path ${path} in node: ${root}` + ) + } + + node = node.nodes[p] + } + + return node + } + + /** + * Check if a descendant node exists at a specific path. + */ + + export const has = (root: Node, path: Path): boolean => { + let node = root + + for (let i = 0; i < path.length; i++) { + const p = path[i] + + if (Text.isText(node) || !node.nodes[p]) { + return false + } + + node = node.nodes[p] + } + + return true + } + + /** + * Check if a value implements the `Node` interface. + */ + + export const isNode = (value: any): value is Node => { + return ( + Text.isText(value) || Element.isElement(value) || Value.isValue(value) + ) + } + + /** + * Check if a value is a list of `Node` objects. + */ + + export const isNodeList = (value: any): value is Node[] => { + return Array.isArray(value) && (value.length === 0 || Node.isNode(value[0])) + } + + /** + * Get the node at a specific path, ensuring it's a leaf text node. + */ + + export const leaf = (root: Node, path: Path): Text => { + const node = Node.get(root, path) + + if (!Text.isText(node)) { + throw new Error( + `Cannot get the leaf node at ${path} because it refers to a non-leaf node: ${node}` + ) + } + + return node + } + + /** + * Return an iterable of the in a branch of the tree, from a specific path. + * + * By default the order is bottom-up, from lowest to highest node in the + * tree, but you can pass the `reverse: true` option to go top-down. + */ + + export function* levels( + root: Node, + path: Path, + options: { + reverse?: boolean + } = {} + ): Iterable { + for (const p of Path.levels(path, options)) { + const n = Node.get(root, p) + yield [n, p] + } + } + + /** + * Return an iterable of all the marks in all of the text nodes in a root node. + */ + + export function* marks( + root: Node, + options: { + path?: Path + range?: Range + reverse?: boolean + inclusive?: boolean + } = {} + ): Iterable { + for (const [node, path] of Node.texts(root, options)) { + for (let i = 0; i < node.marks.length; i++) { + const mark = node.marks[i] + yield [mark, i, node, path] + } + } + } + + /** + * Check if a node matches set of properties. + */ + + export const matches = (node: Node, props: Partial): boolean => { + for (const key in props) { + if (node[key] !== props[key]) { + return false + } + } + + return true + } + + /** + * Calculate the string offset of all the nodes before a node at a given path. + */ + + export const offset = (root: Node, path: Path): number => { + // PERF: We can exit early if the path is empty. + if (!path.length) { + return 0 + } + + if (Text.isText(root)) { + throw new Error(`Cannot get the offset into a text node: ${root}`) + } + + const [index] = path + const befores = root.nodes.slice(0, index) + let o = 0 + + for (const node of befores) { + o += Node.text(node).length + } + + const child = root.nodes[index] + const relPath = Path.relative(path, [index]) + o += Node.offset(child, relPath) + return o + } + + /** + * Get the parent of a node at a specific path. + */ + + export const parent = (root: Node, path: Path): Ancestor => { + const parentPath = Path.parent(path) + const parent = Node.get(root, parentPath) + + if (Text.isText(parent)) { + throw new Error( + `Cannot get the parent of path ${path} because it does not exist in the document.` + ) + } + + return parent + } + + /** + * Get the previous node at a specific path. + */ + + export const previous = (root: Node, path: Path): Node => { + const prevPath = Path.previous(path) + return Node.get(root, prevPath) + } + + /** + * Get the concatenated text string of a node's content. + * + * Note that this will not include spaces or line breaks between block nodes. + * It is not a user-facing string, but a string for performing offset-related + * computations for a node. + */ + + export const text = (node: Node): string => { + if (Text.isText(node)) { + return node.text + } else { + return node.nodes.map(text).join('') + } + } + + /** + * Return an iterable of all leaf text nodes in a root node. + */ + + export function* texts( + root: Node, + options: { + path?: Path + range?: Range + reverse?: boolean + inclusive?: boolean + } = {} + ): Iterable { + for (const [node, path] of Node.entries(root, options)) { + if (Text.isText(node)) { + yield [node, path] + } + } + } +} + +export { Ancestor, AncestorEntry, Descendant, DescendantEntry, Node, NodeEntry } diff --git a/packages/slate/src/interfaces/object.js b/packages/slate/src/interfaces/object.js deleted file mode 100644 index 6f4599ae39..0000000000 --- a/packages/slate/src/interfaces/object.js +++ /dev/null @@ -1,69 +0,0 @@ -import Annotation from '../models/annotation' -import Block from '../models/block' -import Change from '../models/change' -import Decoration from '../models/decoration' -import Document from '../models/document' -import Editor from '../controllers/editor' -import Inline from '../models/inline' -import Leaf from '../models/leaf' -import Mark from '../models/mark' -import Node from '../models/node' -import Operation from '../models/operation' -import Point from '../models/point' -import Range from '../models/range' -import Selection from '../models/selection' -import Text from '../models/text' -import Value from '../models/value' -import isObject, { TYPES } from '../utils/is-object' -import mixin from '../utils/mixin' - -/** - * A factory for the interface that all Slate objects implement. - * - * @type {Function} - */ - -function create(type) { - const TYPE = TYPES[type] - const camel = `${type.charAt(0).toUpperCase()}${type.slice(1)}` - const is = `is${camel}` - - class ObjectInterface { - /** - * Return the type of the object. - * - * @return {String} - */ - - get object() { - return type - } - } - - ObjectInterface[is] = isObject.bind(null, type) - ObjectInterface.prototype[TYPE] = true - return ObjectInterface -} - -/** - * Mix in the object interfaces. - */ - -Object.entries({ - Annotation, - Block, - Change, - Decoration, - Document, - Editor, - Inline, - Leaf, - Mark, - Node, - Operation, - Point, - Range, - Selection, - Text, - Value, -}).forEach(([camel, obj]) => mixin(create(camel.toLowerCase()), [obj])) diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts new file mode 100755 index 0000000000..a8c80730a2 --- /dev/null +++ b/packages/slate/src/interfaces/operation.ts @@ -0,0 +1,427 @@ +import { Annotation, Mark, Node, Path } from '..' +import isPlainObject from 'is-plain-object' + +interface AddMarkOperation { + type: 'add_mark' + path: Path + mark: Mark +} + +interface AddAnnotationOperation { + type: 'add_annotation' + key: string + annotation: Annotation +} + +interface InsertNodeOperation { + type: 'insert_node' + path: Path + node: Node +} + +interface InsertTextOperation { + type: 'insert_text' + path: Path + offset: number + text: string +} + +interface MergeNodeOperation { + type: 'merge_node' + path: Path + position: number + target: number | null + properties: {} +} + +interface MoveNodeOperation { + type: 'move_node' + path: Path + newPath: Path +} + +interface RemoveAnnotationOperation { + type: 'remove_annotation' + key: string + annotation: Annotation +} + +interface RemoveMarkOperation { + type: 'remove_mark' + path: Path + mark: Mark +} + +interface RemoveNodeOperation { + type: 'remove_node' + path: Path + node: Node +} + +interface RemoveTextOperation { + type: 'remove_text' + path: Path + offset: number + text: string +} + +interface SetAnnotationOperation { + type: 'set_annotation' + key: string + properties: {} + newProperties: {} +} + +interface SetMarkOperation { + type: 'set_mark' + path: Path + properties: {} + newProperties: {} +} + +interface SetNodeOperation { + type: 'set_node' + path: Path + properties: {} + newProperties: {} +} + +interface SetSelectionOperation { + type: 'set_selection' + properties: {} | null + newProperties: {} | null +} + +interface SetValueOperation { + type: 'set_value' + properties: {} + newProperties: {} +} + +interface SplitNodeOperation { + type: 'split_node' + path: Path + position: number + target: number | null + properties: {} +} + +/** + * `Operation` objects define the low-level instructions that Slate editors use + * to apply changes to their internal state. Representing all changes as + * operations is what allows Slate editors to easily implement history, + * collaboration, and other features. + */ + +type Operation = + | AnnotationOperation + | NodeOperation + | MarkOperation + | SelectionOperation + | TextOperation + | ValueOperation + +type AnnotationOperation = + | AddAnnotationOperation + | RemoveAnnotationOperation + | SetAnnotationOperation + +type NodeOperation = + | InsertNodeOperation + | MergeNodeOperation + | MoveNodeOperation + | RemoveNodeOperation + | SetNodeOperation + | SplitNodeOperation + +type MarkOperation = AddMarkOperation | RemoveMarkOperation | SetMarkOperation + +type SelectionOperation = SetSelectionOperation + +type TextOperation = InsertTextOperation | RemoveTextOperation + +type ValueOperation = SetValueOperation + +namespace Operation { + /** + * Check of a value is an `AnnotationOperation` object. + */ + + export const isAnnotationOperation = ( + value: any + ): value is AnnotationOperation => { + return Operation.isOperation(value) && value.type.endsWith('_annotation') + } + + /** + * Check of a value is a `NodeOperation` object. + */ + + export const isNodeOperation = (value: any): value is NodeOperation => { + return Operation.isOperation(value) && value.type.endsWith('_node') + } + + /** + * Check of a value is a `MarkOperation` object. + */ + + export const isMarkOperation = (value: any): value is MarkOperation => { + return Operation.isOperation(value) && value.type.endsWith('_mark') + } + + /** + * Check of a value is an `Operation` object. + */ + + export const isOperation = (value: any): value is Operation => { + if (!isPlainObject(value)) { + return false + } + + switch (value.type) { + case 'add_mark': { + return Path.isPath(value.path) && Mark.isMark(value.mark) + } + + case 'add_annotation': { + return ( + typeof value.key === 'string' && + Annotation.isAnnotation(value.annotation) + ) + } + case 'insert_node': { + return Path.isPath(value.path) && Node.isNode(value.node) + } + + case 'insert_text': { + return ( + typeof value.offset === 'number' && + typeof value.text === 'string' && + Path.isPath(value.path) + ) + } + + case 'merge_node': { + return ( + typeof value.position === 'number' && + (typeof value.target === 'number' || value.target === null) && + Path.isPath(value.path) && + isPlainObject(value.properties) + ) + } + + case 'move_node': { + return Path.isPath(value.path) && Path.isPath(value.newPath) + } + + case 'remove_annotation': { + return ( + typeof value.key === 'string' && + Annotation.isAnnotation(value.annotation) + ) + } + + case 'remove_mark': { + return Path.isPath(value.path) && Mark.isMark(value.mark) + } + + case 'remove_node': { + return Path.isPath(value.path) && Node.isNode(value.node) + } + + case 'remove_text': { + return ( + typeof value.offset === 'number' && + typeof value.text === 'string' && + Path.isPath(value.path) + ) + } + + case 'set_annotation': { + return ( + typeof value.key === 'string' && + isPlainObject(value.properties) && + isPlainObject(value.newProperties) + ) + } + + case 'set_mark': { + return ( + Path.isPath(value.path) && + isPlainObject(value.properties) && + isPlainObject(value.newProperties) + ) + } + + case 'set_node': { + return ( + Path.isPath(value.path) && + isPlainObject(value.properties) && + isPlainObject(value.newProperties) + ) + } + + case 'set_selection': { + return ( + isPlainObject(value.properties) && isPlainObject(value.newProperties) + ) + } + + case 'set_value': { + return ( + isPlainObject(value.properties) && isPlainObject(value.newProperties) + ) + } + + case 'split_node': { + return ( + Path.isPath(value.path) && + typeof value.position === 'number' && + (typeof value.target === 'number' || value.target === null) && + isPlainObject(value.properties) + ) + } + + default: { + return false + } + } + } + + /** + * Check if a value is a list of `Operation` objects. + */ + + export const isOperationList = (value: any): value is Operation[] => { + return ( + Array.isArray(value) && + (value.length === 0 || Operation.isOperation(value[0])) + ) + } + + /** + * Check of a value is a `SelectionOperation` object. + */ + + export const isSelectionOperation = ( + value: any + ): value is SelectionOperation => { + return Operation.isOperation(value) && value.type.endsWith('_selection') + } + + /** + * Check of a value is a `TextOperation` object. + */ + + export const isTextOperation = (value: any): value is TextOperation => { + return Operation.isOperation(value) && value.type.endsWith('_text') + } + + /** + * Check of a value is a `ValueOperation` object. + */ + + export const isValueOperation = (value: any): value is ValueOperation => { + return Operation.isOperation(value) && value.type.endsWith('_value') + } + + /** + * Invert an operation, returning a new operation that will exactly undo the + * original when applied. + */ + + export const inverse = (op: Operation): Operation => { + switch (op.type) { + case 'add_annotation': { + return { ...op, type: 'remove_annotation' } + } + + case 'add_mark': { + return { ...op, type: 'remove_mark' } + } + + case 'insert_node': { + return { ...op, type: 'insert_node' } + } + + case 'insert_text': { + return { ...op, type: 'remove_text' } + } + + case 'merge_node': { + return { ...op, type: 'split_node', path: Path.previous(op.path) } + } + + case 'move_node': { + const { newPath, path } = op + + // PERF: in this case the move operation is a no-op anyways. + if (Path.equals(newPath, path)) { + return op + } + + // We need to get the original path here, but sometimes the `newPath` + // is a younger sibling of (or ends before) the original, and this + // accounts for it. + return { + ...op, + path: Path.transform(path, op)!, + newPath: Path.transform(Path.next(path), op)!, + } + } + + case 'remove_annotation': { + return { ...op, type: 'add_annotation' } + } + + case 'remove_mark': { + return { ...op, type: 'add_mark' } + } + + case 'remove_node': { + return { ...op, type: 'insert_node' } + } + + case 'remove_text': { + return { ...op, type: 'insert_text' } + } + + case 'set_annotation': + case 'set_mark': + case 'set_node': + case 'set_value': { + const { properties, newProperties } = op + return { ...op, properties: newProperties, newProperties: properties } + } + + case 'set_selection': { + const { properties, newProperties } = op + return { ...op, properties: newProperties, newProperties: properties } + } + + case 'split_node': { + return { ...op, type: 'merge_node', path: Path.next(op.path) } + } + } + } +} + +export { + AddMarkOperation, + AddAnnotationOperation, + InsertNodeOperation, + InsertTextOperation, + MergeNodeOperation, + MoveNodeOperation, + RemoveAnnotationOperation, + RemoveMarkOperation, + RemoveNodeOperation, + RemoveTextOperation, + SetAnnotationOperation, + SetMarkOperation, + SetNodeOperation, + SetSelectionOperation, + SetValueOperation, + SplitNodeOperation, + Operation, +} diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts new file mode 100755 index 0000000000..1c01fb7920 --- /dev/null +++ b/packages/slate/src/interfaces/path.ts @@ -0,0 +1,422 @@ +import { produce } from 'immer' +import { Operation } from '..' + +/** + * `Path` arrays are a list of indexes that describe a node's exact position in + * a Slate node tree. Although they are usually relative to the root `Value` + * object, they can be relative to any `Node` object. + */ + +type Path = number[] + +namespace Path { + /** + * Get a list of ancestor paths for a given path. + * + * The paths are sorted from deepest to shallowest ancestor. However, if the + * `reverse: true` option is passed, they are reversed. + */ + + export const ancestors = ( + path: Path, + options: { reverse?: boolean } = {} + ): Path[] => { + const { reverse = false } = options + let paths = Path.levels(path, options) + + if (reverse) { + paths = paths.slice(0, -1) + } else { + paths = paths.slice(1) + } + + return paths + } + + /** + * Get the common ancestor path of two paths. + */ + + export const common = (path: Path, another: Path): Path => { + const common: Path = [] + + for (let i = 0; i < path.length && i < another.length; i++) { + const av = path[i] + const bv = another[i] + + if (av !== bv) { + break + } + + common.push(av) + } + + return common + } + + /** + * Compare a path to another, returning an integer indicating whether the path + * was before, at, or after the other. + * + * Note: Two paths of unequal length can still receive a `0` result if one is + * directly above or below the other. If you want exact matching, use + * [[Path.equals]] instead. + */ + + export const compare = (path: Path, another: Path): -1 | 0 | 1 => { + const min = Math.min(path.length, another.length) + + for (let i = 0; i < min; i++) { + if (path[i] < another[i]) return -1 + if (path[i] > another[i]) return 1 + } + + return 0 + } + + /** + * Check if a path ends after one of the indexes in another. + */ + + export const endsAfter = (path: Path, another: Path): boolean => { + const i = path.length - 1 + const as = path.slice(0, i) + const bs = another.slice(0, i) + const av = path[i] + const bv = another[i] + return Path.equals(as, bs) && av > bv + } + + /** + * Check if a path ends at one of the indexes in another. + */ + + export const endsAt = (path: Path, another: Path): boolean => { + const i = path.length + const as = path.slice(0, i) + const bs = another.slice(0, i) + return Path.equals(as, bs) + } + + /** + * Check if a path ends before one of the indexes in another. + */ + + export const endsBefore = (path: Path, another: Path): boolean => { + const i = path.length - 1 + const as = path.slice(0, i) + const bs = another.slice(0, i) + const av = path[i] + const bv = another[i] + return Path.equals(as, bs) && av < bv + } + + /** + * Check if a path is exactly equal to another. + */ + + export const equals = (path: Path, another: Path): boolean => { + return ( + path.length === another.length && path.every((n, i) => n === another[i]) + ) + } + + /** + * Check if a path is after another. + */ + + export const isAfter = (path: Path, another: Path): boolean => { + return Path.compare(path, another) === 1 + } + + /** + * Check if a path is an ancestor of another. + */ + + export const isAncestor = (path: Path, another: Path): boolean => { + return path.length > another.length && Path.compare(path, another) === 0 + } + + /** + * Check if a path is before another. + */ + + export const isBefore = (path: Path, another: Path): boolean => { + return Path.compare(path, another) === -1 + } + + /** + * Check if a path is a child of another. + */ + + export const isChild = (path: Path, another: Path): boolean => { + return ( + path.length === another.length + 1 && Path.compare(path, another) === 0 + ) + } + + /** + * Check if a path is a descendant of another. + */ + + export const isDescendant = (path: Path, another: Path): boolean => { + return path.length < another.length && Path.compare(path, another) === 0 + } + + /** + * Check if a path is the parent of another. + */ + + export const isParent = (path: Path, another: Path): boolean => { + return ( + path.length + 1 === another.length && Path.compare(path, another) === 0 + ) + } + + /** + * Check is a value implements the `Path` interface. + */ + + export const isPath = (value: any): value is Path => { + return ( + Array.isArray(value) && + (value.length === 0 || typeof value[0] === 'number') + ) + } + + /** + * Check if a path is a sibling of another. + */ + + export const isSibling = (path: Path, another: Path): boolean => { + if (path.length !== another.length) { + return false + } + + const as = path.slice(0, -1) + const bs = another.slice(0, -1) + return Path.equals(as, bs) + } + + /** + * Get a list of paths at every level down to a path. Note: this is the same + * as `Path.ancestors`, but including the path itself. + * + * The paths are sorted from deepest to shallowest. However, if the + * `reverse: true` option is passed, they are reversed. + */ + + export const levels = ( + path: Path, + options: { + reverse?: boolean + } = {} + ): Path[] => { + const { reverse = false } = options + const list: Path[] = [] + + for (let i = path.length; i >= 0; i--) { + list.push(path.slice(0, i)) + } + + if (reverse) { + list.reverse() + } + + return list + } + + /** + * Given a path, get the path to the next sibling node. + */ + + export const next = (path: Path): Path => { + if (path.length === 0) { + throw new Error( + `Cannot get the next path of a root path ${path}, because it has no next index.` + ) + } + + const last = path[path.length - 1] + return path.slice(0, -1).concat(last + 1) + } + + /** + * Given a path, return a new path referring to the parent node above it. + */ + + export const parent = (path: Path): Path => { + if (path.length === 0) { + throw new Error(`Cannot get the parent path of the root path ${path}.`) + } + + return path.slice(0, -1) + } + + /** + * Given a path, get the path to the previous sibling node. + */ + + export const previous = (path: Path): Path => { + if (path.length === 0) { + throw new Error( + `Cannot get the previous path of a root path ${path}, because it has no previous index.` + ) + } + + const last = path[path.length - 1] + + if (last >= 0) { + throw new Error( + `Cannot get the previous path of a first child path ${path} because it would result in a negative index.` + ) + } + + return path.slice(0, -1).concat(last - 1) + } + + /** + * Get a path relative to an ancestor. + */ + + export const relative = (path: Path, ancestor: Path): Path => { + if (!isAncestor(ancestor, path)) { + throw new Error( + `Cannot get the relative path of ${path} inside ancestor ${ancestor}, because it is not an ancestor of the path.` + ) + } + + return path.slice(ancestor.length) + } + + /** + * Transform a path by an operation. + */ + + export const transform = ( + path: Path, + operation: Operation, + options: { stick?: 'forward' | 'backward' | null } = {} + ): Path | null => { + return produce(path, p => { + const { stick = 'forward' } = options + + // PERF: Exit early if the operation is guaranteed not to have an effect. + if (path.length === 0) { + return + } + + switch (operation.type) { + case 'add_mark': + case 'insert_text': + case 'remove_mark': + case 'remove_text': + case 'set_mark': + case 'set_node': + case 'set_selection': + case 'set_value': + case 'add_annotation': + case 'remove_annotation': + case 'set_annotation': { + // None of these operations have an affect on paths. + return + } + + case 'insert_node': { + const { path: op } = operation + + if ( + Path.equals(op, p) || + Path.endsBefore(op, p) || + Path.isAncestor(op, p) + ) { + p[op.length - 1] += 1 + } + + break + } + + case 'remove_node': { + const { path: op } = operation + + if (Path.equals(op, p) || Path.isAncestor(op, p)) { + return null + } else if (Path.endsBefore(op, p)) { + p[op.length - 1] -= 1 + } + + break + } + + case 'merge_node': { + const { path: op, position } = operation + + if (Path.equals(op, p) || Path.endsBefore(op, p)) { + p[op.length - 1] -= 1 + } else if (Path.isAncestor(op, p)) { + p[op.length - 1] -= 1 + p[op.length] += position + } + + break + } + + case 'split_node': { + const { path: op, position } = operation + + if (Path.equals(op, p)) { + if (stick === 'forward') { + p[p.length - 1] += 1 + } else if (stick === 'backward') { + // Nothing, because it still refers to the right path. + } else { + return null + } + } else if (Path.endsBefore(op, p)) { + p[op.length - 1] += 1 + } else if (Path.isAncestor(op, p) && path[op.length] >= position) { + p[op.length - 1] += 1 + p[op.length] -= position + } + + break + } + + case 'move_node': { + const { path: op, newPath: onp } = operation + + // If the old and new path are the same, it's a no-op. + if (Path.equals(op, onp)) { + return + } + + if (Path.isAncestor(op, p) || Path.equals(op, p)) { + if (Path.endsBefore(op, onp) && op.length < onp.length) { + const i = Math.min(onp.length, op.length) - 1 + onp[i] -= 1 + } + + // Retain any indices past the move point in the original path. + onp.push(...p.slice(op.length)) + } else { + if (Path.endsBefore(op, p)) { + p[op.length - 1] -= 1 + } + + if ( + Path.endsBefore(onp, p) || + Path.equals(onp, p) || + Path.isAncestor(onp, p) + ) { + p[onp.length - 1] += 1 + } + } + + break + } + } + }) + } +} + +export { Path } diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts new file mode 100755 index 0000000000..e0b279d035 --- /dev/null +++ b/packages/slate/src/interfaces/point.ts @@ -0,0 +1,149 @@ +import isPlainObject from 'is-plain-object' +import { produce } from 'immer' +import { Operation, Path } from '..' + +/** + * `Point` objects refer to a specific location in a text node in a Slate + * document. Its path refers to the location of the node in the tree, and its + * offset refers to the distance into the node's string of text. Points can + * only refer to `Text` nodes. + */ + +interface Point { + path: Path + offset: number +} + +namespace Point { + /** + * Compare a point to another, returning an integer indicating whether the + * point was before, at, or after the other. + */ + + export const compare = (point: Point, another: Point): -1 | 0 | 1 => { + const result = Path.compare(point.path, another.path) + + if (result === 0) { + if (point.offset < another.offset) return -1 + if (point.offset > another.offset) return 1 + return 0 + } + + return result + } + + /** + * Check if a point is after another. + */ + + export const isAfter = (point: Point, another: Point): boolean => { + return Point.compare(point, another) === 1 + } + + /** + * Check if a point is before another. + */ + + export const isBefore = (point: Point, another: Point): boolean => { + return Point.compare(point, another) === 1 + } + + /** + * Check if a point is exactly equal to another. + */ + + export const equals = (point: Point, another: Point): boolean => { + // PERF: We could compare to a result of `0` here, but it's slightly faster + // to first ensure the offsets are equal and to use `Path.equals`. + return ( + point.offset === another.offset && Path.equals(point.path, another.path) + ) + } + + /** + * Check if a value implements the `Point` interface. + */ + + export const isPoint = (value: any): value is Point => { + return ( + isPlainObject(value) && + typeof value.offset === 'number' && + Path.isPath(value.path) + ) + } + + /** + * Transform a point by an operation. + */ + + export const transform = ( + point: Point, + op: Operation, + options: { stick?: 'forward' | 'backward' | null } = {} + ): Point | null => { + return produce(point, p => { + const { stick = 'forward' } = options + const { path, offset } = p + + switch (op.type) { + case 'insert_text': { + if (Path.equals(op.path, path) && op.offset <= offset) { + p.offset += op.text.length + } + + break + } + + case 'remove_text': { + if (Path.equals(op.path, path) && op.offset <= offset) { + p.offset -= Math.min(offset - op.offset, op.text.length) + } + + break + } + + case 'remove_node': { + if (Path.equals(op.path, path)) { + return null + } + + Path.transform(path, op, options) + break + } + + case 'split_node': { + if (Path.equals(op.path, path)) { + if (op.position === offset && stick == null) { + return null + } else if ( + op.position < offset || + (op.position === offset && stick === 'forward') + ) { + p.offset -= op.position + } + } + + Path.transform(path, op, options) + break + } + + case 'merge_node': { + if (Path.equals(op.path, path)) { + p.offset += op.position + } + + Path.transform(path, op, options) + break + } + + case 'insert_node': + case 'move_node': { + Path.transform(path, op, options) + break + } + } + }) + } +} + +export { Point } diff --git a/packages/slate/src/interfaces/range.js b/packages/slate/src/interfaces/range.js deleted file mode 100644 index 57bf6694d6..0000000000 --- a/packages/slate/src/interfaces/range.js +++ /dev/null @@ -1,707 +0,0 @@ -import warning from 'tiny-warning' - -import mixin from '../utils/mixin' -import Annotation from '../models/annotation' -import Decoration from '../models/decoration' -import PathUtils from '../utils/path-utils' -import Point from '../models/point' -import Range from '../models/range' -import Selection from '../models/selection' - -/** - * The interface that `Decoration`, `Range` and `Selection` all implement, to make - * working anchor and focus points easier. - * - * @type {Class} - */ - -class RangeInterface { - /** - * Check whether the range is collapsed. - * - * @return {Boolean} - */ - - get isCollapsed() { - const { anchor, focus } = this - - // PERF: If the points are actually equal we can abort faster. - if (anchor === focus) { - return true - } - - return ( - anchor.offset === focus.offset && - PathUtils.isEqual(anchor.path, focus.path) - ) - } - - /** - * Check whether the range is expanded. - * - * @return {Boolean} - */ - - get isExpanded() { - return !this.isCollapsed - } - - /** - * Check whether the range is backward. - * - * @return {Boolean} - */ - - get isBackward() { - const { isUnset, anchor, focus } = this - - if (isUnset) { - return null - } - - if (anchor.path.equals(focus.path)) { - return anchor.offset > focus.offset - } - - const isBackward = PathUtils.isBefore(focus.path, anchor.path) - return isBackward - } - - /** - * Check whether the range is forward. - * - * @return {Boolean} - */ - - get isForward() { - const { isBackward } = this - const isForward = isBackward == null ? null : !isBackward - return isForward - } - - /** - * Check whether the range isn't set. - * - * @return {Boolean} - */ - - get isUnset() { - const { anchor, focus } = this - const isUnset = anchor.isUnset || focus.isUnset - return isUnset - } - - /** - * Check whether the range is set. - * - * @return {Boolean} - */ - - get isSet() { - return !this.isUnset - } - - /** - * Get the start point. - * - * @return {String} - */ - - get start() { - return this.isBackward ? this.focus : this.anchor - } - - /** - * Get the end point. - * - * @return {String} - */ - - get end() { - return this.isBackward ? this.anchor : this.focus - } - - /** - * Flip the range. - * - * @return {Range} - */ - - flip() { - const range = this.setPoints([this.focus, this.anchor]) - return range - } - - /** - * Move the anchor and focus offsets forward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveForward(n) { - return this.updatePoints(point => point.moveForward(n)) - } - - /** - * Move the anchor and focus offsets backward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveBackward(n) { - return this.updatePoints(point => point.moveBackward(n)) - } - - /** - * Move the anchor offset backward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveAnchorBackward(n) { - const range = this.setAnchor(this.anchor.moveBackward(n)) - return range - } - - /** - * Move the anchor offset forward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveAnchorForward(n) { - const range = this.setAnchor(this.anchor.moveForward(n)) - return range - } - - /** - * Move the range's anchor point to a new `path` and `offset`. - * - * @param {List|String} path - * @param {Number} offset - * @return {Range} - */ - - moveAnchorTo(path, offset) { - const range = this.setAnchor(this.anchor.moveTo(path, offset)) - return range - } - - /** - * Move the range's anchor point to the start of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveAnchorToStartOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveAnchorToStartOfNode` method is deprecated.' - ) - - const range = this.setAnchor(this.anchor.moveToStartOfNode(node)) - return range - } - - /** - * Move the range's anchor point to the end of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveAnchorToEndOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveAnchorToEndOfNode` method is deprecated.' - ) - - const range = this.setAnchor(this.anchor.moveToEndOfNode(node)) - return range - } - - /** - * Move the end offset backward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveEndBackward(n) { - const range = this.setEnd(this.end.moveBackward(n)) - return range - } - - /** - * Move the end offset forward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveEndForward(n) { - const range = this.setEnd(this.end.moveForward(n)) - return range - } - - /** - * Move the range's end point to a new `path` and `offset`. - * - * @param {List|String} path - * @param {Number} offset - * @return {Range} - */ - - moveEndTo(path, offset) { - const range = this.setEnd(this.end.moveTo(path, offset)) - return range - } - - /** - * Move the range's end point to the start of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveEndToStartOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveEndToStartOfNode` method is deprecated.' - ) - - const range = this.setEnd(this.end.moveToStartOfNode(node)) - return range - } - - /** - * Move the range's end point to the end of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveEndToEndOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveEndToEndOfNode` method is deprecated.' - ) - - const range = this.setEnd(this.end.moveToEndOfNode(node)) - return range - } - - /** - * Move the focus offset backward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveFocusBackward(n) { - const range = this.setFocus(this.focus.moveBackward(n)) - return range - } - - /** - * Move the focus offset forward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveFocusForward(n) { - const range = this.setFocus(this.focus.moveForward(n)) - return range - } - - /** - * Move the range's focus point to a new `path` and `offset`. - * - * @param {List|String} path - * @param {Number} offset - * @return {Range} - */ - - moveFocusTo(path, offset) { - const range = this.setFocus(this.focus.moveTo(path, offset)) - return range - } - - /** - * Move the range's focus point to the start of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveFocusToStartOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveFocusToStartOfNode` method is deprecated.' - ) - - const range = this.setFocus(this.focus.moveToStartOfNode(node)) - return range - } - - /** - * Move the range's focus point to the end of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveFocusToEndOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveFocusToEndOfNode` method is deprecated.' - ) - - const range = this.setFocus(this.focus.moveToEndOfNode(node)) - return range - } - - /** - * Move the start offset backward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveStartBackward(n) { - const range = this.setStart(this.start.moveBackward(n)) - return range - } - - /** - * Move the start offset forward `n` characters. - * - * @param {Number} n - * @return {Range} - */ - - moveStartForward(n) { - const range = this.setStart(this.start.moveForward(n)) - return range - } - - /** - * Move the range's start point to a new `path` and `offset`. - * - * @param {List|String} path - * @param {Number} offset - * @return {Range} - */ - - moveStartTo(path, offset) { - const range = this.setStart(this.start.moveTo(path, offset)) - return range - } - - /** - * Move the range's start point to the start of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveStartToStartOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveStartToStartOfNode` method is deprecated.' - ) - - const range = this.setStart(this.start.moveToStartOfNode(node)) - return range - } - - /** - * Move the range's start point to the end of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveStartToEndOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveStartToEndOfNode` method is deprecated.' - ) - - const range = this.setStart(this.start.moveToEndOfNode(node)) - return range - } - - /** - * Move range's points to a new `path` and `offset`. - * - * @param {Number} n - * @return {Range} - */ - - moveTo(path, offset) { - return this.updatePoints(point => point.moveTo(path, offset)) - } - - /** - * Move the focus point to the anchor point. - * - * @return {Range} - */ - - moveToAnchor() { - const range = this.setFocus(this.anchor) - return range - } - - /** - * Move the start point to the end point. - * - * @return {Range} - */ - - moveToEnd() { - const range = this.setStart(this.end) - return range - } - - /** - * Move the range's points to the end of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveToEndOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveToEndOfNode` method is deprecated.' - ) - - return this.updatePoints(point => point.moveToEndOfNode(node)) - } - - /** - * Move the anchor point to the focus point. - * - * @return {Range} - */ - - moveToFocus() { - const range = this.setAnchor(this.focus) - return range - } - - /** - * Move to the entire range of `start` and `end` nodes. - * - * @param {Node} start - * @param {Node} end (optional) - * @return {Range} - */ - - moveToRangeOfNode(start, end = start) { - warning( - false, - 'As of slate@0.48 the `range.moveToRangeOfNode` method is deprecated.' - ) - - const range = this.setPoints([ - this.anchor.moveToStartOfNode(start), - this.focus.moveToEndOfNode(end), - ]) - - return range - } - - /** - * Move the end point to the start point. - * - * @return {Range} - */ - - moveToStart() { - const range = this.setEnd(this.start) - return range - } - - /** - * Move the range's points to the start of a `node`. - * - * @param {Node} node - * @return {Range} - */ - - moveToStartOfNode(node) { - warning( - false, - 'As of slate@0.48 the `range.moveToStartOfNode` method is deprecated.' - ) - - return this.updatePoints(point => point.moveToStartOfNode(node)) - } - - /** - * Normalize the range, relative to a `node`, ensuring that the anchor - * and focus nodes of the range always refer to leaf text nodes. - * - * @param {Node} node - * @return {Range} - */ - - normalize(node) { - return this.updatePoints(point => point.normalize(node)) - } - - /** - * Set the anchor point to a new `anchor`. - * - * @param {Point} anchor - * @return {Range} - */ - - setAnchor(anchor) { - const range = this.set('anchor', anchor) - return range - } - - /** - * Set the end point to a new `point`. - * - * @param {Point} point - * @return {Range} - */ - - setEnd(point) { - const range = this.isBackward ? this.setAnchor(point) : this.setFocus(point) - return range - } - - /** - * Set the focus point to a new `focus`. - * - * @param {Point} focus - * @return {Range} - */ - - setFocus(focus) { - const range = this.set('focus', focus) - return range - } - - /** - * Set the anchor and focus points to new `values`. - * - * @param {Array} values - * @return {Range} - */ - - setPoints(values) { - const [anchor, focus] = values - const range = this.set('anchor', anchor).set('focus', focus) - return range - } - - /** - * Set the anchor and focus points with `updater` callback - * - * @param {Function} updater - * @return {Range} - */ - - updatePoints(updater) { - let { anchor, focus } = this - anchor = updater(anchor) - focus = updater(focus) - return this.merge({ anchor, focus }) - } - - /** - * Set the start point to a new `point`. - * - * @param {Point} point - * @return {Range} - */ - - setStart(point) { - const range = this.isBackward ? this.setFocus(point) : this.setAnchor(point) - return range - } - - /** - * Set new `properties` on the range. - * - * @param {Object|Range} properties - * @return {Range} - */ - - setProperties(properties) { - properties = Range.createProperties(properties) - const { anchor, focus, ...props } = properties - - if (anchor) { - props.anchor = Point.create(anchor) - } - - if (focus) { - props.focus = Point.create(focus) - } - - const range = this.merge(props) - return range - } - - /** - * Return a JSON representation of the range. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - anchor: this.anchor.toJSON(options), - focus: this.focus.toJSON(options), - } - - return object - } - - /** - * Return a `Range` instance from any range-like instance. - * - * @return {Range} - */ - - toRange() { - const properties = Range.createProperties(this) - const range = Range.create(properties) - return range - } - - /** - * Unset the range. - * - * @return {Range} - */ - - unset() { - const range = this.updatePoints(p => p.unset()) - return range - } -} - -/** - * Mix in the range interface. - * - * @param {Record} - */ - -mixin(RangeInterface, [Annotation, Decoration, Range, Selection]) diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts new file mode 100755 index 0000000000..c2b8607ae2 --- /dev/null +++ b/packages/slate/src/interfaces/range.ts @@ -0,0 +1,158 @@ +import { produce } from 'immer' +import isPlainObject from 'is-plain-object' +import { Operation, Path, Point } from '..' + +/** + * `Range` objects are a set of points that refer to a specific span of a Slate + * document. They can define a span inside a single node or a can span across + * multiple nodes. + */ + +interface Range { + anchor: Point + focus: Point +} + +namespace Range { + /** + * Check if a range is exactly equal to another. + */ + + export const equals = (range: Range, another: Range): boolean => { + return ( + Point.equals(range.anchor, another.anchor) && + Point.equals(range.focus, another.focus) + ) + } + + /** + * Check if a range includes a path or a point. + */ + + export const includes = (range: Range, target: Path | Point): boolean => { + const [start, end] = Range.points(range) + + if (Point.isPoint(target)) { + return ( + (Point.equals(target, start) || Point.isAfter(target, start)) && + (Point.equals(target, end) || Point.isBefore(target, end)) + ) + } else { + return ( + (Path.equals(target, start.path) || Path.isAfter(target, start.path)) && + (Path.equals(target, end.path) || Path.isBefore(target, end.path)) + ) + } + } + + /** + * Check if a range is backward, meaning that its anchor point appears in the + * document _after_ its focus point. + */ + + export const isBackward = (range: Range): boolean => { + const { anchor, focus } = range + return Point.isAfter(anchor, focus) + } + + /** + * Check if a range is collapsed, meaning that both its anchor and focus + * points refer to the exact same position in the document. + */ + + export const isCollapsed = (range: Range): boolean => { + const { anchor, focus } = range + return Point.equals(anchor, focus) + } + + /** + * Check if a range is expanded. + * + * This is the opposite of [[Range.isCollapsed]] and is provided for legibility. + */ + + export const isExpanded = (range: Range): boolean => { + return !isCollapsed(range) + } + + /** + * Check if a range is forward. + * + * This is the opposite of [[Range.isBackward]] and is provided for legibility. + */ + + export const isForward = (range: Range): boolean => { + return !isBackward(range) + } + + /** + * Check if a value implements the [[Range]] interface. + */ + + export const isRange = (value: any): value is Range => { + return ( + isPlainObject(value) && + Point.isPoint(value.anchor) && + Point.isPoint(value.focus) + ) + } + + /** + * Get the start and end points of a range, in the order in which they appear + * in the document. + */ + + export const points = (range: Range): [Point, Point] => { + const { anchor, focus } = range + return Range.isBackward(range) ? [focus, anchor] : [anchor, focus] + } + + /** + * Transform a range by an operation. + */ + + export const transform = ( + range: Range, + op: Operation, + options: { stick: 'forward' | 'backward' | 'outward' | 'inward' | null } + ): Range | null => { + const { stick = 'inward' } = options + let stickAnchor: 'forward' | 'backward' | null + let stickFocus: 'forward' | 'backward' | null + + if (stick === 'inward') { + if (Range.isForward(range)) { + stickAnchor = 'forward' + stickFocus = 'backward' + } else { + stickAnchor = 'backward' + stickFocus = 'forward' + } + } else if (stick === 'outward') { + if (Range.isForward(range)) { + stickAnchor = 'backward' + stickFocus = 'forward' + } else { + stickAnchor = 'forward' + stickFocus = 'backward' + } + } else { + stickAnchor = stick + stickFocus = stick + } + + return produce(range, r => { + const anchor = Point.transform(r.anchor, op, { stick: stickAnchor }) + const focus = Point.transform(r.focus, op, { stick: stickFocus }) + + if (!anchor || !focus) { + return null + } + + r.anchor = anchor + r.focus = focus + }) + } +} + +export { Range } diff --git a/packages/slate/src/interfaces/selection.ts b/packages/slate/src/interfaces/selection.ts new file mode 100755 index 0000000000..4b30f2b6dc --- /dev/null +++ b/packages/slate/src/interfaces/selection.ts @@ -0,0 +1,37 @@ +import isPlainObject from 'is-plain-object' +import { Mark, Point, Range } from '..' + +/** + * `Selection` objects represent the range in a document that a user has + * selected with their cursor. They implement the `Range` interface, with an + * extra property denoting whether the editor is currently focused or not. + */ + +interface Selection extends Range { + isFocused: boolean + marks: Mark[] | null +} + +/** + * `SelectionPointEntry` objects are returned when iterating over `Point` + * objects that belong to an `Selection`. + */ + +type SelectionPointEntry = [Point, Selection] + +namespace Selection { + /** + * Check if a value implements the `Selection` interface. + */ + + export const isSelection = (value: any): value is Selection => { + return ( + isPlainObject(value) && + typeof value.isFocused === 'boolean' && + (value.marks == null || Mark.isMarkList(value.marks)) && + Range.isRange(value) + ) + } +} + +export { Selection, SelectionPointEntry } diff --git a/packages/slate/src/interfaces/string.ts b/packages/slate/src/interfaces/string.ts new file mode 100644 index 0000000000..bbdeeaf367 --- /dev/null +++ b/packages/slate/src/interfaces/string.ts @@ -0,0 +1,84 @@ +/** + * The `String` namespace holds functions that are helpful when working with + * text content strings in a rich text editor. + */ + +namespace String { + const SPACE = /\s/ + const PUNCTUATION = /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/ + const CHAMELEON = /['\u2018\u2019]/ + const SURROGATE_START = 0xd800 + const SURROGATE_END = 0xdfff + + /** + * Check if a character is a word character. The `remaining` argument is used + * because sometimes you must read subsequent characters to truly determine it. + */ + + export const isWordCharacter = (char: string, remaining: string): boolean => { + if (SPACE.test(char)) { + return false + } + + // Chameleons count as word characters as long as they're in a word, so + // recurse to see if the next one is a word character or not. + if (CHAMELEON.test(char)) { + let next = remaining.charAt(0) + const length = getCharacterDistance(next) + next = remaining.slice(0, length) + const rest = remaining.slice(length) + + if (isWordCharacter(next, rest)) { + return true + } + } + + if (PUNCTUATION.test(char)) { + return false + } + + return true + } + + /** + * Get the distance to the end of the first character in a string of text. + */ + + export const getCharacterDistance = (text: string): number => { + const code = text.charCodeAt(0) + const isSurrogate = SURROGATE_START <= code && code <= SURROGATE_END + return isSurrogate ? 2 : 1 + } + + /** + * Get the distance to the end of the first word in a string of text. + */ + + export const getWordDistance = (text: string): number => { + let length = 0 + let i = 0 + let started = false + let char + + while ((char = text.charAt(i))) { + const l = getCharacterDistance(char) + char = text.slice(i, i + l) + const rest = text.slice(i + l) + + if (isWordCharacter(char, rest)) { + started = true + length += l + } else if (!started) { + length += l + } else { + break + } + + i += l + } + + return length + } +} + +export { String } diff --git a/packages/slate/src/interfaces/text.ts b/packages/slate/src/interfaces/text.ts new file mode 100755 index 0000000000..2ea1b779a9 --- /dev/null +++ b/packages/slate/src/interfaces/text.ts @@ -0,0 +1,44 @@ +import isPlainObject from 'is-plain-object' +import { Mark, Path } from '..' + +/** + * `Text` objects represent the nodes that contain the actual text content of a + * Slate document along with any formatting marks. They are always leaf nodes in + * the document tree as they cannot contain any children. + */ + +interface Text { + text: string + marks: Mark[] +} + +/** + * `TextEntry` objects refer to an `Text` and the `Path` where it can be + * found inside a root node. + */ + +type TextEntry = [Text, Path] + +namespace Text { + /** + * Check if a value implements the `Text` interface. + */ + + export const isText = (value: any): value is Text => { + return ( + isPlainObject(value) && + typeof value.text === 'string' && + Array.isArray(value.marks) + ) + } + + /** + * Check if a value is a list of `Text` objects. + */ + + export const isTextList = (value: any): value is Text[] => { + return Array.isArray(value) && (value.length === 0 || Text.isText(value[0])) + } +} + +export { Text, TextEntry } diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts new file mode 100755 index 0000000000..3d0ae03f6d --- /dev/null +++ b/packages/slate/src/interfaces/value.ts @@ -0,0 +1,322 @@ +import isPlainObject from 'is-plain-object' +import { produce } from 'immer' +import { + Annotation, + AnnotationPointEntry, + Element, + Mark, + Node, + Operation, + Path, + Point, + Selection, + SelectionPointEntry, + Text, +} from '..' + +/** + * `Value` objects hold all of the state in a Slate editor, including all of the + * nodes in the document and the user's currently selected range of text. + */ + +interface Value extends Element { + selection: Selection | null + annotations: Record +} + +/** + * `ValueEntry` objects refer to an `Value` and the `Path` where it can be + * found inside a root node. + */ + +type ValueEntry = [Value, Path] + +namespace Value { + /** + * Check if a value implements the `Value` interface. + */ + + export const isValue = (value: any): value is Value => { + return ( + isPlainObject(value) && + Selection.isSelection(value.selection) && + Node.isNodeList(value.nodes) && + Annotation.isAnnotationRecord(value.annotations) + ) + } + + /** + * Iterate through all of the point objects in a value. + */ + + export function* points( + value: Value + ): Iterable { + const { selection, annotations } = value + + if (selection != null) { + yield [selection.anchor, selection] + yield [selection.focus, selection] + } + + for (const key in annotations) { + const annotation = annotations[key] + yield [annotation.anchor, annotation, key] + yield [annotation.focus, annotation, key] + } + } + + /** + * Transform a value by an operation. + */ + + export const transform = (value: Value, op: Operation): Value => { + return produce(value, v => { + switch (op.type) { + case 'add_annotation': { + const { annotation, key } = op + v.annotations[key] = annotation + break + } + + case 'add_mark': { + const { path, mark } = op + const node = Node.leaf(v, path) + + if (!Mark.exists(mark, node.marks)) { + node.marks.push(mark) + } + + break + } + + case 'insert_node': { + const { path, node } = op + const parent = Node.parent(v, path) + const index = path[path.length - 1] + parent.nodes[index] = node + + for (const [point] of Value.points(v)) { + Point.transform(point, op) + } + + break + } + + case 'insert_text': { + const { path, offset, text } = op + const node = Node.leaf(v, path) + const before = node.text.slice(0, offset) + const after = node.text.slice(offset) + node.text = before + text + after + + for (const [point] of Value.points(v)) { + Point.transform(point, op) + } + + break + } + + case 'merge_node': { + const { path } = op + const node = Node.get(v, path) + const prev = Node.previous(v, path) + const parent = Node.parent(v, path) + const index = path[path.length - 1] + + if (Text.isText(node) && Text.isText(prev)) { + prev.text = prev.text + node.text + } else if (!Text.isText(node) && !Text.isText(prev)) { + prev.nodes = prev.nodes.concat(node.nodes) + } else { + throw new Error( + `Cannot apply a "merge_node" operation at path ${path} to nodes of different interaces: ${node} ${prev}` + ) + } + + parent.nodes.splice(index, 1) + + for (const [point] of Value.points(v)) { + Point.transform(point, op) + } + + break + } + + case 'move_node': { + const { path } = op + const node = Node.get(v, path) + const parent = Node.parent(v, path) + const index = path[path.length - 1] + parent.nodes.splice(index, 1) + + // This is tricky, but since the `path` and `newPath` both refer to the + // same snapshot in time, after either inserting or removing as the + // first step, the second step's path can be out of date. So instead of + // using the `op.newPath` directly, we transform `op.path` to ascertain + // what the `newPath` would be after the operation was applied. + const newPath = Path.transform(path, op)! + const newParent = Node.parent(v, newPath) + const newIndex = newPath[newPath.length - 1] + newParent.nodes.splice(newIndex, 0, node) + + for (const [point] of Value.points(v)) { + Point.transform(point, op) + } + + break + } + + case 'remove_annotation': { + const { key } = op + delete v.annotations[key] + break + } + + case 'remove_mark': { + const { path, mark } = op + const node = Node.leaf(v, path) + + for (let i = 0; i < node.marks.length; i++) { + if (Mark.matches(node.marks[i], mark)) { + node.marks.splice(i, 1) + break + } + } + + break + } + + case 'remove_node': { + const { path } = op + const index = path[path.length - 1] + const parent = Node.parent(v, path) + parent.nodes.splice(index, 1) + + const [next] = Node.texts(v, { path, inclusive: false }) + const [prev] = Node.texts(v, { + path, + inclusive: false, + reverse: true, + }) + + // Transform all of the points in the value, but if the point was in the + // node that was removed we need to update the range or remove it. + for (const [point, range, key] of Value.points(v)) { + const result = Point.transform(point, op) + + if (result == null) { + if (prev) { + const [prevNode, prevPath] = prev + point.path = prevPath + point.offset = prevNode.text.length + } else if (next) { + const [, nextPath] = next + const newNextPath = Path.transform(nextPath, op)! + point.path = newNextPath + point.offset = 0 + } else if (Selection.isSelection(range)) { + v.selection = null + } else if (Annotation.isAnnotation(range)) { + delete v.annotations[key!] + } + } + } + + break + } + + case 'remove_text': { + const { path, offset, text } = op + const node = Node.leaf(v, path) + const before = node.text.slice(0, offset) + const after = node.text.slice(offset + text.length) + node.text = before + after + + for (const [point] of Value.points(v)) { + Point.transform(point, op) + } + + break + } + + case 'set_annotation': { + const { key, newProperties } = op + const annotation = v.annotations[key] + Object.assign(annotation, newProperties) + break + } + + case 'set_mark': { + const { path, properties, newProperties } = op + const node = Node.leaf(v, path) + + for (const mark of node.marks) { + if (Mark.matches(mark, properties)) { + Object.assign(mark, newProperties) + break + } + } + + break + } + + case 'set_node': { + const { path, newProperties } = op + const node = Node.get(v, path) + Object.assign(node, newProperties) + break + } + + case 'set_selection': { + const { newProperties } = op + Object.assign(v.selection, newProperties) + break + } + + case 'set_value': { + const { newProperties } = op + Object.assign(v, newProperties) + break + } + + case 'split_node': { + const { path, position, properties } = op + + if (path.length === 0) { + throw new Error( + `Cannot apply a "split_node" operation at path ${path} because the top-level value cannot be split.` + ) + } + + const node = Node.get(v, path) + const parent = Node.parent(v, path) + const index = path[path.length - 1] + let newNode: Node + + if (Text.isText(node)) { + const before = node.text.slice(0, position) + const after = node.text.slice(position) + node.text = before + newNode = { ...node, ...properties, text: after } + } else { + const before = node.nodes.slice(0, position) + const after = node.nodes.slice(position) + node.nodes = before + newNode = { ...node, ...properties, nodes: after } + } + + parent.nodes.splice(index + 1, 0, newNode) + + for (const [point] of Value.points(v)) { + Point.transform(point, op) + } + + break + } + } + }) + } +} + +export { Value, ValueEntry } diff --git a/packages/slate/src/models/annotation.js b/packages/slate/src/models/annotation.js deleted file mode 100644 index 777d274cbd..0000000000 --- a/packages/slate/src/models/annotation.js +++ /dev/null @@ -1,193 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Map, Record } from 'immutable' - -import Point from './point' -import Range from './range' -import Data from './data' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - key: undefined, - type: undefined, - data: undefined, - anchor: undefined, - focus: undefined, -} - -/** - * Annotation. - * - * @type {Annotation} - */ - -class Annotation extends Record(DEFAULTS) { - /** - * Create a new `Annotation` with `attrs`. - * - * @param {Object|Annotation} attrs - * @return {Annotation} - */ - - static create(attrs = {}) { - if (Annotation.isAnnotation(attrs)) { - return attrs - } - - if (Range.isRange(attrs)) { - return Annotation.fromJSON(Range.createProperties(attrs)) - } - - if (isPlainObject(attrs)) { - return Annotation.fromJSON(attrs) - } - - throw new Error( - `\`Annotation.create\` only accepts objects or annotations, but you passed it: ${attrs}` - ) - } - - /** - * Create a map of annotations from `elements`. - * - * @param {Object|Map} elements - * @return {Map} - */ - - static createMap(elements = []) { - if (Map.isMap(elements)) { - return elements - } - - if (isPlainObject(elements)) { - const obj = {} - - for (const key in elements) { - const value = elements[key] - const annotation = Annotation.create(value) - obj[key] = annotation - } - - return Map(obj) - } - - throw new Error( - `\`Annotation.createMap\` only accepts arrays or lists, but you passed it: ${elements}` - ) - } - - /** - * Create a dictionary of settable annotation properties from `attrs`. - * - * @param {Object|String|Annotation} attrs - * @return {Object} - */ - - static createProperties(a = {}) { - if (Annotation.isAnnotation(a)) { - return { - key: a.key, - type: a.type, - data: a.data, - anchor: Point.createProperties(a.anchor), - focus: Point.createProperties(a.focus), - } - } - - if (isPlainObject(a)) { - const p = {} - if ('key' in a) p.key = a.key - if ('type' in a) p.type = a.type - if ('data' in a) p.data = Data.create(a.data) - if ('anchor' in a) p.anchor = Point.create(a.anchor) - if ('focus' in a) p.focus = Point.create(a.focus) - return p - } - - throw new Error( - `\`Annotation.createProperties\` only accepts objects or annotations, but you passed it: ${a}` - ) - } - - /** - * Create a `Annotation` from a JSON `object`. - * - * @param {Object} object - * @return {Annotation} - */ - - static fromJSON(object) { - const { key, type, data, anchor, focus } = object - - if (!key) { - throw new Error( - `Annotations must be created with a \`key\`, but you passed: ${JSON.stringify( - object - )}` - ) - } - - if (!type) { - throw new Error( - `Annotations must be created with a \`type\`, but you passed: ${JSON.stringify( - object - )}` - ) - } - - const annotation = new Annotation({ - key, - type, - data: Data.create(data || {}), - anchor: Point.fromJSON(anchor || {}), - focus: Point.fromJSON(focus || {}), - }) - - return annotation - } - - /** - * Set new `properties` on the annotation. - * - * @param {Object|Range|Selection} properties - * @return {Range} - */ - - setProperties(properties) { - properties = Annotation.createProperties(properties) - const annotation = this.merge(properties) - return annotation - } - - /** - * Return a JSON representation of the annotation. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - key: this.key, - type: this.type, - data: this.data.toJSON(), - anchor: this.anchor.toJSON(options), - focus: this.focus.toJSON(options), - } - - return object - } -} - -/** - * Export. - * - * @type {Annotation} - */ - -export default Annotation diff --git a/packages/slate/src/models/block.js b/packages/slate/src/models/block.js deleted file mode 100644 index 3b6ac03de2..0000000000 --- a/packages/slate/src/models/block.js +++ /dev/null @@ -1,138 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { List, Map, Record } from 'immutable' - -import KeyUtils from '../utils/key-utils' -import Node from './node' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - data: undefined, - key: undefined, - nodes: undefined, - type: undefined, -} - -/** - * Block. - * - * @type {Block} - */ - -class Block extends Record(DEFAULTS) { - /** - * Create a new `Block` from `attrs`. - * - * @param {Object|String|Block} attrs - * @return {Block} - */ - - static create(attrs = {}) { - if (Block.isBlock(attrs)) { - return attrs - } - - if (typeof attrs === 'string') { - attrs = { type: attrs } - } - - if (isPlainObject(attrs)) { - return Block.fromJSON(attrs) - } - - throw new Error( - `\`Block.create\` only accepts objects, strings or blocks, but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Blocks` from `attrs`. - * - * @param {Array|List} attrs - * @return {List} - */ - - static createList(attrs = []) { - if (List.isList(attrs) || Array.isArray(attrs)) { - const list = new List(attrs.map(Block.create)) - return list - } - - throw new Error( - `\`Block.createList\` only accepts arrays or lists, but you passed it: ${attrs}` - ) - } - - /** - * Create a `Block` from a JSON `object`. - * - * @param {Object|Block} object - * @return {Block} - */ - - static fromJSON(object) { - if (Block.isBlock(object)) { - return object - } - - const { data = {}, key = KeyUtils.create(), nodes = [], type } = object - - if (typeof type !== 'string') { - throw new Error('`Block.fromJSON` requires a `type` string.') - } - - const block = new Block({ - key, - type, - data: Map(data), - nodes: Node.createList(nodes), - }) - - return block - } - - /** - * Check if `any` is a block list. - * - * @param {Any} any - * @return {Boolean} - */ - - static isBlockList(any) { - return List.isList(any) && any.every(item => Block.isBlock(item)) - } - - /** - * Return a JSON representation of the block. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - type: this.type, - data: this.data.toJSON(), - nodes: this.nodes.toArray().map(n => n.toJSON(options)), - } - - if (options.preserveKeys) { - object.key = this.key - } - - return object - } -} - -/** - * Export. - * - * @type {Block} - */ - -export default Block diff --git a/packages/slate/src/models/change.js b/packages/slate/src/models/change.js deleted file mode 100644 index 5a4362d6dd..0000000000 --- a/packages/slate/src/models/change.js +++ /dev/null @@ -1,88 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Record } from 'immutable' - -import Operation from './operation' -import Value from './value' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - operations: undefined, - value: undefined, -} - -/** - * Change. - * - * @type {Change} - */ - -class Change extends Record(DEFAULTS) { - /** - * Create a new `Change` with `attrs`. - * - * @param {Object|Change} attrs - * @return {Change} - */ - - static create(attrs = {}) { - if (Change.isChange(attrs)) { - return attrs - } - - if (isPlainObject(attrs)) { - return Change.fromJSON(attrs) - } - - throw new Error( - `\`Change.create\` only accepts objects or changes, but you passed it: ${attrs}` - ) - } - - /** - * Create a `Change` from a JSON `object`. - * - * @param {Object} object - * @return {Change} - */ - - static fromJSON(object) { - const { value, operations = [] } = object - - const change = new Change({ - value: Value.create(value), - operations: Operation.createList(operations), - }) - - return change - } - - /** - * Return a JSON representation of the change. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - value: this.value.toJSON(options), - operations: this.operations.toArray().map(o => o.toJSON(options)), - } - - return object - } -} - -/** - * Export. - * - * @type {Change} - */ - -export default Change diff --git a/packages/slate/src/models/data.js b/packages/slate/src/models/data.js deleted file mode 100644 index e51ef87333..0000000000 --- a/packages/slate/src/models/data.js +++ /dev/null @@ -1,59 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Map } from 'immutable' - -/** - * Data. - * - * This isn't an immutable record, it's just a thin wrapper around `Map` so that - * we can allow for more convenient creation. - * - * @type {Object} - */ - -class Data { - /** - * Create a new `Data` with `attrs`. - * - * @param {Object|Data|Map} attrs - * @return {Data} data - */ - - static create(attrs = {}) { - if (Map.isMap(attrs)) { - return attrs - } - - if (isPlainObject(attrs)) { - return Data.fromJSON(attrs) - } - - throw new Error( - `\`Data.create\` only accepts objects or maps, but you passed it: ${attrs}` - ) - } - - /** - * Create a `Data` from a JSON `object`. - * - * @param {Object} object - * @return {Data} - */ - - static fromJSON(object) { - return new Map(object) - } - - /** - * Alias `fromJS`. - */ - - static fromJS = Data.fromJSON -} - -/** - * Export. - * - * @type {Object} - */ - -export default Data diff --git a/packages/slate/src/models/decoration.js b/packages/slate/src/models/decoration.js deleted file mode 100644 index d0983bfabf..0000000000 --- a/packages/slate/src/models/decoration.js +++ /dev/null @@ -1,183 +0,0 @@ -import isPlainObject from 'is-plain-object' -import warning from 'tiny-warning' -import { List, Record } from 'immutable' - -import Mark from './mark' -import Point from './point' -import Data from './data' -import Range from './range' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - type: undefined, - data: undefined, - anchor: undefined, - focus: undefined, -} - -/** - * Decoration. - * - * @type {Decoration} - */ - -class Decoration extends Record(DEFAULTS) { - /** - * Create a new `Decoration` with `attrs`. - * - * @param {Object|Decoration} attrs - * @return {Decoration} - */ - - static create(attrs = {}) { - if (Decoration.isDecoration(attrs)) { - return attrs - } - - if (Range.isRange(attrs)) { - return Decoration.fromJSON(Range.createProperties(attrs)) - } - - if (isPlainObject(attrs)) { - return Decoration.fromJSON(attrs) - } - - throw new Error( - `\`Decoration.create\` only accepts objects or decorations, but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Ranges` from `elements`. - * - * @param {Array|List} elements - * @return {List} - */ - - static createList(elements = []) { - if (List.isList(elements) || Array.isArray(elements)) { - const list = new List(elements.map(Decoration.create)) - return list - } - - throw new Error( - `\`Decoration.createList\` only accepts arrays or lists, but you passed it: ${elements}` - ) - } - - /** - * Create a dictionary of settable decoration properties from `attrs`. - * - * @param {Object|String|Decoration} attrs - * @return {Object} - */ - - static createProperties(a = {}) { - if (Decoration.isDecoration(a)) { - return { - type: a.type, - data: a.data, - anchor: Point.createProperties(a.anchor), - focus: Point.createProperties(a.focus), - mark: Mark.create(a.mark), - } - } - - if (isPlainObject(a)) { - const p = {} - if ('type' in a) p.type = a.type - if ('data' in a) p.data = Data.create(a.data) - if ('anchor' in a) p.anchor = Point.create(a.anchor) - if ('focus' in a) p.focus = Point.create(a.focus) - return p - } - - throw new Error( - `\`Decoration.createProperties\` only accepts objects or decorations, but you passed it: ${a}` - ) - } - - /** - * Create a `Decoration` from a JSON `object`. - * - * @param {Object} object - * @return {Decoration} - */ - - static fromJSON(object) { - const { anchor, focus } = object - let { type, data } = object - - if (object.mark && !type) { - warning( - false, - 'As of slate@0.47 the `decoration.mark` property has been changed to `decoration.type` and `decoration.data` directly.' - ) - - type = object.mark.type - data = object.mark.data - } - - if (!type) { - throw new Error( - `Decorations must be created with a \`type\`, but you passed: ${JSON.stringify( - object - )}` - ) - } - - const decoration = new Decoration({ - type, - data: Data.create(data || {}), - anchor: Point.fromJSON(anchor || {}), - focus: Point.fromJSON(focus || {}), - }) - - return decoration - } - - /** - * Set new `properties` on the decoration. - * - * @param {Object|Range|Selection} properties - * @return {Range} - */ - - setProperties(properties) { - properties = Decoration.createProperties(properties) - const decoration = this.merge(properties) - return decoration - } - - /** - * Return a JSON representation of the decoration. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - type: this.type, - data: this.data.toJSON(), - anchor: this.anchor.toJSON(options), - focus: this.focus.toJSON(options), - } - - return object - } -} - -/** - * Export. - * - * @type {Decoration} - */ - -export default Decoration diff --git a/packages/slate/src/models/document.js b/packages/slate/src/models/document.js deleted file mode 100644 index ad76c99c69..0000000000 --- a/packages/slate/src/models/document.js +++ /dev/null @@ -1,102 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { List, Map, Record } from 'immutable' - -import KeyUtils from '../utils/key-utils' -import Node from './node' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - data: undefined, - key: undefined, - nodes: undefined, -} - -/** - * Document. - * - * @type {Document} - */ - -class Document extends Record(DEFAULTS) { - /** - * Create a new `Document` with `attrs`. - * - * @param {Object|Array|List|Text} attrs - * @return {Document} - */ - - static create(attrs = {}) { - if (Document.isDocument(attrs)) { - return attrs - } - - if (List.isList(attrs) || Array.isArray(attrs)) { - attrs = { nodes: attrs } - } - - if (isPlainObject(attrs)) { - return Document.fromJSON(attrs) - } - - throw new Error( - `\`Document.create\` only accepts objects, arrays, lists or documents, but you passed it: ${attrs}` - ) - } - - /** - * Create a `Document` from a JSON `object`. - * - * @param {Object|Document} object - * @return {Document} - */ - - static fromJSON(object) { - if (Document.isDocument(object)) { - return object - } - - const { data = {}, key = KeyUtils.create(), nodes = [] } = object - - const document = new Document({ - key, - data: new Map(data), - nodes: Node.createList(nodes), - }) - - return document - } - - /** - * Return a JSON representation of the document. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - data: this.data.toJSON(), - nodes: this.nodes.toArray().map(n => n.toJSON(options)), - } - - if (options.preserveKeys) { - object.key = this.key - } - - return object - } -} - -/** - * Export. - * - * @type {Document} - */ - -export default Document diff --git a/packages/slate/src/models/inline.js b/packages/slate/src/models/inline.js deleted file mode 100644 index aca77c2f81..0000000000 --- a/packages/slate/src/models/inline.js +++ /dev/null @@ -1,138 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { List, Map, Record } from 'immutable' - -import KeyUtils from '../utils/key-utils' -import Node from './node' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - data: undefined, - key: undefined, - nodes: undefined, - type: undefined, -} - -/** - * Inline. - * - * @type {Inline} - */ - -class Inline extends Record(DEFAULTS) { - /** - * Create a new `Inline` with `attrs`. - * - * @param {Object|String|Inline} attrs - * @return {Inline} - */ - - static create(attrs = {}) { - if (Inline.isInline(attrs)) { - return attrs - } - - if (typeof attrs === 'string') { - attrs = { type: attrs } - } - - if (isPlainObject(attrs)) { - return Inline.fromJSON(attrs) - } - - throw new Error( - `\`Inline.create\` only accepts objects, strings or inlines, but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Inlines` from an array. - * - * @param {Array|List} elements - * @return {List} - */ - - static createList(elements = []) { - if (List.isList(elements) || Array.isArray(elements)) { - const list = new List(elements.map(Inline.create)) - return list - } - - throw new Error( - `\`Inline.createList\` only accepts arrays or lists, but you passed it: ${elements}` - ) - } - - /** - * Create a `Inline` from a JSON `object`. - * - * @param {Object|Inline} object - * @return {Inline} - */ - - static fromJSON(object) { - if (Inline.isInline(object)) { - return object - } - - const { data = {}, key = KeyUtils.create(), nodes = [], type } = object - - if (typeof type !== 'string') { - throw new Error('`Inline.fromJS` requires a `type` string.') - } - - const inline = new Inline({ - key, - type, - data: new Map(data), - nodes: Node.createList(nodes), - }) - - return inline - } - - /** - * Check if `any` is a list of inlines. - * - * @param {Any} any - * @return {Boolean} - */ - - static isInlineList(any) { - return List.isList(any) && any.every(item => Inline.isInline(item)) - } - - /** - * Return a JSON representation of the inline. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - type: this.type, - data: this.data.toJSON(), - nodes: this.nodes.toArray().map(n => n.toJSON(options)), - } - - if (options.preserveKeys) { - object.key = this.key - } - - return object - } -} - -/** - * Export. - * - * @type {Inline} - */ - -export default Inline diff --git a/packages/slate/src/models/leaf.js b/packages/slate/src/models/leaf.js deleted file mode 100644 index 6712ae6e89..0000000000 --- a/packages/slate/src/models/leaf.js +++ /dev/null @@ -1,299 +0,0 @@ -import isPlainObject from 'is-plain-object' -import warning from 'tiny-warning' -import { List, Record, Set } from 'immutable' - -import Mark from './mark' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - marks: undefined, - text: undefined, -} - -/** - * Leaf. - * - * @type {Leaf} - */ - -class Leaf extends Record(DEFAULTS) { - /** - * Create a new `Leaf` with `attrs`. - * - * @param {Object|Leaf} attrs - * @return {Leaf} - */ - - static create(attrs = {}) { - warning(false, 'As of slate@0.47 the `Leaf` model is deprecated.') - - if (Leaf.isLeaf(attrs)) { - return attrs - } - - if (typeof attrs === 'string') { - attrs = { text: attrs } - } - - if (isPlainObject(attrs)) { - return Leaf.fromJSON(attrs) - } - - throw new Error( - `\`Leaf.create\` only accepts objects, strings or leaves, but you passed it: ${attrs}` - ) - } - - /** - * Create a valid List of `Leaf` from `leaves` - * - * @param {List} leaves - * @return {List} - */ - - static createLeaves(leaves) { - if (leaves.size <= 1) return leaves - - let invalid = false - - // TODO: we can make this faster with [List] and then flatten - const result = List().withMutations(cache => { - // Search from the leaves left end to find invalid node; - leaves.findLast((leaf, index) => { - const firstLeaf = cache.first() - - // If the first leaf of cache exist, check whether the first leaf is connectable with the current leaf - if (firstLeaf) { - // If marks equals, then the two leaves can be connected - if (firstLeaf.marks.equals(leaf.marks)) { - invalid = true - cache.set(0, firstLeaf.set('text', `${leaf.text}${firstLeaf.text}`)) - return - } - - // If the cached leaf is empty, drop the empty leaf with the upcoming leaf - if (firstLeaf.text === '') { - invalid = true - cache.set(0, leaf) - return - } - - // If the current leaf is empty, drop the leaf - if (leaf.text === '') { - invalid = true - return - } - } - - cache.unshift(leaf) - }) - }) - - if (!invalid) return leaves - return result - } - - /** - * Split a list of leaves to two lists; if the leaves are valid leaves, the returned leaves are also valid - * Corner Cases: - * 1. if offset is smaller than 0, then return [List(), leaves] - * 2. if offset is bigger than the text length, then return [leaves, List()] - * - * @param {List leaves - * @return {Array>} - */ - - static splitLeaves(leaves, offset) { - if (offset < 0) return [List(), leaves] - - if (leaves.size === 0) { - return [List(), List()] - } - - let endOffset = 0 - let index = -1 - let left, right - - leaves.find(leaf => { - index++ - const startOffset = endOffset - const { text } = leaf - endOffset += text.length - - if (endOffset < offset) return false - if (startOffset > offset) return false - - const length = offset - startOffset - left = leaf.set('text', text.slice(0, length)) - right = leaf.set('text', text.slice(length)) - return true - }) - - if (!left) return [leaves, List()] - - if (left.text === '') { - if (index === 0) { - return [List.of(left), leaves] - } - - return [leaves.take(index), leaves.skip(index)] - } - - if (right.text === '') { - if (index === leaves.size - 1) { - return [leaves, List.of(right)] - } - - return [leaves.take(index + 1), leaves.skip(index + 1)] - } - - return [ - leaves.take(index).push(left), - leaves.skip(index + 1).unshift(right), - ] - } - - /** - * Create a `Leaf` list from `attrs`. - * - * @param {Array|List} attrs - * @return {List} - */ - - static createList(attrs = []) { - if (List.isList(attrs) || Array.isArray(attrs)) { - const list = new List(attrs.map(Leaf.create)) - return list - } - - throw new Error( - `\`Leaf.createList\` only accepts arrays or lists, but you passed it: ${attrs}` - ) - } - - /** - * Create a `Leaf` from a JSON `object`. - * - * @param {Object} object - * @return {Leaf} - */ - - static fromJSON(object) { - const { text = '', marks = [] } = object - - const leaf = new Leaf({ - text, - marks: Set(marks.map(Mark.fromJSON)), - }) - - return leaf - } - - /** - * Check if `any` is a list of leaves. - * - * @param {Any} any - * @return {Boolean} - */ - - static isLeafList(any) { - return List.isList(any) && any.every(item => Leaf.isLeaf(item)) - } - - /** - * Update a `mark` at leaf, replace with newMark - * - * @param {Mark} mark - * @param {Mark} newMark - * @returns {Leaf} - */ - - updateMark(mark, newMark) { - const { marks } = this - if (newMark.equals(mark)) return this - if (!marks.has(mark)) return this - const newMarks = marks.withMutations(collection => { - collection.remove(mark).add(newMark) - }) - return this.set('marks', newMarks) - } - - /** - * Add a `mark` to the leaf. - * - * @param {Mark} mark - * @returns {Text} - */ - - addMark(mark) { - const { marks } = this - return this.set('marks', marks.add(mark)) - } - - /** - * Add a `set` of marks to the leaf. - * - * @param {Set} set - * @returns {Text} - */ - - addMarks(set) { - const { marks } = this - return this.set('marks', marks.union(set)) - } - - /** - * Insert a text `string` into the leaf at `offset`. - * - * @param {Number} offset - * @param {String} string - * @return {Leaf} - */ - - insertText(offset, string) { - const { text } = this - const next = text.slice(0, offset) + string + text.slice(offset) - return this.set('text', next) - } - - /** - * Remove a `mark` from the leaf. - * - * @param {Mark} mark - * @returns {Text} - */ - - removeMark(mark) { - const { marks } = this - return this.set('marks', marks.remove(mark)) - } - - /** - * Return a JSON representation of the leaf. - * - * @return {Object} - */ - - toJSON() { - const object = { - object: this.object, - text: this.text, - marks: this.marks.toArray().map(m => m.toJSON()), - } - - return object - } -} - -/** - * Export. - * - * @type {Leaf} - */ - -export default Leaf diff --git a/packages/slate/src/models/mark.js b/packages/slate/src/models/mark.js deleted file mode 100644 index 9be64e071c..0000000000 --- a/packages/slate/src/models/mark.js +++ /dev/null @@ -1,158 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Map, Record, Set } from 'immutable' - -import Data from './data' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - data: undefined, - type: undefined, -} - -/** - * Mark. - * - * @type {Mark} - */ - -class Mark extends Record(DEFAULTS) { - /** - * Create a new `Mark` with `attrs`. - * - * @param {Object|Mark} attrs - * @return {Mark} - */ - - static create(attrs = {}) { - if (Mark.isMark(attrs)) { - return attrs - } - - if (typeof attrs === 'string') { - attrs = { type: attrs } - } - - if (isPlainObject(attrs)) { - return Mark.fromJSON(attrs) - } - - throw new Error( - `\`Mark.create\` only accepts objects, strings or marks, but you passed it: ${attrs}` - ) - } - - /** - * Create a set of marks. - * - * @param {Array} elements - * @return {Set} - */ - - static createSet(elements) { - if (Set.isSet(elements) || Array.isArray(elements)) { - const marks = new Set(elements.map(Mark.create)) - return marks - } - - if (elements == null) { - return Set() - } - - throw new Error( - `\`Mark.createSet\` only accepts sets, arrays or null, but you passed it: ${elements}` - ) - } - - /** - * Create a dictionary of settable mark properties from `attrs`. - * - * @param {Object|String|Mark} attrs - * @return {Object} - */ - - static createProperties(attrs = {}) { - if (Mark.isMark(attrs)) { - return { - data: attrs.data, - type: attrs.type, - } - } - - if (typeof attrs === 'string') { - return { type: attrs } - } - - if (isPlainObject(attrs)) { - const props = {} - if ('type' in attrs) props.type = attrs.type - if ('data' in attrs) props.data = Data.create(attrs.data) - return props - } - - throw new Error( - `\`Mark.createProperties\` only accepts objects, strings or marks, but you passed it: ${attrs}` - ) - } - - /** - * Create a `Mark` from a JSON `object`. - * - * @param {Object} object - * @return {Mark} - */ - - static fromJSON(object) { - const { data = {}, type } = object - - if (typeof type !== 'string') { - throw new Error('`Mark.fromJS` requires a `type` string.') - } - - const mark = new Mark({ - type, - data: new Map(data), - }) - - return mark - } - - /** - * Check if `any` is a set of marks. - * - * @param {Any} any - * @return {Boolean} - */ - - static isMarkSet(any) { - return Set.isSet(any) && any.every(item => Mark.isMark(item)) - } - - /** - * Return a JSON representation of the mark. - * - * @return {Object} - */ - - toJSON() { - const object = { - object: this.object, - type: this.type, - data: this.data.toJSON(), - } - - return object - } -} - -/** - * Export. - * - * @type {Mark} - */ - -export default Mark diff --git a/packages/slate/src/models/node.js b/packages/slate/src/models/node.js deleted file mode 100644 index 1cd8d3b829..0000000000 --- a/packages/slate/src/models/node.js +++ /dev/null @@ -1,206 +0,0 @@ -import isPlainObject from 'is-plain-object' -import warning from 'tiny-warning' -import { List } from 'immutable' - -import Block from './block' -import Data from './data' -import Document from './document' -import Inline from './inline' -import Text from './text' - -/** - * A pseudo-model that is used for its static methods only. - * - * @type {Node} - */ - -class Node { - /** - * Create a new `Node` with `attrs`. - * - * @param {Object|Node} attrs - * @return {Node} - */ - - static create(attrs = {}) { - if (Node.isNode(attrs)) { - return attrs - } - - if (isPlainObject(attrs)) { - let { object } = attrs - - if (!object && attrs.kind) { - warning( - false, - 'As of slate@0.32.0, the `kind` property of Slate objects has been renamed to `object`.' - ) - - object = attrs.kind - } - - switch (object) { - case 'block': - return Block.create(attrs) - case 'document': - return Document.create(attrs) - case 'inline': - return Inline.create(attrs) - case 'text': - return Text.create(attrs) - - default: { - throw new Error('`Node.create` requires a `object` string.') - } - } - } - - throw new Error( - `\`Node.create\` only accepts objects or nodes but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Nodes` from an array. - * - * @param {Array} elements - * @return {List} - */ - - static createList(elements = []) { - if (List.isList(elements) || Array.isArray(elements)) { - let array = [] - - elements.forEach(el => { - if ( - el && - el.object === 'text' && - el.leaves && - Array.isArray(el.leaves) - ) { - warning( - false, - 'As of slate@0.46, the `leaves` property of Text nodes has been removed. Instead, each text node contains a string of text and a unique set of marks and leaves are unnecessary.' - ) - - const texts = Text.createList(el.leaves).toArray() - array = array.concat(texts) - return - } - - const node = Node.create(el) - array.push(node) - }) - - const list = List(array) - return list - } - - throw new Error( - `\`Node.createList\` only accepts lists or arrays, but you passed it: ${elements}` - ) - } - - /** - * Create a dictionary of settable node properties from `attrs`. - * - * @param {Object|String|Node} attrs - * @return {Object} - */ - - static createProperties(attrs = {}) { - if (Block.isBlock(attrs) || Inline.isInline(attrs)) { - return { - data: attrs.data, - type: attrs.type, - } - } - - if (typeof attrs === 'string') { - return { type: attrs } - } - - if (isPlainObject(attrs)) { - const props = {} - if ('type' in attrs) props.type = attrs.type - if ('data' in attrs) props.data = Data.create(attrs.data) - return props - } - - throw new Error( - `\`Node.createProperties\` only accepts objects, strings, blocks or inlines, but you passed it: ${attrs}` - ) - } - - /** - * Create a `Node` from a JSON `value`. - * - * @param {Object} value - * @return {Node} - */ - - static fromJSON(value) { - let { object } = value - - if (!object && value.kind) { - warning( - false, - 'As of slate@0.32.0, the `kind` property of Slate objects has been renamed to `object`.' - ) - - object = value.kind - } - - switch (object) { - case 'block': - return Block.fromJSON(value) - case 'document': - return Document.fromJSON(value) - case 'inline': - return Inline.fromJSON(value) - case 'text': - return Text.fromJSON(value) - - default: { - throw new Error( - `\`Node.fromJSON\` requires an \`object\` of either 'block', 'document', 'inline' or 'text', but you passed: ${value}` - ) - } - } - } - - /** - * Check if `any` is a `Node`. - * - * @param {Any} any - * @return {Boolean} - */ - - static isNode(any) { - return ( - Block.isBlock(any) || - Document.isDocument(any) || - Inline.isInline(any) || - Text.isText(any) - ) - } - - /** - * Check if `any` is a list of nodes. - * - * @param {Any} any - * @return {Boolean} - */ - - static isNodeList(any) { - return List.isList(any) && any.every(item => Node.isNode(item)) - } -} - -/** - * Export. - * - * @type {Object} - */ - -export default Node diff --git a/packages/slate/src/models/operation.js b/packages/slate/src/models/operation.js deleted file mode 100644 index 0f76aeac45..0000000000 --- a/packages/slate/src/models/operation.js +++ /dev/null @@ -1,350 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { List, Record, Map } from 'immutable' - -import Annotation from './annotation' -import Mark from './mark' -import Node from './node' -import PathUtils from '../utils/path-utils' -import Selection from './selection' -import Value from './value' -import apply from '../operations/apply' -import invert from '../operations/invert' - -/** - * Operation attributes. - * - * @type {Array} - */ - -const OPERATION_ATTRIBUTES = { - add_mark: ['path', 'mark', 'data'], - add_annotation: ['annotation', 'data'], - insert_node: ['path', 'node', 'data'], - insert_text: ['path', 'offset', 'text', 'data'], - merge_node: ['path', 'position', 'properties', 'target', 'data'], - move_node: ['path', 'newPath', 'data'], - remove_annotation: ['annotation', 'data'], - remove_mark: ['path', 'mark', 'data'], - remove_node: ['path', 'node', 'data'], - remove_text: ['path', 'offset', 'text', 'data'], - set_annotation: ['properties', 'newProperties', 'data'], - set_mark: ['path', 'properties', 'newProperties', 'data'], - set_node: ['path', 'properties', 'newProperties', 'data'], - set_selection: ['properties', 'newProperties', 'data'], - set_value: ['properties', 'newProperties', 'data'], - split_node: ['path', 'position', 'properties', 'target', 'data'], -} - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - annotation: undefined, - data: undefined, - length: undefined, - mark: undefined, - marks: undefined, - newPath: undefined, - newProperties: undefined, - node: undefined, - offset: undefined, - path: undefined, - position: undefined, - properties: undefined, - target: undefined, - text: undefined, - type: undefined, -} - -/** - * Operation. - * - * @type {Operation} - */ - -class Operation extends Record(DEFAULTS) { - /** - * Create a new `Operation` with `attrs`. - * - * @param {Object|Array|List|String|Operation} attrs - * @return {Operation} - */ - - static create(attrs = {}) { - if (Operation.isOperation(attrs)) { - return attrs - } - - if (isPlainObject(attrs)) { - return Operation.fromJSON(attrs) - } - - throw new Error( - `\`Operation.create\` only accepts objects or operations, but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Operations` from `elements`. - * - * @param {Array|List} elements - * @return {List} - */ - - static createList(elements = []) { - if (List.isList(elements) || Array.isArray(elements)) { - const list = new List(elements.map(Operation.create)) - return list - } - - throw new Error( - `\`Operation.createList\` only accepts arrays or lists, but you passed it: ${elements}` - ) - } - - /** - * Create a `Operation` from a JSON `object`. - * - * @param {Object|Operation} object - * @return {Operation} - */ - - static fromJSON(object) { - if (Operation.isOperation(object)) { - return object - } - - const { type } = object - const ATTRIBUTES = OPERATION_ATTRIBUTES[type] - const attrs = { type } - - if (!ATTRIBUTES) { - throw new Error( - `\`Operation.fromJSON\` was passed an unrecognized operation type: "${type}"` - ) - } - - for (const key of ATTRIBUTES) { - let v = object[key] - - // Default `data` to an empty object. - if (key === 'data' && v === undefined) { - v = {} - } - - if (v === undefined) { - throw new Error( - `\`Operation.fromJSON\` was passed a "${type}" operation without the required "${key}" attribute.` - ) - } - - if (key === 'annotation') { - v = Annotation.create(v) - } - - if (key === 'path' || key === 'newPath') { - v = PathUtils.create(v) - } - - if (key === 'mark') { - v = Mark.create(v) - } - - if (key === 'node') { - v = Node.create(v) - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_annotation' - ) { - v = Annotation.createProperties(v) - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_mark' - ) { - v = Mark.createProperties(v) - } - - if ( - (key === 'properties' || key === 'newProperties') && - (type === 'set_node' || type === 'merge_node' || type === 'split_node') - ) { - v = Node.createProperties(v) - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_selection' - ) { - v = Selection.createProperties(v) - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_value' - ) { - v = Value.createProperties(v) - } - - if (key === 'data') { - v = Map(v) - } - - attrs[key] = v - } - - const op = new Operation(attrs) - return op - } - - /** - * Check if `any` is a list of operations. - * - * @param {Any} any - * @return {Boolean} - */ - - static isOperationList(any) { - return List.isList(any) && any.every(item => Operation.isOperation(item)) - } - - /** - * Apply the operation to a `value`. - * - * @param {Value} value - * @return {Value} - */ - - apply(value) { - const next = apply(value, this) - return next - } - - /** - * Invert the operation. - * - * @return {Operation} - */ - - invert() { - const inverted = invert(this) - return inverted - } - - /** - * Return a JSON representation of the operation. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const { object, type } = this - const json = { object, type } - const ATTRIBUTES = OPERATION_ATTRIBUTES[type] - - for (const key of ATTRIBUTES) { - let value = this[key] - - if ( - key === 'annotation' || - key === 'mark' || - key === 'marks' || - key === 'node' || - key === 'path' || - key === 'newPath' - ) { - value = value.toJSON() - } - - if (key === 'properties' && type === 'merge_node') { - const v = {} - if ('data' in value) v.data = value.data.toJS() - if ('type' in value) v.type = value.type - value = v - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_annotation' - ) { - const v = {} - if ('anchor' in value) v.anchor = value.anchor.toJS() - if ('focus' in value) v.focus = value.focus.toJS() - if ('key' in value) v.key = value.key - if ('mark' in value) v.mark = value.mark.toJS() - value = v - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_mark' - ) { - const v = {} - if ('data' in value) v.data = value.data.toJS() - if ('type' in value) v.type = value.type - value = v - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_node' - ) { - const v = {} - if ('data' in value) v.data = value.data.toJS() - if ('type' in value) v.type = value.type - value = v - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_selection' - ) { - const v = {} - if ('anchor' in value) v.anchor = value.anchor.toJSON() - if ('focus' in value) v.focus = value.focus.toJSON() - if ('isFocused' in value) v.isFocused = value.isFocused - if ('marks' in value) v.marks = value.marks && value.marks.toJSON() - value = v - } - - if ( - (key === 'properties' || key === 'newProperties') && - type === 'set_value' - ) { - const v = {} - if ('data' in value) v.data = value.data.toJS() - value = v - } - - if (key === 'properties' && type === 'split_node') { - const v = {} - if ('data' in value) v.data = value.data.toJS() - if ('type' in value) v.type = value.type - value = v - } - - if (key === 'data') { - value = value.toJSON() - } - - json[key] = value - } - - return json - } -} - -/** - * Export. - * - * @type {Operation} - */ - -export default Operation diff --git a/packages/slate/src/models/point.js b/packages/slate/src/models/point.js deleted file mode 100644 index 8a6d427bbf..0000000000 --- a/packages/slate/src/models/point.js +++ /dev/null @@ -1,644 +0,0 @@ -import isPlainObject from 'is-plain-object' -import warning from 'tiny-warning' -import { Record } from 'immutable' - -import KeyUtils from '../utils/key-utils' -import Path from '../utils/path-utils' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - key: undefined, - offset: undefined, - path: undefined, -} - -/** - * Point. - * - * @type {Point} - */ - -class Point extends Record(DEFAULTS) { - /** - * Create a new `Point` with `attrs`. - * - * @param {Object|Point} attrs - * @return {Point} - */ - - static create(attrs = {}) { - if (Point.isPoint(attrs)) { - return attrs - } - - if (isPlainObject(attrs)) { - return Point.fromJSON(attrs) - } - - throw new Error( - `\`Point.create\` only accepts objects or points, but you passed it: ${attrs}` - ) - } - - /** - * Create a dictionary of settable point properties from `attrs`. - * - * @param {Object|Point} attrs - * @return {Object} - */ - - static createProperties(a = {}) { - if (Point.isPoint(a)) { - return { - key: a.key, - offset: a.offset, - path: a.path, - } - } - - if (isPlainObject(a)) { - const p = {} - if ('key' in a) p.key = a.key - if ('offset' in a) p.offset = a.offset - if ('path' in a) p.path = Path.create(a.path) - - // If only a path is set, or only a key is set, ensure that the other is - // set to null so that it can be normalized back to the right value. - // Otherwise we won't realize that the path and key don't match anymore. - if ('path' in a && !('key' in a)) p.key = null - if ('key' in a && !('path' in a)) p.path = null - - return p - } - - throw new Error( - `\`Point.createProperties\` only accepts objects or points, but you passed it: ${a}` - ) - } - - /** - * Create a `Point` from a JSON `object`. - * - * @param {Object} object - * @return {Point} - */ - - static fromJSON(object) { - const { key = null, offset = null, path = null } = object - - const point = new Point({ - key, - offset, - path: Path.create(path), - }) - - return point - } - - /** - * Check whether all properties of the point are set. - * - * @return {Boolean} - */ - - get isSet() { - return this.key != null && this.offset != null && this.path != null - } - - /** - * Check whether any property of the point is not set. - * - * @return {Boolean} - */ - - get isUnset() { - return !this.isSet - } - - /** - * Check whether the point is after another `point`. - * - * @return {Boolean} - */ - - isAfterPoint(point) { - if (this.isUnset || point.isUnset) { - return false - } - - const result = Path.compare(this.path, point.path) - const isAfter = (result === 0 && this.offset > point.offset) || result === 1 - return isAfter - } - - /** - * Check whether the point is after a `range`. - * - * @return {Boolean} - */ - - isAfterRange(range) { - return this.isAfterPoint(range.end) - } - - /** - * Check whether the point is at the end of a `range`. - * - * @return {Boolean} - */ - - isAtEndOfRange(range) { - if (this.isUnset) { - return false - } - - const is = this.equals(range.end) - return is - } - - /** - * Check whether the point is at the start of a `range`. - * - * @return {Boolean} - */ - - isAtStartOfRange(range) { - if (this.isUnset) { - return false - } - - const is = this.equals(range.start) - return is - } - - /** - * Check whether the point is before another `point`. - * - * @return {Boolean} - */ - - isBeforePoint(point) { - if (this.isUnset) { - return false - } - - const result = Path.compare(this.path, point.path) - const isBefore = - (result === 0 && this.offset < point.offset) || result === -1 - - return isBefore - } - - /** - * Check whether the point is before a `range`. - * - * @return {Boolean} - */ - - isBeforeRange(range) { - if (this.isUnset) { - return false - } - - const is = this.isBeforePoint(range.start) - return is - } - - /** - * Check whether the point is inside a `range`. - * - * @return {Boolean} - */ - - isInRange(range) { - if (this.isUnset) { - return false - } - - const is = - this.equals(range.start) || - this.equals(range.end) || - (this.isAfterPoint(range.start) && this.isBeforePoint(range.end)) - return is - } - - /** - * Check whether the point is at the end of a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - isAtEndOfNode(node) { - warning( - false, - 'As of slate@0.48 the `point.isAtEndOfNode` method is deprecated.' - ) - - if (this.isUnset) { - return false - } - - const last = node.getLastText() - const is = this.key === last.key && this.offset === last.text.length - return is - } - - /** - * Check whether the point is at the start of a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - isAtStartOfNode(node) { - warning( - false, - 'As of slate@0.48 the `point.isAtStartOfNode` method is deprecated.' - ) - - if (this.isUnset) { - return false - } - - // PERF: Do a check for a `0` offset first since it's quickest. - if (this.offset !== 0) return false - - const first = node.getFirstText() - const is = this.key === first.key - return is - } - - /** - * Check whether the point is in a `node`. - * - * @param {Node} node - * @return {Boolean} - */ - - isInNode(node) { - warning( - false, - 'As of slate@0.48 the `point.isInNode` method is deprecated.' - ) - - if (this.isUnset) { - return false - } - - if (node.object === 'text' && node.key === this.key) return true - if (node.hasNode(this.key)) return true - return false - } - - /** - * Move the point's offset backward `n` characters. - * - * @param {Number} n (optional) - * @return {Point} - */ - - moveBackward(n = 1) { - if (n === 0) return this - if (n < 0) return this.moveForward(-n) - const point = this.setOffset(this.offset - n) - return point - } - - /** - * Move the point's offset forward `n` characters. - * - * @param {Number} n (optional) - * @return {Point} - */ - - moveForward(n = 1) { - if (n === 0) return this - if (n < 0) return this.moveBackward(-n) - const point = this.setOffset(this.offset + n) - return point - } - - /** - * Move the point's anchor point to a new `path` and `offset`. - * - * @param {List|String|Number} path - * @param {Number} offset - * @return {Point} - */ - - moveTo(path, offset = 0) { - let key = this.key - - if (typeof path === 'number') { - offset = path - path = this.path - } else if (typeof path === 'string') { - key = path - path = key === this.key ? this.path : null - } else { - key = path.equals(this.path) ? this.key : null - } - - const point = this.merge({ key, path, offset }) - return point - } - - /** - * Move the point's anchor point to the start of a `node`. - * - * @param {Node} node - * @return {Point} - */ - - moveToStartOfNode(node) { - warning( - false, - 'As of slate@0.48 the `point.moveToStartOfNode` method is deprecated.' - ) - - const first = node.getFirstText() - const point = this.moveTo(first.key, 0) - return point - } - - /** - * Move the point's anchor point to the end of a `node`. - * - * @param {Node} node - * @return {Point} - */ - - moveToEndOfNode(node) { - warning( - false, - 'As of slate@0.48 the `point.moveToEndOfNode` method is deprecated.' - ) - - const last = node.getLastText() - const point = this.moveTo(last.key, last.text.length) - return point - } - - /** - * Normalize the point relative to a `node`, ensuring that its key and path - * reference a text node, or that it gets unset. - * - * @param {Node} node - * @return {Point} - */ - - normalize(node) { - // If both the key and path are null, there's no reference to a node, so - // make sure it is entirely unset. - if (this.key == null && this.path == null) { - return this.setOffset(null) - } - - const { key, offset, path } = this - - // PERF: this function gets called a lot. - // to avoid creating the key -> path lookup table, we attempt to look up by path first. - let target = path && node.getNode(path) - - if (!target && key) { - warning( - false, - 'As of slate@0.48 a point cannot be created with a `key` but without a `path`, and this line will fail in a future version.' - ) - - target = node.getNode(key) - - if (target) { - // There is a misalignment of path and key - const point = this.merge({ - path: node.getPath(target), - }) - - return point - } - } - - if (!target) { - warning( - false, - "A point's `path` or `key` invalid and was reset! This will fail in a future version." - ) - - const text = node.getFirstText() - if (!text) return Point.create() - - const point = this.merge({ - key: text.key, - offset: 0, - path: node.getPath(text), - }) - - return point - } - - if (target.object !== 'text') { - warning( - false, - 'A point should not reference a non-text node! This will fail in a future version.' - ) - - const text = target.getTextAtOffset(offset) - const before = target.getOffset(text.key) - const point = this.merge({ - offset: offset - before, - key: text.key, - path: node.getPath(text), - }) - - return point - } - - if (target && path && key && key !== target.key) { - warning( - false, - "A point's `key` did not match its `path`! This will fail in a future version." - ) - - // TODO: if we look up by path above and it differs by key, do we want to reset it to looking up by key? - } - - let point = this.merge({ - key: target.key, - path: path == null ? node.getPath(target) : path, - offset: offset == null ? 0 : Math.min(offset, target.text.length), - }) - - // COMPAT: There is an ambiguity, since a point can exist at the end of a - // text node, or at the start of the following one. To eliminate it we - // enforce that if there is a following text node, we always move it there. - if (point.offset === target.text.length) { - const block = node.getClosestBlock(point.path) - // TODO: this next line is broken because `getNextText` takes a path - const next = block.getNextText() - - if (next) { - point = point.merge({ - key: next.key, - path: node.getPath(next), - offset: 0, - }) - } - } - - return point - } - - /** - * Set the point's key to a new `key`. - * - * @param {String} key - * @return {Point} - */ - - setKey(key) { - if (key != null) { - key = KeyUtils.create(key) - } - - const point = this.set('key', key) - return point - } - - /** - * Set the point's offset to a new `offset`. - * - * @param {Number} offset - * @return {Point} - */ - - setOffset(offset) { - const point = this.set('offset', offset) - return point - } - - /** - * Set the point's path to a new `path`. - * - * @param {List|Array} path - * @return {Point} - */ - - setPath(path) { - if (path != null) { - path = Path.create(path) - } - - const point = this.set('path', path) - return point - } - - /** - * Return a JSON representation of the point. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - key: this.key, - offset: this.offset, - path: this.path && this.path.toArray(), - } - - if (!options.preserveKeys) { - delete object.key - } - - return object - } - - /** - * Unset the point. - * - * @return {Point} - */ - - unset() { - return this.merge({ - key: null, - offset: null, - path: null, - }) - } - - transform(op) { - const point = this - const { path, offset } = point - - if (op.type === 'insert_text') { - if (Path.isEqual(op.path, path) && op.offset <= offset) { - const newOffset = offset + op.text.length - return point.setOffset(newOffset) - } - } - - if (op.type === 'remove_text') { - if (Path.isEqual(op.path, path) && op.offset <= offset) { - const newOffset = offset + op.text.length - return point.setOffset(newOffset) - } - } - - if (op.type === 'remove_node') { - if (Path.isEqual(op.path, path)) { - return null - } - } - - if (op.type === 'split_node') { - if (Path.isEqual(op.path, path) && op.position <= offset) { - const newPath = Path.increment(path) - const newOffset = offset - op.position - return point - .setPath(newPath) - .setOffset(newOffset) - .setKey(null) - } - } - - if (op.type === 'merge_node') { - if (Path.isEqual(op.path, path)) { - const newPath = Path.decrement(path) - const newOffset = offset + op.position - return point - .setPath(newPath) - .setOffset(newOffset) - .setKey(null) - } - } - - if ( - op.type === 'insert_node' || - op.type === 'merge_node' || - op.type === 'move_node' || - op.type === 'remove_node' || - op.type === 'split_node' - ) { - const [first] = Path.transform(path, op) - return point.setPath(first).setKey(null) - } - - return point - } -} - -/** - * Export. - * - * @type {Point} - */ - -export default Point diff --git a/packages/slate/src/models/range.js b/packages/slate/src/models/range.js deleted file mode 100644 index bbf77e6e06..0000000000 --- a/packages/slate/src/models/range.js +++ /dev/null @@ -1,153 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { List, Record } from 'immutable' - -import Decoration from './decoration' -import Point from './point' -import Selection from './selection' -import isObject from '../utils/is-object' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - anchor: undefined, - focus: undefined, -} - -/** - * Range. - * - * @type {Range} - */ - -class Range extends Record(DEFAULTS) { - /** - * Create a new `Range` with `attrs`. - * - * @param {Object|Range} attrs - * @return {Range} - */ - - static create(attrs = {}) { - if (Range.isRange(attrs)) { - if (attrs.object === 'range') { - return attrs - } else { - return Range.fromJSON(Range.createProperties(attrs)) - } - } - - if (isPlainObject(attrs)) { - return Range.fromJSON(attrs) - } - - throw new Error( - `\`Range.create\` only accepts objects or ranges, but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Ranges` from `elements`. - * - * @param {Array|List} elements - * @return {List} - */ - - static createList(elements = []) { - if (List.isList(elements) || Array.isArray(elements)) { - const list = new List(elements.map(Range.create)) - return list - } - - throw new Error( - `\`Range.createList\` only accepts arrays or lists, but you passed it: ${elements}` - ) - } - - /** - * Create a dictionary of settable range properties from `attrs`. - * - * @param {Object|String|Range} attrs - * @return {Object} - */ - - static createProperties(a = {}) { - if (Range.isRange(a)) { - return { - anchor: Point.createProperties(a.anchor), - focus: Point.createProperties(a.focus), - } - } - - if (isPlainObject(a)) { - const p = {} - if ('anchor' in a) p.anchor = Point.create(a.anchor) - if ('focus' in a) p.focus = Point.create(a.focus) - return p - } - - throw new Error( - `\`Range.createProperties\` only accepts objects, annotations, decorations, ranges or selections, but you passed it: ${a}` - ) - } - - /** - * Create a `Range` from a JSON `object`. - * - * @param {Object} object - * @return {Range} - */ - - static fromJSON(object) { - const { anchor, focus } = object - const range = new Range({ - anchor: Point.fromJSON(anchor || {}), - focus: Point.fromJSON(focus || {}), - }) - - return range - } - - /** - * Check if a `value` is a `Range`, or is range-like. - * - * @param {Any} value - * @return {Boolean} - */ - - static isRange(value) { - return ( - isObject('range', value) || - Decoration.isDecoration(value) || - Selection.isSelection(value) - ) - } - - /** - * Return a JSON representation of the range. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - anchor: this.anchor.toJSON(options), - focus: this.focus.toJSON(options), - } - - return object - } -} - -/** - * Export. - * - * @type {Range} - */ - -export default Range diff --git a/packages/slate/src/models/selection.js b/packages/slate/src/models/selection.js deleted file mode 100644 index 49fd61f442..0000000000 --- a/packages/slate/src/models/selection.js +++ /dev/null @@ -1,195 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Record, Set } from 'immutable' - -import Mark from './mark' -import Point from './point' -import Range from './range' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - anchor: undefined, - focus: undefined, - isFocused: undefined, - marks: undefined, -} - -/** - * Selection. - * - * @type {Selection} - */ - -class Selection extends Record(DEFAULTS) { - /** - * Create a new `Selection` with `attrs`. - * - * @param {Object|Selection} attrs - * @return {Selection} - */ - - static create(attrs = {}) { - if (Selection.isSelection(attrs)) { - return attrs - } - - if (Range.isRange(attrs)) { - return Selection.fromJSON(Range.createProperties(attrs)) - } - - if (isPlainObject(attrs)) { - return Selection.fromJSON(attrs) - } - - throw new Error( - `\`Selection.create\` only accepts objects, ranges or selections, but you passed it: ${attrs}` - ) - } - - /** - * Create a dictionary of settable selection properties from `attrs`. - * - * @param {Object|String|Selection} attrs - * @return {Object} - */ - - static createProperties(a = {}) { - if (Selection.isSelection(a)) { - return { - anchor: Point.createProperties(a.anchor), - focus: Point.createProperties(a.focus), - isFocused: a.isFocused, - marks: a.marks, - } - } - - if (Range.isRange(a)) { - return { - anchor: Point.createProperties(a.anchor), - focus: Point.createProperties(a.focus), - } - } - - if (isPlainObject(a)) { - const p = {} - if ('anchor' in a) p.anchor = Point.create(a.anchor) - if ('focus' in a) p.focus = Point.create(a.focus) - if ('isFocused' in a) p.isFocused = a.isFocused - if ('marks' in a) - p.marks = a.marks == null ? null : Mark.createSet(a.marks) - return p - } - - throw new Error( - `\`Selection.createProperties\` only accepts objects, ranges or selections, but you passed it: ${a}` - ) - } - - /** - * Create a `Selection` from a JSON `object`. - * - * @param {Object} object - * @return {Selection} - */ - - static fromJSON(object) { - const { anchor, focus, isFocused = false, marks = null } = object - const selection = new Selection({ - anchor: Point.fromJSON(anchor || {}), - focus: Point.fromJSON(focus || {}), - isFocused, - marks: marks == null ? null : new Set(marks.map(Mark.fromJSON)), - }) - - return selection - } - - /** - * Check whether the selection is blurred. - * - * @return {Boolean} - */ - - get isBlurred() { - return !this.isFocused - } - - /** - * Set the `isFocused` property to a new `value`. - * - * @param {Boolean} value - * @return {Selection} - */ - - setIsFocused(value) { - const selection = this.set('isFocused', value) - return selection - } - - /** - * Set the `marks` property to a new set of `marks`. - * - * @param {Set} marks - * @return {Selection} - */ - - setMarks(marks) { - const selection = this.set('marks', marks) - return selection - } - - /** - * Set new `properties` on the selection. - * - * @param {Object|Range|Selection} properties - * @return {Range} - */ - - setProperties(properties) { - properties = Selection.createProperties(properties) - const { anchor, focus, ...props } = properties - - if (anchor) { - props.anchor = Point.create(anchor) - } - - if (focus) { - props.focus = Point.create(focus) - } - - const selection = this.merge(props) - return selection - } - - /** - * Return a JSON representation of the selection. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - anchor: this.anchor.toJSON(options), - focus: this.focus.toJSON(options), - isFocused: this.isFocused, - marks: - this.marks == null ? null : this.marks.toArray().map(m => m.toJSON()), - } - - return object - } -} - -/** - * Export. - * - * @type {Selection} - */ - -export default Selection diff --git a/packages/slate/src/models/text.js b/packages/slate/src/models/text.js deleted file mode 100644 index 6eca9293ed..0000000000 --- a/packages/slate/src/models/text.js +++ /dev/null @@ -1,370 +0,0 @@ -import isPlainObject from 'is-plain-object' -import invariant from 'tiny-invariant' -import { List, Record } from 'immutable' - -import Mark from './mark' -import KeyUtils from '../utils/key-utils' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - key: undefined, - marks: undefined, - text: undefined, -} - -const Leaf = Record({ - text: undefined, - marks: undefined, - annotations: undefined, - decorations: undefined, -}) - -/** - * Text. - * - * @type {Text} - */ - -class Text extends Record(DEFAULTS) { - /** - * Create a new `Text` with `attrs`. - * - * @param {Object|Array|List|String|Text} attrs - * @return {Text} - */ - - static create(attrs = '') { - if (Text.isText(attrs)) { - return attrs - } - - if (typeof attrs === 'string') { - attrs = { text: attrs } - } - - if (isPlainObject(attrs)) { - return Text.fromJSON(attrs) - } - - throw new Error( - `\`Text.create\` only accepts objects, arrays, strings or texts, but you passed it: ${attrs}` - ) - } - - /** - * Create a list of `Texts` from `elements`. - * - * @param {Array|List} elements - * @return {List} - */ - - static createList(elements = []) { - if (List.isList(elements) || Array.isArray(elements)) { - const list = new List(elements.map(Text.create)) - return list - } - - throw new Error( - `\`Text.createList\` only accepts arrays or lists, but you passed it: ${elements}` - ) - } - - /** - * Create a `Text` from a JSON `object`. - * - * @param {Object|Text} object - * @return {Text} - */ - - static fromJSON(object) { - if (Text.isText(object)) { - return object - } - - invariant( - object.leaves == null, - 'As of slate@0.46, the `leaves` property of text nodes has been removed! Each individual leaf should be created as a text node instead.' - ) - - const { text = '', marks = [], key = KeyUtils.create() } = object - const node = new Text({ - key, - text, - marks: Mark.createSet(marks), - }) - - return node - } - - /** - * Check if `any` is a list of texts. - * - * @param {Any} any - * @return {Boolean} - */ - - static isTextList(any) { - return List.isList(any) && any.every(item => Text.isText(item)) - } - - /** - * Add a `mark`. - * - * @param {Mark} mark - * @return {Text} - */ - - addMark(mark) { - mark = Mark.create(mark) - const { marks } = this - const next = marks.add(mark) - const node = this.set('marks', next) - return node - } - - /** - * Add a set of `marks`. - * - * @param {Set} marks - * @return {Text} - */ - - addMarks(marks) { - marks = Mark.createSet(marks) - const node = this.set('marks', this.marks.union(marks)) - return node - } - - /** - * Get a list of uniquely-formatted leaves for the text node, given its - * existing marks, and its current `annotations` and `decorations`. - * - * @param {Map} annotations - * @param {List} decorations - * @return {List} - */ - - getLeaves(annotations, decorations) { - const { text, marks } = this - let leaves = [{ text, marks, annotations: [], decorations: [] }] - - // Helper to split a leaf into two `at` an offset. - const split = (leaf, at) => { - return [ - { - text: leaf.text.slice(0, at), - marks: leaf.marks, - annotations: [...leaf.annotations], - decorations: [...leaf.decorations], - }, - { - text: leaf.text.slice(at), - marks: leaf.marks, - annotations: [...leaf.annotations], - decorations: [...leaf.decorations], - }, - ] - } - - // Helper to compile the leaves for a `kind` of format. - const compile = kind => { - const formats = - kind === 'annotations' ? annotations.values() : decorations - - for (const format of formats) { - const { start, end } = format - const next = [] - let o = 0 - - for (const leaf of leaves) { - const { length } = leaf.text - const offset = o - o += length - - // If the range encompases the entire leaf, add the format. - if (start.offset <= offset && end.offset >= offset + length) { - leaf[kind].push(format) - next.push(leaf) - continue - } - - // If the range starts after the leaf, or ends before it, continue. - if ( - start.offset > offset + length || - end.offset < offset || - (end.offset === offset && offset !== 0) - ) { - next.push(leaf) - continue - } - - // Otherwise we need to split the leaf, at the start, end, or both, - // and add the format to the middle intersecting section. Do the end - // split first since we don't need to update the offset that way. - let middle = leaf - let before - let after - - if (end.offset < offset + length) { - ;[middle, after] = split(middle, end.offset - offset) - } - - if (start.offset > offset) { - ;[before, middle] = split(middle, start.offset - offset) - } - - middle[kind].push(format) - - if (before) { - next.push(before) - } - - next.push(middle) - - if (after) { - next.push(after) - } - } - - leaves = next - } - } - - compile('annotations') - compile('decorations') - - leaves = leaves.map(leaf => { - return new Leaf({ - ...leaf, - annotations: List(leaf.annotations), - decorations: List(leaf.decorations), - }) - }) - - const list = List(leaves) - return list - } - - /** - * Insert `text` at `index`. - * - * @param {Number} index - * @param {String} string - * @return {Text} - */ - - insertText(index, string) { - const { text } = this - const next = text.slice(0, index) + string + text.slice(index) - const node = this.set('text', next) - return node - } - - /** - * Remove a `mark`. - * - * @param {Mark} mark - * @return {Text} - */ - - removeMark(mark) { - mark = Mark.create(mark) - const { marks } = this - const next = marks.remove(mark) - const node = this.set('marks', next) - return node - } - - /** - * Remove text from the text node at `index` for `length`. - * - * @param {Number} index - * @param {Number} length - * @return {Text} - */ - - removeText(index, length) { - const { text } = this - const next = text.slice(0, index) + text.slice(index + length) - const node = this.set('text', next) - return node - } - - /** - * Return a JSON representation of the text. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - text: this.text, - marks: this.marks.toArray().map(m => m.toJSON()), - } - - if (options.preserveKeys) { - object.key = this.key - } - - return object - } - - /** - * Set a `newProperties` on an existing `mark`. - * - * @param {Object} mark - * @param {Object} newProperties - * @return {Text} - */ - - setMark(properties, newProperties) { - const { marks } = this - const mark = Mark.create(properties) - const newMark = mark.merge(newProperties) - const next = marks.remove(mark).add(newMark) - const node = this.set('marks', next) - return node - } - - /** - * Split the node into two at `index`. - * - * @param {Number} index - * @returns {Array} - */ - - splitText(index) { - const { text } = this - const one = this.set('text', text.slice(0, index)) - const two = this.set('text', text.slice(index)).regenerateKey() - return [one, two] - } - - /** - * Merge the node with an `other` text node. - * - * @param {Text} other - * @returns {Text} - */ - - mergeText(other) { - const next = this.text + other.text - const node = this.set('text', next) - return node - } -} - -/** - * Export. - * - * @type {Text} - */ - -export default Text diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js deleted file mode 100644 index b81ca776d8..0000000000 --- a/packages/slate/src/models/value.js +++ /dev/null @@ -1,841 +0,0 @@ -import isPlainObject from 'is-plain-object' -import invariant from 'tiny-invariant' -import warning from 'tiny-warning' -import { Record, Set, List } from 'immutable' - -import Annotation from './annotation' -import Data from './data' -import Document from './document' -import Mark from './mark' -import PathUtils from '../utils/path-utils' - -/** - * Default properties. - * - * @type {Object} - */ - -const DEFAULTS = { - annotations: undefined, - data: undefined, - document: undefined, - selection: undefined, -} - -/** - * Value. - * - * @type {Value} - */ - -class Value extends Record(DEFAULTS) { - /** - * Create a new `Value` with `attrs`. - * - * @param {Object|Value} attrs - * @param {Object} options - * @return {Value} - */ - - static create(attrs = {}, options = {}) { - if (Value.isValue(attrs)) { - return attrs - } - - if (isPlainObject(attrs)) { - return Value.fromJSON(attrs, options) - } - - throw new Error( - `\`Value.create\` only accepts objects or values, but you passed it: ${attrs}` - ) - } - - /** - * Create a dictionary of settable value properties from `attrs`. - * - * @param {Object|Value} attrs - * @return {Object} - */ - - static createProperties(a = {}) { - if (Value.isValue(a)) { - return { - annotations: a.annotations, - data: a.data, - } - } - - if (isPlainObject(a)) { - const p = {} - if ('annotations' in a) - p.annotations = Annotation.createMap(a.annotations) - if ('data' in a) p.data = Data.create(a.data) - return p - } - - throw new Error( - `\`Value.createProperties\` only accepts objects or values, but you passed it: ${a}` - ) - } - - /** - * Create a `Value` from a JSON `object`. - * - * @param {Object} object - * @param {Object} options - * @property {Boolean} normalize - * @property {Array} plugins - * @return {Value} - */ - - static fromJSON(object, options = {}) { - let { data = {}, annotations = {}, document = {}, selection = {} } = object - data = Data.fromJSON(data) - document = Document.fromJSON(document) - selection = document.createSelection(selection) - annotations = Annotation.createMap(annotations) - - if (selection.isUnset) { - const first = document.firstText() - - if (first) { - const [firstText, firstPath] = first - const start = document.createPoint({ - key: firstText.key, - path: firstPath, - offset: 0, - }) - - selection = selection.setPoints([start, start]) - } - - selection = document.createSelection(selection) - } - - const value = new Value({ - annotations, - data, - document, - selection, - }) - - return value - } - - /** - * Return a JSON representation of the value. - * - * @param {Object} options - * @return {Object} - */ - - toJSON(options = {}) { - const object = { - object: this.object, - document: this.document.toJSON(options), - } - - if (options.preserveData) { - object.data = this.data.toJSON(options) - } - - if (options.preserveAnnotations) { - object.annotations = this.annotations - .map(a => a.toJSON(options)) - .toObject() - } - - if (options.preserveSelection) { - object.selection = this.selection.toJSON(options) - } - - return object - } - - /** - * Deprecated. - */ - - get startBlock() { - warning( - false, - 'As of slate@0.48, the `value.startBlock` property is depreacted. Use `document.closestBlock()` instead.' - ) - - return ( - this.selection.start.path && - this.document.getClosestBlock(this.selection.start.path) - ) - } - - get endBlock() { - warning( - false, - 'As of slate@0.48, the `value.endBlock` property is depreacted. Use `document.closestBlock()` instead.' - ) - - return ( - this.selection.end.path && - this.document.getClosestBlock(this.selection.end.path) - ) - } - - get anchorBlock() { - warning( - false, - 'As of slate@0.48, the `value.anchorBlock` property is depreacted. Use `document.closestBlock()` instead.' - ) - - return ( - this.selection.anchor.path && - this.document.getClosestBlock(this.selection.anchor.path) - ) - } - - get focusBlock() { - warning( - false, - 'As of slate@0.48, the `value.focusBlock` property is depreacted. Use `document.closestBlock()` instead.' - ) - - return ( - this.selection.focus.path && - this.document.getClosestBlock(this.selection.focus.path) - ) - } - - get startInline() { - warning( - false, - 'As of slate@0.48, the `value.startInline` property is depreacted. Use `document.closestInline()` instead.' - ) - - return ( - this.selection.start.path && - this.document.getClosestInline(this.selection.start.path) - ) - } - - get endInline() { - warning( - false, - 'As of slate@0.48, the `value.endInline` property is depreacted. Use `document.closestInline()` instead.' - ) - - return ( - this.selection.end.path && - this.document.getClosestInline(this.selection.end.path) - ) - } - - get anchorInline() { - warning( - false, - 'As of slate@0.48, the `value.anchorInline` property is depreacted. Use `document.closestInline()` instead.' - ) - - return ( - this.selection.anchor.path && - this.document.getClosestInline(this.selection.anchor.path) - ) - } - - get focusInline() { - warning( - false, - 'As of slate@0.48, the `value.focusInline` property is depreacted. Use `document.closestInline()` instead.' - ) - - return ( - this.selection.focus.path && - this.document.getClosestInline(this.selection.focus.path) - ) - } - - get startText() { - warning( - false, - 'As of slate@0.48, the `value.startText` property is depreacted. Use `document.getNode()` instead.' - ) - - return ( - this.selection.start.path && - this.document.getDescendant(this.selection.start.path) - ) - } - - get endText() { - warning( - false, - 'As of slate@0.48, the `value.endText` property is depreacted. Use `document.getNode()` instead.' - ) - - return ( - this.selection.end.path && - this.document.getDescendant(this.selection.end.path) - ) - } - - get anchorText() { - warning( - false, - 'As of slate@0.48, the `value.anchorText` property is depreacted. Use `document.getNode()` instead.' - ) - - return ( - this.selection.anchor.path && - this.document.getDescendant(this.selection.anchor.path) - ) - } - - get focusText() { - warning( - false, - 'As of slate@0.48, the `value.focusText` property is depreacted. Use `document.getNode()` instead.' - ) - - return ( - this.selection.focus.path && - this.document.getDescendant(this.selection.focus.path) - ) - } - - get nextBlock() { - warning( - false, - 'As of slate@0.48, the `value.nextBlock` property is depreacted. Use `document.nextBlock()` instead.' - ) - - return ( - this.selection.end.path && - this.document.getNextBlock(this.selection.end.path) - ) - } - - get previousBlock() { - warning( - false, - 'As of slate@0.48, the `value.previousBlock` property is depreacted. Use `document.previousBlock()` instead.' - ) - - return ( - this.selection.start.path && - this.document.getPreviousBlock(this.selection.start.path) - ) - } - - get nextInline() { - warning( - false, - 'As of slate@0.48, the `value.nextInline` property is depreacted. Use `document.nextInline()` instead.' - ) - - return ( - this.selection.end.path && - this.document.getNextInline(this.selection.end.path) - ) - } - - get previousInline() { - warning( - false, - 'As of slate@0.48, the `value.previousInline` property is depreacted. Use `document.previousInline()` instead.' - ) - - return ( - this.selection.start.path && - this.document.getPreviousInline(this.selection.start.path) - ) - } - - get nextText() { - warning( - false, - 'As of slate@0.48, the `value.nextText` property is depreacted. Use `document.nextText()` instead.' - ) - - return ( - this.selection.end.path && - this.document.getNextText(this.selection.end.path) - ) - } - - get previousText() { - warning( - false, - 'As of slate@0.48, the `value.previousText` property is depreacted. Use `document.previousText()` instead.' - ) - - return ( - this.selection.start.path && - this.document.getPreviousText(this.selection.start.path) - ) - } - - get marks() { - warning( - false, - 'As of slate@0.48, the `value.marks` property is depreacted. Use `document.marks()` instead.' - ) - - return this.selection.isUnset - ? new Set() - : this.selection.marks || this.document.getMarksAtRange(this.selection) - } - - get activeMarks() { - warning( - false, - 'As of slate@0.48, the `value.activeMarks` property is depreacted. Use `document.getActiveMarksAtRange()` instead.' - ) - - return this.selection.isUnset - ? new Set() - : this.selection.marks || - this.document.getActiveMarksAtRange(this.selection) - } - - get blocks() { - warning( - false, - 'As of slate@0.48, the `value.blocks` property is depreacted. Use `document.blocks()` instead.' - ) - - return this.selection.isUnset - ? new List() - : this.document.getLeafBlocksAtRange(this.selection) - } - - get fragment() { - warning( - false, - 'As of slate@0.48, the `value.fragment` property is depreacted. Use `document.getFragmentAtRange()` instead.' - ) - - return this.selection.isUnset - ? Document.create() - : this.document.getFragmentAtRange(this.selection) - } - - get inlines() { - warning( - false, - 'As of slate@0.48, the `value.inline` property is depreacted. Use `document.inline()` instead.' - ) - - return this.selection.isUnset - ? new List() - : this.document.getLeafInlinesAtRange(this.selection) - } - - get texts() { - warning( - false, - 'As of slate@0.48, the `value.texts` property is depreacted. Use `document.texts()` instead.' - ) - - return this.selection.isUnset - ? new List() - : this.document.getTextsAtRange(this.selection) - } - - mapRanges(iterator) { - warning( - false, - 'As of slate@0.47 the `value.mapRanges` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - const { document, selection, annotations } = value - - let sel = selection.isSet ? iterator(selection) : selection - if (!sel) sel = selection.unset() - if (sel !== selection) sel = document.createSelection(sel) - value = value.set('selection', sel) - - let anns = annotations.map(annotation => { - let n = annotation.isSet ? iterator(annotation) : annotation - if (n && n !== annotation) n = document.createAnnotation(n) - return n - }) - - anns = anns.filter(annotation => !!annotation) - value = value.set('annotations', anns) - return value - } - - mapPoints(iterator) { - warning( - false, - 'As of slate@0.47 the `value.mapPoints` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - return this.mapRanges(range => range.updatePoints(iterator)) - } - - mergeNode(path) { - warning( - false, - 'As of slate@0.47 the `value.mergeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - const { document } = value - const newDocument = document.mergeNode(path) - path = document.resolvePath(path) - const withPath = PathUtils.decrement(path) - const one = document.getNode(withPath) - const two = document.getNode(path) - value = value.set('document', newDocument) - - value = value.mapRanges(range => { - if (two.object === 'text') { - const max = one.text.length - - if (range.anchor.key === two.key) { - range = range.moveAnchorTo(one.key, max + range.anchor.offset) - } - - if (range.focus.key === two.key) { - range = range.moveFocusTo(one.key, max + range.focus.offset) - } - } - - range = range.updatePoints(point => point.setPath(null)) - - return range - }) - - return value - } - - splitNode(path, position, properties) { - warning( - false, - 'As of slate@0.47 the `value.splitNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - const { document } = value - const newDocument = document.splitNode(path, position, properties) - const node = document.assertNode(path) - value = value.set('document', newDocument) - - value = value.mapRanges(range => { - const next = newDocument.getNextText(node.key) - const { start, end } = range - - // If the start was after the split, move it to the next node. - if (node.key === start.key && position <= start.offset) { - range = range.moveStartTo(next.key, start.offset - position) - } - - // If the end was after the split, move it to the next node. - if (node.key === end.key && position <= end.offset) { - range = range.moveEndTo(next.key, end.offset - position) - } - - range = range.updatePoints(point => point.setPath(null)) - - return range - }) - - return value - } - - removeNode(path) { - warning( - false, - 'As of slate@0.47 the `value.removeNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document } = value - const node = document.assertNode(path) - const first = node.object === 'text' ? node : node.getFirstText() || node - const last = node.object === 'text' ? node : node.getLastText() || node - const prev = document.getPreviousText(first.key) - const next = document.getNextText(last.key) - - document = document.removeNode(path) - value = value.set('document', document) - - value = value.mapRanges(range => { - const { anchor, focus } = range - - if (node.hasNode(anchor.key)) { - range = prev - ? range.moveAnchorTo(prev.key, prev.text.length) - : next ? range.moveAnchorTo(next.key, 0) : range.unset() - } - - if (node.hasNode(focus.key)) { - range = prev - ? range.moveFocusTo(prev.key, prev.text.length) - : next ? range.moveFocusTo(next.key, 0) : range.unset() - } - - range = range.updatePoints(point => point.setPath(null)) - - return range - }) - - return value - } - - moveNode(path, newPath, newIndex = 0) { - warning( - false, - 'As of slate@0.47 the `value.moveNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document } = value - - if (PathUtils.isEqual(path, newPath)) { - return value - } - - document = document.moveNode(path, newPath, newIndex) - value = value.set('document', document) - value = value.mapPoints(point => point.setPath(null)) - return value - } - - removeText(path, offset, text) { - warning( - false, - 'As of slate@0.47 the `value.removeText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document } = value - const node = document.assertNode(path) - document = document.removeText(path, offset, text) - value = value.set('document', document) - - const { length } = text - const start = offset - const end = offset + length - - value = value.mapPoints(point => { - if (point.key !== node.key) { - return point - } - - if (point.offset >= end) { - return point.setOffset(point.offset - length) - } - - if (point.offset > start) { - return point.setOffset(start) - } - - return point - }) - - return value - } - - setNode(path, properties) { - warning( - false, - 'As of slate@0.47 the `value.setNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document } = value - document = document.setNode(path, properties) - value = value.set('document', document) - return value - } - - setAnnotation(properties, newProperties) { - warning( - false, - 'As of slate@0.47 the `value.setAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - newProperties = Annotation.createProperties(newProperties) - const annotation = Annotation.create(properties) - const next = annotation.merge(newProperties) - let value = this - let { annotations } = value - const { key } = annotation - annotations = annotations.set(key, next) - value = value.set('annotations', annotations) - return value - } - - setMark(path, mark, properties) { - warning( - false, - 'As of slate@0.47 the `value.setMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document } = value - document = document.setMark(path, mark, properties) - value = value.set('document', document) - return value - } - - setProperties(properties) { - warning( - false, - 'As of slate@0.47 the `value.setProperties` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - const { document } = value - const { data, annotations } = properties - const props = {} - - if (data) { - props.data = data - } - - if (annotations) { - props.annotations = annotations.map(a => { - return a.isSet ? a : document.resolveAnnotation(a) - }) - } - - value = value.merge(props) - return value - } - - setSelection(properties) { - warning( - false, - 'As of slate@0.47 the `value.setSelection` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document, selection } = value - const next = selection.setProperties(properties) - selection = document.resolveSelection(next) - value = value.set('selection', selection) - return value - } - - removeAnnotation(annotation) { - warning( - false, - 'As of slate@0.47 the `value.removeAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - annotation = Annotation.create(annotation) - let value = this - let { annotations } = value - const { key } = annotation - annotations = annotations.delete(key) - value = value.set('annotations', annotations) - return value - } - - removeMark(path, mark) { - warning( - false, - 'As of slate@0.47 the `value.removeMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - mark = Mark.create(mark) - let value = this - let { document } = value - document = document.removeMark(path, mark) - value = value.set('document', document) - return value - } - - addAnnotation(annotation) { - warning( - false, - 'As of slate@0.47 the `value.addAnnotation` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - annotation = Annotation.create(annotation) - let value = this - let { annotations, document } = value - const { key } = annotation - annotation = annotation.updatePoints(point => point.normalize(document)) - annotations = annotations.set(key, annotation) - value = value.set('annotations', annotations) - return value - } - - addMark(path, mark) { - warning( - false, - 'As of slate@0.47 the `value.addMark` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - mark = Mark.create(mark) - let value = this - let { document } = value - document = document.addMark(path, mark) - value = value.set('document', document) - return value - } - - insertNode(path, node) { - warning( - false, - 'As of slate@0.47 the `value.insertNode` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document } = value - document = document.insertNode(path, node) - value = value.set('document', document) - - value = value.mapRanges(range => - range.updatePoints(point => point.setPath(null)) - ) - - return value - } - - insertText(path, offset, text) { - warning( - false, - 'As of slate@0.47 the `value.insertText` method is deprecated. Use `Operations.apply` for low-level use cases instead.' - ) - - let value = this - let { document } = value - document = document.insertText(path, offset, text) - value = value.set('document', document) - - value = value.mapPoints(point => { - if (point.path.equals(path) && point.offset >= offset) { - return point.setOffset(point.offset + text.length) - } else { - return point - } - }) - - return value - } - - get history() { - invariant( - false, - 'As of Slate 0.42.0, the `value.history` model no longer exists, and the history is stored in `value.data` instead using plugins.' - ) - } - - change() { - invariant( - false, - 'As of Slate 0.42.0, value object are no longer schema-aware, and the `value.change()` method is no longer available. Use the `editor.change()` method on the new `Editor` controller instead.' - ) - } -} - -/** - * Export. - */ - -export default Value diff --git a/packages/slate/src/operations/apply.js b/packages/slate/src/operations/apply.js deleted file mode 100644 index 0d247014d9..0000000000 --- a/packages/slate/src/operations/apply.js +++ /dev/null @@ -1,408 +0,0 @@ -import Debug from 'debug' - -import Annotation from '../models/annotation' -import Operation from '../models/operation' -import Mark from '../models/mark' -import PathUtils from '../utils/path-utils' - -/** - * Debug. - * - * @type {Function} - */ - -const debug = Debug('slate:operation:apply') - -/** - * Apply an `op` to a `value`. - * - * @param {Value} value - * @param {Object|Operation} op - * @return {Value} value - */ - -function applyOperation(value, op) { - op = Operation.create(op) - const { type } = op - debug(type, op) - - switch (type) { - case 'add_annotation': { - const { annotation } = op - const { key } = annotation - const { annotations } = value - const newAnnotations = annotations.set(key, annotation) - const newValue = value.set('annotations', newAnnotations) - return newValue - } - - case 'add_mark': { - const { path, mark } = op - const { document } = value - const node = document.assertNode(path) - const { marks } = node - const newMarks = marks.add(mark) - const newNode = node.set('marks', newMarks) - const newDocument = document.replaceNode(path, newNode) - const newValue = value.set('document', newDocument) - return newValue - } - - case 'insert_node': { - const { path, node } = op - const { document } = value - const index = path.last() - const parentPath = PathUtils.lift(path) - const parentNode = document.assertNode(parentPath) - const newParentNodes = parentNode.nodes.splice(index, 0, node) - const newParentNode = parentNode.set('nodes', newParentNodes) - const newDocument = document.replaceNode(parentPath, newParentNode) - - const newValue = mapPoints(value.set('document', newDocument), point => { - const newPaths = PathUtils.transform(point.path, op) - const newPath = newPaths.first() - const newPoint = point.setPath(newPath).setKey(null) - return newPoint - }) - - return newValue - } - - case 'insert_text': { - const { path, offset, text } = op - const { document } = value - const node = document.assertNode(path) - const newText = - node.text.slice(0, offset) + text + node.text.slice(offset) - const newNode = node.set('text', newText) - const newDocument = document.replaceNode(path, newNode) - - const newValue = mapPoints(value.set('document', newDocument), point => { - if (point.path.equals(path) && point.offset >= offset) { - return point.setOffset(point.offset + text.length) - } else { - return point - } - }) - - return newValue - } - - case 'merge_node': { - const { path, position } = op - const { document } = value - const withPath = PathUtils.decrement(path) - const parentPath = PathUtils.lift(path) - const index = withPath.last() - const parent = document.assertNode(parentPath) - const a = document.assertNode(withPath) - const b = document.assertNode(path) - - const newNode = - a.object === 'text' - ? a.mergeText(b) - : a.set('nodes', a.nodes.concat(b.nodes)) - - const newParentNodes = parent.nodes.splice(index, 2, newNode) - const newParent = parent.set('nodes', newParentNodes) - const newDocument = document.replaceNode(parentPath, newParent) - - const newValue = mapPoints(value.set('document', newDocument), point => { - if (point.path.equals(path)) { - const newPath = PathUtils.decrement(point.path) - const newOffset = point.offset + position - return point.moveTo(newPath, newOffset).setKey(null) - } else if (PathUtils.isAbove(path, point.path)) { - let newPath = PathUtils.decrement(point.path, 1, path.size - 1) - newPath = PathUtils.increment(newPath, position, path.size) - return point.setPath(newPath).setKey(null) - } else if (PathUtils.isYounger(path, point.path)) { - const newPath = PathUtils.decrement(point.path, 1, path.size - 1) - return point.setPath(newPath).setKey(null) - } else { - return point - } - }) - - return newValue - } - - case 'move_node': { - const { path } = op - const { document } = value - const index = path.last() - const parentPath = PathUtils.lift(path) - const node = document.assertNode(path) - const parent = document.assertNode(parentPath) - const nextParentNodes = parent.nodes.splice(index, 1) - const nextParent = parent.set('nodes', nextParentNodes) - let nextDocument = document.replaceNode(parentPath, nextParent) - - // This is a bit tricky, but since the `path` and `newPath` both refer to - // the same snapshot in time, after either inserting or removing as the - // first step, the second step's path can be out of date. So instead of - // using the `op.newPath` directly, we transform `op.path` to ascertain - // what the `newPath` would be after the operation was applied. - const newPath = PathUtils.transform(path, op).first() - - const newIndex = newPath.last() - const newParentPath = PathUtils.lift(newPath) - const newParent = nextDocument.assertNode(newParentPath) - const nextNewParentNodes = newParent.nodes.splice(newIndex, 0, node) - const nextNewParent = newParent.set('nodes', nextNewParentNodes) - nextDocument = nextDocument.replaceNode(newParentPath, nextNewParent) - - const nextValue = mapPoints( - value.set('document', nextDocument), - point => { - const nextPath = PathUtils.transform(point.path, op).first() - return point.setPath(nextPath).setKey(null) - } - ) - - return nextValue - } - - case 'remove_annotation': { - const { annotation } = op - const { key } = annotation - const { annotations } = value - const newAnnotations = annotations.delete(key) - const newValue = value.set('annotations', newAnnotations) - return newValue - } - - case 'remove_mark': { - const { path, mark } = op - const { document } = value - const node = document.assertNode(path) - const { marks } = node - const newMarks = marks.remove(mark) - const newNode = node.set('marks', newMarks) - const newDocument = document.replaceNode(path, newNode) - const newValue = value.set('document', newDocument) - return newValue - } - - case 'remove_node': { - const { path } = op - const { document } = value - const index = path.last() - const parentPath = PathUtils.lift(path) - const parentNode = document.assertNode(parentPath) - const newParentNodes = parentNode.nodes.splice(index, 1) - const newParentNode = parentNode.set('nodes', newParentNodes) - const newDocument = document.replaceNode(parentPath, newParentNode) - - const prev = document.previousText(path) - const next = document.nextText(path) - - const newValue = mapPoints(value.set('document', newDocument), point => { - const newPath = PathUtils.transform(point.path, op).first() - - if (newPath) { - return point.setPath(newPath).setKey(null) - } else if (prev) { - const [prevNode, prevPath] = prev - return point.moveTo(prevPath, prevNode.text.length).setKey(null) - } else if (next) { - let [, nextPath] = next - nextPath = PathUtils.transform(nextPath, op).first() - return point.moveTo(nextPath, 0).setKey(null) - } else { - return point.unset() - } - }) - - return newValue - } - - case 'remove_text': { - const { path, offset, text } = op - const { length } = text - const { document } = value - const node = document.assertNode(path) - const newText = - node.text.slice(0, offset) + node.text.slice(offset + length) - const newNode = node.set('text', newText) - const newDocument = document.replaceNode(path, newNode) - - const newValue = mapPoints(value.set('document', newDocument), point => { - const isEqual = point.path.equals(path) - const isEnd = point.offset >= offset + length - const isStart = point.offset > offset - - if (isEqual && isEnd) { - return point.setOffset(point.offset - length) - } else if (isEqual && isStart) { - return point.setOffset(offset) - } else { - return point - } - }) - - return newValue - } - - case 'set_annotation': { - const { properties, newProperties } = op - const { annotations } = value - const newAnnotation = Annotation.create({ - ...properties, - ...newProperties, - }) - - const { key } = newAnnotation - const newAnnotations = annotations.set(key, newAnnotation) - const newValue = value.set('annotations', newAnnotations) - return newValue - } - - case 'set_mark': { - const { path, properties, newProperties } = op - const { document } = value - const mark = Mark.create(properties) - const newMark = Mark.create({ ...properties, ...newProperties }) - const node = document.assertNode(path) - const { marks } = node - const newMarks = marks.remove(mark).add(newMark) - const newNode = node.set('marks', newMarks) - const newDocument = document.replaceNode(path, newNode) - const newValue = value.set('document', newDocument) - return newValue - } - - case 'set_node': { - const { path, newProperties } = op - const { document } = value - const node = document.assertNode(path) - const newNode = node.merge(newProperties) - const newDocument = document.replaceNode(path, newNode) - const newValue = value.set('document', newDocument) - return newValue - } - - case 'set_selection': { - const { newProperties } = op - const { document, selection } = value - let newSelection = selection.setProperties(newProperties) - - // TODO: this should not be required, and seems actively bad. The op - // should come in with correct properties already, so they shouldn't need - // to be resolved again. - newSelection = document.resolveSelection(newSelection) - - const newValue = value.set('selection', newSelection) - return newValue - } - - case 'set_value': { - const { newProperties } = op - const { document } = value - let { data, annotations } = newProperties - let newValue = value - - if (data) { - newValue = newValue.set('data', data) - } - - if (annotations) { - // TODO: this should not happen, because again the ranges should already - // be resolved relative to the document when the operation is created. - annotations = annotations.map( - a => (a.isSet ? a : document.resolveAnnotation(a)) - ) - - newValue = newValue.set('annotations', annotations) - } - - return newValue - } - - case 'split_node': { - const { path, position, properties } = op - const { document } = value - const node = document.assertNode(path) - let a - let b - - if (node.object === 'text') { - ;[a, b] = node.splitText(position) - } else { - const befores = node.nodes.take(position) - const afters = node.nodes.skip(position) - a = node.set('nodes', befores) - b = node.set('nodes', afters).regenerateKey() - - // TODO: remove this conditional, and always merge these - if (properties) { - b = b.merge(properties) - } - } - - const parentPath = PathUtils.lift(path) - const parent = document.assertNode(parentPath) - const index = path.last() - const newParentNodes = parent.nodes.splice(index, 1, a, b) - const newParent = parent.set('nodes', newParentNodes) - const newDocument = document.replaceNode(parentPath, newParent) - - const newValue = mapPoints(value.set('document', newDocument), point => { - if (point.path.equals(path) && position <= point.offset) { - const newPath = PathUtils.increment(point.path, 1, path.size - 1) - const newOffset = point.offset - position - return point.moveTo(newPath, newOffset).setKey(null) - } else if ( - PathUtils.isAbove(path, point.path) && - position <= point.path.get(path.size) - ) { - let newPath = PathUtils.increment(point.path, 1, path.size - 1) - newPath = PathUtils.decrement(newPath, position, path.size) - return point.setPath(newPath).setKey(null) - } else if (PathUtils.isYounger(path, point.path)) { - const newPath = PathUtils.increment(point.path, 1, path.size - 1) - return point.setPath(newPath).setKey(null) - } else { - return point - } - }) - - return newValue - } - - default: { - throw new Error(`Unknown operation type: "${type}".`) - } - } -} - -function mapRanges(value, iterator) { - const { document, selection, annotations } = value - - let sel = selection.isSet ? iterator(selection) : selection - if (!sel) sel = selection.unset() - if (sel !== selection) sel = document.createSelection(sel) - value = value.set('selection', sel) - - let anns = annotations.map(annotation => { - let n = annotation.isSet ? iterator(annotation) : annotation - if (n && n !== annotation) n = document.createAnnotation(n) - return n - }) - - anns = anns.filter(annotation => !!annotation) - value = value.set('annotations', anns) - return value -} - -function mapPoints(value, iterator) { - return mapRanges(value, range => range.updatePoints(iterator)) -} - -/** - * Export. - * - * @type {Function} - */ - -export default applyOperation diff --git a/packages/slate/src/operations/index.js b/packages/slate/src/operations/index.js deleted file mode 100644 index bf84bb7d04..0000000000 --- a/packages/slate/src/operations/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import apply from './apply' -import invert from './invert' - -/** - * Export. - * - * @type {Object} - */ - -export default { - apply, - invert, -} diff --git a/packages/slate/src/operations/invert.js b/packages/slate/src/operations/invert.js deleted file mode 100644 index c4bf306968..0000000000 --- a/packages/slate/src/operations/invert.js +++ /dev/null @@ -1,112 +0,0 @@ -import Debug from 'debug' - -import Operation from '../models/operation' -import PathUtils from '../utils/path-utils' - -/** - * Debug. - * - * @type {Function} - */ - -const debug = Debug('slate:operation:invert') - -/** - * Invert an `op`. - * - * @param {Object} op - * @return {Object} - */ - -function invertOperation(op) { - op = Operation.create(op) - const { type } = op - debug(type, op) - - switch (type) { - case 'move_node': { - const { newPath, path } = op - - // PERF: this case can exit early. - if (PathUtils.isEqual(newPath, path)) { - return op - } - - const inversePath = PathUtils.transform(path, op).first() - - // Get the true path we are trying to move back to - // We transform the right-sibling of the path - // This will end up at the operation.path most of the time - // But if the newPath is a left-sibling or left-ancestor-sibling, this will account for it - const inverseNewPath = PathUtils.transform( - PathUtils.increment(path), - op - ).first() - - const inverse = op.set('path', inversePath).set('newPath', inverseNewPath) - return inverse - } - - case 'merge_node': { - const { path } = op - const inversePath = PathUtils.decrement(path) - const inverse = op.set('type', 'split_node').set('path', inversePath) - return inverse - } - - case 'split_node': { - const { path } = op - const inversePath = PathUtils.increment(path) - const inverse = op.set('type', 'merge_node').set('path', inversePath) - return inverse - } - - case 'set_annotation': - case 'set_node': - case 'set_value': - case 'set_selection': - case 'set_mark': { - const { properties, newProperties } = op - const inverse = op - .set('properties', newProperties) - .set('newProperties', properties) - return inverse - } - - case 'insert_node': - case 'insert_text': { - const inverse = op.set('type', type.replace('insert_', 'remove_')) - return inverse - } - - case 'remove_node': - case 'remove_text': { - const inverse = op.set('type', type.replace('remove_', 'insert_')) - return inverse - } - - case 'add_annotation': - case 'add_mark': { - const inverse = op.set('type', type.replace('add_', 'remove_')) - return inverse - } - - case 'remove_annotation': - case 'remove_mark': { - const inverse = op.set('type', type.replace('remove_', 'add_')) - return inverse - } - - default: { - throw new Error(`Unknown operation type: "${type}".`) - } - } -} - -/** - * Export. - * - * @type {Function} - */ - -export default invertOperation diff --git a/packages/slate/src/plugins/core/core-commands.js b/packages/slate/src/plugins/core/core-commands.js deleted file mode 100644 index 800144ae17..0000000000 --- a/packages/slate/src/plugins/core/core-commands.js +++ /dev/null @@ -1,35 +0,0 @@ -import AtPoint from '../../commands/at-point' -import AtRange from '../../commands/at-range' -import ByPath from '../../commands/by-path' -import OnHistory from '../../commands/on-history' -import OnSelection from '../../commands/on-selection' -import OnValue from '../../commands/on-value' -import WithIntent from '../../commands/with-intent' - -/** - * A plugin that defines the core Slate commands. - * - * @return {Object} - */ - -function CoreCommandsPlugin() { - return { - onConstruct: () => () => {}, - onChange: () => () => {}, - ...AtPoint, - ...AtRange, - ...ByPath, - ...OnHistory, - ...OnSelection, - ...OnValue, - ...WithIntent, - } -} - -/** - * Export. - * - * @type {Object} - */ - -export default CoreCommandsPlugin diff --git a/packages/slate/src/plugins/core/core-queries.js b/packages/slate/src/plugins/core/core-queries.js deleted file mode 100644 index 878cb4022d..0000000000 --- a/packages/slate/src/plugins/core/core-queries.js +++ /dev/null @@ -1,29 +0,0 @@ -import * as Format from '../../queries/format' -import * as Node from '../../queries/node' -import * as Path from '../../queries/path' -import * as Point from '../../queries/point' -import * as Range from '../../queries/range' - -/** - * A plugin that defines the core Slate queries. - * - * @return {Object} - */ - -function CoreQueriesPlugin() { - return { - ...Format, - ...Node, - ...Path, - ...Point, - ...Range, - } -} - -/** - * Export. - * - * @type {Object} - */ - -export default CoreQueriesPlugin diff --git a/packages/slate/src/plugins/core/core-schema.js b/packages/slate/src/plugins/core/core-schema.js deleted file mode 100644 index 6885c5d8bd..0000000000 --- a/packages/slate/src/plugins/core/core-schema.js +++ /dev/null @@ -1,164 +0,0 @@ -import Schema from '../schema' -import Text from '../../models/text' -import Path from '../../utils/path-utils' - -/** - * A plugin that defines the core Slate schema. - * - * @param {Object} options - * @return {Object} - */ - -function CoreSchemaPlugin(options = {}) { - return Schema({ - rules: [ - // Only allow block nodes in documents. - { - match: { object: 'document' }, - nodes: [ - { - match: { object: 'block' }, - }, - ], - }, - - // Only allow block nodes or inline and text nodes in blocks. - { - match: { - object: 'block', - first: { object: 'block' }, - }, - nodes: [ - { - match: { object: 'block' }, - }, - ], - }, - { - match: { - object: 'block', - first: [{ object: 'inline' }, { object: 'text' }], - }, - nodes: [ - { - match: [{ object: 'inline' }, { object: 'text' }], - }, - ], - }, - - // Only allow inline and text nodes in inlines. - { - match: { object: 'inline' }, - nodes: [{ match: [{ object: 'inline' }, { object: 'text' }] }], - }, - - // Ensure that block and inline nodes have at least one text child. - { - match: [{ object: 'block' }, { object: 'inline' }], - nodes: [{ min: 1 }], - normalize: (editor, error) => { - const { code, path } = error - - if (code === 'child_min_invalid') { - const text = Text.create() - editor.insertNodeByPath(path, text) - } - }, - }, - - // Ensure that inline nodes are surrounded by text nodes. - { - match: { object: 'block' }, - first: [{ object: 'block' }, { object: 'text' }], - last: [{ object: 'block' }, { object: 'text' }], - normalize: (editor, error) => { - const { code, path } = error - let targetPath - - if (code === 'first_child_object_invalid') { - targetPath = path - } else if (code === 'last_child_object_invalid') { - targetPath = Path.increment(path) - } else { - return - } - - const text = Text.create() - editor.insertNodeByPath(targetPath, text) - }, - }, - { - match: { object: 'inline' }, - first: [{ object: 'block' }, { object: 'text' }], - last: [{ object: 'block' }, { object: 'text' }], - previous: [{ object: 'block' }, { object: 'text' }], - next: [{ object: 'block' }, { object: 'text' }], - normalize: (editor, error) => { - const { code, path } = error - let targetPath - - if ( - code === 'first_child_object_invalid' || - code === 'next_sibling_object_invalid' - ) { - targetPath = path - } else if ( - code === 'last_child_object_invalid' || - code === 'previous_sibling_object_invalid' - ) { - targetPath = Path.increment(path) - } else { - return - } - - const text = Text.create() - editor.insertNodeByPath(targetPath, text) - }, - }, - - // Merge adjacent text nodes with the same marks. - { - match: { object: 'text' }, - next: (next, match) => { - return next.object !== 'text' || !match.marks.equals(next.marks) - }, - normalize: (editor, error) => { - const { code, path } = error - - if (code === 'next_sibling_invalid') { - editor.mergeNodeByPath(path) - } - }, - }, - - // Remove extra adjacent empty text nodes. - { - match: { object: 'text' }, - previous: prev => { - return prev.object !== 'text' || prev.text !== '' - }, - next: next => { - return next.object !== 'text' || next.text !== '' - }, - normalize: (editor, error) => { - const { code, path } = error - - if ( - code === 'next_sibling_invalid' || - code === 'previous_sibling_invalid' - ) { - editor.removeNodeByPath(path) - } - }, - }, - ], - }) -} - -/** - * Export. - * - * @type {Object} - */ - -export default CoreSchemaPlugin diff --git a/packages/slate/src/plugins/core/index.js b/packages/slate/src/plugins/core/index.js deleted file mode 100644 index 6c60082361..0000000000 --- a/packages/slate/src/plugins/core/index.js +++ /dev/null @@ -1,26 +0,0 @@ -import CoreQueries from './core-queries' -import CoreCommands from './core-commands' -import CoreSchema from './core-schema' - -/** - * A plugin that defines the core Slate logic. - * - * @param {Object} options - * @return {Object} - */ - -function CorePlugin(options = {}) { - const { plugins = [] } = options - const schema = CoreSchema(options) - const queries = CoreQueries(options) - const commands = CoreCommands(options) - return [schema, ...plugins, commands, queries] -} - -/** - * Export. - * - * @type {Object} - */ - -export default CorePlugin diff --git a/packages/slate/src/plugins/history/history.ts b/packages/slate/src/plugins/history/history.ts new file mode 100644 index 0000000000..a016467ca4 --- /dev/null +++ b/packages/slate/src/plugins/history/history.ts @@ -0,0 +1,46 @@ +import isPlainObject from 'is-plain-object' +import { Operation } from '../..' + +/** + * `HistoryBatch` arrays hold a batch of operations that are applied as a single + * step in the history. They can be merged together with previous batches. + */ + +type HistoryBatch = Operation[] + +/** + * `History` objects hold all of the operations that are applied to a value, so + * they can be undone or redone as necessary. + */ + +interface History { + redos: HistoryBatch[] + undos: HistoryBatch[] +} + +namespace History { + /** + * Check if an object implements the `History` interface. + */ + + export const isHistory = (object: any): object is History => { + return ( + isPlainObject(object) && + isHistoryBatch(object.redos) && + isHistoryBatch(object.undos) + ) + } + + /** + * Check if an object implements the `HistoryBatch` interface. + */ + + export const isHistoryBatch = (object: any): object is HistoryBatch => { + return ( + Array.isArray(object) && + (object.length === 0 || Operation.isOperation(object[0])) + ) + } +} + +export { History, HistoryBatch } diff --git a/packages/slate/src/plugins/history/index.ts b/packages/slate/src/plugins/history/index.ts new file mode 100644 index 0000000000..973119ebbc --- /dev/null +++ b/packages/slate/src/plugins/history/index.ts @@ -0,0 +1,2 @@ +export { HistoryPlugin } from './plugin' +export { History, HistoryBatch } from './history' diff --git a/packages/slate/src/plugins/history/plugin.ts b/packages/slate/src/plugins/history/plugin.ts new file mode 100644 index 0000000000..abf245aa8a --- /dev/null +++ b/packages/slate/src/plugins/history/plugin.ts @@ -0,0 +1,230 @@ +import { produce } from 'immer' +import { EditorConstructor, Operation, Path } from '../..' +import { History } from './history' + +const HISTORY = Symbol('history') +const SAVING = Symbol('saving') +const MERGING = Symbol('merging') + +/** + * The `HistoryPlugin` keeps track of the operation history of a Slate editor as + * operations are applied to it, using undo and redo stacks. + */ + +const HistoryPlugin = () => { + return (Base: EditorConstructor) => { + return class extends Base { + [HISTORY]: History; + [MERGING]: boolean | null; + [SAVING]: boolean + + /** + * Setup defaults for weak maps on construct. + */ + + constructor(...args: any[]) { + super(...args) + const history: History = produce({ undos: [], redos: [] }, () => {}) + this[HISTORY] = history + this[MERGING] = null + this[SAVING] = true + } + + /** + * When an operation is applied to the editor, save it. + */ + + apply(op: Operation): void { + const { operations } = this + const history = this[HISTORY] + let save = this[SAVING] + let merge = this[MERGING] + + if (save === false || !shouldSave(op)) { + super.apply(op) + return + } + + this[HISTORY] = produce(history, h => { + const { undos } = h + const lastBatch = undos[undos.length - 1] + const lastOp = lastBatch && lastBatch[lastBatch.length - 1] + + // If `merge` is non-commital, and this is not the first operation in + // a new editor, then merge, otherwise merge based on the last + // operation. + if (merge == null) { + if (operations.length !== 0) { + merge = true + } else { + merge = shouldMerge(op, lastOp) + } + } + + // If the `merge` flag is true, add the operation to the last batch. + if (merge && lastBatch) { + lastBatch.push(op) + } else { + const batch = [op] + undos.push(batch) + } + + while (undos.length > 100) { + undos.shift() + } + + h.redos = [] + }) + + super.apply(op) + } + + /** + * Get the history object for the editor. + */ + + getHistory(): History { + return this[HISTORY] + } + + /** + * Redo to the next value in the history. + */ + + redo(): void { + const history = this[HISTORY] + const { redos } = history + + if (redos.length === 0) { + return + } + + const batch = redos[redos.length - 1] + + this.withoutSaving(() => { + this.withoutNormalizing(() => { + for (const op of batch) { + this.apply(op) + } + }) + }) + + this[HISTORY] = produce(history, h => { + h.redos.pop() + h.undos.push(batch) + }) + } + + /** + * Undo the previous operations in the history. + */ + + undo(): void { + const history = this[HISTORY] + const { undos } = history + + if (undos.length === 0) { + return + } + + const batch = undos[undos.length - 1] + + this.withoutSaving(() => { + this.withoutNormalizing(() => { + const inverseOps = batch.map(Operation.inverse).reverse() + + for (const op of inverseOps) { + this.apply(op) + } + }) + }) + + this[HISTORY] = produce(history, h => { + h.redos.push(batch) + h.undos.pop() + }) + } + + /** + * Apply a series of changes inside a synchronous `fn`, without merging any of + * the new operations into previous save point in the history. + */ + + withoutMerging(fn: () => void): void { + const prev = this[MERGING] + this[MERGING] = false + fn() + this[MERGING] = prev + } + + /** + * Apply a series of changes inside a synchronous `fn`, without saving any of + * their operations into the history. + */ + + withoutSaving(fn: () => void): void { + const prev = this[SAVING] + this[SAVING] = false + fn() + this[SAVING] = prev + } + } + } +} + +/** + * Check whether to merge an operation into the previous operation. + */ + +const shouldMerge = (op: Operation, into: Operation | null): boolean => { + if (into == null) { + return false + } + + if (op.type === 'set_selection' && into.type === 'set_selection') { + return true + } + + if ( + op.type === 'insert_text' && + into.type === 'insert_text' && + op.offset === into.offset + into.text.length && + Path.equals(op.path, into.path) + ) { + return true + } + + if ( + op.type === 'remove_text' && + into.type === 'remove_text' && + op.offset + op.text.length === into.offset && + Path.equals(op.path, into.path) + ) { + return true + } + + return false +} + +/** + * Check whether an operation needs to be saved to the history. + */ + +const shouldSave = (op: Operation): boolean => { + if (op.type === 'set_selection') { + const { newProperties } = op + + if ( + newProperties != null && + 'isFocused' in newProperties && + !('anchor' in newProperties) && + !('focus' in newProperties) + ) { + return false + } + } + + return true +} + +export { HistoryPlugin } diff --git a/packages/slate/src/plugins/schema/checkers.ts b/packages/slate/src/plugins/schema/checkers.ts new file mode 100644 index 0000000000..bdfa151f9b --- /dev/null +++ b/packages/slate/src/plugins/schema/checkers.ts @@ -0,0 +1,373 @@ +import { + Ancestor, + Annotation, + Element, + Mark, + Node, + Path, + Text, + Value, +} from '../..' +import { SchemaError } from './error' +import { SchemaRule, SchemaCheck } from './rule' + +/** + * Check an annotation object. + */ + +export const checkAnnotation = ( + annotation: Annotation, + key: string, + check: SchemaCheck +): SchemaError | undefined => { + if (typeof check === 'function') { + if (check(annotation)) { + return + } else { + return { code: 'annotation_invalid', annotation, key } + } + } + + if ( + 'object' in check && + check.object === 'annotation' && + !Annotation.isAnnotation(annotation) + ) { + return { code: 'annotation_object_invalid', annotation, key } + } + + if ('properties' in check) { + for (const k in check.properties) { + const fn = check.properties[k] + const value = annotation[k] + + if (!fn(value)) { + return { + code: 'annotation_property_invalid', + annotation, + key, + property: k, + } + } + } + } +} + +/** + * Check a mark object. + */ + +export const checkMark = ( + mark: Mark, + index: number, + node: Text, + path: Path, + check: SchemaCheck +): SchemaError | undefined => { + if (typeof check === 'function') { + if (check(mark)) { + return + } else { + return { code: 'mark_invalid', mark, index, node, path } + } + } + + if ('object' in check && check.object === 'mark' && !Mark.isMark(mark)) { + return { code: 'mark_object_invalid', mark, index, node, path } + } + + if ('properties' in check) { + for (const k in check.properties) { + const p = check.properties[k] + const value = mark[k] + + if ((typeof p === 'function' && !p(value)) || p !== value) { + return { + code: 'mark_property_invalid', + mark, + index, + node, + path, + property: k, + } + } + } + } +} + +/** + * Check a node object. + */ + +export const checkNode = ( + node: Node, + path: Path, + check: SchemaCheck, + rules: SchemaRule[] +): SchemaError | undefined => { + if (typeof check === 'function') { + if (check(node)) { + return + } else { + return { code: 'node_invalid', node, path } + } + } + + if ( + 'object' in check && + ((check.object === 'value' && !Value.isValue(node)) || + (check.object === 'element' && !Element.isElement(node)) || + (check.object === 'text' && !Text.isText(node))) + ) { + return { code: 'node_object_invalid', node, path } + } + + if ('properties' in check) { + for (const k in check.properties) { + const p = check.properties[k] + const value = node[k] + + if ((typeof p === 'function' && !p(value)) || p !== value) { + return { code: 'node_property_invalid', node, path, property: k } + } + } + } + + if ('marks' in check && check.marks != null) { + for (const [mark, index, n, p] of Node.marks(node)) { + for (const c of check.marks) { + const e = checkMark(mark, index, n, path.concat(p), c) + + if (e) { + return e + } + } + } + } + + if ('text' in check && check.text != null) { + const text = Node.text(node) + const valid = + typeof check.text === 'function' + ? check.text(text) + : check.text.test(text) + + if (!valid) { + return { code: 'node_text_invalid', node, path, text } + } + } + + if (!Text.isText(node)) { + const error = checkAncestor(node, path, check, rules) + + if (error) { + return error + } + } +} + +/** + * Check an ancestor object. + */ + +export const checkAncestor = ( + node: Ancestor, + path: Path, + check: SchemaCheck, + rules: SchemaRule[] +): SchemaError | undefined => { + if ('first' in check && check.first != null && node.nodes.length !== 0) { + const n = Node.child(node, 0) + const p = path.concat(0) + const e = checkNode(n, p, check.first, rules) + + if (e) { + if (e.code === 'node_invalid') { + return { ...e, code: 'first_child_invalid', node: n, index: 0 } + } else if (e.code === 'node_object_invalid') { + return { ...e, code: 'first_child_object_invalid', node: n, index: 0 } + } else if (e.code === 'node_property_invalid') { + return { ...e, code: 'first_child_property_invalid', node: n, index: 0 } + } + } + } + + if ('last' in check && check.last != null && node.nodes.length !== 0) { + const i = node.nodes.length - 1 + const n = Node.child(node, i) + const p = path.concat(i) + const e = checkNode(n, p, check.last, rules) + + if (e) { + if (e.code === 'node_invalid') { + return { ...e, code: 'last_child_invalid', node: n, index: i } + } else if (e.code === 'node_object_invalid') { + return { ...e, code: 'last_child_object_invalid', node: n, index: i } + } else if (e.code === 'node_property_invalid') { + return { ...e, code: 'last_child_property_invalid', node: n, index: i } + } + } + } + + const processed = new Set() + let d = 0 + let m = 0 + let i = 0 + + while (i < node.nodes.length) { + const n = Node.child(node, i) + const p = path.concat(i) + + if (!processed.has(i)) { + for (const rule of rules) { + if ( + ('parent' in check || + ('previous' in check && i > 0) || + ('next' in check && i < node.nodes.length - 1)) && + checkNode(n, p, rule.match, rules) === undefined + ) { + if ('parent' in check && check.parent != null) { + const e = checkNode(node, path, check.parent, rules) + + if (e) { + if (e.code === 'node_invalid') { + return { ...e, index: i, node, code: 'parent_invalid' } + } else if (e.code === 'node_object_invalid') { + return { ...e, index: i, node, code: 'parent_object_invalid' } + } else if (e.code === 'node_property_invalid') { + return { ...e, index: i, node, code: 'parent_property_invalid' } + } + } + } + + if ('previous' in check && check.previous != null) { + const prevN = Node.child(node, i - 1) + const prevP = path.concat(i - 1) + const e = checkNode(prevN, prevP, check.previous, rules) + + if (e) { + if (e.code === 'node_invalid') { + return { ...e, code: 'previous_sibling_invalid' } + } else if (e.code === 'node_object_invalid') { + return { ...e, code: 'previous_sibling_object_invalid' } + } else if (e.code === 'node_property_invalid') { + return { ...e, code: 'previous_sibling_property_invalid' } + } + } + } + + if ('next' in check && check.next != null) { + const nextN = Node.child(node, i + 1) + const nextP = path.concat(i + 1) + const e = checkNode(nextN, nextP, check.next, rules) + + if (e) { + if (e.code === 'node_invalid') { + return { ...e, code: 'next_sibling_invalid' } + } else if (e.code === 'node_object_invalid') { + return { ...e, code: 'next_sibling_object_invalid' } + } else if (e.code === 'node_property_invalid') { + return { ...e, code: 'next_sibling_property_invalid' } + } + } + } + } + } + } + + processed.add(i) + + if ('children' in check && check.children != null) { + const child = check.children[d] + const max = child.max != null ? child.max : Infinity + const min = child.min != null ? child.min : 0 + + // If the children assertion was defined, but we don't current have a + // definition, we've reached the end so any other children are overflows. + if (!child) { + return { code: 'child_overflow', node: n, path: p, index: i } + } + + if (child.match != null) { + const e = checkNode(n, p, child.match, rules) + + if (e) { + // Since we want to report overflow on last matching child we don't + // immediately check for count > max, but instead do so once we find + // a child that doesn't match. + if (m - 1 > max) { + return { + code: 'child_max_invalid', + node: n, + path: p, + index: i, + count: m, + max, + } + } + + // If there are more children definitions after this one, then this + // child might actually be valid for a future one. + if (check.children.length > d + 1) { + // If we've already satisfied the current child definition's minimum + // then we can proceed to the next definition. + if (m >= min) { + d++ + continue + } + + // There might just not be enough elements for current group, and + // current child is in fact the first of the next group. If so, the + // next def will not report errors, in which case we can rewind and + // report an minimum error. + const nextChild = check.children[d + 1] + + if ( + nextChild && + nextChild.match != null && + checkNode(n, p, nextChild.match, rules) === undefined + ) { + return { + code: 'child_min_invalid', + node: n, + path: p, + index: i, + count: m, + min, + } + } + } + + // Otherwise either we exhausted the last group, in which case it's + // an unknown child, ... + if (m > max) { + return { code: 'child_overflow', node: n, path: p, index: i } + } + + // ... or it's an invalid child. + if (e.code === 'node_invalid') { + return { ...e, node: n, path: p, index: i, code: 'child_invalid' } + } else if (e.code === 'node_object_invalid') { + return { + ...e, + code: 'child_object_invalid', + node: n, + path: p, + index: i, + } + } else if (e.code === 'node_property_invalid') { + return { + ...e, + code: 'child_property_invalid', + node: n, + path: p, + index: i, + } + } + } + } + } + + i++ + } +} diff --git a/packages/slate/src/plugins/schema/error.ts b/packages/slate/src/plugins/schema/error.ts new file mode 100644 index 0000000000..476dd65d27 --- /dev/null +++ b/packages/slate/src/plugins/schema/error.ts @@ -0,0 +1,266 @@ +import { + Ancestor, + Annotation, + Descendant, + Element, + Mark, + Node, + Path, + Text, +} from '../..' + +interface AnnotationInvalidError { + code: 'annotation_invalid' + annotation: Annotation + key: string +} + +interface AnnotationObjectInvalidError { + code: 'annotation_object_invalid' + annotation: Annotation + key: string +} + +interface AnnotationPropertyInvalidError { + code: 'annotation_property_invalid' + annotation: Annotation + key: string + property: string +} + +interface ChildInvalidError { + code: 'child_invalid' + node: Descendant + path: Path + index: number +} + +interface ChildMaxInvalidError { + code: 'child_max_invalid' + node: Descendant + path: Path + index: number + count: number + max: number +} + +interface ChildMinInvalidError { + code: 'child_min_invalid' + node: Descendant + path: Path + index: number + count: number + min: number +} + +interface ChildObjectInvalidError { + code: 'child_object_invalid' + node: Descendant + path: Path + index: number +} + +interface ChildOverflowError { + code: 'child_overflow' + node: Descendant + path: Path + index: number +} + +interface ChildPropertyInvalidError { + code: 'child_property_invalid' + node: Descendant + path: Path + index: number + property: string +} + +interface FirstChildInvalidError { + code: 'first_child_invalid' + node: Descendant + path: Path + index: number +} + +interface FirstChildObjectInvalidError { + code: 'first_child_object_invalid' + node: Descendant + path: Path + index: number +} + +interface FirstChildPropertyInvalidError { + code: 'first_child_property_invalid' + node: Descendant + path: Path + index: number + property: string +} + +interface LastChildInvalidError { + code: 'last_child_invalid' + node: Descendant + path: Path + index: number +} + +interface LastChildObjectInvalidError { + code: 'last_child_object_invalid' + node: Descendant + path: Path + index: number +} + +interface LastChildPropertyInvalidError { + code: 'last_child_property_invalid' + node: Descendant + path: Path + index: number + property: string +} + +interface NextSiblingInvalidError { + code: 'next_sibling_invalid' + node: Node + path: Path +} + +interface NextSiblingObjectInvalidError { + code: 'next_sibling_object_invalid' + node: Node + path: Path +} + +interface NextSiblingPropertyInvalidError { + code: 'next_sibling_property_invalid' + node: Node + path: Path + property: string +} + +interface NodeTextInvalidError { + code: 'node_text_invalid' + node: Node + path: Path + text: string +} + +interface NodeInvalidError { + code: 'node_invalid' + node: Node + path: Path +} + +interface NodePropertyInvalidError { + code: 'node_property_invalid' + node: Node + path: Path + property: string +} + +interface NodeObjectInvalidError { + code: 'node_object_invalid' + node: Node + path: Path +} + +interface MarkInvalidError { + code: 'mark_invalid' + mark: Mark + index: number + node: Text + path: Path +} + +interface MarkObjectInvalidError { + code: 'mark_object_invalid' + mark: Mark + index: number + node: Text + path: Path +} + +interface MarkPropertyInvalidError { + code: 'mark_property_invalid' + mark: Mark + index: number + node: Text + path: Path + property: string +} + +interface ParentInvalidError { + code: 'parent_invalid' + node: Ancestor + path: Path + index: number +} + +interface ParentObjectInvalidError { + code: 'parent_object_invalid' + node: Ancestor + path: Path + index: number +} + +interface ParentPropertyInvalidError { + code: 'parent_property_invalid' + node: Ancestor + path: Path + index: number + property: string +} + +interface PreviousSiblingInvalidError { + code: 'previous_sibling_invalid' + node: Node + path: Path +} + +interface PreviousSiblingObjectInvalidError { + code: 'previous_sibling_object_invalid' + node: Node + path: Path +} + +interface PreviousSiblingPropertyInvalidError { + code: 'previous_sibling_property_invalid' + node: Node + path: Path + property: string +} + +type SchemaError = + | AnnotationInvalidError + | AnnotationObjectInvalidError + | AnnotationPropertyInvalidError + | ChildInvalidError + | ChildMaxInvalidError + | ChildMinInvalidError + | ChildObjectInvalidError + | ChildOverflowError + | ChildPropertyInvalidError + | FirstChildInvalidError + | FirstChildObjectInvalidError + | FirstChildPropertyInvalidError + | LastChildInvalidError + | LastChildObjectInvalidError + | LastChildPropertyInvalidError + | MarkInvalidError + | MarkObjectInvalidError + | MarkPropertyInvalidError + | NextSiblingInvalidError + | NextSiblingObjectInvalidError + | NextSiblingPropertyInvalidError + | NodeInvalidError + | NodeObjectInvalidError + | NodePropertyInvalidError + | NodeTextInvalidError + | ParentInvalidError + | ParentObjectInvalidError + | ParentPropertyInvalidError + | PreviousSiblingInvalidError + | PreviousSiblingObjectInvalidError + | PreviousSiblingPropertyInvalidError + +export { SchemaError } diff --git a/packages/slate/src/plugins/schema/index.js b/packages/slate/src/plugins/schema/index.js deleted file mode 100644 index 68a317ea9e..0000000000 --- a/packages/slate/src/plugins/schema/index.js +++ /dev/null @@ -1,687 +0,0 @@ -import SlateError from '../../utils/slate-error' -import Path from '../../utils/path-utils' - -/** - * Create a plugin from a `schema` definition. - * - * @param {Object} schema - * @return {Object} - */ - -function SchemaPlugin(schema) { - const { - rules, - document, - blocks, - inlines, - marks, - annotations, - decorations, - } = schema - let schemaRules = [] - - if (rules) { - schemaRules = schemaRules.concat(rules) - } - - if (document) { - schemaRules.push({ - match: [{ object: 'document' }], - ...document, - }) - } - - if (blocks) { - for (const key in blocks) { - schemaRules.push({ - match: [{ object: 'block', type: key }], - ...blocks[key], - }) - } - } - - if (inlines) { - for (const key in inlines) { - schemaRules.push({ - match: [{ object: 'inline', type: key }], - ...inlines[key], - }) - } - } - - if (marks) { - for (const key in marks) { - schemaRules.push({ - match: [{ object: 'mark', type: key }], - ...marks[key], - }) - } - } - - if (annotations) { - for (const key in annotations) { - schemaRules.push({ - match: [{ object: 'annotation', type: key }], - ...annotations[key], - }) - } - } - - if (decorations) { - for (const key in decorations) { - schemaRules.push({ - match: [{ object: 'decoration', type: key }], - ...decorations[key], - }) - } - } - - /** - * Check if a `format` is atomic based on the schema rules. - * - * @param {Editor} editor - * @param {Format} format - * @return {Boolean} - */ - - const isAtomic = (fn, editor) => format => { - const rule = schemaRules.find( - r => 'isAtomic' in r && testRules(format, null, r.match) - ) - - return rule ? rule.isAtomic : fn(format) - } - - /** - * Check if a `node` is void based on the schema rules. - * - * @param {Editor} editor - * @param {Node} node - * @return {Boolean} - */ - - const isVoid = (fn, editor) => node => { - const path = editor.value.document.getPath(node) - const rule = schemaRules.find( - r => 'isVoid' in r && testRules(node, path, r.match) - ) - - return rule ? rule.isVoid : fn(node) - } - - /** - * Normalize a `node` with the schema rules, returning a function that will - * fix the invalid node, or void if the node is valid. - * - * @param {Node} node - * @param {Editor} editor - * @param {Function} next - * @return {Function|Void} - */ - - let validate - - const normalizeNode = (fn, editor) => node => { - if (!validate) { - validate = validateNode(() => {}, editor) - } - - const error = validate(node) - - if (!error) { - return fn(node) - } - - return () => { - const { rule } = error - const { size } = editor.operations - - // First run the user-provided `normalize` function if one exists... - if (rule.normalize) { - rule.normalize(editor, error) - } - - // If the `normalize` function did not add any operations to the editor - // object, it can't have normalized, so run the default one. - if (editor.operations.size === size) { - defaultNormalize(editor, error) - } - } - } - - /** - * Validate a `node` with the schema rules, returning a `SlateError` if it's - * invalid. - * - * @param {Node} node - * @param {Editor} editor - * @param {Function} next - * @return {Error|Void} - */ - - const validateNode = (fn, editor) => node => { - const path = editor.value.document.getPath(node) - const matches = schemaRules.filter(r => testRules(node, path, r.match)) - const failure = validateRules(node, path, matches, schemaRules, { - every: true, - }) - - if (!failure) { - return fn(node) - } - - const error = new SlateError(failure.code, failure) - return error - } - - /** - * Return the plugin. - * - * @type {Object} - */ - - return { normalizeNode, validateNode, isAtomic, isVoid } -} - -/** - * Normalize an invalid value with `error` with default remedies. - * - * @param {Editor} editor - * @param {SlateError} error - */ - -function defaultNormalize(editor, error) { - const { value: { document } } = editor - const { code, key, mark, path } = error - const parentPath = Path.lift(path) - const parent = document.getNode(parentPath) - const node = document.getNode(path) - - switch (code) { - case 'child_max_invalid': - case 'child_object_invalid': - case 'child_type_invalid': - case 'child_unknown': - case 'first_child_object_invalid': - case 'first_child_type_invalid': - case 'last_child_object_invalid': - case 'last_child_type_invalid': - case 'previous_sibling_object_invalid': - case 'previous_sibling_type_invalid': - case 'next_sibling_object_invalid': - case 'next_sibling_type_invalid': { - const isOnlyText = - node.object === 'text' && - parent.object === 'block' && - parent.nodes.size === 1 - const targetPath = isOnlyText ? parentPath : path - editor.removeNodeByPath(targetPath) - break - } - - case 'child_min_invalid': { - if (parent.object === 'document') { - editor.removeChildrenByPath(parentPath) - } else { - editor.removeNodeByPath(parentPath) - } - - break - } - - case 'node_text_invalid': - case 'parent_object_invalid': - case 'parent_type_invalid': { - if (node.object === 'document') { - editor.removeChildrenByPath(path) - } else { - editor.removeNodeByPath(path) - } - - break - } - - case 'node_data_invalid': { - const isUnset = - node.data.get(key) === undefined && node.object !== 'document' - - if (isUnset) { - editor.removeNodeByPath(path) - } else { - editor.setNodeByPath(path, { data: node.data.delete(key) }) - } - - break - } - - case 'node_mark_invalid': { - for (const [text, relativePath] of node.texts()) { - const textPath = path.concat(relativePath) - editor.removeMarkByPath(textPath, 0, text.text.length, mark) - } - - break - } - - default: { - editor.removeNodeByPath(path) - break - } - } -} - -/** - * Check that an `object` matches one of a set of `rules`. - * - * @param {Mixed} object - * @param {Array} path - * @param {Object|Array} rules - * @return {Boolean} - */ - -function testRules(object, path, rules) { - const error = validateRules(object, path, rules) - return !error -} - -/** - * Validate that a `object` matches a `rule` object or array. - * - * @param {Mixed} object - * @param {Array} path - * @param {Object|Array} rule - * @param {Array|Void} rules - * @return {Error|Void} - */ - -function validateRules(object, path, rule, rules, options = {}) { - const { every = false, match = null } = options - - if (typeof rule === 'function') { - const valid = rule(object, match) - return valid ? null : fail('node_invalid', { rule, node: object, path }) - } - - if (Array.isArray(rule)) { - const array = rule.length ? rule : [{}] - let first - - for (const r of array) { - const error = validateRules(object, path, r, rules) - first = first || error - if (every && error) return error - if (!every && !error) return - } - - return first - } - - const error = - validateObject(object, path, rule) || - validateType(object, path, rule) || - validateData(object, path, rule) || - validateMarks(object, path, rule) || - validateText(object, path, rule) || - validateFirst(object, path, rule) || - validateLast(object, path, rule) || - validateNodes(object, path, rule, rules) - - return error -} - -function validateObject(node, path, rule) { - if (rule.object == null) return - if (rule.object === node.object) return - if (typeof rule.object === 'function' && rule.object(node.object)) return - return fail('node_object_invalid', { rule, node, path }) -} - -function validateType(node, path, rule) { - if (rule.type == null) return - if (rule.type === node.type) return - if (typeof rule.type === 'function' && rule.type(node.type)) return - return fail('node_type_invalid', { rule, node, path }) -} - -function validateData(node, path, rule) { - if (rule.data == null) return - if (node.data == null) return - - if (typeof rule.data === 'function') { - if (rule.data(node.data)) return - return fail('node_data_invalid', { rule, node, path }) - } - - for (const key in rule.data) { - const fn = rule.data[key] - const value = node.data && node.data.get(key) - const valid = typeof fn === 'function' ? fn(value) : fn === value - if (valid) continue - return fail('node_data_invalid', { rule, node, path, key, value }) - } -} - -function validateMarks(node, path, rule) { - if (rule.marks == null) return - - const marks = - node.object === 'text' ? node.marks.toArray() : node.getMarks().toArray() - - for (const mark of marks) { - const valid = rule.marks.some( - def => - typeof def.type === 'function' - ? def.type(mark.type) - : def.type === mark.type - ) - if (valid) continue - return fail('node_mark_invalid', { rule, node, path, mark }) - } -} - -function validateText(node, path, rule) { - if (rule.text == null) return - const { text } = node - const valid = - typeof rule.text === 'function' ? rule.text(text) : rule.text.test(text) - if (valid) return - return fail('node_text_invalid', { rule, node, path, text }) -} - -function validateFirst(node, path, rule) { - if (rule.first == null) return - const first = node.nodes.first() - if (!first) return - const firstPath = path.concat([0]) - const error = validateRules(first, firstPath, rule.first) - if (!error) return - error.rule = rule - error.node = node - error.child = first - error.code = error.code.replace('node_', 'first_child_') - return error -} - -function validateLast(node, path, rule) { - if (rule.last == null) return - const last = node.nodes.last() - if (!last) return - const lastPath = path.concat([node.nodes.size - 1]) - const error = validateRules(last, lastPath, rule.last) - if (!error) return - error.rule = rule - error.node = node - error.child = last - error.code = error.code.replace('node_', 'last_child_') - return error -} - -function validateNodes(node, path, rule, rules = []) { - if (node.nodes == null) return - - const children = node.nodes - const defs = rule.nodes != null ? rule.nodes.slice() : [] - let count = 0 - let lastCount = 0 - let min = null - let index = -1 - let def = null - let max = null - let child = null - let childPath = null - let previous = null - let next = null - - function nextDef() { - if (defs.length === 0) return false - def = defs.shift() - lastCount = count - count = 0 - min = def.min || null - max = def.max || null - return true - } - - function nextChild() { - index += 1 - previous = index ? children.get(index - 1) : null - child = children.get(index) - childPath = path.concat([index]) - next = children.get(index + 1) - if (!child) return false - lastCount = count - count += 1 - return true - } - - function rewind() { - if (index > 0) { - index -= 1 - count = lastCount - } - } - - if (rule.nodes != null) { - nextDef() - } - - while (nextChild()) { - const err = - validateParent(node, child, childPath, rules) || - validatePrevious(node, child, childPath, previous, index, rules) || - validateNext(node, child, childPath, next, index, rules) - - if (err) return err - - if (rule.nodes != null) { - if (!def) { - return fail('child_unknown', { - rule, - node, - child, - index, - path: childPath, - }) - } - - if (def.match) { - const error = validateRules(child, childPath, def.match) - - if (error) { - // Since we want to report overflow on last matching child we don't - // immediately check for count > max, but instead do so once we find - // a child that doesn't match. - if (max != null && count - 1 > max) { - rewind() - return fail('child_max_invalid', { - rule, - node, - index, - child: children.get(index), - count, - path: path.concat([index]), - limit: max, - }) - } - - const lastMin = min - - // If there are more groups after this one then child might actually - // be valid. - if (nextDef()) { - // If we've already satisfied the minimum for the current group, - // then we can rewind and proceed to the next group. - if (lastCount - 1 >= lastMin) { - index -= 1 - continue - } - - // Otherwise we know that current value is underflowing. There are - // three possible causes for this... - - // 1. There might just not be enough elements for current group, and - // current child is in fact the first of the next group. If so, the - // next def will not report errors, in which case we can rewind and - // report an minimum error. - if (validateRules(child, childPath, def.match) == null) { - rewind() - return fail('child_min_invalid', { - rule, - node, - index, - path: path.concat([index]), - count: lastCount - 1, - limit: lastMin, - }) - } - - // 2. The current group is underflowing, but there is also an - // invalid child before the next group. - // 3. Or the current group is not underflowing but it appears so - // because there's an invalid child between its members. - // It's either the second or third case. If it's the second then - // we could report an underflow, but presence of an invalid child - // is arguably more important, so we report it first. It also lets - // us avoid checking for which case exactly is it. - error.rule = rule - error.node = node - error.child = child - error.index = index - error.code = error.code.replace('node_', 'child_') - return error - } - - // Otherwise either we exhausted the last group, in which case it's - // an unknown child, ... - if (max != null && count > max) { - return fail('child_unknown', { - rule, - node, - child, - index, - path: path.concat([index]), - }) - } - - // ... or it's an invalid child for the last group. - error.rule = rule - error.node = node - error.child = child - error.index = index - error.code = error.code.replace('node_', 'child_') - return error - } - } - } - } - - // Since we want to report overflow on last matching child we don't - // immediately check for count > max, but do so after processing all nodes. - if (max != null && count > max) { - const i = index - 1 - return fail('child_max_invalid', { - rule, - node, - index: i, - count, - path: path.concat([i]), - child: children.get(i), - limit: max, - }) - } - - if (rule.nodes != null) { - do { - if (count < min) { - return fail('child_min_invalid', { - rule, - node, - index, - count, - path: path.concat([index]), - limit: min, - }) - } - } while (nextDef()) - } -} - -function validateParent(node, child, childPath, rules) { - for (const rule of rules) { - if (rule.parent == null) continue - if (!testRules(child, childPath, rule.match)) continue - - const parentPath = Path.lift(childPath) - const error = validateRules(node, parentPath, rule.parent) - if (!error) continue - - error.rule = rule - error.parent = node - error.node = child - error.path = childPath - error.code = error.code.replace('node_', 'parent_') - return error - } -} - -function validatePrevious(node, child, childPath, previous, index, rules) { - if (!previous) return - - for (const rule of rules) { - if (rule.previous == null) continue - if (!testRules(child, childPath, rule.match)) continue - - const previousPath = Path.decrement(childPath) - const error = validateRules(previous, previousPath, rule.previous) - if (!error) continue - - error.rule = rule - error.node = node - error.child = child - error.index = index - error.previous = previous - error.code = error.code.replace('node_', 'previous_sibling_') - return error - } -} - -function validateNext(node, child, childPath, next, index, rules) { - if (!next) return - - for (const rule of rules) { - if (rule.next == null) continue - if (!testRules(child, childPath, rule.match)) continue - - const nextPath = Path.increment(childPath) - const error = validateRules(next, nextPath, rule.next, [], { match: child }) - if (!error) continue - - error.rule = rule - error.node = node - error.child = child - error.index = index - error.next = next - error.code = error.code.replace('node_', 'next_sibling_') - return error - } -} - -/** - * Create an interim failure object with `code` and `attrs`. - * - * @param {String} code - * @param {Object} attrs - * @return {Object} - */ - -function fail(code, attrs) { - return { code, ...attrs } -} - -/** - * Export. - * - * @type {Object} - */ - -export default SchemaPlugin diff --git a/packages/slate/src/plugins/schema/index.ts b/packages/slate/src/plugins/schema/index.ts new file mode 100644 index 0000000000..f397f12793 --- /dev/null +++ b/packages/slate/src/plugins/schema/index.ts @@ -0,0 +1,3 @@ +export * from './error' +export * from './plugin' +export * from './rule' diff --git a/packages/slate/src/plugins/schema/plugin.ts b/packages/slate/src/plugins/schema/plugin.ts new file mode 100644 index 0000000000..7f49802f27 --- /dev/null +++ b/packages/slate/src/plugins/schema/plugin.ts @@ -0,0 +1,284 @@ +import { + Editor, + Mark, + Annotation, + EditorConstructor, + Element, + Node, + Path, +} from '../..' +import { SchemaError } from './error' +import { SchemaRule } from './rule' +import { checkNode, checkMark, checkAnnotation } from './checkers' + +const SchemaPlugin = ( + options: { + rules?: SchemaRule[] + value?: Omit + annotations?: { + [type: string]: Omit + } + elements?: { + [type: string]: Omit + } + marks?: { + [type: string]: Omit + } + } = {} +) => { + const { value, elements = {}, marks = {}, annotations = {} } = options + const rules = options.rules ? [...options.rules] : [] + + if (value) { + rules.push({ match: { object: 'value' }, ...value }) + } + + for (const type in elements) { + rules.push({ + match: { object: 'element', properties: { type } }, + ...elements[type], + }) + } + + for (const type in marks) { + rules.push({ + match: { object: 'mark', properties: { type } }, + ...marks[type], + }) + } + + for (const type in annotations) { + rules.push({ + match: { object: 'annotation', properties: { type } }, + ...annotations[type], + }) + } + + return (Base: EditorConstructor) => { + return class extends Base { + /** + * Check if a mark is atomic based on the schema rules. + */ + + isAtomic(this: Editor, mark: Mark): boolean { + // HACK: The mark-checking logic needs a node and a path for creating an + // error with details. But we don't care about the error itself, so we + // use fake details here. + const index = 0 + const [node, path] = this.getFirstText([]) + + for (const rule of rules) { + if ( + rule.define != null && + rule.define.isAtomic != null && + ((Annotation.isAnnotation(mark) && + checkAnnotation(mark, '', rule.match) == null) || + checkMark(mark, index, node, path, rule.match) == null) + ) { + return rule.define.isAtomic + } + } + + return super.isAtomic(mark) + } + + /** + * Check if a node is block based on the schema rules. + */ + + isBlock(this: Editor, node: Node): node is Element { + if (!Element.isElement(node)) { + return false + } + + // HACK: The node-checking logic needs a path for creating an error with + // details. But we don't care about the error, so we use a fake path. + const path: Path = [] + + for (const rule of rules) { + if ( + rule.define != null && + rule.define.isInline != null && + checkNode(node, path, rule.match, rules) == null + ) { + return !rule.define.isInline + } + } + + return super.isBlock(node) + } + + /** + * Check if a node is inline based on the schema rules. + */ + + isInline(this: Editor, node: Node): node is Element { + if (!Element.isElement(node)) { + return false + } + + // HACK: The node-checking logic needs a path for creating an error with + // details. But we don't care about the error, so we use a fake path. + const path: Path = [] + + for (const rule of rules) { + if ( + rule.define != null && + rule.define.isInline != null && + checkNode(node, path, rule.match, rules) == null + ) { + return rule.define.isInline + } + } + + return super.isInline(node) + } + + /** + * Check if a node is void based on the schema rules. + */ + + isVoid(this: Editor, node: Node): node is Element { + if (!Element.isElement(node)) { + return false + } + + // HACK: The node-checking logic needs a path for creating an error with + // details. But we don't care about the error, so we use a fake path. + const path: Path = [] + + for (const rule of rules) { + if ( + rule.define != null && + rule.define.isVoid != null && + checkNode(node, path, rule.match, rules) == null + ) { + return rule.define.isVoid + } + } + + return super.isVoid(node) + } + + /** + * Normalize a node at a path with the schema's rules, returning it to a + * valid state if it is currently invalid. + */ + + normalizeNodeAtPath(this: Editor, path: Path): void { + const node = Node.get(this.value, path) + let error: SchemaError | undefined + let rule: SchemaRule | undefined + + for (const r of rules) { + if ('validate' in r) { + const e = checkNode(node, path, r.match, rules) + + if (e) { + error = e + rule = r + break + } + } + } + + if (error == null) { + return super.normalizeNodeAtPath(path) + } + + const prevLength = this.operations.length + + // First run the user-provided `normalize` function if one exists... + if (rule != null && rule.normalize) { + rule.normalize.call(this, error) + } + + // If the `normalize` function did add any operations to the editor, + // we assume that it fully handled the normalization and exit. + if (this.operations.length > prevLength) { + return + } + + switch (error.code) { + case 'annotation_invalid': + case 'annotation_object_invalid': + case 'annotation_property_invalid': { + const { key } = error + this.removeAnnotation(key) + break + } + + case 'child_invalid': + case 'child_max_invalid': + case 'child_object_invalid': + case 'child_overflow': + case 'first_child_invalid': + case 'first_child_object_invalid': + case 'last_child_invalid': + case 'last_child_object_invalid': + case 'next_sibling_invalid': + case 'next_sibling_object_invalid': + case 'node_invalid': + case 'node_object_invalid': + case 'node_text_invalid': + case 'parent_invalid': + case 'parent_object_invalid': + case 'previous_sibling_invalid': + case 'previous_sibling_object_invalid': { + const { path } = error + + if (path.length === 0) { + this.removeChildrenAtPath(path) + } else { + this.removeNodeAtPath(path) + } + + break + } + + case 'child_min_invalid': { + const { path } = error + + if (path.length === 1) { + this.removeChildrenAtPath([]) + } else { + this.removeParentAtPath(path) + } + + break + } + + case 'child_property_invalid': + case 'first_child_property_invalid': + case 'last_child_property_invalid': + case 'next_sibling_property_invalid': + case 'node_property_invalid': + case 'parent_property_invalid': + case 'previous_sibling_property_invalid': { + const { value } = this + const { path, property } = error + const node = Node.get(value, path) + + if (node[property] == null) { + this.removeNodeAtPath(path) + } else { + this.setNodeAtPath(path, { [property]: null }) + } + + break + } + + case 'mark_invalid': + case 'mark_object_invalid': + case 'mark_property_invalid': { + const { path, mark } = error + this.removeMarkAtPath(path, mark) + break + } + } + } + } + } +} + +export default SchemaPlugin diff --git a/packages/slate/src/plugins/schema/rule.ts b/packages/slate/src/plugins/schema/rule.ts new file mode 100644 index 0000000000..eaf69a6f2c --- /dev/null +++ b/packages/slate/src/plugins/schema/rule.ts @@ -0,0 +1,84 @@ +import { Editor } from '../..' +import { SchemaError } from './error' + +type SchemaCheck = + | SchemaNodeCheck + | SchemaAnnotationCheck + | SchemaMarkCheck + | SchemaFunctionCheck + +interface SchemaValueCheck { + object?: 'value' + children?: SchemaChildCheck[] + first?: SchemaDescendantCheck + last?: SchemaDescendantCheck + marks?: SchemaMarkCheck[] + text?: RegExp + properties?: {} +} + +interface SchemaElementCheck { + object?: 'element' + children?: SchemaChildCheck[] + next?: SchemaDescendantCheck + previous?: SchemaDescendantCheck + first?: SchemaDescendantCheck + last?: SchemaDescendantCheck + parent?: SchemaAncestorCheck + marks?: SchemaMarkCheck[] + text?: RegExp | ((text: string) => boolean) + properties?: {} +} + +interface SchemaTextCheck { + object?: 'text' + next?: SchemaDescendantCheck + previous?: SchemaDescendantCheck + parent?: SchemaAncestorCheck + marks?: SchemaMarkCheck[] + text?: RegExp + properties?: {} +} + +type SchemaNodeCheck = SchemaValueCheck | SchemaElementCheck | SchemaTextCheck +type SchemaAncestorCheck = SchemaValueCheck | SchemaElementCheck +type SchemaDescendantCheck = SchemaElementCheck | SchemaTextCheck + +interface SchemaChildCheck { + match?: SchemaDescendantCheck + min?: number + max?: number +} + +interface SchemaAnnotationCheck { + object?: 'annotation' + properties?: {} +} + +interface SchemaMarkCheck { + object?: 'mark' + properties?: {} +} + +interface SchemaFunctionCheck { + (object: any): boolean +} + +interface SchemaDefine { + isAtomic?: boolean + isInline?: boolean + isVoid?: boolean +} + +interface SchemaNormalize { + (this: Editor, error: SchemaError): void +} + +interface SchemaRule { + match: SchemaCheck + validate?: SchemaCheck + define?: SchemaDefine + normalize?: SchemaNormalize +} + +export { SchemaCheck, SchemaDefine, SchemaNormalize, SchemaRule } diff --git a/packages/slate/src/queries/format.js b/packages/slate/src/queries/format.js deleted file mode 100644 index 89bc173e71..0000000000 --- a/packages/slate/src/queries/format.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Check whether a `format` is atomic, defaults to false. - * - * @param {Annotation|Decoration|Mark} format - * @return {Boolean} - */ - -export const isAtomic = (fn, editor) => () => { - return false -} diff --git a/packages/slate/src/queries/node.js b/packages/slate/src/queries/node.js deleted file mode 100644 index 14c20f325e..0000000000 --- a/packages/slate/src/queries/node.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Check whether a `node` is void, defaults to false. - * - * @param {Node} node - * @return {Boolean} - */ - -export const isVoid = (fn, editor) => node => { - return false -} diff --git a/packages/slate/src/queries/path.js b/packages/slate/src/queries/path.js deleted file mode 100644 index f598c63b2d..0000000000 --- a/packages/slate/src/queries/path.js +++ /dev/null @@ -1,47 +0,0 @@ -import { Range } from '..' - -/** - * Get the start point at a `path`. - * - * @param {Path} path - * @return {Point} - */ - -export const getStartOfPath = (fn, editor) => path => { - const { value: { document } } = editor - const [, firstPath] = document.firstText({ path }) - const point = document.createPoint({ path: firstPath, offset: 0 }) - return point -} - -/** - * Get the end point at a `path`. - * - * @param {Path} path - * @return {Point} - */ - -export const getEndOfPath = (fn, editor) => path => { - const { value: { document } } = editor - const [lastNode, lastPath] = document.lastText({ path }) - const point = document.createPoint({ - path: lastPath, - offset: lastNode.text.length, - }) - - return point -} - -/** - * Get the range of a node at `path`. - * - * @param {Path} path - * @return {Range} - */ - -export const getRangeOfPath = (fn, editor) => path => { - const anchor = editor.getStartOfPath(path) - const focus = editor.getEndOfPath(path) - const range = Range.create({ anchor, focus }) - return range -} diff --git a/packages/slate/src/queries/point.js b/packages/slate/src/queries/point.js deleted file mode 100644 index 641a610ee0..0000000000 --- a/packages/slate/src/queries/point.js +++ /dev/null @@ -1,342 +0,0 @@ -import PathUtils from '../utils/path-utils' -import TextUtils from '../utils/text-utils' - -export const isAtStartOfBlock = (fn, editor) => point => { - const { value: { document } } = editor - const [, blockPath] = document.closestBlock(point.path) - const [, firstTextPath] = document.firstText({ path: blockPath }) - return point.offset === 0 && point.path.equals(firstTextPath) -} - -export const isAtStartOfPath = (fn, editor) => (point, path) => { - const { value: { document } } = editor - const [, firstPath] = document.firstText({ path }) - return point.offset === 0 && point.path.equals(firstPath) -} - -export const isAtEndOfPath = (fn, editor) => (point, path) => { - const { value: { document } } = editor - const [firstNode, firstPath] = document.firstText({ path }) - return point.offset === firstNode.text.length && point.path.equals(firstPath) -} - -export const isAtEdgeOfPath = (fn, editor) => (point, path) => { - return ( - editor.isAtStartOfPath(point, path) || editor.isAtEndOfPath(point, path) - ) -} - -/** - * Calculate the next point forward from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getNextPoint = (fn, editor) => (point, options = {}) => { - const { allowZeroWidth = false } = options - const { value } = editor - const { document } = value - const { path, offset } = point - const closestBlock = document.closestBlock(path) - const closestVoid = document.closest(path, editor.isVoid) - const node = document.getNode(path) - - // PERF: if we're not in a void and we have offset to gain, do it easily. - if (!closestVoid && offset < node.text.length) { - const next = point.setOffset(offset + 1) - return next.normalize(document) - } - - for (const [nextNode, nextPath] of document.texts({ path })) { - // If we're still inside the void node, keep going until we exit it. - if (closestVoid) { - const [, voidPath] = closestVoid - - if (!PathUtils.isAfter(nextPath, voidPath)) { - continue - } - } - - // If we're no longer inside the original block node, we don't want to - // add an extra `1` to the offset, since we've changed blocks. Instead - // we move right to the start of the block. - if (closestBlock) { - const [, blockPath] = closestBlock - - if (PathUtils.isAfter(nextPath, blockPath)) { - const next = point.moveTo(nextPath, 0) - return next.normalize(document) - } - } - - // If the point is now inside a new void node, no matter if the void - // node is zero-width, we still count it as a new point. - const nextClosestVoid = document.closest(nextPath, editor.isVoid) - - // If the text node and we're still in the same block, continue onwards - // because we need to have moved one point forwards, and an empty text - // will be perceived as not moving. - if (nextNode.text.length === 0) { - if (nextClosestVoid || allowZeroWidth) { - const next = point.moveTo(nextPath, 0) - return next.normalize(document) - } else { - continue - } - } - - const next = point.moveTo(nextPath, 1) - return next.normalize(document) - } - - return null -} - -/** - * Calculate the next character boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getNextCharacterPoint = (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - const blockText = block.getText() - - if (blockOffset + offset === blockText.length) { - return editor.getNextPoint(point) - } - - const o = blockOffset + offset - const n = TextUtils.getCharOffsetForward(blockText, o) - let next = point - - for (let i = 0; i < n; i++) { - next = editor.getNextPoint(next) - - if (!next) { - break - } - } - - return next -} - -/** - * Get the next point in the document that is not inside a void node. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getNextNonVoidPoint = (fn, editor) => point => { - const { value: { document } } = editor - let next = point - - while (next) { - const closestVoid = document.closest(next.path, editor.isVoid) - - if (closestVoid) { - next = editor.getNextPoint(next, { allowZeroWidth: true }) - } else { - return next - } - } -} - -/** - * Calculate the next word boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getNextWordPoint = (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - const blockText = block.getText() - - if (blockOffset + offset === blockText.length) { - return editor.getNextPoint(point) - } - - const o = blockOffset + offset - const n = TextUtils.getWordOffsetForward(blockText, o) - let next = point - - for (let i = 0; i < n; i++) { - next = editor.getNextPoint(next) - - if (!next) { - break - } - } - - return next -} - -/** - * Calculate the previous point backward from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getPreviousPoint = (fn, editor) => (point, options = {}) => { - const { allowZeroWidth = false } = options - const { value } = editor - const { document } = value - const { path, offset } = point - const closestBlock = document.closestBlock(path) - const closestVoid = document.closest(path, editor.isVoid) - - // PERF: if we're not in a void and we have offset to lose, do it easily. - if (!closestVoid && offset > 0) { - const prev = point.setOffset(offset - 1) - return prev.normalize(document) - } - - const iterable = document.texts({ path, direction: 'backward' }) - - for (const [prevNode, prevPath] of iterable) { - // If we're still inside the void node, keep going until we exit it. - if (closestVoid) { - const [, voidPath] = closestVoid - - if (!PathUtils.isBefore(prevPath, voidPath)) { - continue - } - } - - // If we're no longer inside the original block node, we don't want to - // remove an extra `1` from the offset, since we've changed blocks. - // Instead we move right to the end of the block. - if (closestBlock) { - const [, blockPath] = closestBlock - - if (PathUtils.isBefore(prevPath, blockPath)) { - const prev = point.moveTo(prevPath, prevNode.text.length) - return prev.normalize(document) - } - } - - // If the point is now inside a new void node, no matter if the void - // node is zero-width, we still count it as a new point. - const prevClosestVoid = document.closest(prevPath, editor.isVoid) - - // If the text node and we're still in the same block, continue onwards - // because we need to have moved one point backwards, and an empty text - // will be perceived as not moving. - if (prevNode.text.length === 0) { - if (prevClosestVoid || allowZeroWidth) { - const prev = point.moveTo(prevPath, 0) - return prev.normalize(document) - } else { - continue - } - } - - const prev = point.moveTo(prevPath, prevNode.text.length - 1) - return prev.normalize(document) - } - - return null -} - -/** - * Calculate the previous character boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getPreviousCharacterPoint = (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - - if (blockOffset + offset === 0) { - return editor.getPreviousPoint(point) - } - - const blockText = block.getText() - const o = blockOffset + offset - const n = TextUtils.getCharOffsetBackward(blockText, o) - let prev = point - - for (let i = 0; i < n; i++) { - prev = editor.getPreviousPoint(prev) - - if (!prev) { - break - } - } - - return prev -} - -/** - * Get the previous point in the document that is not inside a void node. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getPreviousNonVoidPoint = (fn, editor) => point => { - const { value: { document } } = editor - let prev = point - - while (prev) { - const closestVoid = document.closest(prev.path, editor.isVoid) - - if (closestVoid) { - prev = editor.getPreviousPoint(prev, { allowZeroWidth: true }) - } else { - return prev - } - } -} - -/** - * Calculate the previous word boundary from a `point`. - * - * @param {Point} point - * @return {Point|Null} - */ - -export const getPreviousWordPoint = (fn, editor) => point => { - const { value: { document } } = editor - const { path, offset } = point - const [block, blockPath] = document.closestBlock(path) - const relativePath = path.slice(blockPath.size) - const blockOffset = block.getOffset(relativePath) - - if (blockOffset + offset === 0) { - return editor.getPreviousPoint(point) - } - - const blockText = block.getText() - const o = blockOffset + offset - const n = TextUtils.getWordOffsetBackward(blockText, o) - let prev = point - - for (let i = 0; i < n; i++) { - prev = editor.getPreviousPoint(prev) - - if (!prev) { - break - } - } - - return prev -} diff --git a/packages/slate/src/queries/range.js b/packages/slate/src/queries/range.js deleted file mode 100644 index 42cf1d2f73..0000000000 --- a/packages/slate/src/queries/range.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Check whether a `range` is hanging. - * - * @param {Range} range - * @return {Boolean} - */ - -export const isHanging = (fn, editor) => range => { - const { isExpanded, start, end } = range - return isExpanded && end.offset === 0 && !start.path.equals(end.path) -} - -/** - * Check whether a `range` is hanging in a block. - * - * @param {Range} range - * @return {Boolean} - */ - -export const isHangingBlock = (fn, editor) => range => { - const { value: { document } } = editor - const { isExpanded, start, end } = range - const [, endBlockPath] = document.closestBlock(end.path) - const [, firstTextPath] = document.firstText({ path: endBlockPath }) - - return ( - isExpanded && - end.offset === 0 && - !start.path.equals(end.path) && - end.path.equals(firstTextPath) - ) -} - -/** - * Calculate a non-hanging range from a `range`. - * - * @param {Range} range - * @return {Range} - */ - -export const getNonHangingRange = (fn, editor) => range => { - const { value: { document } } = editor - const { end } = range - - if (editor.isHanging(range)) { - const [prevText, prevPath] = document.previousText(end.path) - const newEnd = end.moveTo(prevPath, prevText.text.length) - const nonHanging = range.setEnd(newEnd).normalize(document) - return nonHanging - } else { - return range - } -} diff --git a/packages/slate/src/symbols.ts b/packages/slate/src/symbols.ts new file mode 100644 index 0000000000..c0716e6fc9 --- /dev/null +++ b/packages/slate/src/symbols.ts @@ -0,0 +1,6 @@ +export const DIRTY_PATHS = Symbol('dirtyPaths') +export const NORMALIZING = Symbol('normalizing') +export const FLUSHING = Symbol('flushing') +export const PATH_REFS = Symbol('pathRefs') +export const POINT_REFS = Symbol('pointRefs') +export const RANGE_REFS = Symbol('rangeRefs') diff --git a/packages/slate/src/utils/identity.js b/packages/slate/src/utils/identity.js deleted file mode 100644 index f80f0cd10f..0000000000 --- a/packages/slate/src/utils/identity.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function identity() { - return true -} diff --git a/packages/slate/src/utils/is-object.js b/packages/slate/src/utils/is-object.js deleted file mode 100644 index aff4b34324..0000000000 --- a/packages/slate/src/utils/is-object.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Slate-specific object types. - * - * @type {Object} - */ - -export const TYPES = { - annotation: '@@__SLATE_ANNOTATION__@@', - block: '@@__SLATE_BLOCK__@@', - change: '@@__SLATE_CHANGE__@@', - decoration: '@@__SLATE_DECORATION__@@', - document: '@@__SLATE_DOCUMENT__@@', - editor: '@@__SLATE_EDITOR__@@', - inline: '@@__SLATE_INLINE__@@', - leaf: '@@__SLATE_LEAF__@@', - mark: '@@__SLATE_MARK__@@', - operation: '@@__SLATE_OPERATION__@@', - point: '@@__SLATE_POINT__@@', - range: '@@__SLATE_RANGE__@@', - selection: '@@__SLATE_SELECTION__@@', - text: '@@__SLATE_TEXT__@@', - value: '@@__SLATE_VALUE__@@', -} - -/** - * Determine whether a `value` is of `type`. - * - * @param {string} type - * @param {any} value - * @return {boolean} - */ - -export default function isObject(type, value) { - return !!(value && value[TYPES[type]]) -} diff --git a/packages/slate/src/utils/key-utils.js b/packages/slate/src/utils/key-utils.js deleted file mode 100644 index 60ece95ceb..0000000000 --- a/packages/slate/src/utils/key-utils.js +++ /dev/null @@ -1,71 +0,0 @@ -/** - * An auto-incrementing index for generating keys. - * - * @type {Number} - */ - -let n - -/** - * The global key generating function. - * - * @type {Function} - */ - -let generate - -/** - * Create a key, using a provided key if available. - * - * @param {String|Void} key - * @return {String} - */ - -function create(key) { - if (key == null) { - return generate() - } - - if (typeof key === 'string') { - return key - } - - throw new Error(`Keys must be strings, but you passed: ${key}`) -} - -/** - * Set a different unique ID generating `function`. - * - * @param {Function} func - */ - -function setGenerator(func) { - generate = func -} - -/** - * Reset the key generating function to its initial state. - */ - -function resetGenerator() { - n = 0 - generate = () => `${n++}` -} - -/** - * Set the initial state. - */ - -resetGenerator() - -/** - * Export. - * - * @type {Object} - */ - -export default { - create, - setGenerator, - resetGenerator, -} diff --git a/packages/slate/src/utils/memoize.js b/packages/slate/src/utils/memoize.js deleted file mode 100644 index 206e55c8d8..0000000000 --- a/packages/slate/src/utils/memoize.js +++ /dev/null @@ -1,221 +0,0 @@ -/* global WeakMap, Map, Symbol */ - -/** - * GLOBAL: True if memoization should is enabled. - * - * @type {Boolean} - */ - -let ENABLED = true - -/** - * The leaf node of a cache tree. Used to support variable argument length. A - * unique object, so that native Maps will key it by reference. - * - * @type {Symbol} - */ - -const LEAF = Symbol('LEAF') - -/** - * The node of a cache tree for a WeakMap to store cache visited by objects - * - * @type {Symbol} - */ - -const STORE_KEY = Symbol('STORE_KEY') - -/** - * Values to represent a memoized undefined and null value. Allows efficient value - * retrieval using Map.get only. - * - * @type {Symbol} - */ - -const UNDEFINED = Symbol('undefined') -const NULL = Symbol('null') - -/** - * Default value for unset keys in native Maps - * - * @type {Undefined} - */ - -const UNSET = undefined - -/** - * Global Store for all cached values - * - * @type {WeakMap} - */ - -let memoizeStore = new WeakMap() - -/** - * Memoize all of the `properties` on a `object`. - * - * @param {Object} object - * @param {Array} properties - * @return {Record} - */ - -function memoize(object, properties) { - for (const property of properties) { - const original = object[property] - - if (!original) { - throw new Error(`Object does not have a property named "${property}".`) - } - - object[property] = function(...args) { - // If memoization is disabled, call into the original method. - if (!ENABLED) return original.apply(this, args) - - if (!memoizeStore.has(this)) { - memoizeStore.set(this, { - noArgs: {}, - hasArgs: {}, - }) - } - - const { noArgs, hasArgs } = memoizeStore.get(this) - - const takesArguments = args.length !== 0 - - let cachedValue - let keys - - if (takesArguments) { - keys = [property, ...args] - cachedValue = getIn(hasArgs, keys) - } else { - cachedValue = noArgs[property] - } - - // If we've got a result already, return it. - if (cachedValue !== UNSET) { - return cachedValue === UNDEFINED ? undefined : cachedValue - } - - // Otherwise calculate what it should be once and cache it. - const value = original.apply(this, args) - const v = value === undefined ? UNDEFINED : value - - if (takesArguments) { - setIn(hasArgs, keys, v) - } else { - noArgs[property] = v - } - - return value - } - } -} - -/** - * Get a value at a key path in a tree of Map. - * - * If not set, returns UNSET. - * If the set value is undefined, returns UNDEFINED. - * - * @param {Map} map - * @param {Array} keys - * @return {Any|UNSET|UNDEFINED} - */ - -function getIn(map, keys) { - for (let key of keys) { - if (key === undefined) { - key = UNDEFINED - } else if (key == null) { - key = NULL - } - - if (typeof key === 'object') { - map = map[STORE_KEY] && map[STORE_KEY].get(key) - } else { - map = map[key] - } - - if (map === UNSET) return UNSET - } - - return map[LEAF] -} - -/** - * Set a value at a key path in a tree of Map, creating Maps on the go. - * - * @param {Map} map - * @param {Array} keys - * @param {Any} value - * @return {Map} - */ - -function setIn(map, keys, value) { - let child = map - - for (let key of keys) { - if (key === undefined) { - key = UNDEFINED - } else if (key == null) { - key = NULL - } - - if (typeof key !== 'object') { - if (!child[key]) { - child[key] = {} - } - - child = child[key] - continue - } - - if (!child[STORE_KEY]) { - child[STORE_KEY] = new WeakMap() - } - - if (!child[STORE_KEY].has(key)) { - const newChild = {} - child[STORE_KEY].set(key, newChild) - child = newChild - continue - } - - child = child[STORE_KEY].get(key) - } - - // The whole path has been created, so set the value to the bottom most map. - child[LEAF] = value - return map -} - -/** - * In DEV mode, clears the previously memoized values, globally. - * - * @return {Void} - */ - -function resetMemoization() { - memoizeStore = new WeakMap() -} - -/** - * In DEV mode, enable or disable the use of memoize values, globally. - * - * @param {Boolean} enabled - * @return {Void} - */ - -function useMemoization(enabled) { - ENABLED = enabled -} - -/** - * Export. - * - * @type {Object} - */ - -export default memoize -export { resetMemoization, useMemoization } diff --git a/packages/slate/src/utils/mixin.js b/packages/slate/src/utils/mixin.js deleted file mode 100644 index 58ebea28b3..0000000000 --- a/packages/slate/src/utils/mixin.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Mix in an `Interface` to a `Class`. - * - * @param {Class} Interface - * @param {Class} Class - */ - -export default function mixin(Interface, Classes) { - for (const Class of Classes) { - // Copy static properties from the interface. - for (const name of Object.getOwnPropertyNames(Interface)) { - if (Class.hasOwnProperty(name)) continue - const desc = Object.getOwnPropertyDescriptor(Interface, name) - Object.defineProperty(Class, name, desc) - } - - // Copy instance properties from the interface. - for (const name of Object.getOwnPropertyNames(Interface.prototype)) { - if (Class.prototype.hasOwnProperty(name)) continue - const desc = Object.getOwnPropertyDescriptor(Interface.prototype, name) - Object.defineProperty(Class.prototype, name, desc) - } - } -} diff --git a/packages/slate/src/utils/path-utils.js b/packages/slate/src/utils/path-utils.js deleted file mode 100644 index 7e5bfe1968..0000000000 --- a/packages/slate/src/utils/path-utils.js +++ /dev/null @@ -1,510 +0,0 @@ -import { List } from 'immutable' - -/** - * Compare paths `path` and `target` to see which is before or after. - * - * @param {List} path - * @param {List} target - * @return {Number|Null} - */ - -function compare(path, target) { - const m = min(path, target) - - for (let i = 0; i < m; i++) { - const pv = path.get(i) - const tv = target.get(i) - - // If the path's value is ever less than the target's, it's before. - if (pv < tv) return -1 - - // If the target's value is ever less than the path's, it's after. - if (pv > tv) return 1 - } - - // Paths should now be equal, otherwise something is wrong - return path.size === target.size ? 0 : null -} - -/** - * Does path `a` contain path `b`? - * - * @param {List} a - * @param {List} b - * @return {Boolean} - */ - -function contains(a, b) { - ;[a, b] = crop(a, b) - return isEqual(a, b) -} - -/** - * Create a path from `attrs`. - * - * @param {Array|List} attrs - * @return {List} - */ - -function create(attrs) { - if (attrs == null) { - return null - } - - if (List.isList(attrs)) { - return attrs - } - - if (Array.isArray(attrs)) { - return List(attrs) - } - - throw new Error( - `Paths can only be created from arrays or lists, but you passed: ${attrs}` - ) -} - -/** - * Crop paths `a` and `b` to an equal size, defaulting to the shortest. - * - * @param {List} a - * @param {List} b - */ - -function crop(a, b, size = min(a, b)) { - const ca = a.slice(0, size) - const cb = b.slice(0, size) - return [ca, cb] -} - -/** - * Decrement a `path` by `n` at `index`, defaulting to the last index. - * - * @param {List} path - * @param {Number} n - * @param {Number} index - */ - -function decrement(path, n = 1, index = path.size - 1) { - return increment(path, 0 - n, index) -} - -/** - * Get all ancestor paths of the given path. - * - * @param {List} path - * @returns {List} - */ - -function getAncestors(path) { - const ancestors = List().withMutations(list => { - for (let i = 0; i < path.size; i++) { - list.push(path.slice(0, i)) - } - }) - - return ancestors -} - -/** - * Increment a `path` by `n` at `index`, defaulting to the last index. - * - * @param {List} path - * @param {Number} n - * @param {Number} index - */ - -function increment(path, n = 1, index = path.size - 1) { - const value = path.get(index) - const newValue = value + n - const newPath = path.set(index, newValue) - return newPath -} - -/** - * Is a `path` above another `target` path? - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isAbove(path, target) { - const [p, t] = crop(path, target) - return path.size < target.size && isEqual(p, t) -} - -function isUnder(path, target) { - const [p, t] = crop(path, target) - return path.size > target.size && isEqual(p, t) -} - -/** - * Is a `path` after another `target` path in a document? - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isAfter(path, target) { - const [p, t] = crop(path, target) - return compare(p, t) === 1 -} - -/** - * Is a `path` before another `target` path in a document? - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isBefore(path, target) { - const [p, t] = crop(path, target) - return compare(p, t) === -1 -} - -/** - * Is a `path` a chidl of `target` path? - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isChild(path, target) { - if (path.size !== target.size + 1) { - return false - } - - const [p, t] = crop(path, target) - return p.equals(t) -} - -/** - * Is a `path` equal to another `target` path in a document? - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isEqual(path, target) { - return path.equals(target) -} - -/** - * Is a `path` older than a `target` path? Meaning that it ends as an older - * sibling of one of the indexes in the target. - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isOlder(path, target) { - const index = path.size - 1 - const [p, t] = crop(path, target, index) - const pl = path.get(index) - const tl = target.get(index) - return isEqual(p, t) && pl > tl -} - -function isOlderSibling(path, target) { - return isSibling(path, target) && isOlder(path, target) -} - -/** - * Is an `any` object a path? - * - * @param {Mixed} any - * @return {Boolean} - */ - -function isPath(any) { - return ( - (List.isList(any) || Array.isArray(any)) && - any.every(n => typeof n === 'number') - ) -} - -/** - * Is a `path` a sibling of a `target` path? - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isSibling(path, target) { - if (path.size !== target.size) return false - const p = path.butLast() - const t = target.butLast() - return p.equals(t) -} - -/** - * Is a `path` younger than a `target` path? Meaning that it ends as a younger - * sibling of one of the indexes in the target. - * - * @param {List} path - * @param {List} target - * @return {Boolean} - */ - -function isYounger(path, target) { - const index = path.size - 1 - const [p, t] = crop(path, target, index) - const pl = path.get(index) - const tl = target.get(index) - return isEqual(p, t) && pl < tl -} - -function endsBefore(path, target) { - return isYounger(path, target) -} - -function endsAfter(path, target) { - return isOlder(path, target) -} - -function endsAt(path, target) { - const index = path.size - const [p, t] = crop(path, target, index) - return isEqual(p, t) -} - -function isYoungerSibling(path, target) { - return isSibling(path, target) && isYounger(path, target) -} - -/** - * Lift a `path` to refer to its `n`th ancestor. - * - * @param {List} path - * @return {List} - */ - -function lift(path, n = 1) { - const ancestor = path.slice(0, -1 * n) - return ancestor -} - -/** - * Drop a `path`, returning a relative path from a depth of `n`. - * - * @param {List} path - * @param {Number} n - * @return {List} - */ - -function drop(path, n = 1) { - const relative = path.slice(n) - return relative -} - -/** - * Get the maximum length of paths `a` and `b`. - * - * @param {List} path - * @param {List} path - * @return {Number} - */ - -function max(a, b) { - const n = Math.max(a.size, b.size) - return n -} - -/** - * Get the minimum length of paths `a` and `b`. - * - * @param {List} path - * @param {List} path - * @return {Number} - */ - -function min(a, b) { - const n = Math.min(a.size, b.size) - return n -} - -/** - * Get the common ancestor path of path `a` and path `b`. - * - * @param {List} a - * @param {List} b - * @return {List} - */ - -function relate(a, b) { - const array = [] - - for (let i = 0; i < a.size && i < b.size; i++) { - const av = a.get(i) - const bv = b.get(i) - - // If the values aren't equal, they've diverged and don't share an ancestor. - if (av !== bv) break - - // Otherwise, the current value is still a common ancestor. - array.push(av) - } - - const path = create(array) - return path -} - -/** - * Transform a `path` by an `operation`, adjusting it to stay current. - * - * @param {List} path - * @param {Operation} operation - * @return {List} - */ - -function transform(path, operation) { - const { type, position, path: p } = operation - - if ( - type === 'add_mark' || - type === 'insert_text' || - type === 'remove_mark' || - type === 'remove_text' || - type === 'set_mark' || - type === 'set_node' || - type === 'set_selection' || - type === 'set_value' || - type === 'add_annotation' || - type === 'remove_annotation' || - type === 'set_annotation' || - path.size === 0 - ) { - return List([path]) - } - - const pIndex = p.size - 1 - const pEqual = isEqual(p, path) - const pYounger = isYounger(p, path) - const pAbove = isAbove(p, path) - - if (type === 'insert_node') { - if (pEqual || pYounger || pAbove) { - path = increment(path, 1, pIndex) - } - } - - if (type === 'remove_node') { - if (pYounger) { - path = decrement(path, 1, pIndex) - } else if (pEqual || pAbove) { - path = [] - } - } - - if (type === 'merge_node') { - if (pEqual || pYounger) { - path = decrement(path, 1, pIndex) - } else if (pAbove) { - path = decrement(path, 1, pIndex) - path = increment(path, position, pIndex + 1) - } - } - - if (type === 'split_node') { - if (pEqual) { - path = [path, increment(path)] - } else if (pYounger) { - path = increment(path, 1, pIndex) - } else if (pAbove) { - if (path.get(pIndex + 1) >= position) { - path = increment(path, 1, pIndex) - path = decrement(path, position, pIndex + 1) - } - } - } - - if (type === 'move_node') { - const { newPath: np } = operation - - if (isEqual(p, np)) { - return List([path]) - } - - if (pAbove || pEqual) { - // We are comparing something that was moved - // The new path is unaffected unless the old path was the left-sibling of an ancestor - if (isYounger(p, np) && p.size < np.size) { - path = decrement(np, 1, min(np, p) - 1).concat(path.slice(p.size)) - } else { - path = np.concat(path.slice(p.size)) - } - } else { - // This is equivalent logic to remove_node for path - if (pYounger) { - path = decrement(path, 1, pIndex) - } - - // This is the equivalent logic to insert_node for newPath - if (isYounger(np, path) || isEqual(np, path) || isAbove(np, path)) { - path = increment(path, 1, np.size - 1) - } - } - } - - const paths = Array.isArray(path) ? path : [path] - return List(paths) -} - -/** - * Export. - * - * @type {Object} - */ - -function isAt(path, target) { - return isEqual(path, target) || isAbove(path, target) -} - -function isBetween(path, start, end) { - return isAfter(path, start) && isBefore(path, end) -} - -function isIn(path, target) { - return isEqual(path, target) || isUnder(path, target) -} - -export default { - compare, - contains, - create, - crop, - decrement, - getAncestors, - increment, - isAbove, - isAfter, - isBefore, - isEqual, - isOlder, - isPath, - isSibling, - isYounger, - lift, - drop, - max, - min, - relate, - transform, - isChild, - isOlderSibling, - isAt, - isYoungerSibling, - isBetween, - isUnder, - isIn, - endsAt, - endsAfter, - endsBefore, -} diff --git a/packages/slate/src/utils/slate-error.js b/packages/slate/src/utils/slate-error.js deleted file mode 100644 index 84b5c92e63..0000000000 --- a/packages/slate/src/utils/slate-error.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Define a Slate error. - * - * @type {SlateError} - */ - -class SlateError extends Error { - constructor(code, attrs = {}) { - super(code) - this.code = code - - for (const key in attrs) { - this[key] = attrs[key] - } - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, this.constructor) - } else { - this.stack = new Error().stack - } - } -} - -/** - * Export. - * - * @type {SlateError} - */ - -export default SlateError diff --git a/packages/slate/src/utils/text-utils.js b/packages/slate/src/utils/text-utils.js deleted file mode 100644 index e9ae219d08..0000000000 --- a/packages/slate/src/utils/text-utils.js +++ /dev/null @@ -1,366 +0,0 @@ -import { reverse } from 'esrever' - -/** - * Surrogate pair start and end points. - * - * @type {Number} - */ - -const SURROGATE_START = 0xd800 -const SURROGATE_END = 0xdfff - -/** - * A regex to match space characters. - * - * @type {RegExp} - */ - -const SPACE = /\s/ - -/** - * A regex to match chameleon characters, that count as word characters as long - * as they are inside of a word. - * - * @type {RegExp} - */ - -const CHAMELEON = /['\u2018\u2019]/ - -/** - * A regex that matches punctuation. - * - * @type {RegExp} - */ - -const PUNCTUATION = /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/ - -/** - * Is a character `code` in a surrogate character. - * - * @param {Number} code - * @return {Boolean} - */ - -function isSurrogate(code) { - return SURROGATE_START <= code && code <= SURROGATE_END -} - -/** - * Does `code` form Modifier with next one. - * - * https://emojipedia.org/modifiers/ - * - * @param {Number} code - * @param {String} text - * @param {Number} offset - * @return {Boolean} - */ - -function isModifier(code, text, offset) { - if (code === 0xd83c) { - const next = text.charCodeAt(offset + 1) - return next <= 0xdfff && next >= 0xdffb - } - return false -} - -/** - * Is `code` a Variation Selector. - * - * https://codepoints.net/variation_selectors - * - * @param {Number} code - * @return {Boolean} - */ - -function isVariationSelector(code) { - return code <= 0xfe0f && code >= 0xfe00 -} - -/** - * Is `code` one of the BMP codes used in emoji sequences. - * - * https://emojipedia.org/emoji-zwj-sequences/ - * - * @param {Number} code - * @return {Boolean} - */ - -function isBMPEmoji(code) { - // This requires tiny bit of maintanance, better ideas? - // Fortunately it only happens if new Unicode Standard - // is released. Fails gracefully if upkeep lags behind, - // same way Slate previously behaved with all emojis. - return ( - code === 0x2764 || // heart (❤) - code === 0x2642 || // male (♂) - code === 0x2640 || // female (♀) - code === 0x2620 || // scull (☠) - code === 0x2695 || // medical (⚕) - code === 0x2708 || // plane (✈️) - code === 0x25ef // large circle (◯) - ) -} - -/** - * Is a character a word character? Needs the `remaining` characters too. - * - * @param {String} char - * @param {String|Void} remaining - * @return {Boolean} - */ - -function isWord(char, remaining) { - if (SPACE.test(char)) return false - - // If it's a chameleon character, recurse to see if the next one is or not. - if (CHAMELEON.test(char)) { - let next = remaining.charAt(0) - const length = getCharLength(next) - next = remaining.slice(0, length) - const rest = remaining.slice(length) - if (isWord(next, rest)) return true - } - - if (PUNCTUATION.test(char)) return false - return true -} - -/** - * Get the length of a `character`. - * - * @param {String} char - * @return {Number} - */ - -function getCharLength(char) { - return isSurrogate(char.charCodeAt(0)) ? 2 : 1 -} - -/** - * Get the offset to the end of the character(s) in `text`. - * This function is emoji aware and handles them correctly. - * - * @param {String} text - * @param {Number} chars - * @param {Boolean} forward - * @return {Number} - */ - -function getCharOffset(text, chars, forward) { - let offset = 0 - - // Handle end/beginning of node: we have to return 1 in order not to - // break cursor's jumping to next/previous node. We need to return early - // because otherwise, ''.charCodeAt(0) returned NaN and, the default - // handling 'latin characters' at the end of the while loop would - // would never be reached an we returned '0' as offset. - if (text === '') return 1 - - // Calculate offset sum of each character - for (let i = 0; i < chars; i++) { - // `prev` types (better ideas?): - // - SURR: surrogate pair - // - MOD: modifier (technically also surrogate pair) - // - ZWJ: zero width joiner - // - VAR: variation selector - // - BMP: sequenceable character from Basic Multilingual Plane - let prev = null - let charCode = text.charCodeAt(offset) - - while (charCode) { - if (isSurrogate(charCode)) { - const modifier = isModifier(charCode, text, offset) - - // Early returns are the heart of this loop where - // we decide if previous and current codepoints - // should form a single character (in other words: - // how many of them should selection jump over). - if (forward) { - if ( - (!modifier && prev && prev !== 'ZWJ') || - (modifier && prev && prev !== 'SURR') - ) { - break - } - } else if (prev === 'SURR' || prev === 'BMP') { - break - } - - offset += 2 - prev = modifier ? 'MOD' : 'SURR' - charCode = text.charCodeAt(offset) - // It's okay to `continue` without checking - // because if `charCode` is NaN (which is - // the case when out of `text` range), next - // `while` loop won't execute and we're done. - continue - } - - // If zero width joiner - if (charCode === 0x200d) { - offset += 1 - prev = 'ZWJ' - charCode = text.charCodeAt(offset) - continue - } - - if (isBMPEmoji(charCode)) { - if ( - (forward && prev === 'VAR') || - (prev && prev !== 'ZWJ' && prev !== 'VAR') - ) { - break - } - - offset += 1 - prev = 'BMP' - charCode = text.charCodeAt(offset) - continue - } - - if (isVariationSelector(charCode)) { - if (!forward && prev && prev !== 'ZWJ') { - break - } - - offset += 1 - prev = 'VAR' - charCode = text.charCodeAt(offset) - continue - } - - // Modifier "fuses" with what ever character is before that - // (even whitespace), need to look ahead if loop gets here. - if (forward) { - const nextCharCode = text.charCodeAt(offset + 1) - - if (isModifier(nextCharCode, text, offset + 1)) { - offset += 3 - prev = 'MOD' - charCode = text.charCodeAt(offset) - continue - } - } else if (prev === 'MOD') { - offset += 1 - break - } - - // If while loop ever gets here, we're - // done (e.g Latin characters, length 1). - if (prev === null) offset += 1 - break - } - } - - return offset -} - -/** - * Get the offset to the end of character(s) before an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @param {Number} chars - * @return {Number} - */ - -function getCharOffsetBackward(text, offset, chars = 1) { - text = text.slice(0, offset) - text = reverse(text) - return getCharOffset(text, chars) -} - -/** - * Get the offset to the end of character(s) after an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @param {Number} chars - * @return {Number} - */ - -function getCharOffsetForward(text, offset, chars = 1) { - text = text.slice(offset) - return getCharOffset(text, chars, true) -} - -/** - * Get the offset to the end of the first word in `text`. - * - * @param {String} text - * @return {Number} - */ - -function getWordOffset(text) { - let length = 0 - let i = 0 - let started = false - let char - - while ((char = text.charAt(i))) { - const l = getCharLength(char) - char = text.slice(i, i + l) - const rest = text.slice(i + l) - - if (isWord(char, rest)) { - started = true - length += l - } else if (!started) { - length += l - } else { - break - } - - i += l - } - - return length -} - -/** - * Get the offset to the end of the word before an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @return {Number} - */ - -function getWordOffsetBackward(text, offset) { - text = text.slice(0, offset) - text = reverse(text) - const o = getWordOffset(text) - return o -} - -/** - * Get the offset to the end of the word after an `offset` in `text`. - * - * @param {String} text - * @param {Number} offset - * @return {Number} - */ - -function getWordOffsetForward(text, offset) { - text = text.slice(offset) - const o = getWordOffset(text) - return o -} - -/** - * Export. - * - * @type {Object} - */ - -export default { - getCharLength, - getCharOffset, - getCharOffsetBackward, - getCharOffsetForward, - getWordOffset, - getWordOffsetBackward, - getWordOffsetForward, - isSurrogate, - isWord, -} diff --git a/packages/slate/test/changes/at-range/insert-text-at-range/non-matching-section-and-range.js b/packages/slate/test/changes/at-range/insert-text-at-range/non-matching-section-and-range.js deleted file mode 100644 index 4e20ae91c9..0000000000 --- a/packages/slate/test/changes/at-range/insert-text-at-range/non-matching-section-and-range.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { Point, Range } from 'slate' - -import h from '../../../helpers/h' - -export default function(editor) { - const { key } = editor.value.document.getFirstText() - const range = new Range({ - anchor: new Point({ key, offset: 0 }), - focus: new Point({ key, offset: 3 }), - }) - editor.insertTextAtRange(range, 'That') -} - -export const input = ( - - - The change will be here. - - The cursor is over here. - - - -) - -export const output = ( - - - That change will be here. - - The cursor is over here. - - - -) diff --git a/packages/slate/test/controllers/editor/has/exists.js b/packages/slate/test/controllers/editor/has/exists.js deleted file mode 100644 index 7f331fa3a3..0000000000 --- a/packages/slate/test/controllers/editor/has/exists.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -const plugins = [ - { - customCommand: () => () => {}, - }, -] - -export const input = new Editor({ plugins }) - -export default function(editor) { - return editor.has('customCommand') -} - -export const output = true diff --git a/packages/slate/test/controllers/editor/has/missing.js b/packages/slate/test/controllers/editor/has/missing.js deleted file mode 100644 index 411498367d..0000000000 --- a/packages/slate/test/controllers/editor/has/missing.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Editor } from 'slate' - -const plugins = [ - { - customCommand: () => {}, - }, -] - -export const input = new Editor({ plugins }) - -export default function(editor) { - return editor.has('otherCommand') -} - -export const output = false diff --git a/packages/slate/test/index.js b/packages/slate/test/index.js index 5ae66d641e..a17d945b2a 100644 --- a/packages/slate/test/index.js +++ b/packages/slate/test/index.js @@ -1,7 +1,6 @@ import assert from 'assert' -import { fixtures } from 'slate-dev-test-utils' -import { Node, Editor, Value } from 'slate' -import { List } from 'immutable' +import { fixtures } from '../../../support/fixtures' +import { Editor } from 'slate' const plugins = [ { @@ -26,67 +25,10 @@ const plugins = [ ] describe('slate', () => { - fixtures(__dirname, 'models/operation', ({ module }) => { - const { input, output } = module - const fn = module.default - const actual = fn(input).toJSON() - const expected = output - assert.deepEqual(actual, expected) - }) - - fixtures(__dirname, 'models/point', ({ module }) => { - const { input, output } = module - const fn = module.default - const actual = fn(input) - const expected = output - assert.equal(actual, expected) - }) - - // fixtures(__dirname, 'models/text', ({ module }) => { - // const { input, output } = module - // const fn = module.default - // const actual = fn(input).toJSON() - // const expected = output.toJSON() - // assert.deepEqual(actual, expected) - // }) - - fixtures(__dirname, 'models/node', ({ module }) => { - const { input, output } = module - const fn = module.default - let actual = fn(input) - let expected = output - - if (Node.isNode(actual)) { - actual = actual.toJSON() - } - - if (List.isList(actual)) { - actual = actual.toJSON() - } - - if (Node.isNode(expected)) { - expected = expected.toJSON() - } - - if (List.isList(expected)) { - expected = expected.toJSON() - } - - assert.deepEqual(actual, expected) - }) - - fixtures(__dirname, 'serializers/raw/deserialize', ({ module }) => { - const { input, output, options } = module - const actual = Value.fromJSON(input, options).toJSON() - const expected = output.toJSON() - assert.deepEqual(actual, expected) - }) - - fixtures(__dirname, 'serializers/raw/serialize', ({ module }) => { - const { input, output, options } = module - const actual = input.toJSON(options) - const expected = output - assert.deepEqual(actual, expected) + fixtures(__dirname, 'interfaces', ({ module }) => { + const { input, test, output } = module + const result = test(input) + assert.deepEqual(result, output) }) fixtures(__dirname, 'operations', ({ module }) => { @@ -129,15 +71,6 @@ describe('slate', () => { assert.deepEqual(actual, expected) }) - fixtures(__dirname, 'controllers', ({ module }) => { - const { input, output, default: fn } = module - - const actual = fn(input) - const expected = output - - assert.equal(actual, expected) - }) - fixtures(__dirname, 'schema', ({ module }) => { const { input, output, schema } = module const editor = new Editor({ value: input, plugins: [{ schema }] }) @@ -161,9 +94,4 @@ describe('slate', () => { assert.deepEqual(actual, expected) }) - - fixtures(__dirname, 'utils/path-utils', ({ module }) => { - const fn = module.default - fn() - }) }) diff --git a/packages/slate/test/interfaces/Path/transform/move_node/ends-after-to-ends-before.js b/packages/slate/test/interfaces/Path/transform/move_node/ends-after-to-ends-before.js new file mode 100644 index 0000000000..3193e260ea --- /dev/null +++ b/packages/slate/test/interfaces/Path/transform/move_node/ends-after-to-ends-before.js @@ -0,0 +1,15 @@ +import { Path } from 'slate' + +const path = [0, 1] + +const op = { + type: 'move_node', + path: [0, 3], + newPath: [0, 0], +} + +export const test = () => { + return Path.transform(path, op) +} + +export const output = [0, 2] diff --git a/packages/slate/test/interfaces/Path/transform/move_node/ends-before-to-ends-after.js b/packages/slate/test/interfaces/Path/transform/move_node/ends-before-to-ends-after.js new file mode 100644 index 0000000000..1a98878909 --- /dev/null +++ b/packages/slate/test/interfaces/Path/transform/move_node/ends-before-to-ends-after.js @@ -0,0 +1,15 @@ +import { Path } from 'slate' + +const path = [0, 1] + +const op = { + type: 'move_node', + path: [0, 0], + newPath: [0, 3], +} + +export const test = () => { + return Path.transform(path, op) +} + +export const output = [0, 0] diff --git a/packages/slate/test/interfaces/Point/isAfter/point/offset-after.js b/packages/slate/test/interfaces/Point/isAfter/point/offset-after.js new file mode 100644 index 0000000000..c72504b411 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/point/offset-after.js @@ -0,0 +1,17 @@ +import { Point } from 'slate' + +const point = { + path: [4], + offset: 3, +} + +const another = { + path: [4], + offset: 0, +} + +export const test = () => { + return Point.isAfter(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/point/offset-before.js b/packages/slate/test/interfaces/Point/isAfter/point/offset-before.js new file mode 100644 index 0000000000..b8f7c16800 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/point/offset-before.js @@ -0,0 +1,17 @@ +import { Point } from 'slate' + +const point = { + path: [4], + offset: 0, +} + +const another = { + path: [4], + offset: 3, +} + +export const test = () => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js b/packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js new file mode 100644 index 0000000000..13cf6d47d7 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js @@ -0,0 +1,17 @@ +import { Point } from 'slate' + +const point = { + path: [4], + offset: 0, +} + +const another = { + path: [4], + offset: 0, +} + +export const test = () => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/point/path-after.js b/packages/slate/test/interfaces/Point/isAfter/point/path-after.js new file mode 100644 index 0000000000..b669393245 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/point/path-after.js @@ -0,0 +1,17 @@ +import { Point } from 'slate' + +const point = { + path: [8], + offset: 0, +} + +const another = { + path: [4], + offset: 0, +} + +export const test = () => { + return Point.isAfter(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/point/path-before.js b/packages/slate/test/interfaces/Point/isAfter/point/path-before.js new file mode 100644 index 0000000000..95e10ccee7 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/point/path-before.js @@ -0,0 +1,17 @@ +import { Point } from 'slate' + +const point = { + path: [2], + offset: 0, +} + +const another = { + path: [4], + offset: 0, +} + +export const test = () => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/point/path-equal.js b/packages/slate/test/interfaces/Point/isAfter/point/path-equal.js new file mode 100644 index 0000000000..13cf6d47d7 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/point/path-equal.js @@ -0,0 +1,17 @@ +import { Point } from 'slate' + +const point = { + path: [4], + offset: 0, +} + +const another = { + path: [4], + offset: 0, +} + +export const test = () => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/models/node/get-active-marks-at-range.js/different-marks-across-blocks.js b/packages/slate/test/models/node/get-active-marks-at-range.js/different-marks-across-blocks.js deleted file mode 100644 index c60237c22f..0000000000 --- a/packages/slate/test/models/node/get-active-marks-at-range.js/different-marks-across-blocks.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' - -export const input = ( - - - - wo - rd - - - - middle - - - - unmarked - - - another - - unselected marked text - - - -) - -export default function({ document, selection }) { - return document.getActiveMarksAtRange(selection) -} - -export const output = Set() diff --git a/packages/slate/test/models/node/get-active-marks-at-range.js/mixed-marks-across-range.js b/packages/slate/test/models/node/get-active-marks-at-range.js/mixed-marks-across-range.js deleted file mode 100644 index e335a3aaf2..0000000000 --- a/packages/slate/test/models/node/get-active-marks-at-range.js/mixed-marks-across-range.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - - wo - rd - - - - - middle - - - - - - - - another - - - unselected marked text - - - -) - -export default function({ document, selection }) { - return document.getActiveMarksAtRange(selection) -} - -export const output = Set.of(Mark.create('a')) diff --git a/packages/slate/test/models/node/get-active-marks-at-range.js/same-mark-across-blocks.js b/packages/slate/test/models/node/get-active-marks-at-range.js/same-mark-across-blocks.js deleted file mode 100644 index c47729b425..0000000000 --- a/packages/slate/test/models/node/get-active-marks-at-range.js/same-mark-across-blocks.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - - wo - rd - - - - middle - - - - - - another - - unselected marked text - - - -) - -export default function({ document, selection }) { - return document.getActiveMarksAtRange(selection) -} - -export const output = Set.of(Mark.create('a')) diff --git a/packages/slate/test/models/node/get-ancestors/from-block.js b/packages/slate/test/models/node/get-ancestors/from-block.js deleted file mode 100644 index 78897b845d..0000000000 --- a/packages/slate/test/models/node/get-ancestors/from-block.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export const input = ( - - - one - - two - - three - - -) - -export default function({ document, selection }) { - const parentPath = PathUtils.lift(selection.start.path) - return document - .getAncestors(parentPath) - .toArray() - .map(n => `${n.object}:${n.data.get('k')}`) -} - -export const output = [`document:a`] diff --git a/packages/slate/test/models/node/get-ancestors/from-document.js b/packages/slate/test/models/node/get-ancestors/from-document.js deleted file mode 100644 index 9f6032d86d..0000000000 --- a/packages/slate/test/models/node/get-ancestors/from-document.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - three - - -) - -export default function({ document, selection }) { - return document - .getAncestors([]) - .toArray() - .map(n => `${n.object}:${n.data.get('k')}`) -} - -export const output = [] diff --git a/packages/slate/test/models/node/get-ancestors/from-inline.js b/packages/slate/test/models/node/get-ancestors/from-inline.js deleted file mode 100644 index a93223f398..0000000000 --- a/packages/slate/test/models/node/get-ancestors/from-inline.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export const input = ( - - - one - - - - two - - - - three - - -) - -export default function({ document, selection }) { - const parentPath = PathUtils.lift(selection.start.path) - return document - .getAncestors(parentPath) - .toArray() - .map(n => `${n.object}:${n.data.get('k')}`) -} - -export const output = [`document:a`, `block:c`] diff --git a/packages/slate/test/models/node/get-ancestors/from-text-blocks-nested.js b/packages/slate/test/models/node/get-ancestors/from-text-blocks-nested.js deleted file mode 100644 index 6acab7c392..0000000000 --- a/packages/slate/test/models/node/get-ancestors/from-text-blocks-nested.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - - two - - - three - - -) - -export default function({ document, selection }) { - return document - .getAncestors(selection.start.path) - .toArray() - .map(n => `${n.object}:${n.data.get('k')}`) -} - -export const output = [`document:a`, `block:c`, `block:d`] diff --git a/packages/slate/test/models/node/get-ancestors/from-text-inline.js b/packages/slate/test/models/node/get-ancestors/from-text-inline.js deleted file mode 100644 index 79ad3a5851..0000000000 --- a/packages/slate/test/models/node/get-ancestors/from-text-inline.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - - - two - - - - three - - -) - -export default function({ document, selection }) { - return document - .getAncestors(selection.start.path) - .toArray() - .map(n => `${n.object}:${n.data.get('k')}`) -} - -export const output = [`document:a`, `block:c`, `inline:d`] diff --git a/packages/slate/test/models/node/get-ancestors/from-text.js b/packages/slate/test/models/node/get-ancestors/from-text.js deleted file mode 100644 index ed450b4530..0000000000 --- a/packages/slate/test/models/node/get-ancestors/from-text.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - three - - -) - -export default function({ document, selection }) { - return document - .getAncestors(selection.start.path) - .toArray() - .map(n => `${n.object}:${n.data.get('k')}`) -} - -export const output = [`document:a`, `block:c`] diff --git a/packages/slate/test/models/node/get-closest/by-path.js b/packages/slate/test/models/node/get-closest/by-path.js deleted file mode 100644 index c7ddef248d..0000000000 --- a/packages/slate/test/models/node/get-closest/by-path.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - three - four - - -) - -export default function({ document, selection }) { - return document.getClosestBlock(selection.end.path) -} - -export const output = ( - - two - -) diff --git a/packages/slate/test/models/node/get-closest/get-block-parent-inline.js b/packages/slate/test/models/node/get-closest/get-block-parent-inline.js deleted file mode 100644 index c7b3924674..0000000000 --- a/packages/slate/test/models/node/get-closest/get-block-parent-inline.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - - two - - - three - four - - -) - -export default function({ document, selection }) { - return document.getClosestBlock(selection.end.path) -} - -export const output = ( - - - two - - -) diff --git a/packages/slate/test/models/node/get-closest/top-level.js b/packages/slate/test/models/node/get-closest/top-level.js deleted file mode 100644 index 60703e9b76..0000000000 --- a/packages/slate/test/models/node/get-closest/top-level.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export const input = ( - - - one - two - three - four - - -) - -export default function({ document, selection }) { - return document.getClosestBlock(PathUtils.create([1])) -} - -export const output = null diff --git a/packages/slate/test/models/node/get-descendants-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-descendants-at-range/multiple-blocks.js deleted file mode 100644 index 30d4c55a59..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/multiple-blocks.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js b/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js deleted file mode 100644 index 1f42cf0bd7..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - - one - - - - - - two - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'b', 'c', 'd'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js b/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js deleted file mode 100644 index 54aed46f77..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - two - - - - - - three - - - - - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'g', 'h', 'i'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js b/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js deleted file mode 100644 index 2f0e04bd27..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - two - - - - - - three - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'b', 'e', 'f'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-multiple-blocks.js b/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-multiple-blocks.js deleted file mode 100644 index dbca13d2e5..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-multiple-blocks.js +++ /dev/null @@ -1,46 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - - two - - - - - three - - - - - four - - - - five - - - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js b/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js deleted file mode 100644 index 54adf553e5..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - - two - - - - three - - - - four - - - - - - five - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'e', 'f', 'g', 'h', 'i', 'j', 'k'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-spanning-first-text.js b/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-spanning-first-text.js deleted file mode 100644 index 15e6bc6f9a..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/nested-blocks-selection-spanning-first-text.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - - one - - - - - - two - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'b', 'c', 'd'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-beginning-of-text.js b/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-beginning-of-text.js deleted file mode 100644 index 34c286060e..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-beginning-of-text.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - - two - - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['c', 'd'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-end-of-text.js b/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-end-of-text.js deleted file mode 100644 index dd9dce4488..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-end-of-text.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - three - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['c', 'd'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-middle-of-text.js b/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-middle-of-text.js deleted file mode 100644 index 061252a362..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/single-block-cursor-middle-of-text.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - one - - - - two - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'b'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/single-block-with-inline.js b/packages/slate/test/models/node/get-descendants-at-range/single-block-with-inline.js deleted file mode 100644 index a67febbef7..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/single-block-with-inline.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - two - - - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'c', 'd'] diff --git a/packages/slate/test/models/node/get-descendants-at-range/single-void-block.js b/packages/slate/test/models/node/get-descendants-at-range/single-void-block.js deleted file mode 100644 index 3f24f2beb1..0000000000 --- a/packages/slate/test/models/node/get-descendants-at-range/single-void-block.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - - - - - - -) - -export default function({ document, selection }) { - return document - .getDescendantsAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'b'] diff --git a/packages/slate/test/models/node/get-fragment-at-range/across-block-with-marks.js b/packages/slate/test/models/node/get-fragment-at-range/across-block-with-marks.js deleted file mode 100644 index 2d0d760d74..0000000000 --- a/packages/slate/test/models/node/get-fragment-at-range/across-block-with-marks.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - wo - - rd - - - - middle - - - - another - - - - -) - -export default function({ document, selection }) { - return document.getFragmentAtRange(selection) -} - -export const output = ( - - - rd - - - middle - - - an - - -) diff --git a/packages/slate/test/models/node/get-fragment-at-range/block-across.js b/packages/slate/test/models/node/get-fragment-at-range/block-across.js deleted file mode 100644 index 494785f653..0000000000 --- a/packages/slate/test/models/node/get-fragment-at-range/block-across.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - two - - th ree - - - -) - -export default function({ document, selection }) { - return document.getFragmentAtRange(selection) -} - -export const output = ( - - e - two - th - -) diff --git a/packages/slate/test/models/node/get-fragment-at-range/block.js b/packages/slate/test/models/node/get-fragment-at-range/block.js deleted file mode 100644 index bdfbc46336..0000000000 --- a/packages/slate/test/models/node/get-fragment-at-range/block.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one two three - - - -) - -export default function({ document, selection }) { - return document.getFragmentAtRange(selection) -} - -export const output = ( - - two - -) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/multiple-blocks.js deleted file mode 100644 index 3bcf1be186..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/multiple-blocks.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['c', 'e', 'g']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js deleted file mode 100644 index c9fd284239..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - one - - - - - - two - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js deleted file mode 100644 index 634dc2d99c..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - two - - - - - - three - - - - - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['h']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js deleted file mode 100644 index a3c7e4b919..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - two - - - - - - three - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['e']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js deleted file mode 100644 index 587349f136..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js +++ /dev/null @@ -1,46 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - - two - - - - - three - - - - - four - - - - five - - - - - -) - -export default function({ document, selection }) { - return document - .getLeafBlocksAtRange(selection) - .map(n => n.key) - .toArray() -} - -export const output = ['a', 'e', 'h', 'j'] diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js deleted file mode 100644 index 456d9a7a84..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - - two - - - - three - - - - four - - - - - - five - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['f', 'h', 'j']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-spanning-first-text.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-spanning-first-text.js deleted file mode 100644 index 1710b42e38..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/nested-blocks-selection-spanning-first-text.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - one - - - - - - two - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block-with-inline.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block-with-inline.js deleted file mode 100644 index 89fc6fe703..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block-with-inline.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - two - - - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block.js deleted file mode 100644 index 8fb9ac68fd..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-block.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - - two - - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js b/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js deleted file mode 100644 index e6c9585a00..0000000000 --- a/packages/slate/test/models/node/get-leaf-blocks-at-range/single-void-block.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - - - - - -) - -export default function({ document, selection }) { - return document.getLeafBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks-no-inline.js b/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks-no-inline.js deleted file mode 100644 index ceb2265921..0000000000 --- a/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks-no-inline.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - four - - - - -) - -export default function({ document, selection }) { - return document.getLeafInlinesAtRange(selection).map(n => n.key) -} - -export const output = List() diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks.js deleted file mode 100644 index 3754604072..0000000000 --- a/packages/slate/test/models/node/get-leaf-inlines-at-range/multiple-blocks.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - three - - - - - - - - - four - - - five - - - - six - - - - -) - -export default function({ document, selection }) { - return document.getLeafInlinesAtRange(selection).map(n => n.key) -} - -export const output = List(['e', 'k', 'm']) diff --git a/packages/slate/test/models/node/get-leaf-inlines-at-range/nested-with-text-on-every-level.js b/packages/slate/test/models/node/get-leaf-inlines-at-range/nested-with-text-on-every-level.js deleted file mode 100644 index 7608bfab3d..0000000000 --- a/packages/slate/test/models/node/get-leaf-inlines-at-range/nested-with-text-on-every-level.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - - one - - - - - - two - - three - - - four - - - - - -) - -export default function({ document, selection }) { - return document.getLeafInlinesAtRange(selection).map(n => n.key) -} - -export const output = List(['d', 'g']) diff --git a/packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-no-previous-text.js b/packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-no-previous-text.js deleted file mode 100644 index 049632a4cf..0000000000 --- a/packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-no-previous-text.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - - - Cat is Cute - - - - -) - -export default function({ document, selection }) { - return document.getInsertMarksAtPoint(selection.start) -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-previous-text-not-in-the-same-block.js b/packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-previous-text-not-in-the-same-block.js deleted file mode 100644 index 451bfcc37b..0000000000 --- a/packages/slate/test/models/node/get-marks-at-point/marked-text-with-zero-offset-with-previous-text-not-in-the-same-block.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - - Cat is Cute - - - - Dog is Delightful - - - - -) - -export default function({ document, selection }) { - return document.getInsertMarksAtPoint(selection.start) -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/node/get-marks-at-point/marked-text.js b/packages/slate/test/models/node/get-marks-at-point/marked-text.js deleted file mode 100644 index cc7f105b0b..0000000000 --- a/packages/slate/test/models/node/get-marks-at-point/marked-text.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - - - Cat{' '} - - is - Cute - - - -) - -export default function({ document, selection }) { - return document.getInsertMarksAtPoint(selection.start) -} - -export const output = Set.of(Mark.create('italic')) diff --git a/packages/slate/test/models/node/get-marks-at-point/text-with-zero-offset.js b/packages/slate/test/models/node/get-marks-at-point/text-with-zero-offset.js deleted file mode 100644 index 5e869bf4b6..0000000000 --- a/packages/slate/test/models/node/get-marks-at-point/text-with-zero-offset.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - - Cat is Cute - - - Dog is - - - Delightful - - - - - - -) - -export default function({ document, selection }) { - return document.getInsertMarksAtPoint(selection.start) -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/node/get-marks-at-point/unmarked-text.js b/packages/slate/test/models/node/get-marks-at-point/unmarked-text.js deleted file mode 100644 index d5d850c442..0000000000 --- a/packages/slate/test/models/node/get-marks-at-point/unmarked-text.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Set } from 'immutable' - -export const input = ( - - - - - Cat is Cute - - - - -) - -export default function({ document, selection }) { - return document.getInsertMarksAtPoint(selection.start) -} - -export const output = Set.of() diff --git a/packages/slate/test/models/node/get-next-block/by-path.js b/packages/slate/test/models/node/get-next-block/by-path.js deleted file mode 100644 index 84f2f102af..0000000000 --- a/packages/slate/test/models/node/get-next-block/by-path.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - three - four - - -) - -export default function({ document, selection }) { - return document.getNextBlock(selection.end.path) -} - -export const output = three diff --git a/packages/slate/test/models/node/get-next-block/multiple-siblings-to-bypass.js b/packages/slate/test/models/node/get-next-block/multiple-siblings-to-bypass.js deleted file mode 100644 index 90cc978642..0000000000 --- a/packages/slate/test/models/node/get-next-block/multiple-siblings-to-bypass.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - - - three - four - - -) - -export default function({ document, selection }) { - return document.getNextBlock(selection.end.path) -} - -export const output = three diff --git a/packages/slate/test/models/node/get-next-block/next-block-is-ancestor-sibling.js b/packages/slate/test/models/node/get-next-block/next-block-is-ancestor-sibling.js deleted file mode 100644 index 84f2f102af..0000000000 --- a/packages/slate/test/models/node/get-next-block/next-block-is-ancestor-sibling.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - three - four - - -) - -export default function({ document, selection }) { - return document.getNextBlock(selection.end.path) -} - -export const output = three diff --git a/packages/slate/test/models/node/get-next-block/next-block-is-in-sibling-with-deeper-blocks.js b/packages/slate/test/models/node/get-next-block/next-block-is-in-sibling-with-deeper-blocks.js deleted file mode 100644 index 1618f9dd54..0000000000 --- a/packages/slate/test/models/node/get-next-block/next-block-is-in-sibling-with-deeper-blocks.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - 1 - - 2 - - - 3 - - 3.1 - - - 4 - - -) - -export default function({ document, selection }) { - return document.getNextBlock(selection.end.path) -} - -export const output = 3 diff --git a/packages/slate/test/models/node/get-next-block/next-block-is-sibling-descendent.js b/packages/slate/test/models/node/get-next-block/next-block-is-sibling-descendent.js deleted file mode 100644 index 15ef47df09..0000000000 --- a/packages/slate/test/models/node/get-next-block/next-block-is-sibling-descendent.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - - three - - four - - -) - -export default function({ document, selection }) { - return document.getNextBlock(selection.end.path) -} - -export const output = three diff --git a/packages/slate/test/models/node/get-next-block/next-block-is-sibling.js b/packages/slate/test/models/node/get-next-block/next-block-is-sibling.js deleted file mode 100644 index ea25cd59c3..0000000000 --- a/packages/slate/test/models/node/get-next-block/next-block-is-sibling.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' - -export const input = ( - - - one - two - three - four - - -) - -export default function({ document }) { - return document.getNextBlock(PathUtils.create([1])) -} - -export const output = three diff --git a/packages/slate/test/models/node/get-next-block/no-next-block.js b/packages/slate/test/models/node/get-next-block/no-next-block.js deleted file mode 100644 index 3f5ef1b5c0..0000000000 --- a/packages/slate/test/models/node/get-next-block/no-next-block.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - two - - three - - - four - five - - - -) - -export default function({ document, selection }) { - return document.getNextBlock(selection.end.path) -} - -export const output = null diff --git a/packages/slate/test/models/node/get-next-block/no-next-node.js b/packages/slate/test/models/node/get-next-block/no-next-node.js deleted file mode 100644 index b10f89ae13..0000000000 --- a/packages/slate/test/models/node/get-next-block/no-next-node.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - two - - three - - - four - - - -) - -export default function({ document, selection }) { - return document.getNextBlock(selection.end.path) -} - -export const output = null diff --git a/packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling-with-nested-blocks.js b/packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling-with-nested-blocks.js deleted file mode 100644 index c444422e44..0000000000 --- a/packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling-with-nested-blocks.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - - three - - four - - -) - -export default function({ document, selection }) { - return document.getNextNode(selection.end.path) -} - -export const output = ( - - three - -) diff --git a/packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling.js b/packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling.js deleted file mode 100644 index 83e4ba7991..0000000000 --- a/packages/slate/test/models/node/get-next-node/next-node-is-ancestor-sibling.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - three - four - - -) - -export default function({ document, selection }) { - return document.getNextNode(selection.end.path) -} - -export const output = three diff --git a/packages/slate/test/models/node/get-previous-block/by-path.js b/packages/slate/test/models/node/get-previous-block/by-path.js deleted file mode 100644 index c5c14ad6f3..0000000000 --- a/packages/slate/test/models/node/get-previous-block/by-path.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - three - four - - -) - -export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.path) -} - -export const output = one diff --git a/packages/slate/test/models/node/get-previous-block/multiple-siblings-to-bypass.js b/packages/slate/test/models/node/get-previous-block/multiple-siblings-to-bypass.js deleted file mode 100644 index aa542a8ff6..0000000000 --- a/packages/slate/test/models/node/get-previous-block/multiple-siblings-to-bypass.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - - - two - - three - four - - -) - -export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.path) -} - -export const output = one diff --git a/packages/slate/test/models/node/get-previous-block/no-prev-block.js b/packages/slate/test/models/node/get-previous-block/no-prev-block.js deleted file mode 100644 index f5e3473f74..0000000000 --- a/packages/slate/test/models/node/get-previous-block/no-prev-block.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - zer - one - - two - three - - four - - - -) - -export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.path) -} - -export const output = null diff --git a/packages/slate/test/models/node/get-previous-block/no-prev-node.js b/packages/slate/test/models/node/get-previous-block/no-prev-node.js deleted file mode 100644 index ee006a4ec9..0000000000 --- a/packages/slate/test/models/node/get-previous-block/no-prev-node.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - two - - three - - four - - -) - -export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.path) -} - -export const output = null diff --git a/packages/slate/test/models/node/get-previous-block/prev-block-is-ancestor-sibling.js b/packages/slate/test/models/node/get-previous-block/prev-block-is-ancestor-sibling.js deleted file mode 100644 index d4f81976ff..0000000000 --- a/packages/slate/test/models/node/get-previous-block/prev-block-is-ancestor-sibling.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - two - - three - - four - - -) - -export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.path) -} - -export const output = two diff --git a/packages/slate/test/models/node/get-previous-block/prev-block-is-in-sibling-with-deeper-blocks.js b/packages/slate/test/models/node/get-previous-block/prev-block-is-in-sibling-with-deeper-blocks.js deleted file mode 100644 index a3661cb6dd..0000000000 --- a/packages/slate/test/models/node/get-previous-block/prev-block-is-in-sibling-with-deeper-blocks.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - 1 - - 2 - - 2.1 - - - - - 3.1 - - 3.2 - - - 4> - - - -) - -export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.path) -} - -export const output = 3.2 diff --git a/packages/slate/test/models/node/get-previous-block/prev-block-is-sibling-descendent.js b/packages/slate/test/models/node/get-previous-block/prev-block-is-sibling-descendent.js deleted file mode 100644 index 2b49bdfcde..0000000000 --- a/packages/slate/test/models/node/get-previous-block/prev-block-is-sibling-descendent.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - two - - - three - - four - - -) - -export default function({ document, selection }) { - return document.getPreviousBlock(selection.end.path) -} - -export const output = one diff --git a/packages/slate/test/models/node/get-previous-block/prev-block-is-sibling.js b/packages/slate/test/models/node/get-previous-block/prev-block-is-sibling.js deleted file mode 100644 index 7d13b04587..0000000000 --- a/packages/slate/test/models/node/get-previous-block/prev-block-is-sibling.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import PathUtils from '../../../../src/utils/path-utils' - -export const input = ( - - - one - two - three - four - - -) - -export default function({ document }) { - return document.getPreviousBlock(PathUtils.create([2])) -} - -export const output = two diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-root-blocks-at-range/multiple-blocks.js deleted file mode 100644 index 417176e15d..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/multiple-blocks.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['c', 'e', 'g']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js deleted file mode 100644 index 3a6549af79..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-first-parent.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - one - - - - - - two - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js deleted file mode 100644 index 10cfeed692..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-first-leaf-of-second-parent.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - two - - - - - - three - - - - - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js deleted file mode 100644 index 727a16d2f7..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-cursor-in-second-leaf-of-first-parent.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - two - - - - - - three - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js deleted file mode 100644 index ae0768bd0c..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-multiple-blocks.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - - two - - - - - three - - - - - four - - - - five - - - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a', 'c']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js deleted file mode 100644 index 2ba85b4554..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-overlapping-texts-in-second-parent.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - one - - - - - - two - - - - three - - - - four - - - - - - five - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-spanning-first-text.js b/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-spanning-first-text.js deleted file mode 100644 index 30010d31b2..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/nested-blocks-selection-spanning-first-text.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - one - - - - - - two - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/single-block-with-inline.js b/packages/slate/test/models/node/get-root-blocks-at-range/single-block-with-inline.js deleted file mode 100644 index f12acf367e..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/single-block-with-inline.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - two - - - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/single-block.js b/packages/slate/test/models/node/get-root-blocks-at-range/single-block.js deleted file mode 100644 index 72c0115211..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/single-block.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - - two - - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['c']) diff --git a/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js b/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js deleted file mode 100644 index 70ae64a4b2..0000000000 --- a/packages/slate/test/models/node/get-root-blocks-at-range/single-void-block.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - - - - - -) - -export default function({ document, selection }) { - return document.getRootBlocksAtRange(selection).map(n => n.key) -} - -export const output = List(['a']) diff --git a/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks-no-inline.js b/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks-no-inline.js deleted file mode 100644 index 23b8e4a807..0000000000 --- a/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks-no-inline.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - four - - - - -) - -export default function({ document, selection }) { - return document.getRootInlinesAtRange(selection).map(n => n.key) -} - -export const output = List() diff --git a/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks.js b/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks.js deleted file mode 100644 index 125e5d6bb5..0000000000 --- a/packages/slate/test/models/node/get-root-inlines-at-range/multiple-blocks.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - three - - - - - - - - - four - - - five - - - - six - - - - -) - -export default function({ document, selection }) { - return document.getRootInlinesAtRange(selection).map(n => n.key) -} - -export const output = List(['e', 'j']) diff --git a/packages/slate/test/models/node/get-root-inlines-at-range/nested-with-text-on-every-level.js b/packages/slate/test/models/node/get-root-inlines-at-range/nested-with-text-on-every-level.js deleted file mode 100644 index 088a994446..0000000000 --- a/packages/slate/test/models/node/get-root-inlines-at-range/nested-with-text-on-every-level.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import h from '../../../helpers/h' - -export const input = ( - - - - - - - - one - - - - - - two - - three - - - four - - - - - -) - -export default function({ document, selection }) { - return document.getRootInlinesAtRange(selection).map(n => n.key) -} - -export const output = List(['b']) diff --git a/packages/slate/test/models/node/is-in-range/block-above.js b/packages/slate/test/models/node/is-in-range/block-above.js deleted file mode 100644 index 850568878f..0000000000 --- a/packages/slate/test/models/node/is-in-range/block-above.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange([0], selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/block-below.js b/packages/slate/test/models/node/is-in-range/block-below.js deleted file mode 100644 index 769db5c697..0000000000 --- a/packages/slate/test/models/node/is-in-range/block-below.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - five - - - -) - -export default function({ document, selection }) { - return document.isInRange([4], selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/first-block-inside.js b/packages/slate/test/models/node/is-in-range/first-block-inside.js deleted file mode 100644 index dbd2dbe866..0000000000 --- a/packages/slate/test/models/node/is-in-range/first-block-inside.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange([1], selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/first-text-inside.js b/packages/slate/test/models/node/is-in-range/first-text-inside.js deleted file mode 100644 index a7a34d9bcf..0000000000 --- a/packages/slate/test/models/node/is-in-range/first-text-inside.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange([1, 0], selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/last-block-inside.js b/packages/slate/test/models/node/is-in-range/last-block-inside.js deleted file mode 100644 index d087cb8b39..0000000000 --- a/packages/slate/test/models/node/is-in-range/last-block-inside.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange([3], selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/last-text-inside.js b/packages/slate/test/models/node/is-in-range/last-text-inside.js deleted file mode 100644 index 2999650e84..0000000000 --- a/packages/slate/test/models/node/is-in-range/last-text-inside.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange([3, 1], selection) -} - -export const output = true diff --git a/packages/slate/test/models/node/is-in-range/text-above.js b/packages/slate/test/models/node/is-in-range/text-above.js deleted file mode 100644 index 3f7bd23c0d..0000000000 --- a/packages/slate/test/models/node/is-in-range/text-above.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange([0, 0], selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/text-below.js b/packages/slate/test/models/node/is-in-range/text-below.js deleted file mode 100644 index a299a697dd..0000000000 --- a/packages/slate/test/models/node/is-in-range/text-below.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - five - - - -) - -export default function({ document, selection }) { - return document.isInRange([4, 0], selection) -} - -export const output = false diff --git a/packages/slate/test/models/node/is-in-range/text-in-middle-inside.js b/packages/slate/test/models/node/is-in-range/text-in-middle-inside.js deleted file mode 100644 index c44f3c4071..0000000000 --- a/packages/slate/test/models/node/is-in-range/text-in-middle-inside.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - - two - - - - - - - - three - - - four - - - - -) - -export default function({ document, selection }) { - return document.isInRange([2, 0], selection) -} - -export const output = true diff --git a/packages/slate/test/models/operation/create/add-mark-with-data.js b/packages/slate/test/models/operation/create/add-mark-with-data.js deleted file mode 100644 index e174ac89f6..0000000000 --- a/packages/slate/test/models/operation/create/add-mark-with-data.js +++ /dev/null @@ -1,24 +0,0 @@ -import Operation from '../../../../src/models/operation' - -export const input = { - type: 'add_mark', - path: [2, 1], - mark: 'b', - data: { info: 'user supplied text', flag: true }, -} - -export default function(op) { - return Operation.create(op) -} - -export const output = { - object: 'operation', - type: 'add_mark', - path: [2, 1], - mark: { - data: {}, - object: 'mark', - type: 'b', - }, - data: { info: 'user supplied text', flag: true }, -} diff --git a/packages/slate/test/models/operation/create/add-mark-without-data.js b/packages/slate/test/models/operation/create/add-mark-without-data.js deleted file mode 100644 index 5b187b5096..0000000000 --- a/packages/slate/test/models/operation/create/add-mark-without-data.js +++ /dev/null @@ -1,23 +0,0 @@ -import Operation from '../../../../src/models/operation' - -export const input = { - type: 'add_mark', - path: [2, 1], - mark: 'b', -} - -export default function(op) { - return Operation.create(op) -} - -export const output = { - object: 'operation', - type: 'add_mark', - path: [2, 1], - mark: { - data: {}, - object: 'mark', - type: 'b', - }, - data: {}, -} diff --git a/packages/slate/test/models/point/is-after-point/after-target-path.js b/packages/slate/test/models/point/is-after-point/after-target-path.js deleted file mode 100644 index 3cd83f8845..0000000000 --- a/packages/slate/test/models/point/is-after-point/after-target-path.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Point.create({ - key: 'b', - path: [2], - offset: 2, - }), -} - -export default function({ point, target }) { - return point.isAfterPoint(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-after-point/before-target-path.js b/packages/slate/test/models/point/is-after-point/before-target-path.js deleted file mode 100644 index 02a5208501..0000000000 --- a/packages/slate/test/models/point/is-after-point/before-target-path.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), - target: Point.create({ - key: 'b', - path: [0, 2], - offset: 2, - }), -} - -export default function({ point, target }) { - return point.isAfterPoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-point/same-node-after-target-offset.js b/packages/slate/test/models/point/is-after-point/same-node-after-target-offset.js deleted file mode 100644 index dd3b6570df..0000000000 --- a/packages/slate/test/models/point/is-after-point/same-node-after-target-offset.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), - target: Point.create({ - key: 'a', - path: [0, 1], - offset: 3, - }), -} - -export default function({ point, target }) { - return point.isAfterPoint(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-after-point/same-node-before-target-offset.js b/packages/slate/test/models/point/is-after-point/same-node-before-target-offset.js deleted file mode 100644 index 50446f9054..0000000000 --- a/packages/slate/test/models/point/is-after-point/same-node-before-target-offset.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 1, - }), - target: Point.create({ - key: 'a', - path: [0, 1], - offset: 2, - }), -} - -export default function({ point, target }) { - return point.isAfterPoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-point/same-node-same-offset.js b/packages/slate/test/models/point/is-after-point/same-node-same-offset.js deleted file mode 100644 index 712b45d35b..0000000000 --- a/packages/slate/test/models/point/is-after-point/same-node-same-offset.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), - target: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), -} - -export default function({ point, target }) { - return point.isAfterPoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-point/target-is-ancestor.js b/packages/slate/test/models/point/is-after-point/target-is-ancestor.js deleted file mode 100644 index 44b23c4a83..0000000000 --- a/packages/slate/test/models/point/is-after-point/target-is-ancestor.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [1, 2], - offset: 1, - }), - target: Point.create({ - key: 'b', - path: [1], - offset: 1, - }), -} - -export default function({ point, target }) { - return point.isAfterPoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-point/target-is-descendant.js b/packages/slate/test/models/point/is-after-point/target-is-descendant.js deleted file mode 100644 index 6ce6f94d87..0000000000 --- a/packages/slate/test/models/point/is-after-point/target-is-descendant.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 0], - offset: 0, - }), - target: Point.create({ - key: 'b', - path: [0, 0, 1], - offset: 0, - }), -} - -export default function({ point, target }) { - return point.isAfterPoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-range/after-end-node.js b/packages/slate/test/models/point/is-after-range/after-end-node.js deleted file mode 100644 index bf810bbd4b..0000000000 --- a/packages/slate/test/models/point/is-after-range/after-end-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-after-range/after-end-offset.js b/packages/slate/test/models/point/is-after-range/after-end-offset.js deleted file mode 100644 index 4395b5d8fb..0000000000 --- a/packages/slate/test/models/point/is-after-range/after-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 12, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-after-range/after-start-offset.js b/packages/slate/test/models/point/is-after-range/after-start-offset.js deleted file mode 100644 index 7697cb1706..0000000000 --- a/packages/slate/test/models/point/is-after-range/after-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-range/before-end-offset.js b/packages/slate/test/models/point/is-after-range/before-end-offset.js deleted file mode 100644 index 45cf62f192..0000000000 --- a/packages/slate/test/models/point/is-after-range/before-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-range/before-start-node.js b/packages/slate/test/models/point/is-after-range/before-start-node.js deleted file mode 100644 index ede3895c11..0000000000 --- a/packages/slate/test/models/point/is-after-range/before-start-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [0], - offset: 7, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-range/before-start-offset.js b/packages/slate/test/models/point/is-after-range/before-start-offset.js deleted file mode 100644 index ef31fa071e..0000000000 --- a/packages/slate/test/models/point/is-after-range/before-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-range/between-nodes.js b/packages/slate/test/models/point/is-after-range/between-nodes.js deleted file mode 100644 index 809d094686..0000000000 --- a/packages/slate/test/models/point/is-after-range/between-nodes.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [5], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-range/is-end.js b/packages/slate/test/models/point/is-after-range/is-end.js deleted file mode 100644 index 22414adcd7..0000000000 --- a/packages/slate/test/models/point/is-after-range/is-end.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 3, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-after-range/is-start.js b/packages/slate/test/models/point/is-after-range/is-start.js deleted file mode 100644 index 96a7f0798a..0000000000 --- a/packages/slate/test/models/point/is-after-range/is-start.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 0, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAfterRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/after-end-node.js b/packages/slate/test/models/point/is-at-end-of-range/after-end-node.js deleted file mode 100644 index 781c100744..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/after-end-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/after-end-offset.js b/packages/slate/test/models/point/is-at-end-of-range/after-end-offset.js deleted file mode 100644 index 1c6a0beed5..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/after-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 12, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/after-start-offset.js b/packages/slate/test/models/point/is-at-end-of-range/after-start-offset.js deleted file mode 100644 index 5cff0c0284..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/after-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/before-end-offset.js b/packages/slate/test/models/point/is-at-end-of-range/before-end-offset.js deleted file mode 100644 index 80bd67ec3b..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/before-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/before-start-node.js b/packages/slate/test/models/point/is-at-end-of-range/before-start-node.js deleted file mode 100644 index 6dcf7ae868..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/before-start-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [0], - offset: 7, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/before-start-offset.js b/packages/slate/test/models/point/is-at-end-of-range/before-start-offset.js deleted file mode 100644 index 04637014dd..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/before-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/between-nodes.js b/packages/slate/test/models/point/is-at-end-of-range/between-nodes.js deleted file mode 100644 index 439978de33..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/between-nodes.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [5], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-end-of-range/is-end.js b/packages/slate/test/models/point/is-at-end-of-range/is-end.js deleted file mode 100644 index 9047d11653..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/is-end.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 3, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-at-end-of-range/is-start.js b/packages/slate/test/models/point/is-at-end-of-range/is-start.js deleted file mode 100644 index 78934aa5a3..0000000000 --- a/packages/slate/test/models/point/is-at-end-of-range/is-start.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 0, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtEndOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/after-end-node.js b/packages/slate/test/models/point/is-at-start-of-range/after-end-node.js deleted file mode 100644 index 403c62b35b..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/after-end-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/after-end-offset.js b/packages/slate/test/models/point/is-at-start-of-range/after-end-offset.js deleted file mode 100644 index 23c728ce16..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/after-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 12, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/after-start-offset.js b/packages/slate/test/models/point/is-at-start-of-range/after-start-offset.js deleted file mode 100644 index ae8b7792a8..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/after-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/before-end-offset.js b/packages/slate/test/models/point/is-at-start-of-range/before-end-offset.js deleted file mode 100644 index d43b26c5bd..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/before-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/before-start-node.js b/packages/slate/test/models/point/is-at-start-of-range/before-start-node.js deleted file mode 100644 index 9f027726b1..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/before-start-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [0], - offset: 7, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/before-start-offset.js b/packages/slate/test/models/point/is-at-start-of-range/before-start-offset.js deleted file mode 100644 index 6ed72fa260..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/before-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/between-nodes.js b/packages/slate/test/models/point/is-at-start-of-range/between-nodes.js deleted file mode 100644 index ab10b20aec..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/between-nodes.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [5], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/is-end.js b/packages/slate/test/models/point/is-at-start-of-range/is-end.js deleted file mode 100644 index dc1a368398..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/is-end.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 3, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-at-start-of-range/is-start.js b/packages/slate/test/models/point/is-at-start-of-range/is-start.js deleted file mode 100644 index c58ecb1847..0000000000 --- a/packages/slate/test/models/point/is-at-start-of-range/is-start.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 0, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isAtStartOfRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-before-point/after-target-path.js b/packages/slate/test/models/point/is-before-point/after-target-path.js deleted file mode 100644 index 4345d742a1..0000000000 --- a/packages/slate/test/models/point/is-before-point/after-target-path.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Point.create({ - key: 'b', - path: [2], - offset: 2, - }), -} - -export default function({ point, target }) { - return point.isBeforePoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-point/before-target-path.js b/packages/slate/test/models/point/is-before-point/before-target-path.js deleted file mode 100644 index 9022d5d4fc..0000000000 --- a/packages/slate/test/models/point/is-before-point/before-target-path.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), - target: Point.create({ - key: 'b', - path: [0, 2], - offset: 2, - }), -} - -export default function({ point, target }) { - return point.isBeforePoint(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-before-point/same-node-after-target-offset.js b/packages/slate/test/models/point/is-before-point/same-node-after-target-offset.js deleted file mode 100644 index a1edd6e4f4..0000000000 --- a/packages/slate/test/models/point/is-before-point/same-node-after-target-offset.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), - target: Point.create({ - key: 'a', - path: [0, 1], - offset: 3, - }), -} - -export default function({ point, target }) { - return point.isBeforePoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-point/same-node-before-target-offset.js b/packages/slate/test/models/point/is-before-point/same-node-before-target-offset.js deleted file mode 100644 index 8e1402ba44..0000000000 --- a/packages/slate/test/models/point/is-before-point/same-node-before-target-offset.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 1, - }), - target: Point.create({ - key: 'a', - path: [0, 1], - offset: 2, - }), -} - -export default function({ point, target }) { - return point.isBeforePoint(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-before-point/same-node-same-offset.js b/packages/slate/test/models/point/is-before-point/same-node-same-offset.js deleted file mode 100644 index f35563414e..0000000000 --- a/packages/slate/test/models/point/is-before-point/same-node-same-offset.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), - target: Point.create({ - key: 'a', - path: [0, 1], - offset: 4, - }), -} - -export default function({ point, target }) { - return point.isBeforePoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-point/target-is-ancestor.js b/packages/slate/test/models/point/is-before-point/target-is-ancestor.js deleted file mode 100644 index ce57b7dff2..0000000000 --- a/packages/slate/test/models/point/is-before-point/target-is-ancestor.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [1, 2], - offset: 1, - }), - target: Point.create({ - key: 'b', - path: [1], - offset: 1, - }), -} - -export default function({ point, target }) { - return point.isBeforePoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-point/target-is-descendant.js b/packages/slate/test/models/point/is-before-point/target-is-descendant.js deleted file mode 100644 index 15464bd59f..0000000000 --- a/packages/slate/test/models/point/is-before-point/target-is-descendant.js +++ /dev/null @@ -1,20 +0,0 @@ -import Point from '../../../../src/models/point' - -export const input = { - point: Point.create({ - key: 'a', - path: [0, 0], - offset: 0, - }), - target: Point.create({ - key: 'b', - path: [0, 0, 1], - offset: 0, - }), -} - -export default function({ point, target }) { - return point.isBeforePoint(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-range/after-end-node.js b/packages/slate/test/models/point/is-before-range/after-end-node.js deleted file mode 100644 index d308aa8320..0000000000 --- a/packages/slate/test/models/point/is-before-range/after-end-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-range/after-end-offset.js b/packages/slate/test/models/point/is-before-range/after-end-offset.js deleted file mode 100644 index 85a23bfdcd..0000000000 --- a/packages/slate/test/models/point/is-before-range/after-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 12, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-range/after-start-offset.js b/packages/slate/test/models/point/is-before-range/after-start-offset.js deleted file mode 100644 index f8ec0fed87..0000000000 --- a/packages/slate/test/models/point/is-before-range/after-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-range/before-end-offset.js b/packages/slate/test/models/point/is-before-range/before-end-offset.js deleted file mode 100644 index 592b18b58d..0000000000 --- a/packages/slate/test/models/point/is-before-range/before-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-range/before-start-node.js b/packages/slate/test/models/point/is-before-range/before-start-node.js deleted file mode 100644 index b4c87cd443..0000000000 --- a/packages/slate/test/models/point/is-before-range/before-start-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [0], - offset: 7, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-before-range/before-start-offset.js b/packages/slate/test/models/point/is-before-range/before-start-offset.js deleted file mode 100644 index d21260ff2b..0000000000 --- a/packages/slate/test/models/point/is-before-range/before-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-before-range/between-nodes.js b/packages/slate/test/models/point/is-before-range/between-nodes.js deleted file mode 100644 index 32772f50cd..0000000000 --- a/packages/slate/test/models/point/is-before-range/between-nodes.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [5], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-range/is-end.js b/packages/slate/test/models/point/is-before-range/is-end.js deleted file mode 100644 index 4e698dff72..0000000000 --- a/packages/slate/test/models/point/is-before-range/is-end.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 3, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-before-range/is-start.js b/packages/slate/test/models/point/is-before-range/is-start.js deleted file mode 100644 index 9b78cdcc87..0000000000 --- a/packages/slate/test/models/point/is-before-range/is-start.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 0, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isBeforeRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-in-range/after-end-node.js b/packages/slate/test/models/point/is-in-range/after-end-node.js deleted file mode 100644 index 6c0184338b..0000000000 --- a/packages/slate/test/models/point/is-in-range/after-end-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-in-range/after-end-offset.js b/packages/slate/test/models/point/is-in-range/after-end-offset.js deleted file mode 100644 index 04fb0d73bf..0000000000 --- a/packages/slate/test/models/point/is-in-range/after-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 12, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-in-range/after-start-offset.js b/packages/slate/test/models/point/is-in-range/after-start-offset.js deleted file mode 100644 index 6a25bd811d..0000000000 --- a/packages/slate/test/models/point/is-in-range/after-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-in-range/before-end-offset.js b/packages/slate/test/models/point/is-in-range/before-end-offset.js deleted file mode 100644 index 114718f55a..0000000000 --- a/packages/slate/test/models/point/is-in-range/before-end-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-in-range/before-start-node.js b/packages/slate/test/models/point/is-in-range/before-start-node.js deleted file mode 100644 index 100d698436..0000000000 --- a/packages/slate/test/models/point/is-in-range/before-start-node.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [0], - offset: 7, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-in-range/before-start-offset.js b/packages/slate/test/models/point/is-in-range/before-start-offset.js deleted file mode 100644 index cf1bc34420..0000000000 --- a/packages/slate/test/models/point/is-in-range/before-start-offset.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 2, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 4, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = false diff --git a/packages/slate/test/models/point/is-in-range/between-nodes.js b/packages/slate/test/models/point/is-in-range/between-nodes.js deleted file mode 100644 index 8b5087d9ea..0000000000 --- a/packages/slate/test/models/point/is-in-range/between-nodes.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'a', - path: [4], - offset: 1, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [5], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-in-range/is-end.js b/packages/slate/test/models/point/is-in-range/is-end.js deleted file mode 100644 index db232e11ef..0000000000 --- a/packages/slate/test/models/point/is-in-range/is-end.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'c', - path: [2], - offset: 3, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/point/is-in-range/is-start.js b/packages/slate/test/models/point/is-in-range/is-start.js deleted file mode 100644 index b61a1c32d1..0000000000 --- a/packages/slate/test/models/point/is-in-range/is-start.js +++ /dev/null @@ -1,28 +0,0 @@ -import Point from '../../../../src/models/point' -import Range from '../../../../src/models/range' - -export const input = { - point: Point.create({ - key: 'b', - path: [1], - offset: 0, - }), - target: Range.create({ - anchor: { - key: 'b', - path: [1], - offset: 0, - }, - focus: { - key: 'c', - path: [2], - offset: 3, - }, - }), -} - -export default function({ point, target }) { - return point.isInRange(target) -} - -export const output = true diff --git a/packages/slate/test/models/text/delete/across-leaves/connectable-after-remove.js b/packages/slate/test/models/text/delete/across-leaves/connectable-after-remove.js deleted file mode 100644 index 95aba59f31..0000000000 --- a/packages/slate/test/models/text/delete/across-leaves/connectable-after-remove.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat isvery very Cute - -) - -export default function(t) { - return t.removeText(6, 9) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/delete/across-leaves/in-connectable-after-remove.js b/packages/slate/test/models/text/delete/across-leaves/in-connectable-after-remove.js deleted file mode 100644 index 1289789019..0000000000 --- a/packages/slate/test/models/text/delete/across-leaves/in-connectable-after-remove.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat isvery very Cute - -) - -export default function(t) { - return t.removeText(6, 9) -} - -export const output = ( - - Cat is - Cute - -) diff --git a/packages/slate/test/models/text/delete/all-text-length/differently-marked-text.js b/packages/slate/test/models/text/delete/all-text-length/differently-marked-text.js deleted file mode 100644 index 7cab363976..0000000000 --- a/packages/slate/test/models/text/delete/all-text-length/differently-marked-text.js +++ /dev/null @@ -1,15 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat is Cute - -) - -export default function(t) { - return t.removeText(0, t.text.length) -} - -export const output = diff --git a/packages/slate/test/models/text/delete/all-text-length/marked-text.js b/packages/slate/test/models/text/delete/all-text-length/marked-text.js deleted file mode 100644 index 57d12858de..0000000000 --- a/packages/slate/test/models/text/delete/all-text-length/marked-text.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat is Cute - -) - -export default function(t) { - return t.removeText(0, t.text.length) -} - -export const output = ( - - - -) diff --git a/packages/slate/test/models/text/delete/all-text-length/partial-marked-text.js b/packages/slate/test/models/text/delete/all-text-length/partial-marked-text.js deleted file mode 100644 index 4e718bc6d9..0000000000 --- a/packages/slate/test/models/text/delete/all-text-length/partial-marked-text.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - - Cat is Cute - - -) - -export default function(t) { - return t.removeText(0, t.text.length) -} - -export const output = ( - - - -) diff --git a/packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char-with-mark.js b/packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char-with-mark.js deleted file mode 100644 index 83eb32e36b..0000000000 --- a/packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char-with-mark.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat is Cute - -) - -export default function(t) { - return t.removeText(4, 1) -} - -export const output = ( - - Cat s Cute - -) diff --git a/packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char.js b/packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char.js deleted file mode 100644 index 01bf63bc3f..0000000000 --- a/packages/slate/test/models/text/delete/inside-a-leaf/delete-a-char.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Catt is Cute - -) - -export default function(t) { - return t.removeText(3, 1) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/insert/from-end/pure-text-after-marked-text.js b/packages/slate/test/models/text/insert/from-end/pure-text-after-marked-text.js deleted file mode 100644 index 0fec67b788..0000000000 --- a/packages/slate/test/models/text/insert/from-end/pure-text-after-marked-text.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat - Cute - -) - -export default function(t) { - return t.insertText(3, ' is') -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/insert/from-end/pure-text-after-pure-text.js b/packages/slate/test/models/text/insert/from-end/pure-text-after-pure-text.js deleted file mode 100644 index b32077f895..0000000000 --- a/packages/slate/test/models/text/insert/from-end/pure-text-after-pure-text.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat Cute - -) - -export default function(t) { - return t.insertText(3, ' is') -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/insert/from-end/pure-text-at-end-of-all-text.js b/packages/slate/test/models/text/insert/from-end/pure-text-at-end-of-all-text.js deleted file mode 100644 index f30431c876..0000000000 --- a/packages/slate/test/models/text/insert/from-end/pure-text-at-end-of-all-text.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - Cat is - -) - -export default function(t) { - return t.insertText(6, ' Cute') -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-marked-text.js b/packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-marked-text.js deleted file mode 100644 index dad93cdcc4..0000000000 --- a/packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-marked-text.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - CatCute - -) - -export default function(t) { - return t.insertText(3, ' is ', Set.of(Mark.create('bold'))) -} - -export const output = ( - - - Cat is Cute - - -) diff --git a/packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-pure-text.js b/packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-pure-text.js deleted file mode 100644 index 34f1a52a32..0000000000 --- a/packages/slate/test/models/text/insert/from-middle/marked-text-in-middle-of-pure-text.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = CatCute - -export default function(t) { - return t.insertText(3, ' is ', Set.of(Mark.create('bold'))) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/insert/from-middle/pure-text-into-middle-of-marks.js b/packages/slate/test/models/text/insert/from-middle/pure-text-into-middle-of-marks.js deleted file mode 100644 index 3b74d5cf21..0000000000 --- a/packages/slate/test/models/text/insert/from-middle/pure-text-into-middle-of-marks.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = ( - - CatCute - -) - -export default function(t) { - return t.insertText(3, ' is ') -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/insert/from-middle/pure-text.js b/packages/slate/test/models/text/insert/from-middle/pure-text.js deleted file mode 100644 index a95cf73dfe..0000000000 --- a/packages/slate/test/models/text/insert/from-middle/pure-text.js +++ /dev/null @@ -1,11 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = CatCute - -export default function(t) { - return t.insertText(3, ' is ') -} - -export const output = Cat is Cute diff --git a/packages/slate/test/models/text/insert/from-start/marked-text-on-null-text.js b/packages/slate/test/models/text/insert/from-start/marked-text-on-null-text.js deleted file mode 100644 index bf4c6d6f3a..0000000000 --- a/packages/slate/test/models/text/insert/from-start/marked-text-on-null-text.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { List } from 'immutable' -import { Mark } from 'slate' -import h from '../../../../helpers/h' - -export const input = ( - - - -) - -export default function(t) { - return t.insertText(0, 'Cat is Cute', List.of(Mark.create({ type: 'bold' }))) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/insert/from-start/pure-text-on-null-text-at-invalid-offset.js b/packages/slate/test/models/text/insert/from-start/pure-text-on-null-text-at-invalid-offset.js deleted file mode 100644 index 4316a00297..0000000000 --- a/packages/slate/test/models/text/insert/from-start/pure-text-on-null-text-at-invalid-offset.js +++ /dev/null @@ -1,11 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = - -export default function(t) { - return t.insertText(1, 'Cat is Cute') -} - -export const output = Cat is Cute diff --git a/packages/slate/test/models/text/insert/from-start/pure-text-on-null-text.js b/packages/slate/test/models/text/insert/from-start/pure-text-on-null-text.js deleted file mode 100644 index d4ff0dcccc..0000000000 --- a/packages/slate/test/models/text/insert/from-start/pure-text-on-null-text.js +++ /dev/null @@ -1,11 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = - -export default function(t) { - return t.insertText(0, 'Cat is Cute') -} - -export const output = Cat is Cute diff --git a/packages/slate/test/models/text/marks/add-marks/to-affect-nothing.js b/packages/slate/test/models/text/marks/add-marks/to-affect-nothing.js deleted file mode 100644 index 40782d04a6..0000000000 --- a/packages/slate/test/models/text/marks/add-marks/to-affect-nothing.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - Cat is Cute - -) - -export default function(t) { - return t.addMark(3, 4, Mark.create('bold')) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/marks/add-marks/to-cover-whole-text.js b/packages/slate/test/models/text/marks/add-marks/to-cover-whole-text.js deleted file mode 100644 index c84c4bb189..0000000000 --- a/packages/slate/test/models/text/marks/add-marks/to-cover-whole-text.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = Cat is Cute - -export default function(t) { - return t.addMark(0, t.text.length, Mark.create('italic')) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/marks/add-marks/to-merge-two-leaves.js b/packages/slate/test/models/text/marks/add-marks/to-merge-two-leaves.js deleted file mode 100644 index 7284fec6df..0000000000 --- a/packages/slate/test/models/text/marks/add-marks/to-merge-two-leaves.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - Cat is - Cute - -) - -export default function(t) { - return t.addMark(3, 3, Mark.create('bold')) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/marks/add-marks/to-split-leaves.js b/packages/slate/test/models/text/marks/add-marks/to-split-leaves.js deleted file mode 100644 index 748bb82aa2..0000000000 --- a/packages/slate/test/models/text/marks/add-marks/to-split-leaves.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - Cat i - s Cute - -) - -export default function(t) { - return t.addMark(3, 4, Mark.create('italic')) -} - -export const output = ( - - Cat i - - s - - Cute - -) diff --git a/packages/slate/test/models/text/marks/get-active-marks-between/marked-text-at-leaf-end.js b/packages/slate/test/models/text/marks/get-active-marks-between/marked-text-at-leaf-end.js deleted file mode 100644 index 8ddc570905..0000000000 --- a/packages/slate/test/models/text/marks/get-active-marks-between/marked-text-at-leaf-end.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - - Cat - is Cute - - -) - -export default function(t) { - return t.getActiveMarksBetweenOffsets(0, 6) -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-active-marks-between/marked-text-with-totally-different-marks.js b/packages/slate/test/models/text/marks/get-active-marks-between/marked-text-with-totally-different-marks.js deleted file mode 100644 index a89b2e1608..0000000000 --- a/packages/slate/test/models/text/marks/get-active-marks-between/marked-text-with-totally-different-marks.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' - -export const input = ( - - Cat - is Cute - -) - -export default function(t) { - return t.getActiveMarksBetweenOffsets(0, 6) -} - -export const output = Set() diff --git a/packages/slate/test/models/text/marks/get-active-marks-between/null-marked-text.js b/packages/slate/test/models/text/marks/get-active-marks-between/null-marked-text.js deleted file mode 100644 index 201bd15036..0000000000 --- a/packages/slate/test/models/text/marks/get-active-marks-between/null-marked-text.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - - -) - -export default function(t) { - return t.getActiveMarksBetweenOffsets(0, 0) -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-active-marks/adject-same-marks.js b/packages/slate/test/models/text/marks/get-active-marks/adject-same-marks.js deleted file mode 100644 index 05a0e036b1..0000000000 --- a/packages/slate/test/models/text/marks/get-active-marks/adject-same-marks.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - Cat is - Cute - - -) - -export default function(t) { - return t.getActiveMarks() -} - -export const output = Set.of(Mark.create('italic'), Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-active-marks/intersecting-marks-text.js b/packages/slate/test/models/text/marks/get-active-marks/intersecting-marks-text.js deleted file mode 100644 index 68098ca7c6..0000000000 --- a/packages/slate/test/models/text/marks/get-active-marks/intersecting-marks-text.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Set } from 'immutable' -import Mark from '../../../../../src/models/mark' - -export const input = ( - - - - b - - - - u - - g - -) - -export default function(t) { - return t.getActiveMarks() -} - -export const output = Set.of(Mark.create('italic')) diff --git a/packages/slate/test/models/text/marks/get-active-marks/marked-text.js b/packages/slate/test/models/text/marks/get-active-marks/marked-text.js deleted file mode 100644 index 10597169c6..0000000000 --- a/packages/slate/test/models/text/marks/get-active-marks/marked-text.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - - Cat is - Cute - - -) - -export default function(t) { - return t.getActiveMarks() -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-active-marks/partially-marked-text.js b/packages/slate/test/models/text/marks/get-active-marks/partially-marked-text.js deleted file mode 100644 index 26cb453a55..0000000000 --- a/packages/slate/test/models/text/marks/get-active-marks/partially-marked-text.js +++ /dev/null @@ -1,18 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Set } from 'immutable' - -export const input = ( - - Cat - is - Cute - -) - -export default function(t) { - return t.getActiveMarks() -} - -export const output = Set() diff --git a/packages/slate/test/models/text/marks/get-marks-at-index/null-marked-text.js b/packages/slate/test/models/text/marks/get-marks-at-index/null-marked-text.js deleted file mode 100644 index 8d589c3ef3..0000000000 --- a/packages/slate/test/models/text/marks/get-marks-at-index/null-marked-text.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - - -) - -export default function(t) { - return t.getMarksAtIndex(0) -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-marks-between/marked-text-with-leaf-end.js b/packages/slate/test/models/text/marks/get-marks-between/marked-text-with-leaf-end.js deleted file mode 100644 index 3a5930610c..0000000000 --- a/packages/slate/test/models/text/marks/get-marks-between/marked-text-with-leaf-end.js +++ /dev/null @@ -1,18 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - Cat - is Cute - -) - -export default function(t) { - return t.getMarksBetweenOffsets(0, 6) -} - -export const output = Set.of(Mark.create('bold'), Mark.create('italic')) diff --git a/packages/slate/test/models/text/marks/get-marks-between/marked-text-with-many-leaves.js b/packages/slate/test/models/text/marks/get-marks-between/marked-text-with-many-leaves.js deleted file mode 100644 index 07eee77952..0000000000 --- a/packages/slate/test/models/text/marks/get-marks-between/marked-text-with-many-leaves.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - Cat - is - Cat - is - Cat - is - Cat - is - Cat - -) - -export default function(t) { - return t.getMarksBetweenOffsets(0, 12) -} - -export const output = Set.of( - Mark.create({ type: 'bold', data: { x: 1 } }), - Mark.create({ type: 'italic', data: { x: 1 } }), - Mark.create({ type: 'bold', data: { x: 2 } }), - Mark.create({ type: 'italic', data: { x: 2 } }) -) diff --git a/packages/slate/test/models/text/marks/get-marks-between/null-marked-text.js b/packages/slate/test/models/text/marks/get-marks-between/null-marked-text.js deleted file mode 100644 index c82164dd7a..0000000000 --- a/packages/slate/test/models/text/marks/get-marks-between/null-marked-text.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - - -) - -export default function(t) { - return t.getMarksBetweenOffsets(0, 0) -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-marks/marked-text.js b/packages/slate/test/models/text/marks/get-marks/marked-text.js deleted file mode 100644 index ab822d523a..0000000000 --- a/packages/slate/test/models/text/marks/get-marks/marked-text.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Set } from 'immutable' -import { Mark } from 'slate' - -export const input = ( - - Cat - is - Cute - -) - -export default function(t) { - return t.getMarks() -} - -export const output = Set.of(Mark.create('italic'), Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-marks/null-text-with-marks.js b/packages/slate/test/models/text/marks/get-marks/null-text-with-marks.js deleted file mode 100644 index 8c50690ded..0000000000 --- a/packages/slate/test/models/text/marks/get-marks/null-text-with-marks.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - - -) - -export default function(t) { - return t.getMarks() -} - -export const output = Set.of(Mark.create('bold')) diff --git a/packages/slate/test/models/text/marks/get-marks/null-text.js b/packages/slate/test/models/text/marks/get-marks/null-text.js deleted file mode 100644 index 4ae383d2b2..0000000000 --- a/packages/slate/test/models/text/marks/get-marks/null-text.js +++ /dev/null @@ -1,12 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Set } from 'immutable' - -export const input = - -export default function(t) { - return t.getMarks() -} - -export const output = Set() diff --git a/packages/slate/test/models/text/marks/get-marks/partially-marked-text.js b/packages/slate/test/models/text/marks/get-marks/partially-marked-text.js deleted file mode 100644 index fa5cd0945b..0000000000 --- a/packages/slate/test/models/text/marks/get-marks/partially-marked-text.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import { Set } from 'immutable' -import h from '../../../../helpers/h' -import { Mark } from 'slate' - -export const input = ( - - Cat - is - Cute - -) - -export default function(t) { - return t.getMarks() -} - -export const output = Set.of(Mark.create('italic')) diff --git a/packages/slate/test/models/text/marks/get-marks/plain-text.js b/packages/slate/test/models/text/marks/get-marks/plain-text.js deleted file mode 100644 index 44470fd635..0000000000 --- a/packages/slate/test/models/text/marks/get-marks/plain-text.js +++ /dev/null @@ -1,12 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' -import { Set } from 'immutable' - -export const input = Cat is Cute - -export default function(t) { - return t.getMarks() -} - -export const output = Set() diff --git a/packages/slate/test/models/text/marks/remove-mark/remove-mark.js b/packages/slate/test/models/text/marks/remove-mark/remove-mark.js deleted file mode 100644 index 334c279615..0000000000 --- a/packages/slate/test/models/text/marks/remove-mark/remove-mark.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { Mark } from 'slate' -import h from '../../../../helpers/h' - -export const input = ( - - Cat is Cute - -) - -export default function(t) { - return t.removeMark(0, 3, Mark.create('bold')) -} - -export const output = ( - - Cat is Cute - -) diff --git a/packages/slate/test/models/text/marks/update-mark/marked-text-with-some-other-marks.js b/packages/slate/test/models/text/marks/update-mark/marked-text-with-some-other-marks.js deleted file mode 100644 index 4d6ab4c036..0000000000 --- a/packages/slate/test/models/text/marks/update-mark/marked-text-with-some-other-marks.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import { Mark } from 'slate' -import h from '../../../../helpers/h' - -export const input = ( - - Cat - is Cute - -) - -export default function(t) { - return t.updateMark(0, 6, Mark.create('bold'), { data: { x: 1 } }) -} - -export const output = ( - - Cat - is Cute - -) diff --git a/packages/slate/test/models/text/marks/update-mark/marked-text.js b/packages/slate/test/models/text/marks/update-mark/marked-text.js deleted file mode 100644 index c772dbe128..0000000000 --- a/packages/slate/test/models/text/marks/update-mark/marked-text.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { Mark } from 'slate' -import h from '../../../../helpers/h' - -export const input = ( - - Cat is Cute - -) - -export default function(t) { - return t.updateMark(0, 3, Mark.create('bold'), { data: { x: 1 } }) -} - -export const output = ( - - Cat - is Cute - -) diff --git a/packages/slate/test/models/text/marks/update-mark/null-mark-with-invalid-offset.js b/packages/slate/test/models/text/marks/update-mark/null-mark-with-invalid-offset.js deleted file mode 100644 index 15d1a2d44f..0000000000 --- a/packages/slate/test/models/text/marks/update-mark/null-mark-with-invalid-offset.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @jsx h */ - -import { Mark } from 'slate' -import h from '../../../../helpers/h' - -export const input = ( - - - -) - -export default function(t) { - return t.updateMark(0, 1, Mark.create('bold'), { data: { x: 1 } }) -} - -export const output = input diff --git a/packages/slate/test/models/text/marks/update-mark/null-marked-text.js b/packages/slate/test/models/text/marks/update-mark/null-marked-text.js deleted file mode 100644 index 3efb2fc8a9..0000000000 --- a/packages/slate/test/models/text/marks/update-mark/null-marked-text.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { Mark } from 'slate' -import h from '../../../../helpers/h' - -export const input = ( - - - -) - -export default function(t) { - return t.updateMark(0, 0, Mark.create('bold'), { data: { x: 1 } }) -} - -export const output = ( - - - -) diff --git a/packages/slate/test/models/text/merge/empty-leaf-as-next/length-text.js b/packages/slate/test/models/text/merge/empty-leaf-as-next/length-text.js deleted file mode 100644 index 8e52a6edcd..0000000000 --- a/packages/slate/test/models/text/merge/empty-leaf-as-next/length-text.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = { - a: ( - - Some - - ), - b: , -} - -export default function({ a, b }) { - return a.mergeText(b) -} - -export const output = ( - - Some - -) diff --git a/packages/slate/test/models/text/merge/empty-leaf-as-start/another-empty-text.js b/packages/slate/test/models/text/merge/empty-leaf-as-start/another-empty-text.js deleted file mode 100644 index d1181aaa05..0000000000 --- a/packages/slate/test/models/text/merge/empty-leaf-as-start/another-empty-text.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = { - a: ( - - - - ), - b: , -} - -export default function({ a, b }) { - return a.mergeText(b) -} - -export const output = ( - - - -) diff --git a/packages/slate/test/models/text/merge/empty-leaf-as-start/length-text.js b/packages/slate/test/models/text/merge/empty-leaf-as-start/length-text.js deleted file mode 100644 index 12758c96dc..0000000000 --- a/packages/slate/test/models/text/merge/empty-leaf-as-start/length-text.js +++ /dev/null @@ -1,18 +0,0 @@ -/** @jsx h */ - -import h from '../../../../helpers/h' - -export const input = { - a: ( - - - - ), - b: Some, -} - -export default function({ a, b }) { - return a.mergeText(b) -} - -export const output = Some diff --git a/packages/slate/test/serializers/raw/deserialize/block-nested.js b/packages/slate/test/serializers/raw/deserialize/block-nested.js deleted file mode 100644 index deb5f6e947..0000000000 --- a/packages/slate/test/serializers/raw/deserialize/block-nested.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'quote', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} - -export const output = ( - - - - one - - - -) diff --git a/packages/slate/test/serializers/raw/deserialize/block-with-data.js b/packages/slate/test/serializers/raw/deserialize/block-with-data.js deleted file mode 100644 index 454f8eed1b..0000000000 --- a/packages/slate/test/serializers/raw/deserialize/block-with-data.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: { - thing: 'value', - }, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, -} - -export const output = ( - - - one - - -) diff --git a/packages/slate/test/serializers/raw/deserialize/block.js b/packages/slate/test/serializers/raw/deserialize/block.js deleted file mode 100644 index 1d3b2f6767..0000000000 --- a/packages/slate/test/serializers/raw/deserialize/block.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, -} - -export const output = ( - - - one - - -) diff --git a/packages/slate/test/serializers/raw/deserialize/inline-nested.js b/packages/slate/test/serializers/raw/deserialize/inline-nested.js deleted file mode 100644 index be968129df..0000000000 --- a/packages/slate/test/serializers/raw/deserialize/inline-nested.js +++ /dev/null @@ -1,75 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'hashtag', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - ], - }, -} - -export const output = ( - - - - - - - one - - - - - - -) diff --git a/packages/slate/test/serializers/raw/deserialize/inline-with-data.js b/packages/slate/test/serializers/raw/deserialize/inline-with-data.js deleted file mode 100644 index 3859b01105..0000000000 --- a/packages/slate/test/serializers/raw/deserialize/inline-with-data.js +++ /dev/null @@ -1,56 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'link', - data: { - thing: 'value', - }, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - ], - }, -} - -export const output = ( - - - - - one - - - - -) diff --git a/packages/slate/test/serializers/raw/deserialize/inline.js b/packages/slate/test/serializers/raw/deserialize/inline.js deleted file mode 100644 index dfef10b315..0000000000 --- a/packages/slate/test/serializers/raw/deserialize/inline.js +++ /dev/null @@ -1,54 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - ], - }, -} - -export const output = ( - - - - - one - - - - -) diff --git a/packages/slate/test/serializers/raw/deserialize/range-with-mark.js b/packages/slate/test/serializers/raw/deserialize/range-with-mark.js deleted file mode 100644 index 7c7d0b9460..0000000000 --- a/packages/slate/test/serializers/raw/deserialize/range-with-mark.js +++ /dev/null @@ -1,51 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'o', - marks: [], - }, - { - object: 'text', - text: 'n', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - text: 'e', - marks: [], - }, - ], - }, - ], - }, -} - -export const output = ( - - - - one - - - -) diff --git a/packages/slate/test/serializers/raw/serialize/block-nested.js b/packages/slate/test/serializers/raw/serialize/block-nested.js deleted file mode 100644 index 0e5535c08a..0000000000 --- a/packages/slate/test/serializers/raw/serialize/block-nested.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'quote', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - ], - }, -} diff --git a/packages/slate/test/serializers/raw/serialize/block-with-data.js b/packages/slate/test/serializers/raw/serialize/block-with-data.js deleted file mode 100644 index d069d8a142..0000000000 --- a/packages/slate/test/serializers/raw/serialize/block-with-data.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: { - thing: 'value', - }, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, -} diff --git a/packages/slate/test/serializers/raw/serialize/block.js b/packages/slate/test/serializers/raw/serialize/block.js deleted file mode 100644 index 4259df1361..0000000000 --- a/packages/slate/test/serializers/raw/serialize/block.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, -} diff --git a/packages/slate/test/serializers/raw/serialize/inline-nested.js b/packages/slate/test/serializers/raw/serialize/inline-nested.js deleted file mode 100644 index dec446d2d0..0000000000 --- a/packages/slate/test/serializers/raw/serialize/inline-nested.js +++ /dev/null @@ -1,75 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - - - one - - - - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'hashtag', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - ], - }, -} diff --git a/packages/slate/test/serializers/raw/serialize/inline-with-data.js b/packages/slate/test/serializers/raw/serialize/inline-with-data.js deleted file mode 100644 index c6d6a25be4..0000000000 --- a/packages/slate/test/serializers/raw/serialize/inline-with-data.js +++ /dev/null @@ -1,56 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - one - - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'link', - data: { - thing: 'value', - }, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - ], - }, -} diff --git a/packages/slate/test/serializers/raw/serialize/inline.js b/packages/slate/test/serializers/raw/serialize/inline.js deleted file mode 100644 index 403e0379a9..0000000000 --- a/packages/slate/test/serializers/raw/serialize/inline.js +++ /dev/null @@ -1,54 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - - one - - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: '', - marks: [], - }, - { - object: 'inline', - type: 'link', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - { - object: 'text', - text: '', - marks: [], - }, - ], - }, - ], - }, -} diff --git a/packages/slate/test/serializers/raw/serialize/preserve-data.js b/packages/slate/test/serializers/raw/serialize/preserve-data.js deleted file mode 100644 index ad4805c3ef..0000000000 --- a/packages/slate/test/serializers/raw/serialize/preserve-data.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - -) - -export const output = { - object: 'value', - data: {}, - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, -} - -export const options = { - preserveData: true, -} diff --git a/packages/slate/test/serializers/raw/serialize/preserve-keys.js b/packages/slate/test/serializers/raw/serialize/preserve-keys.js deleted file mode 100644 index 2a9bef3742..0000000000 --- a/packages/slate/test/serializers/raw/serialize/preserve-keys.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const skip = true - -export const input = ( - - - one - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - key: '3', - data: {}, - nodes: [ - { - object: 'block', - key: '1', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, -} - -export const options = { - preserveKeys: true, -} diff --git a/packages/slate/test/serializers/raw/serialize/preserve-selection-and-keys.js b/packages/slate/test/serializers/raw/serialize/preserve-selection-and-keys.js deleted file mode 100644 index 968bcb03a1..0000000000 --- a/packages/slate/test/serializers/raw/serialize/preserve-selection-and-keys.js +++ /dev/null @@ -1,60 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const skip = true - -export const input = ( - - - one - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - key: '3', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - key: '1', - data: {}, - nodes: [ - { - object: 'text', - key: '0', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - key: '0', - path: [0, 0], - offset: 0, - }, - isFocused: false, - marks: null, - }, -} - -export const options = { - preserveKeys: true, - preserveSelection: true, -} diff --git a/packages/slate/test/serializers/raw/serialize/preserve-selection.js b/packages/slate/test/serializers/raw/serialize/preserve-selection.js deleted file mode 100644 index 5c06a7ddb5..0000000000 --- a/packages/slate/test/serializers/raw/serialize/preserve-selection.js +++ /dev/null @@ -1,52 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - one - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'one', - marks: [], - }, - ], - }, - ], - }, - selection: { - object: 'selection', - anchor: { - object: 'point', - path: [0, 0], - offset: 0, - }, - focus: { - object: 'point', - path: [0, 0], - offset: 0, - }, - isFocused: false, - marks: null, - }, -} - -export const options = { - preserveSelection: true, -} diff --git a/packages/slate/test/serializers/raw/serialize/range-with-mark.js b/packages/slate/test/serializers/raw/serialize/range-with-mark.js deleted file mode 100644 index e50612818b..0000000000 --- a/packages/slate/test/serializers/raw/serialize/range-with-mark.js +++ /dev/null @@ -1,51 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export const input = ( - - - - one - - - -) - -export const output = { - object: 'value', - document: { - object: 'document', - data: {}, - nodes: [ - { - object: 'block', - type: 'paragraph', - data: {}, - nodes: [ - { - object: 'text', - text: 'o', - marks: [], - }, - { - object: 'text', - text: 'n', - marks: [ - { - object: 'mark', - type: 'bold', - data: {}, - }, - ], - }, - { - object: 'text', - text: 'e', - marks: [], - }, - ], - }, - ], - }, -} diff --git a/packages/slate/test/utils/path-utils/transform/move-node/from-before-not-younger.js b/packages/slate/test/utils/path-utils/transform/move-node/from-before-not-younger.js deleted file mode 100644 index 295ee85143..0000000000 --- a/packages/slate/test/utils/path-utils/transform/move-node/from-before-not-younger.js +++ /dev/null @@ -1,30 +0,0 @@ -import assert from 'assert' -import { PathUtils, Operation } from 'slate' - -const assertEqualPaths = (p1, p2) => - assert.deepEqual(p1.toArray(), p2.toArray()) - -export default () => { - const path = PathUtils.create([0, 1, 0, 1]) - const newPath = PathUtils.create([0, 1, 1, 0, 1]) - const op = Operation.create({ path, newPath, type: 'move_node' }) - - const result_eq = PathUtils.transform(path, op).first() - assertEqualPaths(result_eq, newPath) - - const before_old = PathUtils.create([0, 1, 0, 0]) - const result_before_old = PathUtils.transform(before_old, op).first() - assertEqualPaths(result_before_old, before_old) - - const after_old = PathUtils.create([0, 1, 0, 2]) - const result_after_old = PathUtils.transform(after_old, op).first() - assertEqualPaths(result_after_old, PathUtils.decrement(after_old)) - - const before_new = PathUtils.create([0, 1, 1, 0, 0]) - const result_before_new = PathUtils.transform(before_new, op).first() - assertEqualPaths(result_before_new, before_new) - - const after_new = PathUtils.create([0, 1, 1, 0, 2]) - const result_after_new = PathUtils.transform(after_new, op).first() - assertEqualPaths(result_after_new, PathUtils.increment(after_new)) -} diff --git a/packages/slate/test/utils/path-utils/transform/move-node/from-younger.js b/packages/slate/test/utils/path-utils/transform/move-node/from-younger.js deleted file mode 100644 index 3a5ce45bab..0000000000 --- a/packages/slate/test/utils/path-utils/transform/move-node/from-younger.js +++ /dev/null @@ -1,30 +0,0 @@ -import assert from 'assert' -import { PathUtils, Operation } from 'slate' - -const assertEqualPaths = (p1, p2) => - assert.deepEqual(p1.toArray(), p2.toArray()) - -export default () => { - const path = PathUtils.create([0, 1, 1]) - const newPath = PathUtils.create([0, 1, 2, 0, 1]) - const op = Operation.create({ path, newPath, type: 'move_node' }) - - const result_eq = PathUtils.transform(path, op).first() - assertEqualPaths(result_eq, PathUtils.create([0, 1, 1, 0, 1])) - - const before_old = PathUtils.create([0, 1, 0]) - const result_before_old = PathUtils.transform(before_old, op).first() - assertEqualPaths(result_before_old, before_old) - - const after_old = PathUtils.create([0, 1, 2]) - const result_after_old = PathUtils.transform(after_old, op).first() - assertEqualPaths(result_after_old, PathUtils.decrement(after_old)) - - const before_new = PathUtils.create([0, 1, 2, 0, 0]) - const result_before_new = PathUtils.transform(before_new, op).first() - assertEqualPaths(result_before_new, PathUtils.create([0, 1, 1, 0, 0])) - - const after_new = PathUtils.create([0, 1, 2, 0, 2]) - const result_after_new = PathUtils.transform(after_new, op).first() - assertEqualPaths(result_after_new, PathUtils.create([0, 1, 1, 0, 2])) -} diff --git a/packages/slate/test/utils/path-utils/transform/move-node/siblings-backward.js b/packages/slate/test/utils/path-utils/transform/move-node/siblings-backward.js deleted file mode 100644 index 1ec6eab5bb..0000000000 --- a/packages/slate/test/utils/path-utils/transform/move-node/siblings-backward.js +++ /dev/null @@ -1,17 +0,0 @@ -import assert from 'assert' -import { PathUtils, Operation } from 'slate' - -const assertEqualPaths = (p1, p2) => - assert.deepEqual(p1.toArray(), p2.toArray()) - -export default () => { - const path = PathUtils.create([1]) - const newPath = PathUtils.create([0]) - const op = Operation.create({ path, newPath, type: 'move_node' }) - - const moved_node_result = PathUtils.transform(path, op).first() - assertEqualPaths(moved_node_result, newPath) - - const sibling_result = PathUtils.transform(newPath, op).first() - assertEqualPaths(sibling_result, path) -} diff --git a/packages/slate/test/utils/path-utils/transform/move-node/siblings-forward.js b/packages/slate/test/utils/path-utils/transform/move-node/siblings-forward.js deleted file mode 100644 index 69f5e4600c..0000000000 --- a/packages/slate/test/utils/path-utils/transform/move-node/siblings-forward.js +++ /dev/null @@ -1,17 +0,0 @@ -import assert from 'assert' -import { PathUtils, Operation } from 'slate' - -const assertEqualPaths = (p1, p2) => - assert.deepEqual(p1.toArray(), p2.toArray()) - -export default () => { - const path = PathUtils.create([0]) - const newPath = PathUtils.create([1]) - const op = Operation.create({ path, newPath, type: 'move_node' }) - - const moved_node_result = PathUtils.transform(path, op).first() - assertEqualPaths(moved_node_result, newPath) - - const sibling_result = PathUtils.transform(newPath, op).first() - assertEqualPaths(sibling_result, path) -} diff --git a/packages/slate/tsconfig.json b/packages/slate/tsconfig.json new file mode 100644 index 0000000000..4463c7357c --- /dev/null +++ b/packages/slate/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../config/typescript/tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib", + "composite": true + }, + "references": [] +} diff --git a/support/benchmark/compare.js b/support/benchmark/compare.js deleted file mode 100644 index efe7215c05..0000000000 --- a/support/benchmark/compare.js +++ /dev/null @@ -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() diff --git a/packages/slate-dev-test-utils/src/index.js b/support/fixtures.js similarity index 85% rename from packages/slate-dev-test-utils/src/index.js rename to support/fixtures.js index 05b033e503..3613bcee03 100644 --- a/packages/slate-dev-test-utils/src/index.js +++ b/support/fixtures.js @@ -1,6 +1,5 @@ import fs from 'fs' import { basename, extname, resolve } from 'path' -import { KeyUtils } from 'slate' export const fixtures = (...args) => { let fn = args.pop() @@ -37,9 +36,6 @@ export const fixtures = (...args) => { // This needs to be a non-arrow function to use `this.skip()`. it(name, function() { - // Ensure that the key generator is reset. We have to do this here - // because the `require` call will create the Slate objects. - KeyUtils.resetGenerator() const module = require(p) if (module.skip) { diff --git a/support/rollup/config.js b/support/rollup/config.js deleted file mode 100644 index e339e4d2b8..0000000000 --- a/support/rollup/config.js +++ /dev/null @@ -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 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..607f062545 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "./config/typescript/tsconfig.json", + "references": [{ "path": "./packages/slate" }], + "files": [], + "typedocOptions": { + "excludeExternals": true, + "hideGenerator": true, + "mode": "file", + "name": "Slate API Reference", + "out": "./site", + "readme": null + } +} diff --git a/yarn.lock b/yarn.lock index fd919390cb..1385117e08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,23 @@ # yarn lockfile v1 +"@babel/cli@^7.6.4": + version "7.6.4" + resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.6.4.tgz#9b35a4e15fa7d8f487418aaa8229c8b0bc815f20" + integrity sha512-tqrDyvPryBM6xjIyKKUwr3s8CzmmYidwgdswd7Uc/Cv0ogZcuS1TYQTLx/eWKP3UbJ6JxZAiYlBZabXm/rtRsQ== + dependencies: + commander "^2.8.1" + convert-source-map "^1.1.0" + fs-readdir-recursive "^1.1.0" + glob "^7.0.0" + lodash "^4.17.13" + mkdirp "^0.5.1" + output-file-sync "^2.0.0" + slash "^2.0.0" + source-map "^0.5.0" + optionalDependencies: + chokidar "^2.1.8" + "@babel/code-frame@7.0.0-beta.36": version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.36.tgz#2349d7ec04b3a06945ae173280ef8579b63728e4" @@ -10,6 +27,104 @@ esutils "^2.0.2" js-tokens "^3.0.0" +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d" + integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw== + dependencies: + "@babel/highlight" "^7.0.0" + +"@babel/core@^7.6.4": + version "7.6.4" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.6.4.tgz#6ebd9fe00925f6c3e177bb726a188b5f578088ff" + integrity sha512-Rm0HGw101GY8FTzpWSyRbki/jzq+/PkNQJ+nSulrdY6gFGOsNseCqD6KHRYe2E+EdzuBdr2pxCp6s4Uk6eJ+XQ== + dependencies: + "@babel/code-frame" "^7.5.5" + "@babel/generator" "^7.6.4" + "@babel/helpers" "^7.6.2" + "@babel/parser" "^7.6.4" + "@babel/template" "^7.6.0" + "@babel/traverse" "^7.6.3" + "@babel/types" "^7.6.3" + convert-source-map "^1.1.0" + debug "^4.1.0" + json5 "^2.1.0" + lodash "^4.17.13" + resolve "^1.3.2" + semver "^5.4.1" + source-map "^0.5.0" + +"@babel/generator@^7.6.3", "@babel/generator@^7.6.4": + version "7.6.4" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.6.4.tgz#a4f8437287bf9671b07f483b76e3bb731bc97671" + integrity sha512-jsBuXkFoZxk0yWLyGI9llT9oiQ2FeTASmRFE32U+aaDTfoE92t78eroO7PTpU/OrYq38hlcDM6vbfLDaOLy+7w== + dependencies: + "@babel/types" "^7.6.3" + jsesc "^2.5.1" + lodash "^4.17.13" + source-map "^0.5.0" + +"@babel/helper-annotate-as-pure@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32" + integrity sha512-3UYcJUj9kvSLbLbUIfQTqzcy5VX7GRZ/CCDrnOaZorFFM01aXp1+GJwuFGV4NDDoAS+mOUyHcO6UD/RfqOks3Q== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-builder-binary-assignment-operator-visitor@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.1.0.tgz#6b69628dfe4087798e0c4ed98e3d4a6b2fbd2f5f" + integrity sha512-qNSR4jrmJ8M1VMM9tibvyRAHXQs2PmaksQF7c1CGJNipfe3D8p+wgNwgso/P2A2r2mdgBWAXljNWR0QRZAMW8w== + dependencies: + "@babel/helper-explode-assignable-expression" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-builder-react-jsx@^7.3.0": + version "7.3.0" + resolved "https://registry.yarnpkg.com/@babel/helper-builder-react-jsx/-/helper-builder-react-jsx-7.3.0.tgz#a1ac95a5d2b3e88ae5e54846bf462eeb81b318a4" + integrity sha512-MjA9KgwCuPEkQd9ncSXvSyJ5y+j2sICHyrI0M3L+6fnS4wMSNDc1ARXsbTfbb2cXHn17VisSnU/sHFTCxVxSMw== + dependencies: + "@babel/types" "^7.3.0" + esutils "^2.0.0" + +"@babel/helper-call-delegate@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/helper-call-delegate/-/helper-call-delegate-7.4.4.tgz#87c1f8ca19ad552a736a7a27b1c1fcf8b1ff1f43" + integrity sha512-l79boDFJ8S1c5hvQvG+rc+wHw6IuH7YldmRKsYtpbawsxURu/paVy57FZMomGK22/JckepaikOkY0MoAmdyOlQ== + dependencies: + "@babel/helper-hoist-variables" "^7.4.4" + "@babel/traverse" "^7.4.4" + "@babel/types" "^7.4.4" + +"@babel/helper-create-class-features-plugin@^7.5.5", "@babel/helper-create-class-features-plugin@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.6.0.tgz#769711acca889be371e9bc2eb68641d55218021f" + integrity sha512-O1QWBko4fzGju6VoVvrZg0RROCVifcLxiApnGP3OWfWzvxRZFCoBD81K5ur5e3bVY2Vf/5rIJm8cqPKn8HUJng== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-member-expression-to-functions" "^7.5.5" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.5.5" + "@babel/helper-split-export-declaration" "^7.4.4" + +"@babel/helper-define-map@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/helper-define-map/-/helper-define-map-7.5.5.tgz#3dec32c2046f37e09b28c93eb0b103fd2a25d369" + integrity sha512-fTfxx7i0B5NJqvUOBBGREnrqbTxRh7zinBANpZXAVDlsZxYdclDp467G1sQ8VZYMnAURY3RpBUAgOYT9GfzHBg== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/types" "^7.5.5" + lodash "^4.17.13" + +"@babel/helper-explode-assignable-expression@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.1.0.tgz#537fa13f6f1674df745b0c00ec8fe4e99681c8f6" + integrity sha512-NRQpfHrJ1msCHtKjbzs9YcMmJZOg6mQMmGRB+hbamEdG5PNpaSm95275VD92DvJKuyl0s2sFiDmMZ+EnnvufqA== + dependencies: + "@babel/traverse" "^7.1.0" + "@babel/types" "^7.0.0" + "@babel/helper-function-name@7.0.0-beta.36": version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.36.tgz#366e3bc35147721b69009f803907c4d53212e88d" @@ -18,12 +133,42 @@ "@babel/template" "7.0.0-beta.36" "@babel/types" "7.0.0-beta.36" +"@babel/helper-function-name@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.1.0.tgz#a0ceb01685f73355d4360c1247f582bfafc8ff53" + integrity sha512-A95XEoCpb3TO+KZzJ4S/5uW5fNe26DjBGqf1o9ucyLyCmi1dXq/B3c8iaWTfBk3VvetUxl16e8tIrd5teOCfGw== + dependencies: + "@babel/helper-get-function-arity" "^7.0.0" + "@babel/template" "^7.1.0" + "@babel/types" "^7.0.0" + "@babel/helper-get-function-arity@7.0.0-beta.36": version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.36.tgz#f5383bac9a96b274828b10d98900e84ee43e32b8" dependencies: "@babel/types" "7.0.0-beta.36" +"@babel/helper-get-function-arity@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3" + integrity sha512-r2DbJeg4svYvt3HOS74U4eWKsUAMRH01Z1ds1zx8KNTPtpTL5JAsdFv8BNyOpVqdFhHkkRDIg5B4AsxmkjAlmQ== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-hoist-variables@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.4.4.tgz#0298b5f25c8c09c53102d52ac4a98f773eb2850a" + integrity sha512-VYk2/H/BnYbZDDg39hr3t2kKyifAm1W6zHRfhx8jGjIHpQEBv9dry7oQ2f3+J703TLu69nYdxsovl0XYfcnK4w== + dependencies: + "@babel/types" "^7.4.4" + +"@babel/helper-member-expression-to-functions@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.5.5.tgz#1fb5b8ec4453a93c439ee9fe3aeea4a84b76b590" + integrity sha512-5qZ3D1uMclSNqYcXqiHoA0meVdv+xUEex9em2fqMnrk/scphGlGgg66zjMrPJESPwrFJ6sbfFQYUSa0Mz7FabA== + dependencies: + "@babel/types" "^7.5.5" + "@babel/helper-module-imports@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d" @@ -31,6 +176,618 @@ dependencies: "@babel/types" "^7.0.0" +"@babel/helper-module-transforms@^7.1.0", "@babel/helper-module-transforms@^7.4.4": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.5.5.tgz#f84ff8a09038dcbca1fd4355661a500937165b4a" + integrity sha512-jBeCvETKuJqeiaCdyaheF40aXnnU1+wkSiUs/IQg3tB85up1LyL8x77ClY8qJpuRJUcXQo+ZtdNESmZl4j56Pw== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-simple-access" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.4.4" + "@babel/template" "^7.4.4" + "@babel/types" "^7.5.5" + lodash "^4.17.13" + +"@babel/helper-optimise-call-expression@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.0.0.tgz#a2920c5702b073c15de51106200aa8cad20497d5" + integrity sha512-u8nd9NQePYNQV8iPWu/pLLYBqZBa4ZaY1YWRFMuxrid94wKI1QNt67NEZ7GAe5Kc/0LLScbim05xZFWkAdrj9g== + dependencies: + "@babel/types" "^7.0.0" + +"@babel/helper-plugin-utils@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" + integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== + +"@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.5.5.tgz#0aa6824f7100a2e0e89c1527c23936c152cab351" + integrity sha512-CkCYQLkfkiugbRDO8eZn6lRuR8kzZoGXCg3149iTk5se7g6qykSpy3+hELSwquhu+TgHn8nkLiBwHvNX8Hofcw== + dependencies: + lodash "^4.17.13" + +"@babel/helper-remap-async-to-generator@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.1.0.tgz#361d80821b6f38da75bd3f0785ece20a88c5fe7f" + integrity sha512-3fOK0L+Fdlg8S5al8u/hWE6vhufGSn0bN09xm2LXMy//REAF8kDCrYoOBKYmA8m5Nom+sV9LyLCwrFynA8/slg== + dependencies: + "@babel/helper-annotate-as-pure" "^7.0.0" + "@babel/helper-wrap-function" "^7.1.0" + "@babel/template" "^7.1.0" + "@babel/traverse" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-replace-supers@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.5.5.tgz#f84ce43df031222d2bad068d2626cb5799c34bc2" + integrity sha512-XvRFWrNnlsow2u7jXDuH4jDDctkxbS7gXssrP4q2nUD606ukXHRvydj346wmNg+zAgpFx4MWf4+usfC93bElJg== + dependencies: + "@babel/helper-member-expression-to-functions" "^7.5.5" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/traverse" "^7.5.5" + "@babel/types" "^7.5.5" + +"@babel/helper-simple-access@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.1.0.tgz#65eeb954c8c245beaa4e859da6188f39d71e585c" + integrity sha512-Vk+78hNjRbsiu49zAPALxTb+JUQCz1aolpd8osOF16BGnLtseD21nbHgLPGUwrXEurZgiCOUmvs3ExTu4F5x6w== + dependencies: + "@babel/template" "^7.1.0" + "@babel/types" "^7.0.0" + +"@babel/helper-split-export-declaration@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz#ff94894a340be78f53f06af038b205c49d993677" + integrity sha512-Ro/XkzLf3JFITkW6b+hNxzZ1n5OQ80NvIUdmHspih1XAhtN3vPTuUFT4eQnela+2MaZ5ulH+iyP513KJrxbN7Q== + dependencies: + "@babel/types" "^7.4.4" + +"@babel/helper-wrap-function@^7.1.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.2.0.tgz#c4e0012445769e2815b55296ead43a958549f6fa" + integrity sha512-o9fP1BZLLSrYlxYEYyl2aS+Flun5gtjTIG8iln+XuEzQTs0PLagAGSXUcqruJwD5fM48jzIEggCKpIfWTcR7pQ== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/template" "^7.1.0" + "@babel/traverse" "^7.1.0" + "@babel/types" "^7.2.0" + +"@babel/helpers@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.6.2.tgz#681ffe489ea4dcc55f23ce469e58e59c1c045153" + integrity sha512-3/bAUL8zZxYs1cdX2ilEE0WobqbCmKWr/889lf2SS0PpDcpEIY8pb1CCyz0pEcX3pEb+MCbks1jIokz2xLtGTA== + dependencies: + "@babel/template" "^7.6.0" + "@babel/traverse" "^7.6.2" + "@babel/types" "^7.6.0" + +"@babel/highlight@^7.0.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.5.0.tgz#56d11312bd9248fa619591d02472be6e8cb32540" + integrity sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ== + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^4.0.0" + +"@babel/parser@^7.6.0", "@babel/parser@^7.6.3", "@babel/parser@^7.6.4": + version "7.6.4" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.4.tgz#cb9b36a7482110282d5cb6dd424ec9262b473d81" + integrity sha512-D8RHPW5qd0Vbyo3qb+YjO5nvUVRTXFLQ/FsDxJU2Nqz4uB5EnUN0ZQSEYpvTIbRuttig1XbHWU5oMeQwQSAA+A== + +"@babel/plugin-external-helpers@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-external-helpers/-/plugin-external-helpers-7.2.0.tgz#7f4cb7dee651cd380d2034847d914288467a6be4" + integrity sha512-QFmtcCShFkyAsNtdCM3lJPmRe1iB+vPZymlB4LnDIKEBj2yKQLQKtoxXxJ8ePT5fwMl4QGg303p4mB0UsSI2/g== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-proposal-async-generator-functions@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.2.0.tgz#b289b306669dce4ad20b0252889a15768c9d417e" + integrity sha512-+Dfo/SCQqrwx48ptLVGLdE39YtWRuKc/Y9I5Fy0P1DDBB9lsAHpjcEJQt+4IifuSOSTLBKJObJqMvaO1pIE8LQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-remap-async-to-generator" "^7.1.0" + "@babel/plugin-syntax-async-generators" "^7.2.0" + +"@babel/plugin-proposal-class-properties@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.5.5.tgz#a974cfae1e37c3110e71f3c6a2e48b8e71958cd4" + integrity sha512-AF79FsnWFxjlaosgdi421vmYG6/jg79bVD0dpD44QdgobzHKuLZ6S3vl8la9qIeSwGi8i1fS0O1mfuDAAdo1/A== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.5.5" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-proposal-dynamic-import@^7.5.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.5.0.tgz#e532202db4838723691b10a67b8ce509e397c506" + integrity sha512-x/iMjggsKTFHYC6g11PL7Qy58IK8H5zqfm9e6hu4z1iH2IRyAp9u9dL80zA6R76yFovETFLKz2VJIC2iIPBuFw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-dynamic-import" "^7.2.0" + +"@babel/plugin-proposal-json-strings@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-json-strings/-/plugin-proposal-json-strings-7.2.0.tgz#568ecc446c6148ae6b267f02551130891e29f317" + integrity sha512-MAFV1CA/YVmYwZG0fBQyXhmj0BHCB5egZHCKWIFVv/XCxAeVGIHfos3SwDck4LvCllENIAg7xMKOG5kH0dzyUg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-json-strings" "^7.2.0" + +"@babel/plugin-proposal-object-rest-spread@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.6.2.tgz#8ffccc8f3a6545e9f78988b6bf4fe881b88e8096" + integrity sha512-LDBXlmADCsMZV1Y9OQwMc0MyGZ8Ta/zlD9N67BfQT8uYwkRswiu2hU6nJKrjrt/58aH/vqfQlR/9yId/7A2gWw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-object-rest-spread" "^7.2.0" + +"@babel/plugin-proposal-optional-catch-binding@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.2.0.tgz#135d81edb68a081e55e56ec48541ece8065c38f5" + integrity sha512-mgYj3jCcxug6KUcX4OBoOJz3CMrwRfQELPQ5560F70YQUBZB7uac9fqaWamKR1iWUzGiK2t0ygzjTScZnVz75g== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-optional-catch-binding" "^7.2.0" + +"@babel/plugin-proposal-unicode-property-regex@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.6.2.tgz#05413762894f41bfe42b9a5e80919bd575dcc802" + integrity sha512-NxHETdmpeSCtiatMRYWVJo7266rrvAC3DTeG5exQBIH/fMIUK7ejDNznBbn3HQl/o9peymRRg7Yqkx6PdUXmMw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.4.4" + regexpu-core "^4.6.0" + +"@babel/plugin-syntax-async-generators@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.2.0.tgz#69e1f0db34c6f5a0cf7e2b3323bf159a76c8cb7f" + integrity sha512-1ZrIRBv2t0GSlcwVoQ6VgSLpLgiN/FVQUzt9znxo7v2Ov4jJrs8RY8tv0wvDmFN3qIdMKWrmMMW6yZ0G19MfGg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-dynamic-import@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.2.0.tgz#69c159ffaf4998122161ad8ebc5e6d1f55df8612" + integrity sha512-mVxuJ0YroI/h/tbFTPGZR8cv6ai+STMKNBq0f8hFxsxWjl94qqhsb+wXbpNMDPU3cfR1TIsVFzU3nXyZMqyK4w== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-json-strings@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.2.0.tgz#72bd13f6ffe1d25938129d2a186b11fd62951470" + integrity sha512-5UGYnMSLRE1dqqZwug+1LISpA403HzlSfsg6P9VXU6TBjcSHeNlw4DxDx7LgpF+iKZoOG/+uzqoRHTdcUpiZNg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-jsx@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.2.0.tgz#0b85a3b4bc7cdf4cc4b8bf236335b907ca22e7c7" + integrity sha512-VyN4QANJkRW6lDBmENzRszvZf3/4AXaj9YR7GwrWeeN9tEBPuXbmDYVU9bYBN0D70zCWVwUy0HWq2553VCb6Hw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-object-rest-spread@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e" + integrity sha512-t0JKGgqk2We+9may3t0xDdmneaXmyxq0xieYcKHxIsrJO64n1OiMWNUtc5gQK1PA0NpdCRrtZp4z+IUaKugrSA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-optional-catch-binding@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.2.0.tgz#a94013d6eda8908dfe6a477e7f9eda85656ecf5c" + integrity sha512-bDe4xKNhb0LI7IvZHiA13kff0KEfaGX/Hv4lMA9+7TEc63hMNvfKo6ZFpXhKuEp+II/q35Gc4NoMeDZyaUbj9w== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-syntax-typescript@^7.2.0": + version "7.3.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.3.3.tgz#a7cc3f66119a9f7ebe2de5383cce193473d65991" + integrity sha512-dGwbSMA1YhVS8+31CnPR7LB4pcbrzcV99wQzby4uAfrkZPYZlQ7ImwdpzLqi6Z6IL02b8IAL379CaMwo0x5Lag== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-arrow-functions@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.2.0.tgz#9aeafbe4d6ffc6563bf8f8372091628f00779550" + integrity sha512-ER77Cax1+8/8jCB9fo4Ud161OZzWN5qawi4GusDuRLcDbDG+bIGYY20zb2dfAFdTRGzrfq2xZPvF0R64EHnimg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-async-to-generator@^7.5.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.5.0.tgz#89a3848a0166623b5bc481164b5936ab947e887e" + integrity sha512-mqvkzwIGkq0bEF1zLRRiTdjfomZJDV33AH3oQzHVGkI2VzEmXLpKKOBvEVaFZBJdN0XTyH38s9j/Kiqr68dggg== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-remap-async-to-generator" "^7.1.0" + +"@babel/plugin-transform-block-scoped-functions@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.2.0.tgz#5d3cc11e8d5ddd752aa64c9148d0db6cb79fd190" + integrity sha512-ntQPR6q1/NKuphly49+QiQiTN0O63uOwjdD6dhIjSWBI5xlrbUFh720TIpzBhpnrLfv2tNH/BXvLIab1+BAI0w== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-block-scoping@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.6.3.tgz#6e854e51fbbaa84351b15d4ddafe342f3a5d542a" + integrity sha512-7hvrg75dubcO3ZI2rjYTzUrEuh1E9IyDEhhB6qfcooxhDA33xx2MasuLVgdxzcP6R/lipAC6n9ub9maNW6RKdw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + lodash "^4.17.13" + +"@babel/plugin-transform-classes@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-classes/-/plugin-transform-classes-7.5.5.tgz#d094299d9bd680a14a2a0edae38305ad60fb4de9" + integrity sha512-U2htCNK/6e9K7jGyJ++1p5XRU+LJjrwtoiVn9SzRlDT2KubcZ11OOwy3s24TjHxPgxNwonCYP7U2K51uVYCMDg== + dependencies: + "@babel/helper-annotate-as-pure" "^7.0.0" + "@babel/helper-define-map" "^7.5.5" + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.5.5" + "@babel/helper-split-export-declaration" "^7.4.4" + globals "^11.1.0" + +"@babel/plugin-transform-computed-properties@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.2.0.tgz#83a7df6a658865b1c8f641d510c6f3af220216da" + integrity sha512-kP/drqTxY6Xt3NNpKiMomfgkNn4o7+vKxK2DDKcBG9sHj51vHqMBGy8wbDS/J4lMxnqs153/T3+DmCEAkC5cpA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-destructuring@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.6.0.tgz#44bbe08b57f4480094d57d9ffbcd96d309075ba6" + integrity sha512-2bGIS5P1v4+sWTCnKNDZDxbGvEqi0ijeqM/YqHtVGrvG2y0ySgnEEhXErvE9dA0bnIzY9bIzdFK0jFA46ASIIQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-dotall-regex@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.6.2.tgz#44abb948b88f0199a627024e1508acaf8dc9b2f9" + integrity sha512-KGKT9aqKV+9YMZSkowzYoYEiHqgaDhGmPNZlZxX6UeHC4z30nC1J9IrZuGqbYFB1jaIGdv91ujpze0exiVK8bA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.4.4" + regexpu-core "^4.6.0" + +"@babel/plugin-transform-duplicate-keys@^7.5.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.5.0.tgz#c5dbf5106bf84cdf691222c0974c12b1df931853" + integrity sha512-igcziksHizyQPlX9gfSjHkE2wmoCH3evvD2qR5w29/Dk0SMKE/eOI7f1HhBdNhR/zxJDqrgpoDTq5YSLH/XMsQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-exponentiation-operator@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.2.0.tgz#a63868289e5b4007f7054d46491af51435766008" + integrity sha512-umh4hR6N7mu4Elq9GG8TOu9M0bakvlsREEC+ialrQN6ABS4oDQ69qJv1VtR3uxlKMCQMCvzk7vr17RHKcjx68A== + dependencies: + "@babel/helper-builder-binary-assignment-operator-visitor" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-for-of@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.4.4.tgz#0267fc735e24c808ba173866c6c4d1440fc3c556" + integrity sha512-9T/5Dlr14Z9TIEXLXkt8T1DU7F24cbhwhMNUziN3hB1AXoZcdzPcTiKGRn/6iOymDqtTKWnr/BtRKN9JwbKtdQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-function-name@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.4.4.tgz#e1436116abb0610c2259094848754ac5230922ad" + integrity sha512-iU9pv7U+2jC9ANQkKeNF6DrPy4GBa4NWQtl6dHB4Pb3izX2JOEvDTFarlNsBj/63ZEzNNIAMs3Qw4fNCcSOXJA== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-literals@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-literals/-/plugin-transform-literals-7.2.0.tgz#690353e81f9267dad4fd8cfd77eafa86aba53ea1" + integrity sha512-2ThDhm4lI4oV7fVQ6pNNK+sx+c/GM5/SaML0w/r4ZB7sAneD/piDJtwdKlNckXeyGK7wlwg2E2w33C/Hh+VFCg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-member-expression-literals@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-member-expression-literals/-/plugin-transform-member-expression-literals-7.2.0.tgz#fa10aa5c58a2cb6afcf2c9ffa8cb4d8b3d489a2d" + integrity sha512-HiU3zKkSU6scTidmnFJ0bMX8hz5ixC93b4MHMiYebmk2lUVNGOboPsqQvx5LzooihijUoLR/v7Nc1rbBtnc7FA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-modules-amd@^7.5.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.5.0.tgz#ef00435d46da0a5961aa728a1d2ecff063e4fb91" + integrity sha512-n20UsQMKnWrltocZZm24cRURxQnWIvsABPJlw/fvoy9c6AgHZzoelAIzajDHAQrDpuKFFPPcFGd7ChsYuIUMpg== + dependencies: + "@babel/helper-module-transforms" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + babel-plugin-dynamic-import-node "^2.3.0" + +"@babel/plugin-transform-modules-commonjs@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.6.0.tgz#39dfe957de4420445f1fcf88b68a2e4aa4515486" + integrity sha512-Ma93Ix95PNSEngqomy5LSBMAQvYKVe3dy+JlVJSHEXZR5ASL9lQBedMiCyVtmTLraIDVRE3ZjTZvmXXD2Ozw3g== + dependencies: + "@babel/helper-module-transforms" "^7.4.4" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-simple-access" "^7.1.0" + babel-plugin-dynamic-import-node "^2.3.0" + +"@babel/plugin-transform-modules-systemjs@^7.5.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.5.0.tgz#e75266a13ef94202db2a0620977756f51d52d249" + integrity sha512-Q2m56tyoQWmuNGxEtUyeEkm6qJYFqs4c+XyXH5RAuYxObRNz9Zgj/1g2GMnjYp2EUyEy7YTrxliGCXzecl/vJg== + dependencies: + "@babel/helper-hoist-variables" "^7.4.4" + "@babel/helper-plugin-utils" "^7.0.0" + babel-plugin-dynamic-import-node "^2.3.0" + +"@babel/plugin-transform-modules-umd@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.2.0.tgz#7678ce75169f0877b8eb2235538c074268dd01ae" + integrity sha512-BV3bw6MyUH1iIsGhXlOK6sXhmSarZjtJ/vMiD9dNmpY8QXFFQTj+6v92pcfy1iqa8DeAfJFwoxcrS/TUZda6sw== + dependencies: + "@babel/helper-module-transforms" "^7.1.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-named-capturing-groups-regex@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.6.3.tgz#aaa6e409dd4fb2e50b6e2a91f7e3a3149dbce0cf" + integrity sha512-jTkk7/uE6H2s5w6VlMHeWuH+Pcy2lmdwFoeWCVnvIrDUnB5gQqTVI8WfmEAhF2CDEarGrknZcmSFg1+bkfCoSw== + dependencies: + regexpu-core "^4.6.0" + +"@babel/plugin-transform-new-target@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.4.4.tgz#18d120438b0cc9ee95a47f2c72bc9768fbed60a5" + integrity sha512-r1z3T2DNGQwwe2vPGZMBNjioT2scgWzK9BCnDEh+46z8EEwXBq24uRzd65I7pjtugzPSj921aM15RpESgzsSuA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-object-super@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.5.5.tgz#c70021df834073c65eb613b8679cc4a381d1a9f9" + integrity sha512-un1zJQAhSosGFBduPgN/YFNvWVpRuHKU7IHBglLoLZsGmruJPOo6pbInneflUdmq7YvSVqhpPs5zdBvLnteltQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.5.5" + +"@babel/plugin-transform-parameters@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.4.4.tgz#7556cf03f318bd2719fe4c922d2d808be5571e16" + integrity sha512-oMh5DUO1V63nZcu/ZVLQFqiihBGo4OpxJxR1otF50GMeCLiRx5nUdtokd+u9SuVJrvvuIh9OosRFPP4pIPnwmw== + dependencies: + "@babel/helper-call-delegate" "^7.4.4" + "@babel/helper-get-function-arity" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-property-literals@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-property-literals/-/plugin-transform-property-literals-7.2.0.tgz#03e33f653f5b25c4eb572c98b9485055b389e905" + integrity sha512-9q7Dbk4RhgcLp8ebduOpCbtjh7C0itoLYHXd9ueASKAG/is5PQtMR5VJGka9NKqGhYEGn5ITahd4h9QeBMylWQ== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-react-display-name@^7.0.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.2.0.tgz#ebfaed87834ce8dc4279609a4f0c324c156e3eb0" + integrity sha512-Htf/tPa5haZvRMiNSQSFifK12gtr/8vwfr+A9y69uF0QcU77AVu4K7MiHEkTxF7lQoHOL0F9ErqgfNEAKgXj7A== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-react-jsx-self@^7.0.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.2.0.tgz#461e21ad9478f1031dd5e276108d027f1b5240ba" + integrity sha512-v6S5L/myicZEy+jr6ielB0OR8h+EH/1QFx/YJ7c7Ua+7lqsjj/vW6fD5FR9hB/6y7mGbfT4vAURn3xqBxsUcdg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-jsx" "^7.2.0" + +"@babel/plugin-transform-react-jsx-source@^7.0.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.5.0.tgz#583b10c49cf057e237085bcbd8cc960bd83bd96b" + integrity sha512-58Q+Jsy4IDCZx7kqEZuSDdam/1oW8OdDX8f+Loo6xyxdfg1yF0GE2XNJQSTZCaMol93+FBzpWiPEwtbMloAcPg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-jsx" "^7.2.0" + +"@babel/plugin-transform-react-jsx@^7.0.0": + version "7.3.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.3.0.tgz#f2cab99026631c767e2745a5368b331cfe8f5290" + integrity sha512-a/+aRb7R06WcKvQLOu4/TpjKOdvVEKRLWFpKcNuHhiREPgGRB4TQJxq07+EZLS8LFVYpfq1a5lDUnuMdcCpBKg== + dependencies: + "@babel/helper-builder-react-jsx" "^7.3.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-jsx" "^7.2.0" + +"@babel/plugin-transform-regenerator@^7.4.5": + version "7.4.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.4.5.tgz#629dc82512c55cee01341fb27bdfcb210354680f" + integrity sha512-gBKRh5qAaCWntnd09S8QC7r3auLCqq5DI6O0DlfoyDjslSBVqBibrMdsqO+Uhmx3+BlOmE/Kw1HFxmGbv0N9dA== + dependencies: + regenerator-transform "^0.14.0" + +"@babel/plugin-transform-reserved-words@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-reserved-words/-/plugin-transform-reserved-words-7.2.0.tgz#4792af87c998a49367597d07fedf02636d2e1634" + integrity sha512-fz43fqW8E1tAB3DKF19/vxbpib1fuyCwSPE418ge5ZxILnBhWyhtPgz8eh1RCGGJlwvksHkyxMxh0eenFi+kFw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-runtime@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.6.2.tgz#2669f67c1fae0ae8d8bf696e4263ad52cb98b6f8" + integrity sha512-cqULw/QB4yl73cS5Y0TZlQSjDvNkzDbu0FurTZyHlJpWE5T3PCMdnyV+xXoH1opr1ldyHODe3QAX3OMAii5NxA== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + resolve "^1.8.1" + semver "^5.5.1" + +"@babel/plugin-transform-shorthand-properties@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.2.0.tgz#6333aee2f8d6ee7e28615457298934a3b46198f0" + integrity sha512-QP4eUM83ha9zmYtpbnyjTLAGKQritA5XW/iG9cjtuOI8s1RuL/3V6a3DeSHfKutJQ+ayUfeZJPcnCYEQzaPQqg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-spread@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-spread/-/plugin-transform-spread-7.6.2.tgz#fc77cf798b24b10c46e1b51b1b88c2bf661bb8dd" + integrity sha512-DpSvPFryKdK1x+EDJYCy28nmAaIMdxmhot62jAXF/o99iA33Zj2Lmcp3vDmz+MUh0LNYVPvfj5iC3feb3/+PFg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-sticky-regex@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.2.0.tgz#a1e454b5995560a9c1e0d537dfc15061fd2687e1" + integrity sha512-KKYCoGaRAf+ckH8gEL3JHUaFVyNHKe3ASNsZ+AlktgHevvxGigoIttrEJb8iKN03Q7Eazlv1s6cx2B2cQ3Jabw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.0.0" + +"@babel/plugin-transform-template-literals@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.4.4.tgz#9d28fea7bbce637fb7612a0750989d8321d4bcb0" + integrity sha512-mQrEC4TWkhLN0z8ygIvEL9ZEToPhG5K7KDW3pzGqOfIGZ28Jb0POUkeWcoz8HnHvhFy6dwAT1j8OzqN8s804+g== + dependencies: + "@babel/helper-annotate-as-pure" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-typeof-symbol@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.2.0.tgz#117d2bcec2fbf64b4b59d1f9819894682d29f2b2" + integrity sha512-2LNhETWYxiYysBtrBTqL8+La0jIoQQnIScUJc74OYvUGRmkskNY4EzLCnjHBzdmb38wqtTaixpo1NctEcvMDZw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-typescript@^7.6.0": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.6.3.tgz#dddb50cf3b8b2ef70b22e5326e9a91f05a1db13b" + integrity sha512-aiWINBrPMSC3xTXRNM/dfmyYuPNKY/aexYqBgh0HBI5Y+WO5oRAqW/oROYeYHrF4Zw12r9rK4fMk/ZlAmqx/FQ== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.6.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-typescript" "^7.2.0" + +"@babel/plugin-transform-unicode-regex@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.6.2.tgz#b692aad888a7e8d8b1b214be6b9dc03d5031f698" + integrity sha512-orZI6cWlR3nk2YmYdb0gImrgCUwb5cBUwjf6Ks6dvNVvXERkwtJWOQaEOjPiu0Gu1Tq6Yq/hruCZZOOi9F34Dw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-regex" "^7.4.4" + regexpu-core "^4.6.0" + +"@babel/polyfill@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/polyfill/-/polyfill-7.6.0.tgz#6d89203f8b6cd323e8d946e47774ea35dc0619cc" + integrity sha512-q5BZJI0n/B10VaQQvln1IlDK3BTBJFbADx7tv+oXDPIDZuTo37H5Adb9jhlXm/fEN4Y7/64qD9mnrJJG7rmaTw== + dependencies: + core-js "^2.6.5" + regenerator-runtime "^0.13.2" + +"@babel/preset-env@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.6.3.tgz#9e1bf05a2e2d687036d24c40e4639dc46cef2271" + integrity sha512-CWQkn7EVnwzlOdR5NOm2+pfgSNEZmvGjOhlCHBDq0J8/EStr+G+FvPEiz9B56dR6MoiUFjXhfE4hjLoAKKJtIQ== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-proposal-async-generator-functions" "^7.2.0" + "@babel/plugin-proposal-dynamic-import" "^7.5.0" + "@babel/plugin-proposal-json-strings" "^7.2.0" + "@babel/plugin-proposal-object-rest-spread" "^7.6.2" + "@babel/plugin-proposal-optional-catch-binding" "^7.2.0" + "@babel/plugin-proposal-unicode-property-regex" "^7.6.2" + "@babel/plugin-syntax-async-generators" "^7.2.0" + "@babel/plugin-syntax-dynamic-import" "^7.2.0" + "@babel/plugin-syntax-json-strings" "^7.2.0" + "@babel/plugin-syntax-object-rest-spread" "^7.2.0" + "@babel/plugin-syntax-optional-catch-binding" "^7.2.0" + "@babel/plugin-transform-arrow-functions" "^7.2.0" + "@babel/plugin-transform-async-to-generator" "^7.5.0" + "@babel/plugin-transform-block-scoped-functions" "^7.2.0" + "@babel/plugin-transform-block-scoping" "^7.6.3" + "@babel/plugin-transform-classes" "^7.5.5" + "@babel/plugin-transform-computed-properties" "^7.2.0" + "@babel/plugin-transform-destructuring" "^7.6.0" + "@babel/plugin-transform-dotall-regex" "^7.6.2" + "@babel/plugin-transform-duplicate-keys" "^7.5.0" + "@babel/plugin-transform-exponentiation-operator" "^7.2.0" + "@babel/plugin-transform-for-of" "^7.4.4" + "@babel/plugin-transform-function-name" "^7.4.4" + "@babel/plugin-transform-literals" "^7.2.0" + "@babel/plugin-transform-member-expression-literals" "^7.2.0" + "@babel/plugin-transform-modules-amd" "^7.5.0" + "@babel/plugin-transform-modules-commonjs" "^7.6.0" + "@babel/plugin-transform-modules-systemjs" "^7.5.0" + "@babel/plugin-transform-modules-umd" "^7.2.0" + "@babel/plugin-transform-named-capturing-groups-regex" "^7.6.3" + "@babel/plugin-transform-new-target" "^7.4.4" + "@babel/plugin-transform-object-super" "^7.5.5" + "@babel/plugin-transform-parameters" "^7.4.4" + "@babel/plugin-transform-property-literals" "^7.2.0" + "@babel/plugin-transform-regenerator" "^7.4.5" + "@babel/plugin-transform-reserved-words" "^7.2.0" + "@babel/plugin-transform-shorthand-properties" "^7.2.0" + "@babel/plugin-transform-spread" "^7.6.2" + "@babel/plugin-transform-sticky-regex" "^7.2.0" + "@babel/plugin-transform-template-literals" "^7.4.4" + "@babel/plugin-transform-typeof-symbol" "^7.2.0" + "@babel/plugin-transform-unicode-regex" "^7.6.2" + "@babel/types" "^7.6.3" + browserslist "^4.6.0" + core-js-compat "^3.1.1" + invariant "^2.2.2" + js-levenshtein "^1.1.3" + semver "^5.5.0" + +"@babel/preset-react@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.6.3.tgz#d5242c828322520205ae4eda5d4f4f618964e2f6" + integrity sha512-07yQhmkZmRAfwREYIQgW0HEwMY9GBJVuPY4Q12UC72AbfaawuupVWa8zQs2tlL+yun45Nv/1KreII/0PLfEsgA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-react-display-name" "^7.0.0" + "@babel/plugin-transform-react-jsx" "^7.0.0" + "@babel/plugin-transform-react-jsx-self" "^7.0.0" + "@babel/plugin-transform-react-jsx-source" "^7.0.0" + +"@babel/preset-typescript@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.6.0.tgz#25768cb8830280baf47c45ab1a519a9977498c98" + integrity sha512-4xKw3tTcCm0qApyT6PqM9qniseCE79xGHiUnNdKGdxNsGUc2X7WwZybqIpnTmoukg3nhPceI5KPNzNqLNeIJww== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-typescript" "^7.6.0" + +"@babel/register@^7.6.2": + version "7.6.2" + resolved "https://registry.yarnpkg.com/@babel/register/-/register-7.6.2.tgz#25765a922202cb06f8bdac5a3b1e70cd6bf3dd45" + integrity sha512-xgZk2LRZvt6i2SAUWxc7ellk4+OYRgS3Zpsnr13nMS1Qo25w21Uu8o6vTOAqNaxiqrnv30KTYzh9YWY2k21CeQ== + dependencies: + find-cache-dir "^2.0.0" + lodash "^4.17.13" + mkdirp "^0.5.1" + pirates "^4.0.0" + source-map-support "^0.5.9" + +"@babel/runtime@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.6.3.tgz#935122c74c73d2240cafd32ddb5fc2a6cd35cf1f" + integrity sha512-kq6anf9JGjW8Nt5rYfEuGRaEAaH1mkv3Bbu6rYvLOpPh/RusSJXuKPEAoZ7L7gybZkchE8+NV5g9vKF4AGAtsA== + dependencies: + regenerator-runtime "^0.13.2" + "@babel/template@7.0.0-beta.36": version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.36.tgz#02e903de5d68bd7899bce3c5b5447e59529abb00" @@ -40,6 +797,15 @@ babylon "7.0.0-beta.36" lodash "^4.2.0" +"@babel/template@^7.1.0", "@babel/template@^7.4.4", "@babel/template@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6" + integrity sha512-5AEH2EXD8euCk446b7edmgFdub/qfH1SN6Nii3+fyXP807QRx9Q73A2N5hNwRRslC2H9sNzaFhsPubkS4L8oNQ== + dependencies: + "@babel/code-frame" "^7.0.0" + "@babel/parser" "^7.6.0" + "@babel/types" "^7.6.0" + "@babel/traverse@7.0.0-beta.36": version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0-beta.36.tgz#1dc6f8750e89b6b979de5fe44aa993b1a2192261" @@ -53,6 +819,21 @@ invariant "^2.2.0" lodash "^4.2.0" +"@babel/traverse@^7.1.0", "@babel/traverse@^7.4.4", "@babel/traverse@^7.5.5", "@babel/traverse@^7.6.2", "@babel/traverse@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.6.3.tgz#66d7dba146b086703c0fb10dd588b7364cec47f9" + integrity sha512-unn7P4LGsijIxaAJo/wpoU11zN+2IaClkQAxcJWBNCMS6cmVh802IyLHNkAjQ0iYnRS3nnxk5O3fuXW28IMxTw== + dependencies: + "@babel/code-frame" "^7.5.5" + "@babel/generator" "^7.6.3" + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.4.4" + "@babel/parser" "^7.6.3" + "@babel/types" "^7.6.3" + debug "^4.1.0" + globals "^11.1.0" + lodash "^4.17.13" + "@babel/types@7.0.0-beta.36": version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.36.tgz#64f2004353de42adb72f9ebb4665fc35b5499d23" @@ -70,6 +851,15 @@ lodash "^4.17.11" to-fast-properties "^2.0.0" +"@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.4.4", "@babel/types@^7.5.5", "@babel/types@^7.6.0", "@babel/types@^7.6.3": + version "7.6.3" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.6.3.tgz#3f07d96f854f98e2fbd45c64b0cb942d11e8ba09" + integrity sha512-CqbcpTxMcpuQTMhjI37ZHVgjBkysg5icREQIEZ0eG1yCNwg3oy+5AaLiOKmjsCj6nqOsa6Hf0ObjRVwokb7srA== + dependencies: + esutils "^2.0.2" + lodash "^4.17.13" + to-fast-properties "^2.0.0" + "@emotion/cache@^10.0.9": version "10.0.9" resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-10.0.9.tgz#e0c7b7a289f7530edcfad4dcf3858bd2e5700a6f" @@ -126,10 +916,109 @@ resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.2.tgz#63985d3d8b02530e0869962f4da09142ee8e200e" integrity sha512-n/VQ4mbfr81aqkx/XmVicOLjviMuy02eenSdJY33SVA7S2J42EU0P1H0mOogfYedb3wXA0d/LVtBrgTSm04WEA== +"@gnd/typedoc@^0.15.0-0": + version "0.15.0-0" + resolved "https://registry.yarnpkg.com/@gnd/typedoc/-/typedoc-0.15.0-0.tgz#bb2fd8f316e496cabab0f33966f5f1581e974f86" + integrity sha512-wKtap5cyeOvJ3xWDHnZ6XUWzGqQ4RvrhKbT8UDyhQBJ+1bbKRI6e9dlWw/WX5k6wYoDUi4ZY1nLTZLY3a12i6Q== + dependencies: + "@types/minimatch" "3.0.3" + fs-extra "^8.1.0" + handlebars "^4.1.2" + highlight.js "^9.15.8" + lodash "^4.17.15" + marked "^0.7.0" + minimatch "^3.0.0" + progress "^2.0.3" + shelljs "^0.8.3" + typedoc-default-themes "^0.6.0" + typescript "3.6.x" + +"@types/eslint-visitor-keys@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" + integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== + +"@types/esrever@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@types/esrever/-/esrever-0.2.0.tgz#96404a2284b2c7527f08a1e957f8a31705f9880f" + integrity sha512-5NI6TeGzVEy/iBcuYtcPzzIC6EqlfQ2+UZ54vT0ulq8bPNGAy8UJD+XcsAyEOcnYFUjOVWuUV+k4/rVkxt9/XQ== + +"@types/estree@*", "@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + +"@types/json-schema@^7.0.3": + version "7.0.3" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636" + integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A== + +"@types/minimatch@3.0.3": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" + integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== + +"@types/mocha@^5.2.7": + version "5.2.7" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea" + integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ== + +"@types/node@*", "@types/node@^12.7.12": + version "12.7.12" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.12.tgz#7c6c571cc2f3f3ac4a59a5f2bd48f5bdbc8653cc" + integrity sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ== + "@types/node@^6.0.46": version "6.0.83" resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.83.tgz#dd022db01ac2c01c1057775e88ccffce96d1d6fe" +"@types/resolve@0.0.8": + version "0.0.8" + resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" + integrity sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ== + dependencies: + "@types/node" "*" + +"@typescript-eslint/eslint-plugin@^2.3.3": + version "2.3.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.3.3.tgz#71e06c6887650301e02105c99b4c8f67454157e3" + integrity sha512-12cCbwu5PbQudkq2xCIS/QhB7hCMrsNPXK+vJtqy/zFqtzVkPRGy12O5Yy0gUK086f3VHV/P4a4R4CjMW853pA== + dependencies: + "@typescript-eslint/experimental-utils" "2.3.3" + eslint-utils "^1.4.2" + functional-red-black-tree "^1.0.1" + regexpp "^2.0.1" + tsutils "^3.17.1" + +"@typescript-eslint/experimental-utils@2.3.3": + version "2.3.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.3.3.tgz#0685613063ff397cfa9209be2e6e81c0382a9b11" + integrity sha512-MQ4jKPMTU1ty4TigJCRKFPye2qyQdH8jzIIkceaHgecKFmkNS1hXPqKiZ+mOehkz6+HcN5Nuvwm+frmWZR9tdg== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/typescript-estree" "2.3.3" + eslint-scope "^5.0.0" + +"@typescript-eslint/parser@^2.3.3": + version "2.3.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.3.3.tgz#af519d6572bdee3e9610e21c8362766858976bc1" + integrity sha512-+cV53HuYFeeyrNW8x/rgPmbVrzzp/rpRmwbJnNtwn4K8mroL1BdjxwQh7X9cUHp9rm4BBiEWmD3cSBjKG7d5mw== + dependencies: + "@types/eslint-visitor-keys" "^1.0.0" + "@typescript-eslint/experimental-utils" "2.3.3" + "@typescript-eslint/typescript-estree" "2.3.3" + eslint-visitor-keys "^1.1.0" + +"@typescript-eslint/typescript-estree@2.3.3": + version "2.3.3" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.3.3.tgz#be802220876bedfb80384cde1d46fe57ae7abf71" + integrity sha512-GkACs12Xp8d/STunNv/iSMYJFQrkrax9vuPZySlgSzoJJtw1cp6tbEw4qsLskQv6vloLrkFJHcTJ0a/yCB5cIA== + dependencies: + glob "^7.1.4" + is-glob "^4.0.1" + lodash.unescape "4.0.1" + semver "^6.3.0" + JSONStream@^1.0.4: version "1.3.2" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.2.tgz#c102371b6ec3a7cf3b847ca00c20bb0fce4c6dea" @@ -176,19 +1065,15 @@ acorn-jsx@^3.0.0: dependencies: acorn "^3.0.4" -acorn@^1.0.3: - version "1.2.2" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-1.2.2.tgz#c8ce27de0acc76d896d2b1fad3df588d9e82f014" - acorn@^3.0.4: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" -acorn@^4.0.1, acorn@^4.0.3: +acorn@^4.0.3: version "4.0.13" resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" -acorn@^5.0.0, acorn@^5.1.2, acorn@^5.2.1: +acorn@^5.0.0, acorn@^5.1.2: version "5.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822" @@ -196,6 +1081,16 @@ acorn@^5.5.0: version "5.7.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8" +acorn@^5.7.3: + version "5.7.3" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" + integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw== + +acorn@^7.1.0: + version "7.1.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.1.0.tgz#949d36f2c292535da602283586c2477c57eb2d6c" + integrity sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ== + add-stream@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/add-stream/-/add-stream-1.0.0.tgz#6a7990437ca736d5e1288db92bd3266d5f5cb2aa" @@ -442,6 +1337,11 @@ async-each@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" +async-each@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf" + integrity sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ== + async@1.5.2, async@^1.4.0, async@^1.5.0, async@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" @@ -469,222 +1369,38 @@ autoprefixer@^6.3.1: normalize-range "^0.1.2" num2fraction "^1.2.2" postcss "^5.2.16" - postcss-value-parser "^3.2.3" - -aws-sign2@~0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f" - -aws-sign2@~0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" - -aws4@^1.2.1, aws4@^1.6.0: - version "1.6.0" - resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" - -babel-cli@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-cli/-/babel-cli-6.26.0.tgz#502ab54874d7db88ad00b887a06383ce03d002f1" - dependencies: - babel-core "^6.26.0" - babel-polyfill "^6.26.0" - babel-register "^6.26.0" - babel-runtime "^6.26.0" - commander "^2.11.0" - convert-source-map "^1.5.0" - fs-readdir-recursive "^1.0.0" - glob "^7.1.2" - lodash "^4.17.4" - output-file-sync "^1.1.2" - path-is-absolute "^1.0.1" - slash "^1.0.0" - source-map "^0.5.6" - v8flags "^2.1.1" - optionalDependencies: - chokidar "^1.6.1" - -babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" - dependencies: - chalk "^1.1.3" - esutils "^2.0.2" - js-tokens "^3.0.2" - -babel-core@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.0.tgz#af32f78b31a6fcef119c87b0fd8d9753f03a0bb8" - dependencies: - babel-code-frame "^6.26.0" - babel-generator "^6.26.0" - babel-helpers "^6.24.1" - babel-messages "^6.23.0" - babel-register "^6.26.0" - babel-runtime "^6.26.0" - babel-template "^6.26.0" - babel-traverse "^6.26.0" - babel-types "^6.26.0" - babylon "^6.18.0" - convert-source-map "^1.5.0" - debug "^2.6.8" - json5 "^0.5.1" - lodash "^4.17.4" - minimatch "^3.0.4" - path-is-absolute "^1.0.1" - private "^0.1.7" - slash "^1.0.0" - source-map "^0.5.6" - -babel-eslint@^8.2.1: - version "8.2.1" - resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-8.2.1.tgz#136888f3c109edc65376c23ebf494f36a3e03951" - dependencies: - "@babel/code-frame" "7.0.0-beta.36" - "@babel/traverse" "7.0.0-beta.36" - "@babel/types" "7.0.0-beta.36" - babylon "7.0.0-beta.36" - eslint-scope "~3.7.1" - eslint-visitor-keys "^1.0.0" - -babel-generator@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.0.tgz#ac1ae20070b79f6e3ca1d3269613053774f20dc5" - dependencies: - babel-messages "^6.23.0" - babel-runtime "^6.26.0" - babel-types "^6.26.0" - detect-indent "^4.0.0" - jsesc "^1.3.0" - lodash "^4.17.4" - source-map "^0.5.6" - trim-right "^1.0.1" - -babel-helper-bindify-decorators@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-bindify-decorators/-/babel-helper-bindify-decorators-6.24.1.tgz#14c19e5f142d7b47f19a52431e52b1ccbc40a330" - dependencies: - babel-runtime "^6.22.0" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-builder-binary-assignment-operator-visitor@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz#cce4517ada356f4220bcae8a02c2b346f9a56664" - dependencies: - babel-helper-explode-assignable-expression "^6.24.1" - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-helper-builder-react-jsx@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-builder-react-jsx/-/babel-helper-builder-react-jsx-6.24.1.tgz#0ad7917e33c8d751e646daca4e77cc19377d2cbc" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - esutils "^2.0.0" - -babel-helper-call-delegate@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-call-delegate/-/babel-helper-call-delegate-6.24.1.tgz#ece6aacddc76e41c3461f88bfc575bd0daa2df8d" - dependencies: - babel-helper-hoist-variables "^6.24.1" - babel-runtime "^6.22.0" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-define-map@^6.24.1: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-helper-define-map/-/babel-helper-define-map-6.26.0.tgz#a5f56dab41a25f97ecb498c7ebaca9819f95be5f" - dependencies: - babel-helper-function-name "^6.24.1" - babel-runtime "^6.26.0" - babel-types "^6.26.0" - lodash "^4.17.4" - -babel-helper-explode-assignable-expression@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-explode-assignable-expression/-/babel-helper-explode-assignable-expression-6.24.1.tgz#f25b82cf7dc10433c55f70592d5746400ac22caa" - dependencies: - babel-runtime "^6.22.0" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-explode-class@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-explode-class/-/babel-helper-explode-class-6.24.1.tgz#7dc2a3910dee007056e1e31d640ced3d54eaa9eb" - dependencies: - babel-helper-bindify-decorators "^6.24.1" - babel-runtime "^6.22.0" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-function-name@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9" - dependencies: - babel-helper-get-function-arity "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" + postcss-value-parser "^3.2.3" -babel-helper-get-function-arity@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-get-function-arity/-/babel-helper-get-function-arity-6.24.1.tgz#8f7782aa93407c41d3aa50908f89b031b1b6853d" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" +aws-sign2@~0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f" -babel-helper-hoist-variables@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-hoist-variables/-/babel-helper-hoist-variables-6.24.1.tgz#1ecb27689c9d25513eadbc9914a73f5408be7a76" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" +aws-sign2@~0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" -babel-helper-optimise-call-expression@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.24.1.tgz#f7a13427ba9f73f8f4fa993c54a97882d1244257" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" +aws4@^1.2.1, aws4@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" -babel-helper-regex@^6.24.1: +babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-helper-regex/-/babel-helper-regex-6.26.0.tgz#325c59f902f82f24b74faceed0363954f6495e72" - dependencies: - babel-runtime "^6.26.0" - babel-types "^6.26.0" - lodash "^4.17.4" - -babel-helper-remap-async-to-generator@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-remap-async-to-generator/-/babel-helper-remap-async-to-generator-6.24.1.tgz#5ec581827ad723fecdd381f1c928390676e4551b" - dependencies: - babel-helper-function-name "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-replace-supers@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-replace-supers/-/babel-helper-replace-supers-6.24.1.tgz#bf6dbfe43938d17369a213ca8a8bf74b6a90ab1a" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" dependencies: - babel-helper-optimise-call-expression "^6.24.1" - babel-messages "^6.23.0" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" + chalk "^1.1.3" + esutils "^2.0.2" + js-tokens "^3.0.2" -babel-helpers@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helpers/-/babel-helpers-6.24.1.tgz#3471de9caec388e5c850e597e58a26ddf37602b2" +babel-eslint@^8.2.1: + version "8.2.1" + resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-8.2.1.tgz#136888f3c109edc65376c23ebf494f36a3e03951" dependencies: - babel-runtime "^6.22.0" - babel-template "^6.24.1" + "@babel/code-frame" "7.0.0-beta.36" + "@babel/traverse" "7.0.0-beta.36" + "@babel/types" "7.0.0-beta.36" + babylon "7.0.0-beta.36" + eslint-scope "~3.7.1" + eslint-visitor-keys "^1.0.0" babel-loader@^7.1.2: version "7.1.2" @@ -694,17 +1410,17 @@ babel-loader@^7.1.2: loader-utils "^1.0.2" mkdirp "^0.5.1" -babel-messages@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" - dependencies: - babel-runtime "^6.22.0" +babel-plugin-dev-expression@^0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/babel-plugin-dev-expression/-/babel-plugin-dev-expression-0.2.2.tgz#c18de18a06150f9480edd151acbb01d2e65e999b" + integrity sha512-y32lfBif+c2FIh5dwGfcc/IfX5aw/Bru7Du7W2n17sJE/GJGAsmIk5DPW/8JOoeKpXW5evJfJOvRq5xkiS6vng== -babel-plugin-check-es2015-constants@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a" +babel-plugin-dynamic-import-node@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz#f00f507bdaa3c3e3ff6e7e5e98d90a7acab96f7f" + integrity sha512-o6qFkpeQEBxcqt0XYlWzAVxNCSCZdUgcR8IRlhD/8DylxjjO4foPcvTW0GGKa/cVt3rvxZ7o5ippJ+/0nvLhlQ== dependencies: - babel-runtime "^6.22.0" + object.assign "^4.1.0" babel-plugin-emotion@^10.0.9: version "10.0.9" @@ -722,12 +1438,6 @@ babel-plugin-emotion@^10.0.9: find-root "^1.1.0" source-map "^0.5.7" -babel-plugin-external-helpers@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-external-helpers/-/babel-plugin-external-helpers-6.22.0.tgz#2285f48b02bd5dede85175caf8c62e86adccefa1" - dependencies: - babel-runtime "^6.22.0" - babel-plugin-macros@^2.0.0: version "2.2.2" resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-2.2.2.tgz#049c93f4b934453688a6ec38bba529c55bf0fa1f" @@ -744,517 +1454,20 @@ babel-plugin-module-resolver@^3.1.1: reselect "^3.0.1" resolve "^1.4.0" -babel-plugin-syntax-async-functions@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" - -babel-plugin-syntax-async-generators@^6.5.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-generators/-/babel-plugin-syntax-async-generators-6.13.0.tgz#6bc963ebb16eccbae6b92b596eb7f35c342a8b9a" - -babel-plugin-syntax-class-constructor-call@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-constructor-call/-/babel-plugin-syntax-class-constructor-call-6.18.0.tgz#9cb9d39fe43c8600bec8146456ddcbd4e1a76416" - -babel-plugin-syntax-class-properties@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz#d7eb23b79a317f8543962c505b827c7d6cac27de" - -babel-plugin-syntax-decorators@^6.13.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz#312563b4dbde3cc806cee3e416cceeaddd11ac0b" - -babel-plugin-syntax-do-expressions@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-do-expressions/-/babel-plugin-syntax-do-expressions-6.13.0.tgz#5747756139aa26d390d09410b03744ba07e4796d" - -babel-plugin-syntax-dynamic-import@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-dynamic-import/-/babel-plugin-syntax-dynamic-import-6.18.0.tgz#8d6a26229c83745a9982a441051572caa179b1da" - -babel-plugin-syntax-exponentiation-operator@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" - -babel-plugin-syntax-export-extensions@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-export-extensions/-/babel-plugin-syntax-export-extensions-6.13.0.tgz#70a1484f0f9089a4e84ad44bac353c95b9b12721" - -babel-plugin-syntax-flow@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d" - -babel-plugin-syntax-function-bind@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-function-bind/-/babel-plugin-syntax-function-bind-6.13.0.tgz#48c495f177bdf31a981e732f55adc0bdd2601f46" - -babel-plugin-syntax-jsx@^6.18.0, babel-plugin-syntax-jsx@^6.3.13, babel-plugin-syntax-jsx@^6.8.0: +babel-plugin-syntax-jsx@^6.18.0: version "6.18.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946" -babel-plugin-syntax-object-rest-spread@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5" - -babel-plugin-syntax-trailing-function-commas@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3" - -babel-plugin-transform-async-generator-functions@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-generator-functions/-/babel-plugin-transform-async-generator-functions-6.24.1.tgz#f058900145fd3e9907a6ddf28da59f215258a5db" - dependencies: - babel-helper-remap-async-to-generator "^6.24.1" - babel-plugin-syntax-async-generators "^6.5.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-async-to-generator@^6.22.0, babel-plugin-transform-async-to-generator@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761" - dependencies: - babel-helper-remap-async-to-generator "^6.24.1" - babel-plugin-syntax-async-functions "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-class-constructor-call@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-constructor-call/-/babel-plugin-transform-class-constructor-call-6.24.1.tgz#80dc285505ac067dcb8d6c65e2f6f11ab7765ef9" - dependencies: - babel-plugin-syntax-class-constructor-call "^6.18.0" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-class-properties@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.24.1.tgz#6a79763ea61d33d36f37b611aa9def81a81b46ac" - dependencies: - babel-helper-function-name "^6.24.1" - babel-plugin-syntax-class-properties "^6.8.0" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-decorators@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-decorators/-/babel-plugin-transform-decorators-6.24.1.tgz#788013d8f8c6b5222bdf7b344390dfd77569e24d" - dependencies: - babel-helper-explode-class "^6.24.1" - babel-plugin-syntax-decorators "^6.13.0" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-types "^6.24.1" - -babel-plugin-transform-do-expressions@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-do-expressions/-/babel-plugin-transform-do-expressions-6.22.0.tgz#28ccaf92812d949c2cd1281f690c8fdc468ae9bb" - dependencies: - babel-plugin-syntax-do-expressions "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-arrow-functions@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoped-functions/-/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz#bbc51b49f964d70cb8d8e0b94e820246ce3a6141" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-block-scoping@^6.23.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f" - dependencies: - babel-runtime "^6.26.0" - babel-template "^6.26.0" - babel-traverse "^6.26.0" - babel-types "^6.26.0" - lodash "^4.17.4" - -babel-plugin-transform-es2015-classes@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.24.1.tgz#5a4c58a50c9c9461e564b4b2a3bfabc97a2584db" - dependencies: - babel-helper-define-map "^6.24.1" - babel-helper-function-name "^6.24.1" - babel-helper-optimise-call-expression "^6.24.1" - babel-helper-replace-supers "^6.24.1" - babel-messages "^6.23.0" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-computed-properties@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-computed-properties/-/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz#6fe2a8d16895d5634f4cd999b6d3480a308159b3" - dependencies: - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-destructuring@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.23.0.tgz#997bb1f1ab967f682d2b0876fe358d60e765c56d" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-duplicate-keys@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-duplicate-keys/-/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz#73eb3d310ca969e3ef9ec91c53741a6f1576423e" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-for-of@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.23.0.tgz#f47c95b2b613df1d3ecc2fdb7573623c75248691" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-function-name@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-function-name/-/babel-plugin-transform-es2015-function-name-6.24.1.tgz#834c89853bc36b1af0f3a4c5dbaa94fd8eacaa8b" - dependencies: - babel-helper-function-name "^6.24.1" - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-literals@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-literals/-/babel-plugin-transform-es2015-literals-6.22.0.tgz#4f54a02d6cd66cf915280019a31d31925377ca2e" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-modules-amd@^6.22.0, babel-plugin-transform-es2015-modules-amd@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz#3b3e54017239842d6d19c3011c4bd2f00a00d154" - dependencies: - babel-plugin-transform-es2015-modules-commonjs "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.1: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.0.tgz#0d8394029b7dc6abe1a97ef181e00758dd2e5d8a" - dependencies: - babel-plugin-transform-strict-mode "^6.24.1" - babel-runtime "^6.26.0" - babel-template "^6.26.0" - babel-types "^6.26.0" - -babel-plugin-transform-es2015-modules-systemjs@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-systemjs/-/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz#ff89a142b9119a906195f5f106ecf305d9407d23" - dependencies: - babel-helper-hoist-variables "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-modules-umd@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz#ac997e6285cd18ed6176adb607d602344ad38468" - dependencies: - babel-plugin-transform-es2015-modules-amd "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-object-super@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-object-super/-/babel-plugin-transform-es2015-object-super-6.24.1.tgz#24cef69ae21cb83a7f8603dad021f572eb278f8d" - dependencies: - babel-helper-replace-supers "^6.24.1" - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-parameters@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-parameters/-/babel-plugin-transform-es2015-parameters-6.24.1.tgz#57ac351ab49caf14a97cd13b09f66fdf0a625f2b" - dependencies: - babel-helper-call-delegate "^6.24.1" - babel-helper-get-function-arity "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-shorthand-properties@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-shorthand-properties/-/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz#24f875d6721c87661bbd99a4622e51f14de38aa0" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-spread@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-spread/-/babel-plugin-transform-es2015-spread-6.22.0.tgz#d6d68a99f89aedc4536c81a542e8dd9f1746f8d1" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-sticky-regex@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-sticky-regex/-/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz#00c1cdb1aca71112cdf0cf6126c2ed6b457ccdbc" - dependencies: - babel-helper-regex "^6.24.1" - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-template-literals@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-template-literals/-/babel-plugin-transform-es2015-template-literals-6.22.0.tgz#a84b3450f7e9f8f1f6839d6d687da84bb1236d8d" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-typeof-symbol@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-typeof-symbol/-/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz#dec09f1cddff94b52ac73d505c84df59dcceb372" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-unicode-regex@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-unicode-regex/-/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz#d38b12f42ea7323f729387f18a7c5ae1faeb35e9" - dependencies: - babel-helper-regex "^6.24.1" - babel-runtime "^6.22.0" - regexpu-core "^2.0.0" - -babel-plugin-transform-exponentiation-operator@^6.22.0, babel-plugin-transform-exponentiation-operator@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-exponentiation-operator/-/babel-plugin-transform-exponentiation-operator-6.24.1.tgz#2ab0c9c7f3098fa48907772bb813fe41e8de3a0e" - dependencies: - babel-helper-builder-binary-assignment-operator-visitor "^6.24.1" - babel-plugin-syntax-exponentiation-operator "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-export-extensions@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-export-extensions/-/babel-plugin-transform-export-extensions-6.22.0.tgz#53738b47e75e8218589eea946cbbd39109bbe653" - dependencies: - babel-plugin-syntax-export-extensions "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-flow-strip-types@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf" - dependencies: - babel-plugin-syntax-flow "^6.18.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-function-bind@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-function-bind/-/babel-plugin-transform-function-bind-6.22.0.tgz#c6fb8e96ac296a310b8cf8ea401462407ddf6a97" - dependencies: - babel-plugin-syntax-function-bind "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-object-rest-spread@^6.22.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz#0f36692d50fef6b7e2d4b3ac1478137a963b7b06" - dependencies: - babel-plugin-syntax-object-rest-spread "^6.8.0" - babel-runtime "^6.26.0" - -babel-plugin-transform-react-display-name@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-display-name/-/babel-plugin-transform-react-display-name-6.23.0.tgz#4398910c358441dc4cef18787264d0412ed36b37" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-react-jsx-self@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-jsx-self/-/babel-plugin-transform-react-jsx-self-6.22.0.tgz#df6d80a9da2612a121e6ddd7558bcbecf06e636e" - dependencies: - babel-plugin-syntax-jsx "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-react-jsx-source@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-jsx-source/-/babel-plugin-transform-react-jsx-source-6.22.0.tgz#66ac12153f5cd2d17b3c19268f4bf0197f44ecd6" - dependencies: - babel-plugin-syntax-jsx "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-react-jsx@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-jsx/-/babel-plugin-transform-react-jsx-6.24.1.tgz#840a028e7df460dfc3a2d29f0c0d91f6376e66a3" - dependencies: - babel-helper-builder-react-jsx "^6.24.1" - babel-plugin-syntax-jsx "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-regenerator@^6.22.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f" - dependencies: - regenerator-transform "^0.10.0" - -babel-plugin-transform-runtime@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-strict-mode@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-polyfill@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153" - dependencies: - babel-runtime "^6.26.0" - core-js "^2.5.0" - regenerator-runtime "^0.10.5" - -babel-preset-env@^1.6.1: - version "1.6.1" - resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.6.1.tgz#a18b564cc9b9afdf4aae57ae3c1b0d99188e6f48" - dependencies: - babel-plugin-check-es2015-constants "^6.22.0" - babel-plugin-syntax-trailing-function-commas "^6.22.0" - babel-plugin-transform-async-to-generator "^6.22.0" - babel-plugin-transform-es2015-arrow-functions "^6.22.0" - babel-plugin-transform-es2015-block-scoped-functions "^6.22.0" - babel-plugin-transform-es2015-block-scoping "^6.23.0" - babel-plugin-transform-es2015-classes "^6.23.0" - babel-plugin-transform-es2015-computed-properties "^6.22.0" - babel-plugin-transform-es2015-destructuring "^6.23.0" - babel-plugin-transform-es2015-duplicate-keys "^6.22.0" - babel-plugin-transform-es2015-for-of "^6.23.0" - babel-plugin-transform-es2015-function-name "^6.22.0" - babel-plugin-transform-es2015-literals "^6.22.0" - babel-plugin-transform-es2015-modules-amd "^6.22.0" - babel-plugin-transform-es2015-modules-commonjs "^6.23.0" - babel-plugin-transform-es2015-modules-systemjs "^6.23.0" - babel-plugin-transform-es2015-modules-umd "^6.23.0" - babel-plugin-transform-es2015-object-super "^6.22.0" - babel-plugin-transform-es2015-parameters "^6.23.0" - babel-plugin-transform-es2015-shorthand-properties "^6.22.0" - babel-plugin-transform-es2015-spread "^6.22.0" - babel-plugin-transform-es2015-sticky-regex "^6.22.0" - babel-plugin-transform-es2015-template-literals "^6.22.0" - babel-plugin-transform-es2015-typeof-symbol "^6.23.0" - babel-plugin-transform-es2015-unicode-regex "^6.22.0" - babel-plugin-transform-exponentiation-operator "^6.22.0" - babel-plugin-transform-regenerator "^6.22.0" - browserslist "^2.1.2" - invariant "^2.2.2" - semver "^5.3.0" - -babel-preset-flow@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-preset-flow/-/babel-preset-flow-6.23.0.tgz#e71218887085ae9a24b5be4169affb599816c49d" - dependencies: - babel-plugin-transform-flow-strip-types "^6.22.0" - -babel-preset-react@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-preset-react/-/babel-preset-react-6.24.1.tgz#ba69dfaea45fc3ec639b6a4ecea6e17702c91380" - dependencies: - babel-plugin-syntax-jsx "^6.3.13" - babel-plugin-transform-react-display-name "^6.23.0" - babel-plugin-transform-react-jsx "^6.24.1" - babel-plugin-transform-react-jsx-self "^6.22.0" - babel-plugin-transform-react-jsx-source "^6.22.0" - babel-preset-flow "^6.23.0" - -babel-preset-stage-0@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-preset-stage-0/-/babel-preset-stage-0-6.24.1.tgz#5642d15042f91384d7e5af8bc88b1db95b039e6a" - dependencies: - babel-plugin-transform-do-expressions "^6.22.0" - babel-plugin-transform-function-bind "^6.22.0" - babel-preset-stage-1 "^6.24.1" - -babel-preset-stage-1@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-preset-stage-1/-/babel-preset-stage-1-6.24.1.tgz#7692cd7dcd6849907e6ae4a0a85589cfb9e2bfb0" - dependencies: - babel-plugin-transform-class-constructor-call "^6.24.1" - babel-plugin-transform-export-extensions "^6.22.0" - babel-preset-stage-2 "^6.24.1" - -babel-preset-stage-2@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-preset-stage-2/-/babel-preset-stage-2-6.24.1.tgz#d9e2960fb3d71187f0e64eec62bc07767219bdc1" - dependencies: - babel-plugin-syntax-dynamic-import "^6.18.0" - babel-plugin-transform-class-properties "^6.24.1" - babel-plugin-transform-decorators "^6.24.1" - babel-preset-stage-3 "^6.24.1" - -babel-preset-stage-3@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-preset-stage-3/-/babel-preset-stage-3-6.24.1.tgz#836ada0a9e7a7fa37cb138fb9326f87934a48395" - dependencies: - babel-plugin-syntax-trailing-function-commas "^6.22.0" - babel-plugin-transform-async-generator-functions "^6.24.1" - babel-plugin-transform-async-to-generator "^6.24.1" - babel-plugin-transform-exponentiation-operator "^6.24.1" - babel-plugin-transform-object-rest-spread "^6.22.0" - -babel-register@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-register/-/babel-register-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071" - dependencies: - babel-core "^6.26.0" - babel-runtime "^6.26.0" - core-js "^2.5.0" - home-or-tmp "^2.0.0" - lodash "^4.17.4" - mkdirp "^0.5.1" - source-map-support "^0.4.15" - -babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" - dependencies: - core-js "^2.4.0" - regenerator-runtime "^0.11.0" - -babel-template@^6.24.1, babel-template@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" - dependencies: - babel-runtime "^6.26.0" - babel-traverse "^6.26.0" - babel-types "^6.26.0" - babylon "^6.18.0" - lodash "^4.17.4" - -babel-traverse@^6.24.1, babel-traverse@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" - dependencies: - babel-code-frame "^6.26.0" - babel-messages "^6.23.0" - babel-runtime "^6.26.0" - babel-types "^6.26.0" - babylon "^6.18.0" - debug "^2.6.8" - globals "^9.18.0" - invariant "^2.2.2" - lodash "^4.17.4" - -babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" - dependencies: - babel-runtime "^6.26.0" - esutils "^2.0.2" - lodash "^4.17.4" - to-fast-properties "^1.0.3" - babylon@7.0.0-beta.36: version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.36.tgz#3a3683ba6a9a1e02b0aa507c8e63435e39305b9e" -babylon@^6.18.0: - version "6.18.0" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" +backbone@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/backbone/-/backbone-1.4.0.tgz#54db4de9df7c3811c3f032f34749a4cd27f3bd12" + integrity sha512-RLmDrRXkVdouTg38jcgHhyQ/2zjg7a8E6sz2zxfz21Hh17xDJYUHBZimVIt5fUyS8vbfpeSmTL3gUjTEvUV3qQ== + dependencies: + underscore ">=1.8.3" balanced-match@^0.4.2: version "0.4.2" @@ -1304,17 +1517,6 @@ bl@~0.8.1: dependencies: readable-stream "~1.0.26" -blanket@^1.2.3: - version "1.2.3" - resolved "https://registry.yarnpkg.com/blanket/-/blanket-1.2.3.tgz#151b4987c3bd84552bb5f03b90ef5f7e5931e473" - dependencies: - acorn "^1.0.3" - falafel "~1.2.0" - foreach "^2.0.5" - isarray "0.0.1" - object-keys "^1.0.6" - xtend "~4.0.0" - block-stream@*: version "0.0.9" resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" @@ -1380,7 +1582,7 @@ braces@^1.8.2: preserve "^0.2.0" repeat-element "^1.1.2" -braces@^2.3.0, braces@^2.3.1: +braces@^2.3.0, braces@^2.3.1, braces@^2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729" dependencies: @@ -1475,14 +1677,16 @@ browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6: caniuse-db "^1.0.30000639" electron-to-chromium "^1.2.7" -browserslist@^2.1.2: - version "2.11.3" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.11.3.tgz#fe36167aed1bbcde4827ebfe71347a2cc70b99b2" +browserslist@^4.6.0, browserslist@^4.6.6: + version "4.7.0" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.7.0.tgz#9ee89225ffc07db03409f2fee524dc8227458a17" + integrity sha512-9rGNDtnj+HaahxiVV38Gn8n8Lr8REKsel68v1sPFfIGEK6uSXTY3h9acgiT1dZVtOOUtifo/Dn8daDQ5dUgVsA== dependencies: - caniuse-lite "^1.0.30000792" - electron-to-chromium "^1.3.30" + caniuse-lite "^1.0.30000989" + electron-to-chromium "^1.3.247" + node-releases "^1.1.29" -buffer-es6@^4.9.1, buffer-es6@^4.9.2: +buffer-es6@^4.9.2, buffer-es6@^4.9.3: version "4.9.3" resolved "https://registry.yarnpkg.com/buffer-es6/-/buffer-es6-4.9.3.tgz#f26347b82df76fd37e18bcb5288c4970cfd5c404" @@ -1506,10 +1710,15 @@ buffer@^4.3.0: ieee754 "^1.1.4" isarray "^1.0.0" -builtin-modules@^1.0.0, builtin-modules@^1.1.0, builtin-modules@^1.1.1: +builtin-modules@^1.0.0, builtin-modules@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" +builtin-modules@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484" + integrity sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw== + builtin-status-codes@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" @@ -1630,9 +1839,10 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639: version "1.0.30000808" resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000808.tgz#30dfd83009d5704f02dffb37725068ed12a366bb" -caniuse-lite@^1.0.30000792: - version "1.0.30000792" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000792.tgz#d0cea981f8118f3961471afbb43c9a1e5bbf0332" +caniuse-lite@^1.0.30000989: + version "1.0.30000999" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000999.tgz#427253a69ad7bea4aa8d8345687b8eec51ca0e43" + integrity sha512-1CUyKyecPeksKwXZvYw0tEoaMCo/RwBlXmEtN5vVnabvO0KPd9RQLcaAuR9/1F+KDMv6esmOFWlsXuzDk+8rxg== capture-stack-trace@^1.0.0: version "1.0.0" @@ -1680,7 +1890,7 @@ chardet@^0.4.0: version "0.4.2" resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2" -chokidar@^1.6.1, chokidar@^1.7.0: +chokidar@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468" dependencies: @@ -1713,10 +1923,34 @@ chokidar@^2.0.0: optionalDependencies: fsevents "^1.0.0" +chokidar@^2.1.8: + version "2.1.8" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.1.8.tgz#804b3a7b6a99358c3c5c61e71d8728f041cff917" + integrity sha512-ZmZUazfOzf0Nve7duiCKD23PFSCs4JPoYyccjUFF3aQkQadqBhfzhjkwBH2mNOG9cTBwhamM37EIsIkZw3nRgg== + dependencies: + anymatch "^2.0.0" + async-each "^1.0.1" + braces "^2.3.2" + glob-parent "^3.1.0" + inherits "^2.0.3" + is-binary-path "^1.0.0" + is-glob "^4.0.0" + normalize-path "^3.0.0" + path-is-absolute "^1.0.0" + readdirp "^2.2.1" + upath "^1.1.1" + optionalDependencies: + fsevents "^1.2.7" + chownr@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.0.1.tgz#e2a75042a9551908bebd25b8523d5f9769d79181" +chownr@^1.1.1: + version "1.1.3" + resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.3.tgz#42d837d5239688d55f303003a508230fa6727142" + integrity sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw== + ci-info@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.2.tgz#03561259db48d0474c8bdc90f5b47b068b6bbfb4" @@ -1899,6 +2133,11 @@ commander@2.14.x, commander@~2.14.1: version "2.14.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa" +commander@2.20.0: + version "2.20.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422" + integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ== + commander@2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.3.0.tgz#fd430e889832ec353b9acd1de217c11cb3eef873" @@ -1909,10 +2148,15 @@ commander@2.9.0: dependencies: graceful-readlink ">= 1.0.0" -commander@^2.11.0, commander@^2.15.1: +commander@^2.15.1: version "2.16.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.16.0.tgz#f16390593996ceb4f3eeb020b31d78528f7f8a50" +commander@^2.8.1: + version "2.20.3" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" + integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== + commander@~2.13.0: version "2.13.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" @@ -2142,6 +2386,13 @@ conventional-recommended-bump@^1.0.1: meow "^3.3.0" object-assign "^4.0.1" +convert-source-map@^1.1.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.6.0.tgz#51b537a8c43e0f04dec1993bffcdd504e758ac20" + integrity sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A== + dependencies: + safe-buffer "~5.1.1" + convert-source-map@^1.5.0: version "1.5.1" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5" @@ -2182,17 +2433,22 @@ copy-webpack-plugin@^4.4.1: p-limit "^1.0.0" serialize-javascript "^1.4.0" +core-js-compat@^3.1.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.2.1.tgz#0cbdbc2e386e8e00d3b85dc81c848effec5b8150" + integrity sha512-MwPZle5CF9dEaMYdDeWm73ao/IflDH+FjeJCWEADcEgFSE9TLimFKwJsfmkwzI8eC0Aj0mgvMDjeQjrElkz4/A== + dependencies: + browserslist "^4.6.6" + semver "^6.3.0" + core-js@^1.0.0: version "1.2.7" resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636" -core-js@^2.4.0: - version "2.4.1" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e" - -core-js@^2.5.0: - version "2.5.3" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.3.tgz#8acc38345824f16d8365b7c9b4259168e8ed603e" +core-js@^2.6.5: + version "2.6.9" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.9.tgz#6b4b214620c834152e179323727fc19741b084f2" + integrity sha512-HOpZf6eXmnl7la+cUdMnLvUxKNqLUzJvgIziQ0DiF3JwSImNphIqdGqzj6hIKyX04MmV0poclQ7+wjWvxQyR2A== core-util-is@~1.0.0: version "1.0.2" @@ -2456,7 +2712,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.6, debug@^2.6.8, debug@^2.6. dependencies: ms "2.0.0" -debug@3.2.6: +debug@3.2.6, debug@^3.2.6: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== @@ -2469,6 +2725,13 @@ debug@^3.0.1, debug@^3.1.0: dependencies: ms "2.0.0" +debug@^4.1.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" + integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== + dependencies: + ms "^2.1.1" + decamelize@^1.0.0, decamelize@^1.1.1, decamelize@^1.1.2, decamelize@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -2485,6 +2748,11 @@ deep-equal@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5" +deep-extend@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" + integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== + deep-extend@~0.4.0: version "0.4.1" resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.1.tgz#efe4113d08085f4e6f9687759810f807469e2253" @@ -2589,12 +2857,6 @@ destroy@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" -detect-indent@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-4.0.0.tgz#f76d064352cdf43a1cb6ce619c4ee3a9475de208" - dependencies: - repeating "^2.0.0" - detect-indent@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" @@ -2631,10 +2893,6 @@ dir-glob@^2.0.0: arrify "^1.0.1" path-type "^3.0.0" -direction@^0.1.5: - version "0.1.5" - resolved "https://registry.yarnpkg.com/direction/-/direction-0.1.5.tgz#ce5d797f97e26f8be7beff53f7dc40e1c1a9ec4c" - dns-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d" @@ -2723,12 +2981,6 @@ dot-prop@^3.0.0: dependencies: is-obj "^1.0.0" -drip@1.1.x: - version "1.1.0" - resolved "https://registry.yarnpkg.com/drip/-/drip-1.1.0.tgz#ccefb1e686d86fc115b70c9ec126f8f871bdfd7e" - dependencies: - tea-concat "0.1.0" - duplexer3@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" @@ -2756,19 +3008,14 @@ ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" -electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.30: +electron-to-chromium@^1.2.7: version "1.3.31" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.31.tgz#00d832cba9fe2358652b0c48a8816c8e3a037e9f" -electron@0.4.x: - version "0.4.1" - resolved "https://registry.yarnpkg.com/electron/-/electron-0.4.1.tgz#a78a051a7882f4e542d6e207d8a1a73076b30144" - dependencies: - drip "1.1.x" - -element-closest@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/element-closest/-/element-closest-2.0.2.tgz#72a740a107453382e28df9ce5dbb5a8df0f966ec" +electron-to-chromium@^1.3.247: + version "1.3.281" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.281.tgz#2dbeb9f0bdffddb1662f9ca00d26c49d31dc0f7e" + integrity sha512-oxXKngPjTWRmXFy4vV9FeAkPl7wU4xMejfOY+HXjGrj4T0z9l96loWWVDLJEtbT/aPKOWKrSz6xoYxd+YJ/gJA== elliptic@^6.0.0: version "6.4.0" @@ -3031,10 +3278,30 @@ eslint-scope@^3.7.1, eslint-scope@~3.7.1: esrecurse "^4.1.0" estraverse "^4.1.1" +eslint-scope@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.0.0.tgz#e87c8887c73e8d1ec84f1ca591645c358bfc8fb9" + integrity sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw== + dependencies: + esrecurse "^4.1.0" + estraverse "^4.1.1" + +eslint-utils@^1.4.2: + version "1.4.2" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.2.tgz#166a5180ef6ab7eb462f162fd0e6f2463d7309ab" + integrity sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q== + dependencies: + eslint-visitor-keys "^1.0.0" + eslint-visitor-keys@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d" +eslint-visitor-keys@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" + integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== + eslint@^4.19.1: version "4.19.1" resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.19.1.tgz#32d1d653e1d90408854bfb296f076ec7e186a300" @@ -3117,17 +3384,19 @@ estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" -estree-walker@^0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.2.1.tgz#bdafe8095383d8414d5dc2ecf4c9173b6db9412e" - estree-walker@^0.3.0: version "0.3.1" resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.3.1.tgz#e6b1a51cf7292524e7237c312e5fe6660c1ce1aa" -estree-walker@^0.5.0: - version "0.5.1" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.1.tgz#64fc375053abc6f57d73e9bd2f004644ad3c5854" +estree-walker@^0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39" + integrity sha512-XpCnW/AE10ws/kDAs37cngSkvgIR8aN3G0MS85m7dUpuK2EREo9VJ00uvw6Dg/hXEpfsE1I1TvJOJr+Z+TL+ig== + +estree-walker@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" + integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== esutils@^2.0.0, esutils@^2.0.2: version "2.0.2" @@ -3334,15 +3603,6 @@ faker@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/faker/-/faker-3.1.0.tgz#0f908faf4e6ec02524e54a57e432c5c013e08c9f" -falafel@~1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/falafel/-/falafel-1.2.0.tgz#c18d24ef5091174a497f318cd24b026a25cddab4" - dependencies: - acorn "^1.0.3" - foreach "^2.0.5" - isarray "0.0.1" - object-keys "^1.0.6" - fast-deep-equal@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614" @@ -3450,6 +3710,24 @@ find-cache-dir@^1.0.0: make-dir "^1.0.0" pkg-dir "^2.0.0" +find-cache-dir@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7" + integrity sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ== + dependencies: + commondir "^1.0.1" + make-dir "^2.0.0" + pkg-dir "^3.0.0" + +find-cache-dir@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.0.0.tgz#cd4b7dd97b7185b7e17dbfe2d6e4115ee3eeb8fc" + integrity sha512-t7ulV1fmbxh5G9l/492O1p5+EBbr3uwpt6odhFTMc+nWyhmbloe+ja9BZ8pIBtqFWhOmCWVjx+pTW4zDkFoclw== + dependencies: + commondir "^1.0.1" + make-dir "^3.0.0" + pkg-dir "^4.1.0" + find-root@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4" @@ -3474,6 +3752,14 @@ find-up@^2.0.0, find-up@^2.1.0: dependencies: locate-path "^2.0.0" +find-up@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" + integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== + dependencies: + locate-path "^5.0.0" + path-exists "^4.0.0" + flat-cache@^1.2.1: version "1.3.0" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.3.0.tgz#d3030b32b38154f4e3b7e9c709f490f7ef97c481" @@ -3560,6 +3846,15 @@ from@~0: version "0.1.7" resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" +fs-extra@8.1.0, fs-extra@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" + integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^4.0.0" + universalify "^0.1.0" + fs-extra@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950" @@ -3576,6 +3871,13 @@ fs-extra@^4.0.1: jsonfile "^4.0.0" universalify "^0.1.0" +fs-minipass@^1.2.5: + version "1.2.7" + resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.7.tgz#ccff8570841e7fe4265693da88936c55aed7f7c7" + integrity sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA== + dependencies: + minipass "^2.6.0" + fs-promise@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-promise/-/fs-promise-1.0.0.tgz#4246a4cd45497d2ed57e6e4b22167d3864b23679" @@ -3585,7 +3887,7 @@ fs-promise@^1.0.0: mz "^2.3.1" thenify-all "^1.6.0" -fs-readdir-recursive@^1.0.0: +fs-readdir-recursive@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27" @@ -3609,6 +3911,14 @@ fsevents@^1.0.0: nan "^2.3.0" node-pre-gyp "^0.6.39" +fsevents@^1.2.7: + version "1.2.9" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.9.tgz#3f5ed66583ccd6f400b5a00db6f7e861363e388f" + integrity sha512-oeyj2H3EjjonWcFjD5NvZNE9Rqe4UW+nQBU2HNeKw0koVLEFIhtyETyAakeAM3de7Z/SW5kcA+fZUait9EApnw== + dependencies: + nan "^2.12.1" + node-pre-gyp "^0.12.0" + fstream-ignore@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/fstream-ignore/-/fstream-ignore-1.0.5.tgz#9c31dae34767018fe1d249b24dada67d092da105" @@ -3810,6 +4120,18 @@ glob@^6.0.1: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.0.0, glob@^7.1.4: + version "7.1.4" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255" + integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + glob@^7.0.3, glob@^7.0.5, glob@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" @@ -3832,10 +4154,6 @@ globals@^11.0.1, globals@^11.1.0: version "11.7.0" resolved "https://registry.yarnpkg.com/globals/-/globals-11.7.0.tgz#a583faa43055b1aca771914bf68258e2fc125673" -globals@^9.18.0: - version "9.18.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" - globby@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/globby/-/globby-4.1.0.tgz#080f54549ec1b82a6c60e631fc82e1211dbe95f8" @@ -3905,10 +4223,15 @@ graceful-fs@4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.2.tgz#fe2239b7574972e67e41f808823f9bfa4a991e37" -graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6, graceful-fs@^4.1.9: +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" +graceful-fs@^4.2.0: + version "4.2.2" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" + integrity sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q== + "graceful-readlink@>= 1.0.0": version "1.0.1" resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" @@ -3936,6 +4259,17 @@ handlebars@^4.0.2: optionalDependencies: uglify-js "^2.6" +handlebars@^4.1.2: + version "4.4.3" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.4.3.tgz#180bae52c1d0e9ec0c15d7e82a4362d662762f6e" + integrity sha512-B0W4A2U1ww3q7VVthTKfh+epHx+q4mCt6iK+zEAzbMBpWQAwxCeKxEGpj/1oQTpzPXDNSOG7hmG14TsISH50yw== + dependencies: + neo-async "^2.6.0" + optimist "^0.6.1" + source-map "^0.6.1" + optionalDependencies: + uglify-js "^3.1.4" + har-schema@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e" @@ -4063,6 +4397,11 @@ he@1.2.0: resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +highlight.js@^9.15.8: + version "9.15.10" + resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.15.10.tgz#7b18ed75c90348c045eef9ed08ca1319a2219ad2" + integrity sha512-RoV7OkQm0T3os3Dd2VHLNMoaoDVx77Wygln3n9l5YV172XonWG6rgQD3XnF/BuFFZw9A0TJgmMSO8FEWQgvcXw== + history@^4.7.2: version "4.7.2" resolved "https://registry.yarnpkg.com/history/-/history-4.7.2.tgz#22b5c7f31633c5b8021c7f4a8a954ac139ee8d5b" @@ -4089,13 +4428,6 @@ hoist-non-react-statics@^2.5.0: version "2.5.5" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47" -home-or-tmp@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" - dependencies: - os-homedir "^1.0.0" - os-tmpdir "^1.0.1" - hosted-git-info@^2.1.4, hosted-git-info@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.5.0.tgz#6d60e34b3abbc8313062c3b798ef8d901a07af3c" @@ -4227,6 +4559,13 @@ iconv-lite@^0.4.17, iconv-lite@~0.4.13: dependencies: safer-buffer ">= 2.1.2 < 3" +iconv-lite@^0.4.4: + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" + icss-replace-symbols@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.1.0.tgz#06ea6f83679a7749e386cfe1fe812ae5db223ded" @@ -4249,6 +4588,13 @@ iferr@^0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" +ignore-walk@^3.0.1: + version "3.0.3" + resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.3.tgz#017e2447184bfeade7c238e4aefdd1e8f95b1e37" + integrity sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw== + dependencies: + minimatch "^3.0.4" + ignore@^3.3.3, ignore@^3.3.5: version "3.3.10" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043" @@ -4257,6 +4603,11 @@ image-extensions@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/image-extensions/-/image-extensions-1.1.0.tgz#b8e6bf6039df0056e333502a00b6637a3105d894" +immer@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/immer/-/immer-4.0.1.tgz#9108c1ece7fdd7efb91d21e5eb4bac26f7c3a8ba" + integrity sha512-qZFpWApnbubcJ03gvWa6zUQz2OTkDc6yINdFXI1lm2IoMYsiVVMrxvfeLDURFhUGJfsQysDUjHSXYnJfMMHAwQ== + immutable@^3.8.1: version "3.8.1" resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.1.tgz#200807f11ab0f72710ea485542de088075f68cd2" @@ -4517,6 +4868,13 @@ is-glob@^4.0.0: dependencies: is-extglob "^2.1.1" +is-glob@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" + integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== + dependencies: + is-extglob "^2.1.1" + is-hotkey@0.1.4, is-hotkey@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/is-hotkey/-/is-hotkey-0.1.4.tgz#c34d2c85d6ec8d09a871dcf71931c8067a824c7d" @@ -4565,7 +4923,7 @@ is-path-inside@^1.0.0: dependencies: path-is-inside "^1.0.1" -is-plain-obj@^1.0.0: +is-plain-obj@^1.0.0, is-plain-obj@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e" @@ -4591,6 +4949,13 @@ is-redirect@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-redirect/-/is-redirect-1.0.0.tgz#1d03dded53bd8db0f30c26e4f95d36fc7c87dc24" +is-reference@^1.1.2: + version "1.1.4" + resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.1.4.tgz#3f95849886ddb70256a3e6d062b1a68c13c51427" + integrity sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw== + dependencies: + "@types/estree" "0.0.39" + is-regex@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491" @@ -4720,20 +5085,43 @@ jest-docblock@^21.0.0: version "21.2.0" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" +jest-worker@^24.0.0: + version "24.9.0" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-24.9.0.tgz#5dbfdb5b2d322e98567898238a9697bcce67b3e5" + integrity sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw== + dependencies: + merge-stream "^2.0.0" + supports-color "^6.1.0" + jodid25519@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/jodid25519/-/jodid25519-1.0.2.tgz#06d4912255093419477d425633606e0e90782967" dependencies: jsbn "~0.1.0" +jquery@^3.4.1: + version "3.4.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.1.tgz#714f1f8d9dde4bdfa55764ba37ef214630d80ef2" + integrity sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw== + js-base64@^2.1.9: version "2.4.3" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.3.tgz#2e545ec2b0f2957f41356510205214e98fad6582" +js-levenshtein@^1.1.3: + version "1.1.6" + resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d" + integrity sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g== + js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" +js-tokens@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" + integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== + js-yaml@3.13.1: version "3.13.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" @@ -4789,9 +5177,10 @@ jsdom@^11.5.1: whatwg-url "^6.3.0" xml-name-validator "^2.0.1" -jsesc@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" +jsesc@^2.5.1: + version "2.5.2" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4" + integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== jsesc@~0.5.0: version "0.5.0" @@ -4835,6 +5224,13 @@ json5@^0.5.0, json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" +json5@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.1.tgz#81b6cb04e9ba496f1c7005d07b4368a2638f90b6" + integrity sha512-l+3HXD0GEI3huGq1njuqtzYK8OYJyXMkOLtQ53pjWh89tvWS2h6l+1zMkYWqlb57+SiQodKZyvMEFb2X+KrFhQ== + dependencies: + minimist "^1.2.0" + jsonfile@^2.1.0: version "2.4.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" @@ -5118,6 +5514,13 @@ locate-path@^3.0.0: p-locate "^3.0.0" path-exists "^3.0.0" +locate-path@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" + integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g== + dependencies: + p-locate "^4.1.0" + lodash._reinterpolate@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" @@ -5151,6 +5554,11 @@ lodash.templatesettings@^4.0.0: dependencies: lodash._reinterpolate "~3.0.0" +lodash.unescape@4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" + integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw= + lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" @@ -5168,6 +5576,11 @@ lodash@^4.17.11: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== +lodash@^4.17.13, lodash@^4.17.15: + version "4.17.15" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" + integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== + log-symbols@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a" @@ -5219,21 +5632,28 @@ ltgt@^2.1.2: version "2.2.0" resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.0.tgz#b65ba5fcb349a29924c8e333f7c6a5562f2e4842" +lunr@^2.3.6: + version "2.3.7" + resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.7.tgz#05ccf3af9d0e169b8f432c97e02fc1bdf3f36343" + integrity sha512-HjFSiy0Y0qZoW5OA1I6qBi7OnsDdqQnaUr03jhorh30maQoaP+4lQCKklYE3Nq3WJMSUfuBl6N+bKY5wxCb9hw== + macaddress@^0.2.8: version "0.2.8" resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12" -magic-string@^0.16.0: - version "0.16.0" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.16.0.tgz#970ebb0da7193301285fb1aa650f39bdd81eb45a" +magic-string@^0.22.5: + version "0.22.5" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.22.5.tgz#8e9cf5afddf44385c1da5bc2a6a0dbd10b03657e" + integrity sha512-oreip9rJZkzvA8Qzk9HFs8fZGF/u7H/gtrE8EN6RjKJ9kh2HlC+yQ2QezifqTZfGyiuAV0dRv5a+y/8gBb1m9w== dependencies: - vlq "^0.2.1" + vlq "^0.2.2" -magic-string@^0.22.4: - version "0.22.4" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.22.4.tgz#31039b4e40366395618c1d6cf8193c53917475ff" +magic-string@^0.25.2: + version "0.25.4" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.4.tgz#325b8a0a79fc423db109b77fd5a19183b7ba5143" + integrity sha512-oycWO9nEVAP2RVPbIoDoA4Y7LFIJ3xRYov93gAyJhZkET1tNuB0u7uWkZS2LpBWTJUWnmau/To8ECWRC+jKNfw== dependencies: - vlq "^0.2.1" + sourcemap-codec "^1.4.4" make-dir@^1.0.0: version "1.1.0" @@ -5241,6 +5661,21 @@ make-dir@^1.0.0: dependencies: pify "^3.0.0" +make-dir@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5" + integrity sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA== + dependencies: + pify "^4.0.1" + semver "^5.6.0" + +make-dir@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.0.0.tgz#1b5f39f6b9270ed33f9f054c5c0f84304989f801" + integrity sha512-grNJDhb8b1Jm1qeqW5R/O63wUo4UXo2v2HMic6YT9i/HBlF93S8jkMgH7yugvY9ABDShH4VZMn8I+U8+fCNegw== + dependencies: + semver "^6.0.0" + map-age-cleaner@^0.1.1: version "0.1.3" resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a" @@ -5266,12 +5701,10 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" -matcha@^0.7.0: +marked@^0.7.0: version "0.7.0" - resolved "https://registry.yarnpkg.com/matcha/-/matcha-0.7.0.tgz#13f805409b37be57032c8458643bf1523ba68dda" - dependencies: - electron "0.4.x" - v8-argv "0.1.x" + resolved "https://registry.yarnpkg.com/marked/-/marked-0.7.0.tgz#b64201f051d271b1edc10a04d1ae9b74bb8e5c0e" + integrity sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg== math-expression-evaluator@^1.2.14: version "1.2.17" @@ -5337,6 +5770,11 @@ merge-descriptors@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" +merge-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" + integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== + methods@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" @@ -5359,7 +5797,7 @@ micromatch@^2.1.5, micromatch@^2.3.11: parse-glob "^3.0.4" regex-cache "^0.4.2" -micromatch@^3.1.4: +micromatch@^3.1.10, micromatch@^3.1.4: version "3.1.10" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23" dependencies: @@ -5458,6 +5896,21 @@ minimist@^1.1.3, minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" +minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.9.0.tgz#e713762e7d3e32fed803115cf93e04bca9fcc9a6" + integrity sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg== + dependencies: + safe-buffer "^5.1.2" + yallist "^3.0.0" + +minizlib@^1.2.1: + version "1.3.3" + resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.3.3.tgz#2290de96818a34c29551c8a8d301216bd65a861d" + integrity sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q== + dependencies: + minipass "^2.9.0" + mississippi@^1.3.0: version "1.3.1" resolved "https://registry.yarnpkg.com/mississippi/-/mississippi-1.3.1.tgz#2a8bb465e86550ac8b36a7b6f45599171d78671e" @@ -5499,16 +5952,12 @@ mkdirp@0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e" -mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: +mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" dependencies: minimist "0.0.8" -mocha-lcov-reporter@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/mocha-lcov-reporter/-/mocha-lcov-reporter-1.3.0.tgz#469bdef4f8afc9a116056f079df6182d0afb0384" - mocha@^2.5.3: version "2.5.3" resolved "https://registry.yarnpkg.com/mocha/-/mocha-2.5.3.tgz#161be5bdeb496771eb9b35745050b622b5aefc58" @@ -5613,6 +6062,11 @@ mz@^2.3.1: object-assign "^4.0.1" thenify-all "^1.0.0" +nan@^2.12.1: + version "2.14.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" + integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== + nan@^2.3.0: version "2.8.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a" @@ -5643,10 +6097,24 @@ ncname@1.0.x: dependencies: xml-char-classes "^1.0.0" +needle@^2.2.1: + version "2.4.0" + resolved "https://registry.yarnpkg.com/needle/-/needle-2.4.0.tgz#6833e74975c444642590e15a750288c5f939b57c" + integrity sha512-4Hnwzr3mi5L97hMYeNl8wRW/Onhy4nUKR/lVemJ8gJedxxUyBLm9kkrDColJvoSfwi0jCNhD+xCdOtiGDQiRZg== + dependencies: + debug "^3.2.6" + iconv-lite "^0.4.4" + sax "^1.2.4" + negotiator@0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" +neo-async@^2.6.0: + version "2.6.1" + resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c" + integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw== + nice-try@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" @@ -5705,6 +6173,27 @@ node-libs-browser@^2.0.0: util "^0.10.3" vm-browserify "0.0.4" +node-modules-regexp@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40" + integrity sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA= + +node-pre-gyp@^0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz#39ba4bb1439da030295f899e3b520b7785766149" + integrity sha512-4KghwV8vH5k+g2ylT+sLTjy5wmUOb9vPhnM8NHvRf9dHmnW/CndrFXy2aRPaPST6dugXSdHXfeaHQm77PIz/1A== + dependencies: + detect-libc "^1.0.2" + mkdirp "^0.5.1" + needle "^2.2.1" + nopt "^4.0.1" + npm-packlist "^1.1.6" + npmlog "^4.0.2" + rc "^1.2.7" + rimraf "^2.6.1" + semver "^5.3.0" + tar "^4" + node-pre-gyp@^0.6.39: version "0.6.39" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.39.tgz#c00e96860b23c0e1420ac7befc5044e1d78d8649" @@ -5721,6 +6210,13 @@ node-pre-gyp@^0.6.39: tar "^2.2.1" tar-pack "^3.4.0" +node-releases@^1.1.29: + version "1.1.35" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.35.tgz#32a74a3cd497aa77f23d509f483475fd160e4c48" + integrity sha512-JGcM/wndCN/2elJlU0IGdVEJQQnJwsLbgPCFd2pY7V0mxf17bZ0Gb/lgOtL29ZQhvEX5shnVhxQyZz3ex94N8w== + dependencies: + semver "^6.3.0" + nopt@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d" @@ -5743,6 +6239,11 @@ normalize-path@^2.0.0, normalize-path@^2.0.1, normalize-path@^2.1.1: dependencies: remove-trailing-separator "^1.0.1" +normalize-path@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" + integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== + normalize-range@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/normalize-range/-/normalize-range-0.1.2.tgz#2d10c06bdfd312ea9777695a4d28439456b75942" @@ -5756,6 +6257,19 @@ normalize-url@^1.4.0: query-string "^4.1.0" sort-keys "^1.0.0" +npm-bundled@^1.0.1: + version "1.0.6" + resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.6.tgz#e7ba9aadcef962bb61248f91721cd932b3fe6bdd" + integrity sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g== + +npm-packlist@^1.1.6: + version "1.4.6" + resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.4.6.tgz#53ba3ed11f8523079f1457376dd379ee4ea42ff4" + integrity sha512-u65uQdb+qwtGvEJh/DgQgW1Xg7sqeNbmxYyrvlNznaVTjV3E5P6F/EFjM+BVHXl7JJlsdG8A64M0XI8FI/IOlg== + dependencies: + ignore-walk "^3.0.1" + npm-bundled "^1.0.1" + npm-run-all@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/npm-run-all/-/npm-run-all-4.1.2.tgz#90d62d078792d20669139e718621186656cea056" @@ -5824,7 +6338,7 @@ object-keys@^1.0.11, object-keys@^1.0.12: resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== -object-keys@^1.0.6, object-keys@^1.0.8: +object-keys@^1.0.8: version "1.0.12" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.12.tgz#09c53855377575310cca62f55bb334abff7b3ed2" @@ -5846,7 +6360,7 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" -object.assign@4.1.0: +object.assign@4.1.0, object.assign@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.0.tgz#968bf1100d7956bb3ca086f006f846b3bc4008da" integrity sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w== @@ -5968,7 +6482,7 @@ os-locale@^3.0.0, os-locale@^3.1.0: lcid "^2.0.0" mem "^4.0.0" -os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.2: +os-tmpdir@^1.0.0, os-tmpdir@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" @@ -5979,13 +6493,14 @@ osenv@^0.1.4: os-homedir "^1.0.0" os-tmpdir "^1.0.0" -output-file-sync@^1.1.2: - version "1.1.2" - resolved "https://registry.yarnpkg.com/output-file-sync/-/output-file-sync-1.1.2.tgz#d0a33eefe61a205facb90092e826598d5245ce76" +output-file-sync@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/output-file-sync/-/output-file-sync-2.0.1.tgz#f53118282f5f553c2799541792b723a4c71430c0" + integrity sha512-mDho4qm7WgIXIGf4eYU1RHN2UU5tPfVYVSRwDJw0uTmj35DQUt/eNp19N7v6T3SrR0ESTEf2up2CGO73qI35zQ== dependencies: - graceful-fs "^4.1.4" + graceful-fs "^4.1.11" + is-plain-obj "^1.1.0" mkdirp "^0.5.1" - object-assign "^4.1.0" p-defer@^1.0.0: version "1.0.0" @@ -6007,7 +6522,7 @@ p-limit@^1.0.0, p-limit@^1.1.0: dependencies: p-try "^1.0.0" -p-limit@^2.0.0: +p-limit@^2.0.0, p-limit@^2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.2.1.tgz#aa07a788cc3151c939b5131f63570f0dd2009537" integrity sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg== @@ -6027,6 +6542,13 @@ p-locate@^3.0.0: dependencies: p-limit "^2.0.0" +p-locate@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" + integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A== + dependencies: + p-limit "^2.2.0" + p-map@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b" @@ -6135,7 +6657,12 @@ path-exists@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" -path-is-absolute@^1.0.0, path-is-absolute@^1.0.1: +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + +path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -6151,6 +6678,11 @@ path-parse@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" +path-parse@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + path-to-regexp@0.1.7: version "0.1.7" resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" @@ -6213,6 +6745,11 @@ pify@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" +pify@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231" + integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g== + pinkie-promise@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa" @@ -6223,6 +6760,13 @@ pinkie@^2.0.0: version "2.0.4" resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" +pirates@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87" + integrity sha512-WuNqLTbMI3tmfef2TKxlQmAiLHKtFhlsCZnPIpuv2Ow0RDVO8lfy1Opf4NUzlMXLjPl+Men7AuVdX6TA+s+uGA== + dependencies: + node-modules-regexp "^1.0.0" + pkg-dir@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4" @@ -6235,6 +6779,20 @@ pkg-dir@^2.0.0: dependencies: find-up "^2.1.0" +pkg-dir@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3" + integrity sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw== + dependencies: + find-up "^3.0.0" + +pkg-dir@^4.1.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3" + integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ== + dependencies: + find-up "^4.0.0" + pkg-up@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-2.0.0.tgz#c819ac728059a461cab1c3889a2be3c49a004d7f" @@ -6536,11 +7094,11 @@ prismjs@^1.5.1: optionalDependencies: clipboard "^1.5.5" -private@^0.1.6, private@^0.1.7: +private@^0.1.6: version "0.1.8" resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" -process-es6@^0.11.2, process-es6@^0.11.3: +process-es6@^0.11.2, process-es6@^0.11.6: version "0.11.6" resolved "https://registry.yarnpkg.com/process-es6/-/process-es6-0.11.6.tgz#c6bb389f9a951f82bd4eb169600105bd2ff9c778" @@ -6560,6 +7118,11 @@ progress@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f" +progress@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" + integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== + promise-inflight@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" @@ -6754,6 +7317,16 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.1.7: minimist "^1.2.0" strip-json-comments "~2.0.1" +rc@^1.2.7: + version "1.2.8" + resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" + integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== + dependencies: + deep-extend "^0.6.0" + ini "~1.3.0" + minimist "^1.2.0" + strip-json-comments "~2.0.1" + react-deep-force-update@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-2.1.1.tgz#8ea4263cd6455a050b37445b3f08fd839d86e909" @@ -6924,6 +7497,22 @@ readdirp@^2.0.0: readable-stream "^2.0.2" set-immediate-shim "^1.0.1" +readdirp@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-2.2.1.tgz#0e87622a3325aa33e892285caf8b4e846529a525" + integrity sha512-1JU/8q+VgFZyxwrJ+SVIOsh+KywWGpds3NTqikiKpDMZWScmAYyKIgqkO+ARvNWJfXeXR1zxz7aHF4u4CyH6vQ== + dependencies: + graceful-fs "^4.1.11" + micromatch "^3.1.10" + readable-stream "^2.0.2" + +rechoir@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" + integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= + dependencies: + resolve "^1.1.6" + redbox-react@^1.3.6: version "1.5.0" resolved "https://registry.yarnpkg.com/redbox-react/-/redbox-react-1.5.0.tgz#04dab11557d26651bf3562a67c22ace56c5d3967" @@ -6954,24 +7543,32 @@ reduce-function-call@^1.0.1: dependencies: balanced-match "^0.4.2" +regenerate-unicode-properties@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e" + integrity sha512-LGZzkgtLY79GeXLm8Dp0BVLdQlWICzBnJz/ipWUgo59qBaZ+BHtq51P2q1uVZlppMuUAT37SDk39qUbjTWB7bA== + dependencies: + regenerate "^1.4.0" + regenerate@^1.2.1: version "1.3.3" resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.3.tgz#0c336d3980553d755c39b586ae3b20aa49c82b7f" -regenerator-runtime@^0.10.5: - version "0.10.5" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" +regenerate@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" + integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== -regenerator-runtime@^0.11.0: - version "0.11.1" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" +regenerator-runtime@^0.13.2: + version "0.13.3" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5" + integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw== -regenerator-transform@^0.10.0: - version "0.10.1" - resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.10.1.tgz#1e4996837231da8b7f3cf4114d71b5691a0680dd" +regenerator-transform@^0.14.0: + version "0.14.1" + resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.1.tgz#3b2fce4e1ab7732c08f665dfdb314749c7ddd2fb" + integrity sha512-flVuee02C3FKRISbxhXl9mGzdbWUVHubl1SMaknjxkFB1/iqpJhArQUvRxOOPEc/9tAiX0BaQ28FJH10E4isSQ== dependencies: - babel-runtime "^6.18.0" - babel-types "^6.19.0" private "^0.1.6" regex-cache@^0.4.2: @@ -6998,6 +7595,11 @@ regexpp@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-1.1.0.tgz#0e3516dd0b7904f413d2d4193dce4618c3a689ab" +regexpp@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" + integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== + regexpu-core@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-1.0.0.tgz#86a763f58ee4d7c2f6b102e4764050de7ed90c6b" @@ -7006,13 +7608,17 @@ regexpu-core@^1.0.0: regjsgen "^0.2.0" regjsparser "^0.1.4" -regexpu-core@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-2.0.0.tgz#49d038837b8dcf8bfa5b9a42139938e6ea2ae240" +regexpu-core@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-4.6.0.tgz#2037c18b327cfce8a6fea2a4ec441f2432afb8b6" + integrity sha512-YlVaefl8P5BnFYOITTNzDvan1ulLOiXJzCNZxduTIosN17b87h3bvG9yHMoHaRuo88H4mQ06Aodj5VtYGGGiTg== dependencies: - regenerate "^1.2.1" - regjsgen "^0.2.0" - regjsparser "^0.1.4" + regenerate "^1.4.0" + regenerate-unicode-properties "^8.1.0" + regjsgen "^0.5.0" + regjsparser "^0.6.0" + unicode-match-property-ecmascript "^1.0.4" + unicode-match-property-value-ecmascript "^1.1.0" registry-auth-token@^3.0.1: version "3.3.1" @@ -7031,12 +7637,24 @@ regjsgen@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/regjsgen/-/regjsgen-0.2.0.tgz#6c016adeac554f75823fe37ac05b92d5a4edb1f7" +regjsgen@^0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/regjsgen/-/regjsgen-0.5.0.tgz#a7634dc08f89209c2049adda3525711fb97265dd" + integrity sha512-RnIrLhrXCX5ow/E5/Mh2O4e/oa1/jW0eaBKTSy3LaCj+M3Bqvm97GWDp2yUtzIs4LEn65zR2yiYGFqb2ApnzDA== + regjsparser@^0.1.4: version "0.1.5" resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.1.5.tgz#7ee8f84dc6fa792d3fd0ae228d24bd949ead205c" dependencies: jsesc "~0.5.0" +regjsparser@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.6.0.tgz#f1e6ae8b7da2bae96c99399b868cd6c933a2ba9c" + integrity sha512-RQ7YyokLiQBomUJuUG8iGVvkgOLxwyZM8k6d3q5SAXpg4r5TZJZigKFvC6PpD+qQ98bCDC5YelPeA3EucDoNeQ== + dependencies: + jsesc "~0.5.0" + relateurl@0.2.x: version "0.2.7" resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" @@ -7189,6 +7807,13 @@ resolve-url@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" +resolve@1.12.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.3.2, resolve@^1.8.1: + version "1.12.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.0.tgz#3fc644a35c84a48554609ff26ec52b66fa577df6" + integrity sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w== + dependencies: + path-parse "^1.0.6" + resolve@^1.1.6, resolve@^1.4.0, resolve@^1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36" @@ -7231,27 +7856,31 @@ rollup-plugin-alias@^1.4.0: dependencies: slash "^1.0.0" -rollup-plugin-babel@^3.0.3: - version "3.0.3" - resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-3.0.3.tgz#63adedc863130327512a4a9006efc2241c5b7c15" +rollup-plugin-babel@^4.3.3: + version "4.3.3" + resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-4.3.3.tgz#7eb5ac16d9b5831c3fd5d97e8df77ba25c72a2aa" + integrity sha512-tKzWOCmIJD/6aKNz0H1GMM+lW1q9KyFubbWzGiOG540zxPPifnEAHTZwjo0g991Y+DyOZcLqBgqOdqazYE5fkw== dependencies: - rollup-pluginutils "^1.5.0" + "@babel/helper-module-imports" "^7.0.0" + rollup-pluginutils "^2.8.1" -rollup-plugin-commonjs@^8.3.0: - version "8.3.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-8.3.0.tgz#91b4ba18f340951e39ed7b1901f377a80ab3f9c3" +rollup-plugin-commonjs@^10.1.0: + version "10.1.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz#417af3b54503878e084d127adf4d1caf8beb86fb" + integrity sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q== dependencies: - acorn "^5.2.1" - estree-walker "^0.5.0" - magic-string "^0.22.4" - resolve "^1.4.0" - rollup-pluginutils "^2.0.1" + estree-walker "^0.6.1" + is-reference "^1.1.2" + magic-string "^0.25.2" + resolve "^1.11.0" + rollup-pluginutils "^2.8.1" -rollup-plugin-json@^2.3.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-json/-/rollup-plugin-json-2.3.0.tgz#3c07a452c1b5391be28006fbfff3644056ce0add" +rollup-plugin-json@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-json/-/rollup-plugin-json-4.0.0.tgz#a18da0a4b30bf5ca1ee76ddb1422afbb84ae2b9e" + integrity sha512-hgb8N7Cgfw5SZAkb3jf0QXii6QX/FOkiIq2M7BAQIEydjHvTyxXHQiIzZaTFgx1GK0cRCHOCBHIyEkkLdWKxow== dependencies: - rollup-pluginutils "^2.0.1" + rollup-pluginutils "^2.5.0" rollup-plugin-node-builtins@^2.1.2: version "2.1.2" @@ -7262,32 +7891,36 @@ rollup-plugin-node-builtins@^2.1.2: crypto-browserify "^3.11.0" process-es6 "^0.11.2" -rollup-plugin-node-globals@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-node-globals/-/rollup-plugin-node-globals-1.1.0.tgz#7efd8d611d132737829e804e9f51f50962af451f" +rollup-plugin-node-globals@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-node-globals/-/rollup-plugin-node-globals-1.4.0.tgz#5e1f24a9bb97c0ef51249f625e16c7e61b7c020b" + integrity sha512-xRkB+W/m1KLIzPUmG0ofvR+CPNcvuCuNdjVBVS7ALKSxr3EDhnzNceGkGi1m8MToSli13AzKFYH4ie9w3I5L3g== dependencies: - acorn "^4.0.1" - buffer-es6 "^4.9.1" - estree-walker "^0.2.1" - magic-string "^0.16.0" - process-es6 "^0.11.3" - rollup-pluginutils "^1.5.2" + acorn "^5.7.3" + buffer-es6 "^4.9.3" + estree-walker "^0.5.2" + magic-string "^0.22.5" + process-es6 "^0.11.6" + rollup-pluginutils "^2.3.1" -rollup-plugin-node-resolve@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.0.2.tgz#38babc12fd404cc2ba1ff68648fe43fa3ffee6b0" +rollup-plugin-node-resolve@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523" + integrity sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw== dependencies: - builtin-modules "^1.1.0" + "@types/resolve" "0.0.8" + builtin-modules "^3.1.0" is-module "^1.0.0" - resolve "^1.1.6" + resolve "^1.11.1" + rollup-pluginutils "^2.8.1" -rollup-plugin-replace@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-replace/-/rollup-plugin-replace-2.0.0.tgz#19074089c8ed57184b8cc64e967a03d095119277" +rollup-plugin-replace@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-replace/-/rollup-plugin-replace-2.2.0.tgz#f41ae5372e11e7a217cde349c8b5d5fd115e70e3" + integrity sha512-/5bxtUPkDHyBJAKketb4NfaeZjL5yLZdeUihSfbF2PQMz+rSTEb8ARKoOl3UBT4m7/X+QOXJo3sLTcq+yMMYTA== dependencies: - magic-string "^0.22.4" - minimatch "^3.0.2" - rollup-pluginutils "^2.0.1" + magic-string "^0.25.2" + rollup-pluginutils "^2.6.0" rollup-plugin-sourcemaps@^0.4.2: version "0.4.2" @@ -7296,18 +7929,33 @@ rollup-plugin-sourcemaps@^0.4.2: rollup-pluginutils "^2.0.1" source-map-resolve "^0.5.0" -rollup-plugin-uglify@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-3.0.0.tgz#a34eca24617709c6bf1778e9653baafa06099b86" +rollup-plugin-typescript2@^0.24.3: + version "0.24.3" + resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.24.3.tgz#276fa33a9d584d500da62d3e5400307f4a46bdf2" + integrity sha512-D7yovQlhnRoz7pG/RF0ni+koxgzEShwfAGuOq6OVqKzcATHOvmUt2ePeYVdc9N0adcW1PcTzklUEM0oNWE/POw== dependencies: - uglify-es "^3.3.7" + find-cache-dir "^3.0.0" + fs-extra "8.1.0" + resolve "1.12.0" + rollup-pluginutils "2.8.1" + tslib "1.10.0" -rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.2: - version "1.5.2" - resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408" +rollup-plugin-uglify@^6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.3.tgz#e3f776171344b580bec6c6ab8888622b67099457" + integrity sha512-PIv3CfhZJlOG8C85N0GX+uK09TPggmAS6Nk6fpp2ELzDAV5VUhNzOURDU2j7+MwuRr0zq9IZttUTADc/jH8Gkg== dependencies: - estree-walker "^0.2.1" - minimatch "^3.0.2" + "@babel/code-frame" "^7.0.0" + jest-worker "^24.0.0" + serialize-javascript "^1.9.0" + uglify-js "^3.4.9" + +rollup-pluginutils@2.8.1: + version "2.8.1" + resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz#8fa6dd0697344938ef26c2c09d2488ce9e33ce97" + integrity sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg== + dependencies: + estree-walker "^0.6.1" rollup-pluginutils@^2.0.1: version "2.0.1" @@ -7316,9 +7964,21 @@ rollup-pluginutils@^2.0.1: estree-walker "^0.3.0" micromatch "^2.3.11" -rollup@^0.55.1: - version "0.55.1" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.55.1.tgz#baf4f23abe3014b29e56dea7d72d9946e56ac7dd" +rollup-pluginutils@^2.3.1, rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.8.1: + version "2.8.2" + resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" + integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ== + dependencies: + estree-walker "^0.6.1" + +rollup@^1.23.1: + version "1.23.1" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-1.23.1.tgz#0315a0f5d0dfb056e6363e1dff05b89ac2da6b8e" + integrity sha512-95C1GZQpr/NIA0kMUQmSjuMDQ45oZfPgDBcN0yZwBG7Kee//m7H68vgIyg+SPuyrTZ5PrXfyLK80OzXeKG5dAA== + dependencies: + "@types/estree" "*" + "@types/node" "*" + acorn "^7.1.0" run-async@^2.2.0: version "2.3.0" @@ -7346,6 +8006,11 @@ safe-buffer@5.1.1, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, s version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" +safe-buffer@^5.1.2: + version "5.2.0" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519" + integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg== + safe-regex@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/safe-regex/-/safe-regex-1.1.0.tgz#40a3669f3b077d1e943d44629e157dd48023bf2e" @@ -7360,6 +8025,11 @@ sax@^1.2.1, sax@~1.2.1: version "1.2.2" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828" +sax@^1.2.4: + version "1.2.4" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" + integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== + scheduler@^0.11.2: version "0.11.2" resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.11.2.tgz#a8db5399d06eba5abac51b705b7151d2319d33d3" @@ -7410,11 +8080,16 @@ selfsigned@^1.9.1: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" -semver@^5.5.0, semver@^5.7.0: +semver@^5.5.0, semver@^5.5.1, semver@^5.6.0, semver@^5.7.0: version "5.7.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== +semver@^6.0.0, semver@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" + integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + semver@~2.3.1: version "2.3.2" resolved "https://registry.yarnpkg.com/semver/-/semver-2.3.2.tgz#b9848f25d6cf36333073ec9ef8856d42f1233e52" @@ -7441,6 +8116,11 @@ serialize-javascript@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.4.0.tgz#7c958514db6ac2443a8abc062dc9f7886a7f6005" +serialize-javascript@^1.9.0: + version "1.9.1" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-1.9.1.tgz#cfc200aef77b600c47da9bb8149c943e798c2fdb" + integrity sha512-0Vb/54WJ6k5v8sSWN09S0ora+Hnr+cX40r9F170nT+mSkaxltoE/7R3OrIdBSUv1OoiobH1QoWQbCnAO+e8J1A== + serve-index@^1.7.2: version "1.9.1" resolved "https://registry.yarnpkg.com/serve-index/-/serve-index-1.9.1.tgz#d3768d69b1e7d82e5ce050fff5b453bea12a9239" @@ -7532,6 +8212,15 @@ shell-quote@^1.6.1: array-reduce "~0.0.0" jsonify "~0.0.0" +shelljs@^0.8.3: + version "0.8.3" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097" + integrity sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A== + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + sigmund@~1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" @@ -7544,6 +8233,11 @@ slash@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" +slash@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" + integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A== + slice-ansi@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-1.0.0.tgz#044f1a49d8842ff307aad6b505ed178bd950134d" @@ -7641,11 +8335,13 @@ source-map-support@^0.4.0: dependencies: source-map "^0.5.6" -source-map-support@^0.4.15: - version "0.4.18" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" +source-map-support@^0.5.9: + version "0.5.13" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932" + integrity sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w== dependencies: - source-map "^0.5.6" + buffer-from "^1.0.0" + source-map "^0.6.0" source-map-url@^0.4.0: version "0.4.0" @@ -7655,7 +8351,7 @@ source-map@0.5.6, source-map@^0.5.3, source-map@^0.5.6: version "0.5.6" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" -source-map@0.5.x, source-map@^0.5.7, source-map@~0.5.1, source-map@~0.5.6: +source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.7, source-map@~0.5.1, source-map@~0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -7665,10 +8361,15 @@ source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@^0.6.1, source-map@~0.6.1: +source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" +sourcemap-codec@^1.4.4: + version "1.4.6" + resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz#e30a74f0402bad09807640d39e971090a08ce1e9" + integrity sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg== + sourcemapped-stacktrace@^1.1.6: version "1.1.8" resolved "https://registry.yarnpkg.com/sourcemapped-stacktrace/-/sourcemapped-stacktrace-1.1.8.tgz#6b7a3f1a6fb15f6d40e701e23ce404553480d688" @@ -7979,6 +8680,13 @@ supports-color@^5.2.0, supports-color@^5.3.0: dependencies: has-flag "^3.0.0" +supports-color@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3" + integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ== + dependencies: + has-flag "^3.0.0" + svgo@^0.7.0: version "0.7.2" resolved "https://registry.yarnpkg.com/svgo/-/svgo-0.7.2.tgz#9f5772413952135c6fefbf40afe6a4faa88b4bb5" @@ -8031,9 +8739,18 @@ tar@^2.2.1: fstream "^1.0.2" inherits "2" -tea-concat@0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/tea-concat/-/tea-concat-0.1.0.tgz#ea2e907400fdd78a6334ce020fa3c69502d99e84" +tar@^4: + version "4.4.13" + resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.13.tgz#43b364bc52888d555298637b10d60790254ab525" + integrity sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA== + dependencies: + chownr "^1.1.1" + fs-minipass "^1.2.5" + minipass "^2.8.6" + minizlib "^1.2.1" + mkdirp "^0.5.0" + safe-buffer "^5.1.2" + yallist "^3.0.3" temp-dir@^1.0.0: version "1.0.0" @@ -8134,10 +8851,6 @@ to-camel-case@^1.0.0: dependencies: to-space-case "^1.0.0" -to-fast-properties@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" - to-fast-properties@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" @@ -8208,9 +8921,17 @@ trim-off-newlines@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" -trim-right@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" +tslib@1.10.0, tslib@^1.8.1: + version "1.10.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" + integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== + +tsutils@^3.17.1: + version "3.17.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759" + integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g== + dependencies: + tslib "^1.8.1" tty-browserify@0.0.0: version "0.0.0" @@ -8251,11 +8972,26 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" +typedoc-default-themes@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/typedoc-default-themes/-/typedoc-default-themes-0.6.0.tgz#7e73bf54dd9e11550dd0fb576d5176b758f8f8b5" + integrity sha512-MdTROOojxod78CEv22rIA69o7crMPLnVZPefuDLt/WepXqJwgiSu8Xxq+H36x0Jj3YGc7lOglI2vPJ2GhoOybw== + dependencies: + backbone "^1.4.0" + jquery "^3.4.1" + lunr "^2.3.6" + underscore "^1.9.1" + +typescript@3.6.x, typescript@^3.6.4: + version "3.6.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d" + integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg== + ua-parser-js@^0.7.9: version "0.7.12" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb" -uglify-es@^3.3.4, uglify-es@^3.3.7: +uglify-es@^3.3.4: version "3.3.8" resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.8.tgz#f2c68e6cff0d0f9dc9577e4da207151c2e753b7e" dependencies: @@ -8278,6 +9014,14 @@ uglify-js@^2.6, uglify-js@^2.8.29: optionalDependencies: uglify-to-browserify "~1.0.0" +uglify-js@^3.1.4, uglify-js@^3.4.9: + version "3.6.1" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.6.1.tgz#ae7688c50e1bdcf2f70a0e162410003cf9798311" + integrity sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ== + dependencies: + commander "2.20.0" + source-map "~0.6.1" + uglify-to-browserify@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7" @@ -8307,6 +9051,34 @@ uid-number@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81" +underscore@>=1.8.3, underscore@^1.9.1: + version "1.9.1" + resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961" + integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg== + +unicode-canonical-property-names-ecmascript@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" + integrity sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ== + +unicode-match-property-ecmascript@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz#8ed2a32569961bce9227d09cd3ffbb8fed5f020c" + integrity sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg== + dependencies: + unicode-canonical-property-names-ecmascript "^1.0.4" + unicode-property-aliases-ecmascript "^1.0.4" + +unicode-match-property-value-ecmascript@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.1.0.tgz#5b4b426e08d13a80365e0d657ac7a6c1ec46a277" + integrity sha512-hDTHvaBk3RmFzvSl0UVrUmC3PuW9wKVnpoUDYH0JDkSIovzw+J5viQmeYHxVSBptubnr7PbH2e0fnpDRQnQl5g== + +unicode-property-aliases-ecmascript@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.5.tgz#a9cc6cc7ce63a0a3023fc99e341b94431d405a57" + integrity sha512-L5RAqCfXqAwR3RriF8pM0lU0w4Ryf/GgzONwi6KnL1taJQa7x1TCxdJnILX59WIGOwR57IVxn7Nej0fz1Ny6fw== + union-value@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4" @@ -8365,6 +9137,11 @@ upath@^1.0.0: version "1.0.5" resolved "https://registry.yarnpkg.com/upath/-/upath-1.0.5.tgz#02cab9ecebe95bbec6d5fc2566325725ab6d1a73" +upath@^1.1.1: + version "1.2.0" + resolved "https://registry.yarnpkg.com/upath/-/upath-1.2.0.tgz#8f66dbcd55a883acdae4408af8b035a5044c1894" + integrity sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg== + upper-case@^1.1.1: version "1.1.3" resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-1.1.3.tgz#f6b4501c2ec4cdd26ba78be7222961de77621598" @@ -8412,10 +9189,6 @@ use@^2.0.0: isobject "^3.0.0" lazy-cache "^2.0.2" -user-home@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190" - util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" @@ -8446,16 +9219,6 @@ uuid@^3.0.0, uuid@^3.0.1, uuid@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" -v8-argv@0.1.x: - version "0.1.0" - resolved "https://registry.yarnpkg.com/v8-argv/-/v8-argv-0.1.0.tgz#adf777a52dbdc3da9c89c9465e59ed5f3cb6d9a9" - -v8flags@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.1.1.tgz#aab1a1fa30d45f88dd321148875ac02c0b55e5b4" - dependencies: - user-home "^1.1.1" - validate-npm-package-license@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" @@ -8481,9 +9244,10 @@ verror@1.3.6: dependencies: extsprintf "1.0.2" -vlq@^0.2.1: +vlq@^0.2.2: version "0.2.3" resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26" + integrity sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow== vm-browserify@0.0.4: version "0.0.4" @@ -8748,7 +9512,7 @@ xtend@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/xtend/-/xtend-2.2.0.tgz#eef6b1f198c1c8deafad8b1765a04dad4a01c5a9" -xtend@^4.0.0, xtend@~4.0.0, xtend@~4.0.1: +xtend@^4.0.0, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" @@ -8781,6 +9545,11 @@ yallist@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" +yallist@^3.0.0, yallist@^3.0.3: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" + integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== + yaml-js@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/yaml-js/-/yaml-js-0.0.8.tgz#87cfa5a9613f48e26005420d6a8ee0da6fe8daec" From 8360df2912b8cca2fa0c72b07fd0280c664cadc9 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 14 Oct 2019 16:38:51 -0400 Subject: [PATCH 028/165] add Point, Path, Range, Annotation tests --- packages/slate-hyperscript/src/creators.ts | 2 - packages/slate-render-plaintext/src/index.ts | 14 +++-- .../test/fixtures/custom-is-inline.js | 20 ++++++++ packages/slate/src/classes/editor.ts | 51 +++++++++++-------- packages/slate/src/interfaces/annotation.ts | 4 +- packages/slate/src/interfaces/change.ts | 1 + packages/slate/src/interfaces/element.ts | 1 + packages/slate/src/interfaces/fragment.ts | 1 + packages/slate/src/interfaces/mark.ts | 11 ++-- packages/slate/src/interfaces/operation.ts | 16 ++++++ packages/slate/src/interfaces/path.ts | 10 ++-- packages/slate/src/interfaces/point.ts | 11 +++- packages/slate/src/interfaces/range.ts | 1 + packages/slate/src/interfaces/selection.ts | 5 +- packages/slate/src/interfaces/text.ts | 1 + packages/slate/src/interfaces/value.ts | 35 ++++++------- packages/slate/test/helpers/index.js | 32 ++++++++++++ packages/slate/test/index.js | 22 +++----- .../Annotation/isAnnotation/annotation.js | 18 +++++++ .../Annotation/isAnnotation/boolean.js | 9 ++++ .../isAnnotation/custom-property.js | 19 +++++++ .../Annotation/isAnnotation/object.js | 9 ++++ .../isAnnotationRecord/annotation.js | 18 +++++++ .../Annotation/isAnnotationRecord/boolean.js | 9 ++++ .../Annotation/isAnnotationRecord/empty.js | 9 ++++ .../Annotation/isAnnotationRecord/full.js | 20 ++++++++ .../test/interfaces/Path/ancestors/reverse.js | 9 ++++ .../test/interfaces/Path/ancestors/success.js | 9 ++++ .../test/interfaces/Path/common/equal.js | 12 +++++ .../slate/test/interfaces/Path/common/root.js | 12 +++++ .../test/interfaces/Path/common/success.js | 12 +++++ .../test/interfaces/Path/compare/above.js | 12 +++++ .../test/interfaces/Path/compare/after.js | 12 +++++ .../test/interfaces/Path/compare/before.js | 12 +++++ .../test/interfaces/Path/compare/below.js | 12 +++++ .../test/interfaces/Path/compare/equal.js | 12 +++++ .../test/interfaces/Path/compare/root.js | 12 +++++ .../test/interfaces/Path/endsAfter/above.js | 12 +++++ .../test/interfaces/Path/endsAfter/after.js | 12 +++++ .../test/interfaces/Path/endsAfter/before.js | 12 +++++ .../test/interfaces/Path/endsAfter/below.js | 12 +++++ .../interfaces/Path/endsAfter/ends-after.js | 12 +++++ .../test/interfaces/Path/endsAfter/ends-at.js | 12 +++++ .../interfaces/Path/endsAfter/ends-before.js | 12 +++++ .../test/interfaces/Path/endsAfter/equal.js | 12 +++++ .../test/interfaces/Path/endsAfter/root.js | 12 +++++ .../test/interfaces/Path/endsAt/above.js | 12 +++++ .../test/interfaces/Path/endsAt/after.js | 12 +++++ .../test/interfaces/Path/endsAt/before.js | 12 +++++ .../test/interfaces/Path/endsAt/ends-after.js | 12 +++++ .../test/interfaces/Path/endsAt/ends-at.js | 12 +++++ .../interfaces/Path/endsAt/ends-before.js | 12 +++++ .../test/interfaces/Path/endsAt/equal.js | 12 +++++ .../slate/test/interfaces/Path/endsAt/root.js | 12 +++++ .../test/interfaces/Path/endsBefore/above.js | 12 +++++ .../test/interfaces/Path/endsBefore/after.js | 12 +++++ .../test/interfaces/Path/endsBefore/before.js | 12 +++++ .../test/interfaces/Path/endsBefore/below.js | 12 +++++ .../interfaces/Path/endsBefore/ends-after.js | 12 +++++ .../interfaces/Path/endsBefore/ends-at.js | 12 +++++ .../interfaces/Path/endsBefore/ends-before.js | 12 +++++ .../test/interfaces/Path/endsBefore/equal.js | 12 +++++ .../test/interfaces/Path/endsBefore/root.js | 12 +++++ .../test/interfaces/Path/equals/above.js | 12 +++++ .../test/interfaces/Path/equals/after.js | 12 +++++ .../test/interfaces/Path/equals/before.js | 12 +++++ .../test/interfaces/Path/equals/below.js | 12 +++++ .../test/interfaces/Path/equals/equal.js | 12 +++++ .../slate/test/interfaces/Path/equals/root.js | 12 +++++ .../test/interfaces/Path/isAfter/above.js | 12 +++++ .../test/interfaces/Path/isAfter/after.js | 12 +++++ .../test/interfaces/Path/isAfter/before.js | 12 +++++ .../test/interfaces/Path/isAfter/below.js | 12 +++++ .../test/interfaces/Path/isAfter/equal.js | 12 +++++ .../Path/isAncestor/above-grandparent.js | 12 +++++ .../Path/isAncestor/above-parent.js | 12 +++++ .../test/interfaces/Path/isAncestor/after.js | 12 +++++ .../test/interfaces/Path/isAncestor/before.js | 12 +++++ .../test/interfaces/Path/isAncestor/below.js | 12 +++++ .../test/interfaces/Path/isAncestor/equal.js | 12 +++++ .../test/interfaces/Path/isBefore/above.js | 12 +++++ .../test/interfaces/Path/isBefore/after.js | 12 +++++ .../test/interfaces/Path/isBefore/before.js | 12 +++++ .../test/interfaces/Path/isBefore/below.js | 12 +++++ .../test/interfaces/Path/isBefore/equal.js | 12 +++++ .../test/interfaces/Path/isChild/above.js | 12 +++++ .../test/interfaces/Path/isChild/after.js | 12 +++++ .../test/interfaces/Path/isChild/before.js | 12 +++++ .../interfaces/Path/isChild/below-child.js | 12 +++++ .../Path/isChild/below-grandchild.js | 12 +++++ .../test/interfaces/Path/isChild/equal.js | 12 +++++ .../interfaces/Path/isDescendant/above.js | 12 +++++ .../interfaces/Path/isDescendant/after.js | 12 +++++ .../interfaces/Path/isDescendant/before.js | 12 +++++ .../Path/isDescendant/below-child.js | 12 +++++ .../Path/isDescendant/below-grandchild.js | 12 +++++ .../interfaces/Path/isDescendant/equal.js | 12 +++++ .../Path/isParent/above-grandparent.js | 12 +++++ .../interfaces/Path/isParent/above-parent.js | 12 +++++ .../test/interfaces/Path/isParent/after.js | 12 +++++ .../test/interfaces/Path/isParent/before.js | 12 +++++ .../test/interfaces/Path/isParent/below.js | 12 +++++ .../test/interfaces/Path/isParent/equal.js | 12 +++++ .../test/interfaces/Path/isPath/boolean.js | 9 ++++ .../test/interfaces/Path/isPath/empty.js | 9 ++++ .../slate/test/interfaces/Path/isPath/full.js | 9 ++++ .../test/interfaces/Path/isPath/strings.js | 9 ++++ .../test/interfaces/Path/isSibling/above.js | 12 +++++ .../Path/isSibling/after-sibling.js | 12 +++++ .../test/interfaces/Path/isSibling/after.js | 12 +++++ .../Path/isSibling/before-sibling.js | 12 +++++ .../test/interfaces/Path/isSibling/before.js | 12 +++++ .../test/interfaces/Path/isSibling/below.js | 12 +++++ .../test/interfaces/Path/isSibling/equal.js | 12 +++++ .../test/interfaces/Path/levels/reverse.js | 9 ++++ .../test/interfaces/Path/levels/success.js | 9 ++++ .../test/interfaces/Path/next/success.js | 9 ++++ .../test/interfaces/Path/parent/success.js | 9 ++++ .../test/interfaces/Path/previous/success.js | 9 ++++ .../interfaces/Path/relative/grandparent.js | 12 +++++ .../test/interfaces/Path/relative/parent.js | 12 +++++ .../test/interfaces/Path/relative/root.js | 12 +++++ .../Point/compare/path-after-offset-after.js | 18 +++++++ .../Point/compare/path-after-offset-before.js | 18 +++++++ .../Point/compare/path-after-offset-equal.js | 18 +++++++ .../Point/compare/path-before-offset-after.js | 18 +++++++ .../compare/path-before-offset-before.js | 18 +++++++ .../Point/compare/path-before-offset-equal.js | 18 +++++++ .../Point/compare/path-equal-offset-after.js | 18 +++++++ .../Point/compare/path-equal-offset-before.js | 18 +++++++ .../Point/compare/path-equal-offset-equal.js | 18 +++++++ .../Point/equals/path-after-offset-after.js | 18 +++++++ .../Point/equals/path-after-offset-before.js | 18 +++++++ .../Point/equals/path-after-offset-equal.js | 18 +++++++ .../Point/equals/path-before-offset-after.js | 18 +++++++ .../Point/equals/path-before-offset-before.js | 18 +++++++ .../Point/equals/path-before-offset-equal.js | 18 +++++++ .../Point/equals/path-equal-offset-after.js | 18 +++++++ .../Point/equals/path-equal-offset-before.js | 18 +++++++ .../Point/equals/path-equal-offset-equal.js | 18 +++++++ .../Point/isAfter/path-after-offset-after.js | 18 +++++++ .../Point/isAfter/path-after-offset-before.js | 18 +++++++ .../Point/isAfter/path-after-offset-equal.js | 18 +++++++ .../Point/isAfter/path-before-offset-after.js | 18 +++++++ .../isAfter/path-before-offset-before.js | 18 +++++++ .../Point/isAfter/path-before-offset-equal.js | 18 +++++++ .../Point/isAfter/path-equal-offset-after.js | 18 +++++++ .../Point/isAfter/path-equal-offset-before.js | 18 +++++++ .../Point/isAfter/path-equal-offset-equal.js | 18 +++++++ .../Point/isAfter/point/offset-after.js | 17 ------- .../Point/isAfter/point/offset-before.js | 17 ------- .../Point/isAfter/point/offset-equal.js | 17 ------- .../Point/isAfter/point/path-after.js | 17 ------- .../Point/isAfter/point/path-before.js | 17 ------- .../Point/isAfter/point/path-equal.js | 17 ------- .../Point/isBefore/path-after-offset-after.js | 18 +++++++ .../isBefore/path-after-offset-before.js | 18 +++++++ .../Point/isBefore/path-after-offset-equal.js | 18 +++++++ .../isBefore/path-before-offset-after.js | 18 +++++++ .../isBefore/path-before-offset-before.js | 18 +++++++ .../isBefore/path-before-offset-equal.js | 18 +++++++ .../Point/isBefore/path-equal-offset-after.js | 18 +++++++ .../isBefore/path-equal-offset-before.js | 18 +++++++ .../Point/isBefore/path-equal-offset-equal.js | 18 +++++++ .../test/interfaces/Point/isPoint/boolean.js | 9 ++++ .../Point/isPoint/custom-property.js | 13 +++++ .../test/interfaces/Point/isPoint/object.js | 9 ++++ .../test/interfaces/Point/isPoint/offset.js | 9 ++++ .../test/interfaces/Point/isPoint/path.js | 9 ++++ .../test/interfaces/Point/isPoint/point.js | 12 +++++ .../test/interfaces/Range/equals/equal.js | 30 +++++++++++ .../test/interfaces/Range/equals/not-equal.js | 30 +++++++++++ .../interfaces/Range/includes/path-after.js | 21 ++++++++ .../interfaces/Range/includes/path-before.js | 21 ++++++++ .../interfaces/Range/includes/path-end.js | 21 ++++++++ .../interfaces/Range/includes/path-inside.js | 21 ++++++++ .../interfaces/Range/includes/path-start.js | 21 ++++++++ .../interfaces/Range/includes/point-end.js | 24 +++++++++ .../interfaces/Range/includes/point-inside.js | 24 +++++++++ .../Range/includes/point-offset-after.js | 24 +++++++++ .../Range/includes/point-offset-before.js | 24 +++++++++ .../Range/includes/point-path-after.js | 24 +++++++++ .../Range/includes/point-path-before.js | 24 +++++++++ .../interfaces/Range/includes/point-start.js | 24 +++++++++ .../interfaces/Range/isBackward/backward.js | 18 +++++++ .../interfaces/Range/isBackward/collapsed.js | 18 +++++++ .../interfaces/Range/isBackward/forward.js | 18 +++++++ .../interfaces/Range/isCollapsed/collapsed.js | 18 +++++++ .../interfaces/Range/isCollapsed/expanded.js | 18 +++++++ .../interfaces/Range/isExpanded/collapsed.js | 18 +++++++ .../interfaces/Range/isExpanded/expanded.js | 18 +++++++ .../interfaces/Range/isForward/backward.js | 18 +++++++ .../interfaces/Range/isForward/collapsed.js | 18 +++++++ .../interfaces/Range/isForward/forward.js | 18 +++++++ .../test/interfaces/Range/isRange/boolean.js | 9 ++++ .../Range/isRange/custom-property.js | 19 +++++++ .../test/interfaces/Range/isRange/object.js | 9 ++++ .../test/interfaces/Range/isRange/range.js | 18 +++++++ .../test/interfaces/Range/points/backward.js | 27 ++++++++++ .../test/interfaces/Range/points/collapsed.js | 27 ++++++++++ .../test/interfaces/Range/points/forward.js | 27 ++++++++++ .../apply/insert-text/annotation-before.js | 34 ++++++------- .../merge-node/annotation-across-blocks.js | 38 +++++++------- 203 files changed, 2785 insertions(+), 215 deletions(-) create mode 100644 packages/slate-render-plaintext/test/fixtures/custom-is-inline.js create mode 100644 packages/slate/test/helpers/index.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/object.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationRecord/annotation.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationRecord/boolean.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationRecord/empty.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationRecord/full.js create mode 100644 packages/slate/test/interfaces/Path/ancestors/reverse.js create mode 100644 packages/slate/test/interfaces/Path/ancestors/success.js create mode 100644 packages/slate/test/interfaces/Path/common/equal.js create mode 100644 packages/slate/test/interfaces/Path/common/root.js create mode 100644 packages/slate/test/interfaces/Path/common/success.js create mode 100644 packages/slate/test/interfaces/Path/compare/above.js create mode 100644 packages/slate/test/interfaces/Path/compare/after.js create mode 100644 packages/slate/test/interfaces/Path/compare/before.js create mode 100644 packages/slate/test/interfaces/Path/compare/below.js create mode 100644 packages/slate/test/interfaces/Path/compare/equal.js create mode 100644 packages/slate/test/interfaces/Path/compare/root.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/above.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/after.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/before.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/below.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/ends-after.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/ends-at.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/ends-before.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/equal.js create mode 100644 packages/slate/test/interfaces/Path/endsAfter/root.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/above.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/after.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/before.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/ends-after.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/ends-at.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/ends-before.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/equal.js create mode 100644 packages/slate/test/interfaces/Path/endsAt/root.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/above.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/after.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/before.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/below.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/ends-after.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/ends-at.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/ends-before.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/equal.js create mode 100644 packages/slate/test/interfaces/Path/endsBefore/root.js create mode 100644 packages/slate/test/interfaces/Path/equals/above.js create mode 100644 packages/slate/test/interfaces/Path/equals/after.js create mode 100644 packages/slate/test/interfaces/Path/equals/before.js create mode 100644 packages/slate/test/interfaces/Path/equals/below.js create mode 100644 packages/slate/test/interfaces/Path/equals/equal.js create mode 100644 packages/slate/test/interfaces/Path/equals/root.js create mode 100644 packages/slate/test/interfaces/Path/isAfter/above.js create mode 100644 packages/slate/test/interfaces/Path/isAfter/after.js create mode 100644 packages/slate/test/interfaces/Path/isAfter/before.js create mode 100644 packages/slate/test/interfaces/Path/isAfter/below.js create mode 100644 packages/slate/test/interfaces/Path/isAfter/equal.js create mode 100644 packages/slate/test/interfaces/Path/isAncestor/above-grandparent.js create mode 100644 packages/slate/test/interfaces/Path/isAncestor/above-parent.js create mode 100644 packages/slate/test/interfaces/Path/isAncestor/after.js create mode 100644 packages/slate/test/interfaces/Path/isAncestor/before.js create mode 100644 packages/slate/test/interfaces/Path/isAncestor/below.js create mode 100644 packages/slate/test/interfaces/Path/isAncestor/equal.js create mode 100644 packages/slate/test/interfaces/Path/isBefore/above.js create mode 100644 packages/slate/test/interfaces/Path/isBefore/after.js create mode 100644 packages/slate/test/interfaces/Path/isBefore/before.js create mode 100644 packages/slate/test/interfaces/Path/isBefore/below.js create mode 100644 packages/slate/test/interfaces/Path/isBefore/equal.js create mode 100644 packages/slate/test/interfaces/Path/isChild/above.js create mode 100644 packages/slate/test/interfaces/Path/isChild/after.js create mode 100644 packages/slate/test/interfaces/Path/isChild/before.js create mode 100644 packages/slate/test/interfaces/Path/isChild/below-child.js create mode 100644 packages/slate/test/interfaces/Path/isChild/below-grandchild.js create mode 100644 packages/slate/test/interfaces/Path/isChild/equal.js create mode 100644 packages/slate/test/interfaces/Path/isDescendant/above.js create mode 100644 packages/slate/test/interfaces/Path/isDescendant/after.js create mode 100644 packages/slate/test/interfaces/Path/isDescendant/before.js create mode 100644 packages/slate/test/interfaces/Path/isDescendant/below-child.js create mode 100644 packages/slate/test/interfaces/Path/isDescendant/below-grandchild.js create mode 100644 packages/slate/test/interfaces/Path/isDescendant/equal.js create mode 100644 packages/slate/test/interfaces/Path/isParent/above-grandparent.js create mode 100644 packages/slate/test/interfaces/Path/isParent/above-parent.js create mode 100644 packages/slate/test/interfaces/Path/isParent/after.js create mode 100644 packages/slate/test/interfaces/Path/isParent/before.js create mode 100644 packages/slate/test/interfaces/Path/isParent/below.js create mode 100644 packages/slate/test/interfaces/Path/isParent/equal.js create mode 100644 packages/slate/test/interfaces/Path/isPath/boolean.js create mode 100644 packages/slate/test/interfaces/Path/isPath/empty.js create mode 100644 packages/slate/test/interfaces/Path/isPath/full.js create mode 100644 packages/slate/test/interfaces/Path/isPath/strings.js create mode 100644 packages/slate/test/interfaces/Path/isSibling/above.js create mode 100644 packages/slate/test/interfaces/Path/isSibling/after-sibling.js create mode 100644 packages/slate/test/interfaces/Path/isSibling/after.js create mode 100644 packages/slate/test/interfaces/Path/isSibling/before-sibling.js create mode 100644 packages/slate/test/interfaces/Path/isSibling/before.js create mode 100644 packages/slate/test/interfaces/Path/isSibling/below.js create mode 100644 packages/slate/test/interfaces/Path/isSibling/equal.js create mode 100644 packages/slate/test/interfaces/Path/levels/reverse.js create mode 100644 packages/slate/test/interfaces/Path/levels/success.js create mode 100644 packages/slate/test/interfaces/Path/next/success.js create mode 100644 packages/slate/test/interfaces/Path/parent/success.js create mode 100644 packages/slate/test/interfaces/Path/previous/success.js create mode 100644 packages/slate/test/interfaces/Path/relative/grandparent.js create mode 100644 packages/slate/test/interfaces/Path/relative/parent.js create mode 100644 packages/slate/test/interfaces/Path/relative/root.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-after-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-after-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-after-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-before-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-before-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-before-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-equal-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-equal-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/compare/path-equal-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-after-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-after-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-after-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-before-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-before-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-before-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-equal-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-equal-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/equals/path-equal-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-after-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-after-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-after-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-before-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-before-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-before-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-equal-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-equal-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/isAfter/path-equal-offset-equal.js delete mode 100644 packages/slate/test/interfaces/Point/isAfter/point/offset-after.js delete mode 100644 packages/slate/test/interfaces/Point/isAfter/point/offset-before.js delete mode 100644 packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js delete mode 100644 packages/slate/test/interfaces/Point/isAfter/point/path-after.js delete mode 100644 packages/slate/test/interfaces/Point/isAfter/point/path-before.js delete mode 100644 packages/slate/test/interfaces/Point/isAfter/point/path-equal.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-after-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-after-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-after-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-before-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-before-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-before-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-equal-offset-after.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-equal-offset-before.js create mode 100644 packages/slate/test/interfaces/Point/isBefore/path-equal-offset-equal.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/boolean.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/custom-property.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/object.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/offset.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/path.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/point.js create mode 100644 packages/slate/test/interfaces/Range/equals/equal.js create mode 100644 packages/slate/test/interfaces/Range/equals/not-equal.js create mode 100644 packages/slate/test/interfaces/Range/includes/path-after.js create mode 100644 packages/slate/test/interfaces/Range/includes/path-before.js create mode 100644 packages/slate/test/interfaces/Range/includes/path-end.js create mode 100644 packages/slate/test/interfaces/Range/includes/path-inside.js create mode 100644 packages/slate/test/interfaces/Range/includes/path-start.js create mode 100644 packages/slate/test/interfaces/Range/includes/point-end.js create mode 100644 packages/slate/test/interfaces/Range/includes/point-inside.js create mode 100644 packages/slate/test/interfaces/Range/includes/point-offset-after.js create mode 100644 packages/slate/test/interfaces/Range/includes/point-offset-before.js create mode 100644 packages/slate/test/interfaces/Range/includes/point-path-after.js create mode 100644 packages/slate/test/interfaces/Range/includes/point-path-before.js create mode 100644 packages/slate/test/interfaces/Range/includes/point-start.js create mode 100644 packages/slate/test/interfaces/Range/isBackward/backward.js create mode 100644 packages/slate/test/interfaces/Range/isBackward/collapsed.js create mode 100644 packages/slate/test/interfaces/Range/isBackward/forward.js create mode 100644 packages/slate/test/interfaces/Range/isCollapsed/collapsed.js create mode 100644 packages/slate/test/interfaces/Range/isCollapsed/expanded.js create mode 100644 packages/slate/test/interfaces/Range/isExpanded/collapsed.js create mode 100644 packages/slate/test/interfaces/Range/isExpanded/expanded.js create mode 100644 packages/slate/test/interfaces/Range/isForward/backward.js create mode 100644 packages/slate/test/interfaces/Range/isForward/collapsed.js create mode 100644 packages/slate/test/interfaces/Range/isForward/forward.js create mode 100644 packages/slate/test/interfaces/Range/isRange/boolean.js create mode 100644 packages/slate/test/interfaces/Range/isRange/custom-property.js create mode 100644 packages/slate/test/interfaces/Range/isRange/object.js create mode 100644 packages/slate/test/interfaces/Range/isRange/range.js create mode 100644 packages/slate/test/interfaces/Range/points/backward.js create mode 100644 packages/slate/test/interfaces/Range/points/collapsed.js create mode 100644 packages/slate/test/interfaces/Range/points/forward.js diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts index 29c1520e06..16edde5ec8 100644 --- a/packages/slate-hyperscript/src/creators.ts +++ b/packages/slate-hyperscript/src/creators.ts @@ -238,7 +238,6 @@ export function createValue( if (anchor != null) { const [offset, token] = anchor - debugger selection.anchor = { path, offset } selection.isFocused = token.focused selection.marks = token.marks @@ -246,7 +245,6 @@ export function createValue( if (focus != null) { const [offset, token] = focus - debugger selection.focus = { path, offset } selection.isFocused = token.focused selection.marks = token.marks diff --git a/packages/slate-render-plaintext/src/index.ts b/packages/slate-render-plaintext/src/index.ts index dd53c59387..f40354b6e4 100644 --- a/packages/slate-render-plaintext/src/index.ts +++ b/packages/slate-render-plaintext/src/index.ts @@ -1,21 +1,29 @@ -import { Node, Text } from 'slate' +import { Element, Node, Text } from 'slate' /** * Render a Slate `Node` to a plaintext string. * * By default, it will use `\n` as the delimiter, separating each block-level * element with a line break. + * + * Note: If you need to, you can pass in your own custom `isInline` function + * which is used to determine which element nodes are "inline vs. block". By + * default it checks to see if the element has any text children. */ export const renderPlaintext = ( node: Node, options: { delimiter?: string + isInline?: (element: Element) => boolean } = {} ): string => { - const { delimiter = '\n' } = options + const { + delimiter = '\n', + isInline = (element: Element) => element.nodes.some(n => Text.isText(n)), + } = options - if (Text.isText(node) || node.nodes.some(n => Text.isText(n))) { + if (Text.isText(node) || (Element.isElement(node) && isInline(node))) { return Node.text(node) } else { return node.nodes.map(n => renderPlaintext(n, options)).join(delimiter) diff --git a/packages/slate-render-plaintext/test/fixtures/custom-is-inline.js b/packages/slate-render-plaintext/test/fixtures/custom-is-inline.js new file mode 100644 index 0000000000..fdebb7a3f0 --- /dev/null +++ b/packages/slate-render-plaintext/test/fixtures/custom-is-inline.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + one{'\n'}same paragraph + two + three + +) + +export const options = { + isInline: () => true, +} + +export const output = ` +one +same paragraphtwothree +`.trim() diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index 1c14c4f8b1..daccae1837 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -45,11 +45,13 @@ class Editor { [POINT_REFS]: { [key: number]: PointRef }; [RANGE_REFS]: { [key: number]: RangeRef } - constructor(props: { - onChange?(change: Change): void - readOnly?: boolean - value?: Value - }) { + constructor( + props: { + onChange?(change: Change): void + readOnly?: boolean + value?: Value + } = {} + ) { const { onChange = () => {}, readOnly = false, @@ -86,20 +88,29 @@ interface Editor RangeQueries, ValueQueries {} -Object.assign( - Editor.prototype, - AnnotationCommands.prototype, - PathCommands.prototype, - PointCommands.prototype, - RangeCommands.prototype, - SelectionCommands.prototype, - ValueCommands.prototype, - MarkQueries.prototype, - NodeQueries.prototype, - PathQueries.prototype, - PointQueries.prototype, - RangeQueries.prototype, - ValueQueries.prototype -) +const mixin = (Mixins: Array any>) => { + for (const Mixin of Mixins) { + for (const key of Object.getOwnPropertyNames(Mixin.prototype)) { + if (key !== 'constructor') { + Editor.prototype[key] = Mixin.prototype[key] + } + } + } +} + +mixin([ + AnnotationCommands, + PathCommands, + PointCommands, + RangeCommands, + SelectionCommands, + ValueCommands, + MarkQueries, + NodeQueries, + PathQueries, + PointQueries, + RangeQueries, + ValueQueries, +]) export { Editor, EditorConstructor } diff --git a/packages/slate/src/interfaces/annotation.ts b/packages/slate/src/interfaces/annotation.ts index 4e52cd5af1..bfb4a92b65 100755 --- a/packages/slate/src/interfaces/annotation.ts +++ b/packages/slate/src/interfaces/annotation.ts @@ -1,5 +1,5 @@ import isPlainObject from 'is-plain-object' -import { Mark, Point, Range } from '..' +import { Mark, Point, PointKey, Range } from '..' /** * `Annotation` objects are a type of formatting that are applied at the @@ -15,7 +15,7 @@ interface Annotation extends Mark, Range {} * objects that belong to an `Annotation`. */ -type AnnotationPointEntry = [Point, Annotation, string] +type AnnotationPointEntry = [Point, PointKey, Annotation, string] namespace Annotation { /** diff --git a/packages/slate/src/interfaces/change.ts b/packages/slate/src/interfaces/change.ts index 4b69baee42..dec090e4c2 100644 --- a/packages/slate/src/interfaces/change.ts +++ b/packages/slate/src/interfaces/change.ts @@ -10,6 +10,7 @@ import { Value, Operation } from '..' interface Change { value: Value operations: Operation[] + [key: string]: any } namespace Change { diff --git a/packages/slate/src/interfaces/element.ts b/packages/slate/src/interfaces/element.ts index 83216e5253..30ced8f9a6 100755 --- a/packages/slate/src/interfaces/element.ts +++ b/packages/slate/src/interfaces/element.ts @@ -10,6 +10,7 @@ import { Node, Path, Text } from '..' interface Element { nodes: Node[] + [key: string]: any } /** diff --git a/packages/slate/src/interfaces/fragment.ts b/packages/slate/src/interfaces/fragment.ts index aebb913536..be4806e229 100755 --- a/packages/slate/src/interfaces/fragment.ts +++ b/packages/slate/src/interfaces/fragment.ts @@ -8,6 +8,7 @@ import { Node } from '..' interface Fragment { nodes: Node[] + [key: string]: any } namespace Fragment { diff --git a/packages/slate/src/interfaces/mark.ts b/packages/slate/src/interfaces/mark.ts index 48550400c3..2044b020eb 100755 --- a/packages/slate/src/interfaces/mark.ts +++ b/packages/slate/src/interfaces/mark.ts @@ -7,7 +7,9 @@ import { Path, Text } from '..' * annotations on the root value object. */ -interface Mark {} +interface Mark { + [key: string]: any +} /** * `MarkEntry` tuples are returned when iterating through the marks in a text @@ -31,12 +33,7 @@ namespace Mark { */ export const isMark = (value: any): value is Mark => { - return ( - isPlainObject(value) && - value.key == null && // not an `Annotation` - (value.anchor == null && value.focus == null) && // not a `Decoration` - typeof value.type === 'string' - ) + return isPlainObject(value) } /** diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index a8c80730a2..003fab3599 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -5,18 +5,21 @@ interface AddMarkOperation { type: 'add_mark' path: Path mark: Mark + [key: string]: any } interface AddAnnotationOperation { type: 'add_annotation' key: string annotation: Annotation + [key: string]: any } interface InsertNodeOperation { type: 'insert_node' path: Path node: Node + [key: string]: any } interface InsertTextOperation { @@ -24,6 +27,7 @@ interface InsertTextOperation { path: Path offset: number text: string + [key: string]: any } interface MergeNodeOperation { @@ -32,30 +36,35 @@ interface MergeNodeOperation { position: number target: number | null properties: {} + [key: string]: any } interface MoveNodeOperation { type: 'move_node' path: Path newPath: Path + [key: string]: any } interface RemoveAnnotationOperation { type: 'remove_annotation' key: string annotation: Annotation + [key: string]: any } interface RemoveMarkOperation { type: 'remove_mark' path: Path mark: Mark + [key: string]: any } interface RemoveNodeOperation { type: 'remove_node' path: Path node: Node + [key: string]: any } interface RemoveTextOperation { @@ -63,6 +72,7 @@ interface RemoveTextOperation { path: Path offset: number text: string + [key: string]: any } interface SetAnnotationOperation { @@ -70,6 +80,7 @@ interface SetAnnotationOperation { key: string properties: {} newProperties: {} + [key: string]: any } interface SetMarkOperation { @@ -77,6 +88,7 @@ interface SetMarkOperation { path: Path properties: {} newProperties: {} + [key: string]: any } interface SetNodeOperation { @@ -84,18 +96,21 @@ interface SetNodeOperation { path: Path properties: {} newProperties: {} + [key: string]: any } interface SetSelectionOperation { type: 'set_selection' properties: {} | null newProperties: {} | null + [key: string]: any } interface SetValueOperation { type: 'set_value' properties: {} newProperties: {} + [key: string]: any } interface SplitNodeOperation { @@ -104,6 +119,7 @@ interface SplitNodeOperation { position: number target: number | null properties: {} + [key: string]: any } /** diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index 1c01fb7920..546ff5b98c 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -134,7 +134,7 @@ namespace Path { */ export const isAncestor = (path: Path, another: Path): boolean => { - return path.length > another.length && Path.compare(path, another) === 0 + return path.length < another.length && Path.compare(path, another) === 0 } /** @@ -160,7 +160,7 @@ namespace Path { */ export const isDescendant = (path: Path, another: Path): boolean => { - return path.length < another.length && Path.compare(path, another) === 0 + return path.length > another.length && Path.compare(path, another) === 0 } /** @@ -195,7 +195,9 @@ namespace Path { const as = path.slice(0, -1) const bs = another.slice(0, -1) - return Path.equals(as, bs) + const al = path[path.length - 1] + const bl = another[another.length - 1] + return al !== bl && Path.equals(as, bs) } /** @@ -266,7 +268,7 @@ namespace Path { const last = path[path.length - 1] - if (last >= 0) { + if (last <= 0) { throw new Error( `Cannot get the previous path of a first child path ${path} because it would result in a negative index.` ) diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts index e0b279d035..122658f231 100755 --- a/packages/slate/src/interfaces/point.ts +++ b/packages/slate/src/interfaces/point.ts @@ -12,8 +12,15 @@ import { Operation, Path } from '..' interface Point { path: Path offset: number + [key: string]: any } +/** + * `PointKey` is either an "anchor" or "focus" point string. + */ + +type PointKey = 'anchor' | 'focus' + namespace Point { /** * Compare a point to another, returning an integer indicating whether the @@ -45,7 +52,7 @@ namespace Point { */ export const isBefore = (point: Point, another: Point): boolean => { - return Point.compare(point, another) === 1 + return Point.compare(point, another) === -1 } /** @@ -146,4 +153,4 @@ namespace Point { } } -export { Point } +export { Point, PointKey } diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index c2b8607ae2..2442cc000d 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -11,6 +11,7 @@ import { Operation, Path, Point } from '..' interface Range { anchor: Point focus: Point + [key: string]: any } namespace Range { diff --git a/packages/slate/src/interfaces/selection.ts b/packages/slate/src/interfaces/selection.ts index 4b30f2b6dc..e4e62f3a5d 100755 --- a/packages/slate/src/interfaces/selection.ts +++ b/packages/slate/src/interfaces/selection.ts @@ -1,5 +1,5 @@ import isPlainObject from 'is-plain-object' -import { Mark, Point, Range } from '..' +import { Mark, Point, PointKey, Range } from '..' /** * `Selection` objects represent the range in a document that a user has @@ -10,6 +10,7 @@ import { Mark, Point, Range } from '..' interface Selection extends Range { isFocused: boolean marks: Mark[] | null + [key: string]: any } /** @@ -17,7 +18,7 @@ interface Selection extends Range { * objects that belong to an `Selection`. */ -type SelectionPointEntry = [Point, Selection] +type SelectionPointEntry = [Point, PointKey, Selection] namespace Selection { /** diff --git a/packages/slate/src/interfaces/text.ts b/packages/slate/src/interfaces/text.ts index 2ea1b779a9..b319c70bde 100755 --- a/packages/slate/src/interfaces/text.ts +++ b/packages/slate/src/interfaces/text.ts @@ -10,6 +10,7 @@ import { Mark, Path } from '..' interface Text { text: string marks: Mark[] + [key: string]: any } /** diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 3d0ae03f6d..59c4e0c38c 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -22,6 +22,7 @@ import { interface Value extends Element { selection: Selection | null annotations: Record + [key: string]: any } /** @@ -55,14 +56,14 @@ namespace Value { const { selection, annotations } = value if (selection != null) { - yield [selection.anchor, selection] - yield [selection.focus, selection] + yield [selection.anchor, 'anchor', selection] + yield [selection.focus, 'focus', selection] } for (const key in annotations) { const annotation = annotations[key] - yield [annotation.anchor, annotation, key] - yield [annotation.focus, annotation, key] + yield [annotation.anchor, 'anchor', annotation, key] + yield [annotation.focus, 'focus', annotation, key] } } @@ -96,8 +97,8 @@ namespace Value { const index = path[path.length - 1] parent.nodes[index] = node - for (const [point] of Value.points(v)) { - Point.transform(point, op) + for (const [point, key, range] of Value.points(v)) { + range[key] = Point.transform(point, op)! } break @@ -110,8 +111,8 @@ namespace Value { const after = node.text.slice(offset) node.text = before + text + after - for (const [point] of Value.points(v)) { - Point.transform(point, op) + for (const [point, key, range] of Value.points(v)) { + range[key] = Point.transform(point, op)! } break @@ -136,8 +137,8 @@ namespace Value { parent.nodes.splice(index, 1) - for (const [point] of Value.points(v)) { - Point.transform(point, op) + for (const [point, key, range] of Value.points(v)) { + range[key] = Point.transform(point, op)! } break @@ -160,8 +161,8 @@ namespace Value { const newIndex = newPath[newPath.length - 1] newParent.nodes.splice(newIndex, 0, node) - for (const [point] of Value.points(v)) { - Point.transform(point, op) + for (const [point, key, range] of Value.points(v)) { + range[key] = Point.transform(point, op)! } break @@ -202,7 +203,7 @@ namespace Value { // Transform all of the points in the value, but if the point was in the // node that was removed we need to update the range or remove it. - for (const [point, range, key] of Value.points(v)) { + for (const [point, k, range, key] of Value.points(v)) { const result = Point.transform(point, op) if (result == null) { @@ -233,8 +234,8 @@ namespace Value { const after = node.text.slice(offset + text.length) node.text = before + after - for (const [point] of Value.points(v)) { - Point.transform(point, op) + for (const [point, key, range] of Value.points(v)) { + range[key] = Point.transform(point, op)! } break @@ -308,8 +309,8 @@ namespace Value { parent.nodes.splice(index + 1, 0, newNode) - for (const [point] of Value.points(v)) { - Point.transform(point, op) + for (const [point, key, range] of Value.points(v)) { + range[key] = Point.transform(point, op)! } break diff --git a/packages/slate/test/helpers/index.js b/packages/slate/test/helpers/index.js new file mode 100644 index 0000000000..306b5c88d8 --- /dev/null +++ b/packages/slate/test/helpers/index.js @@ -0,0 +1,32 @@ +import { Element } from 'slate' +import { createHyperscript } from 'slate-hyperscript' + +const h = createHyperscript({ + elements: { + block: {}, + inline: {}, + void_block: {}, + void_inline: {}, + }, + annotations: { + atomic_annotation: {}, + }, +}) + +const TestPlugin = Editor => { + return class extends Editor { + isInline(node) { + return Element.isElement(node) && node.type === 'inline' + } + + isVoid(node) { + return Element.isElement(node) && node.type.startsWith('void_') + } + + isAtomic(mark) { + return mark.type.startsWith('atomic_') + } + } +} + +export { h, TestPlugin } diff --git a/packages/slate/test/index.js b/packages/slate/test/index.js index a17d945b2a..8a5eb9bd03 100644 --- a/packages/slate/test/index.js +++ b/packages/slate/test/index.js @@ -1,6 +1,7 @@ import assert from 'assert' import { fixtures } from '../../../support/fixtures' import { Editor } from 'slate' +import { TestPlugin } from './helpers' const plugins = [ { @@ -32,23 +33,16 @@ describe('slate', () => { }) fixtures(__dirname, 'operations', ({ module }) => { - const { input, output } = module - const operations = module.default - const editor = new Editor({ plugins }) + const { input, operations, output } = module + const TestEditor = TestPlugin(Editor) + const editor = new TestEditor({ value: input }) + editor.normalize({ force: true }) - const opts = { - preserveSelection: true, - preserveDecorations: true, + for (const op of operations) { + editor.apply(op) } - editor.setValue(input) - operations.forEach(op => editor.applyOperation(op)) - - const actual = editor.value.toJSON(opts) - - editor.setValue(output) - const expected = editor.value.toJSON(opts) - assert.deepEqual(actual, expected) + assert.deepEqual(editor.value, output) }) // The hyperscript editor has the schema, but the test diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js b/packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js new file mode 100644 index 0000000000..13c137e371 --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js @@ -0,0 +1,18 @@ +import { Annotation } from 'slate' + +export const input = { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Annotation.isAnnotation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js b/packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js new file mode 100644 index 0000000000..737bf20d83 --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js @@ -0,0 +1,9 @@ +import { Annotation } from 'slate' + +export const input = true + +export const test = value => { + return Annotation.isAnnotation(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js b/packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js new file mode 100644 index 0000000000..afceeadc6b --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js @@ -0,0 +1,19 @@ +import { Annotation } from 'slate' + +export const input = { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + custom: 'value', +} + +export const test = value => { + return Annotation.isAnnotation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/object.js b/packages/slate/test/interfaces/Annotation/isAnnotation/object.js new file mode 100644 index 0000000000..387aeb5bdd --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotation/object.js @@ -0,0 +1,9 @@ +import { Annotation } from 'slate' + +export const input = {} + +export const test = value => { + return Annotation.isAnnotation(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/annotation.js b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/annotation.js new file mode 100644 index 0000000000..63c84e5a70 --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/annotation.js @@ -0,0 +1,18 @@ +import { Annotation } from 'slate' + +export const input = { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Annotation.isAnnotationRecord(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/boolean.js b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/boolean.js new file mode 100644 index 0000000000..3b8508ec14 --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/boolean.js @@ -0,0 +1,9 @@ +import { Annotation } from 'slate' + +export const input = true + +export const test = value => { + return Annotation.isAnnotationRecord(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/empty.js b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/empty.js new file mode 100644 index 0000000000..7d08145d01 --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/empty.js @@ -0,0 +1,9 @@ +import { Annotation } from 'slate' + +export const input = {} + +export const test = value => { + return Annotation.isAnnotationRecord(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/full.js b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/full.js new file mode 100644 index 0000000000..9e5cba0301 --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotationRecord/full.js @@ -0,0 +1,20 @@ +import { Annotation } from 'slate' + +export const input = { + a: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + }, +} + +export const test = value => { + return Annotation.isAnnotationRecord(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/ancestors/reverse.js b/packages/slate/test/interfaces/Path/ancestors/reverse.js new file mode 100644 index 0000000000..3f5e1205b3 --- /dev/null +++ b/packages/slate/test/interfaces/Path/ancestors/reverse.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1, 2] + +export const test = path => { + return Path.ancestors(path, { reverse: true }) +} + +export const output = [[], [0], [0, 1]] diff --git a/packages/slate/test/interfaces/Path/ancestors/success.js b/packages/slate/test/interfaces/Path/ancestors/success.js new file mode 100644 index 0000000000..992d2331f4 --- /dev/null +++ b/packages/slate/test/interfaces/Path/ancestors/success.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1, 2] + +export const test = path => { + return Path.ancestors(path) +} + +export const output = [[0, 1], [0], []] diff --git a/packages/slate/test/interfaces/Path/common/equal.js b/packages/slate/test/interfaces/Path/common/equal.js new file mode 100644 index 0000000000..ce3fb3806f --- /dev/null +++ b/packages/slate/test/interfaces/Path/common/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.common(path, another) +} + +export const output = [0, 1, 2] diff --git a/packages/slate/test/interfaces/Path/common/root.js b/packages/slate/test/interfaces/Path/common/root.js new file mode 100644 index 0000000000..6b9d50ba78 --- /dev/null +++ b/packages/slate/test/interfaces/Path/common/root.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [3, 2], +} + +export const test = ({ path, another }) => { + return Path.common(path, another) +} + +export const output = [] diff --git a/packages/slate/test/interfaces/Path/common/success.js b/packages/slate/test/interfaces/Path/common/success.js new file mode 100644 index 0000000000..af07325a8c --- /dev/null +++ b/packages/slate/test/interfaces/Path/common/success.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 2], +} + +export const test = ({ path, another }) => { + return Path.common(path, another) +} + +export const output = [0] diff --git a/packages/slate/test/interfaces/Path/compare/above.js b/packages/slate/test/interfaces/Path/compare/above.js new file mode 100644 index 0000000000..e763bca7b7 --- /dev/null +++ b/packages/slate/test/interfaces/Path/compare/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.compare(path, another) +} + +export const output = 0 diff --git a/packages/slate/test/interfaces/Path/compare/after.js b/packages/slate/test/interfaces/Path/compare/after.js new file mode 100644 index 0000000000..617324e512 --- /dev/null +++ b/packages/slate/test/interfaces/Path/compare/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.compare(path, another) +} + +export const output = 1 diff --git a/packages/slate/test/interfaces/Path/compare/before.js b/packages/slate/test/interfaces/Path/compare/before.js new file mode 100644 index 0000000000..0078ea21c2 --- /dev/null +++ b/packages/slate/test/interfaces/Path/compare/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.compare(path, another) +} + +export const output = -1 diff --git a/packages/slate/test/interfaces/Path/compare/below.js b/packages/slate/test/interfaces/Path/compare/below.js new file mode 100644 index 0000000000..5ff34fde1c --- /dev/null +++ b/packages/slate/test/interfaces/Path/compare/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.compare(path, another) +} + +export const output = 0 diff --git a/packages/slate/test/interfaces/Path/compare/equal.js b/packages/slate/test/interfaces/Path/compare/equal.js new file mode 100644 index 0000000000..4da4440438 --- /dev/null +++ b/packages/slate/test/interfaces/Path/compare/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.compare(path, another) +} + +export const output = 0 diff --git a/packages/slate/test/interfaces/Path/compare/root.js b/packages/slate/test/interfaces/Path/compare/root.js new file mode 100644 index 0000000000..e7e8e056ab --- /dev/null +++ b/packages/slate/test/interfaces/Path/compare/root.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [], +} + +export const test = ({ path, another }) => { + return Path.compare(path, another) +} + +export const output = 0 diff --git a/packages/slate/test/interfaces/Path/endsAfter/above.js b/packages/slate/test/interfaces/Path/endsAfter/above.js new file mode 100644 index 0000000000..434562c80a --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAfter/after.js b/packages/slate/test/interfaces/Path/endsAfter/after.js new file mode 100644 index 0000000000..df01ffdbcb --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAfter/before.js b/packages/slate/test/interfaces/Path/endsAfter/before.js new file mode 100644 index 0000000000..03605f59cd --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAfter/below.js b/packages/slate/test/interfaces/Path/endsAfter/below.js new file mode 100644 index 0000000000..73fd87e5fe --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAfter/ends-after.js b/packages/slate/test/interfaces/Path/endsAfter/ends-after.js new file mode 100644 index 0000000000..3902d3a10f --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/ends-after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1], + another: [0, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/endsAfter/ends-at.js b/packages/slate/test/interfaces/Path/endsAfter/ends-at.js new file mode 100644 index 0000000000..a889110ec8 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/ends-at.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAfter/ends-before.js b/packages/slate/test/interfaces/Path/endsAfter/ends-before.js new file mode 100644 index 0000000000..3f59fac60c --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/ends-before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [1, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAfter/equal.js b/packages/slate/test/interfaces/Path/endsAfter/equal.js new file mode 100644 index 0000000000..abbd9baf60 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAfter/root.js b/packages/slate/test/interfaces/Path/endsAfter/root.js new file mode 100644 index 0000000000..dff32f6b13 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAfter/root.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [], +} + +export const test = ({ path, another }) => { + return Path.endsAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAt/above.js b/packages/slate/test/interfaces/Path/endsAt/above.js new file mode 100644 index 0000000000..06dde5753e --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAt/after.js b/packages/slate/test/interfaces/Path/endsAt/after.js new file mode 100644 index 0000000000..7a16187b8e --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAt/before.js b/packages/slate/test/interfaces/Path/endsAt/before.js new file mode 100644 index 0000000000..a044038f12 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAt/ends-after.js b/packages/slate/test/interfaces/Path/endsAt/ends-after.js new file mode 100644 index 0000000000..57ebadfe30 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/ends-after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1], + another: [0, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAt/ends-at.js b/packages/slate/test/interfaces/Path/endsAt/ends-at.js new file mode 100644 index 0000000000..30deec49a4 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/ends-at.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/endsAt/ends-before.js b/packages/slate/test/interfaces/Path/endsAt/ends-before.js new file mode 100644 index 0000000000..21079440df --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/ends-before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [1, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsAt/equal.js b/packages/slate/test/interfaces/Path/endsAt/equal.js new file mode 100644 index 0000000000..3c691b0915 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/endsAt/root.js b/packages/slate/test/interfaces/Path/endsAt/root.js new file mode 100644 index 0000000000..307d4dedd2 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsAt/root.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [], +} + +export const test = ({ path, another }) => { + return Path.endsAt(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/above.js b/packages/slate/test/interfaces/Path/endsBefore/above.js new file mode 100644 index 0000000000..6f0e9908b3 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/after.js b/packages/slate/test/interfaces/Path/endsBefore/after.js new file mode 100644 index 0000000000..fd72ff200a --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/before.js b/packages/slate/test/interfaces/Path/endsBefore/before.js new file mode 100644 index 0000000000..ca94ff4505 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/below.js b/packages/slate/test/interfaces/Path/endsBefore/below.js new file mode 100644 index 0000000000..01b2f62aa2 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/ends-after.js b/packages/slate/test/interfaces/Path/endsBefore/ends-after.js new file mode 100644 index 0000000000..2a914855f5 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/ends-after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1], + another: [0, 2], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/ends-at.js b/packages/slate/test/interfaces/Path/endsBefore/ends-at.js new file mode 100644 index 0000000000..a517b972f6 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/ends-at.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 2], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/ends-before.js b/packages/slate/test/interfaces/Path/endsBefore/ends-before.js new file mode 100644 index 0000000000..b9a589ab7e --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/ends-before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [1, 2], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/endsBefore/equal.js b/packages/slate/test/interfaces/Path/endsBefore/equal.js new file mode 100644 index 0000000000..909b4182a6 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/endsBefore/root.js b/packages/slate/test/interfaces/Path/endsBefore/root.js new file mode 100644 index 0000000000..2c63c50850 --- /dev/null +++ b/packages/slate/test/interfaces/Path/endsBefore/root.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [], +} + +export const test = ({ path, another }) => { + return Path.endsBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/equals/above.js b/packages/slate/test/interfaces/Path/equals/above.js new file mode 100644 index 0000000000..0e252aba47 --- /dev/null +++ b/packages/slate/test/interfaces/Path/equals/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.equals(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/equals/after.js b/packages/slate/test/interfaces/Path/equals/after.js new file mode 100644 index 0000000000..f1f4048df7 --- /dev/null +++ b/packages/slate/test/interfaces/Path/equals/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.equals(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/equals/before.js b/packages/slate/test/interfaces/Path/equals/before.js new file mode 100644 index 0000000000..13201509c3 --- /dev/null +++ b/packages/slate/test/interfaces/Path/equals/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.equals(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/equals/below.js b/packages/slate/test/interfaces/Path/equals/below.js new file mode 100644 index 0000000000..5e0af5b748 --- /dev/null +++ b/packages/slate/test/interfaces/Path/equals/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.equals(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/equals/equal.js b/packages/slate/test/interfaces/Path/equals/equal.js new file mode 100644 index 0000000000..64d6e0cc67 --- /dev/null +++ b/packages/slate/test/interfaces/Path/equals/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.equals(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/equals/root.js b/packages/slate/test/interfaces/Path/equals/root.js new file mode 100644 index 0000000000..7bc860bcbd --- /dev/null +++ b/packages/slate/test/interfaces/Path/equals/root.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [], +} + +export const test = ({ path, another }) => { + return Path.equals(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAfter/above.js b/packages/slate/test/interfaces/Path/isAfter/above.js new file mode 100644 index 0000000000..6522e4fce0 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAfter/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAfter/after.js b/packages/slate/test/interfaces/Path/isAfter/after.js new file mode 100644 index 0000000000..e1ad98186b --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAfter/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isAfter(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isAfter/before.js b/packages/slate/test/interfaces/Path/isAfter/before.js new file mode 100644 index 0000000000..80f6aa92be --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAfter/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.isAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAfter/below.js b/packages/slate/test/interfaces/Path/isAfter/below.js new file mode 100644 index 0000000000..ed5a9568a5 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAfter/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAfter/equal.js b/packages/slate/test/interfaces/Path/isAfter/equal.js new file mode 100644 index 0000000000..5d8cd152d8 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAfter/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.isAfter(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAncestor/above-grandparent.js b/packages/slate/test/interfaces/Path/isAncestor/above-grandparent.js new file mode 100644 index 0000000000..79b9da3ab2 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAncestor/above-grandparent.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isAncestor(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isAncestor/above-parent.js b/packages/slate/test/interfaces/Path/isAncestor/above-parent.js new file mode 100644 index 0000000000..3eed026028 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAncestor/above-parent.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isAncestor(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isAncestor/after.js b/packages/slate/test/interfaces/Path/isAncestor/after.js new file mode 100644 index 0000000000..c2b2c3134a --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAncestor/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isAncestor(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAncestor/before.js b/packages/slate/test/interfaces/Path/isAncestor/before.js new file mode 100644 index 0000000000..f4952a9456 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAncestor/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.isAncestor(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAncestor/below.js b/packages/slate/test/interfaces/Path/isAncestor/below.js new file mode 100644 index 0000000000..f63e408d2b --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAncestor/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isAncestor(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isAncestor/equal.js b/packages/slate/test/interfaces/Path/isAncestor/equal.js new file mode 100644 index 0000000000..5cc1a7893d --- /dev/null +++ b/packages/slate/test/interfaces/Path/isAncestor/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.isAncestor(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isBefore/above.js b/packages/slate/test/interfaces/Path/isBefore/above.js new file mode 100644 index 0000000000..0fbd0c1535 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isBefore/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isBefore/after.js b/packages/slate/test/interfaces/Path/isBefore/after.js new file mode 100644 index 0000000000..d238a8005a --- /dev/null +++ b/packages/slate/test/interfaces/Path/isBefore/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isBefore/before.js b/packages/slate/test/interfaces/Path/isBefore/before.js new file mode 100644 index 0000000000..9c9d6ae50f --- /dev/null +++ b/packages/slate/test/interfaces/Path/isBefore/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.isBefore(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isBefore/below.js b/packages/slate/test/interfaces/Path/isBefore/below.js new file mode 100644 index 0000000000..73f4cbaaf1 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isBefore/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isBefore/equal.js b/packages/slate/test/interfaces/Path/isBefore/equal.js new file mode 100644 index 0000000000..398c31e33f --- /dev/null +++ b/packages/slate/test/interfaces/Path/isBefore/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.isBefore(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isChild/above.js b/packages/slate/test/interfaces/Path/isChild/above.js new file mode 100644 index 0000000000..8bd3a5497c --- /dev/null +++ b/packages/slate/test/interfaces/Path/isChild/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isChild(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isChild/after.js b/packages/slate/test/interfaces/Path/isChild/after.js new file mode 100644 index 0000000000..8f992b539d --- /dev/null +++ b/packages/slate/test/interfaces/Path/isChild/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isChild(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isChild/before.js b/packages/slate/test/interfaces/Path/isChild/before.js new file mode 100644 index 0000000000..2d33c258e6 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isChild/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.isChild(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isChild/below-child.js b/packages/slate/test/interfaces/Path/isChild/below-child.js new file mode 100644 index 0000000000..7e36ae2259 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isChild/below-child.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isChild(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isChild/below-grandchild.js b/packages/slate/test/interfaces/Path/isChild/below-grandchild.js new file mode 100644 index 0000000000..c90e76e086 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isChild/below-grandchild.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [], +} + +export const test = ({ path, another }) => { + return Path.isChild(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isChild/equal.js b/packages/slate/test/interfaces/Path/isChild/equal.js new file mode 100644 index 0000000000..0f73ff181a --- /dev/null +++ b/packages/slate/test/interfaces/Path/isChild/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.isChild(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isDescendant/above.js b/packages/slate/test/interfaces/Path/isDescendant/above.js new file mode 100644 index 0000000000..f933c22462 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isDescendant/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isDescendant(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isDescendant/after.js b/packages/slate/test/interfaces/Path/isDescendant/after.js new file mode 100644 index 0000000000..aa1bc800e7 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isDescendant/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isDescendant(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isDescendant/before.js b/packages/slate/test/interfaces/Path/isDescendant/before.js new file mode 100644 index 0000000000..ff861fa159 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isDescendant/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.isDescendant(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isDescendant/below-child.js b/packages/slate/test/interfaces/Path/isDescendant/below-child.js new file mode 100644 index 0000000000..7696b77689 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isDescendant/below-child.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isDescendant(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isDescendant/below-grandchild.js b/packages/slate/test/interfaces/Path/isDescendant/below-grandchild.js new file mode 100644 index 0000000000..bf7772ba19 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isDescendant/below-grandchild.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [], +} + +export const test = ({ path, another }) => { + return Path.isDescendant(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isDescendant/equal.js b/packages/slate/test/interfaces/Path/isDescendant/equal.js new file mode 100644 index 0000000000..3e9f369975 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isDescendant/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.isDescendant(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isParent/above-grandparent.js b/packages/slate/test/interfaces/Path/isParent/above-grandparent.js new file mode 100644 index 0000000000..b990f3aa60 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isParent/above-grandparent.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isParent(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isParent/above-parent.js b/packages/slate/test/interfaces/Path/isParent/above-parent.js new file mode 100644 index 0000000000..147251fc7d --- /dev/null +++ b/packages/slate/test/interfaces/Path/isParent/above-parent.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isParent(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isParent/after.js b/packages/slate/test/interfaces/Path/isParent/after.js new file mode 100644 index 0000000000..3ba765aacd --- /dev/null +++ b/packages/slate/test/interfaces/Path/isParent/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isParent(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isParent/before.js b/packages/slate/test/interfaces/Path/isParent/before.js new file mode 100644 index 0000000000..a21778cfcc --- /dev/null +++ b/packages/slate/test/interfaces/Path/isParent/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.isParent(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isParent/below.js b/packages/slate/test/interfaces/Path/isParent/below.js new file mode 100644 index 0000000000..f32fe4924c --- /dev/null +++ b/packages/slate/test/interfaces/Path/isParent/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isParent(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isParent/equal.js b/packages/slate/test/interfaces/Path/isParent/equal.js new file mode 100644 index 0000000000..05c1b55a2c --- /dev/null +++ b/packages/slate/test/interfaces/Path/isParent/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0, 1, 2], +} + +export const test = ({ path, another }) => { + return Path.isParent(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isPath/boolean.js b/packages/slate/test/interfaces/Path/isPath/boolean.js new file mode 100644 index 0000000000..d40dc2d67d --- /dev/null +++ b/packages/slate/test/interfaces/Path/isPath/boolean.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = true + +export const test = path => { + return Path.isPath(path) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isPath/empty.js b/packages/slate/test/interfaces/Path/isPath/empty.js new file mode 100644 index 0000000000..eaf502668a --- /dev/null +++ b/packages/slate/test/interfaces/Path/isPath/empty.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [] + +export const test = path => { + return Path.isPath(path) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isPath/full.js b/packages/slate/test/interfaces/Path/isPath/full.js new file mode 100644 index 0000000000..3f1d7fe2f2 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isPath/full.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1] + +export const test = path => { + return Path.isPath(path) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isPath/strings.js b/packages/slate/test/interfaces/Path/isPath/strings.js new file mode 100644 index 0000000000..5b58b04f61 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isPath/strings.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = ['a', 'b'] + +export const test = path => { + return Path.isPath(path) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isSibling/above.js b/packages/slate/test/interfaces/Path/isSibling/above.js new file mode 100644 index 0000000000..b1c480eee8 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isSibling/above.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isSibling(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isSibling/after-sibling.js b/packages/slate/test/interfaces/Path/isSibling/after-sibling.js new file mode 100644 index 0000000000..9bede3e2d2 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isSibling/after-sibling.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 4], + another: [1, 2], +} + +export const test = ({ path, another }) => { + return Path.isSibling(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isSibling/after.js b/packages/slate/test/interfaces/Path/isSibling/after.js new file mode 100644 index 0000000000..d2f1fbf535 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isSibling/after.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isSibling(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isSibling/before-sibling.js b/packages/slate/test/interfaces/Path/isSibling/before-sibling.js new file mode 100644 index 0000000000..ef951ce1a4 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isSibling/before-sibling.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [0, 3], +} + +export const test = ({ path, another }) => { + return Path.isSibling(path, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Path/isSibling/before.js b/packages/slate/test/interfaces/Path/isSibling/before.js new file mode 100644 index 0000000000..19ef5cacd7 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isSibling/before.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 2], + another: [1], +} + +export const test = ({ path, another }) => { + return Path.isSibling(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isSibling/below.js b/packages/slate/test/interfaces/Path/isSibling/below.js new file mode 100644 index 0000000000..4469a44f4a --- /dev/null +++ b/packages/slate/test/interfaces/Path/isSibling/below.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.isSibling(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/isSibling/equal.js b/packages/slate/test/interfaces/Path/isSibling/equal.js new file mode 100644 index 0000000000..14ce1931a1 --- /dev/null +++ b/packages/slate/test/interfaces/Path/isSibling/equal.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [0, 1], +} + +export const test = ({ path, another }) => { + return Path.isSibling(path, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Path/levels/reverse.js b/packages/slate/test/interfaces/Path/levels/reverse.js new file mode 100644 index 0000000000..4f1b8978e1 --- /dev/null +++ b/packages/slate/test/interfaces/Path/levels/reverse.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1, 2] + +export const test = path => { + return Path.levels(path, { reverse: true }) +} + +export const output = [[], [0], [0, 1], [0, 1, 2]] diff --git a/packages/slate/test/interfaces/Path/levels/success.js b/packages/slate/test/interfaces/Path/levels/success.js new file mode 100644 index 0000000000..6546dc06ff --- /dev/null +++ b/packages/slate/test/interfaces/Path/levels/success.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1, 2] + +export const test = path => { + return Path.levels(path) +} + +export const output = [[0, 1, 2], [0, 1], [0], []] diff --git a/packages/slate/test/interfaces/Path/next/success.js b/packages/slate/test/interfaces/Path/next/success.js new file mode 100644 index 0000000000..9080ef6259 --- /dev/null +++ b/packages/slate/test/interfaces/Path/next/success.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1] + +export const test = path => { + return Path.next(path) +} + +export const output = [0, 2] diff --git a/packages/slate/test/interfaces/Path/parent/success.js b/packages/slate/test/interfaces/Path/parent/success.js new file mode 100644 index 0000000000..d197cfeff6 --- /dev/null +++ b/packages/slate/test/interfaces/Path/parent/success.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1] + +export const test = path => { + return Path.parent(path) +} + +export const output = [0] diff --git a/packages/slate/test/interfaces/Path/previous/success.js b/packages/slate/test/interfaces/Path/previous/success.js new file mode 100644 index 0000000000..4361c0895a --- /dev/null +++ b/packages/slate/test/interfaces/Path/previous/success.js @@ -0,0 +1,9 @@ +import { Path } from 'slate' + +export const input = [0, 1] + +export const test = path => { + return Path.previous(path) +} + +export const output = [0, 0] diff --git a/packages/slate/test/interfaces/Path/relative/grandparent.js b/packages/slate/test/interfaces/Path/relative/grandparent.js new file mode 100644 index 0000000000..ed64643642 --- /dev/null +++ b/packages/slate/test/interfaces/Path/relative/grandparent.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1, 2], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.relative(path, another) +} + +export const output = [1, 2] diff --git a/packages/slate/test/interfaces/Path/relative/parent.js b/packages/slate/test/interfaces/Path/relative/parent.js new file mode 100644 index 0000000000..5682394a41 --- /dev/null +++ b/packages/slate/test/interfaces/Path/relative/parent.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [0], +} + +export const test = ({ path, another }) => { + return Path.relative(path, another) +} + +export const output = [1] diff --git a/packages/slate/test/interfaces/Path/relative/root.js b/packages/slate/test/interfaces/Path/relative/root.js new file mode 100644 index 0000000000..513f64569f --- /dev/null +++ b/packages/slate/test/interfaces/Path/relative/root.js @@ -0,0 +1,12 @@ +import { Path } from 'slate' + +export const input = { + path: [0, 1], + another: [], +} + +export const test = ({ path, another }) => { + return Path.relative(path, another) +} + +export const output = [0, 1] diff --git a/packages/slate/test/interfaces/Point/compare/path-after-offset-after.js b/packages/slate/test/interfaces/Point/compare/path-after-offset-after.js new file mode 100644 index 0000000000..03047e3e58 --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-after-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = 1 diff --git a/packages/slate/test/interfaces/Point/compare/path-after-offset-before.js b/packages/slate/test/interfaces/Point/compare/path-after-offset-before.js new file mode 100644 index 0000000000..087b8b3dd7 --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-after-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = 1 diff --git a/packages/slate/test/interfaces/Point/compare/path-after-offset-equal.js b/packages/slate/test/interfaces/Point/compare/path-after-offset-equal.js new file mode 100644 index 0000000000..bbea857b1f --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-after-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 3, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = 1 diff --git a/packages/slate/test/interfaces/Point/compare/path-before-offset-after.js b/packages/slate/test/interfaces/Point/compare/path-before-offset-after.js new file mode 100644 index 0000000000..ffd3e1b9af --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-before-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 4, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = -1 diff --git a/packages/slate/test/interfaces/Point/compare/path-before-offset-before.js b/packages/slate/test/interfaces/Point/compare/path-before-offset-before.js new file mode 100644 index 0000000000..ad1134ea25 --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-before-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = -1 diff --git a/packages/slate/test/interfaces/Point/compare/path-before-offset-equal.js b/packages/slate/test/interfaces/Point/compare/path-before-offset-equal.js new file mode 100644 index 0000000000..130ce8c41b --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-before-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = -1 diff --git a/packages/slate/test/interfaces/Point/compare/path-equal-offset-after.js b/packages/slate/test/interfaces/Point/compare/path-equal-offset-after.js new file mode 100644 index 0000000000..1e3fcb9af8 --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-equal-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = 1 diff --git a/packages/slate/test/interfaces/Point/compare/path-equal-offset-before.js b/packages/slate/test/interfaces/Point/compare/path-equal-offset-before.js new file mode 100644 index 0000000000..324c7347ff --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-equal-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = -1 diff --git a/packages/slate/test/interfaces/Point/compare/path-equal-offset-equal.js b/packages/slate/test/interfaces/Point/compare/path-equal-offset-equal.js new file mode 100644 index 0000000000..82a0e172de --- /dev/null +++ b/packages/slate/test/interfaces/Point/compare/path-equal-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 7, + }, +} + +export const test = ({ point, another }) => { + return Point.compare(point, another) +} + +export const output = 0 diff --git a/packages/slate/test/interfaces/Point/equals/path-after-offset-after.js b/packages/slate/test/interfaces/Point/equals/path-after-offset-after.js new file mode 100644 index 0000000000..42828b806b --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-after-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-after-offset-before.js b/packages/slate/test/interfaces/Point/equals/path-after-offset-before.js new file mode 100644 index 0000000000..474bdd8854 --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-after-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-after-offset-equal.js b/packages/slate/test/interfaces/Point/equals/path-after-offset-equal.js new file mode 100644 index 0000000000..fc36f852bf --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-after-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 3, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-before-offset-after.js b/packages/slate/test/interfaces/Point/equals/path-before-offset-after.js new file mode 100644 index 0000000000..d4678f1dc4 --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-before-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 4, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-before-offset-before.js b/packages/slate/test/interfaces/Point/equals/path-before-offset-before.js new file mode 100644 index 0000000000..96652a2fdf --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-before-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-before-offset-equal.js b/packages/slate/test/interfaces/Point/equals/path-before-offset-equal.js new file mode 100644 index 0000000000..39b1f509ca --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-before-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-equal-offset-after.js b/packages/slate/test/interfaces/Point/equals/path-equal-offset-after.js new file mode 100644 index 0000000000..c6c82d6a81 --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-equal-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-equal-offset-before.js b/packages/slate/test/interfaces/Point/equals/path-equal-offset-before.js new file mode 100644 index 0000000000..8c88dc9699 --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-equal-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/equals/path-equal-offset-equal.js b/packages/slate/test/interfaces/Point/equals/path-equal-offset-equal.js new file mode 100644 index 0000000000..32b0eb171e --- /dev/null +++ b/packages/slate/test/interfaces/Point/equals/path-equal-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 7, + }, +} + +export const test = ({ point, another }) => { + return Point.equals(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/path-after-offset-after.js b/packages/slate/test/interfaces/Point/isAfter/path-after-offset-after.js new file mode 100644 index 0000000000..0ba872dde8 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-after-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/path-after-offset-before.js b/packages/slate/test/interfaces/Point/isAfter/path-after-offset-before.js new file mode 100644 index 0000000000..38ff60c4e1 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-after-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/path-after-offset-equal.js b/packages/slate/test/interfaces/Point/isAfter/path-after-offset-equal.js new file mode 100644 index 0000000000..742cd520ce --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-after-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 3, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/path-before-offset-after.js b/packages/slate/test/interfaces/Point/isAfter/path-before-offset-after.js new file mode 100644 index 0000000000..6a2f3178f9 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-before-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 4, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/path-before-offset-before.js b/packages/slate/test/interfaces/Point/isAfter/path-before-offset-before.js new file mode 100644 index 0000000000..ce00dc88b0 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-before-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/path-before-offset-equal.js b/packages/slate/test/interfaces/Point/isAfter/path-before-offset-equal.js new file mode 100644 index 0000000000..c91b89d768 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-before-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-after.js b/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-after.js new file mode 100644 index 0000000000..24ff551ef7 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-before.js b/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-before.js new file mode 100644 index 0000000000..d5420fe582 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-equal.js b/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-equal.js new file mode 100644 index 0000000000..bae2e2e80a --- /dev/null +++ b/packages/slate/test/interfaces/Point/isAfter/path-equal-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 7, + }, +} + +export const test = ({ point, another }) => { + return Point.isAfter(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/point/offset-after.js b/packages/slate/test/interfaces/Point/isAfter/point/offset-after.js deleted file mode 100644 index c72504b411..0000000000 --- a/packages/slate/test/interfaces/Point/isAfter/point/offset-after.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Point } from 'slate' - -const point = { - path: [4], - offset: 3, -} - -const another = { - path: [4], - offset: 0, -} - -export const test = () => { - return Point.isAfter(point, another) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/point/offset-before.js b/packages/slate/test/interfaces/Point/isAfter/point/offset-before.js deleted file mode 100644 index b8f7c16800..0000000000 --- a/packages/slate/test/interfaces/Point/isAfter/point/offset-before.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Point } from 'slate' - -const point = { - path: [4], - offset: 0, -} - -const another = { - path: [4], - offset: 3, -} - -export const test = () => { - return Point.isAfter(point, another) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js b/packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js deleted file mode 100644 index 13cf6d47d7..0000000000 --- a/packages/slate/test/interfaces/Point/isAfter/point/offset-equal.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Point } from 'slate' - -const point = { - path: [4], - offset: 0, -} - -const another = { - path: [4], - offset: 0, -} - -export const test = () => { - return Point.isAfter(point, another) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/point/path-after.js b/packages/slate/test/interfaces/Point/isAfter/point/path-after.js deleted file mode 100644 index b669393245..0000000000 --- a/packages/slate/test/interfaces/Point/isAfter/point/path-after.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Point } from 'slate' - -const point = { - path: [8], - offset: 0, -} - -const another = { - path: [4], - offset: 0, -} - -export const test = () => { - return Point.isAfter(point, another) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Point/isAfter/point/path-before.js b/packages/slate/test/interfaces/Point/isAfter/point/path-before.js deleted file mode 100644 index 95e10ccee7..0000000000 --- a/packages/slate/test/interfaces/Point/isAfter/point/path-before.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Point } from 'slate' - -const point = { - path: [2], - offset: 0, -} - -const another = { - path: [4], - offset: 0, -} - -export const test = () => { - return Point.isAfter(point, another) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Point/isAfter/point/path-equal.js b/packages/slate/test/interfaces/Point/isAfter/point/path-equal.js deleted file mode 100644 index 13cf6d47d7..0000000000 --- a/packages/slate/test/interfaces/Point/isAfter/point/path-equal.js +++ /dev/null @@ -1,17 +0,0 @@ -import { Point } from 'slate' - -const point = { - path: [4], - offset: 0, -} - -const another = { - path: [4], - offset: 0, -} - -export const test = () => { - return Point.isAfter(point, another) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Point/isBefore/path-after-offset-after.js b/packages/slate/test/interfaces/Point/isBefore/path-after-offset-after.js new file mode 100644 index 0000000000..9790362348 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-after-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isBefore/path-after-offset-before.js b/packages/slate/test/interfaces/Point/isBefore/path-after-offset-before.js new file mode 100644 index 0000000000..f48a7c78d1 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-after-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isBefore/path-after-offset-equal.js b/packages/slate/test/interfaces/Point/isBefore/path-after-offset-equal.js new file mode 100644 index 0000000000..ac14d6b636 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-after-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 4], + offset: 3, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isBefore/path-before-offset-after.js b/packages/slate/test/interfaces/Point/isBefore/path-before-offset-after.js new file mode 100644 index 0000000000..328fb6499a --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-before-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 4, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isBefore/path-before-offset-before.js b/packages/slate/test/interfaces/Point/isBefore/path-before-offset-before.js new file mode 100644 index 0000000000..b050002886 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-before-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isBefore/path-before-offset-equal.js b/packages/slate/test/interfaces/Point/isBefore/path-before-offset-equal.js new file mode 100644 index 0000000000..1ddbbf00da --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-before-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 0], + offset: 0, + }, + another: { + path: [0, 1], + offset: 0, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-after.js b/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-after.js new file mode 100644 index 0000000000..33af77b84f --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-after.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-before.js b/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-before.js new file mode 100644 index 0000000000..87d279994e --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-before.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 0, + }, + another: { + path: [0, 1], + offset: 3, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-equal.js b/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-equal.js new file mode 100644 index 0000000000..df619ecef6 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isBefore/path-equal-offset-equal.js @@ -0,0 +1,18 @@ +import { Point } from 'slate' + +export const input = { + point: { + path: [0, 1], + offset: 7, + }, + another: { + path: [0, 1], + offset: 7, + }, +} + +export const test = ({ point, another }) => { + return Point.isBefore(point, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isPoint/boolean.js b/packages/slate/test/interfaces/Point/isPoint/boolean.js new file mode 100644 index 0000000000..cc8f2693ba --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/boolean.js @@ -0,0 +1,9 @@ +import { Point } from 'slate' + +export const input = true + +export const test = value => { + return Point.isPoint(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isPoint/custom-property.js b/packages/slate/test/interfaces/Point/isPoint/custom-property.js new file mode 100644 index 0000000000..b071a4f468 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/custom-property.js @@ -0,0 +1,13 @@ +import { Point } from 'slate' + +export const input = { + path: [0, 1], + offset: 0, + custom: 'value', +} + +export const test = value => { + return Point.isPoint(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isPoint/object.js b/packages/slate/test/interfaces/Point/isPoint/object.js new file mode 100644 index 0000000000..247b6f1633 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/object.js @@ -0,0 +1,9 @@ +import { Point } from 'slate' + +export const input = {} + +export const test = value => { + return Point.isPoint(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isPoint/offset.js b/packages/slate/test/interfaces/Point/isPoint/offset.js new file mode 100644 index 0000000000..bc55d68a52 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/offset.js @@ -0,0 +1,9 @@ +import { Point } from 'slate' + +export const input = 42 + +export const test = value => { + return Point.isPoint(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isPoint/path.js b/packages/slate/test/interfaces/Point/isPoint/path.js new file mode 100644 index 0000000000..0a7acd13ed --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/path.js @@ -0,0 +1,9 @@ +import { Point } from 'slate' + +export const input = [0, 1] + +export const test = value => { + return Point.isPoint(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isPoint/point.js b/packages/slate/test/interfaces/Point/isPoint/point.js new file mode 100644 index 0000000000..21a51e6b5c --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/point.js @@ -0,0 +1,12 @@ +import { Point } from 'slate' + +export const input = { + path: [0, 1], + offset: 0, +} + +export const test = value => { + return Point.isPoint(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/equals/equal.js b/packages/slate/test/interfaces/Range/equals/equal.js new file mode 100644 index 0000000000..7906da2756 --- /dev/null +++ b/packages/slate/test/interfaces/Range/equals/equal.js @@ -0,0 +1,30 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + }, + another: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + }, +} + +export const test = ({ range, another }) => { + return Range.equals(range, another) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/equals/not-equal.js b/packages/slate/test/interfaces/Range/equals/not-equal.js new file mode 100644 index 0000000000..376f35a107 --- /dev/null +++ b/packages/slate/test/interfaces/Range/equals/not-equal.js @@ -0,0 +1,30 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [0, 4], + offset: 7, + }, + focus: { + path: [0, 4], + offset: 7, + }, + }, + another: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + }, +} + +export const test = ({ range, another }) => { + return Range.equals(range, another) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/includes/path-after.js b/packages/slate/test/interfaces/Range/includes/path-after.js new file mode 100644 index 0000000000..259b703e38 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/path-after.js @@ -0,0 +1,21 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: [4], +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/includes/path-before.js b/packages/slate/test/interfaces/Range/includes/path-before.js new file mode 100644 index 0000000000..a5d2235a4b --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/path-before.js @@ -0,0 +1,21 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: [0], +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/includes/path-end.js b/packages/slate/test/interfaces/Range/includes/path-end.js new file mode 100644 index 0000000000..ce79d07262 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/path-end.js @@ -0,0 +1,21 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: [3], +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/includes/path-inside.js b/packages/slate/test/interfaces/Range/includes/path-inside.js new file mode 100644 index 0000000000..eaa6422e16 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/path-inside.js @@ -0,0 +1,21 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: [2], +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/includes/path-start.js b/packages/slate/test/interfaces/Range/includes/path-start.js new file mode 100644 index 0000000000..5be6a3bacc --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/path-start.js @@ -0,0 +1,21 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: [1], +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/includes/point-end.js b/packages/slate/test/interfaces/Range/includes/point-end.js new file mode 100644 index 0000000000..12a5416a00 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/point-end.js @@ -0,0 +1,24 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: { + path: [3], + offset: 0, + }, +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/includes/point-inside.js b/packages/slate/test/interfaces/Range/includes/point-inside.js new file mode 100644 index 0000000000..1ecf3fd626 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/point-inside.js @@ -0,0 +1,24 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: { + path: [2], + offset: 0, + }, +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/includes/point-offset-after.js b/packages/slate/test/interfaces/Range/includes/point-offset-after.js new file mode 100644 index 0000000000..01608fd9d4 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/point-offset-after.js @@ -0,0 +1,24 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: { + path: [3], + offset: 3, + }, +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/includes/point-offset-before.js b/packages/slate/test/interfaces/Range/includes/point-offset-before.js new file mode 100644 index 0000000000..4176bcdc68 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/point-offset-before.js @@ -0,0 +1,24 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 3, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: { + path: [1], + offset: 0, + }, +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/includes/point-path-after.js b/packages/slate/test/interfaces/Range/includes/point-path-after.js new file mode 100644 index 0000000000..6f2f57a877 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/point-path-after.js @@ -0,0 +1,24 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: { + path: [4], + offset: 0, + }, +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/includes/point-path-before.js b/packages/slate/test/interfaces/Range/includes/point-path-before.js new file mode 100644 index 0000000000..67e905cf4a --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/point-path-before.js @@ -0,0 +1,24 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: { + path: [0], + offset: 0, + }, +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/includes/point-start.js b/packages/slate/test/interfaces/Range/includes/point-start.js new file mode 100644 index 0000000000..8482569f58 --- /dev/null +++ b/packages/slate/test/interfaces/Range/includes/point-start.js @@ -0,0 +1,24 @@ +import { Range } from 'slate' + +export const input = { + range: { + anchor: { + path: [1], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, + }, + target: { + path: [1], + offset: 0, + }, +} + +export const test = ({ range, target }) => { + return Range.includes(range, target) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/isBackward/backward.js b/packages/slate/test/interfaces/Range/isBackward/backward.js new file mode 100644 index 0000000000..561297ef73 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isBackward/backward.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [3], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.isBackward(range) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/isBackward/collapsed.js b/packages/slate/test/interfaces/Range/isBackward/collapsed.js new file mode 100644 index 0000000000..f72bc10044 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isBackward/collapsed.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.isBackward(range) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isBackward/forward.js b/packages/slate/test/interfaces/Range/isBackward/forward.js new file mode 100644 index 0000000000..45b080c112 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isBackward/forward.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, +} + +export const test = range => { + return Range.isBackward(range) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isCollapsed/collapsed.js b/packages/slate/test/interfaces/Range/isCollapsed/collapsed.js new file mode 100644 index 0000000000..39b5d35a94 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isCollapsed/collapsed.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.isCollapsed(range) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/isCollapsed/expanded.js b/packages/slate/test/interfaces/Range/isCollapsed/expanded.js new file mode 100644 index 0000000000..7f369bfd6c --- /dev/null +++ b/packages/slate/test/interfaces/Range/isCollapsed/expanded.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, +} + +export const test = range => { + return Range.isCollapsed(range) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isExpanded/collapsed.js b/packages/slate/test/interfaces/Range/isExpanded/collapsed.js new file mode 100644 index 0000000000..3dd570b6f2 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isExpanded/collapsed.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.isExpanded(range) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isExpanded/expanded.js b/packages/slate/test/interfaces/Range/isExpanded/expanded.js new file mode 100644 index 0000000000..651a2a0833 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isExpanded/expanded.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, +} + +export const test = range => { + return Range.isExpanded(range) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/isForward/backward.js b/packages/slate/test/interfaces/Range/isForward/backward.js new file mode 100644 index 0000000000..5b52db7b15 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isForward/backward.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [3], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.isForward(range) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isForward/collapsed.js b/packages/slate/test/interfaces/Range/isForward/collapsed.js new file mode 100644 index 0000000000..99affc9bbc --- /dev/null +++ b/packages/slate/test/interfaces/Range/isForward/collapsed.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.isForward(range) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/isForward/forward.js b/packages/slate/test/interfaces/Range/isForward/forward.js new file mode 100644 index 0000000000..21ef55627a --- /dev/null +++ b/packages/slate/test/interfaces/Range/isForward/forward.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, +} + +export const test = range => { + return Range.isForward(range) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/isRange/boolean.js b/packages/slate/test/interfaces/Range/isRange/boolean.js new file mode 100644 index 0000000000..976cf2dfe9 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isRange/boolean.js @@ -0,0 +1,9 @@ +import { Range } from 'slate' + +export const input = true + +export const test = value => { + return Range.isRange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isRange/custom-property.js b/packages/slate/test/interfaces/Range/isRange/custom-property.js new file mode 100644 index 0000000000..7493dc3964 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isRange/custom-property.js @@ -0,0 +1,19 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + custom: 'value', +} + +export const test = value => { + return Range.isRange(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/isRange/object.js b/packages/slate/test/interfaces/Range/isRange/object.js new file mode 100644 index 0000000000..4c7bfa1ae9 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isRange/object.js @@ -0,0 +1,9 @@ +import { Range } from 'slate' + +export const input = {} + +export const test = value => { + return Range.isRange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isRange/range.js b/packages/slate/test/interfaces/Range/isRange/range.js new file mode 100644 index 0000000000..5a51576ca3 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isRange/range.js @@ -0,0 +1,18 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Range.isRange(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Range/points/backward.js b/packages/slate/test/interfaces/Range/points/backward.js new file mode 100644 index 0000000000..815a1db8d2 --- /dev/null +++ b/packages/slate/test/interfaces/Range/points/backward.js @@ -0,0 +1,27 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [3], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.points(range) +} + +export const output = [ + { + path: [0], + offset: 0, + }, + { + path: [3], + offset: 0, + }, +] diff --git a/packages/slate/test/interfaces/Range/points/collapsed.js b/packages/slate/test/interfaces/Range/points/collapsed.js new file mode 100644 index 0000000000..1e3f3ca264 --- /dev/null +++ b/packages/slate/test/interfaces/Range/points/collapsed.js @@ -0,0 +1,27 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, +} + +export const test = range => { + return Range.points(range) +} + +export const output = [ + { + path: [0], + offset: 0, + }, + { + path: [0], + offset: 0, + }, +] diff --git a/packages/slate/test/interfaces/Range/points/forward.js b/packages/slate/test/interfaces/Range/points/forward.js new file mode 100644 index 0000000000..dce7078186 --- /dev/null +++ b/packages/slate/test/interfaces/Range/points/forward.js @@ -0,0 +1,27 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [3], + offset: 0, + }, +} + +export const test = range => { + return Range.points(range) +} + +export const output = [ + { + path: [0], + offset: 0, + }, + { + path: [3], + offset: 0, + }, +] diff --git a/packages/slate/test/operations/apply/insert-text/annotation-before.js b/packages/slate/test/operations/apply/insert-text/annotation-before.js index 6bfc8445dd..ab0fb20b67 100644 --- a/packages/slate/test/operations/apply/insert-text/annotation-before.js +++ b/packages/slate/test/operations/apply/insert-text/annotation-before.js @@ -1,8 +1,17 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default [ +export const input = ( + + + w + ord + + +) + +export const operations = [ { type: 'insert_text', path: [0, 0], @@ -11,24 +20,11 @@ export default [ }, ] -export const input = ( - - - - w - ord - - - -) - export const output = ( - - - wx - ord - - + + wx + ord + ) diff --git a/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js b/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js index ec132ec271..1677acb224 100644 --- a/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js +++ b/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js @@ -1,8 +1,19 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default [ +export const input = ( + + + one + + + two + + +) + +export const operations = [ { type: 'merge_node', path: [1], @@ -13,31 +24,16 @@ export default [ { type: 'merge_node', path: [0, 1], - position: 1, + position: 3, properties: {}, target: null, }, ] -export const input = ( - - - - one - - - two - - - -) - export const output = ( - - - onetwo - - + + onetwo + ) From a9faf45ee70576ddaa719b747b6cdc6873eeac58 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 14 Oct 2019 17:05:55 -0400 Subject: [PATCH 029/165] add Annotation, Change, Element, Fragment, Mark, Range, Selection, Value interfaces tests --- packages/slate/src/interfaces/annotation.ts | 2 +- packages/slate/src/interfaces/mark.ts | 2 +- packages/slate/src/interfaces/selection.ts | 2 +- packages/slate/src/interfaces/value.ts | 4 +-- .../Annotation/isAnnotation/without-anchor.js | 14 +++++++++++ .../Annotation/isAnnotation/without-focus.js | 14 +++++++++++ .../annotation.js | 2 +- .../boolean.js | 2 +- .../empty.js | 2 +- .../full.js | 2 +- .../interfaces/Change/isChange/boolean.js | 9 +++++++ .../test/interfaces/Change/isChange/change.js | 16 ++++++++++++ .../Change/isChange/custom-property.js | 17 +++++++++++++ .../test/interfaces/Change/isChange/object.js | 9 +++++++ .../Change/isChange/without-operations.js | 15 +++++++++++ .../Change/isChange/without-value.js | 11 ++++++++ .../interfaces/Element/isElement/boolean.js | 9 +++++++ .../Element/isElement/custom-property.js | 12 +++++++++ .../interfaces/Element/isElement/element.js | 11 ++++++++ .../Element/isElement/nodes-full.js | 15 +++++++++++ .../interfaces/Element/isElement/object.js | 9 +++++++ .../Element/isElementList/boolean.js | 9 +++++++ .../Element/isElementList/element.js | 11 ++++++++ .../interfaces/Element/isElementList/empty.js | 9 +++++++ .../Element/isElementList/full-element.js | 13 ++++++++++ .../Element/isElementList/full-text.js | 14 +++++++++++ .../Element/isElementList/full-value.js | 15 +++++++++++ .../interfaces/Fragment/isFragment/boolean.js | 9 +++++++ .../Fragment/isFragment/custom-property.js | 12 +++++++++ .../Fragment/isFragment/fragment.js | 11 ++++++++ .../interfaces/Fragment/isFragment/object.js | 9 +++++++ .../Mark/exists/custom-prop-exists.js | 12 +++++++++ .../Mark/exists/custom-prop-not-exists.js | 12 +++++++++ .../Mark/exists/custom-prop-partial-exists.js | 12 +++++++++ .../Mark/exists/empty-mark-exists.js | 12 +++++++++ .../Mark/exists/empty-mark-partial-exists.js | 12 +++++++++ .../test/interfaces/Mark/exists/empty-set.js | 12 +++++++++ .../test/interfaces/Mark/isMark/boolean.js | 9 +++++++ .../interfaces/Mark/isMark/custom-property.js | 11 ++++++++ .../test/interfaces/Mark/isMark/object.js | 9 +++++++ .../test/interfaces/Mark/isMarkSet/boolean.js | 9 +++++++ .../test/interfaces/Mark/isMarkSet/empty.js | 9 +++++++ .../test/interfaces/Mark/isMarkSet/full.js | 9 +++++++ .../test/interfaces/Mark/isMarkSet/object.js | 9 +++++++ .../Mark/matches/custom-prop-match.js | 12 +++++++++ .../Mark/matches/custom-prop-not-match.js | 12 +++++++++ .../Mark/matches/custom-prop-partial-match.js | 12 +++++++++ .../Mark/matches/empty-mark-match.js | 12 +++++++++ .../Mark/matches/empty-mark-partial-match.js | 12 +++++++++ .../Point/isPoint/without-offset.js | 11 ++++++++ .../interfaces/Point/isPoint/without-path.js | 11 ++++++++ .../Range/isRange/without-anchor.js | 14 +++++++++++ .../interfaces/Range/isRange/without-focus.js | 14 +++++++++++ .../Selection/isSelection/boolean.js | 9 +++++++ .../Selection/isSelection/custom-property.js | 21 ++++++++++++++++ .../Selection/isSelection/is-focused-false.js | 20 +++++++++++++++ .../Selection/isSelection/marks-empty.js | 20 +++++++++++++++ .../Selection/isSelection/marks-full.js | 20 +++++++++++++++ .../Selection/isSelection/object.js | 9 +++++++ .../Selection/isSelection/selection.js | 20 +++++++++++++++ .../Selection/isSelection/without-anchor.js | 16 ++++++++++++ .../Selection/isSelection/without-focus.js | 16 ++++++++++++ .../isSelection/without-isFocused.js | 19 ++++++++++++++ .../Selection/isSelection/without-marks.js | 19 ++++++++++++++ .../test/interfaces/Value/isValue/boolean.js | 9 +++++++ .../Value/isValue/custom-property.js | 14 +++++++++++ .../Value/isValue/full-selection.js | 25 +++++++++++++++++++ .../test/interfaces/Value/isValue/object.js | 9 +++++++ .../test/interfaces/Value/isValue/value.js | 13 ++++++++++ .../Value/isValue/without-annotations.js | 12 +++++++++ .../interfaces/Value/isValue/without-nodes.js | 12 +++++++++ .../Value/isValue/without-selection.js | 12 +++++++++ 72 files changed, 824 insertions(+), 9 deletions(-) create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js create mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js rename packages/slate/test/interfaces/Annotation/{isAnnotationRecord => isAnnotationMap}/annotation.js (82%) rename packages/slate/test/interfaces/Annotation/{isAnnotationRecord => isAnnotationMap}/boolean.js (73%) rename packages/slate/test/interfaces/Annotation/{isAnnotationRecord => isAnnotationMap}/empty.js (72%) rename packages/slate/test/interfaces/Annotation/{isAnnotationRecord => isAnnotationMap}/full.js (84%) create mode 100644 packages/slate/test/interfaces/Change/isChange/boolean.js create mode 100644 packages/slate/test/interfaces/Change/isChange/change.js create mode 100644 packages/slate/test/interfaces/Change/isChange/custom-property.js create mode 100644 packages/slate/test/interfaces/Change/isChange/object.js create mode 100644 packages/slate/test/interfaces/Change/isChange/without-operations.js create mode 100644 packages/slate/test/interfaces/Change/isChange/without-value.js create mode 100644 packages/slate/test/interfaces/Element/isElement/boolean.js create mode 100644 packages/slate/test/interfaces/Element/isElement/custom-property.js create mode 100644 packages/slate/test/interfaces/Element/isElement/element.js create mode 100644 packages/slate/test/interfaces/Element/isElement/nodes-full.js create mode 100644 packages/slate/test/interfaces/Element/isElement/object.js create mode 100644 packages/slate/test/interfaces/Element/isElementList/boolean.js create mode 100644 packages/slate/test/interfaces/Element/isElementList/element.js create mode 100644 packages/slate/test/interfaces/Element/isElementList/empty.js create mode 100644 packages/slate/test/interfaces/Element/isElementList/full-element.js create mode 100644 packages/slate/test/interfaces/Element/isElementList/full-text.js create mode 100644 packages/slate/test/interfaces/Element/isElementList/full-value.js create mode 100644 packages/slate/test/interfaces/Fragment/isFragment/boolean.js create mode 100644 packages/slate/test/interfaces/Fragment/isFragment/custom-property.js create mode 100644 packages/slate/test/interfaces/Fragment/isFragment/fragment.js create mode 100644 packages/slate/test/interfaces/Fragment/isFragment/object.js create mode 100644 packages/slate/test/interfaces/Mark/exists/custom-prop-exists.js create mode 100644 packages/slate/test/interfaces/Mark/exists/custom-prop-not-exists.js create mode 100644 packages/slate/test/interfaces/Mark/exists/custom-prop-partial-exists.js create mode 100644 packages/slate/test/interfaces/Mark/exists/empty-mark-exists.js create mode 100644 packages/slate/test/interfaces/Mark/exists/empty-mark-partial-exists.js create mode 100644 packages/slate/test/interfaces/Mark/exists/empty-set.js create mode 100644 packages/slate/test/interfaces/Mark/isMark/boolean.js create mode 100644 packages/slate/test/interfaces/Mark/isMark/custom-property.js create mode 100644 packages/slate/test/interfaces/Mark/isMark/object.js create mode 100644 packages/slate/test/interfaces/Mark/isMarkSet/boolean.js create mode 100644 packages/slate/test/interfaces/Mark/isMarkSet/empty.js create mode 100644 packages/slate/test/interfaces/Mark/isMarkSet/full.js create mode 100644 packages/slate/test/interfaces/Mark/isMarkSet/object.js create mode 100644 packages/slate/test/interfaces/Mark/matches/custom-prop-match.js create mode 100644 packages/slate/test/interfaces/Mark/matches/custom-prop-not-match.js create mode 100644 packages/slate/test/interfaces/Mark/matches/custom-prop-partial-match.js create mode 100644 packages/slate/test/interfaces/Mark/matches/empty-mark-match.js create mode 100644 packages/slate/test/interfaces/Mark/matches/empty-mark-partial-match.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/without-offset.js create mode 100644 packages/slate/test/interfaces/Point/isPoint/without-path.js create mode 100644 packages/slate/test/interfaces/Range/isRange/without-anchor.js create mode 100644 packages/slate/test/interfaces/Range/isRange/without-focus.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/boolean.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/custom-property.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/marks-empty.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/marks-full.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/object.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/selection.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-anchor.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-focus.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js create mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-marks.js create mode 100644 packages/slate/test/interfaces/Value/isValue/boolean.js create mode 100644 packages/slate/test/interfaces/Value/isValue/custom-property.js create mode 100644 packages/slate/test/interfaces/Value/isValue/full-selection.js create mode 100644 packages/slate/test/interfaces/Value/isValue/object.js create mode 100644 packages/slate/test/interfaces/Value/isValue/value.js create mode 100644 packages/slate/test/interfaces/Value/isValue/without-annotations.js create mode 100644 packages/slate/test/interfaces/Value/isValue/without-nodes.js create mode 100644 packages/slate/test/interfaces/Value/isValue/without-selection.js diff --git a/packages/slate/src/interfaces/annotation.ts b/packages/slate/src/interfaces/annotation.ts index bfb4a92b65..46669d9971 100755 --- a/packages/slate/src/interfaces/annotation.ts +++ b/packages/slate/src/interfaces/annotation.ts @@ -30,7 +30,7 @@ namespace Annotation { * Check if a value is a map of `Annotation` objects. */ - export const isAnnotationRecord = ( + export const isAnnotationMap = ( value: any ): value is Record => { if (!isPlainObject(value)) { diff --git a/packages/slate/src/interfaces/mark.ts b/packages/slate/src/interfaces/mark.ts index 2044b020eb..e49f35239b 100755 --- a/packages/slate/src/interfaces/mark.ts +++ b/packages/slate/src/interfaces/mark.ts @@ -40,7 +40,7 @@ namespace Mark { * Check if a value is an array of `Mark` objects. */ - export const isMarkList = (value: any): value is Mark[] => { + export const isMarkSet = (value: any): value is Mark[] => { return Array.isArray(value) && (value.length === 0 || Mark.isMark(value[0])) } diff --git a/packages/slate/src/interfaces/selection.ts b/packages/slate/src/interfaces/selection.ts index e4e62f3a5d..bc2828e9ee 100755 --- a/packages/slate/src/interfaces/selection.ts +++ b/packages/slate/src/interfaces/selection.ts @@ -29,7 +29,7 @@ namespace Selection { return ( isPlainObject(value) && typeof value.isFocused === 'boolean' && - (value.marks == null || Mark.isMarkList(value.marks)) && + (value.marks === null || Mark.isMarkSet(value.marks)) && Range.isRange(value) ) } diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 59c4e0c38c..b526a7fa08 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -40,9 +40,9 @@ namespace Value { export const isValue = (value: any): value is Value => { return ( isPlainObject(value) && - Selection.isSelection(value.selection) && + (value.selection === null || Selection.isSelection(value.selection)) && Node.isNodeList(value.nodes) && - Annotation.isAnnotationRecord(value.annotations) + Annotation.isAnnotationMap(value.annotations) ) } diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js b/packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js new file mode 100644 index 0000000000..05ad30e351 --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js @@ -0,0 +1,14 @@ +import { Annotation } from 'slate' + +export const input = { + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Annotation.isAnnotation(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js b/packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js new file mode 100644 index 0000000000..39285cf5aa --- /dev/null +++ b/packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js @@ -0,0 +1,14 @@ +import { Annotation } from 'slate' + +export const input = { + anchor: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Annotation.isAnnotation(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/annotation.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/annotation.js similarity index 82% rename from packages/slate/test/interfaces/Annotation/isAnnotationRecord/annotation.js rename to packages/slate/test/interfaces/Annotation/isAnnotationMap/annotation.js index 63c84e5a70..5de86e02b8 100644 --- a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/annotation.js +++ b/packages/slate/test/interfaces/Annotation/isAnnotationMap/annotation.js @@ -12,7 +12,7 @@ export const input = { } export const test = value => { - return Annotation.isAnnotationRecord(value) + return Annotation.isAnnotationMap(value) } export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/boolean.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/boolean.js similarity index 73% rename from packages/slate/test/interfaces/Annotation/isAnnotationRecord/boolean.js rename to packages/slate/test/interfaces/Annotation/isAnnotationMap/boolean.js index 3b8508ec14..0292dd0306 100644 --- a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/boolean.js +++ b/packages/slate/test/interfaces/Annotation/isAnnotationMap/boolean.js @@ -3,7 +3,7 @@ import { Annotation } from 'slate' export const input = true export const test = value => { - return Annotation.isAnnotationRecord(value) + return Annotation.isAnnotationMap(value) } export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/empty.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/empty.js similarity index 72% rename from packages/slate/test/interfaces/Annotation/isAnnotationRecord/empty.js rename to packages/slate/test/interfaces/Annotation/isAnnotationMap/empty.js index 7d08145d01..7394641d10 100644 --- a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/empty.js +++ b/packages/slate/test/interfaces/Annotation/isAnnotationMap/empty.js @@ -3,7 +3,7 @@ import { Annotation } from 'slate' export const input = {} export const test = value => { - return Annotation.isAnnotationRecord(value) + return Annotation.isAnnotationMap(value) } export const output = true diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/full.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/full.js similarity index 84% rename from packages/slate/test/interfaces/Annotation/isAnnotationRecord/full.js rename to packages/slate/test/interfaces/Annotation/isAnnotationMap/full.js index 9e5cba0301..3b69d732ac 100644 --- a/packages/slate/test/interfaces/Annotation/isAnnotationRecord/full.js +++ b/packages/slate/test/interfaces/Annotation/isAnnotationMap/full.js @@ -14,7 +14,7 @@ export const input = { } export const test = value => { - return Annotation.isAnnotationRecord(value) + return Annotation.isAnnotationMap(value) } export const output = true diff --git a/packages/slate/test/interfaces/Change/isChange/boolean.js b/packages/slate/test/interfaces/Change/isChange/boolean.js new file mode 100644 index 0000000000..719335be45 --- /dev/null +++ b/packages/slate/test/interfaces/Change/isChange/boolean.js @@ -0,0 +1,9 @@ +import { Change } from 'slate' + +export const input = true + +export const test = value => { + return Change.isChange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Change/isChange/change.js b/packages/slate/test/interfaces/Change/isChange/change.js new file mode 100644 index 0000000000..8a241d824d --- /dev/null +++ b/packages/slate/test/interfaces/Change/isChange/change.js @@ -0,0 +1,16 @@ +import { Change } from 'slate' + +export const input = { + value: { + nodes: [], + selection: null, + annotations: {}, + }, + operations: [], +} + +export const test = value => { + return Change.isChange(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Change/isChange/custom-property.js b/packages/slate/test/interfaces/Change/isChange/custom-property.js new file mode 100644 index 0000000000..41ebde0cfd --- /dev/null +++ b/packages/slate/test/interfaces/Change/isChange/custom-property.js @@ -0,0 +1,17 @@ +import { Change } from 'slate' + +export const input = { + value: { + nodes: [], + selection: null, + annotations: {}, + }, + operations: [], + custom: true, +} + +export const test = value => { + return Change.isChange(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Change/isChange/object.js b/packages/slate/test/interfaces/Change/isChange/object.js new file mode 100644 index 0000000000..9f232bbd8c --- /dev/null +++ b/packages/slate/test/interfaces/Change/isChange/object.js @@ -0,0 +1,9 @@ +import { Change } from 'slate' + +export const input = {} + +export const test = value => { + return Change.isChange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Change/isChange/without-operations.js b/packages/slate/test/interfaces/Change/isChange/without-operations.js new file mode 100644 index 0000000000..c385532939 --- /dev/null +++ b/packages/slate/test/interfaces/Change/isChange/without-operations.js @@ -0,0 +1,15 @@ +import { Change } from 'slate' + +export const input = { + value: { + nodes: [], + selection: null, + annotations: {}, + }, +} + +export const test = value => { + return Change.isChange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Change/isChange/without-value.js b/packages/slate/test/interfaces/Change/isChange/without-value.js new file mode 100644 index 0000000000..622b35f286 --- /dev/null +++ b/packages/slate/test/interfaces/Change/isChange/without-value.js @@ -0,0 +1,11 @@ +import { Change } from 'slate' + +export const input = { + operations: [], +} + +export const test = value => { + return Change.isChange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElement/boolean.js b/packages/slate/test/interfaces/Element/isElement/boolean.js new file mode 100644 index 0000000000..4fcf64983b --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElement/boolean.js @@ -0,0 +1,9 @@ +import { Element } from 'slate' + +export const input = true + +export const test = value => { + return Element.isElement(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElement/custom-property.js b/packages/slate/test/interfaces/Element/isElement/custom-property.js new file mode 100644 index 0000000000..0a2d337b38 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElement/custom-property.js @@ -0,0 +1,12 @@ +import { Element } from 'slate' + +export const input = { + nodes: [], + custom: 'value', +} + +export const test = value => { + return Element.isElement(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/isElement/element.js b/packages/slate/test/interfaces/Element/isElement/element.js new file mode 100644 index 0000000000..ed6711b295 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElement/element.js @@ -0,0 +1,11 @@ +import { Element } from 'slate' + +export const input = { + nodes: [], +} + +export const test = value => { + return Element.isElement(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/isElement/nodes-full.js b/packages/slate/test/interfaces/Element/isElement/nodes-full.js new file mode 100644 index 0000000000..b19e4e05be --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElement/nodes-full.js @@ -0,0 +1,15 @@ +import { Element } from 'slate' + +export const input = { + nodes: [ + { + nodes: [], + }, + ], +} + +export const test = value => { + return Element.isElement(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/isElement/object.js b/packages/slate/test/interfaces/Element/isElement/object.js new file mode 100644 index 0000000000..568db5ad91 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElement/object.js @@ -0,0 +1,9 @@ +import { Element } from 'slate' + +export const input = {} + +export const test = value => { + return Element.isElement(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElementList/boolean.js b/packages/slate/test/interfaces/Element/isElementList/boolean.js new file mode 100644 index 0000000000..0ed3131704 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElementList/boolean.js @@ -0,0 +1,9 @@ +import { Element } from 'slate' + +export const input = true + +export const test = value => { + return Element.isElementList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElementList/element.js b/packages/slate/test/interfaces/Element/isElementList/element.js new file mode 100644 index 0000000000..0dc7f061f6 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElementList/element.js @@ -0,0 +1,11 @@ +import { Element } from 'slate' + +export const input = { + nodes: [], +} + +export const test = value => { + return Element.isElementList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElementList/empty.js b/packages/slate/test/interfaces/Element/isElementList/empty.js new file mode 100644 index 0000000000..5331e07043 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElementList/empty.js @@ -0,0 +1,9 @@ +import { Element } from 'slate' + +export const input = [] + +export const test = value => { + return Element.isElementList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/isElementList/full-element.js b/packages/slate/test/interfaces/Element/isElementList/full-element.js new file mode 100644 index 0000000000..13db074129 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElementList/full-element.js @@ -0,0 +1,13 @@ +import { Element } from 'slate' + +export const input = [ + { + nodes: [], + }, +] + +export const test = value => { + return Element.isElementList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/isElementList/full-text.js b/packages/slate/test/interfaces/Element/isElementList/full-text.js new file mode 100644 index 0000000000..16b0873a11 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElementList/full-text.js @@ -0,0 +1,14 @@ +import { Element } from 'slate' + +export const input = [ + { + text: '', + marks: [], + }, +] + +export const test = value => { + return Element.isElementList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElementList/full-value.js b/packages/slate/test/interfaces/Element/isElementList/full-value.js new file mode 100644 index 0000000000..1243f81d0f --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElementList/full-value.js @@ -0,0 +1,15 @@ +import { Element } from 'slate' + +export const input = [ + { + nodes: [], + selection: null, + annotations: {}, + }, +] + +export const test = value => { + return Element.isElementList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Fragment/isFragment/boolean.js b/packages/slate/test/interfaces/Fragment/isFragment/boolean.js new file mode 100644 index 0000000000..f75105f359 --- /dev/null +++ b/packages/slate/test/interfaces/Fragment/isFragment/boolean.js @@ -0,0 +1,9 @@ +import { Fragment } from 'slate' + +export const input = true + +export const test = value => { + return Fragment.isFragment(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Fragment/isFragment/custom-property.js b/packages/slate/test/interfaces/Fragment/isFragment/custom-property.js new file mode 100644 index 0000000000..9e8a39ba77 --- /dev/null +++ b/packages/slate/test/interfaces/Fragment/isFragment/custom-property.js @@ -0,0 +1,12 @@ +import { Fragment } from 'slate' + +export const input = { + nodes: [], + custom: true, +} + +export const test = value => { + return Fragment.isFragment(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Fragment/isFragment/fragment.js b/packages/slate/test/interfaces/Fragment/isFragment/fragment.js new file mode 100644 index 0000000000..4649395491 --- /dev/null +++ b/packages/slate/test/interfaces/Fragment/isFragment/fragment.js @@ -0,0 +1,11 @@ +import { Fragment } from 'slate' + +export const input = { + nodes: [], +} + +export const test = value => { + return Fragment.isFragment(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Fragment/isFragment/object.js b/packages/slate/test/interfaces/Fragment/isFragment/object.js new file mode 100644 index 0000000000..b9d8570e78 --- /dev/null +++ b/packages/slate/test/interfaces/Fragment/isFragment/object.js @@ -0,0 +1,9 @@ +import { Fragment } from 'slate' + +export const input = {} + +export const test = value => { + return Fragment.isFragment(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Mark/exists/custom-prop-exists.js b/packages/slate/test/interfaces/Mark/exists/custom-prop-exists.js new file mode 100644 index 0000000000..ebd3b973c5 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/exists/custom-prop-exists.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: { type: 'bold' }, + marks: [{ type: 'bold' }], +} + +export const test = ({ mark, marks }) => { + return Mark.exists(mark, marks) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/exists/custom-prop-not-exists.js b/packages/slate/test/interfaces/Mark/exists/custom-prop-not-exists.js new file mode 100644 index 0000000000..a1921b3fd5 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/exists/custom-prop-not-exists.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: { type: 'bold' }, + marks: [{ type: 'italic' }], +} + +export const test = ({ mark, marks }) => { + return Mark.exists(mark, marks) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Mark/exists/custom-prop-partial-exists.js b/packages/slate/test/interfaces/Mark/exists/custom-prop-partial-exists.js new file mode 100644 index 0000000000..42100c9986 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/exists/custom-prop-partial-exists.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: { type: 'bold' }, + marks: [{ type: 'bold', other: true }], +} + +export const test = ({ mark, marks }) => { + return Mark.exists(mark, marks) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/exists/empty-mark-exists.js b/packages/slate/test/interfaces/Mark/exists/empty-mark-exists.js new file mode 100644 index 0000000000..9dbe7b52db --- /dev/null +++ b/packages/slate/test/interfaces/Mark/exists/empty-mark-exists.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: {}, + marks: [{}], +} + +export const test = ({ mark, marks }) => { + return Mark.exists(mark, marks) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/exists/empty-mark-partial-exists.js b/packages/slate/test/interfaces/Mark/exists/empty-mark-partial-exists.js new file mode 100644 index 0000000000..481c6f05c7 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/exists/empty-mark-partial-exists.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: {}, + marks: [{ type: 'bold' }], +} + +export const test = ({ mark, marks }) => { + return Mark.exists(mark, marks) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/exists/empty-set.js b/packages/slate/test/interfaces/Mark/exists/empty-set.js new file mode 100644 index 0000000000..0acc2aba01 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/exists/empty-set.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: {}, + marks: [], +} + +export const test = ({ mark, marks }) => { + return Mark.exists(mark, marks) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Mark/isMark/boolean.js b/packages/slate/test/interfaces/Mark/isMark/boolean.js new file mode 100644 index 0000000000..9eda0c91ab --- /dev/null +++ b/packages/slate/test/interfaces/Mark/isMark/boolean.js @@ -0,0 +1,9 @@ +import { Mark } from 'slate' + +export const input = true + +export const test = value => { + return Mark.isMark(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Mark/isMark/custom-property.js b/packages/slate/test/interfaces/Mark/isMark/custom-property.js new file mode 100644 index 0000000000..1fef893a96 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/isMark/custom-property.js @@ -0,0 +1,11 @@ +import { Mark } from 'slate' + +export const input = { + custom: 'value', +} + +export const test = value => { + return Mark.isMark(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/isMark/object.js b/packages/slate/test/interfaces/Mark/isMark/object.js new file mode 100644 index 0000000000..21c32daf2f --- /dev/null +++ b/packages/slate/test/interfaces/Mark/isMark/object.js @@ -0,0 +1,9 @@ +import { Mark } from 'slate' + +export const input = {} + +export const test = value => { + return Mark.isMark(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/isMarkSet/boolean.js b/packages/slate/test/interfaces/Mark/isMarkSet/boolean.js new file mode 100644 index 0000000000..27c5e63447 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/isMarkSet/boolean.js @@ -0,0 +1,9 @@ +import { Mark } from 'slate' + +export const input = true + +export const test = value => { + return Mark.isMarkSet(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Mark/isMarkSet/empty.js b/packages/slate/test/interfaces/Mark/isMarkSet/empty.js new file mode 100644 index 0000000000..a1469fe8f6 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/isMarkSet/empty.js @@ -0,0 +1,9 @@ +import { Mark } from 'slate' + +export const input = [] + +export const test = value => { + return Mark.isMarkSet(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/isMarkSet/full.js b/packages/slate/test/interfaces/Mark/isMarkSet/full.js new file mode 100644 index 0000000000..5e3e8faa13 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/isMarkSet/full.js @@ -0,0 +1,9 @@ +import { Mark } from 'slate' + +export const input = [{}] + +export const test = value => { + return Mark.isMarkSet(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/isMarkSet/object.js b/packages/slate/test/interfaces/Mark/isMarkSet/object.js new file mode 100644 index 0000000000..424d46d243 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/isMarkSet/object.js @@ -0,0 +1,9 @@ +import { Mark } from 'slate' + +export const input = {} + +export const test = value => { + return Mark.isMarkSet(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Mark/matches/custom-prop-match.js b/packages/slate/test/interfaces/Mark/matches/custom-prop-match.js new file mode 100644 index 0000000000..e95ef52305 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/matches/custom-prop-match.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: { type: 'bold' }, + another: { type: 'bold' }, +} + +export const test = ({ mark, props }) => { + return Mark.matches(mark, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/matches/custom-prop-not-match.js b/packages/slate/test/interfaces/Mark/matches/custom-prop-not-match.js new file mode 100644 index 0000000000..60b00f680a --- /dev/null +++ b/packages/slate/test/interfaces/Mark/matches/custom-prop-not-match.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: { type: 'bold' }, + props: { type: 'italic' }, +} + +export const test = ({ mark, props }) => { + return Mark.matches(mark, props) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Mark/matches/custom-prop-partial-match.js b/packages/slate/test/interfaces/Mark/matches/custom-prop-partial-match.js new file mode 100644 index 0000000000..40ad88d083 --- /dev/null +++ b/packages/slate/test/interfaces/Mark/matches/custom-prop-partial-match.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: { type: 'bold', other: true }, + props: { type: 'bold' }, +} + +export const test = ({ mark, props }) => { + return Mark.matches(mark, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/matches/empty-mark-match.js b/packages/slate/test/interfaces/Mark/matches/empty-mark-match.js new file mode 100644 index 0000000000..0578f19aca --- /dev/null +++ b/packages/slate/test/interfaces/Mark/matches/empty-mark-match.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: {}, + props: {}, +} + +export const test = ({ mark, props }) => { + return Mark.matches(mark, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/matches/empty-mark-partial-match.js b/packages/slate/test/interfaces/Mark/matches/empty-mark-partial-match.js new file mode 100644 index 0000000000..5cb2bdaabe --- /dev/null +++ b/packages/slate/test/interfaces/Mark/matches/empty-mark-partial-match.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + mark: { type: 'bold' }, + props: {}, +} + +export const test = ({ mark, props }) => { + return Mark.matches(mark, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Point/isPoint/without-offset.js b/packages/slate/test/interfaces/Point/isPoint/without-offset.js new file mode 100644 index 0000000000..cc7db26639 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/without-offset.js @@ -0,0 +1,11 @@ +import { Point } from 'slate' + +export const input = { + path: [0, 1], +} + +export const test = value => { + return Point.isPoint(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Point/isPoint/without-path.js b/packages/slate/test/interfaces/Point/isPoint/without-path.js new file mode 100644 index 0000000000..f578ae7ea9 --- /dev/null +++ b/packages/slate/test/interfaces/Point/isPoint/without-path.js @@ -0,0 +1,11 @@ +import { Point } from 'slate' + +export const input = { + offset: 0, +} + +export const test = value => { + return Point.isPoint(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isRange/without-anchor.js b/packages/slate/test/interfaces/Range/isRange/without-anchor.js new file mode 100644 index 0000000000..a111399e63 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isRange/without-anchor.js @@ -0,0 +1,14 @@ +import { Range } from 'slate' + +export const input = { + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Range.isRange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Range/isRange/without-focus.js b/packages/slate/test/interfaces/Range/isRange/without-focus.js new file mode 100644 index 0000000000..4e2c5decb8 --- /dev/null +++ b/packages/slate/test/interfaces/Range/isRange/without-focus.js @@ -0,0 +1,14 @@ +import { Range } from 'slate' + +export const input = { + anchor: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Range.isRange(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/boolean.js b/packages/slate/test/interfaces/Selection/isSelection/boolean.js new file mode 100644 index 0000000000..90f3c77e53 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/boolean.js @@ -0,0 +1,9 @@ +import { Selection } from 'slate' + +export const input = true + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/custom-property.js b/packages/slate/test/interfaces/Selection/isSelection/custom-property.js new file mode 100644 index 0000000000..2927a075aa --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/custom-property.js @@ -0,0 +1,21 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: true, + marks: null, + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + custom: true, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js b/packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js new file mode 100644 index 0000000000..c005fa2753 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js @@ -0,0 +1,20 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: false, + marks: null, + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/marks-empty.js b/packages/slate/test/interfaces/Selection/isSelection/marks-empty.js new file mode 100644 index 0000000000..ed90e2b19e --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/marks-empty.js @@ -0,0 +1,20 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: true, + marks: [], + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/marks-full.js b/packages/slate/test/interfaces/Selection/isSelection/marks-full.js new file mode 100644 index 0000000000..7efe99d290 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/marks-full.js @@ -0,0 +1,20 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: true, + marks: [{}], + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/object.js b/packages/slate/test/interfaces/Selection/isSelection/object.js new file mode 100644 index 0000000000..8842bf23af --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/object.js @@ -0,0 +1,9 @@ +import { Selection } from 'slate' + +export const input = {} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/selection.js b/packages/slate/test/interfaces/Selection/isSelection/selection.js new file mode 100644 index 0000000000..c0cd9dc185 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/selection.js @@ -0,0 +1,20 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: true, + marks: null, + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-anchor.js b/packages/slate/test/interfaces/Selection/isSelection/without-anchor.js new file mode 100644 index 0000000000..f77cd93b13 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/without-anchor.js @@ -0,0 +1,16 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: true, + marks: null, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-focus.js b/packages/slate/test/interfaces/Selection/isSelection/without-focus.js new file mode 100644 index 0000000000..86c3ad3160 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/without-focus.js @@ -0,0 +1,16 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: true, + marks: null, + anchor: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js b/packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js new file mode 100644 index 0000000000..db60b18698 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js @@ -0,0 +1,19 @@ +import { Selection } from 'slate' + +export const input = { + marks: null, + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-marks.js b/packages/slate/test/interfaces/Selection/isSelection/without-marks.js new file mode 100644 index 0000000000..9f408c2e84 --- /dev/null +++ b/packages/slate/test/interfaces/Selection/isSelection/without-marks.js @@ -0,0 +1,19 @@ +import { Selection } from 'slate' + +export const input = { + isFocused: true, + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, +} + +export const test = value => { + return Selection.isSelection(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Value/isValue/boolean.js b/packages/slate/test/interfaces/Value/isValue/boolean.js new file mode 100644 index 0000000000..763f84768b --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/boolean.js @@ -0,0 +1,9 @@ +import { Value } from 'slate' + +export const input = true + +export const test = value => { + return Value.isValue(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Value/isValue/custom-property.js b/packages/slate/test/interfaces/Value/isValue/custom-property.js new file mode 100644 index 0000000000..374edc9ce3 --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/custom-property.js @@ -0,0 +1,14 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: null, + annotations: {}, + custom: true, +} + +export const test = value => { + return Value.isValue(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Value/isValue/full-selection.js b/packages/slate/test/interfaces/Value/isValue/full-selection.js new file mode 100644 index 0000000000..f2af1637db --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/full-selection.js @@ -0,0 +1,25 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: { + isFocused: true, + marks: [], + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, + }, + annotations: {}, + custom: true, +} + +export const test = value => { + return Value.isValue(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Value/isValue/object.js b/packages/slate/test/interfaces/Value/isValue/object.js new file mode 100644 index 0000000000..26351f8a0e --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/object.js @@ -0,0 +1,9 @@ +import { Value } from 'slate' + +export const input = {} + +export const test = value => { + return Value.isValue(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Value/isValue/value.js b/packages/slate/test/interfaces/Value/isValue/value.js new file mode 100644 index 0000000000..92f75d247b --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/value.js @@ -0,0 +1,13 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: null, + annotations: {}, +} + +export const test = value => { + return Value.isValue(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Value/isValue/without-annotations.js b/packages/slate/test/interfaces/Value/isValue/without-annotations.js new file mode 100644 index 0000000000..d56370405e --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/without-annotations.js @@ -0,0 +1,12 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: null, +} + +export const test = value => { + return Value.isValue(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Value/isValue/without-nodes.js b/packages/slate/test/interfaces/Value/isValue/without-nodes.js new file mode 100644 index 0000000000..53e8d07c9c --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/without-nodes.js @@ -0,0 +1,12 @@ +import { Value } from 'slate' + +export const input = { + selection: null, + annotations: {}, +} + +export const test = value => { + return Value.isValue(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Value/isValue/without-selection.js b/packages/slate/test/interfaces/Value/isValue/without-selection.js new file mode 100644 index 0000000000..a18db3b400 --- /dev/null +++ b/packages/slate/test/interfaces/Value/isValue/without-selection.js @@ -0,0 +1,12 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + annotations: {}, +} + +export const test = value => { + return Value.isValue(value) +} + +export const output = false From 3c8813daab65306b1ccc61c037ad92c0dff0335f Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 14 Oct 2019 17:21:44 -0400 Subject: [PATCH 030/165] add Operation and Text tests --- packages/slate/src/interfaces/operation.ts | 14 +++---- .../Operation/isOperation/add_annotation.js | 22 ++++++++++ .../Operation/isOperation/add_mark.js | 13 ++++++ .../Operation/isOperation/boolean.js | 9 +++++ .../Operation/isOperation/custom-property.js | 14 +++++++ .../Operation/isOperation/insert_node.js | 15 +++++++ .../Operation/isOperation/insert_text.js | 14 +++++++ .../Operation/isOperation/merge_node.js | 15 +++++++ .../Operation/isOperation/move_node.js | 13 ++++++ .../Operation/isOperation/object.js | 9 +++++ .../isOperation/remove_annotation.js | 22 ++++++++++ .../Operation/isOperation/remove_mark.js | 13 ++++++ .../Operation/isOperation/remove_node.js | 15 +++++++ .../Operation/isOperation/remove_text.js | 14 +++++++ .../Operation/isOperation/set_annotation.js | 14 +++++++ .../Operation/isOperation/set_mark.js | 14 +++++++ .../Operation/isOperation/set_node.js | 14 +++++++ .../Operation/isOperation/set_selection.js | 13 ++++++ .../Operation/isOperation/set_value.js | 13 ++++++ .../Operation/isOperation/split_node.js | 15 +++++++ .../Operation/isOperation/without-type.js | 12 ++++++ .../Operation/isOperationList/boolean.js | 9 +++++ .../Operation/isOperationList/empty.js | 9 +++++ .../Operation/isOperationList/full.js | 15 +++++++ .../Operation/isOperationList/operation.js | 13 ++++++ .../test/interfaces/Text/isText/boolean.js | 9 +++++ .../interfaces/Text/isText/custom-property.js | 13 ++++++ .../test/interfaces/Text/isText/marks-full.js | 12 ++++++ .../test/interfaces/Text/isText/object.js | 9 +++++ .../test/interfaces/Text/isText/text-full.js | 12 ++++++ .../slate/test/interfaces/Text/isText/text.js | 12 ++++++ .../interfaces/Text/isText/without-marks.js | 11 +++++ .../interfaces/Text/isText/without-text.js | 11 +++++ .../interfaces/Text/isTextList/boolean.js | 9 +++++ .../test/interfaces/Text/isTextList/empty.js | 9 +++++ .../Text/isTextList/full-element.js | 13 ++++++ .../interfaces/Text/isTextList/full-text.js | 14 +++++++ .../interfaces/Text/isTextList/full-value.js | 15 +++++++ .../test/interfaces/Text/isTextList/text.js | 12 ++++++ .../test/interfaces/Value/points/empty.js | 13 ++++++ .../Value/points/full-annotations.js | 27 +++++++++++++ .../points/full-selection-full-annotations.js | 40 +++++++++++++++++++ .../interfaces/Value/points/full-selection.js | 27 +++++++++++++ 43 files changed, 604 insertions(+), 7 deletions(-) create mode 100644 packages/slate/test/interfaces/Operation/isOperation/add_annotation.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/add_mark.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/boolean.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/custom-property.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/insert_node.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/insert_text.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/merge_node.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/move_node.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/object.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/remove_annotation.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/remove_mark.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/remove_node.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/remove_text.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/set_annotation.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/set_mark.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/set_node.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/set_selection.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/set_value.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/split_node.js create mode 100644 packages/slate/test/interfaces/Operation/isOperation/without-type.js create mode 100644 packages/slate/test/interfaces/Operation/isOperationList/boolean.js create mode 100644 packages/slate/test/interfaces/Operation/isOperationList/empty.js create mode 100644 packages/slate/test/interfaces/Operation/isOperationList/full.js create mode 100644 packages/slate/test/interfaces/Operation/isOperationList/operation.js create mode 100644 packages/slate/test/interfaces/Text/isText/boolean.js create mode 100644 packages/slate/test/interfaces/Text/isText/custom-property.js create mode 100644 packages/slate/test/interfaces/Text/isText/marks-full.js create mode 100644 packages/slate/test/interfaces/Text/isText/object.js create mode 100644 packages/slate/test/interfaces/Text/isText/text-full.js create mode 100644 packages/slate/test/interfaces/Text/isText/text.js create mode 100644 packages/slate/test/interfaces/Text/isText/without-marks.js create mode 100644 packages/slate/test/interfaces/Text/isText/without-text.js create mode 100644 packages/slate/test/interfaces/Text/isTextList/boolean.js create mode 100644 packages/slate/test/interfaces/Text/isTextList/empty.js create mode 100644 packages/slate/test/interfaces/Text/isTextList/full-element.js create mode 100644 packages/slate/test/interfaces/Text/isTextList/full-text.js create mode 100644 packages/slate/test/interfaces/Text/isTextList/full-value.js create mode 100644 packages/slate/test/interfaces/Text/isTextList/text.js create mode 100644 packages/slate/test/interfaces/Value/points/empty.js create mode 100644 packages/slate/test/interfaces/Value/points/full-annotations.js create mode 100644 packages/slate/test/interfaces/Value/points/full-selection-full-annotations.js create mode 100644 packages/slate/test/interfaces/Value/points/full-selection.js diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index 003fab3599..95a71dc202 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -1,13 +1,6 @@ import { Annotation, Mark, Node, Path } from '..' import isPlainObject from 'is-plain-object' -interface AddMarkOperation { - type: 'add_mark' - path: Path - mark: Mark - [key: string]: any -} - interface AddAnnotationOperation { type: 'add_annotation' key: string @@ -15,6 +8,13 @@ interface AddAnnotationOperation { [key: string]: any } +interface AddMarkOperation { + type: 'add_mark' + path: Path + mark: Mark + [key: string]: any +} + interface InsertNodeOperation { type: 'insert_node' path: Path diff --git a/packages/slate/test/interfaces/Operation/isOperation/add_annotation.js b/packages/slate/test/interfaces/Operation/isOperation/add_annotation.js new file mode 100644 index 0000000000..18300e6e21 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/add_annotation.js @@ -0,0 +1,22 @@ +import { Operation } from 'slate' + +export const input = { + type: 'add_annotation', + key: 'a', + annotation: { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, + }, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/add_mark.js b/packages/slate/test/interfaces/Operation/isOperation/add_mark.js new file mode 100644 index 0000000000..88ffbb4380 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/add_mark.js @@ -0,0 +1,13 @@ +import { Operation } from 'slate' + +export const input = { + type: 'add_mark', + path: [0], + mark: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/boolean.js b/packages/slate/test/interfaces/Operation/isOperation/boolean.js new file mode 100644 index 0000000000..b249c8f108 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/boolean.js @@ -0,0 +1,9 @@ +import { Operation } from 'slate' + +export const input = true + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Operation/isOperation/custom-property.js b/packages/slate/test/interfaces/Operation/isOperation/custom-property.js new file mode 100644 index 0000000000..1e52ca2581 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/custom-property.js @@ -0,0 +1,14 @@ +import { Operation } from 'slate' + +export const input = { + type: 'add_mark', + path: [0], + mark: {}, + custom: true, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/insert_node.js b/packages/slate/test/interfaces/Operation/isOperation/insert_node.js new file mode 100644 index 0000000000..4d11963406 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/insert_node.js @@ -0,0 +1,15 @@ +import { Operation } from 'slate' + +export const input = { + type: 'insert_node', + path: [0], + node: { + nodes: [], + }, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/insert_text.js b/packages/slate/test/interfaces/Operation/isOperation/insert_text.js new file mode 100644 index 0000000000..07786bb5ad --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/insert_text.js @@ -0,0 +1,14 @@ +import { Operation } from 'slate' + +export const input = { + type: 'insert_text', + path: [0], + offset: 0, + text: 'string', +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/merge_node.js b/packages/slate/test/interfaces/Operation/isOperation/merge_node.js new file mode 100644 index 0000000000..e4a092129f --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/merge_node.js @@ -0,0 +1,15 @@ +import { Operation } from 'slate' + +export const input = { + type: 'merge_node', + path: [0], + position: 0, + target: 0, + properties: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/move_node.js b/packages/slate/test/interfaces/Operation/isOperation/move_node.js new file mode 100644 index 0000000000..df1a76c5a8 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/move_node.js @@ -0,0 +1,13 @@ +import { Operation } from 'slate' + +export const input = { + type: 'move_node', + path: [0], + newPath: [1], +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/object.js b/packages/slate/test/interfaces/Operation/isOperation/object.js new file mode 100644 index 0000000000..66bbc4137a --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/object.js @@ -0,0 +1,9 @@ +import { Operation } from 'slate' + +export const input = {} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Operation/isOperation/remove_annotation.js b/packages/slate/test/interfaces/Operation/isOperation/remove_annotation.js new file mode 100644 index 0000000000..e644f0d819 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/remove_annotation.js @@ -0,0 +1,22 @@ +import { Operation } from 'slate' + +export const input = { + type: 'remove_annotation', + key: 'a', + annotation: { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, + }, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/remove_mark.js b/packages/slate/test/interfaces/Operation/isOperation/remove_mark.js new file mode 100644 index 0000000000..c7d5527e2e --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/remove_mark.js @@ -0,0 +1,13 @@ +import { Operation } from 'slate' + +export const input = { + type: 'remove_mark', + path: [0], + mark: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/remove_node.js b/packages/slate/test/interfaces/Operation/isOperation/remove_node.js new file mode 100644 index 0000000000..07d0f512c4 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/remove_node.js @@ -0,0 +1,15 @@ +import { Operation } from 'slate' + +export const input = { + type: 'remove_node', + path: [0], + node: { + nodes: [], + }, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/remove_text.js b/packages/slate/test/interfaces/Operation/isOperation/remove_text.js new file mode 100644 index 0000000000..cd1cedf9eb --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/remove_text.js @@ -0,0 +1,14 @@ +import { Operation } from 'slate' + +export const input = { + type: 'remove_text', + path: [0], + offset: 0, + text: 'string', +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/set_annotation.js b/packages/slate/test/interfaces/Operation/isOperation/set_annotation.js new file mode 100644 index 0000000000..0360d7fd44 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/set_annotation.js @@ -0,0 +1,14 @@ +import { Operation } from 'slate' + +export const input = { + type: 'set_annotation', + key: 'a', + properties: {}, + newProperties: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/set_mark.js b/packages/slate/test/interfaces/Operation/isOperation/set_mark.js new file mode 100644 index 0000000000..b4ccf616cc --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/set_mark.js @@ -0,0 +1,14 @@ +import { Operation } from 'slate' + +export const input = { + type: 'set_mark', + path: [0], + properties: {}, + newProperties: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/set_node.js b/packages/slate/test/interfaces/Operation/isOperation/set_node.js new file mode 100644 index 0000000000..9d6c80d3b1 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/set_node.js @@ -0,0 +1,14 @@ +import { Operation } from 'slate' + +export const input = { + type: 'set_node', + path: [0], + properties: {}, + newProperties: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/set_selection.js b/packages/slate/test/interfaces/Operation/isOperation/set_selection.js new file mode 100644 index 0000000000..b092c15e4d --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/set_selection.js @@ -0,0 +1,13 @@ +import { Operation } from 'slate' + +export const input = { + type: 'set_selection', + properties: {}, + newProperties: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/set_value.js b/packages/slate/test/interfaces/Operation/isOperation/set_value.js new file mode 100644 index 0000000000..71bef0491d --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/set_value.js @@ -0,0 +1,13 @@ +import { Operation } from 'slate' + +export const input = { + type: 'set_value', + properties: {}, + newProperties: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/split_node.js b/packages/slate/test/interfaces/Operation/isOperation/split_node.js new file mode 100644 index 0000000000..ef02c735db --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/split_node.js @@ -0,0 +1,15 @@ +import { Operation } from 'slate' + +export const input = { + type: 'split_node', + path: [0], + position: 0, + target: 0, + properties: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperation/without-type.js b/packages/slate/test/interfaces/Operation/isOperation/without-type.js new file mode 100644 index 0000000000..00668d080c --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperation/without-type.js @@ -0,0 +1,12 @@ +import { Operation } from 'slate' + +export const input = { + path: [0], + mark: {}, +} + +export const test = value => { + return Operation.isOperation(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Operation/isOperationList/boolean.js b/packages/slate/test/interfaces/Operation/isOperationList/boolean.js new file mode 100644 index 0000000000..5cc4c0a8f4 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperationList/boolean.js @@ -0,0 +1,9 @@ +import { Operation } from 'slate' + +export const input = true + +export const test = value => { + return Operation.isOperationList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Operation/isOperationList/empty.js b/packages/slate/test/interfaces/Operation/isOperationList/empty.js new file mode 100644 index 0000000000..774c0b50cf --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperationList/empty.js @@ -0,0 +1,9 @@ +import { Operation } from 'slate' + +export const input = [] + +export const test = value => { + return Operation.isOperationList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperationList/full.js b/packages/slate/test/interfaces/Operation/isOperationList/full.js new file mode 100644 index 0000000000..c94c992ddc --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperationList/full.js @@ -0,0 +1,15 @@ +import { Operation } from 'slate' + +export const input = [ + { + type: 'add_mark', + path: [0], + mark: {}, + }, +] + +export const test = value => { + return Operation.isOperationList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Operation/isOperationList/operation.js b/packages/slate/test/interfaces/Operation/isOperationList/operation.js new file mode 100644 index 0000000000..6e9516d656 --- /dev/null +++ b/packages/slate/test/interfaces/Operation/isOperationList/operation.js @@ -0,0 +1,13 @@ +import { Operation } from 'slate' + +export const input = { + type: 'add_mark', + path: [0], + mark: {}, +} + +export const test = value => { + return Operation.isOperationList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isText/boolean.js b/packages/slate/test/interfaces/Text/isText/boolean.js new file mode 100644 index 0000000000..c4fe584cc2 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/boolean.js @@ -0,0 +1,9 @@ +import { Text } from 'slate' + +export const input = true + +export const test = value => { + return Text.isText(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isText/custom-property.js b/packages/slate/test/interfaces/Text/isText/custom-property.js new file mode 100644 index 0000000000..610c50e222 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/custom-property.js @@ -0,0 +1,13 @@ +import { Text } from 'slate' + +export const input = { + text: '', + marks: [], + custom: true, +} + +export const test = value => { + return Text.isText(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Text/isText/marks-full.js b/packages/slate/test/interfaces/Text/isText/marks-full.js new file mode 100644 index 0000000000..9bca478af5 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/marks-full.js @@ -0,0 +1,12 @@ +import { Text } from 'slate' + +export const input = { + text: '', + marks: [{}], +} + +export const test = value => { + return Text.isText(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Text/isText/object.js b/packages/slate/test/interfaces/Text/isText/object.js new file mode 100644 index 0000000000..2ce196777e --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/object.js @@ -0,0 +1,9 @@ +import { Text } from 'slate' + +export const input = {} + +export const test = value => { + return Text.isText(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isText/text-full.js b/packages/slate/test/interfaces/Text/isText/text-full.js new file mode 100644 index 0000000000..0d0f662cb4 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/text-full.js @@ -0,0 +1,12 @@ +import { Text } from 'slate' + +export const input = { + text: 'string', + marks: [], +} + +export const test = value => { + return Text.isText(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Text/isText/text.js b/packages/slate/test/interfaces/Text/isText/text.js new file mode 100644 index 0000000000..6d78fb3dc0 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/text.js @@ -0,0 +1,12 @@ +import { Text } from 'slate' + +export const input = { + text: '', + marks: [], +} + +export const test = value => { + return Text.isText(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Text/isText/without-marks.js b/packages/slate/test/interfaces/Text/isText/without-marks.js new file mode 100644 index 0000000000..a3c34c02a6 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/without-marks.js @@ -0,0 +1,11 @@ +import { Text } from 'slate' + +export const input = { + text: '', +} + +export const test = value => { + return Text.isText(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isText/without-text.js b/packages/slate/test/interfaces/Text/isText/without-text.js new file mode 100644 index 0000000000..0b39452b5c --- /dev/null +++ b/packages/slate/test/interfaces/Text/isText/without-text.js @@ -0,0 +1,11 @@ +import { Text } from 'slate' + +export const input = { + marks: [], +} + +export const test = value => { + return Text.isText(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isTextList/boolean.js b/packages/slate/test/interfaces/Text/isTextList/boolean.js new file mode 100644 index 0000000000..f9d4baedc9 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isTextList/boolean.js @@ -0,0 +1,9 @@ +import { Text } from 'slate' + +export const input = true + +export const test = value => { + return Text.isTextList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isTextList/empty.js b/packages/slate/test/interfaces/Text/isTextList/empty.js new file mode 100644 index 0000000000..dd664f322d --- /dev/null +++ b/packages/slate/test/interfaces/Text/isTextList/empty.js @@ -0,0 +1,9 @@ +import { Text } from 'slate' + +export const input = [] + +export const test = value => { + return Text.isTextList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Text/isTextList/full-element.js b/packages/slate/test/interfaces/Text/isTextList/full-element.js new file mode 100644 index 0000000000..00098e2efa --- /dev/null +++ b/packages/slate/test/interfaces/Text/isTextList/full-element.js @@ -0,0 +1,13 @@ +import { Text } from 'slate' + +export const input = [ + { + nodes: [], + }, +] + +export const test = value => { + return Text.isTextList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isTextList/full-text.js b/packages/slate/test/interfaces/Text/isTextList/full-text.js new file mode 100644 index 0000000000..11541dc602 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isTextList/full-text.js @@ -0,0 +1,14 @@ +import { Text } from 'slate' + +export const input = [ + { + text: '', + marks: [], + }, +] + +export const test = value => { + return Text.isTextList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Text/isTextList/full-value.js b/packages/slate/test/interfaces/Text/isTextList/full-value.js new file mode 100644 index 0000000000..9222d9cb27 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isTextList/full-value.js @@ -0,0 +1,15 @@ +import { Text } from 'slate' + +export const input = [ + { + nodes: [], + selection: null, + annotations: {}, + }, +] + +export const test = value => { + return Text.isTextList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Text/isTextList/text.js b/packages/slate/test/interfaces/Text/isTextList/text.js new file mode 100644 index 0000000000..69848894b0 --- /dev/null +++ b/packages/slate/test/interfaces/Text/isTextList/text.js @@ -0,0 +1,12 @@ +import { Text } from 'slate' + +export const input = { + text: '', + marks: [], +} + +export const test = value => { + return Text.isTextList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Value/points/empty.js b/packages/slate/test/interfaces/Value/points/empty.js new file mode 100644 index 0000000000..bc0c447a3d --- /dev/null +++ b/packages/slate/test/interfaces/Value/points/empty.js @@ -0,0 +1,13 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: null, + annotations: {}, +} + +export const test = value => { + return Array.from(Value.points(value)) +} + +export const output = [] diff --git a/packages/slate/test/interfaces/Value/points/full-annotations.js b/packages/slate/test/interfaces/Value/points/full-annotations.js new file mode 100644 index 0000000000..ceae7e591b --- /dev/null +++ b/packages/slate/test/interfaces/Value/points/full-annotations.js @@ -0,0 +1,27 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: null, + annotations: { + a: { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, + }, + }, +} + +export const test = value => { + return Array.from(Value.points(value)) +} + +export const output = [ + [input.annotations.a.anchor, 'anchor', input.annotations.a, 'a'], + [input.annotations.a.focus, 'focus', input.annotations.a, 'a'], +] diff --git a/packages/slate/test/interfaces/Value/points/full-selection-full-annotations.js b/packages/slate/test/interfaces/Value/points/full-selection-full-annotations.js new file mode 100644 index 0000000000..d001d4d5db --- /dev/null +++ b/packages/slate/test/interfaces/Value/points/full-selection-full-annotations.js @@ -0,0 +1,40 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: { + isFocused: true, + marks: [], + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, + }, + annotations: { + a: { + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, + }, + }, +} + +export const test = value => { + return Array.from(Value.points(value)) +} + +export const output = [ + [input.selection.anchor, 'anchor', input.selection], + [input.selection.focus, 'focus', input.selection], + [input.annotations.a.anchor, 'anchor', input.annotations.a, 'a'], + [input.annotations.a.focus, 'focus', input.annotations.a, 'a'], +] diff --git a/packages/slate/test/interfaces/Value/points/full-selection.js b/packages/slate/test/interfaces/Value/points/full-selection.js new file mode 100644 index 0000000000..812ccae785 --- /dev/null +++ b/packages/slate/test/interfaces/Value/points/full-selection.js @@ -0,0 +1,27 @@ +import { Value } from 'slate' + +export const input = { + nodes: [], + selection: { + isFocused: true, + marks: [], + anchor: { + path: [0], + offset: 0, + }, + focus: { + path: [0], + offset: 0, + }, + }, + annotations: {}, +} + +export const test = value => { + return Array.from(Value.points(value)) +} + +export const output = [ + [input.selection.anchor, 'anchor', input.selection], + [input.selection.focus, 'focus', input.selection], +] From af3b8fd9745e3c92c75984ae2a090264d1d2a849 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 14 Oct 2019 21:49:19 -0400 Subject: [PATCH 031/165] add Node tests --- .eslintrc | 1 - packages/slate-hyperscript/src/creators.ts | 5 +- packages/slate/src/classes/commands/range.ts | 14 ++--- packages/slate/src/classes/queries/path.ts | 8 +-- packages/slate/src/interfaces/element.ts | 33 ++++++++++- packages/slate/src/interfaces/node.ts | 53 ++++------------- packages/slate/src/interfaces/path.ts | 12 ++-- packages/slate/src/interfaces/value.ts | 11 ++-- .../test/interfaces/Element/isElement/text.js | 12 ++++ .../interfaces/Element/isElement/value.js | 13 +++++ .../Element/isElementList/full-value.js | 2 +- .../Element/matches/custom-prop-match.js | 12 ++++ .../Element/matches/custom-prop-not-match.js | 12 ++++ .../matches/custom-prop-partial-match.js | 12 ++++ .../interfaces/Element/matches/empty-match.js | 12 ++++ .../Element/matches/empty-partial-match.js | 12 ++++ .../Mark/matches/custom-prop-match.js | 2 +- .../{empty-mark-match.js => empty-match.js} | 0 ...artial-match.js => empty-partial-match.js} | 0 .../test/interfaces/Node/ancestor/success.js | 18 ++++++ .../test/interfaces/Node/ancestors/reverse.js | 18 ++++++ .../test/interfaces/Node/ancestors/success.js | 18 ++++++ .../test/interfaces/Node/child/success.js | 18 ++++++ .../test/interfaces/Node/closest/success.js | 25 ++++++++ .../interfaces/Node/descendant/success.js | 18 ++++++ .../test/interfaces/Node/descendants/all.js | 29 ++++++++++ .../test/interfaces/Node/descendants/path.js | 28 +++++++++ .../test/interfaces/Node/descendants/range.js | 46 +++++++++++++++ .../interfaces/Node/descendants/reverse.js | 29 ++++++++++ .../test/interfaces/Node/elements/all.js | 27 +++++++++ .../test/interfaces/Node/elements/path.js | 27 +++++++++ .../test/interfaces/Node/elements/range.js | 44 ++++++++++++++ .../test/interfaces/Node/elements/reverse.js | 27 +++++++++ .../slate/test/interfaces/Node/entries/all.js | 38 +++++++++++++ .../test/interfaces/Node/entries/path.js | 37 ++++++++++++ .../test/interfaces/Node/entries/range.js | 57 +++++++++++++++++++ .../test/interfaces/Node/entries/reverse.js | 38 +++++++++++++ .../test/interfaces/Node/furthest/success.js | 27 +++++++++ .../slate/test/interfaces/Node/get/root.js | 24 ++++++++ .../slate/test/interfaces/Node/get/success.js | 22 +++++++ .../slate/test/interfaces/Node/has/exists.js | 18 ++++++ .../test/interfaces/Node/has/not-exists.js | 18 ++++++ .../test/interfaces/Node/isNode/boolean.js | 9 +++ .../interfaces/Node/isNode/custom-property.js | 12 ++++ .../test/interfaces/Node/isNode/element.js | 11 ++++ .../test/interfaces/Node/isNode/object.js | 9 +++ .../slate/test/interfaces/Node/isNode/text.js | 12 ++++ .../test/interfaces/Node/isNode/value.js | 13 +++++ .../interfaces/Node/isNodeList/boolean.js | 9 +++ .../interfaces/Node/isNodeList/element.js | 11 ++++ .../test/interfaces/Node/isNodeList/empty.js | 9 +++ .../Node/isNodeList/full-element.js | 13 +++++ .../interfaces/Node/isNodeList/full-text.js | 14 +++++ .../interfaces/Node/isNodeList/full-value.js | 15 +++++ .../test/interfaces/Node/leaf/success.js | 18 ++++++ .../test/interfaces/Node/levels/reverse.js | 22 +++++++ .../test/interfaces/Node/levels/success.js | 22 +++++++ .../slate/test/interfaces/Node/marks/all.js | 22 +++++++ .../slate/test/interfaces/Node/marks/path.js | 19 +++++++ .../slate/test/interfaces/Node/marks/range.js | 36 ++++++++++++ .../test/interfaces/Node/marks/reverse.js | 22 +++++++ .../interfaces/Node/offset/across-elements.js | 23 ++++++++ .../test/interfaces/Node/offset/element.js | 23 ++++++++ .../slate/test/interfaces/Node/offset/end.js | 20 +++++++ .../test/interfaces/Node/offset/middle.js | 20 +++++++ .../test/interfaces/Node/offset/start.js | 20 +++++++ .../test/interfaces/Node/parent/success.js | 22 +++++++ .../interfaces/Node/text/across-elements.js | 23 ++++++++ .../test/interfaces/Node/text/element.js | 17 ++++++ .../slate/test/interfaces/Node/text/text.js | 12 ++++ .../slate/test/interfaces/Node/texts/all.js | 19 +++++++ .../slate/test/interfaces/Node/texts/path.js | 19 +++++++ .../slate/test/interfaces/Node/texts/range.js | 34 +++++++++++ .../test/interfaces/Node/texts/reverse.js | 19 +++++++ 74 files changed, 1371 insertions(+), 75 deletions(-) create mode 100644 packages/slate/test/interfaces/Element/isElement/text.js create mode 100644 packages/slate/test/interfaces/Element/isElement/value.js create mode 100644 packages/slate/test/interfaces/Element/matches/custom-prop-match.js create mode 100644 packages/slate/test/interfaces/Element/matches/custom-prop-not-match.js create mode 100644 packages/slate/test/interfaces/Element/matches/custom-prop-partial-match.js create mode 100644 packages/slate/test/interfaces/Element/matches/empty-match.js create mode 100644 packages/slate/test/interfaces/Element/matches/empty-partial-match.js rename packages/slate/test/interfaces/Mark/matches/{empty-mark-match.js => empty-match.js} (100%) rename packages/slate/test/interfaces/Mark/matches/{empty-mark-partial-match.js => empty-partial-match.js} (100%) create mode 100644 packages/slate/test/interfaces/Node/ancestor/success.js create mode 100644 packages/slate/test/interfaces/Node/ancestors/reverse.js create mode 100644 packages/slate/test/interfaces/Node/ancestors/success.js create mode 100644 packages/slate/test/interfaces/Node/child/success.js create mode 100644 packages/slate/test/interfaces/Node/closest/success.js create mode 100644 packages/slate/test/interfaces/Node/descendant/success.js create mode 100644 packages/slate/test/interfaces/Node/descendants/all.js create mode 100644 packages/slate/test/interfaces/Node/descendants/path.js create mode 100644 packages/slate/test/interfaces/Node/descendants/range.js create mode 100644 packages/slate/test/interfaces/Node/descendants/reverse.js create mode 100644 packages/slate/test/interfaces/Node/elements/all.js create mode 100644 packages/slate/test/interfaces/Node/elements/path.js create mode 100644 packages/slate/test/interfaces/Node/elements/range.js create mode 100644 packages/slate/test/interfaces/Node/elements/reverse.js create mode 100644 packages/slate/test/interfaces/Node/entries/all.js create mode 100644 packages/slate/test/interfaces/Node/entries/path.js create mode 100644 packages/slate/test/interfaces/Node/entries/range.js create mode 100644 packages/slate/test/interfaces/Node/entries/reverse.js create mode 100644 packages/slate/test/interfaces/Node/furthest/success.js create mode 100644 packages/slate/test/interfaces/Node/get/root.js create mode 100644 packages/slate/test/interfaces/Node/get/success.js create mode 100644 packages/slate/test/interfaces/Node/has/exists.js create mode 100644 packages/slate/test/interfaces/Node/has/not-exists.js create mode 100644 packages/slate/test/interfaces/Node/isNode/boolean.js create mode 100644 packages/slate/test/interfaces/Node/isNode/custom-property.js create mode 100644 packages/slate/test/interfaces/Node/isNode/element.js create mode 100644 packages/slate/test/interfaces/Node/isNode/object.js create mode 100644 packages/slate/test/interfaces/Node/isNode/text.js create mode 100644 packages/slate/test/interfaces/Node/isNode/value.js create mode 100644 packages/slate/test/interfaces/Node/isNodeList/boolean.js create mode 100644 packages/slate/test/interfaces/Node/isNodeList/element.js create mode 100644 packages/slate/test/interfaces/Node/isNodeList/empty.js create mode 100644 packages/slate/test/interfaces/Node/isNodeList/full-element.js create mode 100644 packages/slate/test/interfaces/Node/isNodeList/full-text.js create mode 100644 packages/slate/test/interfaces/Node/isNodeList/full-value.js create mode 100644 packages/slate/test/interfaces/Node/leaf/success.js create mode 100644 packages/slate/test/interfaces/Node/levels/reverse.js create mode 100644 packages/slate/test/interfaces/Node/levels/success.js create mode 100644 packages/slate/test/interfaces/Node/marks/all.js create mode 100644 packages/slate/test/interfaces/Node/marks/path.js create mode 100644 packages/slate/test/interfaces/Node/marks/range.js create mode 100644 packages/slate/test/interfaces/Node/marks/reverse.js create mode 100644 packages/slate/test/interfaces/Node/offset/across-elements.js create mode 100644 packages/slate/test/interfaces/Node/offset/element.js create mode 100644 packages/slate/test/interfaces/Node/offset/end.js create mode 100644 packages/slate/test/interfaces/Node/offset/middle.js create mode 100644 packages/slate/test/interfaces/Node/offset/start.js create mode 100644 packages/slate/test/interfaces/Node/parent/success.js create mode 100644 packages/slate/test/interfaces/Node/text/across-elements.js create mode 100644 packages/slate/test/interfaces/Node/text/element.js create mode 100644 packages/slate/test/interfaces/Node/text/text.js create mode 100644 packages/slate/test/interfaces/Node/texts/all.js create mode 100644 packages/slate/test/interfaces/Node/texts/path.js create mode 100644 packages/slate/test/interfaces/Node/texts/range.js create mode 100644 packages/slate/test/interfaces/Node/texts/reverse.js diff --git a/.eslintrc b/.eslintrc index e322094fe7..faf0db9fdd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -120,7 +120,6 @@ "prettier/prettier": "error", "radix": "error", "react/jsx-boolean-value": ["error", "never"], - "react/jsx-key": "error", "react/jsx-no-duplicate-props": "error", "react/jsx-no-target-blank": "error", "react/jsx-no-undef": "error", diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts index 16edde5ec8..cafbdbe9fd 100644 --- a/packages/slate-hyperscript/src/creators.ts +++ b/packages/slate-hyperscript/src/creators.ts @@ -190,8 +190,9 @@ export function createText( The hyperscript tag can only contain text content as children.`) } - Object.assign(node, attributes) - return node + // COMPAT: Re-create the node, because if they used the tag we want to + // guarantee that it won't be merge with other string children. + return { ...node, ...attributes } } /** diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index 2c1b1b71bb..86ce0c111b 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -1,4 +1,4 @@ -import { Editor, Fragment, Mark, Element, Node, Path, Range } from '../..' +import { Editor, Fragment, Mark, Element, Path, Range } from '../..' class RangeCommands { /** @@ -301,9 +301,9 @@ class RangeCommands { toggleMarkAtRange(this: Editor, range: Range, mark: Mark): void { this.withoutNormalizing(() => { - for (const [node, path] of this.texts({ range })) { + for (const [text, path] of this.texts({ range })) { this.apply({ - type: Mark.exists(mark, node.marks) ? 'remove_mark' : 'add_mark', + type: Mark.exists(mark, text.marks) ? 'remove_mark' : 'add_mark', path, mark, }) @@ -318,8 +318,8 @@ class RangeCommands { unwrapBlockAtRange(this: Editor, range: Range, props: {}) { this.withoutNormalizing(() => { // Iterate in reverse to ensure unwrapping doesn't affect path lookups. - for (const [node, path] of this.blocks({ range, reverse: true })) { - if (Node.matches(node, props)) { + for (const [element, path] of this.blocks({ range, reverse: true })) { + if (Element.matches(element, props)) { this.unwrapChildrenAtPath(path) } } @@ -333,8 +333,8 @@ class RangeCommands { unwrapInlineAtRange(this: Editor, range: Range, props: {}) { this.withoutNormalizing(() => { // Iterate in reverse to ensure unwrapping doesn't affect path lookups. - for (const [node, path] of this.inlines({ range, reverse: true })) { - if (Node.matches(node, props)) { + for (const [element, path] of this.inlines({ range, reverse: true })) { + if (Element.matches(element, props)) { this.unwrapChildrenAtPath(path) } } diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index bb6a817ca6..2e1154c175 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -221,8 +221,8 @@ class PathQueries { getNextText(this: Editor, path: Path): TextEntry | undefined { const { value } = this - const [entry] = Node.texts(value, { path }) - return entry + const [, next] = Node.texts(value, { path }) + return next } /** @@ -283,8 +283,8 @@ class PathQueries { getPreviousText(this: Editor, path: Path): TextEntry | undefined { const { value } = this - const [entry] = Node.texts(value, { path, reverse: true }) - return entry + const [, prev] = Node.texts(value, { path, reverse: true }) + return prev } /** diff --git a/packages/slate/src/interfaces/element.ts b/packages/slate/src/interfaces/element.ts index 30ced8f9a6..8207615c01 100755 --- a/packages/slate/src/interfaces/element.ts +++ b/packages/slate/src/interfaces/element.ts @@ -1,6 +1,5 @@ -import { produce } from 'immer' import isPlainObject from 'is-plain-object' -import { Node, Path, Text } from '..' +import { Node, Path, Value } from '..' /** * `Element` objects are a type of node in a Slate document that contain other @@ -26,7 +25,11 @@ namespace Element { */ export const isElement = (value: any): value is Element => { - return isPlainObject(value) && Node.isNodeList(value.nodes) + return ( + isPlainObject(value) && + Node.isNodeList(value.nodes) && + !Value.isValue(value) + ) } /** @@ -39,6 +42,30 @@ namespace Element { (value.length === 0 || Element.isElement(value[0])) ) } + + /** + * Check if an element matches set of properties. + * + * Note: the is for checking custom properties, and it does not ensure that + * any children in the `nodes` property are equal. + */ + + export const matches = ( + element: Element, + props: Partial + ): boolean => { + for (const key in props) { + if (key === 'nodes') { + continue + } + + if (element[key] !== props[key]) { + return false + } + } + + return true + } } export { Element, ElementEntry } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 9adb443a2b..876fc8b969 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -66,7 +66,7 @@ namespace Node { if (Text.isText(node)) { throw new Error( - `Cannot get the ancestor node at ${path} because it refers to a text node instead: ${node}` + `Cannot get the ancestor node at path [${path}] because it refers to a text node instead: ${node}` ) } @@ -106,7 +106,7 @@ namespace Node { const c = root.nodes[index] as Descendant if (c == null) { - throw new Error(`Cannot get child at index ${index} in node: ${root}`) + throw new Error(`Cannot get child at index \`${index}\` in node: ${root}`) } return c @@ -137,7 +137,7 @@ namespace Node { if (Value.isValue(node)) { throw new Error( - `Cannot get the descendant node at ${path} because it refers to a value node instead: ${node}` + `Cannot get the descendant node at path [${path}] because it refers to a value node instead: ${node}` ) } @@ -154,7 +154,6 @@ namespace Node { path?: Path range?: Range reverse?: boolean - inclusive?: boolean } = {} ): Iterable { for (const [node, path] of Node.entries(root, options)) { @@ -178,7 +177,6 @@ namespace Node { path?: Path range?: Range reverse?: boolean - inclusive?: boolean } = {} ): Iterable { for (const [node, path] of Node.entries(root, options)) { @@ -200,10 +198,9 @@ namespace Node { path?: Path range?: Range reverse?: boolean - inclusive?: boolean } = {} ): Iterable { - const { path, range, reverse = false, inclusive = true } = options + const { path, range, reverse = false } = options let startPath: Path = [] let endPath: Path | null = null @@ -226,11 +223,6 @@ namespace Node { // When iterating over a range, we need to include the specific // ancestors in the start path of the range manually. if (!includedStart) { - if (!inclusive) { - visited.add(n) - continue - } - if (!includingStart) { includingStart = true p = [] @@ -309,7 +301,7 @@ namespace Node { export const fragment = (root: Node, range: Range): Fragment => { if (Text.isText(root)) { throw new Error( - `Cannot get a fragment start from a root text node: ${root}` + `Cannot get a fragment starting from a root text node: ${root}` ) } @@ -365,7 +357,7 @@ namespace Node { if (Text.isText(node) || !node.nodes[p]) { throw new Error( - `Could not find a descedant at path ${path} in node: ${root}` + `Cannot find a descedant at path [${path}] in node: ${root}` ) } @@ -422,7 +414,7 @@ namespace Node { if (!Text.isText(node)) { throw new Error( - `Cannot get the leaf node at ${path} because it refers to a non-leaf node: ${node}` + `Cannot get the leaf node at path [${path}] because it refers to a non-leaf node: ${node}` ) } @@ -459,7 +451,6 @@ namespace Node { path?: Path range?: Range reverse?: boolean - inclusive?: boolean } = {} ): Iterable { for (const [node, path] of Node.texts(root, options)) { @@ -470,20 +461,6 @@ namespace Node { } } - /** - * Check if a node matches set of properties. - */ - - export const matches = (node: Node, props: Partial): boolean => { - for (const key in props) { - if (node[key] !== props[key]) { - return false - } - } - - return true - } - /** * Calculate the string offset of all the nodes before a node at a given path. */ @@ -495,7 +472,7 @@ namespace Node { } if (Text.isText(root)) { - throw new Error(`Cannot get the offset into a text node: ${root}`) + throw new Error(`Cannot get the offset into a root text node: ${root}`) } const [index] = path @@ -506,7 +483,7 @@ namespace Node { o += Node.text(node).length } - const child = root.nodes[index] + const child = Node.child(root, index) const relPath = Path.relative(path, [index]) o += Node.offset(child, relPath) return o @@ -522,22 +499,13 @@ namespace Node { if (Text.isText(parent)) { throw new Error( - `Cannot get the parent of path ${path} because it does not exist in the document.` + `Cannot get the parent of path [${path}] because it does not exist in the root.` ) } return parent } - /** - * Get the previous node at a specific path. - */ - - export const previous = (root: Node, path: Path): Node => { - const prevPath = Path.previous(path) - return Node.get(root, prevPath) - } - /** * Get the concatenated text string of a node's content. * @@ -564,7 +532,6 @@ namespace Node { path?: Path range?: Range reverse?: boolean - inclusive?: boolean } = {} ): Iterable { for (const [node, path] of Node.entries(root, options)) { diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index 546ff5b98c..d25ffd015f 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -235,7 +235,7 @@ namespace Path { export const next = (path: Path): Path => { if (path.length === 0) { throw new Error( - `Cannot get the next path of a root path ${path}, because it has no next index.` + `Cannot get the next path of a root path [${path}], because it has no next index.` ) } @@ -249,7 +249,7 @@ namespace Path { export const parent = (path: Path): Path => { if (path.length === 0) { - throw new Error(`Cannot get the parent path of the root path ${path}.`) + throw new Error(`Cannot get the parent path of the root path [${path}].`) } return path.slice(0, -1) @@ -262,7 +262,7 @@ namespace Path { export const previous = (path: Path): Path => { if (path.length === 0) { throw new Error( - `Cannot get the previous path of a root path ${path}, because it has no previous index.` + `Cannot get the previous path of a root path [${path}], because it has no previous index.` ) } @@ -270,7 +270,7 @@ namespace Path { if (last <= 0) { throw new Error( - `Cannot get the previous path of a first child path ${path} because it would result in a negative index.` + `Cannot get the previous path of a first child path [${path}] because it would result in a negative index.` ) } @@ -282,9 +282,9 @@ namespace Path { */ export const relative = (path: Path, ancestor: Path): Path => { - if (!isAncestor(ancestor, path)) { + if (!Path.isAncestor(ancestor, path) && !Path.equals(path, ancestor)) { throw new Error( - `Cannot get the relative path of ${path} inside ancestor ${ancestor}, because it is not an ancestor of the path.` + `Cannot get the relative path of [${path}] inside ancestor [${ancestor}], because it is not above or equal to the path.` ) } diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index b526a7fa08..d707ea9d14 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -121,7 +121,8 @@ namespace Value { case 'merge_node': { const { path } = op const node = Node.get(v, path) - const prev = Node.previous(v, path) + const prevPath = Path.previous(path) + const prev = Node.get(v, prevPath) const parent = Node.parent(v, path) const index = path[path.length - 1] @@ -194,12 +195,8 @@ namespace Value { const parent = Node.parent(v, path) parent.nodes.splice(index, 1) - const [next] = Node.texts(v, { path, inclusive: false }) - const [prev] = Node.texts(v, { - path, - inclusive: false, - reverse: true, - }) + const [, next] = Node.texts(v, { path }) + const [, prev] = Node.texts(v, { path, reverse: true }) // Transform all of the points in the value, but if the point was in the // node that was removed we need to update the range or remove it. diff --git a/packages/slate/test/interfaces/Element/isElement/text.js b/packages/slate/test/interfaces/Element/isElement/text.js new file mode 100644 index 0000000000..9cad04b551 --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElement/text.js @@ -0,0 +1,12 @@ +import { Element } from 'slate' + +export const input = { + text: '', + marks: [], +} + +export const test = value => { + return Element.isElement(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElement/value.js b/packages/slate/test/interfaces/Element/isElement/value.js new file mode 100644 index 0000000000..85d1fd4dbe --- /dev/null +++ b/packages/slate/test/interfaces/Element/isElement/value.js @@ -0,0 +1,13 @@ +import { Element } from 'slate' + +export const input = { + nodes: [], + selection: null, + annotations: {}, +} + +export const test = value => { + return Element.isElement(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/isElementList/full-value.js b/packages/slate/test/interfaces/Element/isElementList/full-value.js index 1243f81d0f..7ab999107d 100644 --- a/packages/slate/test/interfaces/Element/isElementList/full-value.js +++ b/packages/slate/test/interfaces/Element/isElementList/full-value.js @@ -12,4 +12,4 @@ export const test = value => { return Element.isElementList(value) } -export const output = true +export const output = false diff --git a/packages/slate/test/interfaces/Element/matches/custom-prop-match.js b/packages/slate/test/interfaces/Element/matches/custom-prop-match.js new file mode 100644 index 0000000000..3ab2826dc1 --- /dev/null +++ b/packages/slate/test/interfaces/Element/matches/custom-prop-match.js @@ -0,0 +1,12 @@ +import { Element } from 'slate' + +export const input = { + element: { nodes: [], type: 'bold' }, + props: { type: 'bold' }, +} + +export const test = ({ element, props }) => { + return Element.matches(element, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/matches/custom-prop-not-match.js b/packages/slate/test/interfaces/Element/matches/custom-prop-not-match.js new file mode 100644 index 0000000000..95c60c3f25 --- /dev/null +++ b/packages/slate/test/interfaces/Element/matches/custom-prop-not-match.js @@ -0,0 +1,12 @@ +import { Element } from 'slate' + +export const input = { + element: { nodes: [], type: 'bold' }, + props: { type: 'italic' }, +} + +export const test = ({ element, props }) => { + return Element.matches(element, props) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Element/matches/custom-prop-partial-match.js b/packages/slate/test/interfaces/Element/matches/custom-prop-partial-match.js new file mode 100644 index 0000000000..9796e720e2 --- /dev/null +++ b/packages/slate/test/interfaces/Element/matches/custom-prop-partial-match.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + element: { nodes: [], type: 'bold', other: true }, + props: { type: 'bold' }, +} + +export const test = ({ element, props }) => { + return Mark.matches(element, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/matches/empty-match.js b/packages/slate/test/interfaces/Element/matches/empty-match.js new file mode 100644 index 0000000000..a699a79194 --- /dev/null +++ b/packages/slate/test/interfaces/Element/matches/empty-match.js @@ -0,0 +1,12 @@ +import { Element } from 'slate' + +export const input = { + element: { nodes: [] }, + props: {}, +} + +export const test = ({ element, props }) => { + return Element.matches(element, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Element/matches/empty-partial-match.js b/packages/slate/test/interfaces/Element/matches/empty-partial-match.js new file mode 100644 index 0000000000..044c484739 --- /dev/null +++ b/packages/slate/test/interfaces/Element/matches/empty-partial-match.js @@ -0,0 +1,12 @@ +import { Mark } from 'slate' + +export const input = { + element: { nodes: [], type: 'bold' }, + props: {}, +} + +export const test = ({ mark, props }) => { + return Mark.matches(mark, props) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Mark/matches/custom-prop-match.js b/packages/slate/test/interfaces/Mark/matches/custom-prop-match.js index e95ef52305..b8c7715247 100644 --- a/packages/slate/test/interfaces/Mark/matches/custom-prop-match.js +++ b/packages/slate/test/interfaces/Mark/matches/custom-prop-match.js @@ -2,7 +2,7 @@ import { Mark } from 'slate' export const input = { mark: { type: 'bold' }, - another: { type: 'bold' }, + props: { type: 'bold' }, } export const test = ({ mark, props }) => { diff --git a/packages/slate/test/interfaces/Mark/matches/empty-mark-match.js b/packages/slate/test/interfaces/Mark/matches/empty-match.js similarity index 100% rename from packages/slate/test/interfaces/Mark/matches/empty-mark-match.js rename to packages/slate/test/interfaces/Mark/matches/empty-match.js diff --git a/packages/slate/test/interfaces/Mark/matches/empty-mark-partial-match.js b/packages/slate/test/interfaces/Mark/matches/empty-partial-match.js similarity index 100% rename from packages/slate/test/interfaces/Mark/matches/empty-mark-partial-match.js rename to packages/slate/test/interfaces/Mark/matches/empty-partial-match.js diff --git a/packages/slate/test/interfaces/Node/ancestor/success.js b/packages/slate/test/interfaces/Node/ancestor/success.js new file mode 100644 index 0000000000..5d90f40b8c --- /dev/null +++ b/packages/slate/test/interfaces/Node/ancestor/success.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.ancestor(value, [0]) +} + +export const output = input.nodes[0] diff --git a/packages/slate/test/interfaces/Node/ancestors/reverse.js b/packages/slate/test/interfaces/Node/ancestors/reverse.js new file mode 100644 index 0000000000..74131b89ed --- /dev/null +++ b/packages/slate/test/interfaces/Node/ancestors/reverse.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Array.from(Node.ancestors(value, [0, 0], { reverse: true })) +} + +export const output = [[input, []], [input.nodes[0], [0]]] diff --git a/packages/slate/test/interfaces/Node/ancestors/success.js b/packages/slate/test/interfaces/Node/ancestors/success.js new file mode 100644 index 0000000000..ae2b61303b --- /dev/null +++ b/packages/slate/test/interfaces/Node/ancestors/success.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Array.from(Node.ancestors(value, [0, 0])) +} + +export const output = [[input.nodes[0], [0]], [input, []]] diff --git a/packages/slate/test/interfaces/Node/child/success.js b/packages/slate/test/interfaces/Node/child/success.js new file mode 100644 index 0000000000..559bf617c7 --- /dev/null +++ b/packages/slate/test/interfaces/Node/child/success.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.child(value, 0) +} + +export const output = input.nodes[0] diff --git a/packages/slate/test/interfaces/Node/closest/success.js b/packages/slate/test/interfaces/Node/closest/success.js new file mode 100644 index 0000000000..3f00e3bf47 --- /dev/null +++ b/packages/slate/test/interfaces/Node/closest/success.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { Element, Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + +) + +export const test = value => { + return Node.closest(value, [0, 0, 0], ([e]) => Element.isElement(e)) +} + +export const output = [ + + + , + [0, 0], +] diff --git a/packages/slate/test/interfaces/Node/descendant/success.js b/packages/slate/test/interfaces/Node/descendant/success.js new file mode 100644 index 0000000000..e05d814467 --- /dev/null +++ b/packages/slate/test/interfaces/Node/descendant/success.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.descendant(value, [0]) +} + +export const output = input.nodes[0] diff --git a/packages/slate/test/interfaces/Node/descendants/all.js b/packages/slate/test/interfaces/Node/descendants/all.js new file mode 100644 index 0000000000..191b97d63d --- /dev/null +++ b/packages/slate/test/interfaces/Node/descendants/all.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.descendants(value)) +} + +export const output = [ + [ + + + + , + [0], + ], + [, [0, 0]], + [, [0, 1]], +] diff --git a/packages/slate/test/interfaces/Node/descendants/path.js b/packages/slate/test/interfaces/Node/descendants/path.js new file mode 100644 index 0000000000..5068e54385 --- /dev/null +++ b/packages/slate/test/interfaces/Node/descendants/path.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.descendants(value, { path: [0, 1] })) +} + +export const output = [ + [ + + + + , + [0], + ], + [, [0, 1]], +] diff --git a/packages/slate/test/interfaces/Node/descendants/range.js b/packages/slate/test/interfaces/Node/descendants/range.js new file mode 100644 index 0000000000..af4c27c6c4 --- /dev/null +++ b/packages/slate/test/interfaces/Node/descendants/range.js @@ -0,0 +1,46 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + +) + +export const test = value => { + return Array.from( + Node.descendants(value, { + range: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 2], + offset: 0, + }, + }, + }) + ) +} + +export const output = [ + [ + + + + + + , + [0], + ], + [, [0, 1]], + [, [0, 2]], +] diff --git a/packages/slate/test/interfaces/Node/descendants/reverse.js b/packages/slate/test/interfaces/Node/descendants/reverse.js new file mode 100644 index 0000000000..12aae88447 --- /dev/null +++ b/packages/slate/test/interfaces/Node/descendants/reverse.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.descendants(value, { reverse: true })) +} + +export const output = [ + [ + + + + , + [0], + ], + [, [0, 1]], + [, [0, 0]], +] diff --git a/packages/slate/test/interfaces/Node/elements/all.js b/packages/slate/test/interfaces/Node/elements/all.js new file mode 100644 index 0000000000..3b8ca01bf4 --- /dev/null +++ b/packages/slate/test/interfaces/Node/elements/all.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.elements(value)) +} + +export const output = [ + [ + + + + , + [0], + ], +] diff --git a/packages/slate/test/interfaces/Node/elements/path.js b/packages/slate/test/interfaces/Node/elements/path.js new file mode 100644 index 0000000000..0b052a4d1a --- /dev/null +++ b/packages/slate/test/interfaces/Node/elements/path.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.elements(value, { path: [0, 1] })) +} + +export const output = [ + [ + + + + , + [0], + ], +] diff --git a/packages/slate/test/interfaces/Node/elements/range.js b/packages/slate/test/interfaces/Node/elements/range.js new file mode 100644 index 0000000000..9a95cc8c31 --- /dev/null +++ b/packages/slate/test/interfaces/Node/elements/range.js @@ -0,0 +1,44 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + +) + +export const test = value => { + return Array.from( + Node.elements(value, { + range: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 2], + offset: 0, + }, + }, + }) + ) +} + +export const output = [ + [ + + + + + + , + [0], + ], +] diff --git a/packages/slate/test/interfaces/Node/elements/reverse.js b/packages/slate/test/interfaces/Node/elements/reverse.js new file mode 100644 index 0000000000..fcade3ec9a --- /dev/null +++ b/packages/slate/test/interfaces/Node/elements/reverse.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.elements(value, { reverse: true })) +} + +export const output = [ + [ + + + + , + [0], + ], +] diff --git a/packages/slate/test/interfaces/Node/entries/all.js b/packages/slate/test/interfaces/Node/entries/all.js new file mode 100644 index 0000000000..9965b5eebd --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/all.js @@ -0,0 +1,38 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value)) +} + +export const output = [ + [ + + + + + + , + [], + ], + [ + + + + , + [0], + ], + [, [0, 0]], + [, [0, 1]], +] diff --git a/packages/slate/test/interfaces/Node/entries/path.js b/packages/slate/test/interfaces/Node/entries/path.js new file mode 100644 index 0000000000..4a882b1065 --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/path.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value, { path: [0, 1] })) +} + +export const output = [ + [ + + + + + + , + [], + ], + [ + + + + , + [0], + ], + [, [0, 1]], +] diff --git a/packages/slate/test/interfaces/Node/entries/range.js b/packages/slate/test/interfaces/Node/entries/range.js new file mode 100644 index 0000000000..e23077d5a3 --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/range.js @@ -0,0 +1,57 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + +) + +export const test = value => { + return Array.from( + Node.entries(value, { + range: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 2], + offset: 0, + }, + }, + }) + ) +} + +export const output = [ + [ + + + + + + + + , + [], + ], + [ + + + + + + , + [0], + ], + [, [0, 1]], + [, [0, 2]], +] diff --git a/packages/slate/test/interfaces/Node/entries/reverse.js b/packages/slate/test/interfaces/Node/entries/reverse.js new file mode 100644 index 0000000000..fc59bed7ee --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/reverse.js @@ -0,0 +1,38 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value, { reverse: true })) +} + +export const output = [ + [ + + + + + + , + [], + ], + [ + + + + , + [0], + ], + [, [0, 1]], + [, [0, 0]], +] diff --git a/packages/slate/test/interfaces/Node/furthest/success.js b/packages/slate/test/interfaces/Node/furthest/success.js new file mode 100644 index 0000000000..fe8c1c141d --- /dev/null +++ b/packages/slate/test/interfaces/Node/furthest/success.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { Element, Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + +) + +export const test = value => { + return Node.furthest(value, [0, 0, 0], ([e]) => Element.isElement(e)) +} + +export const output = [ + + + + + , + [0], +] diff --git a/packages/slate/test/interfaces/Node/get/root.js b/packages/slate/test/interfaces/Node/get/root.js new file mode 100644 index 0000000000..f46967ac26 --- /dev/null +++ b/packages/slate/test/interfaces/Node/get/root.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.get(value, []) +} + +export const output = ( + + + + + +) diff --git a/packages/slate/test/interfaces/Node/get/success.js b/packages/slate/test/interfaces/Node/get/success.js new file mode 100644 index 0000000000..9d4d9992b1 --- /dev/null +++ b/packages/slate/test/interfaces/Node/get/success.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.get(value, [0]) +} + +export const output = ( + + + +) diff --git a/packages/slate/test/interfaces/Node/has/exists.js b/packages/slate/test/interfaces/Node/has/exists.js new file mode 100644 index 0000000000..f93fd1ccbc --- /dev/null +++ b/packages/slate/test/interfaces/Node/has/exists.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.has(value, [0]) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/has/not-exists.js b/packages/slate/test/interfaces/Node/has/not-exists.js new file mode 100644 index 0000000000..2cfb9f3767 --- /dev/null +++ b/packages/slate/test/interfaces/Node/has/not-exists.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.has(value, [1]) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Node/isNode/boolean.js b/packages/slate/test/interfaces/Node/isNode/boolean.js new file mode 100644 index 0000000000..fe85f90fb2 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNode/boolean.js @@ -0,0 +1,9 @@ +import { Node } from 'slate' + +export const input = true + +export const test = value => { + return Node.isNode(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Node/isNode/custom-property.js b/packages/slate/test/interfaces/Node/isNode/custom-property.js new file mode 100644 index 0000000000..9a955ebd6f --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNode/custom-property.js @@ -0,0 +1,12 @@ +import { Node } from 'slate' + +export const input = { + nodes: [], + custom: true, +} + +export const test = value => { + return Node.isNode(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/isNode/element.js b/packages/slate/test/interfaces/Node/isNode/element.js new file mode 100644 index 0000000000..9e7bb33d9f --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNode/element.js @@ -0,0 +1,11 @@ +import { Node } from 'slate' + +export const input = { + nodes: [], +} + +export const test = value => { + return Node.isNode(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/isNode/object.js b/packages/slate/test/interfaces/Node/isNode/object.js new file mode 100644 index 0000000000..585bcf3787 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNode/object.js @@ -0,0 +1,9 @@ +import { Node } from 'slate' + +export const input = {} + +export const test = value => { + return Node.isNode(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Node/isNode/text.js b/packages/slate/test/interfaces/Node/isNode/text.js new file mode 100644 index 0000000000..49543108d3 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNode/text.js @@ -0,0 +1,12 @@ +import { Node } from 'slate' + +export const input = { + text: '', + marks: [], +} + +export const test = value => { + return Node.isNode(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/isNode/value.js b/packages/slate/test/interfaces/Node/isNode/value.js new file mode 100644 index 0000000000..71d104d61e --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNode/value.js @@ -0,0 +1,13 @@ +import { Node } from 'slate' + +export const input = { + nodes: [], + selection: null, + annotations: {}, +} + +export const test = value => { + return Node.isNode(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/isNodeList/boolean.js b/packages/slate/test/interfaces/Node/isNodeList/boolean.js new file mode 100644 index 0000000000..842907bfa5 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNodeList/boolean.js @@ -0,0 +1,9 @@ +import { Node } from 'slate' + +export const input = true + +export const test = value => { + return Node.isNodeList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Node/isNodeList/element.js b/packages/slate/test/interfaces/Node/isNodeList/element.js new file mode 100644 index 0000000000..c2744d8ccd --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNodeList/element.js @@ -0,0 +1,11 @@ +import { Node } from 'slate' + +export const input = { + nodes: [], +} + +export const test = value => { + return Node.isNodeList(value) +} + +export const output = false diff --git a/packages/slate/test/interfaces/Node/isNodeList/empty.js b/packages/slate/test/interfaces/Node/isNodeList/empty.js new file mode 100644 index 0000000000..2cf6511088 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNodeList/empty.js @@ -0,0 +1,9 @@ +import { Node } from 'slate' + +export const input = [] + +export const test = value => { + return Node.isNodeList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/isNodeList/full-element.js b/packages/slate/test/interfaces/Node/isNodeList/full-element.js new file mode 100644 index 0000000000..468e49afb0 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNodeList/full-element.js @@ -0,0 +1,13 @@ +import { Node } from 'slate' + +export const input = [ + { + nodes: [], + }, +] + +export const test = value => { + return Node.isNodeList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/isNodeList/full-text.js b/packages/slate/test/interfaces/Node/isNodeList/full-text.js new file mode 100644 index 0000000000..c78b6f1222 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNodeList/full-text.js @@ -0,0 +1,14 @@ +import { Node } from 'slate' + +export const input = [ + { + text: '', + marks: [], + }, +] + +export const test = value => { + return Node.isNodeList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/isNodeList/full-value.js b/packages/slate/test/interfaces/Node/isNodeList/full-value.js new file mode 100644 index 0000000000..695a0397d8 --- /dev/null +++ b/packages/slate/test/interfaces/Node/isNodeList/full-value.js @@ -0,0 +1,15 @@ +import { Node } from 'slate' + +export const input = [ + { + nodes: [], + selection: null, + annotations: {}, + }, +] + +export const test = value => { + return Node.isNodeList(value) +} + +export const output = true diff --git a/packages/slate/test/interfaces/Node/leaf/success.js b/packages/slate/test/interfaces/Node/leaf/success.js new file mode 100644 index 0000000000..33906c3b16 --- /dev/null +++ b/packages/slate/test/interfaces/Node/leaf/success.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.leaf(value, [0, 0]) +} + +export const output = diff --git a/packages/slate/test/interfaces/Node/levels/reverse.js b/packages/slate/test/interfaces/Node/levels/reverse.js new file mode 100644 index 0000000000..7edc3c23ff --- /dev/null +++ b/packages/slate/test/interfaces/Node/levels/reverse.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Array.from(Node.levels(value, [0, 0], { reverse: true })) +} + +export const output = [ + [input, []], + [input.nodes[0], [0]], + [input.nodes[0].nodes[0], [0, 0]], +] diff --git a/packages/slate/test/interfaces/Node/levels/success.js b/packages/slate/test/interfaces/Node/levels/success.js new file mode 100644 index 0000000000..b6fc86b14c --- /dev/null +++ b/packages/slate/test/interfaces/Node/levels/success.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Array.from(Node.levels(value, [0, 0])) +} + +export const output = [ + [input.nodes[0].nodes[0], [0, 0]], + [input.nodes[0], [0]], + [input, []], +] diff --git a/packages/slate/test/interfaces/Node/marks/all.js b/packages/slate/test/interfaces/Node/marks/all.js new file mode 100644 index 0000000000..2f9a5d5b63 --- /dev/null +++ b/packages/slate/test/interfaces/Node/marks/all.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + + +) + +export const test = value => { + return Array.from(Node.marks(value)) +} + +export const output = [ + [{ key: 'a' }, 0, one, [0, 0]], + [{ key: 'b' }, 0, two, [0, 1]], +] diff --git a/packages/slate/test/interfaces/Node/marks/path.js b/packages/slate/test/interfaces/Node/marks/path.js new file mode 100644 index 0000000000..280238eef3 --- /dev/null +++ b/packages/slate/test/interfaces/Node/marks/path.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + + +) + +export const test = value => { + return Array.from(Node.marks(value, { path: [0, 1] })) +} + +export const output = [[{ key: 'b' }, 0, two, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/marks/range.js b/packages/slate/test/interfaces/Node/marks/range.js new file mode 100644 index 0000000000..c997683363 --- /dev/null +++ b/packages/slate/test/interfaces/Node/marks/range.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + three + + +) + +export const test = value => { + return Array.from( + Node.marks(value, { + range: { + anchor: { + path: [0, 0], + offset: 0, + }, + focus: { + path: [0, 1], + offset: 0, + }, + }, + }) + ) +} + +export const output = [ + [{ key: 'a' }, 0, one, [0, 0]], + [{ key: 'b' }, 0, two, [0, 1]], +] diff --git a/packages/slate/test/interfaces/Node/marks/reverse.js b/packages/slate/test/interfaces/Node/marks/reverse.js new file mode 100644 index 0000000000..58568ce5e7 --- /dev/null +++ b/packages/slate/test/interfaces/Node/marks/reverse.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + + +) + +export const test = value => { + return Array.from(Node.marks(value, { reverse: true })) +} + +export const output = [ + [{ key: 'b' }, 0, two, [0, 1]], + [{ key: 'a' }, 0, one, [0, 0]], +] diff --git a/packages/slate/test/interfaces/Node/offset/across-elements.js b/packages/slate/test/interfaces/Node/offset/across-elements.js new file mode 100644 index 0000000000..0973bbe212 --- /dev/null +++ b/packages/slate/test/interfaces/Node/offset/across-elements.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + + + three + four + + +) + +export const test = value => { + return Node.offset(value, [1, 1]) +} + +export const output = 11 diff --git a/packages/slate/test/interfaces/Node/offset/element.js b/packages/slate/test/interfaces/Node/offset/element.js new file mode 100644 index 0000000000..206405afed --- /dev/null +++ b/packages/slate/test/interfaces/Node/offset/element.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + + + three + four + + +) + +export const test = value => { + return Node.offset(value, [1]) +} + +export const output = 6 diff --git a/packages/slate/test/interfaces/Node/offset/end.js b/packages/slate/test/interfaces/Node/offset/end.js new file mode 100644 index 0000000000..53e58374a9 --- /dev/null +++ b/packages/slate/test/interfaces/Node/offset/end.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + three + + +) + +export const test = value => { + return Node.offset(value, [0, 2]) +} + +export const output = 6 diff --git a/packages/slate/test/interfaces/Node/offset/middle.js b/packages/slate/test/interfaces/Node/offset/middle.js new file mode 100644 index 0000000000..7d5a3170cb --- /dev/null +++ b/packages/slate/test/interfaces/Node/offset/middle.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + three + + +) + +export const test = value => { + return Node.offset(value, [0, 1]) +} + +export const output = 3 diff --git a/packages/slate/test/interfaces/Node/offset/start.js b/packages/slate/test/interfaces/Node/offset/start.js new file mode 100644 index 0000000000..55b7b0c885 --- /dev/null +++ b/packages/slate/test/interfaces/Node/offset/start.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + three + + +) + +export const test = value => { + return Node.offset(value, [0, 0]) +} + +export const output = 0 diff --git a/packages/slate/test/interfaces/Node/parent/success.js b/packages/slate/test/interfaces/Node/parent/success.js new file mode 100644 index 0000000000..ba88384377 --- /dev/null +++ b/packages/slate/test/interfaces/Node/parent/success.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + +) + +export const test = value => { + return Node.parent(value, [0, 0]) +} + +export const output = ( + + + +) diff --git a/packages/slate/test/interfaces/Node/text/across-elements.js b/packages/slate/test/interfaces/Node/text/across-elements.js new file mode 100644 index 0000000000..74393f998a --- /dev/null +++ b/packages/slate/test/interfaces/Node/text/across-elements.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + one + two + + + three + four + + +) + +export const test = value => { + return Node.text(value) +} + +export const output = `onetwothreefour` diff --git a/packages/slate/test/interfaces/Node/text/element.js b/packages/slate/test/interfaces/Node/text/element.js new file mode 100644 index 0000000000..8c0b1f27d8 --- /dev/null +++ b/packages/slate/test/interfaces/Node/text/element.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + one + two + +) + +export const test = value => { + return Node.text(value, [1]) +} + +export const output = `onetwo` diff --git a/packages/slate/test/interfaces/Node/text/text.js b/packages/slate/test/interfaces/Node/text/text.js new file mode 100644 index 0000000000..2b713067a2 --- /dev/null +++ b/packages/slate/test/interfaces/Node/text/text.js @@ -0,0 +1,12 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = one + +export const test = value => { + return Node.text(value) +} + +export const output = `one` diff --git a/packages/slate/test/interfaces/Node/texts/all.js b/packages/slate/test/interfaces/Node/texts/all.js new file mode 100644 index 0000000000..b33a495a2c --- /dev/null +++ b/packages/slate/test/interfaces/Node/texts/all.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.texts(value)) +} + +export const output = [[, [0, 0]], [, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/texts/path.js b/packages/slate/test/interfaces/Node/texts/path.js new file mode 100644 index 0000000000..7f4dd4d4ca --- /dev/null +++ b/packages/slate/test/interfaces/Node/texts/path.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.texts(value, { path: [0, 1] })) +} + +export const output = [[, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/texts/range.js b/packages/slate/test/interfaces/Node/texts/range.js new file mode 100644 index 0000000000..699d6affee --- /dev/null +++ b/packages/slate/test/interfaces/Node/texts/range.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + +) + +export const test = value => { + return Array.from( + Node.texts(value, { + range: { + anchor: { + path: [0, 1], + offset: 0, + }, + focus: { + path: [0, 2], + offset: 0, + }, + }, + }) + ) +} + +export const output = [[, [0, 1]], [, [0, 2]]] diff --git a/packages/slate/test/interfaces/Node/texts/reverse.js b/packages/slate/test/interfaces/Node/texts/reverse.js new file mode 100644 index 0000000000..99b5a851ca --- /dev/null +++ b/packages/slate/test/interfaces/Node/texts/reverse.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + +) + +export const test = value => { + return Array.from(Node.texts(value, { reverse: true })) +} + +export const output = [[, [0, 1]], [, [0, 0]]] From 5a9a68605d8096f01174121f74194c69924bc5ce Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 15 Oct 2019 12:33:38 -0400 Subject: [PATCH 032/165] get operations and normalization tests working for slate --- packages/slate/src/classes/commands/path.ts | 83 ++++++++++++++++++- packages/slate/src/interfaces/node.ts | 22 +++-- packages/slate/src/interfaces/point.ts | 10 +-- packages/slate/src/interfaces/text.ts | 46 ++++++++++ packages/slate/src/interfaces/value.ts | 8 +- packages/slate/test/helpers/index.js | 16 ++-- packages/slate/test/index.js | 9 +- .../Node/entries/multiple-elements.js | 47 +++++++++++ .../Node/entries/nested-elements.js | 46 ++++++++++ .../Node/entries/path-multiple-elements.js | 54 ++++++++++++ .../Node/entries/path-of-element.js | 55 ++++++++++++ .../Node/texts/multiple-elements.js | 21 +++++ .../Node/texts/path-multiple-elements.js | 27 ++++++ .../interfaces/Node/texts/path-of-element.js | 28 +++++++ .../normalization/block-insert-text-child.js | 17 ++++ .../normalization/block-remove-block-child.js | 22 +++++ .../block-remove-inline-child.js | 20 +++++ .../inline-insert-adjacent-text.js | 24 ++++++ .../inline-remove-block-child.js | 30 +++++++ .../text-merge-adjacent-empty.js | 22 +++++ .../text-merge-adjacent-with-marks.js | 22 +++++ .../text-merge-adjacent-without-marks.js | 22 +++++ .../value-remove-inline-child.js | 16 ++++ .../normalization/value-remove-text-child.js | 16 ++++ .../apply/insert-text/annotation-before.js | 10 +-- .../merge-node/annotation-across-blocks.js | 14 ++-- .../apply/move-node/path-equals-new-path.js | 26 +++--- .../remove-node/annotation-across-blocks.js | 42 +++++----- .../apply/remove-text/anchor-after.js | 31 +++---- .../apply/remove-text/anchor-before.js | 31 +++---- .../apply/remove-text/anchor-middle.js | 31 +++---- .../apply/remove-text/annotation-after.js | 31 +++---- .../apply/remove-text/annotation-before.js | 30 +++---- .../apply/remove-text/annotation-middle.js | 31 +++---- .../apply/remove-text/cursor-after.js | 31 +++---- .../apply/remove-text/cursor-before.js | 31 +++---- .../apply/remove-text/cursor-middle.js | 31 +++---- .../apply/remove-text/focus-after.js | 31 +++---- .../apply/remove-text/focus-before.js | 31 +++---- .../apply/remove-text/focus-middle.js | 31 +++---- .../schema/core/block-all-block-children.js | 26 ------ .../schema/core/block-all-inline-children.js | 30 ------- .../schema/core/block-all-text-children.js | 24 ------ .../test/schema/core/block-create-text.js | 23 ----- .../core/document-no-inline-children.js | 22 ----- .../schema/core/document-no-text-children.js | 22 ----- .../schema/core/inline-no-block-children.js | 32 ------- .../test/schema/core/inline-text-around.js | 30 ------- .../test/schema/core/merge-adjacent-texts.js | 33 -------- .../core/preserve-inline-with-empty-void.js | 41 --------- 50 files changed, 859 insertions(+), 570 deletions(-) create mode 100644 packages/slate/test/interfaces/Node/entries/multiple-elements.js create mode 100644 packages/slate/test/interfaces/Node/entries/nested-elements.js create mode 100644 packages/slate/test/interfaces/Node/entries/path-multiple-elements.js create mode 100644 packages/slate/test/interfaces/Node/entries/path-of-element.js create mode 100644 packages/slate/test/interfaces/Node/texts/multiple-elements.js create mode 100644 packages/slate/test/interfaces/Node/texts/path-multiple-elements.js create mode 100644 packages/slate/test/interfaces/Node/texts/path-of-element.js create mode 100644 packages/slate/test/normalization/block-insert-text-child.js create mode 100644 packages/slate/test/normalization/block-remove-block-child.js create mode 100644 packages/slate/test/normalization/block-remove-inline-child.js create mode 100644 packages/slate/test/normalization/inline-insert-adjacent-text.js create mode 100644 packages/slate/test/normalization/inline-remove-block-child.js create mode 100644 packages/slate/test/normalization/text-merge-adjacent-empty.js create mode 100644 packages/slate/test/normalization/text-merge-adjacent-with-marks.js create mode 100644 packages/slate/test/normalization/text-merge-adjacent-without-marks.js create mode 100644 packages/slate/test/normalization/value-remove-inline-child.js create mode 100644 packages/slate/test/normalization/value-remove-text-child.js delete mode 100644 packages/slate/test/schema/core/block-all-block-children.js delete mode 100644 packages/slate/test/schema/core/block-all-inline-children.js delete mode 100644 packages/slate/test/schema/core/block-all-text-children.js delete mode 100644 packages/slate/test/schema/core/block-create-text.js delete mode 100644 packages/slate/test/schema/core/document-no-inline-children.js delete mode 100644 packages/slate/test/schema/core/document-no-text-children.js delete mode 100644 packages/slate/test/schema/core/inline-no-block-children.js delete mode 100644 packages/slate/test/schema/core/inline-text-around.js delete mode 100644 packages/slate/test/schema/core/merge-adjacent-texts.js delete mode 100644 packages/slate/test/schema/core/preserve-inline-with-empty-void.js diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index a2dc3a2bac..2115c0cc4e 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -1,5 +1,15 @@ import { produce } from 'immer' -import { Editor, Fragment, Mark, Element, Text, Node, Path } from '../..' +import { + Editor, + Fragment, + Mark, + Element, + Text, + Node, + Path, + Descendant, + Value, +} from '../..' class PathCommands { /** @@ -170,7 +180,76 @@ class PathCommands { * currently invalid. */ - normalizeNodeAtPath(this: Editor, path: Path): void {} + normalizeNodeAtPath(this: Editor, path: Path): void { + const { value } = this + const node = Node.get(value, path) + + // There are no core normalizations for text nodes. + if (Text.isText(node)) { + return + } + + // Ensure that block and inline nodes have at least one text child. + if (Element.isElement(node) && node.nodes.length === 0) { + this.insertNodeAtPath(path.concat(0), { text: '', marks: [] }) + return + } + + // Determine whether the node should have block or inline children. + const hasBlockChildren = + Value.isValue(node) || + (this.isBlock(node) && + node.nodes.length !== 0 && + this.isBlock(node.nodes[0])) + + // Since we'll be applying operations while iterating, keep track of an + // index that accounts for any added/removed nodes. + let n = 0 + + for (let i = 0; i < node.nodes.length; i++, n++) { + const child = node.nodes[i] as Descendant + const isLast = i === node.nodes.length - 1 + + // Only allow block nodes in the top-level value and parent blocks that + // only contain block nodes. Similarly, only allow inline nodes in other + // inline nodes, or parent blocks that only contain inlines and text. + if (this.isBlock(child) !== hasBlockChildren) { + this.removeNodeAtPath(path.concat(n)) + n-- + continue + } + + const prev: Descendant | undefined = node.nodes[i - 1] + + // Ensure that inline nodes are surrounded by text nodes. + if (this.isInline(child)) { + if (prev == null || !Text.isText(prev)) { + this.insertNodeAtPath(path.concat(n), { text: '', marks: [] }) + n++ + continue + } + + if (isLast) { + this.insertNodeAtPath(path.concat(n + 1), { text: '', marks: [] }) + n++ + continue + } + } + + // Merge adjacent text nodes that are empty or have matching marks. + if (prev != null && Text.isText(child) && Text.isText(prev)) { + if ( + prev.text === '' || + child.text === '' || + Text.matches(child, prev) + ) { + this.mergeNodeAtPath(path.concat(n)) + n-- + continue + } + } + } + } /** * Remove all of the children from the node at a path. diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 876fc8b969..777fc56826 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -100,13 +100,19 @@ namespace Node { export const child = (root: Node, index: number): Descendant => { if (Text.isText(root)) { - throw new Error(`Cannot get the child of a text node: ${root}`) + throw new Error( + `Cannot get the child of a text node: ${JSON.stringify(root)}` + ) } const c = root.nodes[index] as Descendant if (c == null) { - throw new Error(`Cannot get child at index \`${index}\` in node: ${root}`) + throw new Error( + `Cannot get child at index \`${index}\` in node: ${JSON.stringify( + root + )}` + ) } return c @@ -301,7 +307,9 @@ namespace Node { export const fragment = (root: Node, range: Range): Fragment => { if (Text.isText(root)) { throw new Error( - `Cannot get a fragment starting from a root text node: ${root}` + `Cannot get a fragment starting from a root text node: ${JSON.stringify( + root + )}` ) } @@ -357,7 +365,9 @@ namespace Node { if (Text.isText(node) || !node.nodes[p]) { throw new Error( - `Cannot find a descedant at path [${path}] in node: ${root}` + `Cannot find a descendant at path [${path}] in node: ${JSON.stringify( + root + )}` ) } @@ -472,7 +482,9 @@ namespace Node { } if (Text.isText(root)) { - throw new Error(`Cannot get the offset into a root text node: ${root}`) + throw new Error( + `Cannot get the offset into a root text node: ${JSON.stringify(root)}` + ) } const [index] = path diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts index 122658f231..e0bfd3012c 100755 --- a/packages/slate/src/interfaces/point.ts +++ b/packages/slate/src/interfaces/point.ts @@ -110,11 +110,11 @@ namespace Point { } case 'remove_node': { - if (Path.equals(op.path, path)) { + if (Path.equals(op.path, path) || Path.isAncestor(op.path, path)) { return null } - Path.transform(path, op, options) + p.path = Path.transform(path, op, options)! break } @@ -130,7 +130,7 @@ namespace Point { } } - Path.transform(path, op, options) + p.path = Path.transform(path, op, options)! break } @@ -139,13 +139,13 @@ namespace Point { p.offset += op.position } - Path.transform(path, op, options) + p.path = Path.transform(path, op, options)! break } case 'insert_node': case 'move_node': { - Path.transform(path, op, options) + p.path = Path.transform(path, op, options)! break } } diff --git a/packages/slate/src/interfaces/text.ts b/packages/slate/src/interfaces/text.ts index b319c70bde..bfb4f22621 100755 --- a/packages/slate/src/interfaces/text.ts +++ b/packages/slate/src/interfaces/text.ts @@ -40,6 +40,52 @@ namespace Text { export const isTextList = (value: any): value is Text[] => { return Array.isArray(value) && (value.length === 0 || Text.isText(value[0])) } + + /** + * Check if an text matches set of properties. + * + * Note: this is for matching custom properties, and it does not ensure that + * the `text` property are two nodes equal. However, if `marks` are passed it + * will ensure that the set of marks is exactly equal. + */ + + export const matches = (text: Text, props: Partial): boolean => { + for (const key in props) { + if (key === 'text') { + continue + } + + if (key === 'marks' && props.marks != null) { + const existing = text.marks + const { marks } = props + + // PERF: If the lengths aren't the same, we know it's not a match. + if (existing.length !== marks.length) { + return false + } + + for (const m of existing) { + if (!Mark.exists(m, marks)) { + return false + } + } + + for (const m of marks) { + if (!Mark.exists(m, existing)) { + return false + } + } + + continue + } + + if (text[key] !== props[key]) { + return false + } + } + + return true + } } export { Text, TextEntry } diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index d707ea9d14..7972717243 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -95,7 +95,7 @@ namespace Value { const { path, node } = op const parent = Node.parent(v, path) const index = path[path.length - 1] - parent.nodes[index] = node + parent.nodes.splice(index, 0, node) for (const [point, key, range] of Value.points(v)) { range[key] = Point.transform(point, op)! @@ -193,11 +193,11 @@ namespace Value { const { path } = op const index = path[path.length - 1] const parent = Node.parent(v, path) - parent.nodes.splice(index, 1) - const [, next] = Node.texts(v, { path }) const [, prev] = Node.texts(v, { path, reverse: true }) + parent.nodes.splice(index, 1) + // Transform all of the points in the value, but if the point was in the // node that was removed we need to update the range or remove it. for (const [point, k, range, key] of Value.points(v)) { @@ -218,6 +218,8 @@ namespace Value { } else if (Annotation.isAnnotation(range)) { delete v.annotations[key!] } + } else { + range[k] = result } } diff --git a/packages/slate/test/helpers/index.js b/packages/slate/test/helpers/index.js index 306b5c88d8..0686cc1ec4 100644 --- a/packages/slate/test/helpers/index.js +++ b/packages/slate/test/helpers/index.js @@ -3,20 +3,24 @@ import { createHyperscript } from 'slate-hyperscript' const h = createHyperscript({ elements: { - block: {}, - inline: {}, - void_block: {}, - void_inline: {}, + block: { type: 'block' }, + inline: { type: 'inline' }, + void_block: { type: 'void_block' }, + void_inline: { type: 'void_inline' }, }, annotations: { - atomic_annotation: {}, + atomic_annotation: { type: 'atomic_annotation' }, }, }) const TestPlugin = Editor => { return class extends Editor { + isBlock(node) { + return Element.isElement(node) && node.type.endsWith('block') + } + isInline(node) { - return Element.isElement(node) && node.type === 'inline' + return Element.isElement(node) && node.type.endsWith('inline') } isVoid(node) { diff --git a/packages/slate/test/index.js b/packages/slate/test/index.js index 8a5eb9bd03..920ac6d4ac 100644 --- a/packages/slate/test/index.js +++ b/packages/slate/test/index.js @@ -36,7 +36,6 @@ describe('slate', () => { const { input, operations, output } = module const TestEditor = TestPlugin(Editor) const editor = new TestEditor({ value: input }) - editor.normalize({ force: true }) for (const op of operations) { editor.apply(op) @@ -45,6 +44,14 @@ describe('slate', () => { assert.deepEqual(editor.value, output) }) + fixtures(__dirname, 'normalization', ({ module }) => { + const { input, output } = module + const TestEditor = TestPlugin(Editor) + const editor = new TestEditor({ value: input }) + editor.normalize({ force: true }) + assert.deepEqual(editor.value, output) + }) + // The hyperscript editor has the schema, but the test // editor doesn't! It needs to live in the tests instead. diff --git a/packages/slate/test/interfaces/Node/entries/multiple-elements.js b/packages/slate/test/interfaces/Node/entries/multiple-elements.js new file mode 100644 index 0000000000..7e0fff4feb --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/multiple-elements.js @@ -0,0 +1,47 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value)) +} + +export const output = [ + [ + + + + + + + + , + [], + ], + [ + + + , + [0], + ], + [, [0, 0]], + [ + + + , + [1], + ], + [, [1, 0]], +] diff --git a/packages/slate/test/interfaces/Node/entries/nested-elements.js b/packages/slate/test/interfaces/Node/entries/nested-elements.js new file mode 100644 index 0000000000..145430306b --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/nested-elements.js @@ -0,0 +1,46 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value)) +} + +export const output = [ + [ + + + + + + + , + [], + ], + [ + + + + + , + [0], + ], + [ + + + , + [0, 0], + ], + [, [0, 0, 0]], +] diff --git a/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js b/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js new file mode 100644 index 0000000000..d820291f59 --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js @@ -0,0 +1,54 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value, { path: [0, 1] })) +} + +export const output = [ + [ + + + + + + + + + + , + [], + ], + [ + + + + , + [0], + ], + [, [0, 1]], + [ + + + + , + [1], + ], + [, [1, 0]], + [, [1, 1]], +] diff --git a/packages/slate/test/interfaces/Node/entries/path-of-element.js b/packages/slate/test/interfaces/Node/entries/path-of-element.js new file mode 100644 index 0000000000..0d66b934ee --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/path-of-element.js @@ -0,0 +1,55 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value, { path: [0] })) +} + +export const output = [ + [ + + + + + + + + + + , + [], + ], + [ + + + + , + [0], + ], + [, [0, 0]], + [, [0, 1]], + [ + + + + , + [1], + ], + [, [1, 0]], + [, [1, 1]], +] diff --git a/packages/slate/test/interfaces/Node/texts/multiple-elements.js b/packages/slate/test/interfaces/Node/texts/multiple-elements.js new file mode 100644 index 0000000000..22431a8209 --- /dev/null +++ b/packages/slate/test/interfaces/Node/texts/multiple-elements.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + +) + +export const test = value => { + return Array.from(Node.texts(value)) +} + +export const output = [[, [0, 0]], [, [1, 0]]] diff --git a/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js b/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js new file mode 100644 index 0000000000..d8bc87d7d8 --- /dev/null +++ b/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + + + +) + +export const test = value => { + return Array.from(Node.texts(value, { path: [0, 1] })) +} + +export const output = [ + [, [0, 1]], + [, [1, 0]], + [, [1, 1]], +] diff --git a/packages/slate/test/interfaces/Node/texts/path-of-element.js b/packages/slate/test/interfaces/Node/texts/path-of-element.js new file mode 100644 index 0000000000..7292b7f421 --- /dev/null +++ b/packages/slate/test/interfaces/Node/texts/path-of-element.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + + + + +) + +export const test = value => { + return Array.from(Node.texts(value, { path: [0] })) +} + +export const output = [ + [, [0, 0]], + [, [0, 1]], + [, [1, 0]], + [, [1, 1]], +] diff --git a/packages/slate/test/normalization/block-insert-text-child.js b/packages/slate/test/normalization/block-insert-text-child.js new file mode 100644 index 0000000000..49a90a3cdf --- /dev/null +++ b/packages/slate/test/normalization/block-insert-text-child.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const input = ( + + + +) + +export const output = ( + + + + + +) diff --git a/packages/slate/test/normalization/block-remove-block-child.js b/packages/slate/test/normalization/block-remove-block-child.js new file mode 100644 index 0000000000..349af01386 --- /dev/null +++ b/packages/slate/test/normalization/block-remove-block-child.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const schema = {} + +export const input = ( + + + one + two + + +) + +export const output = ( + + + one + + +) diff --git a/packages/slate/test/normalization/block-remove-inline-child.js b/packages/slate/test/normalization/block-remove-inline-child.js new file mode 100644 index 0000000000..a5b36213a8 --- /dev/null +++ b/packages/slate/test/normalization/block-remove-inline-child.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const input = ( + + + one + two + + +) + +export const output = ( + + + one + + +) diff --git a/packages/slate/test/normalization/inline-insert-adjacent-text.js b/packages/slate/test/normalization/inline-insert-adjacent-text.js new file mode 100644 index 0000000000..68279a711b --- /dev/null +++ b/packages/slate/test/normalization/inline-insert-adjacent-text.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const input = ( + + + one + two + + +) + +export const output = ( + + + + one + + two + + + +) diff --git a/packages/slate/test/normalization/inline-remove-block-child.js b/packages/slate/test/normalization/inline-remove-block-child.js new file mode 100644 index 0000000000..e707a9c973 --- /dev/null +++ b/packages/slate/test/normalization/inline-remove-block-child.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const schema = {} + +export const input = ( + + + + + one + two + + + + +) + +export const output = ( + + + + + two + + + + +) diff --git a/packages/slate/test/normalization/text-merge-adjacent-empty.js b/packages/slate/test/normalization/text-merge-adjacent-empty.js new file mode 100644 index 0000000000..e5425dab9a --- /dev/null +++ b/packages/slate/test/normalization/text-merge-adjacent-empty.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const schema = {} + +export const input = ( + + + + + + +) + +export const output = ( + + + + + +) diff --git a/packages/slate/test/normalization/text-merge-adjacent-with-marks.js b/packages/slate/test/normalization/text-merge-adjacent-with-marks.js new file mode 100644 index 0000000000..8cc041688b --- /dev/null +++ b/packages/slate/test/normalization/text-merge-adjacent-with-marks.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const schema = {} + +export const input = ( + + + 1 + 2 + + +) + +export const output = ( + + + 12 + + +) diff --git a/packages/slate/test/normalization/text-merge-adjacent-without-marks.js b/packages/slate/test/normalization/text-merge-adjacent-without-marks.js new file mode 100644 index 0000000000..450bc22d35 --- /dev/null +++ b/packages/slate/test/normalization/text-merge-adjacent-without-marks.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const schema = {} + +export const input = ( + + + 1 + 2 + + +) + +export const output = ( + + + 12 + + +) diff --git a/packages/slate/test/normalization/value-remove-inline-child.js b/packages/slate/test/normalization/value-remove-inline-child.js new file mode 100644 index 0000000000..b5c6b981a4 --- /dev/null +++ b/packages/slate/test/normalization/value-remove-inline-child.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const input = ( + + one + two + +) + +export const output = ( + + two + +) diff --git a/packages/slate/test/normalization/value-remove-text-child.js b/packages/slate/test/normalization/value-remove-text-child.js new file mode 100644 index 0000000000..c88fc410c8 --- /dev/null +++ b/packages/slate/test/normalization/value-remove-text-child.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../helpers' + +export const input = ( + + one + two + +) + +export const output = ( + + two + +) diff --git a/packages/slate/test/operations/apply/insert-text/annotation-before.js b/packages/slate/test/operations/apply/insert-text/annotation-before.js index ab0fb20b67..94a3404587 100644 --- a/packages/slate/test/operations/apply/insert-text/annotation-before.js +++ b/packages/slate/test/operations/apply/insert-text/annotation-before.js @@ -1,13 +1,13 @@ /** @jsx h */ -import { h } from '../../../helpers' +import h from 'slate-hyperscript' export const input = ( - + w ord - + ) @@ -22,9 +22,9 @@ export const operations = [ export const output = ( - + wx ord - + ) diff --git a/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js b/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js index 1677acb224..2a566b2869 100644 --- a/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js +++ b/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js @@ -1,15 +1,15 @@ /** @jsx h */ -import { h } from '../../../helpers' +import h from 'slate-hyperscript' export const input = ( - + one - - + + two - + ) @@ -32,8 +32,8 @@ export const operations = [ export const output = ( - + onetwo - + ) diff --git a/packages/slate/test/operations/apply/move-node/path-equals-new-path.js b/packages/slate/test/operations/apply/move-node/path-equals-new-path.js index 6dda7b5bab..04be2ab1ed 100644 --- a/packages/slate/test/operations/apply/move-node/path-equals-new-path.js +++ b/packages/slate/test/operations/apply/move-node/path-equals-new-path.js @@ -1,8 +1,15 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + 1 + 2 + +) + +export const operations = [ { type: 'move_node', path: [0], @@ -10,20 +17,9 @@ export default [ }, ] -export const input = ( - - - 1 - 2 - - -) - export const output = ( - - 1 - 2 - + 1 + 2 ) diff --git a/packages/slate/test/operations/apply/remove-node/annotation-across-blocks.js b/packages/slate/test/operations/apply/remove-node/annotation-across-blocks.js index 20a70f83dc..b65b7d7c58 100644 --- a/packages/slate/test/operations/apply/remove-node/annotation-across-blocks.js +++ b/packages/slate/test/operations/apply/remove-node/annotation-across-blocks.js @@ -1,38 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + one + + + two + + +) + +export const operations = [ { type: 'remove_node', path: [0], node: ( - - one - + + one + ), }, ] -export const input = ( - - - - one - - - two - - - -) - export const output = ( - - - two - - + + two + ) diff --git a/packages/slate/test/operations/apply/remove-text/anchor-after.js b/packages/slate/test/operations/apply/remove-text/anchor-after.js index 321e5b1642..8f1f91c0c3 100644 --- a/packages/slate/test/operations/apply/remove-text/anchor-after.js +++ b/packages/slate/test/operations/apply/remove-text/anchor-after.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/anchor-before.js b/packages/slate/test/operations/apply/remove-text/anchor-before.js index a8629a4d9b..a5d597293a 100644 --- a/packages/slate/test/operations/apply/remove-text/anchor-before.js +++ b/packages/slate/test/operations/apply/remove-text/anchor-before.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/anchor-middle.js b/packages/slate/test/operations/apply/remove-text/anchor-middle.js index 409c29476d..457320a4e5 100644 --- a/packages/slate/test/operations/apply/remove-text/anchor-middle.js +++ b/packages/slate/test/operations/apply/remove-text/anchor-middle.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/annotation-after.js b/packages/slate/test/operations/apply/remove-text/annotation-after.js index b206b06fee..5486a20196 100644 --- a/packages/slate/test/operations/apply/remove-text/annotation-after.js +++ b/packages/slate/test/operations/apply/remove-text/annotation-after.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/annotation-before.js b/packages/slate/test/operations/apply/remove-text/annotation-before.js index 67c1130f06..46b53dde0a 100644 --- a/packages/slate/test/operations/apply/remove-text/annotation-before.js +++ b/packages/slate/test/operations/apply/remove-text/annotation-before.js @@ -1,8 +1,16 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], @@ -12,22 +20,10 @@ export default [ }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/annotation-middle.js b/packages/slate/test/operations/apply/remove-text/annotation-middle.js index 1df3e69bc7..2ef13f989a 100644 --- a/packages/slate/test/operations/apply/remove-text/annotation-middle.js +++ b/packages/slate/test/operations/apply/remove-text/annotation-middle.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'o', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wrd - - + + wrd + ) diff --git a/packages/slate/test/operations/apply/remove-text/cursor-after.js b/packages/slate/test/operations/apply/remove-text/cursor-after.js index b098766c7a..756f38c7c9 100644 --- a/packages/slate/test/operations/apply/remove-text/cursor-after.js +++ b/packages/slate/test/operations/apply/remove-text/cursor-after.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/cursor-before.js b/packages/slate/test/operations/apply/remove-text/cursor-before.js index 621e86f44f..85be90996c 100644 --- a/packages/slate/test/operations/apply/remove-text/cursor-before.js +++ b/packages/slate/test/operations/apply/remove-text/cursor-before.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/cursor-middle.js b/packages/slate/test/operations/apply/remove-text/cursor-middle.js index 26ab18dd8c..0805bc9ed3 100644 --- a/packages/slate/test/operations/apply/remove-text/cursor-middle.js +++ b/packages/slate/test/operations/apply/remove-text/cursor-middle.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/focus-after.js b/packages/slate/test/operations/apply/remove-text/focus-after.js index 09414da663..ee727f8a44 100644 --- a/packages/slate/test/operations/apply/remove-text/focus-after.js +++ b/packages/slate/test/operations/apply/remove-text/focus-after.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/focus-before.js b/packages/slate/test/operations/apply/remove-text/focus-before.js index c88f3a3faa..dfcc673b02 100644 --- a/packages/slate/test/operations/apply/remove-text/focus-before.js +++ b/packages/slate/test/operations/apply/remove-text/focus-before.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/operations/apply/remove-text/focus-middle.js b/packages/slate/test/operations/apply/remove-text/focus-middle.js index aa669515b1..d1af47e97a 100644 --- a/packages/slate/test/operations/apply/remove-text/focus-middle.js +++ b/packages/slate/test/operations/apply/remove-text/focus-middle.js @@ -1,33 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import h from 'slate-hyperscript' -export default [ +export const input = ( + + + word + + +) + +export const operations = [ { type: 'remove_text', path: [0, 0], offset: 1, text: 'or', - marks: [], }, ] -export const input = ( - - - - word - - - -) - export const output = ( - - - wd - - + + wd + ) diff --git a/packages/slate/test/schema/core/block-all-block-children.js b/packages/slate/test/schema/core/block-all-block-children.js deleted file mode 100644 index 9db43e104e..0000000000 --- a/packages/slate/test/schema/core/block-all-block-children.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - one - two - - - -) - -export const output = ( - - - - one - - - -) diff --git a/packages/slate/test/schema/core/block-all-inline-children.js b/packages/slate/test/schema/core/block-all-inline-children.js deleted file mode 100644 index 0790c24cf5..0000000000 --- a/packages/slate/test/schema/core/block-all-inline-children.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - - one - - two - - - -) - -export const output = ( - - - - - one - - - - -) diff --git a/packages/slate/test/schema/core/block-all-text-children.js b/packages/slate/test/schema/core/block-all-text-children.js deleted file mode 100644 index 50c9d933de..0000000000 --- a/packages/slate/test/schema/core/block-all-text-children.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - one - two - - - -) - -export const output = ( - - - one - - -) diff --git a/packages/slate/test/schema/core/block-create-text.js b/packages/slate/test/schema/core/block-create-text.js deleted file mode 100644 index c5bf7ae09e..0000000000 --- a/packages/slate/test/schema/core/block-create-text.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/schema/core/document-no-inline-children.js b/packages/slate/test/schema/core/document-no-inline-children.js deleted file mode 100644 index 0e0089e5d2..0000000000 --- a/packages/slate/test/schema/core/document-no-inline-children.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - one - two - - -) - -export const output = ( - - - two - - -) diff --git a/packages/slate/test/schema/core/document-no-text-children.js b/packages/slate/test/schema/core/document-no-text-children.js deleted file mode 100644 index 119cf22994..0000000000 --- a/packages/slate/test/schema/core/document-no-text-children.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - one - two - - -) - -export const output = ( - - - two - - -) diff --git a/packages/slate/test/schema/core/inline-no-block-children.js b/packages/slate/test/schema/core/inline-no-block-children.js deleted file mode 100644 index fc4ffb2f0e..0000000000 --- a/packages/slate/test/schema/core/inline-no-block-children.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - - - one - two - - - - - -) - -export const output = ( - - - - - two - - - - -) diff --git a/packages/slate/test/schema/core/inline-text-around.js b/packages/slate/test/schema/core/inline-text-around.js deleted file mode 100644 index 0c0923d902..0000000000 --- a/packages/slate/test/schema/core/inline-text-around.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - one - two - - - -) - -export const output = ( - - - - - one - - two - - - - -) diff --git a/packages/slate/test/schema/core/merge-adjacent-texts.js b/packages/slate/test/schema/core/merge-adjacent-texts.js deleted file mode 100644 index 1b7b42ffb3..0000000000 --- a/packages/slate/test/schema/core/merge-adjacent-texts.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - - - -) - -export const output = ( - - - - 123456789 - - - -) diff --git a/packages/slate/test/schema/core/preserve-inline-with-empty-void.js b/packages/slate/test/schema/core/preserve-inline-with-empty-void.js deleted file mode 100644 index 95b520c8b7..0000000000 --- a/packages/slate/test/schema/core/preserve-inline-with-empty-void.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = {} - -export const input = ( - - - - - - - - - - - - - - - -) - -export const output = ( - - - - - - - - - - - - - - - -) From 728f023c239f771946929223c88278488fa487de Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 15 Oct 2019 16:11:30 -0400 Subject: [PATCH 033/165] get *AtPath command tests passing --- packages/slate-hyperscript/src/creators.ts | 93 +++++++++- packages/slate-hyperscript/src/index.ts | 2 + .../src/resolve-descendants.ts | 71 ------- .../test/fixtures/fragment-element.js | 22 +++ .../test/fixtures/fragment-empty.js | 9 + .../test/fixtures/fragment-string.js | 14 ++ packages/slate/src/classes/commands/path.ts | 175 +++++++++--------- packages/slate/src/classes/commands/point.ts | 2 +- packages/slate/src/interfaces/path.ts | 4 +- packages/slate/src/interfaces/value.ts | 31 ++-- .../insert-fragment-by-path/end-of-target.js | 27 +++ .../middle-of-target.js | 29 +++ .../start-of-target.js | 31 ++++ .../at-path/insert-node-by-path/block.js | 31 ++++ .../at-path/insert-node-by-path/inline.js | 32 ++++ .../at-path/insert-node-by-path/text.js | 23 +++ .../at-path/lift-node-by-path/block.js | 21 +++ .../at-path/lift-node-by-path/first-block.js | 25 +++ .../at-path/lift-node-by-path/last-block.js | 25 +++ .../at-path/lift-node-by-path/middle-block.js | 29 +++ .../at-path/merge-node-by-path/block.js | 20 ++ .../at-path/move-node-by-path/block.js | 25 +++ .../at-path/move-node-by-path/inline.js | 35 ++++ .../at-path/move-node-by-path/inside-next.js | 29 +++ .../at-path/move-node-by-path/nested.js | 30 +++ .../at-path/move-node-by-path/noop-equal.js | 21 +++ .../at-path/move-node-by-path/sibling-swap.js | 25 +++ .../at-path/move-node-by-path/text-nodes.js | 27 +++ .../at-path/move-node-by-path/text.js | 23 +++ .../at-path/move-node-by-path/to-sibling.js | 29 +++ .../pluck-node-by-path/block-multiple.js | 23 +++ .../at-path/pluck-node-by-path/block.js | 21 +++ .../at-path/remove-node-by-path/block.js | 20 ++ .../at-path/remove-node-by-path/inline.js | 25 +++ .../remove-node-by-path/selection-inside.js | 29 +++ .../at-path/remove-node-by-path/text.js | 23 +++ .../at-path/replace-node-by-path/block.js | 21 +++ .../at-path/replace-node-by-path/inline.js | 27 +++ .../at-path/replace-node-by-path/text.js | 21 +++ .../at-path/replace-text-by-path/basic.js | 23 +++ .../at-path/set-mark-by-path/basic.js | 31 ++++ .../at-path/set-node-by-path/block.js | 19 ++ .../at-path/set-node-by-path/inline.js | 27 +++ .../commands/at-path/set-node-by-path/text.js | 21 +++ .../at-path/split-node-by-path/block.js | 34 ++++ .../at-path/split-node-by-path/selection.js | 42 +++++ .../at-path/wrap-node-by-path/block.js | 21 +++ .../at-path/wrap-node-by-path/text.js | 23 +++ .../decoration-after-atomic.js | 23 +++ .../decoration-before-atomic.js | 29 +++ .../decoration-middle-atomic.js | 27 +++ .../insert-text-by-path/selection-after.js | 25 +++ .../insert-text-by-path/selection-before.js | 25 +++ .../insert-text-by-path/selection-end.js | 25 +++ .../insert-text-by-path/selection-middle.js | 25 +++ .../insert-text-by-path/selection-start.js | 25 +++ .../text-end-with-marks.js | 31 ++++ .../at-point/insert-text-by-path/text-end.js | 21 +++ .../text-middle-with-marks.js | 25 +++ .../insert-text-by-path/text-middle.js | 21 +++ .../text-start-with-marks.js | 31 ++++ .../insert-text-by-path/text-start.js | 25 +++ .../adjacent-non-void-inlines.js | 31 ++++ .../decoration-after-atomic.js | 29 +++ .../decoration-before-atomic.js | 29 +++ .../decoration-middle-atomic.js | 27 +++ .../inline-last-character.js | 31 ++++ .../inline-nested-last-character.js | 41 ++++ .../remove-text-by-path/inline-void.js | 33 ++++ .../at-point/remove-text-by-path/inline.js | 29 +++ .../remove-text-by-path/next-void-inline.js | 31 ++++ .../previous-void-inline.js | 31 ++++ .../remove-text-by-path/selection-after.js | 25 +++ .../remove-text-by-path/selection-before.js | 25 +++ .../remove-text-by-path/selection-middle.js | 25 +++ .../remove-text-by-path/selection-start.js | 25 +++ .../at-point/remove-text-by-path/text.js | 21 +++ .../at-point/replace-text-by-path/replace.js | 27 +++ .../replace-text-by-path/with-mark.js | 34 ++++ .../block-with-selection.js | 24 +-- .../at-point/split-node-at-point/block.js | 20 +- .../delete-backward-at-range/from-offset.js | 28 +-- .../insert-fragment-by-path/end-of-target.js | 31 ---- .../middle-of-target.js | 33 ---- .../start-of-target.js | 35 ---- .../by-path/insert-node-by-path/block.js | 29 --- .../by-path/insert-node-by-path/inline.js | 29 --- .../decoration-after-atomic.js | 33 ---- .../decoration-before-atomic.js | 33 ---- .../decoration-middle-atomic.js | 31 ---- .../insert-text-by-path/selection-after.js | 29 --- .../insert-text-by-path/selection-before.js | 29 --- .../insert-text-by-path/selection-end.js | 29 --- .../insert-text-by-path/selection-middle.js | 29 --- .../insert-text-by-path/selection-start.js | 29 --- .../text-end-with-marks.js | 31 ---- .../by-path/insert-text-by-path/text-end.js | 25 --- .../text-middle-with-marks.js | 29 --- .../insert-text-by-path/text-middle.js | 25 --- .../text-start-with-marks.js | 31 ---- .../by-path/insert-text-by-path/text-start.js | 29 --- .../by-path/merge-node-by-path/block.js | 24 --- .../by-path/move-node-by-path/block.js | 29 --- .../by-path/move-node-by-path/inline.js | 39 ---- .../by-path/move-node-by-path/inside-next.js | 34 ---- .../by-path/move-node-by-path/nested.js | 33 ---- .../by-path/move-node-by-path/noop-equal.js | 19 -- .../by-path/move-node-by-path/noop-inside.js | 19 -- .../by-path/move-node-by-path/sibling-swap.js | 30 --- .../by-path/move-node-by-path/text-nodes.js | 30 --- .../by-path/move-node-by-path/text.js | 25 --- .../by-path/move-node-by-path/to-sibling.js | 33 ---- .../by-path/remove-node-by-path/block.js | 24 --- .../by-path/remove-node-by-path/inline.js | 31 ---- .../remove-node-by-path/selection-inside.js | 31 ---- .../by-path/remove-node-by-path/text.js | 31 ---- .../adjacent-non-void-inlines.js | 35 ---- .../decoration-after-atomic.js | 33 ---- .../decoration-before-atomic.js | 33 ---- .../decoration-middle-atomic.js | 31 ---- .../inline-last-character.js | 35 ---- .../inline-nested-last-character.js | 45 ----- .../remove-text-by-path/inline-void.js | 37 ---- .../by-path/remove-text-by-path/inline.js | 33 ---- .../remove-text-by-path/next-void-inline.js | 35 ---- .../previous-void-inline.js | 35 ---- .../remove-text-by-path/selection-after.js | 29 --- .../remove-text-by-path/selection-before.js | 29 --- .../remove-text-by-path/selection-middle.js | 29 --- .../remove-text-by-path/selection-start.js | 29 --- .../by-path/remove-text-by-path/text.js | 25 --- .../by-path/replace-node-by-path/block.js | 25 --- .../by-path/replace-node-by-path/inline.js | 34 ---- .../by-path/replace-node-by-path/text.js | 25 --- .../by-path/replace-text-by-path/replace.js | 27 --- .../by-path/replace-text-by-path/with-mark.js | 34 ---- .../by-path/set-mark-by-path/with-data.js | 39 ---- .../by-path/set-node-by-path/block.js | 26 --- .../set-node-by-path/inline-with-is-void.js | 35 ---- .../set-node-by-path/string-shorthand.js | 23 --- .../commands/by-path/set-text-by-path/set.js | 27 --- .../by-path/set-text-by-path/with-mark.js | 28 --- .../block-with-selection.js | 39 ---- .../by-path/split-node-by-path/block.js | 31 ---- .../unwrap-block-by-path/single-block.js | 31 ---- .../unwrap-children-by-path/block-multiple.js | 27 --- .../by-path/unwrap-children-by-path/block.js | 25 --- .../unwrap-inline-by-path/single-block.js | 27 --- .../by-path/unwrap-node-by-path/block.js | 25 --- .../unwrap-node-by-path/first-block.js | 29 --- .../by-path/unwrap-node-by-path/last-block.js | 29 --- .../unwrap-node-by-path/middle-block.js | 33 ---- .../by-path/wrap-block-by-path/block.js | 25 --- .../by-path/wrap-block-by-path/text.js | 27 --- .../test/commands/on-selection/blur/basic.js | 18 +- .../test/commands/on-selection/focus/basic.js | 18 +- .../move-anchor-backward/default.js | 20 +- .../move-anchor-backward/from-collapsed.js | 20 +- .../move-anchor-backward/out-of-reverse.js | 20 +- .../move-anchor-backward/param.js | 20 +- .../move-anchor-forward/default.js | 20 +- .../move-anchor-forward/from-collapsed.js | 20 +- .../move-anchor-forward/into-reverse.js | 20 +- .../on-selection/move-anchor-forward/param.js | 20 +- .../on-selection/move-backward/default.js | 20 +- .../on-selection/move-backward/expanded.js | 20 +- .../on-selection/move-backward/param.js | 20 +- .../on-selection/move-backward/reversed.js | 20 +- .../on-selection/move-end-backward/default.js | 20 +- .../move-end-backward/from-collapsed.js | 20 +- .../move-end-backward/into-reverse.js | 20 +- .../move-end-backward/out-of-reverse.js | 20 +- .../on-selection/move-end-backward/param.js | 20 +- .../move-end-backward/reversed.js | 20 +- .../on-selection/move-end-forward/default.js | 20 +- .../move-end-forward/from-collapsed.js | 20 +- .../on-selection/move-end-forward/param.js | 20 +- .../on-selection/move-end-forward/reversed.js | 20 +- .../move-focus-backward/default.js | 20 +- .../move-focus-backward/from-collapsed.js | 20 +- .../move-focus-backward/into-reverse.js | 20 +- .../on-selection/move-focus-backward/param.js | 20 +- .../move-focus-forward/default.js | 20 +- .../move-focus-forward/from-collapsed.js | 20 +- .../move-focus-forward/out-of-reverse.js | 20 +- .../on-selection/move-focus-forward/param.js | 20 +- .../on-selection/move-forward/default.js | 20 +- .../on-selection/move-forward/expanded.js | 20 +- .../on-selection/move-forward/param.js | 20 +- .../on-selection/move-forward/reversed.js | 20 +- .../move-start-backward/default.js | 20 +- .../move-start-backward/from-collapsed.js | 20 +- .../on-selection/move-start-backward/param.js | 20 +- .../move-start-backward/reversed.js | 20 +- .../move-start-forward/default.js | 20 +- .../move-start-forward/from-collapsed.js | 20 +- .../move-start-forward/into-reverse.js | 20 +- .../move-start-forward/out-of-reverse.js | 20 +- .../on-selection/move-start-forward/param.js | 20 +- .../move-start-forward/reversed.js | 20 +- .../move-to-anchor/already-collapsed.js | 20 +- .../on-selection/move-to-anchor/basic.js | 20 +- .../on-selection/move-to-end-of-block/end.js | 28 +-- .../move-to-end-of-block/middle.js | 28 +-- .../move-to-end-of-block/start.js | 28 +-- .../move-to-end-of-document/block-end.js | 28 +-- .../move-to-end-of-document/block-middle.js | 28 +-- .../move-to-end-of-document/block-start.js | 28 +-- .../move-to-end-of-document/document-end.js | 28 +-- .../move-to-end-of-document/document-start.js | 28 +-- .../move-to-end-of-next-block/block-end.js | 28 +-- .../move-to-end-of-next-block/block-middle.js | 28 +-- .../move-to-end-of-next-block/block-start.js | 28 +-- .../move-to-end-of-next-block/document-end.js | 28 +-- .../document-start.js | 28 +-- .../block-end.js | 28 +-- .../block-middle.js | 28 +-- .../block-start.js | 28 +-- .../document-end.js | 28 +-- .../document-start.js | 28 +-- .../move-to-end/already-collapsed.js | 20 +- .../on-selection/move-to-end/basic.js | 20 +- .../commands/on-selection/move-to-end/void.js | 12 +- .../move-to-focus/already-collapsed.js | 20 +- .../on-selection/move-to-focus/basic.js | 20 +- .../move-to-range-of-document/basic.js | 30 +-- .../move-to-start-of-document/block-end.js | 28 +-- .../move-to-start-of-document/block-middle.js | 28 +-- .../move-to-start-of-document/block-start.js | 28 +-- .../move-to-start-of-document/document-end.js | 28 +-- .../document-start.js | 28 +-- .../move-to-start/already-collapsed.js | 20 +- .../on-selection/move-to-start/basic.js | 20 +- .../on-selection/move-to-start/void.js | 12 +- .../move-word-backward/collapsed.js | 20 +- .../move-word-backward/expanded.js | 20 +- .../move-word-backward/reversed.js | 20 +- .../move-word-forward/collapsed.js | 20 +- .../move-word-forward/expanded.js | 20 +- .../move-word-forward/reversed.js | 20 +- .../on-selection/select/with-object.js | 20 +- .../on-selection/select/with-selection.js | 20 +- .../test/commands/on-state/set-data/simple.js | 20 +- .../with-intent/add-mark/across-blocks.js | 28 +-- .../with-intent/add-mark/across-inlines.js | 44 ++--- .../add-mark/collapsed-selection-end.js | 20 +- .../add-mark/collapsed-selection-middle.js | 20 +- .../add-mark/collapsed-selection-start.js | 20 +- .../existing-marks-across-blocks-at-edge.js | 28 +-- .../add-mark/existing-marks-across-blocks.js | 28 +-- .../with-intent/add-mark/existing-marks.js | 20 +- .../with-intent/add-mark/first-character.js | 20 +- .../with-intent/add-mark/last-character.js | 20 +- .../with-intent/add-mark/middle-character.js | 20 +- .../with-intent/add-mark/whole-word.js | 20 +- .../with-intent/add-mark/with-mark-object.js | 20 +- .../with-intent/add-mark/with-plain-object.js | 20 +- .../with-intent/add-marks/across-blocks.js | 28 +-- .../with-intent/add-marks/across-inlines.js | 80 ++++---- .../with-intent/add-marks/across-marks.js | 20 +- .../add-marks/collapsed-selection-end.js | 20 +- .../add-marks/collapsed-selection-middle.js | 20 +- .../add-marks/collapsed-selection-start.js | 20 +- .../with-intent/add-marks/first-character.js | 20 +- .../with-intent/add-marks/inside-mark.js | 20 +- .../with-intent/add-marks/last-character.js | 20 +- .../with-intent/add-marks/middle-character.js | 20 +- .../with-intent/add-marks/whole-word.js | 20 +- .../with-intent/add-marks/with-mark-object.js | 20 +- .../add-marks/with-plain-object.js | 20 +- .../delete-backward/empty-after-void-block.js | 20 +- .../empty-after-void-inline.js | 20 +- .../delete-backward/first-character.js | 20 +- .../delete-backward/inline-after.js | 26 +-- .../delete-backward/inline-before.js | 26 +-- .../with-intent/delete-backward/inline-end.js | 24 +-- .../delete-backward/inline-inside.js | 32 ++-- .../join-blocks-from-inline.js | 36 ++-- .../join-blocks-with-inline-void.js | 24 +-- .../join-blocks-with-inline.js | 26 +-- .../delete-backward/join-blocks.js | 22 +-- .../join-nested-blocks-different-depth.js | 18 +- .../delete-backward/join-nested-blocks.js | 30 +-- .../delete-backward/last-character.js | 20 +- .../delete-backward/middle-character.js | 20 +- .../delete-backward/multiple-characters.js | 20 +- .../delete-backward/single-non-void-block.js | 20 +- .../delete-backward/single-void-block.js | 8 +- .../delete-backward/start-of-document.js | 20 +- .../inline-after-emoji.js | 26 +-- .../delete-char-backward/inline-end-emoji.js | 28 +-- .../inline-inside-emoji.js | 28 +-- .../delete-char-backward/inline-only-emoji.js | 28 ++- .../delete-char-backward/text-end.js | 20 +- .../delete-char-backward/text-middle.js | 20 +- .../delete-char-backward/text-start.js | 20 +- .../inline-before-emoji.js | 26 +-- .../inline-middle-emoji.js | 28 +-- .../delete-char-forward/inline-start-emoji.js | 26 +-- .../delete-char-forward/text-last.js | 20 +- .../delete-char-forward/text-middle.js | 20 +- .../delete-char-forward/text-start.js | 20 +- .../delete-forward/before-inline-sibling.js | 28 ++- .../delete-forward/empty-before-void-block.js | 16 +- .../empty-before-void-inline.js | 20 +- .../delete-forward/end-of-document.js | 20 +- .../delete-forward/first-character.js | 20 +- .../delete-forward/inside-inline-sibling.js | 30 ++- .../join-blocks-with-inline-void.js | 24 +-- .../delete-forward/join-blocks-with-inline.js | 26 ++- .../with-intent/delete-forward/join-blocks.js | 22 +-- .../delete-forward/join-nested-blocks.js | 30 +-- .../delete-forward/last-character.js | 20 +- .../delete-forward/middle-character.js | 20 +- .../delete-forward/multiple-characters.js | 20 +- .../delete-forward/single-non-void-block.js | 20 +- .../delete-forward/single-void-block.js | 8 +- .../start-text-middle-inline.js | 28 ++- .../inline-middle-emoji.js | 22 +-- .../inline-multi-voids.js | 20 +- .../delete-line-backward/inline-void-first.js | 20 +- .../delete-line-backward/text-end.js | 20 +- .../delete-line-backward/text-start.js | 12 +- .../delete-line-backward/word-middle.js | 20 +- .../inline-middle-emoji.js | 22 +-- .../delete-line-forward/inline-multi-voids.js | 20 +- .../delete-line-forward/inline-void-end.js | 20 +- .../delete-line-forward/text-end.js | 12 +- .../delete-line-forward/text-start.js | 20 +- .../delete-line-forward/word-middle.js | 20 +- .../inline-after-emoji.js | 20 +- .../inline-middle-emoji.js | 28 ++- .../delete-word-backward/join-blocks.js | 22 +-- .../delete-word-backward/text-end.js | 20 +- .../delete-word-backward/word-middle.js | 20 +- .../delete-word-forward/inline-after-emoji.js | 22 +-- .../inline-middle-emoji.js | 22 +-- .../delete-word-forward/join-blocks.js | 22 +-- .../delete-word-forward/word-middle.js | 20 +- .../delete-word-forward/word-start.js | 20 +- .../delete/across-blocks-inlines.js | 54 +++--- .../with-intent/delete/across-blocks.js | 24 +-- .../with-intent/delete/across-depths.js | 32 ++-- .../delete/across-nested-blocks.js | 46 ++--- .../delete/across-texts-and-inlines.js | 22 +-- .../with-intent/delete/all-nested-blocks.js | 42 ++--- .../delete/before-inline-sibling.js | 26 +-- .../delete/expanded-across-whole-mark.js | 24 +-- .../with-intent/delete/first-character.js | 20 +- .../with-intent/delete/first-position.js | 20 +- .../hanging-selection-multiple-blocks.js | 26 +-- .../delete/hanging-selection-single-block.js | 24 +-- .../delete/inside-inline-sibling.js | 28 ++- .../with-intent/delete/inside-inline.js | 28 +-- .../delete/join-blocks-and-trim.js | 24 +-- .../delete/join-blocks-with-inlines.js | 28 +-- .../with-intent/delete/join-blocks.js | 24 +-- .../delete/join-double-nested-blocks.js | 40 ++-- .../with-intent/delete/join-nested-blocks.js | 32 ++-- .../with-intent/delete/last-character.js | 20 +- .../with-intent/delete/middle-character.js | 20 +- .../with-intent/delete/nested-block.js | 30 +-- ...-first-with-void-siblings-only-non-void.js | 20 +- ...tially-non-void-and-up-to-start-of-void.js | 24 +-- ...id-siblings-partially-non-void-and-void.js | 24 +-- ...t-with-void-siblings-partially-non-void.js | 24 +-- .../with-intent/delete/non-void-triple.js | 26 +-- ...ock-as-first-with-non-void-siblings-all.js | 22 +-- ...on-void-siblings-backward-selection-all.js | 22 +-- ...-first-with-non-void-siblings-only-void.js | 24 +-- ...void-siblings-select-void-and-next-word.js | 24 +-- ...-siblings-select-void-end-and-next-word.js | 24 +-- .../with-intent/delete/void-block-as-only.js | 8 +- ...-with-non-void-siblings-only-first-void.js | 22 +-- ...first-with-non-void-siblings-only-voids.js | 24 +-- ...nline-as-first-with-non-void-block-next.js | 24 +-- ...d-inline-as-first-with-non-void-sibling.js | 20 +- ...as-last-with-non-void-previous-siblings.js | 26 +-- .../with-intent/delete/whole-inline.js | 28 ++- .../with-intent/delete/whole-word-mark.js | 20 +- .../commands/with-intent/delete/whole-word.js | 20 +- .../with-intent/insert-block/block-end.js | 22 +-- .../with-intent/insert-block/block-middle.js | 24 +-- .../with-intent/insert-block/block-start.js | 22 +-- .../with-intent/insert-block/is-empty.js | 28 ++- .../insert-block/is-inline-void.js | 42 ++--- .../with-intent/insert-block/is-void-end.js | 20 +- .../with-intent/insert-block/is-void-start.js | 20 +- .../with-intent/insert-block/with-block.js | 22 +-- .../with-intent/insert-block/with-object.js | 22 +-- .../insert-fragment/block-empty.js | 28 +-- .../with-intent/insert-fragment/block-end.js | 26 +-- .../insert-fragment/block-middle.js | 26 +-- .../insert-fragment/block-start.js | 26 +-- .../end-block-multiple-blocks.js | 34 ++-- .../with-intent/insert-fragment/end-block.js | 26 +-- .../with-intent/insert-fragment/end-inline.js | 30 +-- .../insert-fragment/flat-blocks/end-block.js | 32 ++-- .../hanging-selection-mixed-types.js | 40 ++-- .../flat-blocks/start-block.js | 32 ++-- .../fragment-adjacent-texts.js | 28 +-- .../insert-fragment/fragment-inline-node.js | 28 +-- .../fragment-multiple-blocks.js | 30 +-- .../fragment-multiple-marks.js | 28 +-- .../fragment-nested-blocks-end-of-node.js | 44 ++--- .../fragment-nested-blocks-start-of-node.js | 44 ++--- .../insert-fragment/fragment-nested-blocks.js | 42 ++--- .../fragment-single-child-block.js | 26 +-- .../insert-fragment/fragment-single-inline.js | 28 +-- .../insert-fragment/fragment-single-mark.js | 28 +-- .../insert-fragment/hanging-block.js | 42 ++--- .../hanging-selection-single-block.js | 42 ++--- .../insert-fragment/inline-middle.js | 34 ++-- .../insert-fragment/inline-start.js | 30 +-- .../between-texts-into-middle-block.js | 30 +-- .../insert-fragment/inlines/middle-block.js | 32 ++-- .../insert-fragment/inlines/middle-inline.js | 34 ++-- .../insert-fragment/insert-block.js | 28 +-- .../insert-inline-at-inline-middle.js | 36 ++-- .../insert-fragment/insert-inline.js | 32 ++-- .../insert-multiple-blocks-at-middle.js | 30 +-- .../insert-multiple-blocks-at-start.js | 34 ++-- .../insert-fragment/insert-multiple-texts.js | 28 +-- .../insert-nested-blocks-at-end.js | 42 ++--- .../insert-nested-blocks-at-middle.js | 38 ++-- .../insert-nested-blocks-at-start.js | 42 ++--- .../last-block-fragment-multiple.js | 34 ++-- .../last-block-fragment-single.js | 26 +-- .../last-block-inline-fragment-single.js | 30 +-- .../insert-fragment/lists/merge-lists.js | 14 +- .../insert-fragment/marks/middle-block.js | 26 +-- .../marks/multiple-marks-middle-block.js | 26 +-- .../insert-fragment/merge-deep-nested.js | 30 +-- .../insert-fragment/merge-lists.js | 16 +- .../insert-fragment/middle-block.js | 26 +-- .../middle-fragment-adjacent-texts.js | 32 ++-- .../middle-inline-fragment-inline.js | 36 ++-- .../insert-fragment/middle-inline.js | 34 ++-- .../nested-block-fragment-nested-blocks.js | 42 ++--- .../end-block.js | 42 ++--- .../middle-block-nested.js | 40 ++-- .../middle-block.js | 40 ++-- .../start-block.js | 42 ++--- .../end-block-nested.js | 48 ++--- .../start-block.js | 24 +-- .../start-block-multiple-blocks.js | 34 ++-- .../start-block-with-void-no-text.js | 28 +-- .../insert-fragment/start-block.js | 26 +-- .../insert-fragment/start-inline.js | 30 +-- .../insert-fragment/start-second-block.js | 30 +-- .../tables/merge-cells-with-nested-blocks.js | 94 +++++----- .../tables/merge-into-empty-cells.js | 14 +- .../tables/merge-into-full-cells.js | 14 +- .../with-delete-across-blocks.js | 30 +-- .../insert-fragment/with-previous-block.js | 30 +-- .../words/adjacent-texts-after-void.js | 26 +-- .../words/adjacent-texts-end-first-block.js | 30 +-- .../words/adjacent-texts-into-empty-block.js | 26 +-- .../insert-fragment/words/after-inline.js | 28 +-- .../insert-fragment/words/before-inline.js | 28 +-- .../insert-fragment/words/end-block.js | 24 +-- .../insert-fragment/words/end-inline.js | 36 ++-- .../insert-fragment/words/middle-block.js | 24 +-- .../insert-fragment/words/middle-inline.js | 32 ++-- .../insert-fragment/words/start-block.js | 24 +-- .../words/start-second-block.js | 28 +-- .../words/with-delete-across-blocks.js | 28 +-- .../with-intent/insert-inline/block-end.js | 20 +- .../with-intent/insert-inline/block-middle.js | 20 +- .../with-intent/insert-inline/block-start.js | 20 +- .../insert-inline/inline-middle.js | 28 +-- .../with-intent/insert-inline/is-empty.js | 20 +- .../with-intent/insert-inline/is-void.js | 12 +- .../with-intent/insert-inline/with-inline.js | 20 +- .../with-intent/insert-text/after-mark.js | 20 +- .../with-intent/insert-text/before-mark.js | 20 +- .../blocks-with-overlapping-marks.js | 28 +-- .../with-intent/insert-text/during-mark.js | 20 +- .../insert-text/empty-block-with-mark.js | 20 +- .../insert-text/expanded-with-mark.js | 24 +-- .../insert-text/first-character.js | 20 +- .../with-intent/insert-text/first-space.js | 20 +- .../with-intent/insert-text/first-words.js | 20 +- .../hanging-selection-multiple-blocks.js | 26 +-- .../hanging-selection-single-block.js | 24 +-- .../with-intent/insert-text/inside-void.js | 12 +- .../with-intent/insert-text/last-character.js | 20 +- .../with-intent/insert-text/last-space.js | 20 +- .../with-intent/insert-text/last-words.js | 20 +- .../insert-text/middle-character.js | 20 +- .../with-intent/insert-text/middle-space.js | 20 +- .../with-intent/insert-text/middle-words.js | 20 +- .../with-intent/insert-text/with-marks.js | 20 +- .../with-intent/remove-mark/across-blocks.js | 28 +-- .../with-intent/remove-mark/across-inlines.js | 44 ++--- .../remove-mark/collapsed-selection.js | 20 +- .../with-intent/remove-mark/existing-marks.js | 20 +- .../remove-mark/first-character.js | 20 +- .../with-intent/remove-mark/last-character.js | 20 +- .../remove-mark/middle-character.js | 20 +- .../remove-mark/part-of-mark-backward.js | 20 +- .../with-intent/remove-mark/part-of-mark.js | 20 +- .../with-intent/remove-mark/whole-word.js | 20 +- .../remove-mark/with-mark-object.js | 20 +- .../remove-mark/with-plain-object.js | 20 +- .../with-intent/replace-mark/across-blocks.js | 28 +-- .../replace-mark/across-inlines.js | 44 ++--- .../replace-mark/existing-marks.js | 20 +- .../replace-mark/first-character.js | 20 +- .../replace-mark/last-character.js | 20 +- .../replace-mark/middle-character.js | 20 +- .../with-intent/replace-mark/whole-word.js | 20 +- .../replace-mark/with-mark-object.js | 20 +- .../replace-mark/with-plain-object.js | 20 +- .../with-intent/set-block/across-blocks.js | 20 +- .../with-intent/set-block/across-inlines.js | 48 +++-- .../with-intent/set-block/data-only.js | 18 +- .../hanging-selection-across-inlines.js | 48 +++-- .../set-block/hanging-selection.js | 24 +-- .../with-intent/set-block/nested-block.js | 24 +-- .../single-block-string-shorthand.js | 16 +- .../with-intent/set-block/single-block.js | 16 +- .../with-intent/set-block/with-data-as-map.js | 16 +- .../set-block/with-data-as-object.js | 16 +- .../with-intent/set-block/with-is-void.js | 16 +- .../with-intent/set-inline/across-inlines.js | 36 ++-- .../with-intent/set-inline/data-only.js | 26 +-- .../with-intent/set-inline/nested-inline.js | 24 +-- .../single-inline-string-shorthand.js | 24 +-- .../with-intent/set-inline/single-inline.js | 24 +-- .../set-inline/with-data-object.js | 24 +-- .../with-intent/set-inline/with-data.js | 28 ++- .../with-intent/set-inline/with-is-void.js | 24 +-- .../split-block/after-inline-void.js | 24 +-- .../with-intent/split-block/after-inline.js | 28 +-- .../with-intent/split-block/before-inline.js | 28 +-- .../with-intent/split-block/block-end.js | 26 +-- .../with-intent/split-block/block-middle.js | 22 +-- .../with-intent/split-block/block-start.js | 28 ++- .../commands/with-intent/split-block/depth.js | 46 ++--- .../with-delete-across-blocks-and-inlines.js | 34 ++-- .../split-block/with-delete-across-blocks.js | 26 +-- .../with-delete-hanging-selection.js | 34 ++-- .../with-intent/split-block/with-delete.js | 22 +-- .../with-intent/split-block/with-inline.js | 34 ++-- .../with-intent/split-block/with-marks.js | 24 +-- .../with-intent/split-inline/block-end.js | 30 ++- .../with-intent/split-inline/block-middle.js | 30 ++- .../with-intent/split-inline/block-start.js | 32 ++-- .../with-intent/split-inline/height.js | 48 +++-- .../with-intent/split-inline/with-delete.js | 30 ++- .../with-intent/split-inline/with-marks.js | 42 ++--- .../toggle-mark/add-across-blocks.js | 28 +-- .../toggle-mark/add-across-inlines.js | 72 ++++--- .../add-collapsed-selection-start.js | 20 +- .../toggle-mark/add-collapsed-selection.js | 20 +- .../add-existing-marks-partially-marked.js | 20 +- .../toggle-mark/add-existing-marks.js | 20 +- .../toggle-mark/add-first-character.js | 20 +- .../toggle-mark/add-last-character.js | 20 +- .../toggle-mark/add-middle-character.js | 20 +- .../toggle-mark/add-partially-marked.js | 20 +- .../with-intent/toggle-mark/add-whole-word.js | 20 +- .../toggle-mark/add-with-mark-object.js | 20 +- .../toggle-mark/add-with-plain-object.js | 20 +- .../toggle-mark/remove-across-blocks.js | 28 +-- .../toggle-mark/remove-across-inlines.js | 70 ++++--- .../remove-collapsed-selection-beginning.js | 20 +- .../toggle-mark/remove-collapsed-selection.js | 20 +- .../toggle-mark/remove-existing-marks.js | 20 +- .../toggle-mark/remove-first-character.js | 20 +- .../toggle-mark/remove-last-character.js | 20 +- .../toggle-mark/remove-middle-character.js | 20 +- .../toggle-mark/remove-whole-word.js | 20 +- .../toggle-mark/remove-with-mark-object.js | 20 +- .../toggle-mark/remove-with-plain-object.js | 20 +- .../with-intent/unwrap-block/across-blocks.js | 32 ++-- .../unwrap-block/across-inlines.js | 48 ++--- .../unwrap-block/ending-child-blocks.js | 52 +++--- ...le-child-blocks-with-backward-selection.js | 56 +++--- .../unwrap-block/middle-child-blocks.js | 56 +++--- .../with-intent/unwrap-block/nested-block.js | 32 ++-- .../with-intent/unwrap-block/single-block.js | 24 +-- .../unwrap-block/starting-child-blocks.js | 52 +++--- .../with-intent/unwrap-block/with-object.js | 18 +- .../unwrap-inline/across-blocks.js | 28 +-- .../unwrap-inline/across-inlines-and-text.js | 26 +-- .../unwrap-inline/across-inlines.js | 44 ++--- .../with-intent/unwrap-inline/nested-block.js | 28 +-- .../with-intent/unwrap-inline/only-one.js | 20 +- .../with-intent/unwrap-inline/single-block.js | 20 +- .../with-intent/unwrap-inline/with-object.js | 20 +- .../with-intent/wrap-block/across-blocks.js | 32 ++-- .../with-intent/wrap-block/across-inlines.js | 52 +++--- .../wrap-block/nested-block-with-object.js | 30 +-- .../with-intent/wrap-block/nested-block.js | 32 ++-- .../with-intent/wrap-block/single-block.js | 24 +-- .../with-intent/wrap-block/with-object.js | 22 +-- .../with-intent/wrap-inline/across-blocks.js | 28 +-- .../with-intent/wrap-inline/across-inlines.js | 40 ++-- .../with-intent/wrap-inline/collapsed.js | 20 +- .../with-intent/wrap-inline/inline-end.js | 30 +-- .../wrap-inline/inline-middle-with-marks.js | 36 ++-- .../with-intent/wrap-inline/inline-middle.js | 34 ++-- .../with-intent/wrap-inline/inline-start.js | 32 ++-- .../with-intent/wrap-inline/inline-void.js | 24 +-- .../with-intent/wrap-inline/nested-block.js | 28 +-- .../with-intent/wrap-inline/single-block.js | 20 +- .../commands/with-intent/wrap-inline/twice.js | 24 +-- .../with-intent/wrap-inline/whole-block.js | 20 +- .../with-intent/wrap-inline/with-object.js | 20 +- .../with-intent/wrap-text/across-blocks.js | 28 +-- .../with-intent/wrap-text/across-inlines.js | 36 ++-- .../wrap-text/backwards-selection.js | 20 +- .../with-intent/wrap-text/empty-block.js | 20 +- .../with-intent/wrap-text/end-of-block.js | 20 +- .../with-intent/wrap-text/middle-of-block.js | 20 +- .../with-intent/wrap-text/start-of-block.js | 20 +- .../with-intent/wrap-text/whole-block.js | 20 +- .../with-intent/wrap-text/without-suffix.js | 20 +- packages/slate/test/helpers/index.js | 18 +- packages/slate/test/index.js | 68 +------ 622 files changed, 8022 insertions(+), 8430 deletions(-) delete mode 100644 packages/slate-hyperscript/src/resolve-descendants.ts create mode 100644 packages/slate-hyperscript/test/fixtures/fragment-element.js create mode 100644 packages/slate-hyperscript/test/fixtures/fragment-empty.js create mode 100644 packages/slate-hyperscript/test/fixtures/fragment-string.js create mode 100644 packages/slate/test/commands/at-path/insert-fragment-by-path/end-of-target.js create mode 100644 packages/slate/test/commands/at-path/insert-fragment-by-path/middle-of-target.js create mode 100644 packages/slate/test/commands/at-path/insert-fragment-by-path/start-of-target.js create mode 100644 packages/slate/test/commands/at-path/insert-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/insert-node-by-path/inline.js create mode 100644 packages/slate/test/commands/at-path/insert-node-by-path/text.js create mode 100644 packages/slate/test/commands/at-path/lift-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/lift-node-by-path/first-block.js create mode 100644 packages/slate/test/commands/at-path/lift-node-by-path/last-block.js create mode 100644 packages/slate/test/commands/at-path/lift-node-by-path/middle-block.js create mode 100644 packages/slate/test/commands/at-path/merge-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/inline.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/inside-next.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/nested.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/noop-equal.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/sibling-swap.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/text-nodes.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/text.js create mode 100644 packages/slate/test/commands/at-path/move-node-by-path/to-sibling.js create mode 100644 packages/slate/test/commands/at-path/pluck-node-by-path/block-multiple.js create mode 100644 packages/slate/test/commands/at-path/pluck-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/remove-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/remove-node-by-path/inline.js create mode 100644 packages/slate/test/commands/at-path/remove-node-by-path/selection-inside.js create mode 100644 packages/slate/test/commands/at-path/remove-node-by-path/text.js create mode 100644 packages/slate/test/commands/at-path/replace-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/replace-node-by-path/inline.js create mode 100644 packages/slate/test/commands/at-path/replace-node-by-path/text.js create mode 100644 packages/slate/test/commands/at-path/replace-text-by-path/basic.js create mode 100644 packages/slate/test/commands/at-path/set-mark-by-path/basic.js create mode 100644 packages/slate/test/commands/at-path/set-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/set-node-by-path/inline.js create mode 100644 packages/slate/test/commands/at-path/set-node-by-path/text.js create mode 100644 packages/slate/test/commands/at-path/split-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/split-node-by-path/selection.js create mode 100644 packages/slate/test/commands/at-path/wrap-node-by-path/block.js create mode 100644 packages/slate/test/commands/at-path/wrap-node-by-path/text.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-end.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-middle-with-marks.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js create mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-start.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/inline.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js create mode 100644 packages/slate/test/commands/at-point/remove-text-by-path/text.js create mode 100644 packages/slate/test/commands/at-point/replace-text-by-path/replace.js create mode 100644 packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js delete mode 100644 packages/slate/test/commands/by-path/insert-fragment-by-path/end-of-target.js delete mode 100644 packages/slate/test/commands/by-path/insert-fragment-by-path/middle-of-target.js delete mode 100644 packages/slate/test/commands/by-path/insert-fragment-by-path/start-of-target.js delete mode 100644 packages/slate/test/commands/by-path/insert-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/insert-node-by-path/inline.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/decoration-after-atomic.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/decoration-before-atomic.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/decoration-middle-atomic.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/selection-after.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/selection-before.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/selection-end.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/selection-middle.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/selection-start.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/text-end.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/text-middle-with-marks.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/text-middle.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js delete mode 100644 packages/slate/test/commands/by-path/insert-text-by-path/text-start.js delete mode 100644 packages/slate/test/commands/by-path/merge-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/inline.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/inside-next.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/nested.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/text.js delete mode 100644 packages/slate/test/commands/by-path/move-node-by-path/to-sibling.js delete mode 100644 packages/slate/test/commands/by-path/remove-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/remove-node-by-path/inline.js delete mode 100644 packages/slate/test/commands/by-path/remove-node-by-path/selection-inside.js delete mode 100644 packages/slate/test/commands/by-path/remove-node-by-path/text.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/adjacent-non-void-inlines.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/decoration-after-atomic.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/decoration-before-atomic.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/decoration-middle-atomic.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/inline-last-character.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/inline-nested-last-character.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/inline-void.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/inline.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/next-void-inline.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/previous-void-inline.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/selection-after.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/selection-before.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/selection-middle.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/selection-start.js delete mode 100644 packages/slate/test/commands/by-path/remove-text-by-path/text.js delete mode 100644 packages/slate/test/commands/by-path/replace-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/replace-node-by-path/inline.js delete mode 100644 packages/slate/test/commands/by-path/replace-node-by-path/text.js delete mode 100644 packages/slate/test/commands/by-path/replace-text-by-path/replace.js delete mode 100644 packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js delete mode 100644 packages/slate/test/commands/by-path/set-mark-by-path/with-data.js delete mode 100644 packages/slate/test/commands/by-path/set-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/set-node-by-path/inline-with-is-void.js delete mode 100644 packages/slate/test/commands/by-path/set-node-by-path/string-shorthand.js delete mode 100644 packages/slate/test/commands/by-path/set-text-by-path/set.js delete mode 100644 packages/slate/test/commands/by-path/set-text-by-path/with-mark.js delete mode 100644 packages/slate/test/commands/by-path/split-node-by-path/block-with-selection.js delete mode 100644 packages/slate/test/commands/by-path/split-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-block-by-path/single-block.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-children-by-path/block-multiple.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-children-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-inline-by-path/single-block.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-node-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-node-by-path/first-block.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-node-by-path/last-block.js delete mode 100644 packages/slate/test/commands/by-path/unwrap-node-by-path/middle-block.js delete mode 100644 packages/slate/test/commands/by-path/wrap-block-by-path/block.js delete mode 100644 packages/slate/test/commands/by-path/wrap-block-by-path/text.js diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts index cafbdbe9fd..bb97534ee7 100644 --- a/packages/slate-hyperscript/src/creators.ts +++ b/packages/slate-hyperscript/src/creators.ts @@ -1,15 +1,89 @@ -import { Element, Mark, Node, Path, Selection, Text, Value } from 'slate' +import { + Element, + Descendant, + Fragment, + Mark, + Node, + Path, + Selection, + Text, + Value, +} from 'slate' import { resolveDescendants } from './resolve-descendants' import { AnchorToken, AnnotationToken, FocusToken, Token, + addAnchorToken, + addAnnotationToken, + addFocusToken, getAnchorOffset, getFocusOffset, getAnnotationOffsets, } from './tokens' +/** + * Resolve the descedants of a node by normalizing the children that can be + * passed into a hyperscript creator function. + */ + +const STRINGS: WeakSet = new WeakSet() + +const resolveDescendants = (children: any[]): Descendant[] => { + const nodes: Node[] = [] + + const addChild = (child: Node | Token): void => { + const prev = nodes[nodes.length - 1] + + if (typeof child === 'string') { + const text = { text: child, marks: [] } + STRINGS.add(text) + child = text + } + + if (Text.isText(child)) { + const c = child // HACK: fix typescript complaining + if ( + Text.isText(prev) && + STRINGS.has(prev) && + STRINGS.has(c) && + c.marks.every(m => Mark.exists(m, prev.marks)) && + prev.marks.every(m => Mark.exists(m, c.marks)) + ) { + prev.text += c.text + } else { + nodes.push(c) + } + } else if (Element.isElement(child)) { + nodes.push(child) + } else if (child instanceof Token) { + let n = nodes[nodes.length - 1] + + if (!Text.isText(n)) { + addChild('') + n = nodes[nodes.length - 1] as Text + } + + if (child instanceof AnchorToken) { + addAnchorToken(n, child) + } else if (child instanceof FocusToken) { + addFocusToken(n, child) + } else if (child instanceof AnnotationToken) { + addAnnotationToken(n, child) + } + } else { + throw new Error(`Unexpected hyperscript child object: ${child}`) + } + } + + for (const child of children.flat()) { + addChild(child) + } + + return nodes +} + /** * Create an anchor token. */ @@ -87,6 +161,18 @@ export function createFocus( return new FocusToken(attributes) } +/** + * Create an `Fragment` object. + */ + +export function createFragment( + tagName: string, + attributes: { [key: string]: any }, + children: any[] +): Fragment { + return { nodes: resolveDescendants(children) } +} + /** * Create a `Text` object with a mark applied. */ @@ -192,7 +278,10 @@ export function createText( // COMPAT: Re-create the node, because if they used the tag we want to // guarantee that it won't be merge with other string children. - return { ...node, ...attributes } + STRINGS.delete(node) + + Object.assign(node, attributes) + return node } /** diff --git a/packages/slate-hyperscript/src/index.ts b/packages/slate-hyperscript/src/index.ts index cf5e51f3a1..bb2a3524f6 100644 --- a/packages/slate-hyperscript/src/index.ts +++ b/packages/slate-hyperscript/src/index.ts @@ -7,6 +7,7 @@ import { createAnnotation, createElement, createFocus, + createFragment, createMark, createSelection, createText, @@ -23,6 +24,7 @@ const DEFAULT_CREATORS = { cursor: createCursor, element: createElement, focus: createFocus, + fragment: createFragment, mark: createMark, selection: createSelection, text: createText, diff --git a/packages/slate-hyperscript/src/resolve-descendants.ts b/packages/slate-hyperscript/src/resolve-descendants.ts deleted file mode 100644 index 5b8f16c0e5..0000000000 --- a/packages/slate-hyperscript/src/resolve-descendants.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { Descendant, Element, Mark, Node, Text } from 'slate' -import { - AnchorToken, - AnnotationToken, - FocusToken, - Token, - addAnchorToken, - addAnnotationToken, - addFocusToken, -} from './tokens' - -/** - * Resolve the descedants of a node by normalizing the children that can be - * passed into a hyperscript creator function. - */ - -const STRINGS: WeakSet = new WeakSet() - -export const resolveDescendants = (children: any[]): Descendant[] => { - const nodes: Node[] = [] - - const addChild = (child: Node | Token): void => { - const prev = nodes[nodes.length - 1] - - if (typeof child === 'string') { - const text = { text: child, marks: [] } - STRINGS.add(text) - child = text - } - - if (Text.isText(child)) { - const c = child // HACK: fix typescript complaining - if ( - Text.isText(prev) && - STRINGS.has(prev) && - STRINGS.has(c) && - c.marks.every(m => Mark.exists(m, prev.marks)) && - prev.marks.every(m => Mark.exists(m, c.marks)) - ) { - prev.text += c.text - } else { - nodes.push(c) - } - } else if (Element.isElement(child)) { - nodes.push(child) - } else if (child instanceof Token) { - let n = nodes[nodes.length - 1] - - if (!Text.isText(n)) { - addChild('') - n = nodes[nodes.length - 1] as Text - } - - if (child instanceof AnchorToken) { - addAnchorToken(n, child) - } else if (child instanceof FocusToken) { - addFocusToken(n, child) - } else if (child instanceof AnnotationToken) { - addAnnotationToken(n, child) - } - } else { - throw new Error(`Unexpected hyperscript child object: ${child}`) - } - } - - for (const child of children.flat()) { - addChild(child) - } - - return nodes -} diff --git a/packages/slate-hyperscript/test/fixtures/fragment-element.js b/packages/slate-hyperscript/test/fixtures/fragment-element.js new file mode 100644 index 0000000000..2d124bc473 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/fragment-element.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = ( + + word + +) + +export const output = { + nodes: [ + { + nodes: [ + { + text: 'word', + marks: [], + }, + ], + }, + ], +} diff --git a/packages/slate-hyperscript/test/fixtures/fragment-empty.js b/packages/slate-hyperscript/test/fixtures/fragment-empty.js new file mode 100644 index 0000000000..3e80b927d8 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/fragment-empty.js @@ -0,0 +1,9 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = + +export const output = { + nodes: [], +} diff --git a/packages/slate-hyperscript/test/fixtures/fragment-string.js b/packages/slate-hyperscript/test/fixtures/fragment-string.js new file mode 100644 index 0000000000..6db984ff33 --- /dev/null +++ b/packages/slate-hyperscript/test/fixtures/fragment-string.js @@ -0,0 +1,14 @@ +/** @jsx h */ + +import h from 'slate-hyperscript' + +export const input = word + +export const output = { + nodes: [ + { + text: 'word', + marks: [], + }, + ], +} diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 2115c0cc4e..6d31283095 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -6,6 +6,7 @@ import { Element, Text, Node, + NodeEntry, Path, Descendant, Value, @@ -62,13 +63,13 @@ class PathCommands { if (!closestBlock) { throw new Error( - `Cannot merge the leaf block above path ${path} because there isn't one.` + `Cannot merge the leaf block above path [${path}] because there isn't one.` ) } if (!prevBlock) { throw new Error( - `Cannot merge the block above path ${path} with the previous leaf block because there isn't one.` + `Cannot merge the block above path [${path}] with the previous leaf block because there isn't one.` ) } @@ -104,7 +105,7 @@ class PathCommands { if (path[path.length - 1] === 0) { throw new Error( - `Cannot merge the node at path ${path} with the previous sibling because there isn't one.` + `Cannot merge the node at path [${path}] with the previous sibling because there isn't one.` ) } @@ -135,7 +136,9 @@ class PathCommands { }) } else { throw new Error( - `Cannot merge the node at path ${path} with the previous sibling because it is not the same kind: ${node} ${prevNode}` + `Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify( + node + )} ${JSON.stringify(prevNode)}` ) } } @@ -146,25 +149,24 @@ class PathCommands { moveNodeAtPath(this: Editor, path: Path, newPath: Path): void { const { value } = this - const prevPath = Path.previous(path) const parentPath = Path.parent(path) const newIndex = newPath[newPath.length - 1] if (!Node.has(value, path)) { throw new Error( - `Cannot move the node at path ${path} because it does not exist.` + `Cannot move the node at path [${path}] because it does not exist.` ) } if (!Node.has(value, parentPath)) { throw new Error( - `Cannot move the node at path ${path} to the new parent at path ${parentPath} because the parent does not exist.` + `Cannot move the node at path [${path}] to the new parent at path [${parentPath}] because the parent does not exist.` ) } - if (newIndex !== 0 && !Node.has(value, prevPath)) { + if (newIndex !== 0 && !Node.has(value, Path.previous(newPath))) { throw new Error( - `Cannot move the node at path ${path} to ${newPath} because the index is out of range.` + `Cannot move the node at path [${path}] to new path [${newPath}] because the index is out of range.` ) } @@ -302,6 +304,17 @@ class PathCommands { this.apply({ type: 'remove_node', path: parentPath, node: parent }) } + /** + * Replace a mark on the text node at a path. + */ + + replaceMarkAtPath(this: Editor, path: Path, before: Mark, after: Mark): void { + this.withoutNormalizing(() => { + this.removeMarkAtPath(path, before) + this.addMarkAtPath(path, after) + }) + } + /** * Replace the node at a path with a new node. */ @@ -314,59 +327,16 @@ class PathCommands { } /** - * Set new properties on the node at a path. + * Replace all of the text in a node at a path. */ - setNodeAtPath(this: Editor, path: Path, props: {}): void { - if (path.length === 0) { - this.setValue(props) - return - } - - const { value } = this - const node = Node.get(value, path) - const newProps = {} - const oldProps = {} - let isChange = true - - for (const k in props) { - // Disallow setting restricted properties that should use the editor - // methods that result in more semantic operations being applied. - if (Element.isElement(node) && k === 'nodes') { - throw new Error( - `Cannot set the \`nodes\` property of an element node at path ${path}. You must use the node-specific editor methods instead like \`editor.insertNodeAtPath\`, \`editor.removeNodeAtPath\`, etc.` - ) - } - - if (Text.isText(node) && k === 'text') { - throw new Error( - `Cannot set the \`text\` property of a text node at path ${path}. You must use the text-specific editor methods instead like \`editor.insertTextAtPath\`, \`editor.removeTextAtPath\`, etc.` - ) - } - - if (Text.isText(node) && k === 'marks') { - throw new Error( - `Cannot set the \`marks\` property of a text node at path ${path}. You must use the text-specific editor methods instead like \`editor.addMarkAtPath\`, \`editor.removeMarkAtPath\`, etc.` - ) - } - - if (props[k] !== node[k]) { - isChange = true - newProps[k] = props[k] - oldProps[k] = node[k] - } - } - - // PERF: If no properties have changed don't apply an operation at all. - if (!isChange) { - return - } - - this.apply({ - type: 'set_node', - path, - properties: oldProps, - newProperties: newProps, + replaceTextAtPath(this: Editor, path: Path, text: string): void { + this.withoutNormalizing(() => { + const { value } = this + const node = Node.leaf(value, path) + const point = { path, offset: 0 } + this.removeTextAtPoint(point, node.text.length) + this.insertTextAtPoint(point, text) }) } @@ -386,7 +356,9 @@ class PathCommands { if (match == null) { throw new Error( - `Cannot set new properties on mark ${mark} at path ${path} because the mark does not exist.` + `Cannot set new properties on mark ${JSON.stringify( + mark + )} at path [${path}] because the mark does not exist.` ) } @@ -414,27 +386,59 @@ class PathCommands { } /** - * Replace a mark on the text node at a path. + * Set new properties on the node at a path. */ - replaceMarkAtPath(this: Editor, path: Path, before: Mark, after: Mark): void { - this.withoutNormalizing(() => { - this.removeMarkAtPath(path, before) - this.addMarkAtPath(path, after) - }) - } + setNodeAtPath(this: Editor, path: Path, props: {}): void { + if (path.length === 0) { + this.setValue(props) + return + } - /** - * Replace all of the text in a node at a path. - */ + const { value } = this + const node = Node.get(value, path) + const newProps = {} + const oldProps = {} + let isChange = true - replaceTextAtPath(this: Editor, path: Path, text: string): void { - this.withoutNormalizing(() => { - const { value } = this - const node = Node.leaf(value, path) - const point = { path, offset: 0 } - this.removeTextAtPoint(point, node.text.length) - this.insertTextAtPoint(point, text) + for (const k in props) { + // Disallow setting restricted properties that should use the editor + // methods that result in more semantic operations being applied. + if (Element.isElement(node) && k === 'nodes') { + throw new Error( + `Cannot set the \`nodes\` property of an element node at path [${path}]. You must use the node-specific editor methods instead like \`editor.insertNodeAtPath\`, \`editor.removeNodeAtPath\`, etc.` + ) + } + + if (Text.isText(node) && k === 'text') { + throw new Error( + `Cannot set the \`text\` property of a text node at path [${path}]. You must use the text-specific editor methods instead like \`editor.insertTextAtPath\`, \`editor.removeTextAtPath\`, etc.` + ) + } + + if (Text.isText(node) && k === 'marks') { + throw new Error( + `Cannot set the \`marks\` property of a text node at path [${path}]. You must use the text-specific editor methods instead like \`editor.addMarkAtPath\`, \`editor.removeMarkAtPath\`, etc.` + ) + } + + if (props[k] !== node[k]) { + isChange = true + newProps[k] = props[k] + oldProps[k] = node[k] + } + } + + // PERF: If no properties have changed don't apply an operation at all. + if (!isChange) { + return + } + + this.apply({ + type: 'set_node', + path, + properties: oldProps, + newProperties: newProps, }) } @@ -454,7 +458,7 @@ class PathCommands { options: { target?: number } = {} ): void { if (path.length === 0) { - throw new Error(`Cannot split the top-level node in the document.`) + throw new Error(`Cannot split the root node.`) } const { target = null } = options @@ -480,17 +484,16 @@ class PathCommands { } /** - * Unwrap all of the children of a node, by removing the node and replacing it - * in the tree with its children. + * Removing a node at a path, replacing it with its children. */ - unwrapChildrenAtPath(this: Editor, path: Path): void { + pluckNodeAtPath(this: Editor, path: Path): void { const { value } = this const node = Node.get(value, path) if (Text.isText(node)) { throw new Error( - `Cannot unwrap children from the node at ${path} because it is a text node and has no children.` + `Cannot pluck a node at [${path}] because it is a text node and has no children.` ) } @@ -499,8 +502,8 @@ class PathCommands { const index = path[path.length - 1] for (let i = 0; i < node.nodes.length; i++) { - const targetPath = path.concat(i) - const newPath = parentPath.concat(index + i) + const targetPath = path.concat(0) + const newPath = parentPath.concat(index + i + 1) this.moveNodeAtPath(targetPath, newPath) } @@ -516,7 +519,7 @@ class PathCommands { * node itself. */ - unwrapNodeAtPath(this: Editor, path: Path): void { + liftNodeAtPath(this: Editor, path: Path): void { const { value } = this const parent = Node.parent(value, path) const parentPath = Path.parent(path) diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index f91d9a5be7..4a1c325c58 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -162,7 +162,7 @@ class PointCommands { } this.apply({ - type: 'insert_text', + type: 'remove_text', path, offset, text, diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index d25ffd015f..3d1132a011 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -398,8 +398,10 @@ namespace Path { onp[i] -= 1 } + onp.concat(p.slice(op.length)) + // Retain any indices past the move point in the original path. - onp.push(...p.slice(op.length)) + p.splice(0, op.length, ...onp) } else { if (Path.endsBefore(op, p)) { p[op.length - 1] -= 1 diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 7972717243..c6e21ae88e 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -132,7 +132,7 @@ namespace Value { prev.nodes = prev.nodes.concat(node.nodes) } else { throw new Error( - `Cannot apply a "merge_node" operation at path ${path} to nodes of different interaces: ${node} ${prev}` + `Cannot apply a "merge_node" operation at path [${path}] to nodes of different interaces: ${node} ${prev}` ) } @@ -146,20 +146,28 @@ namespace Value { } case 'move_node': { - const { path } = op + const { path, newPath } = op + + if (Path.isAncestor(path, newPath)) { + throw new Error( + `Cannot move a path [${path}] to new path [${newPath}] because the destination is inside itself.` + ) + } + const node = Node.get(v, path) const parent = Node.parent(v, path) const index = path[path.length - 1] parent.nodes.splice(index, 1) - // This is tricky, but since the `path` and `newPath` both refer to the - // same snapshot in time, after either inserting or removing as the - // first step, the second step's path can be out of date. So instead of - // using the `op.newPath` directly, we transform `op.path` to ascertain - // what the `newPath` would be after the operation was applied. - const newPath = Path.transform(path, op)! - const newParent = Node.parent(v, newPath) - const newIndex = newPath[newPath.length - 1] + // This is tricky, but since the `path` and `newPath` both refer to + // the same snapshot in time, there's a mismatch. After either + // removing the original position, the second step's path can be out + // of date. So instead of using the `op.newPath` directly, we + // transform `op.path` to ascertain what the `newPath` would be after + // the operation was applied. + const truePath = Path.transform(path, op)! + const newParent = Node.parent(v, truePath) + const newIndex = truePath[truePath.length - 1] newParent.nodes.splice(newIndex, 0, node) for (const [point, key, range] of Value.points(v)) { @@ -195,7 +203,6 @@ namespace Value { const parent = Node.parent(v, path) const [, next] = Node.texts(v, { path }) const [, prev] = Node.texts(v, { path, reverse: true }) - parent.nodes.splice(index, 1) // Transform all of the points in the value, but if the point was in the @@ -285,7 +292,7 @@ namespace Value { if (path.length === 0) { throw new Error( - `Cannot apply a "split_node" operation at path ${path} because the top-level value cannot be split.` + `Cannot apply a "split_node" operation at path [${path}] because the top-level value cannot be split.` ) } diff --git a/packages/slate/test/commands/at-path/insert-fragment-by-path/end-of-target.js b/packages/slate/test/commands/at-path/insert-fragment-by-path/end-of-target.js new file mode 100644 index 0000000000..e9e26f2b3f --- /dev/null +++ b/packages/slate/test/commands/at-path/insert-fragment-by-path/end-of-target.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + word + +) + +export const run = editor => { + editor.insertFragmentAtPath( + [1], + + one + two + + ) +} + +export const output = ( + + word + one + two + +) diff --git a/packages/slate/test/commands/at-path/insert-fragment-by-path/middle-of-target.js b/packages/slate/test/commands/at-path/insert-fragment-by-path/middle-of-target.js new file mode 100644 index 0000000000..8b583390b1 --- /dev/null +++ b/packages/slate/test/commands/at-path/insert-fragment-by-path/middle-of-target.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + word + another + +) + +export const run = editor => { + editor.insertFragmentAtPath( + [1], + + one + two + + ) +} + +export const output = ( + + word + one + two + another + +) diff --git a/packages/slate/test/commands/at-path/insert-fragment-by-path/start-of-target.js b/packages/slate/test/commands/at-path/insert-fragment-by-path/start-of-target.js new file mode 100644 index 0000000000..986e29af86 --- /dev/null +++ b/packages/slate/test/commands/at-path/insert-fragment-by-path/start-of-target.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + word + + +) + +export const run = editor => { + editor.insertFragmentAtPath( + [0], + + one + two + + ) +} + +export const output = ( + + one + two + + word + + +) diff --git a/packages/slate/test/commands/at-path/insert-node-by-path/block.js b/packages/slate/test/commands/at-path/insert-node-by-path/block.js new file mode 100644 index 0000000000..d11e6b73b9 --- /dev/null +++ b/packages/slate/test/commands/at-path/insert-node-by-path/block.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + editor.insertNodeAtPath( + [0], + + + + ) +} + +export const output = ( + + + + + + one + + +) diff --git a/packages/slate/test/commands/at-path/insert-node-by-path/inline.js b/packages/slate/test/commands/at-path/insert-node-by-path/inline.js new file mode 100644 index 0000000000..2da3af6f30 --- /dev/null +++ b/packages/slate/test/commands/at-path/insert-node-by-path/inline.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + word + + +) + +export const run = editor => { + editor.insertNodeAtPath( + [0, 0], + + + + ) +} + +export const output = ( + + + + + + + word + + +) diff --git a/packages/slate/test/commands/at-path/insert-node-by-path/text.js b/packages/slate/test/commands/at-path/insert-node-by-path/text.js new file mode 100644 index 0000000000..f04bc06e6a --- /dev/null +++ b/packages/slate/test/commands/at-path/insert-node-by-path/text.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + word + + +) + +export const run = editor => { + editor.insertNodeAtPath([0, 0], another) +} + +export const output = ( + + + anotherword + + +) diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/block.js b/packages/slate/test/commands/at-path/lift-node-by-path/block.js new file mode 100644 index 0000000000..83a42d6fe2 --- /dev/null +++ b/packages/slate/test/commands/at-path/lift-node-by-path/block.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.liftNodeAtPath([0, 0]) +} + +export const input = ( + + + word + + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/first-block.js b/packages/slate/test/commands/at-path/lift-node-by-path/first-block.js new file mode 100644 index 0000000000..14ce4347e7 --- /dev/null +++ b/packages/slate/test/commands/at-path/lift-node-by-path/first-block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.liftNodeAtPath([0, 0]) +} + +export const input = ( + + + one + two + + +) + +export const output = ( + + one + + two + + +) diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/last-block.js b/packages/slate/test/commands/at-path/lift-node-by-path/last-block.js new file mode 100644 index 0000000000..e7de9be845 --- /dev/null +++ b/packages/slate/test/commands/at-path/lift-node-by-path/last-block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.liftNodeAtPath([0, 1]) +} + +export const input = ( + + + one + two + + +) + +export const output = ( + + + one + + two + +) diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/middle-block.js b/packages/slate/test/commands/at-path/lift-node-by-path/middle-block.js new file mode 100644 index 0000000000..9b8291c5fd --- /dev/null +++ b/packages/slate/test/commands/at-path/lift-node-by-path/middle-block.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.liftNodeAtPath([0, 1]) +} + +export const input = ( + + + one + two + three + + +) + +export const output = ( + + + one + + two + + three + + +) diff --git a/packages/slate/test/commands/at-path/merge-node-by-path/block.js b/packages/slate/test/commands/at-path/merge-node-by-path/block.js new file mode 100644 index 0000000000..b88e7ffb1e --- /dev/null +++ b/packages/slate/test/commands/at-path/merge-node-by-path/block.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + editor.mergeNodeAtPath([1]) +} + +export const output = ( + + onetwo + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/block.js b/packages/slate/test/commands/at-path/move-node-by-path/block.js new file mode 100644 index 0000000000..fd81dcac9f --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + two + +) + +export const run = editor => { + editor.moveNodeAtPath([0], [1]) +} + +export const output = ( + + two + + one + + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/inline.js b/packages/slate/test/commands/at-path/move-node-by-path/inline.js new file mode 100644 index 0000000000..8ffc2a7592 --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/inline.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + + one + + + two + + + +) + +export const run = editor => { + editor.moveNodeAtPath([0, 1], [0, 3]) +} + +export const output = ( + + + + two + + + one + + + + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/inside-next.js b/packages/slate/test/commands/at-path/move-node-by-path/inside-next.js new file mode 100644 index 0000000000..27f7038001 --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/inside-next.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + editor.moveNodeAtPath([0], [1, 1]) +} + +export const output = ( + + + two + + one + + + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/nested.js b/packages/slate/test/commands/at-path/move-node-by-path/nested.js new file mode 100644 index 0000000000..17c7e814f6 --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/nested.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + editor.moveNodeAtPath([0, 0], [1, 0]) +} + +export const output = ( + + + + + + one + two + + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/noop-equal.js b/packages/slate/test/commands/at-path/move-node-by-path/noop-equal.js new file mode 100644 index 0000000000..406cc269e7 --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/noop-equal.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + 1 + 2 + +) + +export const run = editor => { + editor.moveNodeAtPath([1], [1]) +} + +export const output = ( + + 1 + 2 + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/sibling-swap.js b/packages/slate/test/commands/at-path/move-node-by-path/sibling-swap.js new file mode 100644 index 0000000000..fd81dcac9f --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/sibling-swap.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + two + +) + +export const run = editor => { + editor.moveNodeAtPath([0], [1]) +} + +export const output = ( + + two + + one + + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/text-nodes.js b/packages/slate/test/commands/at-path/move-node-by-path/text-nodes.js new file mode 100644 index 0000000000..1f4e009ba0 --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/text-nodes.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + + two + + +) + +export const run = editor => { + editor.moveNodeAtPath([0, 0], [1, 0]) +} + +export const output = ( + + + + + + onetwo + + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/text.js b/packages/slate/test/commands/at-path/move-node-by-path/text.js new file mode 100644 index 0000000000..257d0268ba --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/text.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + editor.moveNodeAtPath([1, 0], [0, 1]) +} + +export const output = ( + + onetwo + + + + +) diff --git a/packages/slate/test/commands/at-path/move-node-by-path/to-sibling.js b/packages/slate/test/commands/at-path/move-node-by-path/to-sibling.js new file mode 100644 index 0000000000..27f7038001 --- /dev/null +++ b/packages/slate/test/commands/at-path/move-node-by-path/to-sibling.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + editor.moveNodeAtPath([0], [1, 1]) +} + +export const output = ( + + + two + + one + + + +) diff --git a/packages/slate/test/commands/at-path/pluck-node-by-path/block-multiple.js b/packages/slate/test/commands/at-path/pluck-node-by-path/block-multiple.js new file mode 100644 index 0000000000..223d8f6445 --- /dev/null +++ b/packages/slate/test/commands/at-path/pluck-node-by-path/block-multiple.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.pluckNodeAtPath([0]) +} + +export const input = ( + + + one + two + + +) + +export const output = ( + + one + two + +) diff --git a/packages/slate/test/commands/at-path/pluck-node-by-path/block.js b/packages/slate/test/commands/at-path/pluck-node-by-path/block.js new file mode 100644 index 0000000000..d5e20a3f40 --- /dev/null +++ b/packages/slate/test/commands/at-path/pluck-node-by-path/block.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.pluckNodeAtPath([0]) +} + +export const input = ( + + + word + + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/block.js b/packages/slate/test/commands/at-path/remove-node-by-path/block.js new file mode 100644 index 0000000000..e1ed811fc1 --- /dev/null +++ b/packages/slate/test/commands/at-path/remove-node-by-path/block.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + editor.removeNodeAtPath([1]) +} + +export const output = ( + + one + +) diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/inline.js b/packages/slate/test/commands/at-path/remove-node-by-path/inline.js new file mode 100644 index 0000000000..1297e6a96e --- /dev/null +++ b/packages/slate/test/commands/at-path/remove-node-by-path/inline.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + one + + + +) + +export const run = editor => { + editor.removeNodeAtPath([0, 1]) +} + +export const output = ( + + + + + +) diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/selection-inside.js b/packages/slate/test/commands/at-path/remove-node-by-path/selection-inside.js new file mode 100644 index 0000000000..e1e9d395aa --- /dev/null +++ b/packages/slate/test/commands/at-path/remove-node-by-path/selection-inside.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + + + two + + + +) + +export const run = editor => { + editor.removeNodeAtPath([1, 0]) +} + +export const output = ( + + + one + + + + + +) diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/text.js b/packages/slate/test/commands/at-path/remove-node-by-path/text.js new file mode 100644 index 0000000000..9e0a385c0e --- /dev/null +++ b/packages/slate/test/commands/at-path/remove-node-by-path/text.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeNodeAtPath([0, 0]) +} + +export const input = ( + + + one + + +) + +export const output = ( + + + + + +) diff --git a/packages/slate/test/commands/at-path/replace-node-by-path/block.js b/packages/slate/test/commands/at-path/replace-node-by-path/block.js new file mode 100644 index 0000000000..3c948215f3 --- /dev/null +++ b/packages/slate/test/commands/at-path/replace-node-by-path/block.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.replaceNodeAtPath([1], another) +} + +export const input = ( + + one + two + +) + +export const output = ( + + one + another + +) diff --git a/packages/slate/test/commands/at-path/replace-node-by-path/inline.js b/packages/slate/test/commands/at-path/replace-node-by-path/inline.js new file mode 100644 index 0000000000..a5544b101e --- /dev/null +++ b/packages/slate/test/commands/at-path/replace-node-by-path/inline.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.replaceNodeAtPath([0, 1], another) +} + +export const input = ( + + + one + two + three + + +) + +export const output = ( + + + one + another + three + + +) diff --git a/packages/slate/test/commands/at-path/replace-node-by-path/text.js b/packages/slate/test/commands/at-path/replace-node-by-path/text.js new file mode 100644 index 0000000000..fe2c4e6636 --- /dev/null +++ b/packages/slate/test/commands/at-path/replace-node-by-path/text.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.replaceNodeAtPath([1, 0], three) +} + +export const input = ( + + one + two + +) + +export const output = ( + + one + three + +) diff --git a/packages/slate/test/commands/at-path/replace-text-by-path/basic.js b/packages/slate/test/commands/at-path/replace-text-by-path/basic.js new file mode 100644 index 0000000000..0d1c6c40e5 --- /dev/null +++ b/packages/slate/test/commands/at-path/replace-text-by-path/basic.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.replaceTextAtPath([0, 0], 'two') +} + +export const input = ( + + + one + + +) + +export const output = ( + + + two + + +) diff --git a/packages/slate/test/commands/at-path/set-mark-by-path/basic.js b/packages/slate/test/commands/at-path/set-mark-by-path/basic.js new file mode 100644 index 0000000000..e32a2cd7ce --- /dev/null +++ b/packages/slate/test/commands/at-path/set-mark-by-path/basic.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setMarkAtPath( + [0, 0], + { + key: 'a', + }, + { + key: 'b', + } + ) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/at-path/set-node-by-path/block.js b/packages/slate/test/commands/at-path/set-node-by-path/block.js new file mode 100644 index 0000000000..41172492c2 --- /dev/null +++ b/packages/slate/test/commands/at-path/set-node-by-path/block.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setNodeAtPath([0], { key: 'a' }) +} + +export const input = ( + + word + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/commands/at-path/set-node-by-path/inline.js b/packages/slate/test/commands/at-path/set-node-by-path/inline.js new file mode 100644 index 0000000000..75584eca64 --- /dev/null +++ b/packages/slate/test/commands/at-path/set-node-by-path/inline.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setNodeAtPath([0, 1], { key: 'a' }) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + word + + + +) diff --git a/packages/slate/test/commands/at-path/set-node-by-path/text.js b/packages/slate/test/commands/at-path/set-node-by-path/text.js new file mode 100644 index 0000000000..9c68fec96d --- /dev/null +++ b/packages/slate/test/commands/at-path/set-node-by-path/text.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setNodeAtPath([0, 0], { key: 'a' }) +} + +export const input = ( + + word + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/at-path/split-node-by-path/block.js b/packages/slate/test/commands/at-path/split-node-by-path/block.js new file mode 100644 index 0000000000..1b2468bce1 --- /dev/null +++ b/packages/slate/test/commands/at-path/split-node-by-path/block.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodeAtPath([0], 2) +} + +export const input = ( + + + + one + + two + + + +) + +export const output = ( + + + + one + + + + + two + + + +) diff --git a/packages/slate/test/commands/at-path/split-node-by-path/selection.js b/packages/slate/test/commands/at-path/split-node-by-path/selection.js new file mode 100644 index 0000000000..987624cf5b --- /dev/null +++ b/packages/slate/test/commands/at-path/split-node-by-path/selection.js @@ -0,0 +1,42 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodeAtPath([0], 2) +} + +export const input = ( + + + + + one + + + + two + + + + +) + +export const output = ( + + + + + one + + + + + + + two + + + + +) diff --git a/packages/slate/test/commands/at-path/wrap-node-by-path/block.js b/packages/slate/test/commands/at-path/wrap-node-by-path/block.js new file mode 100644 index 0000000000..930b5b4323 --- /dev/null +++ b/packages/slate/test/commands/at-path/wrap-node-by-path/block.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.wrapNodeAtPath([0], ) +} + +export const input = ( + + word + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/at-path/wrap-node-by-path/text.js b/packages/slate/test/commands/at-path/wrap-node-by-path/text.js new file mode 100644 index 0000000000..8e2b8b5413 --- /dev/null +++ b/packages/slate/test/commands/at-path/wrap-node-by-path/text.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.wrapNodeAtPath([0, 0], ) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js new file mode 100644 index 0000000000..ade8a433ad --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + word + + +) + +export const run = editor => { + editor.insertTextAtPath([0, 0], 4, 'x') +} + +export const output = ( + + + wordx + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js new file mode 100644 index 0000000000..f7f1f7a795 --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 1, 'x') +} + +export const options = { + preserveDecorations: true, +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wxord + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js new file mode 100644 index 0000000000..8c376c34ba --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 2, 'x') +} + +export const options = { + preserveDecorations: true, +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + woxrd + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js new file mode 100644 index 0000000000..466e6de621 --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 4, 'x') +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wordx + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js new file mode 100644 index 0000000000..9ae76376c1 --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 0, 'x') +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + xword + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js new file mode 100644 index 0000000000..440d5e7e1a --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 3, 'x') +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + worxd + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js new file mode 100644 index 0000000000..56e58ff4f4 --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 2, 'x') +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + woxrd + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js new file mode 100644 index 0000000000..e899217724 --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 1, 'x') +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wxord + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js new file mode 100644 index 0000000000..93b9da44f6 --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 4, 'x') +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + word + x + + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js new file mode 100644 index 0000000000..320a05bbcd --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 4, 'x') +} + +export const input = ( + + + word + + +) + +export const output = ( + + wordx + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-middle-with-marks.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-middle-with-marks.js new file mode 100644 index 0000000000..9cc8bf9f8d --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-middle-with-marks.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 2, 'x', [{ type: 'bold' }]) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + woxrd + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js new file mode 100644 index 0000000000..603d4d2fcc --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 2, 'x') +} + +export const input = ( + + + word + + +) + +export const output = ( + + woxrd + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js new file mode 100644 index 0000000000..6e47e54cca --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 0, 'a') +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + a + word + + + + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js new file mode 100644 index 0000000000..2121bbe839 --- /dev/null +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertTextAtPath([0, 0], 0, 'a') +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + aword + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js b/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js new file mode 100644 index 0000000000..c56d220539 --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + one + a + two + + + +) + +export const run = editor => { + editor.removeTextAtPath([0, 2], 0, 1) +} + +export const output = ( + + + + one + + two + + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js new file mode 100644 index 0000000000..a70ba4b8af --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 3, 1) +} + +export const options = { + preserveDecorations: true, +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wor + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js new file mode 100644 index 0000000000..63b207cacb --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 0, 1) +} + +export const options = { + preserveDecorations: true, +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + ord + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js new file mode 100644 index 0000000000..cb0e6e6d3b --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 2, 1) +} + +export const options = { + preserveDecorations: true, +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + wod + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js new file mode 100644 index 0000000000..9e75d947e2 --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 1, 0], 0, 1) +} + +export const input = ( + + + + + a + + + + +) + +export const output = ( + + + + + + + + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js new file mode 100644 index 0000000000..ba6be8460b --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 1, 1, 0], 0, 1) +} + +export const input = ( + + + + + + + + a + + + + + + + +) + +export const output = ( + + + + + + + + + + + + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js new file mode 100644 index 0000000000..e1682182ce --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 1, 0], 0, 1) +} + +export const input = ( + + + + + + a + + + + + +) + +export const output = ( + + + + + + + + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline.js new file mode 100644 index 0000000000..613e1ae3b6 --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 1, 0], 3, 1) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + wor + + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js b/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js new file mode 100644 index 0000000000..a5ac729f7d --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 2], 0, 1) +} + +export const input = ( + + + + one + a + + + + +) + +export const output = ( + + + + one + + + + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js b/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js new file mode 100644 index 0000000000..8a9d9cd1a4 --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 2], 0, 1) +} + +export const input = ( + + + + + a + two + + + +) + +export const output = ( + + + + + + two + + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js new file mode 100644 index 0000000000..b19a92cca0 --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 3, 1) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wor + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js new file mode 100644 index 0000000000..2bb4b2dcf9 --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 0, 1) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + ord + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js new file mode 100644 index 0000000000..89cb92a670 --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 2, 1) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wod + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js new file mode 100644 index 0000000000..25c1e1c12a --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 2, 1) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wod + + +) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/text.js b/packages/slate/test/commands/at-point/remove-text-by-path/text.js new file mode 100644 index 0000000000..cc5195effe --- /dev/null +++ b/packages/slate/test/commands/at-point/remove-text-by-path/text.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeTextAtPath([0, 0], 3, 1) +} + +export const input = ( + + + word + + +) + +export const output = ( + + wor + +) diff --git a/packages/slate/test/commands/at-point/replace-text-by-path/replace.js b/packages/slate/test/commands/at-point/replace-text-by-path/replace.js new file mode 100644 index 0000000000..781e3f7e5f --- /dev/null +++ b/packages/slate/test/commands/at-point/replace-text-by-path/replace.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.replaceTextAtPath([0, 0], 3, 1, 'three') +} + +export const input = ( + + + + onetwo + + + +) + +export const output = ( + + + + onethreewo + + + +) diff --git a/packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js b/packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js new file mode 100644 index 0000000000..0ef2ab5189 --- /dev/null +++ b/packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.replaceTextAtPath([0, 1], 0, 1, 'three', ['italic']) +} + +export const input = ( + + + + one + + two + + + + +) + +export const output = ( + + + + one + three + + wo + + + + +) diff --git a/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js b/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js index 68e1a616d2..62d0291129 100644 --- a/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js +++ b/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { const { value: { document } } = editor const point = document.createPoint({ path: [0, 0], offset: 2 }) editor.splitNodeAtPoint(point, [0]) @@ -10,25 +10,25 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + wo - - + + rd - - + + ) diff --git a/packages/slate/test/commands/at-point/split-node-at-point/block.js b/packages/slate/test/commands/at-point/split-node-at-point/block.js index 4bd836d9b2..d76c980d9d 100644 --- a/packages/slate/test/commands/at-point/split-node-at-point/block.js +++ b/packages/slate/test/commands/at-point/split-node-at-point/block.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { const { value: { document } } = editor const point = document.createPoint({ path: [0, 0], offset: 2 }) editor.splitNodeAtPoint(point, [0]) @@ -10,19 +10,19 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - wo - rd - + + wo + rd + ) diff --git a/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js b/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js index 611f4e8179..bc9b8dfe2d 100644 --- a/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js +++ b/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js @@ -2,9 +2,9 @@ import { Point, Range } from 'slate' -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { const { value: { document } } = editor const [firstText, firstPath] = document.firstText() const point = Point.create({ key: firstText.key, offset: 2, path: firstPath }) @@ -14,24 +14,24 @@ export default function(editor) { export const input = ( - - - + + + onetwo - - - + + + ) export const output = ( - - - + + + etwo - - - + + + ) diff --git a/packages/slate/test/commands/by-path/insert-fragment-by-path/end-of-target.js b/packages/slate/test/commands/by-path/insert-fragment-by-path/end-of-target.js deleted file mode 100644 index ea63b917f9..0000000000 --- a/packages/slate/test/commands/by-path/insert-fragment-by-path/end-of-target.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertFragmentByPath( - [1], - - one - two - - ) -} - -export const input = ( - - - word - - -) - -export const output = ( - - - word - one - two - - -) diff --git a/packages/slate/test/commands/by-path/insert-fragment-by-path/middle-of-target.js b/packages/slate/test/commands/by-path/insert-fragment-by-path/middle-of-target.js deleted file mode 100644 index c6c630da80..0000000000 --- a/packages/slate/test/commands/by-path/insert-fragment-by-path/middle-of-target.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertFragmentByPath( - [1], - - one - two - - ) -} - -export const input = ( - - - word - another - - -) - -export const output = ( - - - word - one - two - another - - -) diff --git a/packages/slate/test/commands/by-path/insert-fragment-by-path/start-of-target.js b/packages/slate/test/commands/by-path/insert-fragment-by-path/start-of-target.js deleted file mode 100644 index c26ccf3d78..0000000000 --- a/packages/slate/test/commands/by-path/insert-fragment-by-path/start-of-target.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertFragmentByPath( - [0], - - one - two - - ) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - one - two - - word - - - -) diff --git a/packages/slate/test/commands/by-path/insert-node-by-path/block.js b/packages/slate/test/commands/by-path/insert-node-by-path/block.js deleted file mode 100644 index 1e45d87f6e..0000000000 --- a/packages/slate/test/commands/by-path/insert-node-by-path/block.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Block } from 'slate' - -export default function(editor) { - editor.insertNodeByPath([0], Block.create('paragraph')) -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - - one - - - -) diff --git a/packages/slate/test/commands/by-path/insert-node-by-path/inline.js b/packages/slate/test/commands/by-path/insert-node-by-path/inline.js deleted file mode 100644 index 425e6ec08c..0000000000 --- a/packages/slate/test/commands/by-path/insert-node-by-path/inline.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { Inline } from 'slate' - -export default function(editor) { - editor.insertNodeByPath([0, 0], Inline.create('emoji')) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - word - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-after-atomic.js deleted file mode 100644 index a5db353e78..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/decoration-after-atomic.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 4, 'x') -} - -export const options = { - preserveDecorations: true, -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wordx - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-before-atomic.js deleted file mode 100644 index 19bf659d6e..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/decoration-before-atomic.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 1, 'x') -} - -export const options = { - preserveDecorations: true, -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wxord - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/by-path/insert-text-by-path/decoration-middle-atomic.js deleted file mode 100644 index 42dccf5ca2..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/decoration-middle-atomic.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 2, 'x') -} - -export const options = { - preserveDecorations: true, -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - woxrd - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/selection-after.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-after.js deleted file mode 100644 index ea3fa19e77..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/selection-after.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 4, 'x') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wordx - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/selection-before.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-before.js deleted file mode 100644 index 50ca1145d6..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/selection-before.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 0, 'x') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - xword - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/selection-end.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-end.js deleted file mode 100644 index be11f8392e..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/selection-end.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 3, 'x') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - worxd - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/selection-middle.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-middle.js deleted file mode 100644 index 17cf47a9e3..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/selection-middle.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 2, 'x') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - woxrd - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/selection-start.js b/packages/slate/test/commands/by-path/insert-text-by-path/selection-start.js deleted file mode 100644 index da3696d5ee..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/selection-start.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 1, 'x') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wxord - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js deleted file mode 100644 index 6152576771..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-end-with-marks.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 4, 'x') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - word - x - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-end.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-end.js deleted file mode 100644 index c58803edcd..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-end.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 4, 'x') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - wordx - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-middle-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-middle-with-marks.js deleted file mode 100644 index 5430d29389..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-middle-with-marks.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 2, 'x', [{ type: 'bold' }]) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - woxrd - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-middle.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-middle.js deleted file mode 100644 index 3f21253722..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-middle.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 2, 'x') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - woxrd - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js deleted file mode 100644 index 90199e16c5..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-start-with-marks.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 0, 'a') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - a - word - - - - -) diff --git a/packages/slate/test/commands/by-path/insert-text-by-path/text-start.js b/packages/slate/test/commands/by-path/insert-text-by-path/text-start.js deleted file mode 100644 index 217d1e3c4e..0000000000 --- a/packages/slate/test/commands/by-path/insert-text-by-path/text-start.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.insertTextByPath([0, 0], 0, 'a') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - aword - - - -) diff --git a/packages/slate/test/commands/by-path/merge-node-by-path/block.js b/packages/slate/test/commands/by-path/merge-node-by-path/block.js deleted file mode 100644 index 7c8f423b9c..0000000000 --- a/packages/slate/test/commands/by-path/merge-node-by-path/block.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.mergeNodeByPath([1]) -} - -export const input = ( - - - one - two - - -) - -export const output = ( - - - onetwo - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/block.js b/packages/slate/test/commands/by-path/move-node-by-path/block.js deleted file mode 100644 index 2286e6a7ec..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/block.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.moveNodeByPath([0], [1]) -} - -export const input = ( - - - - one - - two - - -) - -export const output = ( - - - two - - one - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/inline.js b/packages/slate/test/commands/by-path/move-node-by-path/inline.js deleted file mode 100644 index 9912480162..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/inline.js +++ /dev/null @@ -1,39 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.moveNodeByPath([0, 1], [0, 3]) -} - -export const input = ( - - - - - - one - - - two - - - - -) - -export const output = ( - - - - - two - - - one - - - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/inside-next.js b/packages/slate/test/commands/by-path/move-node-by-path/inside-next.js deleted file mode 100644 index 37235dac8a..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/inside-next.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export default function(editor) { - editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1, 1])) -} - -export const input = ( - - - - one - - - two - - - -) - -export const output = ( - - - - two - - one - - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/nested.js b/packages/slate/test/commands/by-path/move-node-by-path/nested.js deleted file mode 100644 index 44ec5b7bcd..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/nested.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export default function(editor) { - editor.moveNodeByPath(PathUtils.create([0, 0]), PathUtils.create([1, 0])) -} - -export const input = ( - - - - one - - - two - - - -) - -export const output = ( - - - - - one - two - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js b/packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js deleted file mode 100644 index c4c4e7f059..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/noop-equal.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export default function(editor) { - editor.moveNodeByPath(PathUtils.create([1]), PathUtils.create([1])) -} - -export const input = ( - - - 1 - 2 - - -) - -export const output = input diff --git a/packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js b/packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js deleted file mode 100644 index f9d8f1a105..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/noop-inside.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export default function(editor) { - editor.moveNodeByPath(PathUtils.create([1]), PathUtils.create([1, 0])) -} - -export const input = ( - - - 1 - 2 - - -) - -export const output = input diff --git a/packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js b/packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js deleted file mode 100644 index bcd209ecc0..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/sibling-swap.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export default function(editor) { - editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1])) -} - -export const input = ( - - - - one - - two - - -) - -export const output = ( - - - two - - one - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js b/packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js deleted file mode 100644 index d5f339798b..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/text-nodes.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' -import { PathUtils } from 'slate' - -export default function(editor) { - editor.moveNodeByPath(PathUtils.create([0, 0]), PathUtils.create([1, 0])) -} - -export const input = ( - - - one - - two - - - -) - -export const output = ( - - - - - onetwo - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/text.js b/packages/slate/test/commands/by-path/move-node-by-path/text.js deleted file mode 100644 index cfe8ebd6e4..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/text.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.moveNodeByPath([1, 0], [0, 1]) -} - -export const input = ( - - - one - two - - -) - -export const output = ( - - - onetwo - - - -) diff --git a/packages/slate/test/commands/by-path/move-node-by-path/to-sibling.js b/packages/slate/test/commands/by-path/move-node-by-path/to-sibling.js deleted file mode 100644 index bb2c0313e8..0000000000 --- a/packages/slate/test/commands/by-path/move-node-by-path/to-sibling.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.moveNodeByPath([0], [1, 1]) -} - -export const input = ( - - - - one - - - two - - - -) - -export const output = ( - - - - two - - one - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-node-by-path/block.js b/packages/slate/test/commands/by-path/remove-node-by-path/block.js deleted file mode 100644 index 119d1f1439..0000000000 --- a/packages/slate/test/commands/by-path/remove-node-by-path/block.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeNodeByPath([1]) -} - -export const input = ( - - - one - two - - -) - -export const output = ( - - - one - - -) diff --git a/packages/slate/test/commands/by-path/remove-node-by-path/inline.js b/packages/slate/test/commands/by-path/remove-node-by-path/inline.js deleted file mode 100644 index 7a44de904a..0000000000 --- a/packages/slate/test/commands/by-path/remove-node-by-path/inline.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeNodeByPath([0, 1]) -} - -export const input = ( - - - - - one - - - two - - -) - -export const output = ( - - - - - - two - - -) diff --git a/packages/slate/test/commands/by-path/remove-node-by-path/selection-inside.js b/packages/slate/test/commands/by-path/remove-node-by-path/selection-inside.js deleted file mode 100644 index a9c2fde90b..0000000000 --- a/packages/slate/test/commands/by-path/remove-node-by-path/selection-inside.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeNodeByPath([1, 0]) -} - -export const input = ( - - - one - - - two - - - - -) - -export const output = ( - - - - one - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-node-by-path/text.js b/packages/slate/test/commands/by-path/remove-node-by-path/text.js deleted file mode 100644 index f36e1215a1..0000000000 --- a/packages/slate/test/commands/by-path/remove-node-by-path/text.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeNodeByPath([0, 0]) -} - -export const input = ( - - - - - one - - - two - - -) - -export const output = ( - - - - - two - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/adjacent-non-void-inlines.js b/packages/slate/test/commands/by-path/remove-text-by-path/adjacent-non-void-inlines.js deleted file mode 100644 index 1acff4e7d4..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/adjacent-non-void-inlines.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 2], 0, 1) -} - -export const input = ( - - - - - one - a - two - - - - -) - -export const output = ( - - - - - one - - two - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-after-atomic.js deleted file mode 100644 index cd500f8a68..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/decoration-after-atomic.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 3, 1) -} - -export const options = { - preserveDecorations: true, -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wor - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-before-atomic.js deleted file mode 100644 index 566a23118e..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/decoration-before-atomic.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 0, 1) -} - -export const options = { - preserveDecorations: true, -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - ord - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/by-path/remove-text-by-path/decoration-middle-atomic.js deleted file mode 100644 index a0b646b193..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/decoration-middle-atomic.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 2, 1) -} - -export const options = { - preserveDecorations: true, -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - wod - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/inline-last-character.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline-last-character.js deleted file mode 100644 index 28f60d1864..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/inline-last-character.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 1, 0], 0, 1) -} - -export const input = ( - - - - - - a - - - - - -) - -export const output = ( - - - - - - - - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/inline-nested-last-character.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline-nested-last-character.js deleted file mode 100644 index 332bd28a80..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/inline-nested-last-character.js +++ /dev/null @@ -1,45 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 1, 1, 0], 0, 1) -} - -export const input = ( - - - - - - - - - a - - - - - - - - -) - -export const output = ( - - - - - - - - - - - - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/inline-void.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline-void.js deleted file mode 100644 index b0bdc186d6..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/inline-void.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 1, 0], 0, 1) -} - -export const input = ( - - - - - - - a - - - - - - -) - -export const output = ( - - - - - - - - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/inline.js b/packages/slate/test/commands/by-path/remove-text-by-path/inline.js deleted file mode 100644 index 854cbc2f33..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/inline.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 1, 0], 3, 1) -} - -export const input = ( - - - - - - word - - - - - -) - -export const output = ( - - - - - wor - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/next-void-inline.js b/packages/slate/test/commands/by-path/remove-text-by-path/next-void-inline.js deleted file mode 100644 index 259e41033b..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/next-void-inline.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 2], 0, 1) -} - -export const input = ( - - - - - one - a - - - - - -) - -export const output = ( - - - - - one - - - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/previous-void-inline.js b/packages/slate/test/commands/by-path/remove-text-by-path/previous-void-inline.js deleted file mode 100644 index 0441200f8b..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/previous-void-inline.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 2], 0, 1) -} - -export const input = ( - - - - - - a - two - - - - -) - -export const output = ( - - - - - - - two - - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/selection-after.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-after.js deleted file mode 100644 index a7cb2f9095..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/selection-after.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 3, 1) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wor - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/selection-before.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-before.js deleted file mode 100644 index 866855a78a..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/selection-before.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 0, 1) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - ord - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/selection-middle.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-middle.js deleted file mode 100644 index ab1fe117bd..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/selection-middle.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 2, 1) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wod - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/selection-start.js b/packages/slate/test/commands/by-path/remove-text-by-path/selection-start.js deleted file mode 100644 index 9856d38c01..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/selection-start.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 2, 1) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wod - - - -) diff --git a/packages/slate/test/commands/by-path/remove-text-by-path/text.js b/packages/slate/test/commands/by-path/remove-text-by-path/text.js deleted file mode 100644 index 85ac9ecbc0..0000000000 --- a/packages/slate/test/commands/by-path/remove-text-by-path/text.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.removeTextByPath([0, 0], 3, 1) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - wor - - -) diff --git a/packages/slate/test/commands/by-path/replace-node-by-path/block.js b/packages/slate/test/commands/by-path/replace-node-by-path/block.js deleted file mode 100644 index 2536c1541d..0000000000 --- a/packages/slate/test/commands/by-path/replace-node-by-path/block.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.replaceNodeByPath([1], { object: 'block', type: 'quote' }) -} - -export const input = ( - - - one - two - - -) - -export const output = ( - - - one - - - -) diff --git a/packages/slate/test/commands/by-path/replace-node-by-path/inline.js b/packages/slate/test/commands/by-path/replace-node-by-path/inline.js deleted file mode 100644 index e95a23fb09..0000000000 --- a/packages/slate/test/commands/by-path/replace-node-by-path/inline.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.replaceNodeByPath([0, 1], { - object: 'inline', - type: 'emoji', - }) -} - -export const input = ( - - - - one - two - three - - - -) - -export const output = ( - - - - one - - three - - - -) diff --git a/packages/slate/test/commands/by-path/replace-node-by-path/text.js b/packages/slate/test/commands/by-path/replace-node-by-path/text.js deleted file mode 100644 index 92c83ac6a3..0000000000 --- a/packages/slate/test/commands/by-path/replace-node-by-path/text.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.replaceNodeByPath([1, 0], { object: 'text', text: 'three' }) -} - -export const input = ( - - - one - two - - -) - -export const output = ( - - - one - three - - -) diff --git a/packages/slate/test/commands/by-path/replace-text-by-path/replace.js b/packages/slate/test/commands/by-path/replace-text-by-path/replace.js deleted file mode 100644 index c225f26732..0000000000 --- a/packages/slate/test/commands/by-path/replace-text-by-path/replace.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.replaceTextByPath([0, 0], 3, 1, 'three') -} - -export const input = ( - - - - onetwo - - - -) - -export const output = ( - - - - onethreewo - - - -) diff --git a/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js b/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js deleted file mode 100644 index ea9888b7b8..0000000000 --- a/packages/slate/test/commands/by-path/replace-text-by-path/with-mark.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.replaceTextByPath([0, 1], 0, 1, 'three', ['italic']) -} - -export const input = ( - - - - one - - two - - - - -) - -export const output = ( - - - - one - three - - wo - - - - -) diff --git a/packages/slate/test/commands/by-path/set-mark-by-path/with-data.js b/packages/slate/test/commands/by-path/set-mark-by-path/with-data.js deleted file mode 100644 index b6d02d0d29..0000000000 --- a/packages/slate/test/commands/by-path/set-mark-by-path/with-data.js +++ /dev/null @@ -1,39 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.setMarkByPath( - [0, 0], - 0, - 2, - { - type: 'bold', - data: { thing: 'value' }, - }, - { - data: { thing: false }, - } - ) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - wo - rd - - - -) diff --git a/packages/slate/test/commands/by-path/set-node-by-path/block.js b/packages/slate/test/commands/by-path/set-node-by-path/block.js deleted file mode 100644 index 23c44cf917..0000000000 --- a/packages/slate/test/commands/by-path/set-node-by-path/block.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.setNodeByPath([0], { - type: 'quote', - data: { thing: false }, - }) -} - -export const input = ( - - - word - - -) - -export const output = ( - - - word - - -) diff --git a/packages/slate/test/commands/by-path/set-node-by-path/inline-with-is-void.js b/packages/slate/test/commands/by-path/set-node-by-path/inline-with-is-void.js deleted file mode 100644 index 94c5c71376..0000000000 --- a/packages/slate/test/commands/by-path/set-node-by-path/inline-with-is-void.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.setNodeByPath([0, 1], 'emoji') -} - -export const input = ( - - - - - - word - - - - - -) - -export const output = ( - - - - - - word - - - - - -) diff --git a/packages/slate/test/commands/by-path/set-node-by-path/string-shorthand.js b/packages/slate/test/commands/by-path/set-node-by-path/string-shorthand.js deleted file mode 100644 index e6a1f929a1..0000000000 --- a/packages/slate/test/commands/by-path/set-node-by-path/string-shorthand.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.setNodeByPath([0], 'quote') -} - -export const input = ( - - - word - - -) - -export const output = ( - - - word - - -) diff --git a/packages/slate/test/commands/by-path/set-text-by-path/set.js b/packages/slate/test/commands/by-path/set-text-by-path/set.js deleted file mode 100644 index 9cc1f2624e..0000000000 --- a/packages/slate/test/commands/by-path/set-text-by-path/set.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.setTextByPath([0, 0], 'two') -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - two - - - -) diff --git a/packages/slate/test/commands/by-path/set-text-by-path/with-mark.js b/packages/slate/test/commands/by-path/set-text-by-path/with-mark.js deleted file mode 100644 index cb0190872d..0000000000 --- a/packages/slate/test/commands/by-path/set-text-by-path/with-mark.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.setTextByPath([0, 0], 'two', ['bold']) -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - two - - - - -) diff --git a/packages/slate/test/commands/by-path/split-node-by-path/block-with-selection.js b/packages/slate/test/commands/by-path/split-node-by-path/block-with-selection.js deleted file mode 100644 index 78510748a2..0000000000 --- a/packages/slate/test/commands/by-path/split-node-by-path/block-with-selection.js +++ /dev/null @@ -1,39 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.splitNodeByPath([0], 2) -} - -export const input = ( - - - - - one - - - two - - - - -) - -export const output = ( - - - - - one - - - - - two - - - - -) diff --git a/packages/slate/test/commands/by-path/split-node-by-path/block.js b/packages/slate/test/commands/by-path/split-node-by-path/block.js deleted file mode 100644 index dcc8eea8c7..0000000000 --- a/packages/slate/test/commands/by-path/split-node-by-path/block.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.splitNodeByPath([0], 2) -} - -export const input = ( - - - - one - two - - - -) - -export const output = ( - - - - one - - - two - - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-block-by-path/single-block.js b/packages/slate/test/commands/by-path/unwrap-block-by-path/single-block.js deleted file mode 100644 index 0426685720..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-block-by-path/single-block.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapBlockByPath([0, 0], 'quote') -} - -export const input = ( - - - - word - - - word - - - -) - -export const output = ( - - - word - - word - - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-children-by-path/block-multiple.js b/packages/slate/test/commands/by-path/unwrap-children-by-path/block-multiple.js deleted file mode 100644 index b9f5d5dbd1..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-children-by-path/block-multiple.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapChildrenByPath([0]) -} - -export const input = ( - - - - one - two - - - -) - -export const output = ( - - - one - two - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-children-by-path/block.js b/packages/slate/test/commands/by-path/unwrap-children-by-path/block.js deleted file mode 100644 index b809e52ed7..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-children-by-path/block.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapChildrenByPath([0]) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - word - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-inline-by-path/single-block.js b/packages/slate/test/commands/by-path/unwrap-inline-by-path/single-block.js deleted file mode 100644 index 0734f8fdd7..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-inline-by-path/single-block.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapInlineByPath([0, 1], 'link') -} - -export const input = ( - - - - wordanother - - - -) - -export const output = ( - - - - wordanother - - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-node-by-path/block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/block.js deleted file mode 100644 index f68249f64e..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-node-by-path/block.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapNodeByPath([0, 0]) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - word - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-node-by-path/first-block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/first-block.js deleted file mode 100644 index 8217a09bf1..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-node-by-path/first-block.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapNodeByPath([0, 0]) -} - -export const input = ( - - - - one - two - - - -) - -export const output = ( - - - one - - two - - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-node-by-path/last-block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/last-block.js deleted file mode 100644 index a2d5801c5d..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-node-by-path/last-block.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapNodeByPath([0, 1]) -} - -export const input = ( - - - - one - two - - - -) - -export const output = ( - - - - one - - two - - -) diff --git a/packages/slate/test/commands/by-path/unwrap-node-by-path/middle-block.js b/packages/slate/test/commands/by-path/unwrap-node-by-path/middle-block.js deleted file mode 100644 index 534aad2409..0000000000 --- a/packages/slate/test/commands/by-path/unwrap-node-by-path/middle-block.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.unwrapNodeByPath([0, 1]) -} - -export const input = ( - - - - one - two - three - - - -) - -export const output = ( - - - - one - - two - - three - - - -) diff --git a/packages/slate/test/commands/by-path/wrap-block-by-path/block.js b/packages/slate/test/commands/by-path/wrap-block-by-path/block.js deleted file mode 100644 index 0be9adb058..0000000000 --- a/packages/slate/test/commands/by-path/wrap-block-by-path/block.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.wrapBlockByPath([0], 'quote') -} - -export const input = ( - - - word - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/by-path/wrap-block-by-path/text.js b/packages/slate/test/commands/by-path/wrap-block-by-path/text.js deleted file mode 100644 index 375971fddd..0000000000 --- a/packages/slate/test/commands/by-path/wrap-block-by-path/text.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import h from '../../../helpers/h' - -export default function(editor) { - editor.wrapBlockByPath([0, 0], 'quote') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/on-selection/blur/basic.js b/packages/slate/test/commands/on-selection/blur/basic.js index 2cc05373e7..d95ab534b4 100644 --- a/packages/slate/test/commands/on-selection/blur/basic.js +++ b/packages/slate/test/commands/on-selection/blur/basic.js @@ -1,25 +1,25 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.blur() } export const input = ( - - + + one - - + + ) export const output = ( - - one - + + one + ) diff --git a/packages/slate/test/commands/on-selection/focus/basic.js b/packages/slate/test/commands/on-selection/focus/basic.js index c812b73a18..a22c25d73d 100644 --- a/packages/slate/test/commands/on-selection/focus/basic.js +++ b/packages/slate/test/commands/on-selection/focus/basic.js @@ -1,25 +1,25 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.focus() } export const input = ( - - one - + + one + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/default.js b/packages/slate/test/commands/on-selection/move-anchor-backward/default.js index e8f50e791f..66266b9984 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js index e6a25108b2..8a2045d7f0 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js index 1ee9c3af79..193e783207 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorBackward(8) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/param.js b/packages/slate/test/commands/on-selection/move-anchor-backward/param.js index 8fd1f57023..cc9c1162ac 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorBackward(3) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/default.js b/packages/slate/test/commands/on-selection/move-anchor-forward/default.js index c101b62e0a..0780525dde 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js index 51b5f08118..3c39503591 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js b/packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js index e22c1128bb..12de63d147 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorForward(8) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/param.js b/packages/slate/test/commands/on-selection/move-anchor-forward/param.js index 782c2d0bbd..9d885421bd 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveAnchorForward(3) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-backward/default.js b/packages/slate/test/commands/on-selection/move-backward/default.js index 3ea3b5aa40..cfcc8577ef 100644 --- a/packages/slate/test/commands/on-selection/move-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-backward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-backward/expanded.js b/packages/slate/test/commands/on-selection/move-backward/expanded.js index 9926bc1442..da098e0c9f 100644 --- a/packages/slate/test/commands/on-selection/move-backward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-backward/expanded.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-backward/param.js b/packages/slate/test/commands/on-selection/move-backward/param.js index 79206535d3..70c51f6288 100644 --- a/packages/slate/test/commands/on-selection/move-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-backward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveBackward(6) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-backward/reversed.js b/packages/slate/test/commands/on-selection/move-backward/reversed.js index 5524964a12..1c13b910e2 100644 --- a/packages/slate/test/commands/on-selection/move-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-backward/reversed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/default.js b/packages/slate/test/commands/on-selection/move-end-backward/default.js index 2402755a77..073d523257 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js index cb9946136e..d64b341932 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js b/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js index dcd163afb3..7bab223835 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndBackward(6) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js index d8c49466f6..b62e65aa28 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndBackward(7) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/param.js b/packages/slate/test/commands/on-selection/move-end-backward/param.js index 6516746d98..2efff1a07a 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndBackward(3) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/reversed.js b/packages/slate/test/commands/on-selection/move-end-backward/reversed.js index bf83a7a94a..4460b21e39 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/reversed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/default.js b/packages/slate/test/commands/on-selection/move-end-forward/default.js index 796dedcbbd..8d4d359dfc 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js index 9de3fa3a4e..a2d7684ad7 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/param.js b/packages/slate/test/commands/on-selection/move-end-forward/param.js index 8433f9de6a..37dd15e9ba 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndForward(3) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/reversed.js b/packages/slate/test/commands/on-selection/move-end-forward/reversed.js index 2680e98807..1ae2138406 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/reversed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveEndForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/default.js b/packages/slate/test/commands/on-selection/move-focus-backward/default.js index 25f5e64522..ae553fcc8e 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js index af91c7df44..45d6efcea0 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js b/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js index 9780661c72..d7119ed1da 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusBackward(10) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/param.js b/packages/slate/test/commands/on-selection/move-focus-backward/param.js index a17daac782..7b7d7d77b3 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusBackward(6) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/default.js b/packages/slate/test/commands/on-selection/move-focus-forward/default.js index 5100dfed6b..67e7032cfe 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js index 6d474b4cdd..e13f2ce6ff 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js index 018f124706..2b0496670d 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusForward(7) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/param.js b/packages/slate/test/commands/on-selection/move-focus-forward/param.js index bdb83b1f8f..d3acbb46b8 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveFocusForward(4) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/default.js b/packages/slate/test/commands/on-selection/move-forward/default.js index 396f0df135..5233abb4c6 100644 --- a/packages/slate/test/commands/on-selection/move-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-forward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/expanded.js b/packages/slate/test/commands/on-selection/move-forward/expanded.js index 633134b5f6..eb7d713901 100644 --- a/packages/slate/test/commands/on-selection/move-forward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-forward/expanded.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/param.js b/packages/slate/test/commands/on-selection/move-forward/param.js index 7c83f7f998..5062a3f1fe 100644 --- a/packages/slate/test/commands/on-selection/move-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-forward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveForward(6) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/reversed.js b/packages/slate/test/commands/on-selection/move-forward/reversed.js index 8f6cf86185..62a587ed8e 100644 --- a/packages/slate/test/commands/on-selection/move-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-forward/reversed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/default.js b/packages/slate/test/commands/on-selection/move-start-backward/default.js index 17c2e58e53..ef61da9829 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js index 39cc5354dd..57461909f8 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/param.js b/packages/slate/test/commands/on-selection/move-start-backward/param.js index 41a8dbd41c..9d8d0e7749 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartBackward(3) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/reversed.js b/packages/slate/test/commands/on-selection/move-start-backward/reversed.js index d02cb02b57..f1c043077e 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/reversed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/default.js b/packages/slate/test/commands/on-selection/move-start-forward/default.js index 5129aed22a..ed0511d579 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/default.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js index 73a3b354f6..70d59cf3dc 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js b/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js index 14daf3ab0e..4629b685ad 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartForward(8) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js index 8e2034d710..9518282686 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartForward(7) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/param.js b/packages/slate/test/commands/on-selection/move-start-forward/param.js index 1613d92fc6..23242e92d0 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/param.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartForward(3) } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/reversed.js b/packages/slate/test/commands/on-selection/move-start-forward/reversed.js index 7280da5fcd..0af4ce3eb0 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/reversed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveStartForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-anchor/already-collapsed.js b/packages/slate/test/commands/on-selection/move-to-anchor/already-collapsed.js index 95cef63edd..d403888545 100644 --- a/packages/slate/test/commands/on-selection/move-to-anchor/already-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-to-anchor/already-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToAnchor() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-anchor/basic.js b/packages/slate/test/commands/on-selection/move-to-anchor/basic.js index 6c13ddb8e1..403b028d8c 100644 --- a/packages/slate/test/commands/on-selection/move-to-anchor/basic.js +++ b/packages/slate/test/commands/on-selection/move-to-anchor/basic.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToAnchor() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-block/end.js b/packages/slate/test/commands/on-selection/move-to-end-of-block/end.js index 7b93cc1247..6778f02137 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-block/end.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-block/end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - + + one + two - - three - + + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js index f96bd52ad5..b0823919e4 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - + + one + two - - three - + + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-block/start.js b/packages/slate/test/commands/on-selection/move-to-end-of-block/start.js index 37a41c2a22..e62d5b77bc 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-block/start.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-block/start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - + + one + two - - three - + + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js index c7672915ec..ab43103095 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfDocument() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js index 619c00f547..eec88b4b58 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfDocument() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js index 9fb25f445e..daeb3d1c23 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfDocument() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js index 30c46b5938..bb820a4c16 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfDocument() } export const input = ( - - one - two - + + one + two + three - - + + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js index 7b977f8650..779ea8e279 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfDocument() } export const input = ( - - + + one - - two - three - + + two + three + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js index 364aa0da4c..6b8e9de346 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfNextBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js index 35a0b55517..74d35fb928 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfNextBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js index 3519ffddf2..a78a9c0e59 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfNextBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js index 654d12c7aa..f472520c0a 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfNextBlock() } export const input = ( - - one - two - + + one + two + three - - + + ) export const output = ( - - one - two - + + one + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js index c7e1ee2cd4..a97f6452b5 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfNextBlock() } export const input = ( - - + + one - - two - three - + + two + three + ) export const output = ( - - one - + + one + two - - three - + + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js index 72b32c6b53..f7f95c0106 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfPreviousBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js index 12d8833e84..e73a82e0a0 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfPreviousBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js index d19a017964..29cf383de9 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfPreviousBlock() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js index 776916ec65..b9fa5853de 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfPreviousBlock() } export const input = ( - - one - two - + + one + two + three - - + + ) export const output = ( - - one - + + one + two - - three - + + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js index d634c10b91..48d2e083f2 100644 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js +++ b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEndOfPreviousBlock() } export const input = ( - - + + one - - two - three - + + two + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end/already-collapsed.js b/packages/slate/test/commands/on-selection/move-to-end/already-collapsed.js index 0497a15ca0..f22091478d 100644 --- a/packages/slate/test/commands/on-selection/move-to-end/already-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-to-end/already-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEnd() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end/basic.js b/packages/slate/test/commands/on-selection/move-to-end/basic.js index 7ba9601d98..3ac11d6319 100644 --- a/packages/slate/test/commands/on-selection/move-to-end/basic.js +++ b/packages/slate/test/commands/on-selection/move-to-end/basic.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEnd() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end/void.js b/packages/slate/test/commands/on-selection/move-to-end/void.js index f9e0b39276..29a512a097 100644 --- a/packages/slate/test/commands/on-selection/move-to-end/void.js +++ b/packages/slate/test/commands/on-selection/move-to-end/void.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToEnd() } export const input = ( - + - + ) export const output = ( - + {' '} - + ) diff --git a/packages/slate/test/commands/on-selection/move-to-focus/already-collapsed.js b/packages/slate/test/commands/on-selection/move-to-focus/already-collapsed.js index dfa4da9203..24bdd7d622 100644 --- a/packages/slate/test/commands/on-selection/move-to-focus/already-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-to-focus/already-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToFocus() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-focus/basic.js b/packages/slate/test/commands/on-selection/move-to-focus/basic.js index 7eb994cdd5..9e724a7d75 100644 --- a/packages/slate/test/commands/on-selection/move-to-focus/basic.js +++ b/packages/slate/test/commands/on-selection/move-to-focus/basic.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToFocus() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js b/packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js index fa1a2af6a6..2cb5ec6281 100644 --- a/packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js +++ b/packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToRangeOfDocument() } export const input = ( - - + + one - - two - three - + + two + three + ) export const output = ( - - + + one - - two - + + two + three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js index 580d7b69d9..b74189b149 100644 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js +++ b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStartOfDocument() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js index 1eecfe86d4..94d7eb4ded 100644 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js +++ b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStartOfDocument() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js index 0f6b422802..4b024a7865 100644 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js +++ b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStartOfDocument() } export const input = ( - - one - + + one + two - - three - + + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js index 8e19a5f09b..f67872d6b2 100644 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js +++ b/packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStartOfDocument() } export const input = ( - - one - two - + + one + two + three - - + + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js index 88bf21d8da..6ca276c24f 100644 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js +++ b/packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStartOfDocument() } export const input = ( - - + + one - - two - three - + + two + three + ) export const output = ( - - + + one - - two - three - + + two + three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js b/packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js index 3d1788c3f4..9ae5c4ca05 100644 --- a/packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStart() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start/basic.js b/packages/slate/test/commands/on-selection/move-to-start/basic.js index 228f2e75f3..faf9e84d4a 100644 --- a/packages/slate/test/commands/on-selection/move-to-start/basic.js +++ b/packages/slate/test/commands/on-selection/move-to-start/basic.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStart() } export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-to-start/void.js b/packages/slate/test/commands/on-selection/move-to-start/void.js index 19350a6c03..8e415a81b1 100644 --- a/packages/slate/test/commands/on-selection/move-to-start/void.js +++ b/packages/slate/test/commands/on-selection/move-to-start/void.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveToStart() } export const input = ( - + - + ) export const output = ( - + {' '} - + ) diff --git a/packages/slate/test/commands/on-selection/move-word-backward/collapsed.js b/packages/slate/test/commands/on-selection/move-word-backward/collapsed.js index 0829afcf3f..d258b3a020 100644 --- a/packages/slate/test/commands/on-selection/move-word-backward/collapsed.js +++ b/packages/slate/test/commands/on-selection/move-word-backward/collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveWordBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-word-backward/expanded.js b/packages/slate/test/commands/on-selection/move-word-backward/expanded.js index d66413fecd..8837570698 100644 --- a/packages/slate/test/commands/on-selection/move-word-backward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-word-backward/expanded.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveWordBackward() } export const input = ( - - + + one two three four five six - - + + ) export const output = ( - - + + one two three four five six - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-word-backward/reversed.js b/packages/slate/test/commands/on-selection/move-word-backward/reversed.js index 6893f04e6c..30218d775e 100644 --- a/packages/slate/test/commands/on-selection/move-word-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-word-backward/reversed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveWordBackward() } export const input = ( - - + + one two three four five six - - + + ) export const output = ( - - + + one two three four five six - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-word-forward/collapsed.js b/packages/slate/test/commands/on-selection/move-word-forward/collapsed.js index bf8606d0fb..76526e4ee9 100644 --- a/packages/slate/test/commands/on-selection/move-word-forward/collapsed.js +++ b/packages/slate/test/commands/on-selection/move-word-forward/collapsed.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveWordForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-word-forward/expanded.js b/packages/slate/test/commands/on-selection/move-word-forward/expanded.js index e8e918e1c4..3ead686788 100644 --- a/packages/slate/test/commands/on-selection/move-word-forward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-word-forward/expanded.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveWordForward() } export const input = ( - - + + one two three four five six - - + + ) // Should move to next word after focus and collapse export const output = ( - - + + one two three four five six - - + + ) diff --git a/packages/slate/test/commands/on-selection/move-word-forward/reversed.js b/packages/slate/test/commands/on-selection/move-word-forward/reversed.js index 45465dacf2..ea0d70634a 100644 --- a/packages/slate/test/commands/on-selection/move-word-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-word-forward/reversed.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.moveWordForward() } export const input = ( - - + + one two three four five six - - + + ) // Should move to next word after focus and collapse export const output = ( - - + + one two three four five six - - + + ) diff --git a/packages/slate/test/commands/on-selection/select/with-object.js b/packages/slate/test/commands/on-selection/select/with-object.js index a1de73ecde..e2b0a6ef9a 100644 --- a/packages/slate/test/commands/on-selection/select/with-object.js +++ b/packages/slate/test/commands/on-selection/select/with-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { const { value: { document } } = editor const [[node]] = document.texts() @@ -22,20 +22,20 @@ export default function(editor) { export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-selection/select/with-selection.js b/packages/slate/test/commands/on-selection/select/with-selection.js index 7876cec3d9..1bee4fe3ae 100644 --- a/packages/slate/test/commands/on-selection/select/with-selection.js +++ b/packages/slate/test/commands/on-selection/select/with-selection.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { const { value: { document, selection } } = editor const [[node]] = document.texts() @@ -24,20 +24,20 @@ export default function(editor) { export const input = ( - - + + one - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/on-state/set-data/simple.js b/packages/slate/test/commands/on-state/set-data/simple.js index f8b142c925..fb520e28f7 100644 --- a/packages/slate/test/commands/on-state/set-data/simple.js +++ b/packages/slate/test/commands/on-state/set-data/simple.js @@ -1,25 +1,25 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setData({ thing: 'value' }) } export const input = ( - - word - another - + + word + another + ) export const output = ( - - word - another - + + word + another + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/across-blocks.js b/packages/slate/test/commands/with-intent/add-mark/across-blocks.js index 7839eb2462..058284561a 100644 --- a/packages/slate/test/commands/with-intent/add-mark/across-blocks.js +++ b/packages/slate/test/commands/with-intent/add-mark/across-blocks.js @@ -1,37 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wo rd - - + + an other - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/across-inlines.js b/packages/slate/test/commands/with-intent/add-mark/across-inlines.js index 002907bc7d..1e45efdbaa 100644 --- a/packages/slate/test/commands/with-intent/add-mark/across-inlines.js +++ b/packages/slate/test/commands/with-intent/add-mark/across-inlines.js @@ -1,53 +1,53 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + - + word - + - - + + - + another - + - - + + ) export const output = ( - - + + - + wo rd - + - - + + - + an other - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js index 7251a5dcfa..bd769efab3 100644 --- a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js +++ b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word a - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js index 17175f0434..ef21ec3484 100644 --- a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js +++ b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + woa rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js index 9608b93230..ca26f34341 100644 --- a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js +++ b/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + a word - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js b/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js index a7a19f53a2..2f0d155e37 100644 --- a/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js +++ b/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js @@ -1,44 +1,44 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + wo rd - - + + an other - - + + ) export const output = ( - - + + wo rd - - + + an other - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js b/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js index b56edd815e..6fc2ed16a2 100644 --- a/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js +++ b/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js @@ -1,47 +1,47 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wo rd - - + + an other - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/existing-marks.js b/packages/slate/test/commands/with-intent/add-mark/existing-marks.js index 631b6992c4..cb40bec804 100644 --- a/packages/slate/test/commands/with-intent/add-mark/existing-marks.js +++ b/packages/slate/test/commands/with-intent/add-mark/existing-marks.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo @@ -30,7 +30,7 @@ export const output = ( rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/first-character.js b/packages/slate/test/commands/with-intent/add-mark/first-character.js index aa00b1fc5a..acf124f497 100644 --- a/packages/slate/test/commands/with-intent/add-mark/first-character.js +++ b/packages/slate/test/commands/with-intent/add-mark/first-character.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/last-character.js b/packages/slate/test/commands/with-intent/add-mark/last-character.js index ac0147b1b6..6589c0fa8a 100644 --- a/packages/slate/test/commands/with-intent/add-mark/last-character.js +++ b/packages/slate/test/commands/with-intent/add-mark/last-character.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor d - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/middle-character.js b/packages/slate/test/commands/with-intent/add-mark/middle-character.js index babf707514..b13e2d6bc9 100644 --- a/packages/slate/test/commands/with-intent/add-mark/middle-character.js +++ b/packages/slate/test/commands/with-intent/add-mark/middle-character.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w o rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/whole-word.js b/packages/slate/test/commands/with-intent/add-mark/whole-word.js index 356284b8aa..e5ee812249 100644 --- a/packages/slate/test/commands/with-intent/add-mark/whole-word.js +++ b/packages/slate/test/commands/with-intent/add-mark/whole-word.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/with-mark-object.js b/packages/slate/test/commands/with-intent/add-mark/with-mark-object.js index f9a4940db1..08feb50ff0 100644 --- a/packages/slate/test/commands/with-intent/add-mark/with-mark-object.js +++ b/packages/slate/test/commands/with-intent/add-mark/with-mark-object.js @@ -1,10 +1,10 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Mark } from 'slate' -export default function(editor) { +export const run = editor => { editor.addMark( Mark.create({ type: 'bold', @@ -15,23 +15,23 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-mark/with-plain-object.js b/packages/slate/test/commands/with-intent/add-mark/with-plain-object.js index 622ea76355..1c7d8b2e72 100644 --- a/packages/slate/test/commands/with-intent/add-mark/with-plain-object.js +++ b/packages/slate/test/commands/with-intent/add-mark/with-plain-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark({ type: 'bold', data: { thing: 'value' }, @@ -11,23 +11,23 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/across-blocks.js b/packages/slate/test/commands/with-intent/add-marks/across-blocks.js index ab3d133a46..885768a4c1 100644 --- a/packages/slate/test/commands/with-intent/add-marks/across-blocks.js +++ b/packages/slate/test/commands/with-intent/add-marks/across-blocks.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wo rd - - + + an other - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/across-inlines.js b/packages/slate/test/commands/with-intent/add-marks/across-inlines.js index ad2ba8ba0e..551dfd644e 100644 --- a/packages/slate/test/commands/with-intent/add-marks/across-inlines.js +++ b/packages/slate/test/commands/with-intent/add-marks/across-inlines.js @@ -1,61 +1,57 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) } export const input = ( - - - - - word - - - - - - - another - - - - + + + + word + + + + + + + another + + + ) export const output = ( - - - - - wo - - - rd - - - + + + + wo - + + rd + - - + + + + + + + + + + - + an - - - an - - other - - - - + other + + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/across-marks.js b/packages/slate/test/commands/with-intent/add-marks/across-marks.js index 57c508060c..ca46f88a0e 100644 --- a/packages/slate/test/commands/with-intent/add-marks/across-marks.js +++ b/packages/slate/test/commands/with-intent/add-marks/across-marks.js @@ -1,15 +1,15 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['underline']) } export const input = ( - - + + Some{' '} bold @@ -18,15 +18,15 @@ export const input = ( italic - - + + ) export const output = ( - - + + Some{' '} @@ -41,7 +41,7 @@ export const output = ( lic - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js index d43947067c..423437cbcf 100644 --- a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js +++ b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word a - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js index 42e7638024..4a81731b44 100644 --- a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js +++ b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo a rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js index 68ed7f6d2e..69558a16c4 100644 --- a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js +++ b/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + a word - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/first-character.js b/packages/slate/test/commands/with-intent/add-marks/first-character.js index 3132c64e06..f73b91051e 100644 --- a/packages/slate/test/commands/with-intent/add-marks/first-character.js +++ b/packages/slate/test/commands/with-intent/add-marks/first-character.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) } export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/inside-mark.js b/packages/slate/test/commands/with-intent/add-marks/inside-mark.js index 42c79be82d..937f6f754a 100644 --- a/packages/slate/test/commands/with-intent/add-marks/inside-mark.js +++ b/packages/slate/test/commands/with-intent/add-marks/inside-mark.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'underline']) } export const input = ( - - + + word - - + + ) export const output = ( - - + + @@ -32,7 +32,7 @@ export const output = ( rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/last-character.js b/packages/slate/test/commands/with-intent/add-marks/last-character.js index 582a4f45ed..25b9eaf0f2 100644 --- a/packages/slate/test/commands/with-intent/add-marks/last-character.js +++ b/packages/slate/test/commands/with-intent/add-marks/last-character.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor d - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/middle-character.js b/packages/slate/test/commands/with-intent/add-marks/middle-character.js index ede6456c19..5438b19af6 100644 --- a/packages/slate/test/commands/with-intent/add-marks/middle-character.js +++ b/packages/slate/test/commands/with-intent/add-marks/middle-character.js @@ -1,25 +1,25 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) } export const input = ( - - + + word - - + + ) export const output = ( - - + + w @@ -27,7 +27,7 @@ export const output = ( rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/whole-word.js b/packages/slate/test/commands/with-intent/add-marks/whole-word.js index 45c5a461d2..8a1d9745d2 100644 --- a/packages/slate/test/commands/with-intent/add-marks/whole-word.js +++ b/packages/slate/test/commands/with-intent/add-marks/whole-word.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks(['bold', 'italic']) } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/with-mark-object.js b/packages/slate/test/commands/with-intent/add-marks/with-mark-object.js index 3a23de29cd..5a49159a9f 100644 --- a/packages/slate/test/commands/with-intent/add-marks/with-mark-object.js +++ b/packages/slate/test/commands/with-intent/add-marks/with-mark-object.js @@ -1,10 +1,10 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Mark } from 'slate' -export default function(editor) { +export const run = editor => { editor.addMarks([ Mark.create({ type: 'bold', @@ -19,25 +19,25 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/add-marks/with-plain-object.js b/packages/slate/test/commands/with-intent/add-marks/with-plain-object.js index 72d044559d..6344f661c4 100644 --- a/packages/slate/test/commands/with-intent/add-marks/with-plain-object.js +++ b/packages/slate/test/commands/with-intent/add-marks/with-plain-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMarks([ { type: 'bold', @@ -18,25 +18,25 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js index b57ff90dff..881405b4ef 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js +++ b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - + - + - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js index 13acf32749..5dfeddf6cc 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js +++ b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/first-character.js b/packages/slate/test/commands/with-intent/delete-backward/first-character.js index a2ee54c634..6c001ac35c 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/first-character.js +++ b/packages/slate/test/commands/with-intent/delete-backward/first-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-after.js b/packages/slate/test/commands/with-intent/delete-backward/inline-after.js index 42359e0f34..1d05038145 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/inline-after.js +++ b/packages/slate/test/commands/with-intent/delete-backward/inline-after.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - - onetwoa - - + + + onetwoa + + ) export const output = ( - - - one + + + one two - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-before.js b/packages/slate/test/commands/with-intent/delete-backward/inline-before.js index 62c17209a4..bb42489178 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/inline-before.js +++ b/packages/slate/test/commands/with-intent/delete-backward/inline-before.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + a - two + two - - + + ) export const output = ( - - + + - + two - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-end.js b/packages/slate/test/commands/with-intent/delete-backward/inline-end.js index b0947e12c3..183fee82b4 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/inline-end.js +++ b/packages/slate/test/commands/with-intent/delete-backward/inline-end.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - - onetwo + + + onetwo - - + + ) export const output = ( - - - onetw + + + onetw - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-inside.js b/packages/slate/test/commands/with-intent/delete-backward/inline-inside.js index ee4a7e7419..54f1f9fba6 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/inline-inside.js +++ b/packages/slate/test/commands/with-intent/delete-backward/inline-inside.js @@ -1,32 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - - one - a - two - - + + one + a + two + ) export const output = ( - - - one - - - two - - + + one + + + + + two + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js index 6debcd02f2..22a80019fc 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js +++ b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js @@ -1,38 +1,38 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - - onetwo + + + onetwo - - + + - + three - four - - + four + + ) export const output = ( - - - onetwo + + + onetwo - + three - four - - + four + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js index 74d48786fd..5136ac4421 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js +++ b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js index 391e0de754..2e0c17e7fb 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js +++ b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - one - - twothreefour - - + + one + + twothreefour + + ) export const output = ( - - - onetwothreefour - - + + + onetwothreefour + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks.js index 02ffd93dce..1f804318fa 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/join-blocks.js +++ b/packages/slate/test/commands/with-intent/delete-backward/join-blocks.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - word - + + word + another - - + + ) export const output = ( - - + + wordanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js b/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js index ae076d808b..cc57146783 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js +++ b/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - Hello + + Hello world! - + ) export const output = ( - - + + Helloworld! - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js b/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js index bb195d6011..635b8aea9d 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - - word - + + + word + another - - - + + + ) export const output = ( - - - + + + wordanother - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/last-character.js b/packages/slate/test/commands/with-intent/delete-backward/last-character.js index 27f0377fa8..64aa82eaac 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/last-character.js +++ b/packages/slate/test/commands/with-intent/delete-backward/last-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/middle-character.js b/packages/slate/test/commands/with-intent/delete-backward/middle-character.js index 4e1b02ef68..f72a13254f 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/middle-character.js +++ b/packages/slate/test/commands/with-intent/delete-backward/middle-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wrd - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js b/packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js index 0c1c0fb39c..15f02b3e9a 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js +++ b/packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward(3) } export const input = ( - - + + word - - + + ) export const output = ( - - + + w - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js b/packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js index d6fc986ced..4a53764d0d 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js +++ b/packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/single-void-block.js b/packages/slate/test/commands/with-intent/delete-backward/single-void-block.js index a3d1fb79df..82fe98e458 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/single-void-block.js +++ b/packages/slate/test/commands/with-intent/delete-backward/single-void-block.js @@ -1,18 +1,18 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - + {' '} - + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/start-of-document.js b/packages/slate/test/commands/with-intent/delete-backward/start-of-document.js index 0e23061788..b87a5d4cd4 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/start-of-document.js +++ b/packages/slate/test/commands/with-intent/delete-backward/start-of-document.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteBackward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js index c4dc78349f..2c2d2c0844 100644 --- a/packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharBackward() } export const input = ( - - - word📛 - - + + + word📛 + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js index 033a610279..0049e54973 100644 --- a/packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharBackward() } export const input = ( - - - + + + word📛 - - - + + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js index 2989465bbd..703edc2a14 100644 --- a/packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharBackward() } export const input = ( - - - + + + wor📛d - - - + + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js b/packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js index 94f7dd4c9d..36adec6039 100644 --- a/packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js @@ -1,30 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharBackward() } export const input = ( - - - - 📛 - - - + + + 📛 + + ) export const output = ( - - - - - - + + + + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/text-end.js b/packages/slate/test/commands/with-intent/delete-char-backward/text-end.js index 6803158a52..eac59d7cb4 100644 --- a/packages/slate/test/commands/with-intent/delete-char-backward/text-end.js +++ b/packages/slate/test/commands/with-intent/delete-char-backward/text-end.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharBackward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js b/packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js index 112924bc2d..4774397f24 100644 --- a/packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js +++ b/packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharBackward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wod - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/text-start.js b/packages/slate/test/commands/with-intent/delete-char-backward/text-start.js index 77b5fa5159..15d94a853b 100644 --- a/packages/slate/test/commands/with-intent/delete-char-backward/text-start.js +++ b/packages/slate/test/commands/with-intent/delete-char-backward/text-start.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharBackward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js b/packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js index fdf6e04392..041a39690b 100644 --- a/packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharForward() } export const input = ( - - - 📛word - - + + + 📛word + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js index 54f473c71c..d3acc1aba9 100644 --- a/packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharForward() } export const input = ( - - - + + + wo📛rd - - - + + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js b/packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js index c1fc23d83f..4bd48481bb 100644 --- a/packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharForward() } export const input = ( - - - + + + 📛word - - - + + + ) export const output = ( - - + + - word - - + word + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/text-last.js b/packages/slate/test/commands/with-intent/delete-char-forward/text-last.js index d1015aeaea..1dc75799e9 100644 --- a/packages/slate/test/commands/with-intent/delete-char-forward/text-last.js +++ b/packages/slate/test/commands/with-intent/delete-char-forward/text-last.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharForward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js b/packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js index 4492bf3ac2..0975a25c8c 100644 --- a/packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js +++ b/packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharForward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wod - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/text-start.js b/packages/slate/test/commands/with-intent/delete-char-forward/text-start.js index aa032f7603..ce88ea260f 100644 --- a/packages/slate/test/commands/with-intent/delete-char-forward/text-start.js +++ b/packages/slate/test/commands/with-intent/delete-char-forward/text-start.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteCharForward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js b/packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js index fdef4ed5c7..f2c60719d4 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js +++ b/packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js @@ -1,31 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - - onetwo - a - - + + onetwo + a + ) export const output = ( - - - one - two - - - - + + one + two + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js index 14eb1665ce..0610c09341 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js +++ b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + - + - + ) export const output = ( - + - + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js index 4370d44c1b..63278ccd8e 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js +++ b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/end-of-document.js b/packages/slate/test/commands/with-intent/delete-forward/end-of-document.js index 1efa8b0a44..8eef8e345a 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/end-of-document.js +++ b/packages/slate/test/commands/with-intent/delete-forward/end-of-document.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/first-character.js b/packages/slate/test/commands/with-intent/delete-forward/first-character.js index 4eaa7b07d6..465ffd5e69 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/first-character.js +++ b/packages/slate/test/commands/with-intent/delete-forward/first-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js b/packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js index 685312a51c..3d76ecee1d 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js +++ b/packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js @@ -1,31 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - - one - a - two - - + + one + a + two + ) export const output = ( - - - one - - two - - + + one + + + + two + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js index ecc2c9e8bd..df94f4f167 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js +++ b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + word - - + + - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js index 17020811bd..a16d57ca42 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js +++ b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js @@ -1,30 +1,26 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - - one - - - twothreefour - - + + one + + + twothreefour + ) export const output = ( - - - onetwothreefour - - + + onetwothreefour + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-forward/join-blocks.js index c2b159ce07..ac3d28c109 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/join-blocks.js +++ b/packages/slate/test/commands/with-intent/delete-forward/join-blocks.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + word - - another - + + another + ) export const output = ( - - + + wordanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js b/packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js index 7601a8478a..89d74e449c 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - - + + + word - - another - - + + another + + ) export const output = ( - - - + + + wordanother - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/last-character.js b/packages/slate/test/commands/with-intent/delete-forward/last-character.js index 4b064c43a5..a99b19a574 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/last-character.js +++ b/packages/slate/test/commands/with-intent/delete-forward/last-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/middle-character.js b/packages/slate/test/commands/with-intent/delete-forward/middle-character.js index ff46f74a35..1304f759c5 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/middle-character.js +++ b/packages/slate/test/commands/with-intent/delete-forward/middle-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wrd - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js b/packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js index b072f05776..e30d7f927f 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js +++ b/packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward(3) } export const input = ( - - + + word - - + + ) export const output = ( - - + + d - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js b/packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js index 09610e8ce4..bc8254cab5 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js +++ b/packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - + + - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/single-void-block.js b/packages/slate/test/commands/with-intent/delete-forward/single-void-block.js index 5aa4333e5b..c0b1cfead6 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/single-void-block.js +++ b/packages/slate/test/commands/with-intent/delete-forward/single-void-block.js @@ -1,18 +1,18 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - + {' '} - + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js b/packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js index 3b2d842bbe..b197d99eee 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js +++ b/packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js @@ -1,32 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteForward() } export const input = ( - - - one - two - - - + + one + two + + ) // TODO: this output selection seems bad export const output = ( - - - - wo - - - + + + wo + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js index 4eac3d2710..82e83be80d 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineBackward() } export const input = ( - - - one wo📛rd + + + one wo📛rd - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js index 2117ac46fa..7b61e8ff3a 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js @@ -1,15 +1,15 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineBackward() } export const input = ( - - + + 😊 one 😊 @@ -17,17 +17,17 @@ export const input = ( 😀 three - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js index 0d198c9d2b..3908beec98 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineBackward() } export const input = ( - - + + 😊one two three - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/text-end.js b/packages/slate/test/commands/with-intent/delete-line-backward/text-end.js index a590f6af94..37177af149 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/text-end.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/text-end.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/text-start.js b/packages/slate/test/commands/with-intent/delete-line-backward/text-start.js index 4bc9eb2edf..1a314c3638 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/text-start.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/text-start.js @@ -1,19 +1,19 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineBackward() } export const input = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js b/packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js index ae089f93dd..8dc4a97313 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + ee - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js index a4af45b8f7..7d9a8d92f2 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js @@ -1,28 +1,24 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineForward() } export const input = ( - - - - one wo📛rd - - + + + one wo📛rd + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js index 669a13af5d..41b5856b6e 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js @@ -1,15 +1,15 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineForward() } export const input = ( - - + + one 😊 @@ -17,17 +17,17 @@ export const input = ( 😊 three 😀 - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js index d5da2d4664..e59ccbc316 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineForward() } export const input = ( - - + + one two three😊 - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/text-end.js b/packages/slate/test/commands/with-intent/delete-line-forward/text-end.js index 5679ff8bdb..09408d9b59 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/text-end.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/text-end.js @@ -1,19 +1,19 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineForward() } export const input = ( - - + + one two three - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/text-start.js b/packages/slate/test/commands/with-intent/delete-line-forward/text-start.js index 0b29864355..4e725229b0 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/text-start.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/text-start.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js b/packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js index 93bcb6627e..f9cbd1195a 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteLineForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two thr - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js b/packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js index 3afd1a3960..8af168dfda 100644 --- a/packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js @@ -1,27 +1,23 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordBackward() } export const input = ( - - - word📛 - - + + word📛 + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js index 859662a09f..fabd99b3b4 100644 --- a/packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js @@ -1,30 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordBackward() } export const input = ( - - - - wo📛rd - - - + + + wo📛rd + + ) export const output = ( - - - - - - + + + + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js index 498fe79c38..aa91a9908c 100644 --- a/packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js +++ b/packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordBackward() } export const input = ( - - word - + + word + another - - + + ) export const output = ( - - + + wordanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/text-end.js b/packages/slate/test/commands/with-intent/delete-word-backward/text-end.js index 92dc1be8ef..c20d1d0c31 100644 --- a/packages/slate/test/commands/with-intent/delete-word-backward/text-end.js +++ b/packages/slate/test/commands/with-intent/delete-word-backward/text-end.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js b/packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js index 0e45bf385e..3ce94becec 100644 --- a/packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js +++ b/packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordBackward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + one two ee - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js b/packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js index ac602faf29..c556450cef 100644 --- a/packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordForward() } export const input = ( - - + + - word📛 - - + word📛 + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js b/packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js index 780637ea76..444bab1fc2 100644 --- a/packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js +++ b/packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordForward() } export const input = ( - - + + - wo📛rd - - + wo📛rd + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js b/packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js index 2ae78fab12..6e4f9c5af1 100644 --- a/packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js +++ b/packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordForward() } export const input = ( - - + + word - - another - + + another + ) export const output = ( - - + + wordanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js b/packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js index 0db74ee735..887003e602 100644 --- a/packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js +++ b/packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + o two three - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/word-start.js b/packages/slate/test/commands/with-intent/delete-word-forward/word-start.js index 68dc1869a5..9839331133 100644 --- a/packages/slate/test/commands/with-intent/delete-word-forward/word-start.js +++ b/packages/slate/test/commands/with-intent/delete-word-forward/word-start.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.deleteWordForward() } export const input = ( - - + + one two three - - + + ) export const output = ( - - + + two three - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js b/packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js index 9a28589c5c..e5e89fbe88 100644 --- a/packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js +++ b/packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js @@ -1,44 +1,40 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - - - word - - - - - - - another - - - - + + + + word + + + + + + + another + + + ) export const output = ( - - - - wo - - - other - - - - + + + wo + + + other + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/across-blocks.js b/packages/slate/test/commands/with-intent/delete/across-blocks.js index 6b0276cefd..4428c797d4 100644 --- a/packages/slate/test/commands/with-intent/delete/across-blocks.js +++ b/packages/slate/test/commands/with-intent/delete/across-blocks.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + woother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/across-depths.js b/packages/slate/test/commands/with-intent/delete/across-depths.js index 855c24b5dc..1aa0e9b96a 100644 --- a/packages/slate/test/commands/with-intent/delete/across-depths.js +++ b/packages/slate/test/commands/with-intent/delete/across-depths.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - + + + one - - - + + + two - - + + ) export const output = ( - - - + + + onetwo - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/across-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/across-nested-blocks.js index eed09a668a..c05edfa503 100644 --- a/packages/slate/test/commands/with-intent/delete/across-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/delete/across-nested-blocks.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - + + + one - - two - - - + + two + + + three - - four - - + + four + + ) export const output = ( - - - + + + onethree - - - - four - - + + + + four + + ) diff --git a/packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js b/packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js index 2a33fe9a6f..341e06a59d 100644 --- a/packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js +++ b/packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - onetwothree - - + + + onetwothree + + ) export const output = ( - - + + oe - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/all-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/all-nested-blocks.js index 76fb368803..122b42db06 100644 --- a/packages/slate/test/commands/with-intent/delete/all-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/delete/all-nested-blocks.js @@ -1,39 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - + + + one - - - two - - + + + two + + three - - - - - + + + + + ) export const output = ( - - - + + + - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/before-inline-sibling.js b/packages/slate/test/commands/with-intent/delete/before-inline-sibling.js index f2cae192ae..6ec0e68035 100644 --- a/packages/slate/test/commands/with-intent/delete/before-inline-sibling.js +++ b/packages/slate/test/commands/with-intent/delete/before-inline-sibling.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - onetwo + + + onetwo a - - + + ) export const output = ( - - - one + + + one two - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js b/packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js index c48c5bc518..142ed8bc91 100644 --- a/packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js +++ b/packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + wo rd - - + + two - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/first-character.js b/packages/slate/test/commands/with-intent/delete/first-character.js index 4889fa5a93..140bbf956e 100644 --- a/packages/slate/test/commands/with-intent/delete/first-character.js +++ b/packages/slate/test/commands/with-intent/delete/first-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + ) export const output = ( - - + + ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/first-position.js b/packages/slate/test/commands/with-intent/delete/first-position.js index 076680879a..980a2d5150 100644 --- a/packages/slate/test/commands/with-intent/delete/first-position.js +++ b/packages/slate/test/commands/with-intent/delete/first-position.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js index bffde4769c..17abc6d6cb 100644 --- a/packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js +++ b/packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one - - two - + + two + three - - + + ) export const output = ( - - + + three - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js b/packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js index 7717f136be..4d8d010a6c 100644 --- a/packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js +++ b/packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one - - + + two - - + + ) export const output = ( - - + + two - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js b/packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js index 6c84852576..b87faa8847 100644 --- a/packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js +++ b/packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js @@ -1,30 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - one - a - two - - + + one + a + two + ) export const output = ( - - - one - two - - + + one + + + two + ) diff --git a/packages/slate/test/commands/with-intent/delete/inside-inline.js b/packages/slate/test/commands/with-intent/delete/inside-inline.js index 189d6fa27c..c88ff0259c 100644 --- a/packages/slate/test/commands/with-intent/delete/inside-inline.js +++ b/packages/slate/test/commands/with-intent/delete/inside-inline.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - + + + wod - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js b/packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js index 6b0276cefd..4428c797d4 100644 --- a/packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js +++ b/packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + woother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js b/packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js index 2d8595746f..06ed28adc9 100644 --- a/packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js +++ b/packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one - - - twothreefour - - + + + twothreefour + + ) export const output = ( - - - onetwothreefour - - + + + onetwothreefour + + ) diff --git a/packages/slate/test/commands/with-intent/delete/join-blocks.js b/packages/slate/test/commands/with-intent/delete/join-blocks.js index 1f1d874a21..8401a48aae 100644 --- a/packages/slate/test/commands/with-intent/delete/join-blocks.js +++ b/packages/slate/test/commands/with-intent/delete/join-blocks.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wordanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js index 23910db1b1..f71eeea35f 100644 --- a/packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js @@ -1,38 +1,38 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - - + + + + word - - + + another - - - - + + + + ) export const output = ( - - - - + + + + wordanother - - - - + + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/join-nested-blocks.js b/packages/slate/test/commands/with-intent/delete/join-nested-blocks.js index 06e09d25ee..029a926aca 100644 --- a/packages/slate/test/commands/with-intent/delete/join-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/delete/join-nested-blocks.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - + + + word - - + + another - - - + + + ) export const output = ( - - - + + + wordanother - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/last-character.js b/packages/slate/test/commands/with-intent/delete/last-character.js index a33fe1533e..65d05485d9 100644 --- a/packages/slate/test/commands/with-intent/delete/last-character.js +++ b/packages/slate/test/commands/with-intent/delete/last-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/middle-character.js b/packages/slate/test/commands/with-intent/delete/middle-character.js index 6b8debfb4b..100a1b2d34 100644 --- a/packages/slate/test/commands/with-intent/delete/middle-character.js +++ b/packages/slate/test/commands/with-intent/delete/middle-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + ) export const output = ( - - + + wrd - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/nested-block.js b/packages/slate/test/commands/with-intent/delete/nested-block.js index 499fe9f117..e66b8feb94 100644 --- a/packages/slate/test/commands/with-intent/delete/nested-block.js +++ b/packages/slate/test/commands/with-intent/delete/nested-block.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - - middle - + + + middle + another - - - + + + ) export const output = ( - - + + woother - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js index 596f57668d..374e8c94ad 100644 --- a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js +++ b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one - + - two - + two + ) export const output = ( - + - two - + two + ) diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js index 4b2cd5dd25..0462eff862 100644 --- a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js +++ b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one - + - three - + three + ) export const output = ( - - + + on - - three - + + three + ) diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js index 4b2cd5dd25..0462eff862 100644 --- a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js +++ b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one - + - three - + three + ) export const output = ( - - + + on - - three - + + three + ) diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js index bdbabd43b3..18d189fa29 100644 --- a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js +++ b/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one - + - three - + three + ) export const output = ( - - + + on - + - three - + three + ) diff --git a/packages/slate/test/commands/with-intent/delete/non-void-triple.js b/packages/slate/test/commands/with-intent/delete/non-void-triple.js index adf54cde13..6a97ded345 100644 --- a/packages/slate/test/commands/with-intent/delete/non-void-triple.js +++ b/packages/slate/test/commands/with-intent/delete/non-void-triple.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + 1 - - 2 - + + 2 + 3 - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js index 89ff8d78a7..6c13835158 100644 --- a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js +++ b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - one - + one + two - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js index 74c2facffb..70bfeba857 100644 --- a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js +++ b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - one - + one + two - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js index d536b13815..5bc3cec4c5 100644 --- a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js +++ b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - + one - - two - + + two + ) export const output = ( - - + + one - - two - + + two + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js index b724d37141..14050b2eb8 100644 --- a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js +++ b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - + two - - three - + + three + ) export const output = ( - - + + o - - three - + + three + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js index b724d37141..14050b2eb8 100644 --- a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js +++ b/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - + two - - three - + + three + ) export const output = ( - - + + o - - three - + + three + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-only.js b/packages/slate/test/commands/with-intent/delete/void-block-as-only.js index 1fe3d9c58e..5386b69fa2 100644 --- a/packages/slate/test/commands/with-intent/delete/void-block-as-only.js +++ b/packages/slate/test/commands/with-intent/delete/void-block-as-only.js @@ -1,18 +1,18 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js b/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js index 8321662cad..e6d3d5d041 100644 --- a/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js +++ b/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - one - two - + one + two + ) export const output = ( - - + + one - - two - + + two + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js b/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js index b4a0f7e814..afe45571f7 100644 --- a/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js +++ b/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - + - + one - - two - + + two + ) export const output = ( - - + + one - - two - + + two + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js index 5b3bbdc946..d029248f9b 100644 --- a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js +++ b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + one two - - + + three - - + + ) export const output = ( - - + + onethree - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js index 65f48ed6da..504a7859af 100644 --- a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js +++ b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + abc - - + + ) export const output = ( - - + + abc - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js index 245c4e9eca..94b8c0175d 100644 --- a/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js +++ b/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + Hi - - there - + + there + - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/whole-inline.js b/packages/slate/test/commands/with-intent/delete/whole-inline.js index 95e218c2f0..74697485a6 100644 --- a/packages/slate/test/commands/with-intent/delete/whole-inline.js +++ b/packages/slate/test/commands/with-intent/delete/whole-inline.js @@ -1,30 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - - - + + + + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/whole-word-mark.js b/packages/slate/test/commands/with-intent/delete/whole-word-mark.js index 4d8e46f381..128c2e9c61 100644 --- a/packages/slate/test/commands/with-intent/delete/whole-word-mark.js +++ b/packages/slate/test/commands/with-intent/delete/whole-word-mark.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/delete/whole-word.js b/packages/slate/test/commands/with-intent/delete/whole-word.js index 3aaee3addc..df0676da0e 100644 --- a/packages/slate/test/commands/with-intent/delete/whole-word.js +++ b/packages/slate/test/commands/with-intent/delete/whole-word.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.delete() } export const input = ( - - + + word - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/block-end.js b/packages/slate/test/commands/with-intent/insert-block/block-end.js index 896a4a08d9..3707919a33 100644 --- a/packages/slate/test/commands/with-intent/insert-block/block-end.js +++ b/packages/slate/test/commands/with-intent/insert-block/block-end.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock('quote') } export const input = ( - - + + word - - + + ) export const output = ( - - word - + + word + - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/block-middle.js b/packages/slate/test/commands/with-intent/insert-block/block-middle.js index 2f93cf7fdd..093ee325fc 100644 --- a/packages/slate/test/commands/with-intent/insert-block/block-middle.js +++ b/packages/slate/test/commands/with-intent/insert-block/block-middle.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock('quote') } export const input = ( - - + + word - - + + ) export const output = ( - - wo - + + wo + - - rd - + + rd + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/block-start.js b/packages/slate/test/commands/with-intent/insert-block/block-start.js index 1b31d9cb37..74c6870a7a 100644 --- a/packages/slate/test/commands/with-intent/insert-block/block-start.js +++ b/packages/slate/test/commands/with-intent/insert-block/block-start.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock('quote') } export const input = ( - - + + word - - + + ) export const output = ( - - + + - - word - + + word + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/is-empty.js b/packages/slate/test/commands/with-intent/insert-block/is-empty.js index 86692e8d74..b97ffb4953 100644 --- a/packages/slate/test/commands/with-intent/insert-block/is-empty.js +++ b/packages/slate/test/commands/with-intent/insert-block/is-empty.js @@ -1,30 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock('quote') } export const input = ( - - - - - not empty - + + + + not empty ) export const output = ( - - - - - - not empty - + + + + + + + not empty ) diff --git a/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js b/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js index 3ed415febe..2ec2e63cee 100644 --- a/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js +++ b/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js @@ -1,37 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock('quote') } export const input = ( - - - - - - - - - + + + + + + + ) export const output = ( - - - - - - - - - - - + + + + + + + + + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/is-void-end.js b/packages/slate/test/commands/with-intent/insert-block/is-void-end.js index a484aab8a7..62beff7669 100644 --- a/packages/slate/test/commands/with-intent/insert-block/is-void-end.js +++ b/packages/slate/test/commands/with-intent/insert-block/is-void-end.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock('quote') } export const input = ( - + text - text - + text + ) export const output = ( - + text - + - - text - + + text + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/is-void-start.js b/packages/slate/test/commands/with-intent/insert-block/is-void-start.js index 18bf5ed601..a1161424b8 100644 --- a/packages/slate/test/commands/with-intent/insert-block/is-void-start.js +++ b/packages/slate/test/commands/with-intent/insert-block/is-void-start.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock('quote') } export const input = ( - + text - text - + text + ) export const output = ( - - + + - + text - text - + text + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/with-block.js b/packages/slate/test/commands/with-intent/insert-block/with-block.js index a3ab20bf16..8d5cbb638a 100644 --- a/packages/slate/test/commands/with-intent/insert-block/with-block.js +++ b/packages/slate/test/commands/with-intent/insert-block/with-block.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Block } from 'slate' -export default function(editor) { +export const run = editor => { editor.insertBlock(Block.create({ type: 'quote' })) } export const input = ( - - + + word - - + + ) export const output = ( - - + + - - word - + + word + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/with-object.js b/packages/slate/test/commands/with-intent/insert-block/with-object.js index f2999cd718..d66f631d07 100644 --- a/packages/slate/test/commands/with-intent/insert-block/with-object.js +++ b/packages/slate/test/commands/with-intent/insert-block/with-object.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertBlock({ type: 'quote' }) } export const input = ( - - + + word - - + + ) export const output = ( - - + + - - word - + + word + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js b/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js index 371628e95b..9c179e371a 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one - - + + ) } export const input = ( - - + + - - + + ) export const output = ( - - + + one - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-end.js b/packages/slate/test/commands/with-intent/insert-fragment/block-end.js index f7da4747d1..86d34aa985 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/block-end.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-end.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wordfragment - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js index 02221340a8..4885903c2c 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wofragmentrd - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-start.js b/packages/slate/test/commands/with-intent/insert-fragment/block-start.js index 5f3f691738..28ba7bb77a 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/block-start.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/block-start.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + fragmentword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js index fdfa818d28..2d0bcf97fa 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - three - + + one + two + three + ) } export const input = ( - - + + word - - + + ) export const output = ( - - wordone - two - + + wordone + two + three - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/end-block.js index f7da4747d1..86d34aa985 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/end-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/end-block.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wordfragment - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/end-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/end-inline.js index 12329bfe72..682126eadb 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/end-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/end-inline.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - - word + + + word - - + + ) export const output = ( - - - word + + + word fragment - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js index 59d77de82c..03f8a3c619 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js @@ -2,34 +2,34 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - three - + + one + two + three + ) } export const input = ( - - + + word - - + + ) export const output = ( - - wordone - two - + + wordone + two + three - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js index 94d3872768..5a26b90652 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js @@ -3,41 +3,41 @@ import h from '../../../../helpers/h' const fragment = ( - - fragment zero - fragment one - fragment two - + + fragment zero + fragment one + fragment two + ) -export default function(editor) { +export const run = editor => { editor.insertFragment(fragment) } export const input = ( - - zero - + + zero + one - - + + two - - + + ) // TODO: is this the right behavior? export const output = ( - - zero - fragment zero - fragment one - + + zero + fragment zero + fragment one + fragment twotwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js index 7b4b4d41c9..2823f9fcbf 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js @@ -2,34 +2,34 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - three - + + one + two + three + ) } export const input = ( - - + + word - - + + ) export const output = ( - - one - two - + + one + two + threeword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js index 95ef72c090..18f8482619 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one two - - + + ) } export const input = ( - - + + - - + + ) export const output = ( - - + + onetwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js index 49652f5d19..d00d619b43 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one Some inline stuff two - - + + ) } export const input = ( - - + + AB - - + + ) export const output = ( - - + + AoneSome inline stufftwoB - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js index cf03f6846f..90e002c235 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - + + one + two + ) } export const input = ( - - + + word - - + + ) export const output = ( - - woone - + + woone + tword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-marks.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-marks.js index f1679d26b1..4c404dc1be 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-marks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-marks.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + b u i - - + + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo b u @@ -35,7 +35,7 @@ export const output = ( i rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js index 06fb7ce9bb..8706479dc4 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js @@ -1,40 +1,40 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - after quote - + + + one + two + + after quote + ) } export const input = ( - - + + word - - + + ) export const output = ( - - word - - one - two - - + + word + + one + two + + after quote - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js index f150204e46..ed01a7fcb0 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js @@ -1,40 +1,40 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - after quote - + + + one + two + + after quote + ) } export const input = ( - - + + word - - + + ) export const output = ( - - - one - two - - + + + one + two + + after quote - - word - + + word + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js index 1c0b4b1346..85fb93518d 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js @@ -1,39 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - + + + one + two + + ) } export const input = ( - - + + word - - + + ) export const output = ( - - wo - - one - + + wo + + one + two - - - rd - + + + rd + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js index c5f57ae902..cd470f2984 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js @@ -1,37 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + - 2 + 2 - + ) } export const input = ( - + - + 1 - + - + ) export const output = ( - + - + 12 - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-inline.js index 6e23dd4828..1723ee9cee 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-inline.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + bar - - + + ) } export const input = ( - + - + Foobaz - + - + ) export const output = ( - + - + Foo bar baz - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-mark.js b/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-mark.js index bb239535e1..ece06d4594 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-mark.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-mark.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + bar - - + + ) } export const input = ( - + - + Foobaz - + - + ) export const output = ( - + - + Foo bar baz - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js b/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js index 9806eecd65..46f0a44676 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js @@ -1,42 +1,42 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' const fragment = ( - - 1 - 2 - 3 - + + 1 + 2 + 3 + ) -export default function(editor) { +export const run = editor => { editor.insertFragment(fragment) } export const input = ( - - one - + + one + two - - + + three - - + + ) export const output = ( - - one - 1 - 2 - + + one + 1 + 2 + 3three - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js b/packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js index dd11795441..20d7906b92 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js @@ -1,42 +1,42 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' const fragment = ( - - fragment zero - fragment one - fragment two - + + fragment zero + fragment one + fragment two + ) -export default function(editor) { +export const run = editor => { editor.insertFragment(fragment) } export const input = ( - - zero - + + zero + one - - + + two - - + + ) export const output = ( - - zero - fragment zero - fragment one - + + zero + fragment zero + fragment one + fragment twotwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js index 0baadba0c6..3e5cac88dc 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - wo + + + wo fragment - rd - - + rd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js b/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js index 4437ae2815..cf6e3c317c 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + - word - - + word + + ) export const output = ( - - + + fragment - word - - + word + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js index fa36c4a568..7126781d42 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js @@ -2,34 +2,34 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one - Some inline stuff + Some inline stuff two - - + + ) } export const input = ( - - + + AB - - + + ) export const output = ( - - - AoneSome inline stufftwoB - - + + + AoneSome inline stufftwoB + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js index 028d91557e..24cc079b54 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js @@ -2,40 +2,40 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - bar - - + + + bar + + ) } export const input = ( - + - + Foobaz - + - + ) export const output = ( - + - + Foo - + bar - + baz - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js index e98c37ac4e..57408af2dd 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js @@ -2,38 +2,38 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + fragment - - + + ) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - wo + + + wo fragment - rd - - + rd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js index e16fdf3db3..5ca6bf895a 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + two - - + + ) } export const input = ( - - + + one - - + + ) export const output = ( - - + + onetwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js index 629276bbc9..c714be33db 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js @@ -1,39 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + fragment - - + + ) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - wo + + + wo fragment - rd - - + rd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js index fff3b21fe2..3131480407 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one - two + two three - - + + ) } export const input = ( - - + + word - - + + ) export const output = ( - - - woonetwothreerd - - + + + woonetwothreerd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js index cf03f6846f..90e002c235 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - + + one + two + ) } export const input = ( - - + + word - - + + ) export const output = ( - - woone - + + woone + tword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js index f8779423d8..cfe3b7384f 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - three - + + one + two + three + ) } export const input = ( - - + + word - - + + ) export const output = ( - - one - two - + + one + two + threeword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js index 95ef72c090..18f8482619 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one two - - + + ) } export const input = ( - - + + - - + + ) export const output = ( - - + + onetwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js index f3e820c9f1..097a7c7844 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js @@ -1,39 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - after quote - + + + one + two + + after quote + ) } export const input = ( - - + + word - - + + ) export const output = ( - - wordone - - two - - + + wordone + + two + + after quote - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js index 6d83ae50eb..cc6fff55c7 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js @@ -1,37 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - + + + one + two + + ) } export const input = ( - - + + word - - + + ) export const output = ( - - woone - - + + woone + + tword - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js index c9685dd945..1f9550cbbb 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js @@ -1,39 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - after quote - + + + one + two + + after quote + ) } export const input = ( - - + + word - - + + ) export const output = ( - - one - - two - - + + one + + two + + after quoteword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js index fdfa818d28..2d0bcf97fa 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - three - + + one + two + three + ) } export const input = ( - - + + word - - + + ) export const output = ( - - wordone - two - + + wordone + two + three - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js index f7da4747d1..86d34aa985 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wordfragment - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js b/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js index 12329bfe72..682126eadb 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - - word + + + word - - + + ) export const output = ( - - - word + + + word fragment - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js b/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js index 95c6aea90c..457f4ad090 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js @@ -2,33 +2,33 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + 3 4 - + ) } export const input = ( - + 1 2 - + ) export const output = ( - + 1 23 @@ -36,7 +36,7 @@ export const output = ( 4 - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js index 5a5efec409..a9be2b4223 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js @@ -2,40 +2,40 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + bar - - + + ) } export const input = ( - + - + Foobaz - + - + ) export const output = ( - + - + Foo bar baz - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js index 85ef31a848..cbf26637eb 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js @@ -2,32 +2,32 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + b u i - - + + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo b u @@ -35,7 +35,7 @@ export const output = ( i rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js index f881a64cb3..bdac1f7e63 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js @@ -1,50 +1,50 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + - 2 + 2 - 3 + 3 - + ) } export const input = ( - + - + 1 - + - + ) export const output = ( - + - 12 + 12 - + 3 - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js b/packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js index d55ea091ed..6463ead4cc 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + 3 4 - + ) } export const input = ( - + 1 2 - + ) export const output = ( - + 1 23 @@ -36,6 +36,6 @@ export const output = ( 4 - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-block.js index 02221340a8..4885903c2c 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/middle-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/middle-block.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wofragmentrd - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js index 2db1dbf2ac..43059dcc8c 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js @@ -1,36 +1,36 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one two - - + + ) } export const input = ( - - + + word - - another - + + another + ) export const output = ( - - + + wordonetwo - - another - + + another + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js index 629276bbc9..c714be33db 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js @@ -1,39 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + fragment - - + + ) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - wo + + + wo fragment - rd - - + rd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js index 0baadba0c6..3e5cac88dc 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - wo + + + wo fragment - rd - - + rd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js index da4bdb5a31..643f9ad7f7 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js @@ -1,39 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - + + + one + two + + ) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - woone - + + + woone + tword - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js index 0e4b0321fc..bc324453df 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js @@ -2,40 +2,40 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - after quote - + + + one + two + + after quote + ) } export const input = ( - - + + word - - + + ) export const output = ( - - word - - one - two - - + + word + + one + two + + after quote - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js index 4d97589907..c183072781 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js @@ -2,39 +2,39 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - + + + one + two + + ) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - woone - + + + woone + tword - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js index ad06318d40..80352b91e4 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js @@ -2,39 +2,39 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - + + + one + two + + ) } export const input = ( - - + + word - - + + ) export const output = ( - - wo - - one - + + wo + + one + two - - - rd - + + + rd + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js index 4b66e0e502..0658a5d162 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js @@ -2,41 +2,41 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - one - two - - after quote - + + + one + two + + after quote + ) } export const input = ( - - + + word - - + + ) // TODO: should "after quote" be put together with "word"? export const output = ( - - - one - two - - + + + one + two + + after quote - - word - + + word + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js index 7dcd134412..63088a10d3 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js @@ -2,49 +2,49 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + - - 2 - 3 - + + 2 + 3 + - + ) } export const input = ( - - + + - - + + 1 - - + + - - + + ) export const output = ( - - + + - - 12 - + + 12 + 3 - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js index 8213b2fc06..718b60b259 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js @@ -2,38 +2,38 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + - 2 + 2 - + ) } export const input = ( - + - + {'1 '} - + - + ) export const output = ( - + - + 1 2 - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js index f8779423d8..cfe3b7384f 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - one - two - three - + + one + two + three + ) } export const input = ( - - + + word - - + + ) export const output = ( - - one - two - + + one + two + threeword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js b/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js index b1efcd24ca..69cce1abd1 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js @@ -1,38 +1,38 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one two - - + + ) } export const input = ( - - + + - - + + ) export const output = ( - - + + onetwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/start-block.js index 5f3f691738..28ba7bb77a 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/start-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/start-block.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + fragmentword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/start-inline.js index 4437ae2815..cf6e3c317c 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/start-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/start-inline.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + - word - - + word + + ) export const output = ( - - + + fragment - word - - + word + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js b/packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js index 07af463504..7020d26a6d 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - word - + + word + another - - + + ) export const output = ( - - word - + + word + fragmentanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js index 215af41978..f0ed510f9a 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js @@ -2,43 +2,41 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - - - - - 1 - - - 2 - - - -
-
+ + + + + 1 + + + 2 + + + +
) } export const input = ( - - - - - - - - - - - - - - -
-
+ + + + + + + + + + + + + + + +
) @@ -46,25 +44,25 @@ export const input = ( // ideally, paragraph with "2" goes into second cell export const output = ( - - - - - - 1 - - - 2 - - - +
+ + + + 1 - + + 2 + - - -
-
+ + + + + + + + +
) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js index ed276d6e7f..14be69aa5f 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js @@ -2,9 +2,9 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + @@ -13,13 +13,13 @@ export default function(editor) {
-
+ ) } export const input = ( - + @@ -30,14 +30,14 @@ export const input = (
-
+
) // TODO: paste "2" into second cell instead of creating new one? export const output = ( - + @@ -49,7 +49,7 @@ export const output = (
-
+
) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js index 638645012d..f3646d4905 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js @@ -2,9 +2,9 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - + @@ -13,13 +13,13 @@ export default function(editor) {
-
+ ) } export const input = ( - + @@ -31,14 +31,14 @@ export const input = (
-
+
) // TODO: paste "Existing 2" before / after "New 2" in second cell? export const output = ( - + @@ -50,7 +50,7 @@ export const output = (
-
+
) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js index 8673e1bfe5..d5862f5ef3 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wofragmentother - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js b/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js index 07af463504..7020d26a6d 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - word - + + word + another - - + + ) export const output = ( - - word - + + word + fragmentanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js index cf9cb1beec..407e1d81da 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js @@ -2,37 +2,37 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one two - - + + ) } export const input = ( - - + + - - + + ) export const output = ( - - + + onetwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js index 33b5cd4870..9c387ea84b 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js @@ -2,36 +2,36 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + {'one '} two - - + + ) } export const input = ( - - + + {'word '} - - another - + + another + ) export const output = ( - - + + word one two - - another - + + another + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js index f288a55cbc..16a5328976 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js @@ -2,33 +2,33 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - + + one two - - + + ) } export const input = ( - - + + - - + + ) export const output = ( - - + + onetwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js index 5324ad150f..142e19b525 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js @@ -2,32 +2,32 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - - word + + + word - - + + ) export const output = ( - - - word + + + word fragment - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js index 27d9e1ed9e..9d3d293e1c 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js @@ -2,32 +2,32 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + - word - - + word + + ) export const output = ( - - + + fragment - word - - + word + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js index 1354581233..4c18140f2f 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js @@ -2,30 +2,30 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wordfragment - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js index 414d41ffd9..6d6ed4eb88 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js @@ -2,36 +2,30 @@ import h from '../../../../helpers/h' -export default function(editor) { - editor.insertFragment( - - fragment - - ) +export const run = editor => { + editor.insertFragment(fragment) } export const input = ( - - - - {'word '} - - - - + + + {'word '} + + + ) // TODO: argument to made that fragment should go into the inline export const output = ( - - - {'word '} - fragment - - - + + {'word '} + fragment + + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js index 80ccdc225e..775b8c3532 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js @@ -2,30 +2,30 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wofragmentrd - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js index 46137abd63..a0a0455d05 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js @@ -2,35 +2,35 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - - + + + word - - - + + + ) // TODO: argument to made that fragment should go into the inline export const output = ( - - - wo + + + wo fragment - rd - - + rd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js index 06bf491cbf..9b4c413af8 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js @@ -2,30 +2,30 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + ) export const output = ( - - + + fragmentword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js b/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js index bf53068542..c146e4423e 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js @@ -2,32 +2,32 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - word - + + word + another - - + + ) export const output = ( - - word - + + word + fragmentanother - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js b/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js index b96af30ce3..be1c675cec 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js @@ -2,33 +2,33 @@ import h from '../../../../helpers/h' -export default function(editor) { +export const run = editor => { editor.insertFragment( - - fragment - + + fragment + ) } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wofragmentother - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-end.js b/packages/slate/test/commands/with-intent/insert-inline/block-end.js index f41588b0f4..5a0fde0f55 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/block-end.js +++ b/packages/slate/test/commands/with-intent/insert-inline/block-end.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertInline('emoji') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-middle.js b/packages/slate/test/commands/with-intent/insert-inline/block-middle.js index e688b20ca5..8695c9443a 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/block-middle.js +++ b/packages/slate/test/commands/with-intent/insert-inline/block-middle.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertInline('emoji') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-start.js b/packages/slate/test/commands/with-intent/insert-inline/block-start.js index 491b45b5ad..fea70a701d 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/block-start.js +++ b/packages/slate/test/commands/with-intent/insert-inline/block-start.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertInline('emoji') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js b/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js index 324dbed104..7c9bc2e0ec 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js +++ b/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertInline('emoji') } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - + + + wo rd - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/is-empty.js b/packages/slate/test/commands/with-intent/insert-inline/is-empty.js index 8dd2e4c610..e3af58c608 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/is-empty.js +++ b/packages/slate/test/commands/with-intent/insert-inline/is-empty.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertInline('emoji') } export const input = ( - - + + - - + + ) export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/is-void.js b/packages/slate/test/commands/with-intent/insert-inline/is-void.js index 9c459ce133..b6235a95e2 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/is-void.js +++ b/packages/slate/test/commands/with-intent/insert-inline/is-void.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertInline('emoji') } export const input = ( - + - + ) export const output = ( - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/with-inline.js b/packages/slate/test/commands/with-intent/insert-inline/with-inline.js index 00bbc99118..2b00787527 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/with-inline.js +++ b/packages/slate/test/commands/with-intent/insert-inline/with-inline.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Inline } from 'slate' -export default function(editor) { +export const run = editor => { editor.insertInline(Inline.create('emoji')) } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/after-mark.js b/packages/slate/test/commands/with-intent/insert-text/after-mark.js index f373ed006a..d0a4f4b812 100644 --- a/packages/slate/test/commands/with-intent/insert-text/after-mark.js +++ b/packages/slate/test/commands/with-intent/insert-text/after-mark.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + w or d - - + + ) export const output = ( - - + + w ora d - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/before-mark.js b/packages/slate/test/commands/with-intent/insert-text/before-mark.js index 9a8e064b76..5046ac9ec7 100644 --- a/packages/slate/test/commands/with-intent/insert-text/before-mark.js +++ b/packages/slate/test/commands/with-intent/insert-text/before-mark.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + w ord - - + + ) export const output = ( - - + + wa ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js b/packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js index 1282da352c..69cfeb8eb1 100644 --- a/packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js +++ b/packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('is ') } export const input = ( - - + + Cat - - + + Cute - - + + ) export const output = ( - - + + Cat - - + + is Cute - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/during-mark.js b/packages/slate/test/commands/with-intent/insert-text/during-mark.js index 313d416071..7c43ab2d49 100644 --- a/packages/slate/test/commands/with-intent/insert-text/during-mark.js +++ b/packages/slate/test/commands/with-intent/insert-text/during-mark.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + w or d - - + + ) export const output = ( - - + + w oar d - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js b/packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js index dce2c70c0e..da51140373 100644 --- a/packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js +++ b/packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('Cat') } export const input = ( - - + + - - + + ) export const output = ( - - + + Cat - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js b/packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js index 02c2e0bfbb..d41dfd3029 100644 --- a/packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js +++ b/packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') editor.insertText('b') } export const input = ( - - + + lorem ipsum - - + + ipsum - - + + ) export const output = ( - - + + ab - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/first-character.js b/packages/slate/test/commands/with-intent/insert-text/first-character.js index bf7a9383ba..f3082b6752 100644 --- a/packages/slate/test/commands/with-intent/insert-text/first-character.js +++ b/packages/slate/test/commands/with-intent/insert-text/first-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + aword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/first-space.js b/packages/slate/test/commands/with-intent/insert-text/first-space.js index ac295ca68f..c21b8c2104 100644 --- a/packages/slate/test/commands/with-intent/insert-text/first-space.js +++ b/packages/slate/test/commands/with-intent/insert-text/first-space.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText(' ') } export const input = ( - - + + word - - + + ) export const output = ( - - + + {' '} word - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/first-words.js b/packages/slate/test/commands/with-intent/insert-text/first-words.js index a9b5b01cb8..5412f7f318 100644 --- a/packages/slate/test/commands/with-intent/insert-text/first-words.js +++ b/packages/slate/test/commands/with-intent/insert-text/first-words.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a few words') } export const input = ( - - + + word - - + + ) export const output = ( - - + + a few wordsword - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js index 66a8a4bfb6..cc98f434f9 100644 --- a/packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js +++ b/packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + one - - two - + + two + three - - + + ) export const output = ( - - + + athree - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js b/packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js index cda360d160..ac2626465e 100644 --- a/packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js +++ b/packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + one - - + + two - - + + ) export const output = ( - - + + atwo - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/inside-void.js b/packages/slate/test/commands/with-intent/insert-text/inside-void.js index 3fe3bb2096..6a85366c06 100644 --- a/packages/slate/test/commands/with-intent/insert-text/inside-void.js +++ b/packages/slate/test/commands/with-intent/insert-text/inside-void.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - + - + ) export const output = ( - + - + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/last-character.js b/packages/slate/test/commands/with-intent/insert-text/last-character.js index c19622375b..d214a14ea1 100644 --- a/packages/slate/test/commands/with-intent/insert-text/last-character.js +++ b/packages/slate/test/commands/with-intent/insert-text/last-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + worda - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/last-space.js b/packages/slate/test/commands/with-intent/insert-text/last-space.js index eeafc13e86..5902952f95 100644 --- a/packages/slate/test/commands/with-intent/insert-text/last-space.js +++ b/packages/slate/test/commands/with-intent/insert-text/last-space.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText(' ') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/last-words.js b/packages/slate/test/commands/with-intent/insert-text/last-words.js index 190d20aad6..9a60b7efe0 100644 --- a/packages/slate/test/commands/with-intent/insert-text/last-words.js +++ b/packages/slate/test/commands/with-intent/insert-text/last-words.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText(' a few words') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word a few words - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/middle-character.js b/packages/slate/test/commands/with-intent/insert-text/middle-character.js index feae12a02e..fa22cdf9af 100644 --- a/packages/slate/test/commands/with-intent/insert-text/middle-character.js +++ b/packages/slate/test/commands/with-intent/insert-text/middle-character.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + waord - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/middle-space.js b/packages/slate/test/commands/with-intent/insert-text/middle-space.js index 31be79924d..6e692b972a 100644 --- a/packages/slate/test/commands/with-intent/insert-text/middle-space.js +++ b/packages/slate/test/commands/with-intent/insert-text/middle-space.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText(' ') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/middle-words.js b/packages/slate/test/commands/with-intent/insert-text/middle-words.js index 176cfd65f8..b14a47394a 100644 --- a/packages/slate/test/commands/with-intent/insert-text/middle-words.js +++ b/packages/slate/test/commands/with-intent/insert-text/middle-words.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.insertText(' a few words ') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w a few words ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/insert-text/with-marks.js b/packages/slate/test/commands/with-intent/insert-text/with-marks.js index 45945f6516..09fb6d261b 100644 --- a/packages/slate/test/commands/with-intent/insert-text/with-marks.js +++ b/packages/slate/test/commands/with-intent/insert-text/with-marks.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Mark } from 'slate' -export default function(editor) { +export const run = editor => { const marks = Mark.createSet([{ type: 'bold' }]) editor.insertText('a', marks) } export const input = ( - - + + word - - + + ) export const output = ( - - + + worda - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/across-blocks.js b/packages/slate/test/commands/with-intent/remove-mark/across-blocks.js index c93a989af8..415d5437cf 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/across-blocks.js +++ b/packages/slate/test/commands/with-intent/remove-mark/across-blocks.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + wo rd - - + + an other - - + + ) export const output = ( - - + + word - - + + another - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/across-inlines.js b/packages/slate/test/commands/with-intent/remove-mark/across-inlines.js index fa75848daf..4d8522c4e0 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/across-inlines.js +++ b/packages/slate/test/commands/with-intent/remove-mark/across-inlines.js @@ -1,43 +1,43 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - - + + + wo rd - - - - + + + + an other - - - + + + ) export const output = ( - - - + + + word - - - - + + + + another - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js b/packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js index 45d186c896..044c4c492f 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js +++ b/packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('bold') editor.removeMark('bold') editor.insertText('a') @@ -10,20 +10,20 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + aword - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/existing-marks.js b/packages/slate/test/commands/with-intent/remove-mark/existing-marks.js index 3c086fb604..f0e11f6006 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/existing-marks.js +++ b/packages/slate/test/commands/with-intent/remove-mark/existing-marks.js @@ -1,15 +1,15 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + wo @@ -17,19 +17,19 @@ export const input = ( rd - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/first-character.js b/packages/slate/test/commands/with-intent/remove-mark/first-character.js index e1cf38f14d..c4ddd4e775 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/first-character.js +++ b/packages/slate/test/commands/with-intent/remove-mark/first-character.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + w ord - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/last-character.js b/packages/slate/test/commands/with-intent/remove-mark/last-character.js index 68811dd33e..08958e5ab5 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/last-character.js +++ b/packages/slate/test/commands/with-intent/remove-mark/last-character.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + wor d - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/middle-character.js b/packages/slate/test/commands/with-intent/remove-mark/middle-character.js index 783aa191ab..d1df242c12 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/middle-character.js +++ b/packages/slate/test/commands/with-intent/remove-mark/middle-character.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + w o rd - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/part-of-mark-backward.js b/packages/slate/test/commands/with-intent/remove-mark/part-of-mark-backward.js index c23513da89..6563a055a9 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/part-of-mark-backward.js +++ b/packages/slate/test/commands/with-intent/remove-mark/part-of-mark-backward.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor d - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/part-of-mark.js b/packages/slate/test/commands/with-intent/remove-mark/part-of-mark.js index f83f87662c..5e6bfd6f91 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/part-of-mark.js +++ b/packages/slate/test/commands/with-intent/remove-mark/part-of-mark.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor d - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/whole-word.js b/packages/slate/test/commands/with-intent/remove-mark/whole-word.js index e109a378b0..3a5a3e0de4 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/whole-word.js +++ b/packages/slate/test/commands/with-intent/remove-mark/whole-word.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js b/packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js index 21112acaae..44cc6e7e81 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js +++ b/packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js @@ -1,9 +1,9 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Mark } from 'slate' -export default function(editor) { +export const run = editor => { editor.removeMark( Mark.create({ type: 'bold', @@ -14,22 +14,22 @@ export default function(editor) { export const input = ( - - + + w ord - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js b/packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js index 8889a75bf5..d4dc93d4fb 100644 --- a/packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js +++ b/packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.removeMark({ type: 'bold', data: { thing: 'value' }, @@ -11,22 +11,22 @@ export default function(editor) { export const input = ( - - + + w ord - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/across-blocks.js b/packages/slate/test/commands/with-intent/replace-mark/across-blocks.js index f941304be4..6553592a1a 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/across-blocks.js +++ b/packages/slate/test/commands/with-intent/replace-mark/across-blocks.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', 'bold') } export const input = ( - - + + wo rd - - + + an other - - + + ) export const output = ( - - + + wo rd - - + + an other - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/across-inlines.js b/packages/slate/test/commands/with-intent/replace-mark/across-inlines.js index bab0c64dd6..6fa140be58 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/across-inlines.js +++ b/packages/slate/test/commands/with-intent/replace-mark/across-inlines.js @@ -1,57 +1,57 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', 'bold') } export const input = ( - - + + - + wo rd - + - - + + - + an other - + - - + + ) export const output = ( - - + + - + wo rd - + - - + + - + an other - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/existing-marks.js b/packages/slate/test/commands/with-intent/replace-mark/existing-marks.js index 055d488ecd..dd589775e3 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/existing-marks.js +++ b/packages/slate/test/commands/with-intent/replace-mark/existing-marks.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', 'bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/first-character.js b/packages/slate/test/commands/with-intent/replace-mark/first-character.js index 07ebac88f6..3605388a8c 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/first-character.js +++ b/packages/slate/test/commands/with-intent/replace-mark/first-character.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', 'bold') } export const input = ( - - + + w ord - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/last-character.js b/packages/slate/test/commands/with-intent/replace-mark/last-character.js index 6ec7f8834e..f0fe948ab7 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/last-character.js +++ b/packages/slate/test/commands/with-intent/replace-mark/last-character.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', 'bold') } export const input = ( - - + + wor d - - + + ) export const output = ( - - + + wor d - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/middle-character.js b/packages/slate/test/commands/with-intent/replace-mark/middle-character.js index 974ccdaeb3..027e5ac5d3 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/middle-character.js +++ b/packages/slate/test/commands/with-intent/replace-mark/middle-character.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', 'bold') } export const input = ( - - + + w o rd - - + + ) export const output = ( - - + + w o rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/whole-word.js b/packages/slate/test/commands/with-intent/replace-mark/whole-word.js index 9afefca243..86b2666a18 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/whole-word.js +++ b/packages/slate/test/commands/with-intent/replace-mark/whole-word.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', 'bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js b/packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js index 7a69a68aed..7f9dad4ca6 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js +++ b/packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js @@ -1,10 +1,10 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Mark } from 'slate' -export default function(editor) { +export const run = editor => { editor.replaceMark( 'italic', Mark.create({ @@ -16,26 +16,26 @@ export default function(editor) { export const input = ( - - + + w ord - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js b/packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js index 5dedf9b385..97cb070abe 100644 --- a/packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js +++ b/packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.replaceMark('italic', { type: 'bold', data: { thing: 'value' }, @@ -11,26 +11,26 @@ export default function(editor) { export const input = ( - - + + w ord - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-block/across-blocks.js b/packages/slate/test/commands/with-intent/set-block/across-blocks.js index 2a9586302a..741cac49ea 100644 --- a/packages/slate/test/commands/with-intent/set-block/across-blocks.js +++ b/packages/slate/test/commands/with-intent/set-block/across-blocks.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code' }) } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - + word another - + ) diff --git a/packages/slate/test/commands/with-intent/set-block/across-inlines.js b/packages/slate/test/commands/with-intent/set-block/across-inlines.js index db1c63d0d6..7801b45adb 100644 --- a/packages/slate/test/commands/with-intent/set-block/across-inlines.js +++ b/packages/slate/test/commands/with-intent/set-block/across-inlines.js @@ -1,41 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code' }) } export const input = ( - - - - word - - - - - another - - - + + + word + + + + + another + + ) export const output = ( - - - - word - - - - - another - - - + + + word + + + + + another + + ) diff --git a/packages/slate/test/commands/with-intent/set-block/data-only.js b/packages/slate/test/commands/with-intent/set-block/data-only.js index 89fa4f6d84..a7b7ce5ae5 100644 --- a/packages/slate/test/commands/with-intent/set-block/data-only.js +++ b/packages/slate/test/commands/with-intent/set-block/data-only.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Data } from 'slate' -export default function(editor) { +export const run = editor => { editor.setBlocks({ data: Data.create({ thing: 'value' }) }) } export const input = ( - - + + word - - + + ) export const output = ( - + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js b/packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js index 30144f027f..715d9f867a 100644 --- a/packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js +++ b/packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js @@ -1,41 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code' }) } export const input = ( - - - - word - - - - - another - - - + + + word + + + + + another + + ) export const output = ( - - - - word - - - - - another - - - + + + word + + + + + another + + ) diff --git a/packages/slate/test/commands/with-intent/set-block/hanging-selection.js b/packages/slate/test/commands/with-intent/set-block/hanging-selection.js index 35c96c497f..ce01abb3b1 100644 --- a/packages/slate/test/commands/with-intent/set-block/hanging-selection.js +++ b/packages/slate/test/commands/with-intent/set-block/hanging-selection.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code' }) } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - + word - + another - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-block/nested-block.js b/packages/slate/test/commands/with-intent/set-block/nested-block.js index c5f499c146..ecddb2bbec 100644 --- a/packages/slate/test/commands/with-intent/set-block/nested-block.js +++ b/packages/slate/test/commands/with-intent/set-block/nested-block.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code' }) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js b/packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js index 085fca84c4..5f2ccc6939 100644 --- a/packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js +++ b/packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks('code') } export const input = ( - - + + word - - + + ) export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/with-intent/set-block/single-block.js b/packages/slate/test/commands/with-intent/set-block/single-block.js index 44aac81673..45837478ed 100644 --- a/packages/slate/test/commands/with-intent/set-block/single-block.js +++ b/packages/slate/test/commands/with-intent/set-block/single-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code' }) } export const input = ( - - + + word - - + + ) export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/with-intent/set-block/with-data-as-map.js b/packages/slate/test/commands/with-intent/set-block/with-data-as-map.js index 414083d82a..d333db09b2 100644 --- a/packages/slate/test/commands/with-intent/set-block/with-data-as-map.js +++ b/packages/slate/test/commands/with-intent/set-block/with-data-as-map.js @@ -1,9 +1,9 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Data } from 'slate' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code', data: Data.create({ thing: 'value' }), @@ -12,20 +12,20 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/with-intent/set-block/with-data-as-object.js b/packages/slate/test/commands/with-intent/set-block/with-data-as-object.js index 6366cf1e00..523efab745 100644 --- a/packages/slate/test/commands/with-intent/set-block/with-data-as-object.js +++ b/packages/slate/test/commands/with-intent/set-block/with-data-as-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks({ type: 'code', data: { thing: 'value' }, @@ -11,20 +11,20 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/with-intent/set-block/with-is-void.js b/packages/slate/test/commands/with-intent/set-block/with-is-void.js index 7a6c73b820..64c81324b4 100644 --- a/packages/slate/test/commands/with-intent/set-block/with-is-void.js +++ b/packages/slate/test/commands/with-intent/set-block/with-is-void.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setBlocks('image') } export const input = ( - - + + word - - + + ) export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/across-inlines.js b/packages/slate/test/commands/with-intent/set-inline/across-inlines.js index d287269a9d..6312e9232d 100644 --- a/packages/slate/test/commands/with-intent/set-inline/across-inlines.js +++ b/packages/slate/test/commands/with-intent/set-inline/across-inlines.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setInlines({ type: 'hashtag' }) } export const input = ( - - - + + + word - - - - + + + + another - - - + + + ) export const output = ( - - + + word - - + + another - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/data-only.js b/packages/slate/test/commands/with-intent/set-inline/data-only.js index 77048e0143..d25a5e44cf 100644 --- a/packages/slate/test/commands/with-intent/set-inline/data-only.js +++ b/packages/slate/test/commands/with-intent/set-inline/data-only.js @@ -1,32 +1,32 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Data } from 'slate' -export default function(editor) { +export const run = editor => { editor.setInlines({ data: Data.create({ thing: 'value' }) }) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/nested-inline.js b/packages/slate/test/commands/with-intent/set-inline/nested-inline.js index 9b968f579f..333ebbae8d 100644 --- a/packages/slate/test/commands/with-intent/set-inline/nested-inline.js +++ b/packages/slate/test/commands/with-intent/set-inline/nested-inline.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setInlines({ type: 'comment' }) } export const input = ( - - + + - + word - + - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js b/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js index 5d681b0c02..c665332576 100644 --- a/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js +++ b/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setInlines('hashtag') } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/single-inline.js b/packages/slate/test/commands/with-intent/set-inline/single-inline.js index 576cb40856..7980201308 100644 --- a/packages/slate/test/commands/with-intent/set-inline/single-inline.js +++ b/packages/slate/test/commands/with-intent/set-inline/single-inline.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setInlines({ type: 'hashtag' }) } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/with-data-object.js b/packages/slate/test/commands/with-intent/set-inline/with-data-object.js index 3f2c9b7c0f..811b680597 100644 --- a/packages/slate/test/commands/with-intent/set-inline/with-data-object.js +++ b/packages/slate/test/commands/with-intent/set-inline/with-data-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setInlines({ type: 'hashtag', data: { thing: 'value' }, @@ -11,24 +11,24 @@ export default function(editor) { export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/with-data.js b/packages/slate/test/commands/with-intent/set-inline/with-data.js index bae0b48127..2923b26501 100644 --- a/packages/slate/test/commands/with-intent/set-inline/with-data.js +++ b/packages/slate/test/commands/with-intent/set-inline/with-data.js @@ -1,9 +1,9 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Data } from 'slate' -export default function(editor) { +export const run = editor => { editor.setInlines({ type: 'hashtag', data: Data.create({ thing: 'value' }), @@ -12,24 +12,20 @@ export default function(editor) { export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - word - - - + + + word + + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/with-is-void.js b/packages/slate/test/commands/with-intent/set-inline/with-is-void.js index 94de528c5a..0fb9fda72b 100644 --- a/packages/slate/test/commands/with-intent/set-inline/with-is-void.js +++ b/packages/slate/test/commands/with-intent/set-inline/with-is-void.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.setInlines('emoji') } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/after-inline-void.js b/packages/slate/test/commands/with-intent/split-block/after-inline-void.js index 4c19a6b001..6f145cd2d5 100644 --- a/packages/slate/test/commands/with-intent/split-block/after-inline-void.js +++ b/packages/slate/test/commands/with-intent/split-block/after-inline-void.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - + + one two - - + + ) export const output = ( - - + + one - - + + two - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/after-inline.js b/packages/slate/test/commands/with-intent/split-block/after-inline.js index dcd9da6f31..8b1b7b160a 100644 --- a/packages/slate/test/commands/with-intent/split-block/after-inline.js +++ b/packages/slate/test/commands/with-intent/split-block/after-inline.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - - wordhyperlink + + + wordhyperlink word - - + + ) export const output = ( - - - wordhyperlink - - + + + wordhyperlink + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/before-inline.js b/packages/slate/test/commands/with-intent/split-block/before-inline.js index a761ffa313..83791880b9 100644 --- a/packages/slate/test/commands/with-intent/split-block/before-inline.js +++ b/packages/slate/test/commands/with-intent/split-block/before-inline.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - + + word hyperlink - word - - + word + + ) export const output = ( - - + + word - - + + hyperlink - word - - + word + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/block-end.js b/packages/slate/test/commands/with-intent/split-block/block-end.js index d350bcc3b0..df246e0abf 100644 --- a/packages/slate/test/commands/with-intent/split-block/block-end.js +++ b/packages/slate/test/commands/with-intent/split-block/block-end.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - + + word - - another - + + another + ) export const output = ( - - word - + + word + - - another - + + another + ) diff --git a/packages/slate/test/commands/with-intent/split-block/block-middle.js b/packages/slate/test/commands/with-intent/split-block/block-middle.js index 639a81d3ca..8806453cfe 100644 --- a/packages/slate/test/commands/with-intent/split-block/block-middle.js +++ b/packages/slate/test/commands/with-intent/split-block/block-middle.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - + + word - - + + ) export const output = ( - - wo - + + wo + rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/block-start.js b/packages/slate/test/commands/with-intent/split-block/block-start.js index c1da8e03e1..581126e9e0 100644 --- a/packages/slate/test/commands/with-intent/split-block/block-start.js +++ b/packages/slate/test/commands/with-intent/split-block/block-start.js @@ -1,30 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - word - - another - - + word + + another + ) export const output = ( - - word - - - another - - + word + + + + + another + ) diff --git a/packages/slate/test/commands/with-intent/split-block/depth.js b/packages/slate/test/commands/with-intent/split-block/depth.js index 941aa623c6..4fbfc73425 100644 --- a/packages/slate/test/commands/with-intent/split-block/depth.js +++ b/packages/slate/test/commands/with-intent/split-block/depth.js @@ -1,40 +1,40 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock(Infinity) } export const input = ( - - - - + + + + word - - - - + + + + ) export const output = ( - - - - wo - - - - - + + + + wo + + + + + rd - - - - + + + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js index 99bb9be213..c9724f6118 100644 --- a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js +++ b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js @@ -1,51 +1,51 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - + + - + word - + - - + + another - - + + ) export const output = ( - - + + - wo + wo - - + + other - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js index 3419c3007b..ff47735161 100644 --- a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js +++ b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - wo - + + wo + other - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js b/packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js index b8104c8f4a..4c030ddbd9 100644 --- a/packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js +++ b/packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js @@ -1,33 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - zero - - word - - - cat is cute - - + zero + + word + + + cat is cute + ) export const output = ( - - zero - - - cat is cute - - + zero + + + + + cat is cute + ) diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete.js b/packages/slate/test/commands/with-intent/split-block/with-delete.js index fababb74fa..38e280d8a1 100644 --- a/packages/slate/test/commands/with-intent/split-block/with-delete.js +++ b/packages/slate/test/commands/with-intent/split-block/with-delete.js @@ -1,28 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - + + word - - + + ) export const output = ( - - w - + + w + d - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/with-inline.js b/packages/slate/test/commands/with-intent/split-block/with-inline.js index d838c30b68..d97661dcbc 100644 --- a/packages/slate/test/commands/with-intent/split-block/with-inline.js +++ b/packages/slate/test/commands/with-intent/split-block/with-inline.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitBlock() } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - wo - - - + + + wo + + + rd - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/with-marks.js b/packages/slate/test/commands/with-intent/split-block/with-marks.js index 1d609d6cf2..aa35e2051e 100644 --- a/packages/slate/test/commands/with-intent/split-block/with-marks.js +++ b/packages/slate/test/commands/with-intent/split-block/with-marks.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.addMark('italic') editor.splitBlock() editor.insertText('cat is cute') @@ -10,28 +10,28 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + cat is cute - - + + ) diff --git a/packages/slate/test/commands/with-intent/split-inline/block-end.js b/packages/slate/test/commands/with-intent/split-inline/block-end.js index 47b4768da3..f21148c0ab 100644 --- a/packages/slate/test/commands/with-intent/split-inline/block-end.js +++ b/packages/slate/test/commands/with-intent/split-inline/block-end.js @@ -1,32 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitInline() } export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - word - - - - - + + word + + + + ) diff --git a/packages/slate/test/commands/with-intent/split-inline/block-middle.js b/packages/slate/test/commands/with-intent/split-inline/block-middle.js index 42b0b048bf..de98c88ecd 100644 --- a/packages/slate/test/commands/with-intent/split-inline/block-middle.js +++ b/packages/slate/test/commands/with-intent/split-inline/block-middle.js @@ -1,32 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitInline() } export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - wo - - rd - - - + + wo + + rd + + ) diff --git a/packages/slate/test/commands/with-intent/split-inline/block-start.js b/packages/slate/test/commands/with-intent/split-inline/block-start.js index 2ba9c0aac9..0f486a29e8 100644 --- a/packages/slate/test/commands/with-intent/split-inline/block-start.js +++ b/packages/slate/test/commands/with-intent/split-inline/block-start.js @@ -1,32 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitInline() } export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - - word - - - + + + + + + word + + ) diff --git a/packages/slate/test/commands/with-intent/split-inline/height.js b/packages/slate/test/commands/with-intent/split-inline/height.js index 654bfd3c05..a83687633a 100644 --- a/packages/slate/test/commands/with-intent/split-inline/height.js +++ b/packages/slate/test/commands/with-intent/split-inline/height.js @@ -1,45 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitInline(1) } export const input = ( - - + + + - - - - word - - - + + word + - - + + + ) export const output = ( - - + + + - - - wo - - - rd - - - + wo - - + + rd + + + + + ) diff --git a/packages/slate/test/commands/with-intent/split-inline/with-delete.js b/packages/slate/test/commands/with-intent/split-inline/with-delete.js index bead5d226e..31af7485a5 100644 --- a/packages/slate/test/commands/with-intent/split-inline/with-delete.js +++ b/packages/slate/test/commands/with-intent/split-inline/with-delete.js @@ -1,32 +1,28 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitInline() } export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - w - - d - - - + + w + + d + + ) diff --git a/packages/slate/test/commands/with-intent/split-inline/with-marks.js b/packages/slate/test/commands/with-intent/split-inline/with-marks.js index f4cc1891a7..037ac5dac0 100644 --- a/packages/slate/test/commands/with-intent/split-inline/with-marks.js +++ b/packages/slate/test/commands/with-intent/split-inline/with-marks.js @@ -1,38 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.splitInline() } export const input = ( - - - - - word - - - - + + + + word + + + ) export const output = ( - - - - wo - - - - rd - - - - + + + wo + + + + rd + + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js b/packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js index a5cbf4a8cb..8ad56ff2f2 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js @@ -1,37 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wo rd - - + + an other - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js b/packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js index 92d1824afc..a7e9d1f65a 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js @@ -1,53 +1,49 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - - - - word - - - - - - - another - - - - + + + + word + + + + + + + another + + + ) export const output = ( - - - - - wo - - rd - - - - - - - - an - other - - - - + + + + wo + + rd + + + + + + + + an + other + + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js b/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js index 0fe9f5294e..872dff91f9 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') editor.insertText('a') } export const input = ( - - + + word - - + + ) export const output = ( - - + + a word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js b/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js index 99c8de1c10..b5c60bb12d 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') editor.insertText('s') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word s - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js b/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js index 7076ed552d..2a2c5594f6 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + a word - - + + ) export const output = ( - - + + a @@ -34,7 +34,7 @@ export const output = ( rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js b/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js index ead899ace7..a6c69502ea 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo @@ -30,7 +30,7 @@ export const output = ( rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js b/packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js index b9b2845a92..304c517350 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js b/packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js index 3e1439b7d2..26d78cdef5 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wor d - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js b/packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js index 016fcab75d..e34fe4355d 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w o rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js b/packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js index cb95f2f7c5..4d5c6f1a1b 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + a word - - + + ) export const output = ( - - + + aword - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js b/packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js index 8d3dc0b5c4..ee5fed3734 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js b/packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js index fde5824ea2..6f900d6620 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js @@ -1,9 +1,9 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Mark } from 'slate' -export default function(editor) { +export const run = editor => { editor.toggleMark( Mark.create({ type: 'bold', @@ -14,23 +14,23 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js b/packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js index 6f9039ecf6..70679e0ddb 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark({ type: 'bold', data: { thing: 'value' }, @@ -11,23 +11,23 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + w ord - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js index 20fdc56b44..b75322c74a 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js @@ -1,37 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + wo rd - - + + an other - - + + ) export const output = ( - - + + word - - + + another - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js index 21be73e958..6bacfb328f 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js @@ -1,52 +1,48 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - - - - wo - rd - - - - - - - - an - other - - - - + + + + wo + rd + + + + + + + + an + other + + + ) export const output = ( - - - - - word - - - - - - - another - - - - + + + + word + + + + + + + another + + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js index ad8eccd41f..5a4ca668f1 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') editor.toggleMark('bold') editor.insertText('a') @@ -10,20 +10,20 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + aword - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js index 9dd1af655f..d679236775 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') editor.toggleMark('bold') editor.insertText('s') @@ -10,20 +10,20 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + words - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js index 874f67d467..8a6a25165f 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js @@ -1,15 +1,15 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + wo @@ -18,19 +18,19 @@ export const input = ( rd - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js index d8aade2180..426378a0b2 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + w ord - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js index a22f9dcf47..28db502993 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + wor d - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js index 35c8127929..eb00badafc 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + w o rd - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js index b04dff3189..eac798ff5f 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark('bold') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js index 1525aa7270..814aa99eca 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js @@ -1,9 +1,9 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' import { Mark } from 'slate' -export default function(editor) { +export const run = editor => { editor.toggleMark( Mark.create({ type: 'bold', @@ -14,23 +14,23 @@ export default function(editor) { export const input = ( - - + + w ord - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js b/packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js index 2b4b8d60ea..58288e047d 100644 --- a/packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js +++ b/packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.toggleMark({ type: 'bold', data: { thing: 'value' }, @@ -11,23 +11,23 @@ export default function(editor) { export const input = ( - - + + w ord - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js index 08d4e19b05..cfe1cad951 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - + + + word - - + + another - - - + + + ) export const output = ( - - + + word - - + + another - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js b/packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js index 5f93b13335..e049993bd8 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js @@ -1,43 +1,43 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - - + + + + word - - - - + + + + another - - - - + + + + ) export const output = ( - - - + + + word - - - - + + + + another - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js index 67fbe782b7..c54b685263 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js @@ -1,45 +1,45 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - one - two - three - four - + + + one + two + three + four + five - - + + six - - - + + + ) export const output = ( - - - one - two - three - four - - + + + one + two + three + four + + five - - + + six - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js b/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js index f2e39d3b26..41f1b9cf41 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js @@ -1,47 +1,47 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - one - two - + + + one + two + three - - + + four - - five - six - - + + five + six + + ) export const output = ( - - - one - two - - + + + one + two + + three - - + + four - - - five - six - - + + + five + six + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js index bd6ea1765c..a80cb189fb 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js @@ -1,47 +1,47 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - one - two - + + + one + two + three - - + + four - - five - six - - + + five + six + + ) export const output = ( - - - one - two - - + + + one + two + + three - - + + four - - - five - six - - + + + five + six + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/nested-block.js b/packages/slate/test/commands/with-intent/unwrap-block/nested-block.js index d73bb1845b..a89870db73 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/nested-block.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/nested-block.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - - + + + + word - - - - + + + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/single-block.js b/packages/slate/test/commands/with-intent/unwrap-block/single-block.js index 98a53e04e6..e8d1a3bcdc 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/single-block.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/single-block.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js b/packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js index 03a9bb6421..ee3c7e954c 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js @@ -1,45 +1,45 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock('quote') } export const input = ( - - - + + + one - - + + two - - three - four - five - six - - + + three + four + five + six + + ) export const output = ( - - + + one - - + + two - - - three - four - five - six - - + + + three + four + five + six + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-block/with-object.js b/packages/slate/test/commands/with-intent/unwrap-block/with-object.js index c800d2b78e..3e5a2077e3 100644 --- a/packages/slate/test/commands/with-intent/unwrap-block/with-object.js +++ b/packages/slate/test/commands/with-intent/unwrap-block/with-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapBlock({ type: 'quote', data: { thing: 'value' }, @@ -11,18 +11,18 @@ export default function(editor) { export const input = ( - + - word - - + word + + ) export const output = ( - - word - + + word + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js index d0d989dc0e..9ba22b65d5 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapInline('hashtag') } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + word - - + + another - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js index 3f78933579..340a8519d8 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js @@ -1,31 +1,31 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapInline('link') } export const input = ( - - - + + + one - two + two three - - - + + + ) export const output = ( - - + + onetwothree - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js index 5c5c1befdd..78ad57b7b2 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js @@ -1,45 +1,45 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapInline('hashtag') } export const input = ( - - - + + + wo - + - rd + rd - an + an - + other - - - + + + ) export const output = ( - - - + + + wo - - rd - an - + + rd + an + other - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js b/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js index 30c8131a5e..204f5fb19c 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapInline('hashtag') } export const input = ( - - - + + + w or d - - - + + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js b/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js index 888179bbb2..b7c1a39bb7 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapInline('hashtag') } export const input = ( - - + + hello w or d - - + + ) export const output = ( - - + + hello word - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js b/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js index 1ae187648f..419b516f61 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapInline('hashtag') } export const input = ( - - + + w or d - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js b/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js index f376598acd..039ee3d1dc 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.unwrapInline({ type: 'hashtag', data: { thing: 'value' }, @@ -11,26 +11,26 @@ export default function(editor) { export const input = ( - - + + w or d - - + + ) export const output = ( - - + + w or d - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-block/across-blocks.js b/packages/slate/test/commands/with-intent/wrap-block/across-blocks.js index 785981fb87..95d5411f32 100644 --- a/packages/slate/test/commands/with-intent/wrap-block/across-blocks.js +++ b/packages/slate/test/commands/with-intent/wrap-block/across-blocks.js @@ -1,35 +1,35 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapBlock('quote') } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - - + + + word - - + + another - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-block/across-inlines.js b/packages/slate/test/commands/with-intent/wrap-block/across-inlines.js index 36de8165cc..a1137afd1d 100644 --- a/packages/slate/test/commands/with-intent/wrap-block/across-inlines.js +++ b/packages/slate/test/commands/with-intent/wrap-block/across-inlines.js @@ -1,43 +1,39 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapBlock('quote') } export const input = ( - - - - word - - - - - another - - - + + + word + + + + + another + + ) export const output = ( - - - - - word - - - - - another - - - - + + + + word + + + + + another + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js b/packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js index 3e9bbe9074..07b3fc781c 100644 --- a/packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js +++ b/packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapBlock({ type: 'quote', data: { thing: 'value' }, @@ -11,26 +11,26 @@ export default function(editor) { export const input = ( - - - + + + word - - - + + + ) export const output = ( - - + + - + word - - - - + + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-block/nested-block.js b/packages/slate/test/commands/with-intent/wrap-block/nested-block.js index 17e0cfa56f..46765a1cbb 100644 --- a/packages/slate/test/commands/with-intent/wrap-block/nested-block.js +++ b/packages/slate/test/commands/with-intent/wrap-block/nested-block.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapBlock('quote') } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - - + + + + word - - - - + + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-block/single-block.js b/packages/slate/test/commands/with-intent/wrap-block/single-block.js index 2bef52d064..6808a9fab3 100644 --- a/packages/slate/test/commands/with-intent/wrap-block/single-block.js +++ b/packages/slate/test/commands/with-intent/wrap-block/single-block.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapBlock('quote') } export const input = ( - - + + word - - + + ) export const output = ( - - - + + + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-block/with-object.js b/packages/slate/test/commands/with-intent/wrap-block/with-object.js index 34b300caba..19420653b9 100644 --- a/packages/slate/test/commands/with-intent/wrap-block/with-object.js +++ b/packages/slate/test/commands/with-intent/wrap-block/with-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapBlock({ type: 'quote', data: { thing: 'value' }, @@ -11,22 +11,22 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - + - + word - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js b/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js index ab934c7f28..ccb5847796 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js @@ -1,38 +1,38 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wo rd - - + + an other - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js b/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js index f3afbd1f97..876f6e4c10 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - - + + + word - - + + another - - - + + + ) export const output = ( - - - wo + + + wo - + rd - - an + + an - + other - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js b/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js index 11e7b30c6b..d4c17ce87c 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + wd - - + + ) export const output = ( - - + + w d - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js index 5636b8a7a6..86eec29e93 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js @@ -1,41 +1,41 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + - + hello - + - - + + ) export const output = ( - - + + - hel + hel - + lo - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js index 64082ff3c4..c01c4418d7 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js @@ -1,52 +1,52 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + - + hello - + - - + + ) // TODO: this selection logic isn't right export const output = ( - - + + - + he - + - + ll - + - + o - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js index eb423ffef0..ef5e4f1a9e 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js @@ -1,44 +1,44 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + - + hello - + - - + + ) // TODO: this selection logic isn't right export const output = ( - - + + - he + he - + ll - + - + o - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js index dc241eab99..55690b9f5a 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js @@ -1,43 +1,43 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + - + hello - + - - + + ) export const output = ( - - + + - + hel - + - + lo - + - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js index 5a49950bc3..d75ba289d0 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('link') } export const input = ( - - + + - - + + ) export const output = ( - - - + + + - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js b/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js index 98feb35b3e..3bc66ab844 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js @@ -1,34 +1,34 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - - + + + word - - - + + + ) export const output = ( - - - + + + w or d - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/single-block.js b/packages/slate/test/commands/with-intent/wrap-inline/single-block.js index 4023946ba3..c723370625 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/single-block.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/single-block.js @@ -1,30 +1,30 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w or d - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/twice.js b/packages/slate/test/commands/with-intent/wrap-inline/twice.js index fdd6d5a070..4e6c37c19d 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/twice.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/twice.js @@ -1,36 +1,36 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('link') editor.wrapInline('hashtag') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w - + or - + d - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js b/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js index 20272ae46b..8ec7693213 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js @@ -1,29 +1,29 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline('hashtag') } export const input = ( - - + + word - - + + ) export const output = ( - - + + word - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/with-object.js b/packages/slate/test/commands/with-intent/wrap-inline/with-object.js index a6e4bf0300..171b3f2b63 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/with-object.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/with-object.js @@ -1,8 +1,8 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapInline({ type: 'hashtag', data: { thing: 'value' }, @@ -11,23 +11,23 @@ export default function(editor) { export const input = ( - - + + word - - + + ) export const output = ( - - + + w or d - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/across-blocks.js b/packages/slate/test/commands/with-intent/wrap-text/across-blocks.js index 4d1039652b..81dd2cfd0a 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/across-blocks.js +++ b/packages/slate/test/commands/with-intent/wrap-text/across-blocks.js @@ -1,33 +1,33 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - + + word - - + + another - - + + ) export const output = ( - - + + wo[[rd - - + + an]]other - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/across-inlines.js b/packages/slate/test/commands/with-intent/wrap-text/across-inlines.js index 8a12a34f59..ebb5612665 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/across-inlines.js +++ b/packages/slate/test/commands/with-intent/wrap-text/across-inlines.js @@ -1,37 +1,37 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - - + + + word - - + + another - - - + + + ) export const output = ( - - - + + + wo[[rd - - + + an]]other - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js b/packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js index ca249e8e59..521fed17c7 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js +++ b/packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w[[or]]d - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/empty-block.js b/packages/slate/test/commands/with-intent/wrap-text/empty-block.js index 64dc0b98ec..4b0d135594 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/empty-block.js +++ b/packages/slate/test/commands/with-intent/wrap-text/empty-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - + + - - + + ) export const output = ( - - + + [[]] - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/end-of-block.js b/packages/slate/test/commands/with-intent/wrap-text/end-of-block.js index 24517cd3f3..4ad5b80847 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/end-of-block.js +++ b/packages/slate/test/commands/with-intent/wrap-text/end-of-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - + + word - - + + ) export const output = ( - - + + wo[[rd]] - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js b/packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js index dc8dc31b0c..1efad9ea35 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js +++ b/packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w[[or]]d - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/start-of-block.js b/packages/slate/test/commands/with-intent/wrap-text/start-of-block.js index 779b91a159..378253ea55 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/start-of-block.js +++ b/packages/slate/test/commands/with-intent/wrap-text/start-of-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - + + word - - + + ) export const output = ( - - + + [[wo]]rd - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/whole-block.js b/packages/slate/test/commands/with-intent/wrap-text/whole-block.js index 72746f4a0c..38da209cf1 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/whole-block.js +++ b/packages/slate/test/commands/with-intent/wrap-text/whole-block.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('[[', ']]') } export const input = ( - - + + word - - + + ) export const output = ( - - + + [[word]] - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-text/without-suffix.js b/packages/slate/test/commands/with-intent/wrap-text/without-suffix.js index 1849b07fc6..d7adc46b72 100644 --- a/packages/slate/test/commands/with-intent/wrap-text/without-suffix.js +++ b/packages/slate/test/commands/with-intent/wrap-text/without-suffix.js @@ -1,27 +1,27 @@ /** @jsx h */ -import h from '../../../helpers/h' +import { h } from '../../../helpers' -export default function(editor) { +export const run = editor => { editor.wrapText('**') } export const input = ( - - + + word - - + + ) export const output = ( - - + + w**or**d - - + + ) diff --git a/packages/slate/test/helpers/index.js b/packages/slate/test/helpers/index.js index 0686cc1ec4..ecca38d1cf 100644 --- a/packages/slate/test/helpers/index.js +++ b/packages/slate/test/helpers/index.js @@ -3,32 +3,32 @@ import { createHyperscript } from 'slate-hyperscript' const h = createHyperscript({ elements: { - block: { type: 'block' }, - inline: { type: 'inline' }, - void_block: { type: 'void_block' }, - void_inline: { type: 'void_inline' }, + block: { kind: 'block' }, + inline: { kind: 'inline' }, + void_block: { kind: 'void_block' }, + void_inline: { kind: 'void_inline' }, }, annotations: { - atomic_annotation: { type: 'atomic_annotation' }, + atomic_annotation: { kind: 'atomic_annotation' }, }, }) const TestPlugin = Editor => { return class extends Editor { isBlock(node) { - return Element.isElement(node) && node.type.endsWith('block') + return Element.isElement(node) && node.kind.endsWith('block') } isInline(node) { - return Element.isElement(node) && node.type.endsWith('inline') + return Element.isElement(node) && node.kind.endsWith('inline') } isVoid(node) { - return Element.isElement(node) && node.type.startsWith('void_') + return Element.isElement(node) && node.kind.startsWith('void_') } isAtomic(mark) { - return mark.type.startsWith('atomic_') + return mark.kind.startsWith('atomic_') } } } diff --git a/packages/slate/test/index.js b/packages/slate/test/index.js index 920ac6d4ac..32720a8cdb 100644 --- a/packages/slate/test/index.js +++ b/packages/slate/test/index.js @@ -3,28 +3,6 @@ import { fixtures } from '../../../support/fixtures' import { Editor } from 'slate' import { TestPlugin } from './helpers' -const plugins = [ - { - schema: { - blocks: { - image: { - isVoid: true, - }, - }, - inlines: { - emoji: { - isVoid: true, - }, - }, - marks: { - result: { - isAtomic: true, - }, - }, - }, - }, -] - describe('slate', () => { fixtures(__dirname, 'interfaces', ({ module }) => { const { input, test, output } = module @@ -52,47 +30,11 @@ describe('slate', () => { assert.deepEqual(editor.value, output) }) - // The hyperscript editor has the schema, but the test - // editor doesn't! It needs to live in the tests instead. - fixtures(__dirname, 'commands', ({ module }) => { - const { input, output, options = {}, plugins: module_plugins } = module - const fn = module.default - const editor = new Editor({ - plugins: module_plugins ? plugins.concat(module_plugins) : plugins, - }) - const opts = { preserveSelection: true, ...options } - - editor.setValue(input) - fn(editor) - const actual = editor.value.toJSON(opts) - - editor.setValue(output) - const expected = editor.value.toJSON(opts) - assert.deepEqual(actual, expected) - }) - - fixtures(__dirname, 'schema', ({ module }) => { - const { input, output, schema } = module - const editor = new Editor({ value: input, plugins: [{ schema }] }) - const actual = editor.value.toJSON() - const expected = output.toJSON() - assert.deepEqual(actual, expected) - }) - - fixtures(__dirname, 'history', ({ module }) => { - const { input, output } = module - const fn = module.default - const editor = new Editor({ plugins }) - const opts = { preserveSelection: true } - - editor.setValue(input) - fn(editor) - const actual = editor.value.toJSON(opts) - - editor.setValue(output) - const expected = output.toJSON(opts) - - assert.deepEqual(actual, expected) + const { input, run, output } = module + const TestEditor = TestPlugin(Editor) + const editor = new TestEditor({ value: input }) + run(editor) + assert.deepEqual(editor.value, output) }) }) From e305a49836bceed0ce697fdced78bceea83a4439 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 15 Oct 2019 16:12:49 -0400 Subject: [PATCH 034/165] rename *AtPath command tests --- .../end-of-target.js | 0 .../middle-of-target.js | 0 .../start-of-target.js | 0 .../at-path/{insert-node-by-path => insertNodeAtPath}/block.js | 0 .../at-path/{insert-node-by-path => insertNodeAtPath}/inline.js | 0 .../at-path/{insert-node-by-path => insertNodeAtPath}/text.js | 0 .../at-path/{lift-node-by-path => liftNodeAtPath}/block.js | 0 .../at-path/{lift-node-by-path => liftNodeAtPath}/first-block.js | 0 .../at-path/{lift-node-by-path => liftNodeAtPath}/last-block.js | 0 .../at-path/{lift-node-by-path => liftNodeAtPath}/middle-block.js | 0 .../at-path/{merge-node-by-path => mergeNodeAtPath}/block.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/block.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/inline.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/inside-next.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/nested.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/noop-equal.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/sibling-swap.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/text-nodes.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/text.js | 0 .../at-path/{move-node-by-path => moveNodeAtPath}/to-sibling.js | 0 .../{pluck-node-by-path => pluckNodeAtPath}/block-multiple.js | 0 .../at-path/{pluck-node-by-path => pluckNodeAtPath}/block.js | 0 .../at-path/{remove-node-by-path => removeNodeAtPath}/block.js | 0 .../at-path/{remove-node-by-path => removeNodeAtPath}/inline.js | 0 .../{remove-node-by-path => removeNodeAtPath}/selection-inside.js | 0 .../at-path/{remove-node-by-path => removeNodeAtPath}/text.js | 0 .../at-path/{replace-node-by-path => replaceNodeAtPath}/block.js | 0 .../at-path/{replace-node-by-path => replaceNodeAtPath}/inline.js | 0 .../at-path/{replace-node-by-path => replaceNodeAtPath}/text.js | 0 .../at-path/{replace-text-by-path => replaceTextAtPath}/basic.js | 0 .../commands/at-path/{set-mark-by-path => setMarkAtPath}/basic.js | 0 .../commands/at-path/{set-node-by-path => setNodeAtPath}/block.js | 0 .../at-path/{set-node-by-path => setNodeAtPath}/inline.js | 0 .../commands/at-path/{set-node-by-path => setNodeAtPath}/text.js | 0 .../at-path/{split-node-by-path => splitNodeAtPath}/block.js | 0 .../at-path/{split-node-by-path => splitNodeAtPath}/selection.js | 0 .../at-path/{wrap-node-by-path => wrapNodeAtPath}/block.js | 0 .../at-path/{wrap-node-by-path => wrapNodeAtPath}/text.js | 0 38 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/commands/at-path/{insert-fragment-by-path => insertFragmentAtPath}/end-of-target.js (100%) rename packages/slate/test/commands/at-path/{insert-fragment-by-path => insertFragmentAtPath}/middle-of-target.js (100%) rename packages/slate/test/commands/at-path/{insert-fragment-by-path => insertFragmentAtPath}/start-of-target.js (100%) rename packages/slate/test/commands/at-path/{insert-node-by-path => insertNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{insert-node-by-path => insertNodeAtPath}/inline.js (100%) rename packages/slate/test/commands/at-path/{insert-node-by-path => insertNodeAtPath}/text.js (100%) rename packages/slate/test/commands/at-path/{lift-node-by-path => liftNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{lift-node-by-path => liftNodeAtPath}/first-block.js (100%) rename packages/slate/test/commands/at-path/{lift-node-by-path => liftNodeAtPath}/last-block.js (100%) rename packages/slate/test/commands/at-path/{lift-node-by-path => liftNodeAtPath}/middle-block.js (100%) rename packages/slate/test/commands/at-path/{merge-node-by-path => mergeNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/inline.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/inside-next.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/nested.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/noop-equal.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/sibling-swap.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/text-nodes.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/text.js (100%) rename packages/slate/test/commands/at-path/{move-node-by-path => moveNodeAtPath}/to-sibling.js (100%) rename packages/slate/test/commands/at-path/{pluck-node-by-path => pluckNodeAtPath}/block-multiple.js (100%) rename packages/slate/test/commands/at-path/{pluck-node-by-path => pluckNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{remove-node-by-path => removeNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{remove-node-by-path => removeNodeAtPath}/inline.js (100%) rename packages/slate/test/commands/at-path/{remove-node-by-path => removeNodeAtPath}/selection-inside.js (100%) rename packages/slate/test/commands/at-path/{remove-node-by-path => removeNodeAtPath}/text.js (100%) rename packages/slate/test/commands/at-path/{replace-node-by-path => replaceNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{replace-node-by-path => replaceNodeAtPath}/inline.js (100%) rename packages/slate/test/commands/at-path/{replace-node-by-path => replaceNodeAtPath}/text.js (100%) rename packages/slate/test/commands/at-path/{replace-text-by-path => replaceTextAtPath}/basic.js (100%) rename packages/slate/test/commands/at-path/{set-mark-by-path => setMarkAtPath}/basic.js (100%) rename packages/slate/test/commands/at-path/{set-node-by-path => setNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{set-node-by-path => setNodeAtPath}/inline.js (100%) rename packages/slate/test/commands/at-path/{set-node-by-path => setNodeAtPath}/text.js (100%) rename packages/slate/test/commands/at-path/{split-node-by-path => splitNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{split-node-by-path => splitNodeAtPath}/selection.js (100%) rename packages/slate/test/commands/at-path/{wrap-node-by-path => wrapNodeAtPath}/block.js (100%) rename packages/slate/test/commands/at-path/{wrap-node-by-path => wrapNodeAtPath}/text.js (100%) diff --git a/packages/slate/test/commands/at-path/insert-fragment-by-path/end-of-target.js b/packages/slate/test/commands/at-path/insertFragmentAtPath/end-of-target.js similarity index 100% rename from packages/slate/test/commands/at-path/insert-fragment-by-path/end-of-target.js rename to packages/slate/test/commands/at-path/insertFragmentAtPath/end-of-target.js diff --git a/packages/slate/test/commands/at-path/insert-fragment-by-path/middle-of-target.js b/packages/slate/test/commands/at-path/insertFragmentAtPath/middle-of-target.js similarity index 100% rename from packages/slate/test/commands/at-path/insert-fragment-by-path/middle-of-target.js rename to packages/slate/test/commands/at-path/insertFragmentAtPath/middle-of-target.js diff --git a/packages/slate/test/commands/at-path/insert-fragment-by-path/start-of-target.js b/packages/slate/test/commands/at-path/insertFragmentAtPath/start-of-target.js similarity index 100% rename from packages/slate/test/commands/at-path/insert-fragment-by-path/start-of-target.js rename to packages/slate/test/commands/at-path/insertFragmentAtPath/start-of-target.js diff --git a/packages/slate/test/commands/at-path/insert-node-by-path/block.js b/packages/slate/test/commands/at-path/insertNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/insert-node-by-path/block.js rename to packages/slate/test/commands/at-path/insertNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/insert-node-by-path/inline.js b/packages/slate/test/commands/at-path/insertNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/insert-node-by-path/inline.js rename to packages/slate/test/commands/at-path/insertNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/insert-node-by-path/text.js b/packages/slate/test/commands/at-path/insertNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/insert-node-by-path/text.js rename to packages/slate/test/commands/at-path/insertNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/block.js b/packages/slate/test/commands/at-path/liftNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/lift-node-by-path/block.js rename to packages/slate/test/commands/at-path/liftNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/first-block.js b/packages/slate/test/commands/at-path/liftNodeAtPath/first-block.js similarity index 100% rename from packages/slate/test/commands/at-path/lift-node-by-path/first-block.js rename to packages/slate/test/commands/at-path/liftNodeAtPath/first-block.js diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/last-block.js b/packages/slate/test/commands/at-path/liftNodeAtPath/last-block.js similarity index 100% rename from packages/slate/test/commands/at-path/lift-node-by-path/last-block.js rename to packages/slate/test/commands/at-path/liftNodeAtPath/last-block.js diff --git a/packages/slate/test/commands/at-path/lift-node-by-path/middle-block.js b/packages/slate/test/commands/at-path/liftNodeAtPath/middle-block.js similarity index 100% rename from packages/slate/test/commands/at-path/lift-node-by-path/middle-block.js rename to packages/slate/test/commands/at-path/liftNodeAtPath/middle-block.js diff --git a/packages/slate/test/commands/at-path/merge-node-by-path/block.js b/packages/slate/test/commands/at-path/mergeNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/merge-node-by-path/block.js rename to packages/slate/test/commands/at-path/mergeNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/block.js b/packages/slate/test/commands/at-path/moveNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/block.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/inline.js b/packages/slate/test/commands/at-path/moveNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/inline.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/inside-next.js b/packages/slate/test/commands/at-path/moveNodeAtPath/inside-next.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/inside-next.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/inside-next.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/nested.js b/packages/slate/test/commands/at-path/moveNodeAtPath/nested.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/nested.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/nested.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/noop-equal.js b/packages/slate/test/commands/at-path/moveNodeAtPath/noop-equal.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/noop-equal.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/noop-equal.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/sibling-swap.js b/packages/slate/test/commands/at-path/moveNodeAtPath/sibling-swap.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/sibling-swap.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/sibling-swap.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/text-nodes.js b/packages/slate/test/commands/at-path/moveNodeAtPath/text-nodes.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/text-nodes.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/text-nodes.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/text.js b/packages/slate/test/commands/at-path/moveNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/text.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/move-node-by-path/to-sibling.js b/packages/slate/test/commands/at-path/moveNodeAtPath/to-sibling.js similarity index 100% rename from packages/slate/test/commands/at-path/move-node-by-path/to-sibling.js rename to packages/slate/test/commands/at-path/moveNodeAtPath/to-sibling.js diff --git a/packages/slate/test/commands/at-path/pluck-node-by-path/block-multiple.js b/packages/slate/test/commands/at-path/pluckNodeAtPath/block-multiple.js similarity index 100% rename from packages/slate/test/commands/at-path/pluck-node-by-path/block-multiple.js rename to packages/slate/test/commands/at-path/pluckNodeAtPath/block-multiple.js diff --git a/packages/slate/test/commands/at-path/pluck-node-by-path/block.js b/packages/slate/test/commands/at-path/pluckNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/pluck-node-by-path/block.js rename to packages/slate/test/commands/at-path/pluckNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/block.js b/packages/slate/test/commands/at-path/removeNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/remove-node-by-path/block.js rename to packages/slate/test/commands/at-path/removeNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/inline.js b/packages/slate/test/commands/at-path/removeNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/remove-node-by-path/inline.js rename to packages/slate/test/commands/at-path/removeNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/selection-inside.js b/packages/slate/test/commands/at-path/removeNodeAtPath/selection-inside.js similarity index 100% rename from packages/slate/test/commands/at-path/remove-node-by-path/selection-inside.js rename to packages/slate/test/commands/at-path/removeNodeAtPath/selection-inside.js diff --git a/packages/slate/test/commands/at-path/remove-node-by-path/text.js b/packages/slate/test/commands/at-path/removeNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/remove-node-by-path/text.js rename to packages/slate/test/commands/at-path/removeNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/replace-node-by-path/block.js b/packages/slate/test/commands/at-path/replaceNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/replace-node-by-path/block.js rename to packages/slate/test/commands/at-path/replaceNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/replace-node-by-path/inline.js b/packages/slate/test/commands/at-path/replaceNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/replace-node-by-path/inline.js rename to packages/slate/test/commands/at-path/replaceNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/replace-node-by-path/text.js b/packages/slate/test/commands/at-path/replaceNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/replace-node-by-path/text.js rename to packages/slate/test/commands/at-path/replaceNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/replace-text-by-path/basic.js b/packages/slate/test/commands/at-path/replaceTextAtPath/basic.js similarity index 100% rename from packages/slate/test/commands/at-path/replace-text-by-path/basic.js rename to packages/slate/test/commands/at-path/replaceTextAtPath/basic.js diff --git a/packages/slate/test/commands/at-path/set-mark-by-path/basic.js b/packages/slate/test/commands/at-path/setMarkAtPath/basic.js similarity index 100% rename from packages/slate/test/commands/at-path/set-mark-by-path/basic.js rename to packages/slate/test/commands/at-path/setMarkAtPath/basic.js diff --git a/packages/slate/test/commands/at-path/set-node-by-path/block.js b/packages/slate/test/commands/at-path/setNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/set-node-by-path/block.js rename to packages/slate/test/commands/at-path/setNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/set-node-by-path/inline.js b/packages/slate/test/commands/at-path/setNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/set-node-by-path/inline.js rename to packages/slate/test/commands/at-path/setNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/set-node-by-path/text.js b/packages/slate/test/commands/at-path/setNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/set-node-by-path/text.js rename to packages/slate/test/commands/at-path/setNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/split-node-by-path/block.js b/packages/slate/test/commands/at-path/splitNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/split-node-by-path/block.js rename to packages/slate/test/commands/at-path/splitNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/split-node-by-path/selection.js b/packages/slate/test/commands/at-path/splitNodeAtPath/selection.js similarity index 100% rename from packages/slate/test/commands/at-path/split-node-by-path/selection.js rename to packages/slate/test/commands/at-path/splitNodeAtPath/selection.js diff --git a/packages/slate/test/commands/at-path/wrap-node-by-path/block.js b/packages/slate/test/commands/at-path/wrapNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/wrap-node-by-path/block.js rename to packages/slate/test/commands/at-path/wrapNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/wrap-node-by-path/text.js b/packages/slate/test/commands/at-path/wrapNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/wrap-node-by-path/text.js rename to packages/slate/test/commands/at-path/wrapNodeAtPath/text.js From f3cc2441639a195e5d7a2a60c31c8e68031e40cf Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 15 Oct 2019 16:13:02 -0400 Subject: [PATCH 035/165] rename --- .../{at-path => path}/insertFragmentAtPath/end-of-target.js | 0 .../{at-path => path}/insertFragmentAtPath/middle-of-target.js | 0 .../{at-path => path}/insertFragmentAtPath/start-of-target.js | 0 .../test/commands/{at-path => path}/insertNodeAtPath/block.js | 0 .../test/commands/{at-path => path}/insertNodeAtPath/inline.js | 0 .../test/commands/{at-path => path}/insertNodeAtPath/text.js | 0 .../slate/test/commands/{at-path => path}/liftNodeAtPath/block.js | 0 .../test/commands/{at-path => path}/liftNodeAtPath/first-block.js | 0 .../test/commands/{at-path => path}/liftNodeAtPath/last-block.js | 0 .../commands/{at-path => path}/liftNodeAtPath/middle-block.js | 0 .../test/commands/{at-path => path}/mergeNodeAtPath/block.js | 0 .../slate/test/commands/{at-path => path}/moveNodeAtPath/block.js | 0 .../test/commands/{at-path => path}/moveNodeAtPath/inline.js | 0 .../test/commands/{at-path => path}/moveNodeAtPath/inside-next.js | 0 .../test/commands/{at-path => path}/moveNodeAtPath/nested.js | 0 .../test/commands/{at-path => path}/moveNodeAtPath/noop-equal.js | 0 .../commands/{at-path => path}/moveNodeAtPath/sibling-swap.js | 0 .../test/commands/{at-path => path}/moveNodeAtPath/text-nodes.js | 0 .../slate/test/commands/{at-path => path}/moveNodeAtPath/text.js | 0 .../test/commands/{at-path => path}/moveNodeAtPath/to-sibling.js | 0 .../commands/{at-path => path}/pluckNodeAtPath/block-multiple.js | 0 .../test/commands/{at-path => path}/pluckNodeAtPath/block.js | 0 .../test/commands/{at-path => path}/removeNodeAtPath/block.js | 0 .../test/commands/{at-path => path}/removeNodeAtPath/inline.js | 0 .../{at-path => path}/removeNodeAtPath/selection-inside.js | 0 .../test/commands/{at-path => path}/removeNodeAtPath/text.js | 0 .../test/commands/{at-path => path}/replaceNodeAtPath/block.js | 0 .../test/commands/{at-path => path}/replaceNodeAtPath/inline.js | 0 .../test/commands/{at-path => path}/replaceNodeAtPath/text.js | 0 .../test/commands/{at-path => path}/replaceTextAtPath/basic.js | 0 .../slate/test/commands/{at-path => path}/setMarkAtPath/basic.js | 0 .../slate/test/commands/{at-path => path}/setNodeAtPath/block.js | 0 .../slate/test/commands/{at-path => path}/setNodeAtPath/inline.js | 0 .../slate/test/commands/{at-path => path}/setNodeAtPath/text.js | 0 .../test/commands/{at-path => path}/splitNodeAtPath/block.js | 0 .../test/commands/{at-path => path}/splitNodeAtPath/selection.js | 0 .../slate/test/commands/{at-path => path}/wrapNodeAtPath/block.js | 0 .../slate/test/commands/{at-path => path}/wrapNodeAtPath/text.js | 0 38 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/commands/{at-path => path}/insertFragmentAtPath/end-of-target.js (100%) rename packages/slate/test/commands/{at-path => path}/insertFragmentAtPath/middle-of-target.js (100%) rename packages/slate/test/commands/{at-path => path}/insertFragmentAtPath/start-of-target.js (100%) rename packages/slate/test/commands/{at-path => path}/insertNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/insertNodeAtPath/inline.js (100%) rename packages/slate/test/commands/{at-path => path}/insertNodeAtPath/text.js (100%) rename packages/slate/test/commands/{at-path => path}/liftNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/liftNodeAtPath/first-block.js (100%) rename packages/slate/test/commands/{at-path => path}/liftNodeAtPath/last-block.js (100%) rename packages/slate/test/commands/{at-path => path}/liftNodeAtPath/middle-block.js (100%) rename packages/slate/test/commands/{at-path => path}/mergeNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/inline.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/inside-next.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/nested.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/noop-equal.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/sibling-swap.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/text-nodes.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/text.js (100%) rename packages/slate/test/commands/{at-path => path}/moveNodeAtPath/to-sibling.js (100%) rename packages/slate/test/commands/{at-path => path}/pluckNodeAtPath/block-multiple.js (100%) rename packages/slate/test/commands/{at-path => path}/pluckNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/removeNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/removeNodeAtPath/inline.js (100%) rename packages/slate/test/commands/{at-path => path}/removeNodeAtPath/selection-inside.js (100%) rename packages/slate/test/commands/{at-path => path}/removeNodeAtPath/text.js (100%) rename packages/slate/test/commands/{at-path => path}/replaceNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/replaceNodeAtPath/inline.js (100%) rename packages/slate/test/commands/{at-path => path}/replaceNodeAtPath/text.js (100%) rename packages/slate/test/commands/{at-path => path}/replaceTextAtPath/basic.js (100%) rename packages/slate/test/commands/{at-path => path}/setMarkAtPath/basic.js (100%) rename packages/slate/test/commands/{at-path => path}/setNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/setNodeAtPath/inline.js (100%) rename packages/slate/test/commands/{at-path => path}/setNodeAtPath/text.js (100%) rename packages/slate/test/commands/{at-path => path}/splitNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/splitNodeAtPath/selection.js (100%) rename packages/slate/test/commands/{at-path => path}/wrapNodeAtPath/block.js (100%) rename packages/slate/test/commands/{at-path => path}/wrapNodeAtPath/text.js (100%) diff --git a/packages/slate/test/commands/at-path/insertFragmentAtPath/end-of-target.js b/packages/slate/test/commands/path/insertFragmentAtPath/end-of-target.js similarity index 100% rename from packages/slate/test/commands/at-path/insertFragmentAtPath/end-of-target.js rename to packages/slate/test/commands/path/insertFragmentAtPath/end-of-target.js diff --git a/packages/slate/test/commands/at-path/insertFragmentAtPath/middle-of-target.js b/packages/slate/test/commands/path/insertFragmentAtPath/middle-of-target.js similarity index 100% rename from packages/slate/test/commands/at-path/insertFragmentAtPath/middle-of-target.js rename to packages/slate/test/commands/path/insertFragmentAtPath/middle-of-target.js diff --git a/packages/slate/test/commands/at-path/insertFragmentAtPath/start-of-target.js b/packages/slate/test/commands/path/insertFragmentAtPath/start-of-target.js similarity index 100% rename from packages/slate/test/commands/at-path/insertFragmentAtPath/start-of-target.js rename to packages/slate/test/commands/path/insertFragmentAtPath/start-of-target.js diff --git a/packages/slate/test/commands/at-path/insertNodeAtPath/block.js b/packages/slate/test/commands/path/insertNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/insertNodeAtPath/block.js rename to packages/slate/test/commands/path/insertNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/insertNodeAtPath/inline.js b/packages/slate/test/commands/path/insertNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/insertNodeAtPath/inline.js rename to packages/slate/test/commands/path/insertNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/insertNodeAtPath/text.js b/packages/slate/test/commands/path/insertNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/insertNodeAtPath/text.js rename to packages/slate/test/commands/path/insertNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/liftNodeAtPath/block.js b/packages/slate/test/commands/path/liftNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/liftNodeAtPath/block.js rename to packages/slate/test/commands/path/liftNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/liftNodeAtPath/first-block.js b/packages/slate/test/commands/path/liftNodeAtPath/first-block.js similarity index 100% rename from packages/slate/test/commands/at-path/liftNodeAtPath/first-block.js rename to packages/slate/test/commands/path/liftNodeAtPath/first-block.js diff --git a/packages/slate/test/commands/at-path/liftNodeAtPath/last-block.js b/packages/slate/test/commands/path/liftNodeAtPath/last-block.js similarity index 100% rename from packages/slate/test/commands/at-path/liftNodeAtPath/last-block.js rename to packages/slate/test/commands/path/liftNodeAtPath/last-block.js diff --git a/packages/slate/test/commands/at-path/liftNodeAtPath/middle-block.js b/packages/slate/test/commands/path/liftNodeAtPath/middle-block.js similarity index 100% rename from packages/slate/test/commands/at-path/liftNodeAtPath/middle-block.js rename to packages/slate/test/commands/path/liftNodeAtPath/middle-block.js diff --git a/packages/slate/test/commands/at-path/mergeNodeAtPath/block.js b/packages/slate/test/commands/path/mergeNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/mergeNodeAtPath/block.js rename to packages/slate/test/commands/path/mergeNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/block.js b/packages/slate/test/commands/path/moveNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/block.js rename to packages/slate/test/commands/path/moveNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/inline.js b/packages/slate/test/commands/path/moveNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/inline.js rename to packages/slate/test/commands/path/moveNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/inside-next.js b/packages/slate/test/commands/path/moveNodeAtPath/inside-next.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/inside-next.js rename to packages/slate/test/commands/path/moveNodeAtPath/inside-next.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/nested.js b/packages/slate/test/commands/path/moveNodeAtPath/nested.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/nested.js rename to packages/slate/test/commands/path/moveNodeAtPath/nested.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/noop-equal.js b/packages/slate/test/commands/path/moveNodeAtPath/noop-equal.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/noop-equal.js rename to packages/slate/test/commands/path/moveNodeAtPath/noop-equal.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/sibling-swap.js b/packages/slate/test/commands/path/moveNodeAtPath/sibling-swap.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/sibling-swap.js rename to packages/slate/test/commands/path/moveNodeAtPath/sibling-swap.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/text-nodes.js b/packages/slate/test/commands/path/moveNodeAtPath/text-nodes.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/text-nodes.js rename to packages/slate/test/commands/path/moveNodeAtPath/text-nodes.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/text.js b/packages/slate/test/commands/path/moveNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/text.js rename to packages/slate/test/commands/path/moveNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/moveNodeAtPath/to-sibling.js b/packages/slate/test/commands/path/moveNodeAtPath/to-sibling.js similarity index 100% rename from packages/slate/test/commands/at-path/moveNodeAtPath/to-sibling.js rename to packages/slate/test/commands/path/moveNodeAtPath/to-sibling.js diff --git a/packages/slate/test/commands/at-path/pluckNodeAtPath/block-multiple.js b/packages/slate/test/commands/path/pluckNodeAtPath/block-multiple.js similarity index 100% rename from packages/slate/test/commands/at-path/pluckNodeAtPath/block-multiple.js rename to packages/slate/test/commands/path/pluckNodeAtPath/block-multiple.js diff --git a/packages/slate/test/commands/at-path/pluckNodeAtPath/block.js b/packages/slate/test/commands/path/pluckNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/pluckNodeAtPath/block.js rename to packages/slate/test/commands/path/pluckNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/removeNodeAtPath/block.js b/packages/slate/test/commands/path/removeNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/removeNodeAtPath/block.js rename to packages/slate/test/commands/path/removeNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/removeNodeAtPath/inline.js b/packages/slate/test/commands/path/removeNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/removeNodeAtPath/inline.js rename to packages/slate/test/commands/path/removeNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/removeNodeAtPath/selection-inside.js b/packages/slate/test/commands/path/removeNodeAtPath/selection-inside.js similarity index 100% rename from packages/slate/test/commands/at-path/removeNodeAtPath/selection-inside.js rename to packages/slate/test/commands/path/removeNodeAtPath/selection-inside.js diff --git a/packages/slate/test/commands/at-path/removeNodeAtPath/text.js b/packages/slate/test/commands/path/removeNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/removeNodeAtPath/text.js rename to packages/slate/test/commands/path/removeNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/replaceNodeAtPath/block.js b/packages/slate/test/commands/path/replaceNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/replaceNodeAtPath/block.js rename to packages/slate/test/commands/path/replaceNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/replaceNodeAtPath/inline.js b/packages/slate/test/commands/path/replaceNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/replaceNodeAtPath/inline.js rename to packages/slate/test/commands/path/replaceNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/replaceNodeAtPath/text.js b/packages/slate/test/commands/path/replaceNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/replaceNodeAtPath/text.js rename to packages/slate/test/commands/path/replaceNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/replaceTextAtPath/basic.js b/packages/slate/test/commands/path/replaceTextAtPath/basic.js similarity index 100% rename from packages/slate/test/commands/at-path/replaceTextAtPath/basic.js rename to packages/slate/test/commands/path/replaceTextAtPath/basic.js diff --git a/packages/slate/test/commands/at-path/setMarkAtPath/basic.js b/packages/slate/test/commands/path/setMarkAtPath/basic.js similarity index 100% rename from packages/slate/test/commands/at-path/setMarkAtPath/basic.js rename to packages/slate/test/commands/path/setMarkAtPath/basic.js diff --git a/packages/slate/test/commands/at-path/setNodeAtPath/block.js b/packages/slate/test/commands/path/setNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/setNodeAtPath/block.js rename to packages/slate/test/commands/path/setNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/setNodeAtPath/inline.js b/packages/slate/test/commands/path/setNodeAtPath/inline.js similarity index 100% rename from packages/slate/test/commands/at-path/setNodeAtPath/inline.js rename to packages/slate/test/commands/path/setNodeAtPath/inline.js diff --git a/packages/slate/test/commands/at-path/setNodeAtPath/text.js b/packages/slate/test/commands/path/setNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/setNodeAtPath/text.js rename to packages/slate/test/commands/path/setNodeAtPath/text.js diff --git a/packages/slate/test/commands/at-path/splitNodeAtPath/block.js b/packages/slate/test/commands/path/splitNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/splitNodeAtPath/block.js rename to packages/slate/test/commands/path/splitNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/splitNodeAtPath/selection.js b/packages/slate/test/commands/path/splitNodeAtPath/selection.js similarity index 100% rename from packages/slate/test/commands/at-path/splitNodeAtPath/selection.js rename to packages/slate/test/commands/path/splitNodeAtPath/selection.js diff --git a/packages/slate/test/commands/at-path/wrapNodeAtPath/block.js b/packages/slate/test/commands/path/wrapNodeAtPath/block.js similarity index 100% rename from packages/slate/test/commands/at-path/wrapNodeAtPath/block.js rename to packages/slate/test/commands/path/wrapNodeAtPath/block.js diff --git a/packages/slate/test/commands/at-path/wrapNodeAtPath/text.js b/packages/slate/test/commands/path/wrapNodeAtPath/text.js similarity index 100% rename from packages/slate/test/commands/at-path/wrapNodeAtPath/text.js rename to packages/slate/test/commands/path/wrapNodeAtPath/text.js From dd90c25844cb7e161b3717b1d8f5c058e5f27b7e Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 15 Oct 2019 17:49:22 -0400 Subject: [PATCH 036/165] get *AtPoint tests working --- .gitignore | 23 +----- packages/slate-hyperscript/src/creators.ts | 1 - packages/slate/src/classes/commands/path.ts | 76 ++++++++++--------- packages/slate/src/classes/commands/point.ts | 37 ++++----- packages/slate/src/classes/commands/range.ts | 8 +- packages/slate/src/classes/commands/value.ts | 21 +++-- packages/slate/src/classes/editor.ts | 6 +- packages/slate/src/classes/queries/element.ts | 49 ++++++++++++ packages/slate/src/classes/queries/node.ts | 48 ------------ packages/slate/src/classes/queries/path.ts | 33 ++++---- packages/slate/src/classes/queries/value.ts | 8 +- packages/slate/src/interfaces/point.ts | 34 +++++---- packages/slate/src/plugins/schema/plugin.ts | 46 ++--------- .../decoration-after-atomic.js | 10 ++- .../decoration-before-atomic.js | 20 ++--- .../decoration-middle-atomic.js | 16 ++-- .../insert-text-by-path/selection-after.js | 8 +- .../insert-text-by-path/selection-before.js | 8 +- .../insert-text-by-path/selection-end.js | 8 +- .../insert-text-by-path/selection-middle.js | 8 +- .../insert-text-by-path/selection-start.js | 8 +- .../text-end-with-marks.js | 31 -------- .../at-point/insert-text-by-path/text-end.js | 8 +- .../insert-text-by-path/text-middle.js | 8 +- .../text-start-with-marks.js | 31 -------- .../insert-text-by-path/text-start.js | 2 +- .../adjacent-non-void-inlines.js | 2 +- .../decoration-after-atomic.js | 14 ++-- .../decoration-before-atomic.js | 14 ++-- .../decoration-middle-atomic.js | 10 +-- .../inline-last-character.js | 2 +- .../inline-nested-last-character.js | 10 +-- .../remove-text-by-path/inline-void.js | 10 +-- .../at-point/remove-text-by-path/inline.js | 2 +- .../remove-text-by-path/next-void-inline.js | 10 ++- .../previous-void-inline.js | 10 ++- .../remove-text-by-path/selection-after.js | 2 +- .../remove-text-by-path/selection-before.js | 2 +- .../remove-text-by-path/selection-middle.js | 2 +- .../remove-text-by-path/selection-start.js | 2 +- .../at-point/remove-text-by-path/text.js | 2 +- .../at-point/replace-text-by-path/replace.js | 27 ------- .../replace-text-by-path/with-mark.js | 34 --------- .../block-with-selection.js | 34 --------- .../at-point/split-node-at-point/block.js | 18 ++--- .../at-point/split-node-at-point/inline.js | 35 +++++++++ .../at-point/split-node-at-point/selection.js | 28 +++++++ .../at-point/splitBlockAtPoint/block.js | 22 ++++++ .../selection.js} | 9 ++- .../at-point/splitInlineAtPoint/inline.js | 35 +++++++++ .../empty-after-void-inline.js | 28 ++++--- .../join-blocks-with-inline-void.js | 28 +++---- .../empty-before-void-inline.js | 28 ++++--- .../join-blocks-with-inline-void.js | 28 +++---- .../inline-multi-voids.js | 28 +++---- .../delete-line-backward/inline-void-first.js | 16 ++-- .../delete-line-forward/inline-multi-voids.js | 28 +++---- .../delete-line-forward/inline-void-end.js | 18 ++--- ...nline-as-first-with-non-void-block-next.js | 26 +++---- ...d-inline-as-first-with-non-void-sibling.js | 22 +++--- ...as-last-with-non-void-previous-siblings.js | 28 ++++--- .../insert-block/is-inline-void.js | 8 +- .../insert-fragment/inlines/middle-inline.js | 6 +- .../insert-inline-at-inline-middle.js | 6 +- .../middle-inline-fragment-inline.js | 6 +- .../start-block-with-void-no-text.js | 38 +++++----- .../words/adjacent-texts-after-void.js | 38 +++++----- .../with-intent/insert-inline/block-end.js | 20 ++--- .../with-intent/insert-inline/block-middle.js | 20 ++--- .../with-intent/insert-inline/block-start.js | 20 ++--- .../insert-inline/inline-middle.js | 28 +++---- .../with-intent/insert-inline/is-empty.js | 20 ++--- .../with-intent/insert-inline/with-inline.js | 20 ++--- .../with-intent/set-inline/across-inlines.js | 8 +- .../with-intent/set-inline/nested-inline.js | 8 +- .../single-inline-string-shorthand.js | 4 +- .../with-intent/set-inline/single-inline.js | 4 +- .../set-inline/with-data-object.js | 2 +- .../with-intent/set-inline/with-data.js | 2 +- .../with-intent/set-inline/with-is-void.js | 24 +++--- .../split-block/after-inline-void.js | 28 +++---- .../with-delete-across-blocks-and-inlines.js | 12 +-- .../unwrap-inline/across-blocks.js | 28 +++---- .../unwrap-inline/across-inlines.js | 52 ++++++------- .../with-intent/unwrap-inline/nested-block.js | 4 +- .../with-intent/unwrap-inline/only-one.js | 20 ++--- .../with-intent/unwrap-inline/single-block.js | 4 +- .../with-intent/unwrap-inline/with-object.js | 10 +-- .../with-intent/wrap-inline/across-blocks.js | 6 +- .../with-intent/wrap-inline/across-inlines.js | 4 +- .../with-intent/wrap-inline/collapsed.js | 4 +- .../with-intent/wrap-inline/inline-end.js | 4 +- .../wrap-inline/inline-middle-with-marks.js | 4 +- .../with-intent/wrap-inline/inline-middle.js | 4 +- .../with-intent/wrap-inline/inline-start.js | 4 +- .../with-intent/wrap-inline/inline-void.js | 26 +++---- .../with-intent/wrap-inline/nested-block.js | 4 +- .../with-intent/wrap-inline/single-block.js | 4 +- .../commands/with-intent/wrap-inline/twice.js | 4 +- .../with-intent/wrap-inline/whole-block.js | 4 +- .../with-intent/wrap-inline/with-object.js | 2 +- packages/slate/test/helpers/index.js | 29 +++---- 102 files changed, 774 insertions(+), 939 deletions(-) create mode 100644 packages/slate/src/classes/queries/element.ts delete mode 100644 packages/slate/src/classes/queries/node.ts delete mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js delete mode 100644 packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js delete mode 100644 packages/slate/test/commands/at-point/replace-text-by-path/replace.js delete mode 100644 packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js delete mode 100644 packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js create mode 100644 packages/slate/test/commands/at-point/split-node-at-point/inline.js create mode 100644 packages/slate/test/commands/at-point/split-node-at-point/selection.js create mode 100644 packages/slate/test/commands/at-point/splitBlockAtPoint/block.js rename packages/slate/test/commands/at-point/{insert-text-by-path/text-middle-with-marks.js => splitBlockAtPoint/selection.js} (63%) create mode 100644 packages/slate/test/commands/at-point/splitInlineAtPoint/inline.js diff --git a/.gitignore b/.gitignore index 94b19ed8a6..1b3c1617ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,7 @@ -# Build files. -*.js.map +*.log build/ dist/ lib/ - -# Temporary files. -tmp/ - -# Gitbook files. -_book/ - -# Package files. -lerna-debug.log node_modules/ -npm-debug.log -yarn-error.log packages/*/yarn.lock - -# OS files. -.DS_Store -.idea/ -.vscode/ - -# Editor files -.tern-port +tmp/ diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts index bb97534ee7..765dc44f4a 100644 --- a/packages/slate-hyperscript/src/creators.ts +++ b/packages/slate-hyperscript/src/creators.ts @@ -9,7 +9,6 @@ import { Text, Value, } from 'slate' -import { resolveDescendants } from './resolve-descendants' import { AnchorToken, AnnotationToken, diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 6d31283095..039a813917 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -198,11 +198,12 @@ class PathCommands { } // Determine whether the node should have block or inline children. - const hasBlockChildren = - Value.isValue(node) || - (this.isBlock(node) && - node.nodes.length !== 0 && - this.isBlock(node.nodes[0])) + const shouldHaveInlines = + Element.isElement(node) && + (this.isInline(node) || + node.nodes.length === 0 || + Text.isText(node.nodes[0]) || + this.isInline(node.nodes[0])) // Since we'll be applying operations while iterating, keep track of an // index that accounts for any added/removed nodes. @@ -210,44 +211,47 @@ class PathCommands { for (let i = 0; i < node.nodes.length; i++, n++) { const child = node.nodes[i] as Descendant + const prev: Descendant | undefined = node.nodes[i - 1] const isLast = i === node.nodes.length - 1 - // Only allow block nodes in the top-level value and parent blocks that - // only contain block nodes. Similarly, only allow inline nodes in other - // inline nodes, or parent blocks that only contain inlines and text. - if (this.isBlock(child) !== hasBlockChildren) { - this.removeNodeAtPath(path.concat(n)) - n-- - continue - } - - const prev: Descendant | undefined = node.nodes[i - 1] + if (Element.isElement(child)) { + const isInline = this.isInline(child) - // Ensure that inline nodes are surrounded by text nodes. - if (this.isInline(child)) { - if (prev == null || !Text.isText(prev)) { - this.insertNodeAtPath(path.concat(n), { text: '', marks: [] }) - n++ + // Only allow block nodes in the top-level value and parent blocks that + // only contain block nodes. Similarly, only allow inline nodes in other + // inline nodes, or parent blocks that only contain inlines and text. + if (isInline !== shouldHaveInlines) { + this.removeNodeAtPath(path.concat(n)) + n-- continue } - if (isLast) { - this.insertNodeAtPath(path.concat(n + 1), { text: '', marks: [] }) - n++ - continue + // Ensure that inline nodes are surrounded by text nodes. + if (isInline) { + if (prev == null || !Text.isText(prev)) { + this.insertNodeAtPath(path.concat(n), { text: '', marks: [] }) + n++ + continue + } + + if (isLast) { + this.insertNodeAtPath(path.concat(n + 1), { text: '', marks: [] }) + n++ + continue + } } - } - - // Merge adjacent text nodes that are empty or have matching marks. - if (prev != null && Text.isText(child) && Text.isText(prev)) { - if ( - prev.text === '' || - child.text === '' || - Text.matches(child, prev) - ) { - this.mergeNodeAtPath(path.concat(n)) - n-- - continue + } else { + // Merge adjacent text nodes that are empty or have matching marks. + if (prev != null && Text.isText(prev)) { + if ( + prev.text === '' || + child.text === '' || + Text.matches(child, prev) + ) { + this.mergeNodeAtPath(path.concat(n)) + n-- + continue + } } } } diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index 4a1c325c58..6a5bb82b1b 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -223,10 +223,10 @@ class PointCommands { // Ensure that the height isn't higher than the furthest inline, since // this command should never split any block nodes. const h = Math.max(furthestRelPath.length, height) - totalHeight = h + 1 + totalHeight = h } else { // If there are no inline ancestors, just split the text node. - totalHeight = 1 + totalHeight = 0 } this.splitNodeAtPoint(point, { height: totalHeight, ...rest }) @@ -250,14 +250,15 @@ class PointCommands { const { path, offset } = point const { height = 0, always = true } = options - if (height < path.length) { + if (height > path.length) { throw new Error( - `Cannot split the leaf node at path ${path} to a height of ${height} because it does not have that many ancestors.` + `Cannot split the leaf node at path [${path}] to a height of \`${height}\` because it does not have that many ancestors.` ) } this.withoutNormalizing(() => { let position = offset + let target: number | undefined let h = 0 // Create a ref that tracks the split point as we move up the ancestors. @@ -266,40 +267,28 @@ class PointCommands { const pointRef = this.createPointRef(point, { stick: 'backward' }) // Iterate up the ancestors, splitting each until the right depth. - while (h < height) { + while (h <= height) { + debugger const depth = path.length - h - const index = depth - 1 - const parentPath = path.slice(0, index) - const target = position - position = path[index] - h++ + const p = path.slice(0, depth) // With the `always: false` option, we will instead split the nodes only // when the point isn't already at it's edge. if ( !always && pointRef.current != null && - this.isAtEdgeOfPath(pointRef.current, parentPath) + this.isAtEdgeOfPath(pointRef.current, Path.parent(p)) ) { continue } - this.splitNodeAtPath(parentPath, position, { target }) + this.splitNodeAtPath(p, position, { target }) + target = position + position = path[depth - 1] + 1 + h++ } }) } - - /** - * Split the text node at a point. - */ - - splitTextAtPoint( - this: Editor, - point: Point, - options: { always?: boolean } = {} - ): void { - this.splitNodeAtPoint(point, { height: 0, ...options }) - } } export default PointCommands diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index 86ce0c111b..8d4c4987ef 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -10,8 +10,8 @@ class RangeCommands { this.withoutNormalizing(() => { const rangeRef = this.createRangeRef(range, { stick: 'inward' }) const [start, end] = Range.points(range) - this.splitTextAtPoint(end, { always: false }) - this.splitTextAtPoint(start, { always: false }) + this.splitNodeAtPoint(end, { always: false }) + this.splitNodeAtPoint(start, { always: false }) range = rangeRef.unref()! for (const [node, path] of this.texts({ range })) { @@ -320,7 +320,7 @@ class RangeCommands { // Iterate in reverse to ensure unwrapping doesn't affect path lookups. for (const [element, path] of this.blocks({ range, reverse: true })) { if (Element.matches(element, props)) { - this.unwrapChildrenAtPath(path) + this.pluckNodeAtPath(path) } } }) @@ -335,7 +335,7 @@ class RangeCommands { // Iterate in reverse to ensure unwrapping doesn't affect path lookups. for (const [element, path] of this.inlines({ range, reverse: true })) { if (Element.matches(element, props)) { - this.unwrapChildrenAtPath(path) + this.pluckNodeAtPath(path) } } }) diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts index 53814b8b72..446860214c 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/value.ts @@ -542,25 +542,17 @@ const getDirtyPaths = (op: Operation) => { case 'set_mark': case 'set_node': { const { path } = op - const ancestors = Path.ancestors(path) - return [...ancestors, path] + return Path.levels(path) } case 'insert_node': { const { node, path } = op + const levels = Path.levels(path) const descendants = Text.isText(node) ? [] : Array.from(Node.entries(node), ([, p]) => path.concat(p)) - const ancestors = Path.ancestors(path) - return [...ancestors, path, ...descendants] - } - - case 'split_node': { - const { path } = op - const ancestors = Path.ancestors(path) - const nextPath = Path.next(path) - return [...ancestors, path, nextPath] + return [...levels, ...descendants] } case 'merge_node': { @@ -599,6 +591,13 @@ const getDirtyPaths = (op: Operation) => { return [...ancestors] } + case 'split_node': { + const { path } = op + const levels = Path.levels(path) + const nextPath = Path.next(path) + return [...levels, nextPath] + } + default: { return [] } diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index daccae1837..e8d60c0f99 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -14,8 +14,8 @@ import PointCommands from './commands/point' import RangeCommands from './commands/range' import SelectionCommands from './commands/selection' import ValueCommands from './commands/value' +import ElementQueries from './queries/element' import MarkQueries from './queries/mark' -import NodeQueries from './queries/node' import PathQueries from './queries/path' import PointQueries from './queries/point' import RangeQueries from './queries/range' @@ -81,8 +81,8 @@ interface Editor RangeCommands, SelectionCommands, ValueCommands, + ElementQueries, MarkQueries, - NodeQueries, PathQueries, PointQueries, RangeQueries, @@ -105,8 +105,8 @@ mixin([ RangeCommands, SelectionCommands, ValueCommands, + ElementQueries, MarkQueries, - NodeQueries, PathQueries, PointQueries, RangeQueries, diff --git a/packages/slate/src/classes/queries/element.ts b/packages/slate/src/classes/queries/element.ts new file mode 100644 index 0000000000..5b3cd929d1 --- /dev/null +++ b/packages/slate/src/classes/queries/element.ts @@ -0,0 +1,49 @@ +import { Editor, Element, Text } from '../..' + +class ElementQueries { + /** + * Check if a node has block children. + */ + + hasBlocks(this: Editor, element: Element): boolean { + return element.nodes.every(n => Element.isElement(n) && !this.isInline(n)) + } + + /** + * Check if a node has inline and text children. + */ + + hasInlines(this: Editor, element: Element): boolean { + return element.nodes.every( + n => Text.isText(n) || (Element.isElement(n) && this.isInline(n)) + ) + } + + /** + * Check if a node has text children. + */ + + hasTexts(this: Editor, element: Element): boolean { + return element.nodes.every(n => Text.isText(n)) + } + + /** + * Check if a node is an inline, meaning that it lives intermixed with text + * nodes in the document tree. + */ + + isInline(this: Editor, element: Element): boolean { + return false + } + + /** + * Check if a node is a void, meaning that Slate considers its content a black + * box. It will be edited as if it has no content. + */ + + isVoid(this: Editor, element: Element): boolean { + return false + } +} + +export default ElementQueries diff --git a/packages/slate/src/classes/queries/node.ts b/packages/slate/src/classes/queries/node.ts deleted file mode 100644 index dc6e41f94e..0000000000 --- a/packages/slate/src/classes/queries/node.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { Editor, Node, Element, Text } from '../..' - -class NodeQueries { - /** - * Check if a node is a block, meaning it lives at the level above text nodes - * in the document tree. - */ - - isBlock(this: Editor, node: Node): node is Element { - return Element.isElement(node) - } - - /** - * Check if a node is an inline, meaning that it lives intermixed with text - * nodes in the document tree. - */ - - isInline(this: Editor, node: Node): node is Element { - return false - } - - /** - * Check if a node is a leaf block node. - */ - - isLeafBlock(this: Editor, node: Node): node is Element { - return this.isBlock(node) && !this.isBlock(node.nodes[0]) - } - - /** - * Check if a node is a leaf inline node. - */ - - isLeafInline(this: Editor, node: Node): node is Element { - return this.isInline(node) && node.nodes.every(n => Text.isText(n)) - } - - /** - * Check if a node is a void, meaning that Slate considers its content a black - * box. It will be edited as if it has no content. - */ - - isVoid(this: Editor, node: Node): node is Element { - return false - } -} - -export default NodeQueries diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 2e1154c175..79b7f1e477 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -1,6 +1,7 @@ import { produce } from 'immer' import { Editor, + Element, ElementEntry, Node, Operation, @@ -41,7 +42,7 @@ class PathQueries { getClosestBlock(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.levels(this.value, path)) { - if (this.isBlock(n)) { + if (Element.isElement(n) && !this.isInline(n)) { return [n, p] } } @@ -53,7 +54,7 @@ class PathQueries { getClosestInline(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.levels(this.value, path)) { - if (this.isInline(n)) { + if (Element.isElement(n) && this.isInline(n)) { return [n, p] } } @@ -65,7 +66,7 @@ class PathQueries { getClosestVoid(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.levels(this.value, path)) { - if (this.isVoid(n)) { + if (Element.isElement(n) && this.isVoid(n)) { return [n, p] } } @@ -110,7 +111,7 @@ class PathQueries { getFurthestBlock(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { - if (this.isBlock(n)) { + if (Element.isElement(n) && !this.isInline(n)) { return [n, p] } } @@ -122,7 +123,7 @@ class PathQueries { getFurthestInline(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { - if (this.isInline(n)) { + if (Element.isElement(n) && this.isInline(n)) { return [n, p] } } @@ -134,7 +135,7 @@ class PathQueries { getFurthestVoid(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { - if (this.isVoid(n)) { + if (Element.isElement(n) && this.isVoid(n)) { return [n, p] } } @@ -169,7 +170,7 @@ class PathQueries { getNextLeafBlock(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path })) { - if (this.isLeafBlock(n)) { + if (!this.isInline(n) && this.hasInlines(n)) { return [n, p] } } @@ -181,7 +182,7 @@ class PathQueries { getNextLeafInline(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path })) { - if (this.isLeafInline(n)) { + if (this.isInline(n) && this.hasTexts(n)) { return [n, p] } } @@ -193,7 +194,7 @@ class PathQueries { getNextRootBlock(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path })) { - if (this.isBlock(n) && p.length === 1) { + if (!this.isInline(n) && p.length === 1) { return [n, p] } } @@ -205,10 +206,10 @@ class PathQueries { getNextRootInline(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path })) { - if (this.isInline(n)) { + if (Element.isElement(n) && this.isInline(n)) { const parent = Node.parent(this.value, p) - if (this.isBlock(parent)) { + if (Element.isElement(parent) && !this.isInline(parent)) { return [n, p] } } @@ -231,7 +232,7 @@ class PathQueries { getPreviousLeafBlock(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (this.isLeafBlock(n)) { + if (!this.isInline(n) && this.hasInlines(n)) { return [n, p] } } @@ -243,7 +244,7 @@ class PathQueries { getPreviousLeafInline(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (this.isLeafInline(n)) { + if (this.isInline(n) && this.hasTexts(n)) { return [n, p] } } @@ -255,7 +256,7 @@ class PathQueries { getPreviousRootBlock(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (this.isBlock(n) && p.length === 1) { + if (!this.isInline(n) && p.length === 1) { return [n, p] } } @@ -267,10 +268,10 @@ class PathQueries { getPreviousRootInline(this: Editor, path: Path): ElementEntry | undefined { for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (this.isInline(n)) { + if (Element.isElement(n) && this.isInline(n)) { const parent = Node.parent(this.value, p) - if (this.isBlock(parent)) { + if (Element.isElement(parent) && !this.isInline(parent)) { return [n, p] } } diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 59ece20576..1ac5c8450a 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -20,7 +20,7 @@ class ValueQueries { *blocks(this: Editor, options: {} = {}): Iterable { for (const [n, p] of Node.elements(this.value, options)) { - if (this.isBlock(n)) { + if (!this.isInline(n)) { yield [n, p] } } @@ -136,7 +136,7 @@ class ValueQueries { *leafBlocks(this: Editor, options: {} = {}): Iterable { for (const [n, p] of this.blocks(options)) { - if (this.isLeafBlock(n)) { + if (this.hasInlines(n)) { yield [n, p] } } @@ -148,7 +148,7 @@ class ValueQueries { *leafInlines(this: Editor, options: {} = {}): Iterable { for (const [n, p] of this.inlines(options)) { - if (this.isLeafInline(n)) { + if (this.hasTexts(n)) { yield [n, p] } } @@ -310,7 +310,7 @@ class ValueQueries { for (const [n, p] of this.inlines(options)) { const parent = Node.parent(this.value, p) - if (this.isBlock(parent)) { + if (!this.isInline(parent)) { yield [n, p] } } diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts index e0bfd3012c..46191991ae 100755 --- a/packages/slate/src/interfaces/point.ts +++ b/packages/slate/src/interfaces/point.ts @@ -93,6 +93,12 @@ namespace Point { const { path, offset } = p switch (op.type) { + case 'insert_node': + case 'move_node': { + p.path = Path.transform(path, op, options)! + break + } + case 'insert_text': { if (Path.equals(op.path, path) && op.offset <= offset) { p.offset += op.text.length @@ -101,6 +107,15 @@ namespace Point { break } + case 'merge_node': { + if (Path.equals(op.path, path)) { + p.offset += op.position + } + + p.path = Path.transform(path, op, options)! + break + } + case 'remove_text': { if (Path.equals(op.path, path) && op.offset <= offset) { p.offset -= Math.min(offset - op.offset, op.text.length) @@ -127,25 +142,12 @@ namespace Point { (op.position === offset && stick === 'forward') ) { p.offset -= op.position + p.path = Path.transform(path, op, options)! } + } else { + p.path = Path.transform(path, op, options)! } - p.path = Path.transform(path, op, options)! - break - } - - case 'merge_node': { - if (Path.equals(op.path, path)) { - p.offset += op.position - } - - p.path = Path.transform(path, op, options)! - break - } - - case 'insert_node': - case 'move_node': { - p.path = Path.transform(path, op, options)! break } } diff --git a/packages/slate/src/plugins/schema/plugin.ts b/packages/slate/src/plugins/schema/plugin.ts index 7f49802f27..3d86a9046d 100644 --- a/packages/slate/src/plugins/schema/plugin.ts +++ b/packages/slate/src/plugins/schema/plugin.ts @@ -82,41 +82,11 @@ const SchemaPlugin = ( return super.isAtomic(mark) } - /** - * Check if a node is block based on the schema rules. - */ - - isBlock(this: Editor, node: Node): node is Element { - if (!Element.isElement(node)) { - return false - } - - // HACK: The node-checking logic needs a path for creating an error with - // details. But we don't care about the error, so we use a fake path. - const path: Path = [] - - for (const rule of rules) { - if ( - rule.define != null && - rule.define.isInline != null && - checkNode(node, path, rule.match, rules) == null - ) { - return !rule.define.isInline - } - } - - return super.isBlock(node) - } - /** * Check if a node is inline based on the schema rules. */ - isInline(this: Editor, node: Node): node is Element { - if (!Element.isElement(node)) { - return false - } - + isInline(this: Editor, element: Element): boolean { // HACK: The node-checking logic needs a path for creating an error with // details. But we don't care about the error, so we use a fake path. const path: Path = [] @@ -125,24 +95,20 @@ const SchemaPlugin = ( if ( rule.define != null && rule.define.isInline != null && - checkNode(node, path, rule.match, rules) == null + checkNode(element, path, rule.match, rules) == null ) { return rule.define.isInline } } - return super.isInline(node) + return super.isInline(element) } /** * Check if a node is void based on the schema rules. */ - isVoid(this: Editor, node: Node): node is Element { - if (!Element.isElement(node)) { - return false - } - + isVoid(this: Editor, element: Element): boolean { // HACK: The node-checking logic needs a path for creating an error with // details. But we don't care about the error, so we use a fake path. const path: Path = [] @@ -151,13 +117,13 @@ const SchemaPlugin = ( if ( rule.define != null && rule.define.isVoid != null && - checkNode(node, path, rule.match, rules) == null + checkNode(element, path, rule.match, rules) == null ) { return rule.define.isVoid } } - return super.isVoid(node) + return super.isVoid(element) } /** diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js index ade8a433ad..eb86e11309 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js @@ -5,19 +5,23 @@ import { h } from '../../../helpers' export const input = ( - word + w + or + d ) export const run = editor => { - editor.insertTextAtPath([0, 0], 4, 'x') + editor.insertTextAtPoint({ path: [0, 0], offset: 4 }, 'x') } export const output = ( - wordx + w + or + dx ) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js index f7f1f7a795..2413f7073a 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js @@ -2,28 +2,28 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 1, 'x') -} - -export const options = { - preserveDecorations: true, -} - export const input = ( - word + w + or + d ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 1 }, 'x') +} + export const output = ( - wxord + wx + or + d ) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js index 8c376c34ba..b2e76f2580 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js @@ -2,24 +2,22 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 2, 'x') -} - -export const options = { - preserveDecorations: true, -} - export const input = ( - word + w + or + d ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 2 }, 'x') +} + export const output = ( woxrd diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js index 466e6de621..c2e62331cd 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 4, 'x') -} - export const input = ( @@ -16,6 +12,10 @@ export const input = ( ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 4 }, 'x') +} + export const output = ( diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js index 9ae76376c1..735ae85e8b 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 0, 'x') -} - export const input = ( @@ -16,6 +12,10 @@ export const input = ( ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 0 }, 'x') +} + export const output = ( diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js index 440d5e7e1a..b59d68867e 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 3, 'x') -} - export const input = ( @@ -16,6 +12,10 @@ export const input = ( ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 3 }, 'x') +} + export const output = ( diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js index 56e58ff4f4..16c3160966 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 2, 'x') -} - export const input = ( @@ -16,6 +12,10 @@ export const input = ( ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 2 }, 'x') +} + export const output = ( diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js b/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js index e899217724..7607577bd5 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 1, 'x') -} - export const input = ( @@ -16,6 +12,10 @@ export const input = ( ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 1 }, 'x') +} + export const output = ( diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js deleted file mode 100644 index 93b9da44f6..0000000000 --- a/packages/slate/test/commands/at-point/insert-text-by-path/text-end-with-marks.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertTextAtPath([0, 0], 4, 'x') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - word - x - - - -) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js index 320a05bbcd..8d7557bc6e 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 4, 'x') -} - export const input = ( @@ -14,6 +10,10 @@ export const input = ( ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 4 }, 'x') +} + export const output = ( wordx diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js index 603d4d2fcc..ddbc6c95a8 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertTextAtPath([0, 0], 2, 'x') -} - export const input = ( @@ -14,6 +10,10 @@ export const input = ( ) +export const run = editor => { + editor.insertTextAtPoint({ path: [0, 0], offset: 2 }, 'x') +} + export const output = ( woxrd diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js deleted file mode 100644 index 6e47e54cca..0000000000 --- a/packages/slate/test/commands/at-point/insert-text-by-path/text-start-with-marks.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertTextAtPath([0, 0], 0, 'a') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - a - word - - - - -) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js b/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js index 2121bbe839..859ca1dfa0 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js +++ b/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertTextAtPath([0, 0], 0, 'a') + editor.insertTextAtPoint({ path: [0, 0], offset: 0 }, 'a') } export const input = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js b/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js index c56d220539..a77f2c8138 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js @@ -15,7 +15,7 @@ export const input = ( ) export const run = editor => { - editor.removeTextAtPath([0, 2], 0, 1) + editor.removeTextAtPoint({ path: [0, 2], offset: 0 }, 1) } export const output = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js index a70ba4b8af..14684dbd6d 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js @@ -3,18 +3,16 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 3, 1) -} - -export const options = { - preserveDecorations: true, + editor.removeTextAtPoint({ path: [0, 0], offset: 3 }, 1) } export const input = ( - word + w + or + d @@ -23,7 +21,9 @@ export const input = ( export const output = ( - wor + w + or + ) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js index 63b207cacb..433e40f58f 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js @@ -3,18 +3,16 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 0, 1) -} - -export const options = { - preserveDecorations: true, + editor.removeTextAtPoint({ path: [0, 0], offset: 0 }, 1) } export const input = ( - word + w + or + d @@ -23,7 +21,9 @@ export const input = ( export const output = ( - ord + + or + d ) diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js index cb0e6e6d3b..d351803d76 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js @@ -3,18 +3,16 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 2, 1) -} - -export const options = { - preserveDecorations: true, + editor.removeTextAtPoint({ path: [0, 0], offset: 2 }, 1) } export const input = ( - word + w + or + d diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js index 9e75d947e2..2c288535d7 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 1, 0], 0, 1) + editor.removeTextAtPoint({ path: [0, 1, 0], offset: 0 }, 1) } export const input = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js index ba6be8460b..9f45ae58e5 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 1, 1, 0], 0, 1) + editor.removeTextAtPoint({ path: [0, 1, 1, 0], offset: 0 }, 1) } export const input = ( @@ -12,11 +12,11 @@ export const input = ( - + a - + @@ -30,9 +30,9 @@ export const output = ( - + - + diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js index e1682182ce..6e8e14afdf 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js @@ -3,18 +3,18 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 1, 0], 0, 1) + editor.removeTextAtPoint({ path: [0, 1, 0], offset: 0 }, 1) } export const input = ( - + a - + @@ -24,9 +24,9 @@ export const output = ( - + - + diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline.js b/packages/slate/test/commands/at-point/remove-text-by-path/inline.js index 613e1ae3b6..17a361d8bc 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/inline.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 1, 0], 3, 1) + editor.removeTextAtPoint({ path: [0, 1, 0], offset: 3 }, 1) } export const input = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js b/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js index a5ac729f7d..c2856234c1 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 2], 0, 1) + editor.removeTextAtPoint({ path: [0, 2], offset: 0 }, 1) } export const input = ( @@ -12,7 +12,9 @@ export const input = ( one a - + + + @@ -24,7 +26,9 @@ export const output = ( one - + + + diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js b/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js index 8a9d9cd1a4..bcfac77de8 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js @@ -3,14 +3,16 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 2], 0, 1) + editor.removeTextAtPoint({ path: [0, 2], offset: 0 }, 1) } export const input = ( - + + + a two @@ -22,7 +24,9 @@ export const output = ( - + + + two diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js index b19a92cca0..dae6b7a2d7 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 3, 1) + editor.removeTextAtPoint({ path: [0, 0], offset: 3 }, 1) } export const input = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js index 2bb4b2dcf9..fe23dfb411 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 0, 1) + editor.removeTextAtPoint({ path: [0, 0], offset: 0 }, 1) } export const input = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js index 89cb92a670..4a3bb5cca0 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 2, 1) + editor.removeTextAtPoint({ path: [0, 0], offset: 2 }, 1) } export const input = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js b/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js index 25c1e1c12a..7efaebd178 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 2, 1) + editor.removeTextAtPoint({ path: [0, 0], offset: 2 }, 1) } export const input = ( diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/text.js b/packages/slate/test/commands/at-point/remove-text-by-path/text.js index cc5195effe..177b6fbca4 100644 --- a/packages/slate/test/commands/at-point/remove-text-by-path/text.js +++ b/packages/slate/test/commands/at-point/remove-text-by-path/text.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPath([0, 0], 3, 1) + editor.removeTextAtPoint({ path: [0, 0], offset: 3 }, 1) } export const input = ( diff --git a/packages/slate/test/commands/at-point/replace-text-by-path/replace.js b/packages/slate/test/commands/at-point/replace-text-by-path/replace.js deleted file mode 100644 index 781e3f7e5f..0000000000 --- a/packages/slate/test/commands/at-point/replace-text-by-path/replace.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.replaceTextAtPath([0, 0], 3, 1, 'three') -} - -export const input = ( - - - - onetwo - - - -) - -export const output = ( - - - - onethreewo - - - -) diff --git a/packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js b/packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js deleted file mode 100644 index 0ef2ab5189..0000000000 --- a/packages/slate/test/commands/at-point/replace-text-by-path/with-mark.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.replaceTextAtPath([0, 1], 0, 1, 'three', ['italic']) -} - -export const input = ( - - - - one - - two - - - - -) - -export const output = ( - - - - one - three - - wo - - - - -) diff --git a/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js b/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js deleted file mode 100644 index 62d0291129..0000000000 --- a/packages/slate/test/commands/at-point/split-node-at-point/block-with-selection.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - const { value: { document } } = editor - const point = document.createPoint({ path: [0, 0], offset: 2 }) - editor.splitNodeAtPoint(point, [0]) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wo - - - rd - - - -) diff --git a/packages/slate/test/commands/at-point/split-node-at-point/block.js b/packages/slate/test/commands/at-point/split-node-at-point/block.js index d76c980d9d..505ec92fdf 100644 --- a/packages/slate/test/commands/at-point/split-node-at-point/block.js +++ b/packages/slate/test/commands/at-point/split-node-at-point/block.js @@ -3,26 +3,20 @@ import { h } from '../../../helpers' export const run = editor => { - const { value: { document } } = editor - const point = document.createPoint({ path: [0, 0], offset: 2 }) - editor.splitNodeAtPoint(point, [0]) + editor.splitNodeAtPoint({ path: [0, 0], offset: 2 }, { height: 1 }) } export const input = ( - - - word - - + + word + ) export const output = ( - - wo - rd - + wo + rd ) diff --git a/packages/slate/test/commands/at-point/split-node-at-point/inline.js b/packages/slate/test/commands/at-point/split-node-at-point/inline.js new file mode 100644 index 0000000000..085efc1380 --- /dev/null +++ b/packages/slate/test/commands/at-point/split-node-at-point/inline.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodeAtPoint({ path: [0, 1, 0], offset: 2 }, { height: 1 }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + wo + + + + rd + + + + +) diff --git a/packages/slate/test/commands/at-point/split-node-at-point/selection.js b/packages/slate/test/commands/at-point/split-node-at-point/selection.js new file mode 100644 index 0000000000..79d4226bab --- /dev/null +++ b/packages/slate/test/commands/at-point/split-node-at-point/selection.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodeAtPoint({ path: [0, 0], offset: 2 }, { height: 1 }) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wo + + + rd + + +) diff --git a/packages/slate/test/commands/at-point/splitBlockAtPoint/block.js b/packages/slate/test/commands/at-point/splitBlockAtPoint/block.js new file mode 100644 index 0000000000..8c4718cc1e --- /dev/null +++ b/packages/slate/test/commands/at-point/splitBlockAtPoint/block.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitBlockAtPoint({ path: [0, 0], offset: 2 }) +} + +export const input = ( + + + word + + +) + +export const output = ( + + wo + rd + +) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-middle-with-marks.js b/packages/slate/test/commands/at-point/splitBlockAtPoint/selection.js similarity index 63% rename from packages/slate/test/commands/at-point/insert-text-by-path/text-middle-with-marks.js rename to packages/slate/test/commands/at-point/splitBlockAtPoint/selection.js index 9cc8bf9f8d..02430ebc96 100644 --- a/packages/slate/test/commands/at-point/insert-text-by-path/text-middle-with-marks.js +++ b/packages/slate/test/commands/at-point/splitBlockAtPoint/selection.js @@ -3,14 +3,14 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertTextAtPath([0, 0], 2, 'x', [{ type: 'bold' }]) + editor.splitBlockAtPoint({ path: [0, 0], offset: 2 }) } export const input = ( - word + word @@ -19,7 +19,10 @@ export const input = ( export const output = ( - woxrd + wo + + + rd ) diff --git a/packages/slate/test/commands/at-point/splitInlineAtPoint/inline.js b/packages/slate/test/commands/at-point/splitInlineAtPoint/inline.js new file mode 100644 index 0000000000..087ed791d7 --- /dev/null +++ b/packages/slate/test/commands/at-point/splitInlineAtPoint/inline.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitInlineAtPoint({ path: [0, 1, 0], offset: 2 }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + wo + + + + rd + + + + +) diff --git a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js index 5dfeddf6cc..ca0081772a 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js +++ b/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js @@ -8,26 +8,24 @@ export const run = editor => { export const input = ( - - + + + - - - - - - + + + + + ) export const output = ( - - - - - - - + + + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js index 5136ac4421..51039a307d 100644 --- a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js +++ b/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - - - - - - word - - + + + + + + + word + ) export const output = ( - - - - word - - + + + + + word + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js index 63278ccd8e..8ad7b3b2d1 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js +++ b/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js @@ -8,26 +8,24 @@ export const run = editor => { export const input = ( - - - - - - + + + + + - - + + + ) export const output = ( - - - - - - - + + + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js index df94f4f167..b9af8646a1 100644 --- a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js +++ b/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - - - word - - - - - + + word + + + + + + ) export const output = ( - - - word - - - + + word + + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js index 7b61e8ff3a..c28b4c8aec 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - 😊 - one - 😊 - two - 😀 - three - - - + + 😊 + one + 😊 + two + 😀 + three + + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js b/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js index 3908beec98..d01a99aa18 100644 --- a/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js +++ b/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js @@ -8,20 +8,16 @@ export const run = editor => { export const input = ( - - - 😊one two three - - + + 😊one two three + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js index 41b5856b6e..4a901f7689 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - - one - 😊 - two - 😊 - three - 😀 - - + + + one + 😊 + two + 😊 + three + 😀 + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js b/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js index e59ccbc316..fe6d3ae5b1 100644 --- a/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js +++ b/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js @@ -8,21 +8,17 @@ export const run = editor => { export const input = ( - - - - one two three😊 - - + + + one two three😊 + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js index d029248f9b..6173a7d1d0 100644 --- a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js +++ b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js @@ -8,25 +8,21 @@ export const run = editor => { export const input = ( - - - one - - two - - - three - - + + one + + two + + + three + ) export const output = ( - - - onethree - - + + onethree + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js index 504a7859af..5765ca2f07 100644 --- a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js +++ b/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js @@ -8,23 +8,19 @@ export const run = editor => { export const input = ( - - - - - - abc - - + + + + + abc + ) export const output = ( - - - abc - - + + abc + ) diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js b/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js index 94b8c0175d..ed59b1abdf 100644 --- a/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js +++ b/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js @@ -8,25 +8,23 @@ export const run = editor => { export const input = ( - - - Hi - - there - - - - - + + Hi + + there + + + + + + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js b/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js index 2ec2e63cee..2f7ffdc119 100644 --- a/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js +++ b/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js @@ -10,9 +10,9 @@ export const input = ( - + - + @@ -22,7 +22,9 @@ export const output = ( - + + + diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js index 57408af2dd..7e06e290b2 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js @@ -6,7 +6,7 @@ export const run = editor => { editor.insertFragment( - fragment + fragment ) @@ -29,9 +29,9 @@ export const output = ( wo - + fragment - + rd diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js index c714be33db..a6cf983bf2 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js @@ -6,7 +6,7 @@ export const run = editor => { editor.insertFragment( - fragment + fragment ) @@ -29,9 +29,9 @@ export const output = ( wo - + fragment - + rd diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js index c714be33db..a6cf983bf2 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js @@ -6,7 +6,7 @@ export const run = editor => { editor.insertFragment( - fragment + fragment ) @@ -29,9 +29,9 @@ export const output = ( wo - + fragment - + rd diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js b/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js index 69cce1abd1..6efcc8bbce 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js @@ -4,35 +4,33 @@ import { h } from '../../../helpers' export const run = editor => { editor.insertFragment( - - - one - two - - + + one + two + ) } export const input = ( - - - - - - + + + + + + ) export const output = ( - - - - - onetwo - - - + + + + + + onetwo + + ) diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js index 407e1d81da..8a47346840 100644 --- a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js +++ b/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js @@ -4,35 +4,33 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - one - two - - + + one + two + ) } export const input = ( - - - - - - + + + + + + ) export const output = ( - - - - - onetwo - - - + + + + + + onetwo + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-end.js b/packages/slate/test/commands/with-intent/insert-inline/block-end.js index 5a0fde0f55..df63771b9f 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/block-end.js +++ b/packages/slate/test/commands/with-intent/insert-inline/block-end.js @@ -8,22 +8,18 @@ export const run = editor => { export const input = ( - - - word - - + + word + ) export const output = ( - - - word - - - - + + word + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-middle.js b/packages/slate/test/commands/with-intent/insert-inline/block-middle.js index 8695c9443a..93e15b10bd 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/block-middle.js +++ b/packages/slate/test/commands/with-intent/insert-inline/block-middle.js @@ -8,22 +8,18 @@ export const run = editor => { export const input = ( - - - word - - + + word + ) export const output = ( - - - wo - - rd - - + + wo + + rd + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-start.js b/packages/slate/test/commands/with-intent/insert-inline/block-start.js index fea70a701d..353ad3ed0c 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/block-start.js +++ b/packages/slate/test/commands/with-intent/insert-inline/block-start.js @@ -8,22 +8,18 @@ export const run = editor => { export const input = ( - - - word - - + + word + ) export const output = ( - - - - - word - - + + + + word + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js b/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js index 7c9bc2e0ec..1cc9708703 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js +++ b/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - wo - - rd - - - + + + wo + + rd + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/is-empty.js b/packages/slate/test/commands/with-intent/insert-inline/is-empty.js index e3af58c608..6557d0d59f 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/is-empty.js +++ b/packages/slate/test/commands/with-intent/insert-inline/is-empty.js @@ -8,22 +8,18 @@ export const run = editor => { export const input = ( - - - - - + + + ) export const output = ( - - - - - - - + + + + + ) diff --git a/packages/slate/test/commands/with-intent/insert-inline/with-inline.js b/packages/slate/test/commands/with-intent/insert-inline/with-inline.js index 2b00787527..5323d1cf19 100644 --- a/packages/slate/test/commands/with-intent/insert-inline/with-inline.js +++ b/packages/slate/test/commands/with-intent/insert-inline/with-inline.js @@ -9,22 +9,18 @@ export const run = editor => { export const input = ( - - - word - - + + word + ) export const output = ( - - - wo - - rd - - + + wo + + rd + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/across-inlines.js b/packages/slate/test/commands/with-intent/set-inline/across-inlines.js index 6312e9232d..d12f645410 100644 --- a/packages/slate/test/commands/with-intent/set-inline/across-inlines.js +++ b/packages/slate/test/commands/with-intent/set-inline/across-inlines.js @@ -27,14 +27,14 @@ export const output = ( - + word - + - + another - + diff --git a/packages/slate/test/commands/with-intent/set-inline/nested-inline.js b/packages/slate/test/commands/with-intent/set-inline/nested-inline.js index 333ebbae8d..b707bc8bed 100644 --- a/packages/slate/test/commands/with-intent/set-inline/nested-inline.js +++ b/packages/slate/test/commands/with-intent/set-inline/nested-inline.js @@ -10,11 +10,11 @@ export const input = ( - + word - + @@ -24,11 +24,11 @@ export const output = ( - + word - + diff --git a/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js b/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js index c665332576..afb841d6eb 100644 --- a/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js +++ b/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js @@ -22,9 +22,9 @@ export const output = ( - + word - + diff --git a/packages/slate/test/commands/with-intent/set-inline/single-inline.js b/packages/slate/test/commands/with-intent/set-inline/single-inline.js index 7980201308..b7b590f9d4 100644 --- a/packages/slate/test/commands/with-intent/set-inline/single-inline.js +++ b/packages/slate/test/commands/with-intent/set-inline/single-inline.js @@ -22,9 +22,9 @@ export const output = ( - + word - + diff --git a/packages/slate/test/commands/with-intent/set-inline/with-data-object.js b/packages/slate/test/commands/with-intent/set-inline/with-data-object.js index 811b680597..fd94671152 100644 --- a/packages/slate/test/commands/with-intent/set-inline/with-data-object.js +++ b/packages/slate/test/commands/with-intent/set-inline/with-data-object.js @@ -27,7 +27,7 @@ export const output = ( word - + diff --git a/packages/slate/test/commands/with-intent/set-inline/with-data.js b/packages/slate/test/commands/with-intent/set-inline/with-data.js index 2923b26501..5f2c08cedb 100644 --- a/packages/slate/test/commands/with-intent/set-inline/with-data.js +++ b/packages/slate/test/commands/with-intent/set-inline/with-data.js @@ -25,7 +25,7 @@ export const output = ( word - + ) diff --git a/packages/slate/test/commands/with-intent/set-inline/with-is-void.js b/packages/slate/test/commands/with-intent/set-inline/with-is-void.js index 0fb9fda72b..5e1f205e33 100644 --- a/packages/slate/test/commands/with-intent/set-inline/with-is-void.js +++ b/packages/slate/test/commands/with-intent/set-inline/with-is-void.js @@ -8,24 +8,20 @@ export const run = editor => { export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - word - - - + + + word + + ) diff --git a/packages/slate/test/commands/with-intent/split-block/after-inline-void.js b/packages/slate/test/commands/with-intent/split-block/after-inline-void.js index 6f145cd2d5..339d1bbe3a 100644 --- a/packages/slate/test/commands/with-intent/split-block/after-inline-void.js +++ b/packages/slate/test/commands/with-intent/split-block/after-inline-void.js @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - - - one - two - - + + one + + + two + ) export const output = ( - - - one - - - two - - + + one + + + + + two + ) diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js index c9724f6118..0032e9fa6b 100644 --- a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js +++ b/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js @@ -18,9 +18,9 @@ export const input = ( - + another - + @@ -34,16 +34,16 @@ export const output = ( wo - + - + - + other - + diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js index 9ba22b65d5..874dc7eb0e 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - word - - - another - - + + word + + + another + ) export const output = ( - - - word - - - another - - + + word + + + another + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js index 78ad57b7b2..900037568e 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js @@ -8,38 +8,34 @@ export const run = editor => { export const input = ( - - - - wo - - - rd - - - an - - - other - - - + + + wo + + + rd + + + an + + + other + + ) export const output = ( - - - - wo - - rd - an - - other - - - + + + wo + + rd + an + + other + + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js b/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js index 204f5fb19c..d13258acb8 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js @@ -12,9 +12,9 @@ export const input = ( w - + or - d + d diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js b/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js index b7c1a39bb7..18cec822c5 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js @@ -8,22 +8,18 @@ export const run = editor => { export const input = ( - - - hello w - or - d - - + + hello w + or + d + ) export const output = ( - - - hello word - - + + hello word + ) diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js b/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js index 419b516f61..83e48cdaa6 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js @@ -11,9 +11,9 @@ export const input = ( w - + or - d + d diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js b/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js index 039ee3d1dc..c58322dddd 100644 --- a/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js +++ b/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js @@ -14,10 +14,10 @@ export const input = ( w - + or - - d + + d @@ -27,9 +27,9 @@ export const output = ( - w + w or - d + d diff --git a/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js b/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js index ccb5847796..dbbce905d7 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js @@ -23,14 +23,14 @@ export const output = ( - wo + wo rd - + - an + an other diff --git a/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js b/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js index 876f6e4c10..374c98edad 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js @@ -26,12 +26,12 @@ export const output = ( wo - + rd an - + other diff --git a/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js b/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js index d4c17ce87c..421b29bd7d 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js @@ -20,9 +20,9 @@ export const output = ( - w + w - + d diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js index 86eec29e93..f5555e1d1e 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js @@ -27,13 +27,13 @@ export const output = ( hel - + lo - + diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js index c01c4418d7..fa887e6f42 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js @@ -32,13 +32,13 @@ export const output = ( he - + ll - + diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js index ef5e4f1a9e..5a8e838d11 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js @@ -28,11 +28,11 @@ export const output = ( he - + ll - + o diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js index 55690b9f5a..dc94658489 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js @@ -25,13 +25,13 @@ export const output = ( - + hel - + lo diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js b/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js index d75ba289d0..c2adddda77 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - - - - - + + + + + ) export const output = ( - - - - - - + + + + - - + + ) diff --git a/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js b/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js index 3bc66ab844..ea0077023f 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js @@ -23,9 +23,9 @@ export const output = ( - w + w or - + d diff --git a/packages/slate/test/commands/with-intent/wrap-inline/single-block.js b/packages/slate/test/commands/with-intent/wrap-inline/single-block.js index c723370625..c31bd8b7dd 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/single-block.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/single-block.js @@ -20,9 +20,9 @@ export const output = ( - w + w or - + d diff --git a/packages/slate/test/commands/with-intent/wrap-inline/twice.js b/packages/slate/test/commands/with-intent/wrap-inline/twice.js index 4e6c37c19d..3f131bcae9 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/twice.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/twice.js @@ -22,13 +22,13 @@ export const output = ( w - + or - + d diff --git a/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js b/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js index 8ec7693213..6495044ee1 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js @@ -20,9 +20,9 @@ export const output = ( - + word - + diff --git a/packages/slate/test/commands/with-intent/wrap-inline/with-object.js b/packages/slate/test/commands/with-intent/wrap-inline/with-object.js index 171b3f2b63..561d63d2f1 100644 --- a/packages/slate/test/commands/with-intent/wrap-inline/with-object.js +++ b/packages/slate/test/commands/with-intent/wrap-inline/with-object.js @@ -25,7 +25,7 @@ export const output = ( w or - + d diff --git a/packages/slate/test/helpers/index.js b/packages/slate/test/helpers/index.js index ecca38d1cf..fec56e21aa 100644 --- a/packages/slate/test/helpers/index.js +++ b/packages/slate/test/helpers/index.js @@ -3,32 +3,33 @@ import { createHyperscript } from 'slate-hyperscript' const h = createHyperscript({ elements: { - block: { kind: 'block' }, - inline: { kind: 'inline' }, - void_block: { kind: 'void_block' }, - void_inline: { kind: 'void_inline' }, - }, - annotations: { - atomic_annotation: { kind: 'atomic_annotation' }, + block: {}, + inline: { inline: true }, }, }) const TestPlugin = Editor => { return class extends Editor { + isAtomic(mark) { + return mark.atomic === true ? true : super.isAtomic(mark) + } + isBlock(node) { - return Element.isElement(node) && node.kind.endsWith('block') + return Element.isElement(node) && node.inline !== true + ? true + : super.isBlock(node) } isInline(node) { - return Element.isElement(node) && node.kind.endsWith('inline') + return Element.isElement(node) && node.inline === true + ? true + : super.isInline(node) } isVoid(node) { - return Element.isElement(node) && node.kind.startsWith('void_') - } - - isAtomic(mark) { - return mark.kind.startsWith('atomic_') + return Element.isElement(node) && node.void === true + ? true + : super.isVoid(node) } } } From 0c9b1f8aa8e063bfded56717182dcaddb3cb5a0e Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 15 Oct 2019 17:49:45 -0400 Subject: [PATCH 037/165] rename --- .../insertTextAtPoint}/decoration-after-atomic.js | 0 .../insertTextAtPoint}/decoration-before-atomic.js | 0 .../insertTextAtPoint}/decoration-middle-atomic.js | 0 .../insertTextAtPoint}/selection-after.js | 0 .../insertTextAtPoint}/selection-before.js | 0 .../insertTextAtPoint}/selection-end.js | 0 .../insertTextAtPoint}/selection-middle.js | 0 .../insertTextAtPoint}/selection-start.js | 0 .../insert-text-by-path => point/insertTextAtPoint}/text-end.js | 0 .../insertTextAtPoint}/text-middle.js | 0 .../insert-text-by-path => point/insertTextAtPoint}/text-start.js | 0 .../removeTextAtPoint}/adjacent-non-void-inlines.js | 0 .../removeTextAtPoint}/decoration-after-atomic.js | 0 .../removeTextAtPoint}/decoration-before-atomic.js | 0 .../removeTextAtPoint}/decoration-middle-atomic.js | 0 .../removeTextAtPoint}/inline-last-character.js | 0 .../removeTextAtPoint}/inline-nested-last-character.js | 0 .../removeTextAtPoint}/inline-void.js | 0 .../remove-text-by-path => point/removeTextAtPoint}/inline.js | 0 .../removeTextAtPoint}/next-void-inline.js | 0 .../removeTextAtPoint}/previous-void-inline.js | 0 .../removeTextAtPoint}/selection-after.js | 0 .../removeTextAtPoint}/selection-before.js | 0 .../removeTextAtPoint}/selection-middle.js | 0 .../removeTextAtPoint}/selection-start.js | 0 .../remove-text-by-path => point/removeTextAtPoint}/text.js | 0 .../test/commands/{at-point => point}/splitBlockAtPoint/block.js | 0 .../commands/{at-point => point}/splitBlockAtPoint/selection.js | 0 .../commands/{at-point => point}/splitInlineAtPoint/inline.js | 0 .../split-node-at-point => point/splitNodeAtPoint}/block.js | 0 .../split-node-at-point => point/splitNodeAtPoint}/inline.js | 0 .../split-node-at-point => point/splitNodeAtPoint}/selection.js | 0 32 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/decoration-after-atomic.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/decoration-before-atomic.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/decoration-middle-atomic.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/selection-after.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/selection-before.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/selection-end.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/selection-middle.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/selection-start.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/text-end.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/text-middle.js (100%) rename packages/slate/test/commands/{at-point/insert-text-by-path => point/insertTextAtPoint}/text-start.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/adjacent-non-void-inlines.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/decoration-after-atomic.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/decoration-before-atomic.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/decoration-middle-atomic.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/inline-last-character.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/inline-nested-last-character.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/inline-void.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/inline.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/next-void-inline.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/previous-void-inline.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/selection-after.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/selection-before.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/selection-middle.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/selection-start.js (100%) rename packages/slate/test/commands/{at-point/remove-text-by-path => point/removeTextAtPoint}/text.js (100%) rename packages/slate/test/commands/{at-point => point}/splitBlockAtPoint/block.js (100%) rename packages/slate/test/commands/{at-point => point}/splitBlockAtPoint/selection.js (100%) rename packages/slate/test/commands/{at-point => point}/splitInlineAtPoint/inline.js (100%) rename packages/slate/test/commands/{at-point/split-node-at-point => point/splitNodeAtPoint}/block.js (100%) rename packages/slate/test/commands/{at-point/split-node-at-point => point/splitNodeAtPoint}/inline.js (100%) rename packages/slate/test/commands/{at-point/split-node-at-point => point/splitNodeAtPoint}/selection.js (100%) diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/point/insertTextAtPoint/decoration-after-atomic.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/decoration-after-atomic.js rename to packages/slate/test/commands/point/insertTextAtPoint/decoration-after-atomic.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/point/insertTextAtPoint/decoration-before-atomic.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/decoration-before-atomic.js rename to packages/slate/test/commands/point/insertTextAtPoint/decoration-before-atomic.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/point/insertTextAtPoint/decoration-middle-atomic.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/decoration-middle-atomic.js rename to packages/slate/test/commands/point/insertTextAtPoint/decoration-middle-atomic.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js b/packages/slate/test/commands/point/insertTextAtPoint/selection-after.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/selection-after.js rename to packages/slate/test/commands/point/insertTextAtPoint/selection-after.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js b/packages/slate/test/commands/point/insertTextAtPoint/selection-before.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/selection-before.js rename to packages/slate/test/commands/point/insertTextAtPoint/selection-before.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js b/packages/slate/test/commands/point/insertTextAtPoint/selection-end.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/selection-end.js rename to packages/slate/test/commands/point/insertTextAtPoint/selection-end.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js b/packages/slate/test/commands/point/insertTextAtPoint/selection-middle.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/selection-middle.js rename to packages/slate/test/commands/point/insertTextAtPoint/selection-middle.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js b/packages/slate/test/commands/point/insertTextAtPoint/selection-start.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/selection-start.js rename to packages/slate/test/commands/point/insertTextAtPoint/selection-start.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-end.js b/packages/slate/test/commands/point/insertTextAtPoint/text-end.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/text-end.js rename to packages/slate/test/commands/point/insertTextAtPoint/text-end.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js b/packages/slate/test/commands/point/insertTextAtPoint/text-middle.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/text-middle.js rename to packages/slate/test/commands/point/insertTextAtPoint/text-middle.js diff --git a/packages/slate/test/commands/at-point/insert-text-by-path/text-start.js b/packages/slate/test/commands/point/insertTextAtPoint/text-start.js similarity index 100% rename from packages/slate/test/commands/at-point/insert-text-by-path/text-start.js rename to packages/slate/test/commands/point/insertTextAtPoint/text-start.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js b/packages/slate/test/commands/point/removeTextAtPoint/adjacent-non-void-inlines.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/adjacent-non-void-inlines.js rename to packages/slate/test/commands/point/removeTextAtPoint/adjacent-non-void-inlines.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js b/packages/slate/test/commands/point/removeTextAtPoint/decoration-after-atomic.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/decoration-after-atomic.js rename to packages/slate/test/commands/point/removeTextAtPoint/decoration-after-atomic.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js b/packages/slate/test/commands/point/removeTextAtPoint/decoration-before-atomic.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/decoration-before-atomic.js rename to packages/slate/test/commands/point/removeTextAtPoint/decoration-before-atomic.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js b/packages/slate/test/commands/point/removeTextAtPoint/decoration-middle-atomic.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/decoration-middle-atomic.js rename to packages/slate/test/commands/point/removeTextAtPoint/decoration-middle-atomic.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js b/packages/slate/test/commands/point/removeTextAtPoint/inline-last-character.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/inline-last-character.js rename to packages/slate/test/commands/point/removeTextAtPoint/inline-last-character.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js b/packages/slate/test/commands/point/removeTextAtPoint/inline-nested-last-character.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/inline-nested-last-character.js rename to packages/slate/test/commands/point/removeTextAtPoint/inline-nested-last-character.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js b/packages/slate/test/commands/point/removeTextAtPoint/inline-void.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/inline-void.js rename to packages/slate/test/commands/point/removeTextAtPoint/inline-void.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/inline.js b/packages/slate/test/commands/point/removeTextAtPoint/inline.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/inline.js rename to packages/slate/test/commands/point/removeTextAtPoint/inline.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js b/packages/slate/test/commands/point/removeTextAtPoint/next-void-inline.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/next-void-inline.js rename to packages/slate/test/commands/point/removeTextAtPoint/next-void-inline.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js b/packages/slate/test/commands/point/removeTextAtPoint/previous-void-inline.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/previous-void-inline.js rename to packages/slate/test/commands/point/removeTextAtPoint/previous-void-inline.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js b/packages/slate/test/commands/point/removeTextAtPoint/selection-after.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/selection-after.js rename to packages/slate/test/commands/point/removeTextAtPoint/selection-after.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js b/packages/slate/test/commands/point/removeTextAtPoint/selection-before.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/selection-before.js rename to packages/slate/test/commands/point/removeTextAtPoint/selection-before.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js b/packages/slate/test/commands/point/removeTextAtPoint/selection-middle.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/selection-middle.js rename to packages/slate/test/commands/point/removeTextAtPoint/selection-middle.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js b/packages/slate/test/commands/point/removeTextAtPoint/selection-start.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/selection-start.js rename to packages/slate/test/commands/point/removeTextAtPoint/selection-start.js diff --git a/packages/slate/test/commands/at-point/remove-text-by-path/text.js b/packages/slate/test/commands/point/removeTextAtPoint/text.js similarity index 100% rename from packages/slate/test/commands/at-point/remove-text-by-path/text.js rename to packages/slate/test/commands/point/removeTextAtPoint/text.js diff --git a/packages/slate/test/commands/at-point/splitBlockAtPoint/block.js b/packages/slate/test/commands/point/splitBlockAtPoint/block.js similarity index 100% rename from packages/slate/test/commands/at-point/splitBlockAtPoint/block.js rename to packages/slate/test/commands/point/splitBlockAtPoint/block.js diff --git a/packages/slate/test/commands/at-point/splitBlockAtPoint/selection.js b/packages/slate/test/commands/point/splitBlockAtPoint/selection.js similarity index 100% rename from packages/slate/test/commands/at-point/splitBlockAtPoint/selection.js rename to packages/slate/test/commands/point/splitBlockAtPoint/selection.js diff --git a/packages/slate/test/commands/at-point/splitInlineAtPoint/inline.js b/packages/slate/test/commands/point/splitInlineAtPoint/inline.js similarity index 100% rename from packages/slate/test/commands/at-point/splitInlineAtPoint/inline.js rename to packages/slate/test/commands/point/splitInlineAtPoint/inline.js diff --git a/packages/slate/test/commands/at-point/split-node-at-point/block.js b/packages/slate/test/commands/point/splitNodeAtPoint/block.js similarity index 100% rename from packages/slate/test/commands/at-point/split-node-at-point/block.js rename to packages/slate/test/commands/point/splitNodeAtPoint/block.js diff --git a/packages/slate/test/commands/at-point/split-node-at-point/inline.js b/packages/slate/test/commands/point/splitNodeAtPoint/inline.js similarity index 100% rename from packages/slate/test/commands/at-point/split-node-at-point/inline.js rename to packages/slate/test/commands/point/splitNodeAtPoint/inline.js diff --git a/packages/slate/test/commands/at-point/split-node-at-point/selection.js b/packages/slate/test/commands/point/splitNodeAtPoint/selection.js similarity index 100% rename from packages/slate/test/commands/at-point/split-node-at-point/selection.js rename to packages/slate/test/commands/point/splitNodeAtPoint/selection.js From ee6b08d3a61a1d7b7fb7947aca6bce391488cebe Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 15 Oct 2019 17:50:18 -0400 Subject: [PATCH 038/165] rename --- .../commands/{with-intent => value}/add-mark/across-blocks.js | 0 .../commands/{with-intent => value}/add-mark/across-inlines.js | 0 .../{with-intent => value}/add-mark/collapsed-selection-end.js | 0 .../{with-intent => value}/add-mark/collapsed-selection-middle.js | 0 .../{with-intent => value}/add-mark/collapsed-selection-start.js | 0 .../add-mark/existing-marks-across-blocks-at-edge.js | 0 .../add-mark/existing-marks-across-blocks.js | 0 .../commands/{with-intent => value}/add-mark/existing-marks.js | 0 .../commands/{with-intent => value}/add-mark/first-character.js | 0 .../commands/{with-intent => value}/add-mark/last-character.js | 0 .../commands/{with-intent => value}/add-mark/middle-character.js | 0 .../test/commands/{with-intent => value}/add-mark/whole-word.js | 0 .../commands/{with-intent => value}/add-mark/with-mark-object.js | 0 .../commands/{with-intent => value}/add-mark/with-plain-object.js | 0 .../commands/{with-intent => value}/add-marks/across-blocks.js | 0 .../commands/{with-intent => value}/add-marks/across-inlines.js | 0 .../commands/{with-intent => value}/add-marks/across-marks.js | 0 .../{with-intent => value}/add-marks/collapsed-selection-end.js | 0 .../add-marks/collapsed-selection-middle.js | 0 .../{with-intent => value}/add-marks/collapsed-selection-start.js | 0 .../commands/{with-intent => value}/add-marks/first-character.js | 0 .../test/commands/{with-intent => value}/add-marks/inside-mark.js | 0 .../commands/{with-intent => value}/add-marks/last-character.js | 0 .../commands/{with-intent => value}/add-marks/middle-character.js | 0 .../test/commands/{with-intent => value}/add-marks/whole-word.js | 0 .../commands/{with-intent => value}/add-marks/with-mark-object.js | 0 .../{with-intent => value}/add-marks/with-plain-object.js | 0 .../delete-backward/empty-after-void-block.js | 0 .../delete-backward/empty-after-void-inline.js | 0 .../{with-intent => value}/delete-backward/first-character.js | 0 .../{with-intent => value}/delete-backward/inline-after.js | 0 .../{with-intent => value}/delete-backward/inline-before.js | 0 .../commands/{with-intent => value}/delete-backward/inline-end.js | 0 .../{with-intent => value}/delete-backward/inline-inside.js | 0 .../delete-backward/join-blocks-from-inline.js | 0 .../delete-backward/join-blocks-with-inline-void.js | 0 .../delete-backward/join-blocks-with-inline.js | 0 .../{with-intent => value}/delete-backward/join-blocks.js | 0 .../delete-backward/join-nested-blocks-different-depth.js | 0 .../{with-intent => value}/delete-backward/join-nested-blocks.js | 0 .../{with-intent => value}/delete-backward/last-character.js | 0 .../{with-intent => value}/delete-backward/middle-character.js | 0 .../{with-intent => value}/delete-backward/multiple-characters.js | 0 .../delete-backward/single-non-void-block.js | 0 .../{with-intent => value}/delete-backward/single-void-block.js | 0 .../{with-intent => value}/delete-backward/start-of-document.js | 0 .../delete-char-backward/inline-after-emoji.js | 0 .../delete-char-backward/inline-end-emoji.js | 0 .../delete-char-backward/inline-inside-emoji.js | 0 .../delete-char-backward/inline-only-emoji.js | 0 .../{with-intent => value}/delete-char-backward/text-end.js | 0 .../{with-intent => value}/delete-char-backward/text-middle.js | 0 .../{with-intent => value}/delete-char-backward/text-start.js | 0 .../delete-char-forward/inline-before-emoji.js | 0 .../delete-char-forward/inline-middle-emoji.js | 0 .../delete-char-forward/inline-start-emoji.js | 0 .../{with-intent => value}/delete-char-forward/text-last.js | 0 .../{with-intent => value}/delete-char-forward/text-middle.js | 0 .../{with-intent => value}/delete-char-forward/text-start.js | 0 .../delete-forward/before-inline-sibling.js | 0 .../delete-forward/empty-before-void-block.js | 0 .../delete-forward/empty-before-void-inline.js | 0 .../{with-intent => value}/delete-forward/end-of-document.js | 0 .../{with-intent => value}/delete-forward/first-character.js | 0 .../delete-forward/inside-inline-sibling.js | 0 .../delete-forward/join-blocks-with-inline-void.js | 0 .../delete-forward/join-blocks-with-inline.js | 0 .../commands/{with-intent => value}/delete-forward/join-blocks.js | 0 .../{with-intent => value}/delete-forward/join-nested-blocks.js | 0 .../{with-intent => value}/delete-forward/last-character.js | 0 .../{with-intent => value}/delete-forward/middle-character.js | 0 .../{with-intent => value}/delete-forward/multiple-characters.js | 0 .../delete-forward/single-non-void-block.js | 0 .../{with-intent => value}/delete-forward/single-void-block.js | 0 .../delete-forward/start-text-middle-inline.js | 0 .../delete-line-backward/inline-middle-emoji.js | 0 .../delete-line-backward/inline-multi-voids.js | 0 .../delete-line-backward/inline-void-first.js | 0 .../{with-intent => value}/delete-line-backward/text-end.js | 0 .../{with-intent => value}/delete-line-backward/text-start.js | 0 .../{with-intent => value}/delete-line-backward/word-middle.js | 0 .../delete-line-forward/inline-middle-emoji.js | 0 .../delete-line-forward/inline-multi-voids.js | 0 .../{with-intent => value}/delete-line-forward/inline-void-end.js | 0 .../{with-intent => value}/delete-line-forward/text-end.js | 0 .../{with-intent => value}/delete-line-forward/text-start.js | 0 .../{with-intent => value}/delete-line-forward/word-middle.js | 0 .../delete-word-backward/inline-after-emoji.js | 0 .../delete-word-backward/inline-middle-emoji.js | 0 .../{with-intent => value}/delete-word-backward/join-blocks.js | 0 .../{with-intent => value}/delete-word-backward/text-end.js | 0 .../{with-intent => value}/delete-word-backward/word-middle.js | 0 .../delete-word-forward/inline-after-emoji.js | 0 .../delete-word-forward/inline-middle-emoji.js | 0 .../{with-intent => value}/delete-word-forward/join-blocks.js | 0 .../{with-intent => value}/delete-word-forward/word-middle.js | 0 .../{with-intent => value}/delete-word-forward/word-start.js | 0 .../{with-intent => value}/delete/across-blocks-inlines.js | 0 .../test/commands/{with-intent => value}/delete/across-blocks.js | 0 .../test/commands/{with-intent => value}/delete/across-depths.js | 0 .../{with-intent => value}/delete/across-nested-blocks.js | 0 .../{with-intent => value}/delete/across-texts-and-inlines.js | 0 .../commands/{with-intent => value}/delete/all-nested-blocks.js | 0 .../{with-intent => value}/delete/before-inline-sibling.js | 0 .../{with-intent => value}/delete/expanded-across-whole-mark.js | 0 .../commands/{with-intent => value}/delete/first-character.js | 0 .../test/commands/{with-intent => value}/delete/first-position.js | 0 .../delete/hanging-selection-multiple-blocks.js | 0 .../delete/hanging-selection-single-block.js | 0 .../{with-intent => value}/delete/inside-inline-sibling.js | 0 .../test/commands/{with-intent => value}/delete/inside-inline.js | 0 .../{with-intent => value}/delete/join-blocks-and-trim.js | 0 .../{with-intent => value}/delete/join-blocks-with-inlines.js | 0 .../test/commands/{with-intent => value}/delete/join-blocks.js | 0 .../{with-intent => value}/delete/join-double-nested-blocks.js | 0 .../commands/{with-intent => value}/delete/join-nested-blocks.js | 0 .../test/commands/{with-intent => value}/delete/last-character.js | 0 .../commands/{with-intent => value}/delete/middle-character.js | 0 .../test/commands/{with-intent => value}/delete/nested-block.js | 0 .../non-void-block-as-first-with-void-siblings-only-non-void.js | 0 ...th-void-siblings-partially-non-void-and-up-to-start-of-void.js | 0 ...ock-as-first-with-void-siblings-partially-non-void-and-void.js | 0 ...n-void-block-as-first-with-void-siblings-partially-non-void.js | 0 .../commands/{with-intent => value}/delete/non-void-triple.js | 0 .../delete/void-block-as-first-with-non-void-siblings-all.js | 0 ...lock-as-first-with-non-void-siblings-backward-selection-all.js | 0 .../void-block-as-first-with-non-void-siblings-only-void.js | 0 ...k-as-first-with-non-void-siblings-select-void-and-next-word.js | 0 ...-first-with-non-void-siblings-select-void-end-and-next-word.js | 0 .../commands/{with-intent => value}/delete/void-block-as-only.js | 0 ...void-blocks-as-first-with-non-void-siblings-only-first-void.js | 0 .../void-blocks-as-first-with-non-void-siblings-only-voids.js | 0 .../delete/void-inline-as-first-with-non-void-block-next.js | 0 .../delete/void-inline-as-first-with-non-void-sibling.js | 0 .../delete/void-inline-as-last-with-non-void-previous-siblings.js | 0 .../test/commands/{with-intent => value}/delete/whole-inline.js | 0 .../commands/{with-intent => value}/delete/whole-word-mark.js | 0 .../test/commands/{with-intent => value}/delete/whole-word.js | 0 .../commands/{with-intent => value}/insert-block/block-end.js | 0 .../commands/{with-intent => value}/insert-block/block-middle.js | 0 .../commands/{with-intent => value}/insert-block/block-start.js | 0 .../test/commands/{with-intent => value}/insert-block/is-empty.js | 0 .../{with-intent => value}/insert-block/is-inline-void.js | 0 .../commands/{with-intent => value}/insert-block/is-void-end.js | 0 .../commands/{with-intent => value}/insert-block/is-void-start.js | 0 .../commands/{with-intent => value}/insert-block/with-block.js | 0 .../commands/{with-intent => value}/insert-block/with-object.js | 0 .../{with-intent => value}/insert-fragment/block-empty.js | 0 .../commands/{with-intent => value}/insert-fragment/block-end.js | 0 .../{with-intent => value}/insert-fragment/block-middle.js | 0 .../{with-intent => value}/insert-fragment/block-start.js | 0 .../insert-fragment/end-block-multiple-blocks.js | 0 .../commands/{with-intent => value}/insert-fragment/end-block.js | 0 .../commands/{with-intent => value}/insert-fragment/end-inline.js | 0 .../insert-fragment/flat-blocks/end-block.js | 0 .../insert-fragment/flat-blocks/hanging-selection-mixed-types.js | 0 .../insert-fragment/flat-blocks/start-block.js | 0 .../insert-fragment/fragment-adjacent-texts.js | 0 .../insert-fragment/fragment-inline-node.js | 0 .../insert-fragment/fragment-multiple-blocks.js | 0 .../insert-fragment/fragment-multiple-marks.js | 0 .../insert-fragment/fragment-nested-blocks-end-of-node.js | 0 .../insert-fragment/fragment-nested-blocks-start-of-node.js | 0 .../insert-fragment/fragment-nested-blocks.js | 0 .../insert-fragment/fragment-single-child-block.js | 0 .../insert-fragment/fragment-single-inline.js | 0 .../insert-fragment/fragment-single-mark.js | 0 .../{with-intent => value}/insert-fragment/hanging-block.js | 0 .../insert-fragment/hanging-selection-single-block.js | 0 .../{with-intent => value}/insert-fragment/inline-middle.js | 0 .../{with-intent => value}/insert-fragment/inline-start.js | 0 .../insert-fragment/inlines/between-texts-into-middle-block.js | 0 .../insert-fragment/inlines/middle-block.js | 0 .../insert-fragment/inlines/middle-inline.js | 0 .../{with-intent => value}/insert-fragment/insert-block.js | 0 .../insert-fragment/insert-inline-at-inline-middle.js | 0 .../{with-intent => value}/insert-fragment/insert-inline.js | 0 .../insert-fragment/insert-multiple-blocks-at-middle.js | 0 .../insert-fragment/insert-multiple-blocks-at-start.js | 0 .../insert-fragment/insert-multiple-texts.js | 0 .../insert-fragment/insert-nested-blocks-at-end.js | 0 .../insert-fragment/insert-nested-blocks-at-middle.js | 0 .../insert-fragment/insert-nested-blocks-at-start.js | 0 .../insert-fragment/last-block-fragment-multiple.js | 0 .../insert-fragment/last-block-fragment-single.js | 0 .../insert-fragment/last-block-inline-fragment-single.js | 0 .../{with-intent => value}/insert-fragment/lists/merge-lists.js | 0 .../{with-intent => value}/insert-fragment/marks/middle-block.js | 0 .../insert-fragment/marks/multiple-marks-middle-block.js | 0 .../{with-intent => value}/insert-fragment/merge-deep-nested.js | 0 .../{with-intent => value}/insert-fragment/merge-lists.js | 0 .../{with-intent => value}/insert-fragment/middle-block.js | 0 .../insert-fragment/middle-fragment-adjacent-texts.js | 0 .../insert-fragment/middle-inline-fragment-inline.js | 0 .../{with-intent => value}/insert-fragment/middle-inline.js | 0 .../insert-fragment/nested-block-fragment-nested-blocks.js | 0 .../nested-blocks-different-structure/end-block.js | 0 .../nested-blocks-different-structure/middle-block-nested.js | 0 .../nested-blocks-different-structure/middle-block.js | 0 .../nested-blocks-different-structure/start-block.js | 0 .../nested-blocks-same-structure/end-block-nested.js | 0 .../insert-fragment/nested-blocks-same-structure/start-block.js | 0 .../insert-fragment/start-block-multiple-blocks.js | 0 .../insert-fragment/start-block-with-void-no-text.js | 0 .../{with-intent => value}/insert-fragment/start-block.js | 0 .../{with-intent => value}/insert-fragment/start-inline.js | 0 .../{with-intent => value}/insert-fragment/start-second-block.js | 0 .../insert-fragment/tables/merge-cells-with-nested-blocks.js | 0 .../insert-fragment/tables/merge-into-empty-cells.js | 0 .../insert-fragment/tables/merge-into-full-cells.js | 0 .../insert-fragment/with-delete-across-blocks.js | 0 .../{with-intent => value}/insert-fragment/with-previous-block.js | 0 .../insert-fragment/words/adjacent-texts-after-void.js | 0 .../insert-fragment/words/adjacent-texts-end-first-block.js | 0 .../insert-fragment/words/adjacent-texts-into-empty-block.js | 0 .../{with-intent => value}/insert-fragment/words/after-inline.js | 0 .../{with-intent => value}/insert-fragment/words/before-inline.js | 0 .../{with-intent => value}/insert-fragment/words/end-block.js | 0 .../{with-intent => value}/insert-fragment/words/end-inline.js | 0 .../{with-intent => value}/insert-fragment/words/middle-block.js | 0 .../{with-intent => value}/insert-fragment/words/middle-inline.js | 0 .../{with-intent => value}/insert-fragment/words/start-block.js | 0 .../insert-fragment/words/start-second-block.js | 0 .../insert-fragment/words/with-delete-across-blocks.js | 0 .../commands/{with-intent => value}/insert-inline/block-end.js | 0 .../commands/{with-intent => value}/insert-inline/block-middle.js | 0 .../commands/{with-intent => value}/insert-inline/block-start.js | 0 .../{with-intent => value}/insert-inline/inline-middle.js | 0 .../commands/{with-intent => value}/insert-inline/is-empty.js | 0 .../test/commands/{with-intent => value}/insert-inline/is-void.js | 0 .../commands/{with-intent => value}/insert-inline/with-inline.js | 0 .../commands/{with-intent => value}/insert-text/after-mark.js | 0 .../commands/{with-intent => value}/insert-text/before-mark.js | 0 .../insert-text/blocks-with-overlapping-marks.js | 0 .../commands/{with-intent => value}/insert-text/during-mark.js | 0 .../{with-intent => value}/insert-text/empty-block-with-mark.js | 0 .../{with-intent => value}/insert-text/expanded-with-mark.js | 0 .../{with-intent => value}/insert-text/first-character.js | 0 .../commands/{with-intent => value}/insert-text/first-space.js | 0 .../commands/{with-intent => value}/insert-text/first-words.js | 0 .../insert-text/hanging-selection-multiple-blocks.js | 0 .../insert-text/hanging-selection-single-block.js | 0 .../commands/{with-intent => value}/insert-text/inside-void.js | 0 .../commands/{with-intent => value}/insert-text/last-character.js | 0 .../commands/{with-intent => value}/insert-text/last-space.js | 0 .../commands/{with-intent => value}/insert-text/last-words.js | 0 .../{with-intent => value}/insert-text/middle-character.js | 0 .../commands/{with-intent => value}/insert-text/middle-space.js | 0 .../commands/{with-intent => value}/insert-text/middle-words.js | 0 .../commands/{with-intent => value}/insert-text/with-marks.js | 0 .../commands/{with-intent => value}/remove-mark/across-blocks.js | 0 .../commands/{with-intent => value}/remove-mark/across-inlines.js | 0 .../{with-intent => value}/remove-mark/collapsed-selection.js | 0 .../commands/{with-intent => value}/remove-mark/existing-marks.js | 0 .../{with-intent => value}/remove-mark/first-character.js | 0 .../commands/{with-intent => value}/remove-mark/last-character.js | 0 .../{with-intent => value}/remove-mark/middle-character.js | 0 .../{with-intent => value}/remove-mark/part-of-mark-backward.js | 0 .../commands/{with-intent => value}/remove-mark/part-of-mark.js | 0 .../commands/{with-intent => value}/remove-mark/whole-word.js | 0 .../{with-intent => value}/remove-mark/with-mark-object.js | 0 .../{with-intent => value}/remove-mark/with-plain-object.js | 0 .../commands/{with-intent => value}/replace-mark/across-blocks.js | 0 .../{with-intent => value}/replace-mark/across-inlines.js | 0 .../{with-intent => value}/replace-mark/existing-marks.js | 0 .../{with-intent => value}/replace-mark/first-character.js | 0 .../{with-intent => value}/replace-mark/last-character.js | 0 .../{with-intent => value}/replace-mark/middle-character.js | 0 .../commands/{with-intent => value}/replace-mark/whole-word.js | 0 .../{with-intent => value}/replace-mark/with-mark-object.js | 0 .../{with-intent => value}/replace-mark/with-plain-object.js | 0 .../commands/{with-intent => value}/set-block/across-blocks.js | 0 .../commands/{with-intent => value}/set-block/across-inlines.js | 0 .../test/commands/{with-intent => value}/set-block/data-only.js | 0 .../set-block/hanging-selection-across-inlines.js | 0 .../{with-intent => value}/set-block/hanging-selection.js | 0 .../commands/{with-intent => value}/set-block/nested-block.js | 0 .../set-block/single-block-string-shorthand.js | 0 .../commands/{with-intent => value}/set-block/single-block.js | 0 .../commands/{with-intent => value}/set-block/with-data-as-map.js | 0 .../{with-intent => value}/set-block/with-data-as-object.js | 0 .../commands/{with-intent => value}/set-block/with-is-void.js | 0 .../slate/test/commands/{on-state => value}/set-data/simple.js | 0 .../commands/{with-intent => value}/set-inline/across-inlines.js | 0 .../test/commands/{with-intent => value}/set-inline/data-only.js | 0 .../commands/{with-intent => value}/set-inline/nested-inline.js | 0 .../set-inline/single-inline-string-shorthand.js | 0 .../commands/{with-intent => value}/set-inline/single-inline.js | 0 .../{with-intent => value}/set-inline/with-data-object.js | 0 .../test/commands/{with-intent => value}/set-inline/with-data.js | 0 .../commands/{with-intent => value}/set-inline/with-is-void.js | 0 .../{with-intent => value}/split-block/after-inline-void.js | 0 .../commands/{with-intent => value}/split-block/after-inline.js | 0 .../commands/{with-intent => value}/split-block/before-inline.js | 0 .../test/commands/{with-intent => value}/split-block/block-end.js | 0 .../commands/{with-intent => value}/split-block/block-middle.js | 0 .../commands/{with-intent => value}/split-block/block-start.js | 0 .../test/commands/{with-intent => value}/split-block/depth.js | 0 .../split-block/with-delete-across-blocks-and-inlines.js | 0 .../split-block/with-delete-across-blocks.js | 0 .../split-block/with-delete-hanging-selection.js | 0 .../commands/{with-intent => value}/split-block/with-delete.js | 0 .../commands/{with-intent => value}/split-block/with-inline.js | 0 .../commands/{with-intent => value}/split-block/with-marks.js | 0 .../commands/{with-intent => value}/split-inline/block-end.js | 0 .../commands/{with-intent => value}/split-inline/block-middle.js | 0 .../commands/{with-intent => value}/split-inline/block-start.js | 0 .../test/commands/{with-intent => value}/split-inline/height.js | 0 .../commands/{with-intent => value}/split-inline/with-delete.js | 0 .../commands/{with-intent => value}/split-inline/with-marks.js | 0 .../{with-intent => value}/toggle-mark/add-across-blocks.js | 0 .../{with-intent => value}/toggle-mark/add-across-inlines.js | 0 .../toggle-mark/add-collapsed-selection-start.js | 0 .../{with-intent => value}/toggle-mark/add-collapsed-selection.js | 0 .../toggle-mark/add-existing-marks-partially-marked.js | 0 .../{with-intent => value}/toggle-mark/add-existing-marks.js | 0 .../{with-intent => value}/toggle-mark/add-first-character.js | 0 .../{with-intent => value}/toggle-mark/add-last-character.js | 0 .../{with-intent => value}/toggle-mark/add-middle-character.js | 0 .../{with-intent => value}/toggle-mark/add-partially-marked.js | 0 .../commands/{with-intent => value}/toggle-mark/add-whole-word.js | 0 .../{with-intent => value}/toggle-mark/add-with-mark-object.js | 0 .../{with-intent => value}/toggle-mark/add-with-plain-object.js | 0 .../{with-intent => value}/toggle-mark/remove-across-blocks.js | 0 .../{with-intent => value}/toggle-mark/remove-across-inlines.js | 0 .../toggle-mark/remove-collapsed-selection-beginning.js | 0 .../toggle-mark/remove-collapsed-selection.js | 0 .../{with-intent => value}/toggle-mark/remove-existing-marks.js | 0 .../{with-intent => value}/toggle-mark/remove-first-character.js | 0 .../{with-intent => value}/toggle-mark/remove-last-character.js | 0 .../{with-intent => value}/toggle-mark/remove-middle-character.js | 0 .../{with-intent => value}/toggle-mark/remove-whole-word.js | 0 .../{with-intent => value}/toggle-mark/remove-with-mark-object.js | 0 .../toggle-mark/remove-with-plain-object.js | 0 .../commands/{with-intent => value}/unwrap-block/across-blocks.js | 0 .../{with-intent => value}/unwrap-block/across-inlines.js | 0 .../{with-intent => value}/unwrap-block/ending-child-blocks.js | 0 .../unwrap-block/middle-child-blocks-with-backward-selection.js | 0 .../{with-intent => value}/unwrap-block/middle-child-blocks.js | 0 .../commands/{with-intent => value}/unwrap-block/nested-block.js | 0 .../commands/{with-intent => value}/unwrap-block/single-block.js | 0 .../{with-intent => value}/unwrap-block/starting-child-blocks.js | 0 .../commands/{with-intent => value}/unwrap-block/with-object.js | 0 .../{with-intent => value}/unwrap-inline/across-blocks.js | 0 .../unwrap-inline/across-inlines-and-text.js | 0 .../{with-intent => value}/unwrap-inline/across-inlines.js | 0 .../commands/{with-intent => value}/unwrap-inline/nested-block.js | 0 .../commands/{with-intent => value}/unwrap-inline/only-one.js | 0 .../commands/{with-intent => value}/unwrap-inline/single-block.js | 0 .../commands/{with-intent => value}/unwrap-inline/with-object.js | 0 .../commands/{with-intent => value}/wrap-block/across-blocks.js | 0 .../commands/{with-intent => value}/wrap-block/across-inlines.js | 0 .../{with-intent => value}/wrap-block/nested-block-with-object.js | 0 .../commands/{with-intent => value}/wrap-block/nested-block.js | 0 .../commands/{with-intent => value}/wrap-block/single-block.js | 0 .../commands/{with-intent => value}/wrap-block/with-object.js | 0 .../commands/{with-intent => value}/wrap-inline/across-blocks.js | 0 .../commands/{with-intent => value}/wrap-inline/across-inlines.js | 0 .../test/commands/{with-intent => value}/wrap-inline/collapsed.js | 0 .../commands/{with-intent => value}/wrap-inline/inline-end.js | 0 .../wrap-inline/inline-middle-with-marks.js | 0 .../commands/{with-intent => value}/wrap-inline/inline-middle.js | 0 .../commands/{with-intent => value}/wrap-inline/inline-start.js | 0 .../commands/{with-intent => value}/wrap-inline/inline-void.js | 0 .../commands/{with-intent => value}/wrap-inline/nested-block.js | 0 .../commands/{with-intent => value}/wrap-inline/single-block.js | 0 .../test/commands/{with-intent => value}/wrap-inline/twice.js | 0 .../commands/{with-intent => value}/wrap-inline/whole-block.js | 0 .../commands/{with-intent => value}/wrap-inline/with-object.js | 0 .../commands/{with-intent => value}/wrap-text/across-blocks.js | 0 .../commands/{with-intent => value}/wrap-text/across-inlines.js | 0 .../{with-intent => value}/wrap-text/backwards-selection.js | 0 .../test/commands/{with-intent => value}/wrap-text/empty-block.js | 0 .../commands/{with-intent => value}/wrap-text/end-of-block.js | 0 .../commands/{with-intent => value}/wrap-text/middle-of-block.js | 0 .../commands/{with-intent => value}/wrap-text/start-of-block.js | 0 .../test/commands/{with-intent => value}/wrap-text/whole-block.js | 0 .../commands/{with-intent => value}/wrap-text/without-suffix.js | 0 378 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/commands/{with-intent => value}/add-mark/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/collapsed-selection-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/collapsed-selection-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/collapsed-selection-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/existing-marks-across-blocks-at-edge.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/existing-marks-across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/existing-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/whole-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/with-mark-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-mark/with-plain-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/across-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/collapsed-selection-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/collapsed-selection-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/collapsed-selection-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/inside-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/whole-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/with-mark-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/add-marks/with-plain-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/empty-after-void-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/empty-after-void-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/inline-after.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/inline-before.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/inline-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/inline-inside.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/join-blocks-from-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/join-blocks-with-inline-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/join-blocks-with-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/join-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/join-nested-blocks-different-depth.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/join-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/multiple-characters.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/single-non-void-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/single-void-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-backward/start-of-document.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-backward/inline-after-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-backward/inline-end-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-backward/inline-inside-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-backward/inline-only-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-backward/text-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-backward/text-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-backward/text-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-forward/inline-before-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-forward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-forward/inline-start-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-forward/text-last.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-forward/text-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-char-forward/text-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/before-inline-sibling.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/empty-before-void-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/empty-before-void-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/end-of-document.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/inside-inline-sibling.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/join-blocks-with-inline-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/join-blocks-with-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/join-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/join-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/multiple-characters.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/single-non-void-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/single-void-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-forward/start-text-middle-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-backward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-backward/inline-multi-voids.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-backward/inline-void-first.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-backward/text-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-backward/text-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-backward/word-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-forward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-forward/inline-multi-voids.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-forward/inline-void-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-forward/text-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-forward/text-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-line-forward/word-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-backward/inline-after-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-backward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-backward/join-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-backward/text-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-backward/word-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-forward/inline-after-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-forward/inline-middle-emoji.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-forward/join-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-forward/word-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete-word-forward/word-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/across-blocks-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/across-depths.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/across-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/across-texts-and-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/all-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/before-inline-sibling.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/expanded-across-whole-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/first-position.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/hanging-selection-multiple-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/inside-inline-sibling.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/inside-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/join-blocks-and-trim.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/join-blocks-with-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/join-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/join-double-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/join-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/nested-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/non-void-block-as-first-with-void-siblings-only-non-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/non-void-triple.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-block-as-first-with-non-void-siblings-all.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-block-as-first-with-non-void-siblings-only-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-block-as-only.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-inline-as-first-with-non-void-block-next.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-inline-as-first-with-non-void-sibling.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/void-inline-as-last-with-non-void-previous-siblings.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/whole-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/whole-word-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/delete/whole-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/block-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/block-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/block-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/is-empty.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/is-inline-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/is-void-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/is-void-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/with-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-block/with-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/block-empty.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/block-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/block-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/block-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/end-block-multiple-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/end-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/end-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/flat-blocks/end-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/flat-blocks/hanging-selection-mixed-types.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/flat-blocks/start-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-adjacent-texts.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-inline-node.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-multiple-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-multiple-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-nested-blocks-end-of-node.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-nested-blocks-start-of-node.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-single-child-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-single-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/fragment-single-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/hanging-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/inline-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/inline-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/inlines/between-texts-into-middle-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/inlines/middle-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/inlines/middle-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-inline-at-inline-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-multiple-blocks-at-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-multiple-blocks-at-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-multiple-texts.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-nested-blocks-at-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-nested-blocks-at-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/insert-nested-blocks-at-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/last-block-fragment-multiple.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/last-block-fragment-single.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/last-block-inline-fragment-single.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/lists/merge-lists.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/marks/middle-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/marks/multiple-marks-middle-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/merge-deep-nested.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/merge-lists.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/middle-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/middle-fragment-adjacent-texts.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/middle-inline-fragment-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/middle-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/nested-block-fragment-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/nested-blocks-different-structure/end-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/nested-blocks-different-structure/middle-block-nested.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/nested-blocks-different-structure/middle-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/nested-blocks-different-structure/start-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/nested-blocks-same-structure/end-block-nested.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/nested-blocks-same-structure/start-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/start-block-multiple-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/start-block-with-void-no-text.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/start-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/start-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/start-second-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/tables/merge-cells-with-nested-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/tables/merge-into-empty-cells.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/tables/merge-into-full-cells.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/with-previous-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/adjacent-texts-after-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/adjacent-texts-end-first-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/adjacent-texts-into-empty-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/after-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/before-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/end-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/end-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/middle-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/middle-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/start-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/start-second-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-fragment/words/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-inline/block-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-inline/block-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-inline/block-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-inline/inline-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-inline/is-empty.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-inline/is-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-inline/with-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/after-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/before-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/blocks-with-overlapping-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/during-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/empty-block-with-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/expanded-with-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/first-space.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/first-words.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/hanging-selection-multiple-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/inside-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/last-space.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/last-words.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/middle-space.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/middle-words.js (100%) rename packages/slate/test/commands/{with-intent => value}/insert-text/with-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/collapsed-selection.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/existing-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/part-of-mark-backward.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/part-of-mark.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/whole-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/with-mark-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/remove-mark/with-plain-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/existing-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/whole-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/with-mark-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/replace-mark/with-plain-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/data-only.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/hanging-selection-across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/hanging-selection.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/nested-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/single-block-string-shorthand.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/with-data-as-map.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/with-data-as-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-block/with-is-void.js (100%) rename packages/slate/test/commands/{on-state => value}/set-data/simple.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/data-only.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/nested-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/single-inline-string-shorthand.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/single-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/with-data-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/with-data.js (100%) rename packages/slate/test/commands/{with-intent => value}/set-inline/with-is-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/after-inline-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/after-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/before-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/block-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/block-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/block-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/depth.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/with-delete-across-blocks-and-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/with-delete-hanging-selection.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/with-delete.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/with-inline.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-block/with-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-inline/block-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-inline/block-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-inline/block-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-inline/height.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-inline/with-delete.js (100%) rename packages/slate/test/commands/{with-intent => value}/split-inline/with-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-collapsed-selection-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-collapsed-selection.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-existing-marks-partially-marked.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-existing-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-partially-marked.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-whole-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-with-mark-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/add-with-plain-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-collapsed-selection-beginning.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-collapsed-selection.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-existing-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-first-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-last-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-middle-character.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-whole-word.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-with-mark-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/toggle-mark/remove-with-plain-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/ending-child-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/middle-child-blocks-with-backward-selection.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/middle-child-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/nested-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/starting-child-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-block/with-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-inline/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-inline/across-inlines-and-text.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-inline/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-inline/nested-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-inline/only-one.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-inline/single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/unwrap-inline/with-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-block/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-block/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-block/nested-block-with-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-block/nested-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-block/single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-block/with-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/collapsed.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/inline-end.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/inline-middle-with-marks.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/inline-middle.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/inline-start.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/inline-void.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/nested-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/single-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/twice.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/whole-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-inline/with-object.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/across-blocks.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/across-inlines.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/backwards-selection.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/empty-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/end-of-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/middle-of-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/start-of-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/whole-block.js (100%) rename packages/slate/test/commands/{with-intent => value}/wrap-text/without-suffix.js (100%) diff --git a/packages/slate/test/commands/with-intent/add-mark/across-blocks.js b/packages/slate/test/commands/value/add-mark/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/across-blocks.js rename to packages/slate/test/commands/value/add-mark/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/add-mark/across-inlines.js b/packages/slate/test/commands/value/add-mark/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/across-inlines.js rename to packages/slate/test/commands/value/add-mark/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js b/packages/slate/test/commands/value/add-mark/collapsed-selection-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/collapsed-selection-end.js rename to packages/slate/test/commands/value/add-mark/collapsed-selection-end.js diff --git a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js b/packages/slate/test/commands/value/add-mark/collapsed-selection-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/collapsed-selection-middle.js rename to packages/slate/test/commands/value/add-mark/collapsed-selection-middle.js diff --git a/packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js b/packages/slate/test/commands/value/add-mark/collapsed-selection-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/collapsed-selection-start.js rename to packages/slate/test/commands/value/add-mark/collapsed-selection-start.js diff --git a/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js b/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks-at-edge.js rename to packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js diff --git a/packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js b/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/existing-marks-across-blocks.js rename to packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js diff --git a/packages/slate/test/commands/with-intent/add-mark/existing-marks.js b/packages/slate/test/commands/value/add-mark/existing-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/existing-marks.js rename to packages/slate/test/commands/value/add-mark/existing-marks.js diff --git a/packages/slate/test/commands/with-intent/add-mark/first-character.js b/packages/slate/test/commands/value/add-mark/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/first-character.js rename to packages/slate/test/commands/value/add-mark/first-character.js diff --git a/packages/slate/test/commands/with-intent/add-mark/last-character.js b/packages/slate/test/commands/value/add-mark/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/last-character.js rename to packages/slate/test/commands/value/add-mark/last-character.js diff --git a/packages/slate/test/commands/with-intent/add-mark/middle-character.js b/packages/slate/test/commands/value/add-mark/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/middle-character.js rename to packages/slate/test/commands/value/add-mark/middle-character.js diff --git a/packages/slate/test/commands/with-intent/add-mark/whole-word.js b/packages/slate/test/commands/value/add-mark/whole-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/whole-word.js rename to packages/slate/test/commands/value/add-mark/whole-word.js diff --git a/packages/slate/test/commands/with-intent/add-mark/with-mark-object.js b/packages/slate/test/commands/value/add-mark/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/with-mark-object.js rename to packages/slate/test/commands/value/add-mark/with-mark-object.js diff --git a/packages/slate/test/commands/with-intent/add-mark/with-plain-object.js b/packages/slate/test/commands/value/add-mark/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-mark/with-plain-object.js rename to packages/slate/test/commands/value/add-mark/with-plain-object.js diff --git a/packages/slate/test/commands/with-intent/add-marks/across-blocks.js b/packages/slate/test/commands/value/add-marks/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/across-blocks.js rename to packages/slate/test/commands/value/add-marks/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/add-marks/across-inlines.js b/packages/slate/test/commands/value/add-marks/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/across-inlines.js rename to packages/slate/test/commands/value/add-marks/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/add-marks/across-marks.js b/packages/slate/test/commands/value/add-marks/across-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/across-marks.js rename to packages/slate/test/commands/value/add-marks/across-marks.js diff --git a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js b/packages/slate/test/commands/value/add-marks/collapsed-selection-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/collapsed-selection-end.js rename to packages/slate/test/commands/value/add-marks/collapsed-selection-end.js diff --git a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js b/packages/slate/test/commands/value/add-marks/collapsed-selection-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/collapsed-selection-middle.js rename to packages/slate/test/commands/value/add-marks/collapsed-selection-middle.js diff --git a/packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js b/packages/slate/test/commands/value/add-marks/collapsed-selection-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/collapsed-selection-start.js rename to packages/slate/test/commands/value/add-marks/collapsed-selection-start.js diff --git a/packages/slate/test/commands/with-intent/add-marks/first-character.js b/packages/slate/test/commands/value/add-marks/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/first-character.js rename to packages/slate/test/commands/value/add-marks/first-character.js diff --git a/packages/slate/test/commands/with-intent/add-marks/inside-mark.js b/packages/slate/test/commands/value/add-marks/inside-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/inside-mark.js rename to packages/slate/test/commands/value/add-marks/inside-mark.js diff --git a/packages/slate/test/commands/with-intent/add-marks/last-character.js b/packages/slate/test/commands/value/add-marks/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/last-character.js rename to packages/slate/test/commands/value/add-marks/last-character.js diff --git a/packages/slate/test/commands/with-intent/add-marks/middle-character.js b/packages/slate/test/commands/value/add-marks/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/middle-character.js rename to packages/slate/test/commands/value/add-marks/middle-character.js diff --git a/packages/slate/test/commands/with-intent/add-marks/whole-word.js b/packages/slate/test/commands/value/add-marks/whole-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/whole-word.js rename to packages/slate/test/commands/value/add-marks/whole-word.js diff --git a/packages/slate/test/commands/with-intent/add-marks/with-mark-object.js b/packages/slate/test/commands/value/add-marks/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/with-mark-object.js rename to packages/slate/test/commands/value/add-marks/with-mark-object.js diff --git a/packages/slate/test/commands/with-intent/add-marks/with-plain-object.js b/packages/slate/test/commands/value/add-marks/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/add-marks/with-plain-object.js rename to packages/slate/test/commands/value/add-marks/with-plain-object.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js b/packages/slate/test/commands/value/delete-backward/empty-after-void-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/empty-after-void-block.js rename to packages/slate/test/commands/value/delete-backward/empty-after-void-block.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js b/packages/slate/test/commands/value/delete-backward/empty-after-void-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/empty-after-void-inline.js rename to packages/slate/test/commands/value/delete-backward/empty-after-void-inline.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/first-character.js b/packages/slate/test/commands/value/delete-backward/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/first-character.js rename to packages/slate/test/commands/value/delete-backward/first-character.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-after.js b/packages/slate/test/commands/value/delete-backward/inline-after.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/inline-after.js rename to packages/slate/test/commands/value/delete-backward/inline-after.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-before.js b/packages/slate/test/commands/value/delete-backward/inline-before.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/inline-before.js rename to packages/slate/test/commands/value/delete-backward/inline-before.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-end.js b/packages/slate/test/commands/value/delete-backward/inline-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/inline-end.js rename to packages/slate/test/commands/value/delete-backward/inline-end.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/inline-inside.js b/packages/slate/test/commands/value/delete-backward/inline-inside.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/inline-inside.js rename to packages/slate/test/commands/value/delete-backward/inline-inside.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js b/packages/slate/test/commands/value/delete-backward/join-blocks-from-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/join-blocks-from-inline.js rename to packages/slate/test/commands/value/delete-backward/join-blocks-from-inline.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js b/packages/slate/test/commands/value/delete-backward/join-blocks-with-inline-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline-void.js rename to packages/slate/test/commands/value/delete-backward/join-blocks-with-inline-void.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js b/packages/slate/test/commands/value/delete-backward/join-blocks-with-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/join-blocks-with-inline.js rename to packages/slate/test/commands/value/delete-backward/join-blocks-with-inline.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-blocks.js b/packages/slate/test/commands/value/delete-backward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/join-blocks.js rename to packages/slate/test/commands/value/delete-backward/join-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js b/packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks-different-depth.js rename to packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js b/packages/slate/test/commands/value/delete-backward/join-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/join-nested-blocks.js rename to packages/slate/test/commands/value/delete-backward/join-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/last-character.js b/packages/slate/test/commands/value/delete-backward/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/last-character.js rename to packages/slate/test/commands/value/delete-backward/last-character.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/middle-character.js b/packages/slate/test/commands/value/delete-backward/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/middle-character.js rename to packages/slate/test/commands/value/delete-backward/middle-character.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js b/packages/slate/test/commands/value/delete-backward/multiple-characters.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/multiple-characters.js rename to packages/slate/test/commands/value/delete-backward/multiple-characters.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js b/packages/slate/test/commands/value/delete-backward/single-non-void-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/single-non-void-block.js rename to packages/slate/test/commands/value/delete-backward/single-non-void-block.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/single-void-block.js b/packages/slate/test/commands/value/delete-backward/single-void-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/single-void-block.js rename to packages/slate/test/commands/value/delete-backward/single-void-block.js diff --git a/packages/slate/test/commands/with-intent/delete-backward/start-of-document.js b/packages/slate/test/commands/value/delete-backward/start-of-document.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-backward/start-of-document.js rename to packages/slate/test/commands/value/delete-backward/start-of-document.js diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js b/packages/slate/test/commands/value/delete-char-backward/inline-after-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-backward/inline-after-emoji.js rename to packages/slate/test/commands/value/delete-char-backward/inline-after-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js b/packages/slate/test/commands/value/delete-char-backward/inline-end-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-backward/inline-end-emoji.js rename to packages/slate/test/commands/value/delete-char-backward/inline-end-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js b/packages/slate/test/commands/value/delete-char-backward/inline-inside-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-backward/inline-inside-emoji.js rename to packages/slate/test/commands/value/delete-char-backward/inline-inside-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js b/packages/slate/test/commands/value/delete-char-backward/inline-only-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-backward/inline-only-emoji.js rename to packages/slate/test/commands/value/delete-char-backward/inline-only-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/text-end.js b/packages/slate/test/commands/value/delete-char-backward/text-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-backward/text-end.js rename to packages/slate/test/commands/value/delete-char-backward/text-end.js diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js b/packages/slate/test/commands/value/delete-char-backward/text-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-backward/text-middle.js rename to packages/slate/test/commands/value/delete-char-backward/text-middle.js diff --git a/packages/slate/test/commands/with-intent/delete-char-backward/text-start.js b/packages/slate/test/commands/value/delete-char-backward/text-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-backward/text-start.js rename to packages/slate/test/commands/value/delete-char-backward/text-start.js diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js b/packages/slate/test/commands/value/delete-char-forward/inline-before-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-forward/inline-before-emoji.js rename to packages/slate/test/commands/value/delete-char-forward/inline-before-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-char-forward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-forward/inline-middle-emoji.js rename to packages/slate/test/commands/value/delete-char-forward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js b/packages/slate/test/commands/value/delete-char-forward/inline-start-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-forward/inline-start-emoji.js rename to packages/slate/test/commands/value/delete-char-forward/inline-start-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/text-last.js b/packages/slate/test/commands/value/delete-char-forward/text-last.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-forward/text-last.js rename to packages/slate/test/commands/value/delete-char-forward/text-last.js diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js b/packages/slate/test/commands/value/delete-char-forward/text-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-forward/text-middle.js rename to packages/slate/test/commands/value/delete-char-forward/text-middle.js diff --git a/packages/slate/test/commands/with-intent/delete-char-forward/text-start.js b/packages/slate/test/commands/value/delete-char-forward/text-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-char-forward/text-start.js rename to packages/slate/test/commands/value/delete-char-forward/text-start.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js b/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/before-inline-sibling.js rename to packages/slate/test/commands/value/delete-forward/before-inline-sibling.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js b/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/empty-before-void-block.js rename to packages/slate/test/commands/value/delete-forward/empty-before-void-block.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js b/packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/empty-before-void-inline.js rename to packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/end-of-document.js b/packages/slate/test/commands/value/delete-forward/end-of-document.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/end-of-document.js rename to packages/slate/test/commands/value/delete-forward/end-of-document.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/first-character.js b/packages/slate/test/commands/value/delete-forward/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/first-character.js rename to packages/slate/test/commands/value/delete-forward/first-character.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js b/packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/inside-inline-sibling.js rename to packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js b/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline-void.js rename to packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js b/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/join-blocks-with-inline.js rename to packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-blocks.js b/packages/slate/test/commands/value/delete-forward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/join-blocks.js rename to packages/slate/test/commands/value/delete-forward/join-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js b/packages/slate/test/commands/value/delete-forward/join-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/join-nested-blocks.js rename to packages/slate/test/commands/value/delete-forward/join-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/last-character.js b/packages/slate/test/commands/value/delete-forward/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/last-character.js rename to packages/slate/test/commands/value/delete-forward/last-character.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/middle-character.js b/packages/slate/test/commands/value/delete-forward/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/middle-character.js rename to packages/slate/test/commands/value/delete-forward/middle-character.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js b/packages/slate/test/commands/value/delete-forward/multiple-characters.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/multiple-characters.js rename to packages/slate/test/commands/value/delete-forward/multiple-characters.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js b/packages/slate/test/commands/value/delete-forward/single-non-void-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/single-non-void-block.js rename to packages/slate/test/commands/value/delete-forward/single-non-void-block.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/single-void-block.js b/packages/slate/test/commands/value/delete-forward/single-void-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/single-void-block.js rename to packages/slate/test/commands/value/delete-forward/single-void-block.js diff --git a/packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js b/packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-forward/start-text-middle-inline.js rename to packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-line-backward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-backward/inline-middle-emoji.js rename to packages/slate/test/commands/value/delete-line-backward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js b/packages/slate/test/commands/value/delete-line-backward/inline-multi-voids.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-backward/inline-multi-voids.js rename to packages/slate/test/commands/value/delete-line-backward/inline-multi-voids.js diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js b/packages/slate/test/commands/value/delete-line-backward/inline-void-first.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-backward/inline-void-first.js rename to packages/slate/test/commands/value/delete-line-backward/inline-void-first.js diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/text-end.js b/packages/slate/test/commands/value/delete-line-backward/text-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-backward/text-end.js rename to packages/slate/test/commands/value/delete-line-backward/text-end.js diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/text-start.js b/packages/slate/test/commands/value/delete-line-backward/text-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-backward/text-start.js rename to packages/slate/test/commands/value/delete-line-backward/text-start.js diff --git a/packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js b/packages/slate/test/commands/value/delete-line-backward/word-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-backward/word-middle.js rename to packages/slate/test/commands/value/delete-line-backward/word-middle.js diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-line-forward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-forward/inline-middle-emoji.js rename to packages/slate/test/commands/value/delete-line-forward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js b/packages/slate/test/commands/value/delete-line-forward/inline-multi-voids.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-forward/inline-multi-voids.js rename to packages/slate/test/commands/value/delete-line-forward/inline-multi-voids.js diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js b/packages/slate/test/commands/value/delete-line-forward/inline-void-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-forward/inline-void-end.js rename to packages/slate/test/commands/value/delete-line-forward/inline-void-end.js diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/text-end.js b/packages/slate/test/commands/value/delete-line-forward/text-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-forward/text-end.js rename to packages/slate/test/commands/value/delete-line-forward/text-end.js diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/text-start.js b/packages/slate/test/commands/value/delete-line-forward/text-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-forward/text-start.js rename to packages/slate/test/commands/value/delete-line-forward/text-start.js diff --git a/packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js b/packages/slate/test/commands/value/delete-line-forward/word-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-line-forward/word-middle.js rename to packages/slate/test/commands/value/delete-line-forward/word-middle.js diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js b/packages/slate/test/commands/value/delete-word-backward/inline-after-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-backward/inline-after-emoji.js rename to packages/slate/test/commands/value/delete-word-backward/inline-after-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-word-backward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-backward/inline-middle-emoji.js rename to packages/slate/test/commands/value/delete-word-backward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js b/packages/slate/test/commands/value/delete-word-backward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-backward/join-blocks.js rename to packages/slate/test/commands/value/delete-word-backward/join-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/text-end.js b/packages/slate/test/commands/value/delete-word-backward/text-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-backward/text-end.js rename to packages/slate/test/commands/value/delete-word-backward/text-end.js diff --git a/packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js b/packages/slate/test/commands/value/delete-word-backward/word-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-backward/word-middle.js rename to packages/slate/test/commands/value/delete-word-backward/word-middle.js diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js b/packages/slate/test/commands/value/delete-word-forward/inline-after-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-forward/inline-after-emoji.js rename to packages/slate/test/commands/value/delete-word-forward/inline-after-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-word-forward/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-forward/inline-middle-emoji.js rename to packages/slate/test/commands/value/delete-word-forward/inline-middle-emoji.js diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js b/packages/slate/test/commands/value/delete-word-forward/join-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-forward/join-blocks.js rename to packages/slate/test/commands/value/delete-word-forward/join-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js b/packages/slate/test/commands/value/delete-word-forward/word-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-forward/word-middle.js rename to packages/slate/test/commands/value/delete-word-forward/word-middle.js diff --git a/packages/slate/test/commands/with-intent/delete-word-forward/word-start.js b/packages/slate/test/commands/value/delete-word-forward/word-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete-word-forward/word-start.js rename to packages/slate/test/commands/value/delete-word-forward/word-start.js diff --git a/packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js b/packages/slate/test/commands/value/delete/across-blocks-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/across-blocks-inlines.js rename to packages/slate/test/commands/value/delete/across-blocks-inlines.js diff --git a/packages/slate/test/commands/with-intent/delete/across-blocks.js b/packages/slate/test/commands/value/delete/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/across-blocks.js rename to packages/slate/test/commands/value/delete/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete/across-depths.js b/packages/slate/test/commands/value/delete/across-depths.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/across-depths.js rename to packages/slate/test/commands/value/delete/across-depths.js diff --git a/packages/slate/test/commands/with-intent/delete/across-nested-blocks.js b/packages/slate/test/commands/value/delete/across-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/across-nested-blocks.js rename to packages/slate/test/commands/value/delete/across-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js b/packages/slate/test/commands/value/delete/across-texts-and-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/across-texts-and-inlines.js rename to packages/slate/test/commands/value/delete/across-texts-and-inlines.js diff --git a/packages/slate/test/commands/with-intent/delete/all-nested-blocks.js b/packages/slate/test/commands/value/delete/all-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/all-nested-blocks.js rename to packages/slate/test/commands/value/delete/all-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete/before-inline-sibling.js b/packages/slate/test/commands/value/delete/before-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/before-inline-sibling.js rename to packages/slate/test/commands/value/delete/before-inline-sibling.js diff --git a/packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js b/packages/slate/test/commands/value/delete/expanded-across-whole-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/expanded-across-whole-mark.js rename to packages/slate/test/commands/value/delete/expanded-across-whole-mark.js diff --git a/packages/slate/test/commands/with-intent/delete/first-character.js b/packages/slate/test/commands/value/delete/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/first-character.js rename to packages/slate/test/commands/value/delete/first-character.js diff --git a/packages/slate/test/commands/with-intent/delete/first-position.js b/packages/slate/test/commands/value/delete/first-position.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/first-position.js rename to packages/slate/test/commands/value/delete/first-position.js diff --git a/packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/hanging-selection-multiple-blocks.js rename to packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js b/packages/slate/test/commands/value/delete/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/hanging-selection-single-block.js rename to packages/slate/test/commands/value/delete/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js b/packages/slate/test/commands/value/delete/inside-inline-sibling.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/inside-inline-sibling.js rename to packages/slate/test/commands/value/delete/inside-inline-sibling.js diff --git a/packages/slate/test/commands/with-intent/delete/inside-inline.js b/packages/slate/test/commands/value/delete/inside-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/inside-inline.js rename to packages/slate/test/commands/value/delete/inside-inline.js diff --git a/packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js b/packages/slate/test/commands/value/delete/join-blocks-and-trim.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/join-blocks-and-trim.js rename to packages/slate/test/commands/value/delete/join-blocks-and-trim.js diff --git a/packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js b/packages/slate/test/commands/value/delete/join-blocks-with-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/join-blocks-with-inlines.js rename to packages/slate/test/commands/value/delete/join-blocks-with-inlines.js diff --git a/packages/slate/test/commands/with-intent/delete/join-blocks.js b/packages/slate/test/commands/value/delete/join-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/join-blocks.js rename to packages/slate/test/commands/value/delete/join-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js b/packages/slate/test/commands/value/delete/join-double-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/join-double-nested-blocks.js rename to packages/slate/test/commands/value/delete/join-double-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete/join-nested-blocks.js b/packages/slate/test/commands/value/delete/join-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/join-nested-blocks.js rename to packages/slate/test/commands/value/delete/join-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/delete/last-character.js b/packages/slate/test/commands/value/delete/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/last-character.js rename to packages/slate/test/commands/value/delete/last-character.js diff --git a/packages/slate/test/commands/with-intent/delete/middle-character.js b/packages/slate/test/commands/value/delete/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/middle-character.js rename to packages/slate/test/commands/value/delete/middle-character.js diff --git a/packages/slate/test/commands/with-intent/delete/nested-block.js b/packages/slate/test/commands/value/delete/nested-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/nested-block.js rename to packages/slate/test/commands/value/delete/nested-block.js diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-only-non-void.js rename to packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js rename to packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js rename to packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js diff --git a/packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js rename to packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js diff --git a/packages/slate/test/commands/with-intent/delete/non-void-triple.js b/packages/slate/test/commands/value/delete/non-void-triple.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/non-void-triple.js rename to packages/slate/test/commands/value/delete/non-void-triple.js diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-all.js rename to packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js rename to packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-only-void.js rename to packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js rename to packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js rename to packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js diff --git a/packages/slate/test/commands/with-intent/delete/void-block-as-only.js b/packages/slate/test/commands/value/delete/void-block-as-only.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-block-as-only.js rename to packages/slate/test/commands/value/delete/void-block-as-only.js diff --git a/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js b/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js rename to packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js diff --git a/packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js b/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js rename to packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js b/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-block-next.js rename to packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js b/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-inline-as-first-with-non-void-sibling.js rename to packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js diff --git a/packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js b/packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/void-inline-as-last-with-non-void-previous-siblings.js rename to packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js diff --git a/packages/slate/test/commands/with-intent/delete/whole-inline.js b/packages/slate/test/commands/value/delete/whole-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/whole-inline.js rename to packages/slate/test/commands/value/delete/whole-inline.js diff --git a/packages/slate/test/commands/with-intent/delete/whole-word-mark.js b/packages/slate/test/commands/value/delete/whole-word-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/whole-word-mark.js rename to packages/slate/test/commands/value/delete/whole-word-mark.js diff --git a/packages/slate/test/commands/with-intent/delete/whole-word.js b/packages/slate/test/commands/value/delete/whole-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/delete/whole-word.js rename to packages/slate/test/commands/value/delete/whole-word.js diff --git a/packages/slate/test/commands/with-intent/insert-block/block-end.js b/packages/slate/test/commands/value/insert-block/block-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/block-end.js rename to packages/slate/test/commands/value/insert-block/block-end.js diff --git a/packages/slate/test/commands/with-intent/insert-block/block-middle.js b/packages/slate/test/commands/value/insert-block/block-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/block-middle.js rename to packages/slate/test/commands/value/insert-block/block-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-block/block-start.js b/packages/slate/test/commands/value/insert-block/block-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/block-start.js rename to packages/slate/test/commands/value/insert-block/block-start.js diff --git a/packages/slate/test/commands/with-intent/insert-block/is-empty.js b/packages/slate/test/commands/value/insert-block/is-empty.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/is-empty.js rename to packages/slate/test/commands/value/insert-block/is-empty.js diff --git a/packages/slate/test/commands/with-intent/insert-block/is-inline-void.js b/packages/slate/test/commands/value/insert-block/is-inline-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/is-inline-void.js rename to packages/slate/test/commands/value/insert-block/is-inline-void.js diff --git a/packages/slate/test/commands/with-intent/insert-block/is-void-end.js b/packages/slate/test/commands/value/insert-block/is-void-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/is-void-end.js rename to packages/slate/test/commands/value/insert-block/is-void-end.js diff --git a/packages/slate/test/commands/with-intent/insert-block/is-void-start.js b/packages/slate/test/commands/value/insert-block/is-void-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/is-void-start.js rename to packages/slate/test/commands/value/insert-block/is-void-start.js diff --git a/packages/slate/test/commands/with-intent/insert-block/with-block.js b/packages/slate/test/commands/value/insert-block/with-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/with-block.js rename to packages/slate/test/commands/value/insert-block/with-block.js diff --git a/packages/slate/test/commands/with-intent/insert-block/with-object.js b/packages/slate/test/commands/value/insert-block/with-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-block/with-object.js rename to packages/slate/test/commands/value/insert-block/with-object.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-empty.js b/packages/slate/test/commands/value/insert-fragment/block-empty.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/block-empty.js rename to packages/slate/test/commands/value/insert-fragment/block-empty.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-end.js b/packages/slate/test/commands/value/insert-fragment/block-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/block-end.js rename to packages/slate/test/commands/value/insert-fragment/block-end.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-middle.js b/packages/slate/test/commands/value/insert-fragment/block-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/block-middle.js rename to packages/slate/test/commands/value/insert-fragment/block-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/block-start.js b/packages/slate/test/commands/value/insert-fragment/block-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/block-start.js rename to packages/slate/test/commands/value/insert-fragment/block-start.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js b/packages/slate/test/commands/value/insert-fragment/end-block-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/end-block-multiple-blocks.js rename to packages/slate/test/commands/value/insert-fragment/end-block-multiple-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/end-block.js b/packages/slate/test/commands/value/insert-fragment/end-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/end-block.js rename to packages/slate/test/commands/value/insert-fragment/end-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/end-inline.js b/packages/slate/test/commands/value/insert-fragment/end-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/end-inline.js rename to packages/slate/test/commands/value/insert-fragment/end-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js b/packages/slate/test/commands/value/insert-fragment/flat-blocks/end-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/end-block.js rename to packages/slate/test/commands/value/insert-fragment/flat-blocks/end-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js b/packages/slate/test/commands/value/insert-fragment/flat-blocks/hanging-selection-mixed-types.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/hanging-selection-mixed-types.js rename to packages/slate/test/commands/value/insert-fragment/flat-blocks/hanging-selection-mixed-types.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js b/packages/slate/test/commands/value/insert-fragment/flat-blocks/start-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/flat-blocks/start-block.js rename to packages/slate/test/commands/value/insert-fragment/flat-blocks/start-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js b/packages/slate/test/commands/value/insert-fragment/fragment-adjacent-texts.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-adjacent-texts.js rename to packages/slate/test/commands/value/insert-fragment/fragment-adjacent-texts.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js b/packages/slate/test/commands/value/insert-fragment/fragment-inline-node.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-inline-node.js rename to packages/slate/test/commands/value/insert-fragment/fragment-inline-node.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js b/packages/slate/test/commands/value/insert-fragment/fragment-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-blocks.js rename to packages/slate/test/commands/value/insert-fragment/fragment-multiple-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-marks.js b/packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-multiple-marks.js rename to packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js b/packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-end-of-node.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-end-of-node.js rename to packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-end-of-node.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js b/packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-start-of-node.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks-start-of-node.js rename to packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-start-of-node.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js b/packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-nested-blocks.js rename to packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js b/packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-single-child-block.js rename to packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-inline.js b/packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-single-inline.js rename to packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/fragment-single-mark.js b/packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/fragment-single-mark.js rename to packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js b/packages/slate/test/commands/value/insert-fragment/hanging-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/hanging-block.js rename to packages/slate/test/commands/value/insert-fragment/hanging-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js b/packages/slate/test/commands/value/insert-fragment/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/hanging-selection-single-block.js rename to packages/slate/test/commands/value/insert-fragment/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js b/packages/slate/test/commands/value/insert-fragment/inline-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/inline-middle.js rename to packages/slate/test/commands/value/insert-fragment/inline-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inline-start.js b/packages/slate/test/commands/value/insert-fragment/inline-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/inline-start.js rename to packages/slate/test/commands/value/insert-fragment/inline-start.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js b/packages/slate/test/commands/value/insert-fragment/inlines/between-texts-into-middle-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/inlines/between-texts-into-middle-block.js rename to packages/slate/test/commands/value/insert-fragment/inlines/between-texts-into-middle-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js b/packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-block.js rename to packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js b/packages/slate/test/commands/value/insert-fragment/inlines/middle-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/inlines/middle-inline.js rename to packages/slate/test/commands/value/insert-fragment/inlines/middle-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-block.js b/packages/slate/test/commands/value/insert-fragment/insert-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-block.js rename to packages/slate/test/commands/value/insert-fragment/insert-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js b/packages/slate/test/commands/value/insert-fragment/insert-inline-at-inline-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-inline-at-inline-middle.js rename to packages/slate/test/commands/value/insert-fragment/insert-inline-at-inline-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js b/packages/slate/test/commands/value/insert-fragment/insert-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-inline.js rename to packages/slate/test/commands/value/insert-fragment/insert-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js b/packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-middle.js rename to packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js b/packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-blocks-at-start.js rename to packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-start.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js b/packages/slate/test/commands/value/insert-fragment/insert-multiple-texts.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-multiple-texts.js rename to packages/slate/test/commands/value/insert-fragment/insert-multiple-texts.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js b/packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-end.js rename to packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-end.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js b/packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-middle.js rename to packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js b/packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/insert-nested-blocks-at-start.js rename to packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-start.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js b/packages/slate/test/commands/value/insert-fragment/last-block-fragment-multiple.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-multiple.js rename to packages/slate/test/commands/value/insert-fragment/last-block-fragment-multiple.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js b/packages/slate/test/commands/value/insert-fragment/last-block-fragment-single.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/last-block-fragment-single.js rename to packages/slate/test/commands/value/insert-fragment/last-block-fragment-single.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js b/packages/slate/test/commands/value/insert-fragment/last-block-inline-fragment-single.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/last-block-inline-fragment-single.js rename to packages/slate/test/commands/value/insert-fragment/last-block-inline-fragment-single.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js b/packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/lists/merge-lists.js rename to packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js b/packages/slate/test/commands/value/insert-fragment/marks/middle-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/marks/middle-block.js rename to packages/slate/test/commands/value/insert-fragment/marks/middle-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js b/packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/marks/multiple-marks-middle-block.js rename to packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js b/packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/merge-deep-nested.js rename to packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js b/packages/slate/test/commands/value/insert-fragment/merge-lists.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/merge-lists.js rename to packages/slate/test/commands/value/insert-fragment/merge-lists.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-block.js b/packages/slate/test/commands/value/insert-fragment/middle-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/middle-block.js rename to packages/slate/test/commands/value/insert-fragment/middle-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js b/packages/slate/test/commands/value/insert-fragment/middle-fragment-adjacent-texts.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/middle-fragment-adjacent-texts.js rename to packages/slate/test/commands/value/insert-fragment/middle-fragment-adjacent-texts.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js b/packages/slate/test/commands/value/insert-fragment/middle-inline-fragment-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/middle-inline-fragment-inline.js rename to packages/slate/test/commands/value/insert-fragment/middle-inline-fragment-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js b/packages/slate/test/commands/value/insert-fragment/middle-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/middle-inline.js rename to packages/slate/test/commands/value/insert-fragment/middle-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js b/packages/slate/test/commands/value/insert-fragment/nested-block-fragment-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/nested-block-fragment-nested-blocks.js rename to packages/slate/test/commands/value/insert-fragment/nested-block-fragment-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/end-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/end-block.js rename to packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/end-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block-nested.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block-nested.js rename to packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block-nested.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/middle-block.js rename to packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/start-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-different-structure/start-block.js rename to packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/start-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/end-block-nested.js rename to packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/nested-blocks-same-structure/start-block.js rename to packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js b/packages/slate/test/commands/value/insert-fragment/start-block-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/start-block-multiple-blocks.js rename to packages/slate/test/commands/value/insert-fragment/start-block-multiple-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js b/packages/slate/test/commands/value/insert-fragment/start-block-with-void-no-text.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/start-block-with-void-no-text.js rename to packages/slate/test/commands/value/insert-fragment/start-block-with-void-no-text.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-block.js b/packages/slate/test/commands/value/insert-fragment/start-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/start-block.js rename to packages/slate/test/commands/value/insert-fragment/start-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-inline.js b/packages/slate/test/commands/value/insert-fragment/start-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/start-inline.js rename to packages/slate/test/commands/value/insert-fragment/start-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js b/packages/slate/test/commands/value/insert-fragment/start-second-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/start-second-block.js rename to packages/slate/test/commands/value/insert-fragment/start-second-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js b/packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/tables/merge-cells-with-nested-blocks.js rename to packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js b/packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-empty-cells.js rename to packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js b/packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/tables/merge-into-full-cells.js rename to packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js b/packages/slate/test/commands/value/insert-fragment/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/with-delete-across-blocks.js rename to packages/slate/test/commands/value/insert-fragment/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js b/packages/slate/test/commands/value/insert-fragment/with-previous-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/with-previous-block.js rename to packages/slate/test/commands/value/insert-fragment/with-previous-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js b/packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-after-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-after-void.js rename to packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-after-void.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js b/packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-end-first-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-end-first-block.js rename to packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-end-first-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js b/packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-into-empty-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/adjacent-texts-into-empty-block.js rename to packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-into-empty-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js b/packages/slate/test/commands/value/insert-fragment/words/after-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/after-inline.js rename to packages/slate/test/commands/value/insert-fragment/words/after-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js b/packages/slate/test/commands/value/insert-fragment/words/before-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/before-inline.js rename to packages/slate/test/commands/value/insert-fragment/words/before-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js b/packages/slate/test/commands/value/insert-fragment/words/end-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/end-block.js rename to packages/slate/test/commands/value/insert-fragment/words/end-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js b/packages/slate/test/commands/value/insert-fragment/words/end-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/end-inline.js rename to packages/slate/test/commands/value/insert-fragment/words/end-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js b/packages/slate/test/commands/value/insert-fragment/words/middle-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/middle-block.js rename to packages/slate/test/commands/value/insert-fragment/words/middle-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js b/packages/slate/test/commands/value/insert-fragment/words/middle-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/middle-inline.js rename to packages/slate/test/commands/value/insert-fragment/words/middle-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js b/packages/slate/test/commands/value/insert-fragment/words/start-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/start-block.js rename to packages/slate/test/commands/value/insert-fragment/words/start-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js b/packages/slate/test/commands/value/insert-fragment/words/start-second-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/start-second-block.js rename to packages/slate/test/commands/value/insert-fragment/words/start-second-block.js diff --git a/packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js b/packages/slate/test/commands/value/insert-fragment/words/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-fragment/words/with-delete-across-blocks.js rename to packages/slate/test/commands/value/insert-fragment/words/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-end.js b/packages/slate/test/commands/value/insert-inline/block-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-inline/block-end.js rename to packages/slate/test/commands/value/insert-inline/block-end.js diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-middle.js b/packages/slate/test/commands/value/insert-inline/block-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-inline/block-middle.js rename to packages/slate/test/commands/value/insert-inline/block-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-inline/block-start.js b/packages/slate/test/commands/value/insert-inline/block-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-inline/block-start.js rename to packages/slate/test/commands/value/insert-inline/block-start.js diff --git a/packages/slate/test/commands/with-intent/insert-inline/inline-middle.js b/packages/slate/test/commands/value/insert-inline/inline-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-inline/inline-middle.js rename to packages/slate/test/commands/value/insert-inline/inline-middle.js diff --git a/packages/slate/test/commands/with-intent/insert-inline/is-empty.js b/packages/slate/test/commands/value/insert-inline/is-empty.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-inline/is-empty.js rename to packages/slate/test/commands/value/insert-inline/is-empty.js diff --git a/packages/slate/test/commands/with-intent/insert-inline/is-void.js b/packages/slate/test/commands/value/insert-inline/is-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-inline/is-void.js rename to packages/slate/test/commands/value/insert-inline/is-void.js diff --git a/packages/slate/test/commands/with-intent/insert-inline/with-inline.js b/packages/slate/test/commands/value/insert-inline/with-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-inline/with-inline.js rename to packages/slate/test/commands/value/insert-inline/with-inline.js diff --git a/packages/slate/test/commands/with-intent/insert-text/after-mark.js b/packages/slate/test/commands/value/insert-text/after-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/after-mark.js rename to packages/slate/test/commands/value/insert-text/after-mark.js diff --git a/packages/slate/test/commands/with-intent/insert-text/before-mark.js b/packages/slate/test/commands/value/insert-text/before-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/before-mark.js rename to packages/slate/test/commands/value/insert-text/before-mark.js diff --git a/packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js b/packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/blocks-with-overlapping-marks.js rename to packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js diff --git a/packages/slate/test/commands/with-intent/insert-text/during-mark.js b/packages/slate/test/commands/value/insert-text/during-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/during-mark.js rename to packages/slate/test/commands/value/insert-text/during-mark.js diff --git a/packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js b/packages/slate/test/commands/value/insert-text/empty-block-with-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/empty-block-with-mark.js rename to packages/slate/test/commands/value/insert-text/empty-block-with-mark.js diff --git a/packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js b/packages/slate/test/commands/value/insert-text/expanded-with-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/expanded-with-mark.js rename to packages/slate/test/commands/value/insert-text/expanded-with-mark.js diff --git a/packages/slate/test/commands/with-intent/insert-text/first-character.js b/packages/slate/test/commands/value/insert-text/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/first-character.js rename to packages/slate/test/commands/value/insert-text/first-character.js diff --git a/packages/slate/test/commands/with-intent/insert-text/first-space.js b/packages/slate/test/commands/value/insert-text/first-space.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/first-space.js rename to packages/slate/test/commands/value/insert-text/first-space.js diff --git a/packages/slate/test/commands/with-intent/insert-text/first-words.js b/packages/slate/test/commands/value/insert-text/first-words.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/first-words.js rename to packages/slate/test/commands/value/insert-text/first-words.js diff --git a/packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/value/insert-text/hanging-selection-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/hanging-selection-multiple-blocks.js rename to packages/slate/test/commands/value/insert-text/hanging-selection-multiple-blocks.js diff --git a/packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js b/packages/slate/test/commands/value/insert-text/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/hanging-selection-single-block.js rename to packages/slate/test/commands/value/insert-text/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/with-intent/insert-text/inside-void.js b/packages/slate/test/commands/value/insert-text/inside-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/inside-void.js rename to packages/slate/test/commands/value/insert-text/inside-void.js diff --git a/packages/slate/test/commands/with-intent/insert-text/last-character.js b/packages/slate/test/commands/value/insert-text/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/last-character.js rename to packages/slate/test/commands/value/insert-text/last-character.js diff --git a/packages/slate/test/commands/with-intent/insert-text/last-space.js b/packages/slate/test/commands/value/insert-text/last-space.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/last-space.js rename to packages/slate/test/commands/value/insert-text/last-space.js diff --git a/packages/slate/test/commands/with-intent/insert-text/last-words.js b/packages/slate/test/commands/value/insert-text/last-words.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/last-words.js rename to packages/slate/test/commands/value/insert-text/last-words.js diff --git a/packages/slate/test/commands/with-intent/insert-text/middle-character.js b/packages/slate/test/commands/value/insert-text/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/middle-character.js rename to packages/slate/test/commands/value/insert-text/middle-character.js diff --git a/packages/slate/test/commands/with-intent/insert-text/middle-space.js b/packages/slate/test/commands/value/insert-text/middle-space.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/middle-space.js rename to packages/slate/test/commands/value/insert-text/middle-space.js diff --git a/packages/slate/test/commands/with-intent/insert-text/middle-words.js b/packages/slate/test/commands/value/insert-text/middle-words.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/middle-words.js rename to packages/slate/test/commands/value/insert-text/middle-words.js diff --git a/packages/slate/test/commands/with-intent/insert-text/with-marks.js b/packages/slate/test/commands/value/insert-text/with-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/insert-text/with-marks.js rename to packages/slate/test/commands/value/insert-text/with-marks.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/across-blocks.js b/packages/slate/test/commands/value/remove-mark/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/across-blocks.js rename to packages/slate/test/commands/value/remove-mark/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/across-inlines.js b/packages/slate/test/commands/value/remove-mark/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/across-inlines.js rename to packages/slate/test/commands/value/remove-mark/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js b/packages/slate/test/commands/value/remove-mark/collapsed-selection.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/collapsed-selection.js rename to packages/slate/test/commands/value/remove-mark/collapsed-selection.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/existing-marks.js b/packages/slate/test/commands/value/remove-mark/existing-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/existing-marks.js rename to packages/slate/test/commands/value/remove-mark/existing-marks.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/first-character.js b/packages/slate/test/commands/value/remove-mark/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/first-character.js rename to packages/slate/test/commands/value/remove-mark/first-character.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/last-character.js b/packages/slate/test/commands/value/remove-mark/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/last-character.js rename to packages/slate/test/commands/value/remove-mark/last-character.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/middle-character.js b/packages/slate/test/commands/value/remove-mark/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/middle-character.js rename to packages/slate/test/commands/value/remove-mark/middle-character.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/part-of-mark-backward.js b/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/part-of-mark-backward.js rename to packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/part-of-mark.js b/packages/slate/test/commands/value/remove-mark/part-of-mark.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/part-of-mark.js rename to packages/slate/test/commands/value/remove-mark/part-of-mark.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/whole-word.js b/packages/slate/test/commands/value/remove-mark/whole-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/whole-word.js rename to packages/slate/test/commands/value/remove-mark/whole-word.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js b/packages/slate/test/commands/value/remove-mark/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/with-mark-object.js rename to packages/slate/test/commands/value/remove-mark/with-mark-object.js diff --git a/packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js b/packages/slate/test/commands/value/remove-mark/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/remove-mark/with-plain-object.js rename to packages/slate/test/commands/value/remove-mark/with-plain-object.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/across-blocks.js b/packages/slate/test/commands/value/replace-mark/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/across-blocks.js rename to packages/slate/test/commands/value/replace-mark/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/across-inlines.js b/packages/slate/test/commands/value/replace-mark/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/across-inlines.js rename to packages/slate/test/commands/value/replace-mark/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/existing-marks.js b/packages/slate/test/commands/value/replace-mark/existing-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/existing-marks.js rename to packages/slate/test/commands/value/replace-mark/existing-marks.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/first-character.js b/packages/slate/test/commands/value/replace-mark/first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/first-character.js rename to packages/slate/test/commands/value/replace-mark/first-character.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/last-character.js b/packages/slate/test/commands/value/replace-mark/last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/last-character.js rename to packages/slate/test/commands/value/replace-mark/last-character.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/middle-character.js b/packages/slate/test/commands/value/replace-mark/middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/middle-character.js rename to packages/slate/test/commands/value/replace-mark/middle-character.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/whole-word.js b/packages/slate/test/commands/value/replace-mark/whole-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/whole-word.js rename to packages/slate/test/commands/value/replace-mark/whole-word.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js b/packages/slate/test/commands/value/replace-mark/with-mark-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/with-mark-object.js rename to packages/slate/test/commands/value/replace-mark/with-mark-object.js diff --git a/packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js b/packages/slate/test/commands/value/replace-mark/with-plain-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/replace-mark/with-plain-object.js rename to packages/slate/test/commands/value/replace-mark/with-plain-object.js diff --git a/packages/slate/test/commands/with-intent/set-block/across-blocks.js b/packages/slate/test/commands/value/set-block/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/across-blocks.js rename to packages/slate/test/commands/value/set-block/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/set-block/across-inlines.js b/packages/slate/test/commands/value/set-block/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/across-inlines.js rename to packages/slate/test/commands/value/set-block/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/set-block/data-only.js b/packages/slate/test/commands/value/set-block/data-only.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/data-only.js rename to packages/slate/test/commands/value/set-block/data-only.js diff --git a/packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js b/packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/hanging-selection-across-inlines.js rename to packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js diff --git a/packages/slate/test/commands/with-intent/set-block/hanging-selection.js b/packages/slate/test/commands/value/set-block/hanging-selection.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/hanging-selection.js rename to packages/slate/test/commands/value/set-block/hanging-selection.js diff --git a/packages/slate/test/commands/with-intent/set-block/nested-block.js b/packages/slate/test/commands/value/set-block/nested-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/nested-block.js rename to packages/slate/test/commands/value/set-block/nested-block.js diff --git a/packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js b/packages/slate/test/commands/value/set-block/single-block-string-shorthand.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/single-block-string-shorthand.js rename to packages/slate/test/commands/value/set-block/single-block-string-shorthand.js diff --git a/packages/slate/test/commands/with-intent/set-block/single-block.js b/packages/slate/test/commands/value/set-block/single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/single-block.js rename to packages/slate/test/commands/value/set-block/single-block.js diff --git a/packages/slate/test/commands/with-intent/set-block/with-data-as-map.js b/packages/slate/test/commands/value/set-block/with-data-as-map.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/with-data-as-map.js rename to packages/slate/test/commands/value/set-block/with-data-as-map.js diff --git a/packages/slate/test/commands/with-intent/set-block/with-data-as-object.js b/packages/slate/test/commands/value/set-block/with-data-as-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/with-data-as-object.js rename to packages/slate/test/commands/value/set-block/with-data-as-object.js diff --git a/packages/slate/test/commands/with-intent/set-block/with-is-void.js b/packages/slate/test/commands/value/set-block/with-is-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-block/with-is-void.js rename to packages/slate/test/commands/value/set-block/with-is-void.js diff --git a/packages/slate/test/commands/on-state/set-data/simple.js b/packages/slate/test/commands/value/set-data/simple.js similarity index 100% rename from packages/slate/test/commands/on-state/set-data/simple.js rename to packages/slate/test/commands/value/set-data/simple.js diff --git a/packages/slate/test/commands/with-intent/set-inline/across-inlines.js b/packages/slate/test/commands/value/set-inline/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/across-inlines.js rename to packages/slate/test/commands/value/set-inline/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/set-inline/data-only.js b/packages/slate/test/commands/value/set-inline/data-only.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/data-only.js rename to packages/slate/test/commands/value/set-inline/data-only.js diff --git a/packages/slate/test/commands/with-intent/set-inline/nested-inline.js b/packages/slate/test/commands/value/set-inline/nested-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/nested-inline.js rename to packages/slate/test/commands/value/set-inline/nested-inline.js diff --git a/packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js b/packages/slate/test/commands/value/set-inline/single-inline-string-shorthand.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/single-inline-string-shorthand.js rename to packages/slate/test/commands/value/set-inline/single-inline-string-shorthand.js diff --git a/packages/slate/test/commands/with-intent/set-inline/single-inline.js b/packages/slate/test/commands/value/set-inline/single-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/single-inline.js rename to packages/slate/test/commands/value/set-inline/single-inline.js diff --git a/packages/slate/test/commands/with-intent/set-inline/with-data-object.js b/packages/slate/test/commands/value/set-inline/with-data-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/with-data-object.js rename to packages/slate/test/commands/value/set-inline/with-data-object.js diff --git a/packages/slate/test/commands/with-intent/set-inline/with-data.js b/packages/slate/test/commands/value/set-inline/with-data.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/with-data.js rename to packages/slate/test/commands/value/set-inline/with-data.js diff --git a/packages/slate/test/commands/with-intent/set-inline/with-is-void.js b/packages/slate/test/commands/value/set-inline/with-is-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/set-inline/with-is-void.js rename to packages/slate/test/commands/value/set-inline/with-is-void.js diff --git a/packages/slate/test/commands/with-intent/split-block/after-inline-void.js b/packages/slate/test/commands/value/split-block/after-inline-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/after-inline-void.js rename to packages/slate/test/commands/value/split-block/after-inline-void.js diff --git a/packages/slate/test/commands/with-intent/split-block/after-inline.js b/packages/slate/test/commands/value/split-block/after-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/after-inline.js rename to packages/slate/test/commands/value/split-block/after-inline.js diff --git a/packages/slate/test/commands/with-intent/split-block/before-inline.js b/packages/slate/test/commands/value/split-block/before-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/before-inline.js rename to packages/slate/test/commands/value/split-block/before-inline.js diff --git a/packages/slate/test/commands/with-intent/split-block/block-end.js b/packages/slate/test/commands/value/split-block/block-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/block-end.js rename to packages/slate/test/commands/value/split-block/block-end.js diff --git a/packages/slate/test/commands/with-intent/split-block/block-middle.js b/packages/slate/test/commands/value/split-block/block-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/block-middle.js rename to packages/slate/test/commands/value/split-block/block-middle.js diff --git a/packages/slate/test/commands/with-intent/split-block/block-start.js b/packages/slate/test/commands/value/split-block/block-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/block-start.js rename to packages/slate/test/commands/value/split-block/block-start.js diff --git a/packages/slate/test/commands/with-intent/split-block/depth.js b/packages/slate/test/commands/value/split-block/depth.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/depth.js rename to packages/slate/test/commands/value/split-block/depth.js diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/value/split-block/with-delete-across-blocks-and-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks-and-inlines.js rename to packages/slate/test/commands/value/split-block/with-delete-across-blocks-and-inlines.js diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js b/packages/slate/test/commands/value/split-block/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/with-delete-across-blocks.js rename to packages/slate/test/commands/value/split-block/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js b/packages/slate/test/commands/value/split-block/with-delete-hanging-selection.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/with-delete-hanging-selection.js rename to packages/slate/test/commands/value/split-block/with-delete-hanging-selection.js diff --git a/packages/slate/test/commands/with-intent/split-block/with-delete.js b/packages/slate/test/commands/value/split-block/with-delete.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/with-delete.js rename to packages/slate/test/commands/value/split-block/with-delete.js diff --git a/packages/slate/test/commands/with-intent/split-block/with-inline.js b/packages/slate/test/commands/value/split-block/with-inline.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/with-inline.js rename to packages/slate/test/commands/value/split-block/with-inline.js diff --git a/packages/slate/test/commands/with-intent/split-block/with-marks.js b/packages/slate/test/commands/value/split-block/with-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-block/with-marks.js rename to packages/slate/test/commands/value/split-block/with-marks.js diff --git a/packages/slate/test/commands/with-intent/split-inline/block-end.js b/packages/slate/test/commands/value/split-inline/block-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-inline/block-end.js rename to packages/slate/test/commands/value/split-inline/block-end.js diff --git a/packages/slate/test/commands/with-intent/split-inline/block-middle.js b/packages/slate/test/commands/value/split-inline/block-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-inline/block-middle.js rename to packages/slate/test/commands/value/split-inline/block-middle.js diff --git a/packages/slate/test/commands/with-intent/split-inline/block-start.js b/packages/slate/test/commands/value/split-inline/block-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-inline/block-start.js rename to packages/slate/test/commands/value/split-inline/block-start.js diff --git a/packages/slate/test/commands/with-intent/split-inline/height.js b/packages/slate/test/commands/value/split-inline/height.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-inline/height.js rename to packages/slate/test/commands/value/split-inline/height.js diff --git a/packages/slate/test/commands/with-intent/split-inline/with-delete.js b/packages/slate/test/commands/value/split-inline/with-delete.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-inline/with-delete.js rename to packages/slate/test/commands/value/split-inline/with-delete.js diff --git a/packages/slate/test/commands/with-intent/split-inline/with-marks.js b/packages/slate/test/commands/value/split-inline/with-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/split-inline/with-marks.js rename to packages/slate/test/commands/value/split-inline/with-marks.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js b/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-across-blocks.js rename to packages/slate/test/commands/value/toggle-mark/add-across-blocks.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js b/packages/slate/test/commands/value/toggle-mark/add-across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-across-inlines.js rename to packages/slate/test/commands/value/toggle-mark/add-across-inlines.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection-start.js rename to packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-collapsed-selection.js rename to packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js b/packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks-partially-marked.js rename to packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js b/packages/slate/test/commands/value/toggle-mark/add-existing-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-existing-marks.js rename to packages/slate/test/commands/value/toggle-mark/add-existing-marks.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js b/packages/slate/test/commands/value/toggle-mark/add-first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-first-character.js rename to packages/slate/test/commands/value/toggle-mark/add-first-character.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js b/packages/slate/test/commands/value/toggle-mark/add-last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-last-character.js rename to packages/slate/test/commands/value/toggle-mark/add-last-character.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js b/packages/slate/test/commands/value/toggle-mark/add-middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-middle-character.js rename to packages/slate/test/commands/value/toggle-mark/add-middle-character.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js b/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-partially-marked.js rename to packages/slate/test/commands/value/toggle-mark/add-partially-marked.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js b/packages/slate/test/commands/value/toggle-mark/add-whole-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-whole-word.js rename to packages/slate/test/commands/value/toggle-mark/add-whole-word.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js b/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-with-mark-object.js rename to packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js b/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/add-with-plain-object.js rename to packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js b/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-across-blocks.js rename to packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js b/packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-across-inlines.js rename to packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js b/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection-beginning.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection-beginning.js rename to packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection-beginning.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js b/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-collapsed-selection.js rename to packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js b/packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-existing-marks.js rename to packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js b/packages/slate/test/commands/value/toggle-mark/remove-first-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-first-character.js rename to packages/slate/test/commands/value/toggle-mark/remove-first-character.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js b/packages/slate/test/commands/value/toggle-mark/remove-last-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-last-character.js rename to packages/slate/test/commands/value/toggle-mark/remove-last-character.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js b/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-middle-character.js rename to packages/slate/test/commands/value/toggle-mark/remove-middle-character.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js b/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-whole-word.js rename to packages/slate/test/commands/value/toggle-mark/remove-whole-word.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js b/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-with-mark-object.js rename to packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js diff --git a/packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js b/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/toggle-mark/remove-with-plain-object.js rename to packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js b/packages/slate/test/commands/value/unwrap-block/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/across-blocks.js rename to packages/slate/test/commands/value/unwrap-block/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js b/packages/slate/test/commands/value/unwrap-block/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/across-inlines.js rename to packages/slate/test/commands/value/unwrap-block/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js b/packages/slate/test/commands/value/unwrap-block/ending-child-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/ending-child-blocks.js rename to packages/slate/test/commands/value/unwrap-block/ending-child-blocks.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js b/packages/slate/test/commands/value/unwrap-block/middle-child-blocks-with-backward-selection.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks-with-backward-selection.js rename to packages/slate/test/commands/value/unwrap-block/middle-child-blocks-with-backward-selection.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js b/packages/slate/test/commands/value/unwrap-block/middle-child-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/middle-child-blocks.js rename to packages/slate/test/commands/value/unwrap-block/middle-child-blocks.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/nested-block.js b/packages/slate/test/commands/value/unwrap-block/nested-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/nested-block.js rename to packages/slate/test/commands/value/unwrap-block/nested-block.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/single-block.js b/packages/slate/test/commands/value/unwrap-block/single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/single-block.js rename to packages/slate/test/commands/value/unwrap-block/single-block.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js b/packages/slate/test/commands/value/unwrap-block/starting-child-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/starting-child-blocks.js rename to packages/slate/test/commands/value/unwrap-block/starting-child-blocks.js diff --git a/packages/slate/test/commands/with-intent/unwrap-block/with-object.js b/packages/slate/test/commands/value/unwrap-block/with-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-block/with-object.js rename to packages/slate/test/commands/value/unwrap-block/with-object.js diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js b/packages/slate/test/commands/value/unwrap-inline/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-inline/across-blocks.js rename to packages/slate/test/commands/value/unwrap-inline/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js b/packages/slate/test/commands/value/unwrap-inline/across-inlines-and-text.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-inline/across-inlines-and-text.js rename to packages/slate/test/commands/value/unwrap-inline/across-inlines-and-text.js diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js b/packages/slate/test/commands/value/unwrap-inline/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-inline/across-inlines.js rename to packages/slate/test/commands/value/unwrap-inline/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js b/packages/slate/test/commands/value/unwrap-inline/nested-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-inline/nested-block.js rename to packages/slate/test/commands/value/unwrap-inline/nested-block.js diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/only-one.js b/packages/slate/test/commands/value/unwrap-inline/only-one.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-inline/only-one.js rename to packages/slate/test/commands/value/unwrap-inline/only-one.js diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/single-block.js b/packages/slate/test/commands/value/unwrap-inline/single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-inline/single-block.js rename to packages/slate/test/commands/value/unwrap-inline/single-block.js diff --git a/packages/slate/test/commands/with-intent/unwrap-inline/with-object.js b/packages/slate/test/commands/value/unwrap-inline/with-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/unwrap-inline/with-object.js rename to packages/slate/test/commands/value/unwrap-inline/with-object.js diff --git a/packages/slate/test/commands/with-intent/wrap-block/across-blocks.js b/packages/slate/test/commands/value/wrap-block/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-block/across-blocks.js rename to packages/slate/test/commands/value/wrap-block/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/wrap-block/across-inlines.js b/packages/slate/test/commands/value/wrap-block/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-block/across-inlines.js rename to packages/slate/test/commands/value/wrap-block/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js b/packages/slate/test/commands/value/wrap-block/nested-block-with-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-block/nested-block-with-object.js rename to packages/slate/test/commands/value/wrap-block/nested-block-with-object.js diff --git a/packages/slate/test/commands/with-intent/wrap-block/nested-block.js b/packages/slate/test/commands/value/wrap-block/nested-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-block/nested-block.js rename to packages/slate/test/commands/value/wrap-block/nested-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-block/single-block.js b/packages/slate/test/commands/value/wrap-block/single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-block/single-block.js rename to packages/slate/test/commands/value/wrap-block/single-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-block/with-object.js b/packages/slate/test/commands/value/wrap-block/with-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-block/with-object.js rename to packages/slate/test/commands/value/wrap-block/with-object.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js b/packages/slate/test/commands/value/wrap-inline/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/across-blocks.js rename to packages/slate/test/commands/value/wrap-inline/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js b/packages/slate/test/commands/value/wrap-inline/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/across-inlines.js rename to packages/slate/test/commands/value/wrap-inline/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/collapsed.js b/packages/slate/test/commands/value/wrap-inline/collapsed.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/collapsed.js rename to packages/slate/test/commands/value/wrap-inline/collapsed.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-end.js b/packages/slate/test/commands/value/wrap-inline/inline-end.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/inline-end.js rename to packages/slate/test/commands/value/wrap-inline/inline-end.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js b/packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/inline-middle-with-marks.js rename to packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js b/packages/slate/test/commands/value/wrap-inline/inline-middle.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/inline-middle.js rename to packages/slate/test/commands/value/wrap-inline/inline-middle.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-start.js b/packages/slate/test/commands/value/wrap-inline/inline-start.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/inline-start.js rename to packages/slate/test/commands/value/wrap-inline/inline-start.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/inline-void.js b/packages/slate/test/commands/value/wrap-inline/inline-void.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/inline-void.js rename to packages/slate/test/commands/value/wrap-inline/inline-void.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/nested-block.js b/packages/slate/test/commands/value/wrap-inline/nested-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/nested-block.js rename to packages/slate/test/commands/value/wrap-inline/nested-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/single-block.js b/packages/slate/test/commands/value/wrap-inline/single-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/single-block.js rename to packages/slate/test/commands/value/wrap-inline/single-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/twice.js b/packages/slate/test/commands/value/wrap-inline/twice.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/twice.js rename to packages/slate/test/commands/value/wrap-inline/twice.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/whole-block.js b/packages/slate/test/commands/value/wrap-inline/whole-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/whole-block.js rename to packages/slate/test/commands/value/wrap-inline/whole-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-inline/with-object.js b/packages/slate/test/commands/value/wrap-inline/with-object.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-inline/with-object.js rename to packages/slate/test/commands/value/wrap-inline/with-object.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/across-blocks.js b/packages/slate/test/commands/value/wrap-text/across-blocks.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/across-blocks.js rename to packages/slate/test/commands/value/wrap-text/across-blocks.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/across-inlines.js b/packages/slate/test/commands/value/wrap-text/across-inlines.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/across-inlines.js rename to packages/slate/test/commands/value/wrap-text/across-inlines.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js b/packages/slate/test/commands/value/wrap-text/backwards-selection.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/backwards-selection.js rename to packages/slate/test/commands/value/wrap-text/backwards-selection.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/empty-block.js b/packages/slate/test/commands/value/wrap-text/empty-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/empty-block.js rename to packages/slate/test/commands/value/wrap-text/empty-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/end-of-block.js b/packages/slate/test/commands/value/wrap-text/end-of-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/end-of-block.js rename to packages/slate/test/commands/value/wrap-text/end-of-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js b/packages/slate/test/commands/value/wrap-text/middle-of-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/middle-of-block.js rename to packages/slate/test/commands/value/wrap-text/middle-of-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/start-of-block.js b/packages/slate/test/commands/value/wrap-text/start-of-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/start-of-block.js rename to packages/slate/test/commands/value/wrap-text/start-of-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/whole-block.js b/packages/slate/test/commands/value/wrap-text/whole-block.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/whole-block.js rename to packages/slate/test/commands/value/wrap-text/whole-block.js diff --git a/packages/slate/test/commands/with-intent/wrap-text/without-suffix.js b/packages/slate/test/commands/value/wrap-text/without-suffix.js similarity index 100% rename from packages/slate/test/commands/with-intent/wrap-text/without-suffix.js rename to packages/slate/test/commands/value/wrap-text/without-suffix.js From 906f6e11aa3ad2e16076ef8e99dafa63e526bf66 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 21 Oct 2019 14:15:18 -0400 Subject: [PATCH 039/165] add value queries tests --- packages/slate/src/classes/commands/path.ts | 34 +-- packages/slate/src/classes/commands/point.ts | 1 - .../slate/src/classes/commands/selection.ts | 142 +++++---- packages/slate/src/classes/queries/path.ts | 67 ++++- packages/slate/src/classes/queries/value.ts | 284 ++++++++++-------- packages/slate/src/interfaces/node.ts | 161 ++++++---- packages/slate/src/interfaces/operation.ts | 94 ++++-- packages/slate/src/interfaces/value.ts | 18 +- .../delete-backward-at-range/from-offset.js | 37 --- .../test/commands/on-selection/blur/basic.js | 14 +- .../commands/on-selection/deselect/basic.js | 21 ++ .../on-selection/deselect/unfocused.js | 21 ++ .../test/commands/on-selection/focus/basic.js | 14 +- .../move-anchor-backward/default.js | 18 +- .../move-anchor-backward/from-collapsed.js | 18 +- .../move-anchor-backward/out-of-reverse.js | 18 +- .../move-anchor-backward/param.js | 18 +- packages/slate/test/index.js | 8 + .../test/interfaces/Node/entries/pass.js | 45 +++ .../test/interfaces/Node/entries/reverse.js | 17 ++ .../queries/value/blocks/block-multiple.js | 21 ++ .../test/queries/value/blocks/block-nested.js | 36 +++ .../queries/value/blocks/block-reverse.js | 21 ++ .../test/queries/value/blocks/block-void.js | 24 ++ .../slate/test/queries/value/blocks/block.js | 15 + .../slate/test/queries/value/blocks/inline.js | 24 ++ .../queries/value/entries/block-multiple.js | 28 ++ .../queries/value/entries/block-nested.js | 48 +++ .../queries/value/entries/block-reverse.js | 28 ++ .../test/queries/value/entries/block-void.js | 23 ++ .../slate/test/queries/value/entries/block.js | 24 ++ .../queries/value/entries/inline-multiple.js | 39 +++ .../queries/value/entries/inline-nested.js | 50 +++ .../queries/value/entries/inline-reverse.js | 39 +++ .../test/queries/value/entries/inline-void.js | 35 +++ .../test/queries/value/entries/inline.js | 36 +++ .../value/getActiveMarks/block-across.js | 28 ++ .../value/getActiveMarks/block-start.js | 20 ++ .../value/getActiveMarks/inline-start.js | 22 ++ .../value/getActiveMarks/intersection.js | 21 ++ .../queries/value/getActiveMarks/multiple.js | 21 ++ .../test/queries/value/getActiveMarks/none.js | 17 ++ .../test/queries/value/getActiveMarks/one.js | 19 ++ .../value/getActiveMarks/selection-marks.js | 19 ++ .../value/getActiveMarks/selection-null.js | 17 ++ .../value/getActiveMarks/text-start.js | 19 ++ .../queries/value/getActiveMarks/union.js | 21 ++ .../slate/test/queries/value/inlines/block.js | 15 + .../queries/value/inlines/inline-multiple.js | 20 ++ .../queries/value/inlines/inline-nested.js | 27 ++ .../queries/value/inlines/inline-reverse.js | 20 ++ .../test/queries/value/inlines/inline-void.js | 17 ++ .../test/queries/value/inlines/inline.js | 17 ++ .../value/leafBlocks/block-multiple.js | 21 ++ .../queries/value/leafBlocks/block-nested.js | 23 ++ .../queries/value/leafBlocks/block-reverse.js | 21 ++ .../queries/value/leafBlocks/block-void.js | 24 ++ .../test/queries/value/leafBlocks/block.js | 15 + .../test/queries/value/leafBlocks/inline.js | 24 ++ .../test/queries/value/leafInlines/block.js | 15 + .../value/leafInlines/inline-multiple.js | 20 ++ .../value/leafInlines/inline-nested.js | 19 ++ .../value/leafInlines/inline-reverse.js | 20 ++ .../queries/value/leafInlines/inline-void.js | 17 ++ .../test/queries/value/leafInlines/inline.js | 17 ++ .../queries/value/positions/block-multiple.js | 32 ++ .../queries/value/positions/block-nested.js | 29 ++ .../queries/value/positions/block-reverse.js | 20 ++ .../test/queries/value/positions/block.js | 20 ++ .../value/positions/inline-multiple.js | 38 +++ .../queries/value/positions/inline-nested.js | 40 +++ .../queries/value/positions/inline-reverse.js | 30 ++ .../test/queries/value/positions/inline.js | 30 ++ .../test/queries/value/positions/point.js | 15 + .../value/positions/unit-block-reverse.js | 20 ++ .../queries/value/positions/unit-block.js | 20 ++ .../value/positions/unit-character-reverse.js | 30 ++ .../queries/value/positions/unit-character.js | 30 ++ .../value/positions/unit-line-reverse.js | 20 ++ .../test/queries/value/positions/unit-line.js | 20 ++ .../value/positions/unit-word-reverse.js | 24 ++ .../test/queries/value/positions/unit-word.js | 24 ++ .../value/rootBlocks/block-multiple.js | 21 ++ .../queries/value/rootBlocks/block-nested.js | 33 ++ .../queries/value/rootBlocks/block-reverse.js | 21 ++ .../queries/value/rootBlocks/block-void.js | 24 ++ .../test/queries/value/rootBlocks/block.js | 15 + .../test/queries/value/rootBlocks/inline.js | 24 ++ .../test/queries/value/rootInlines/block.js | 15 + .../value/rootInlines/inline-multiple.js | 20 ++ .../value/rootInlines/inline-nested.js | 26 ++ .../value/rootInlines/inline-reverse.js | 20 ++ .../queries/value/rootInlines/inline-void.js | 17 ++ .../test/queries/value/rootInlines/inline.js | 17 ++ .../queries/value/texts/block-multiple.js | 16 + .../test/queries/value/texts/block-nested.js | 23 ++ .../test/queries/value/texts/block-reverse.js | 16 + .../test/queries/value/texts/block-void.js | 15 + .../slate/test/queries/value/texts/block.js | 15 + .../queries/value/texts/inline-multiple.js | 23 ++ .../test/queries/value/texts/inline-nested.js | 25 ++ .../queries/value/texts/inline-reverse.js | 23 ++ .../test/queries/value/texts/inline-void.js | 17 ++ .../slate/test/queries/value/texts/inline.js | 21 ++ 104 files changed, 2596 insertions(+), 410 deletions(-) delete mode 100644 packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js create mode 100644 packages/slate/test/commands/on-selection/deselect/basic.js create mode 100644 packages/slate/test/commands/on-selection/deselect/unfocused.js create mode 100644 packages/slate/test/interfaces/Node/entries/pass.js create mode 100644 packages/slate/test/queries/value/blocks/block-multiple.js create mode 100644 packages/slate/test/queries/value/blocks/block-nested.js create mode 100644 packages/slate/test/queries/value/blocks/block-reverse.js create mode 100644 packages/slate/test/queries/value/blocks/block-void.js create mode 100644 packages/slate/test/queries/value/blocks/block.js create mode 100644 packages/slate/test/queries/value/blocks/inline.js create mode 100644 packages/slate/test/queries/value/entries/block-multiple.js create mode 100644 packages/slate/test/queries/value/entries/block-nested.js create mode 100644 packages/slate/test/queries/value/entries/block-reverse.js create mode 100644 packages/slate/test/queries/value/entries/block-void.js create mode 100644 packages/slate/test/queries/value/entries/block.js create mode 100644 packages/slate/test/queries/value/entries/inline-multiple.js create mode 100644 packages/slate/test/queries/value/entries/inline-nested.js create mode 100644 packages/slate/test/queries/value/entries/inline-reverse.js create mode 100644 packages/slate/test/queries/value/entries/inline-void.js create mode 100644 packages/slate/test/queries/value/entries/inline.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/block-across.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/block-start.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/inline-start.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/intersection.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/multiple.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/none.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/one.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/selection-marks.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/selection-null.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/text-start.js create mode 100644 packages/slate/test/queries/value/getActiveMarks/union.js create mode 100644 packages/slate/test/queries/value/inlines/block.js create mode 100644 packages/slate/test/queries/value/inlines/inline-multiple.js create mode 100644 packages/slate/test/queries/value/inlines/inline-nested.js create mode 100644 packages/slate/test/queries/value/inlines/inline-reverse.js create mode 100644 packages/slate/test/queries/value/inlines/inline-void.js create mode 100644 packages/slate/test/queries/value/inlines/inline.js create mode 100644 packages/slate/test/queries/value/leafBlocks/block-multiple.js create mode 100644 packages/slate/test/queries/value/leafBlocks/block-nested.js create mode 100644 packages/slate/test/queries/value/leafBlocks/block-reverse.js create mode 100644 packages/slate/test/queries/value/leafBlocks/block-void.js create mode 100644 packages/slate/test/queries/value/leafBlocks/block.js create mode 100644 packages/slate/test/queries/value/leafBlocks/inline.js create mode 100644 packages/slate/test/queries/value/leafInlines/block.js create mode 100644 packages/slate/test/queries/value/leafInlines/inline-multiple.js create mode 100644 packages/slate/test/queries/value/leafInlines/inline-nested.js create mode 100644 packages/slate/test/queries/value/leafInlines/inline-reverse.js create mode 100644 packages/slate/test/queries/value/leafInlines/inline-void.js create mode 100644 packages/slate/test/queries/value/leafInlines/inline.js create mode 100644 packages/slate/test/queries/value/positions/block-multiple.js create mode 100644 packages/slate/test/queries/value/positions/block-nested.js create mode 100644 packages/slate/test/queries/value/positions/block-reverse.js create mode 100644 packages/slate/test/queries/value/positions/block.js create mode 100644 packages/slate/test/queries/value/positions/inline-multiple.js create mode 100644 packages/slate/test/queries/value/positions/inline-nested.js create mode 100644 packages/slate/test/queries/value/positions/inline-reverse.js create mode 100644 packages/slate/test/queries/value/positions/inline.js create mode 100644 packages/slate/test/queries/value/positions/point.js create mode 100644 packages/slate/test/queries/value/positions/unit-block-reverse.js create mode 100644 packages/slate/test/queries/value/positions/unit-block.js create mode 100644 packages/slate/test/queries/value/positions/unit-character-reverse.js create mode 100644 packages/slate/test/queries/value/positions/unit-character.js create mode 100644 packages/slate/test/queries/value/positions/unit-line-reverse.js create mode 100644 packages/slate/test/queries/value/positions/unit-line.js create mode 100644 packages/slate/test/queries/value/positions/unit-word-reverse.js create mode 100644 packages/slate/test/queries/value/positions/unit-word.js create mode 100644 packages/slate/test/queries/value/rootBlocks/block-multiple.js create mode 100644 packages/slate/test/queries/value/rootBlocks/block-nested.js create mode 100644 packages/slate/test/queries/value/rootBlocks/block-reverse.js create mode 100644 packages/slate/test/queries/value/rootBlocks/block-void.js create mode 100644 packages/slate/test/queries/value/rootBlocks/block.js create mode 100644 packages/slate/test/queries/value/rootBlocks/inline.js create mode 100644 packages/slate/test/queries/value/rootInlines/block.js create mode 100644 packages/slate/test/queries/value/rootInlines/inline-multiple.js create mode 100644 packages/slate/test/queries/value/rootInlines/inline-nested.js create mode 100644 packages/slate/test/queries/value/rootInlines/inline-reverse.js create mode 100644 packages/slate/test/queries/value/rootInlines/inline-void.js create mode 100644 packages/slate/test/queries/value/rootInlines/inline.js create mode 100644 packages/slate/test/queries/value/texts/block-multiple.js create mode 100644 packages/slate/test/queries/value/texts/block-nested.js create mode 100644 packages/slate/test/queries/value/texts/block-reverse.js create mode 100644 packages/slate/test/queries/value/texts/block-void.js create mode 100644 packages/slate/test/queries/value/texts/block.js create mode 100644 packages/slate/test/queries/value/texts/inline-multiple.js create mode 100644 packages/slate/test/queries/value/texts/inline-nested.js create mode 100644 packages/slate/test/queries/value/texts/inline-reverse.js create mode 100644 packages/slate/test/queries/value/texts/inline-void.js create mode 100644 packages/slate/test/queries/value/texts/inline.js diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 039a813917..7bd30855dd 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -367,17 +367,15 @@ class PathCommands { } const newProps = {} - let isChange = true for (const k in props) { if (props[k] !== match[k]) { - isChange = true newProps[k] = props[k] } } - // PERF: If no properties have changed don't apply an operation at all. - if (!isChange) { + // If no properties have changed don't apply an operation at all. + if (Object.keys(newProps).length !== 0) { return } @@ -403,38 +401,20 @@ class PathCommands { const node = Node.get(value, path) const newProps = {} const oldProps = {} - let isChange = true for (const k in props) { - // Disallow setting restricted properties that should use the editor - // methods that result in more semantic operations being applied. - if (Element.isElement(node) && k === 'nodes') { - throw new Error( - `Cannot set the \`nodes\` property of an element node at path [${path}]. You must use the node-specific editor methods instead like \`editor.insertNodeAtPath\`, \`editor.removeNodeAtPath\`, etc.` - ) - } - - if (Text.isText(node) && k === 'text') { - throw new Error( - `Cannot set the \`text\` property of a text node at path [${path}]. You must use the text-specific editor methods instead like \`editor.insertTextAtPath\`, \`editor.removeTextAtPath\`, etc.` - ) - } - - if (Text.isText(node) && k === 'marks') { - throw new Error( - `Cannot set the \`marks\` property of a text node at path [${path}]. You must use the text-specific editor methods instead like \`editor.addMarkAtPath\`, \`editor.removeMarkAtPath\`, etc.` - ) + if (k === 'nodes' || k === 'text' || k === 'marks') { + continue } if (props[k] !== node[k]) { - isChange = true - newProps[k] = props[k] oldProps[k] = node[k] + newProps[k] = props[k] } } - // PERF: If no properties have changed don't apply an operation at all. - if (!isChange) { + // If no properties have changed don't apply an operation at all. + if (Object.keys(newProps).length !== 0) { return } diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index 6a5bb82b1b..5e0995604e 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -268,7 +268,6 @@ class PointCommands { // Iterate up the ancestors, splitting each until the right depth. while (h <= height) { - debugger const depth = path.length - h const p = path.slice(0, depth) diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index b656055460..09366ff02f 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -6,7 +6,11 @@ class SelectionCommands { */ blur(this: Editor) { - this.select({ isFocused: false }) + const { selection } = this.value + + if (selection != null) { + this.select({ isFocused: false }) + } } /** @@ -14,7 +18,15 @@ class SelectionCommands { */ deselect(this: Editor) { - this.select(null) + const { selection } = this.value + + if (selection != null) { + this.apply({ + type: 'set_selection', + properties: selection, + newProperties: null, + }) + } } /** @@ -22,7 +34,11 @@ class SelectionCommands { */ focus(this: Editor) { - this.select({ isFocused: true }) + const { selection } = this.value + + if (selection != null) { + this.select({ isFocused: true }) + } } /** @@ -32,12 +48,10 @@ class SelectionCommands { flip(this: Editor) { const { selection } = this.value - if (selection == null) { - return + if (selection != null) { + const { anchor, focus } = selection + this.setSelection({ anchor: focus, focus: anchor }) } - - const { anchor, focus } = selection - this.select({ anchor: focus, focus: anchor }) } /** @@ -94,7 +108,7 @@ class SelectionCommands { */ moveAnchorTo(this: Editor, point: Point) { - this.select({ anchor: point }) + this.setSelection({ anchor: point }) } /** @@ -172,7 +186,7 @@ class SelectionCommands { */ moveFocusTo(this: Editor, point: Point) { - this.select({ anchor: point }) + this.setSelection({ anchor: point }) } /** @@ -219,69 +233,85 @@ class SelectionCommands { */ moveTo(this: Editor, point: Point) { - this.select({ anchor: point, focus: point }) + this.setSelection({ anchor: point, focus: point }) } /** - * Set new properties on the selection. + * Set the selection to a new value. */ - select(this: Editor, properties: Partial | null) { + select(this: Editor, props: Partial) { const { selection } = this.value - let prevProps: Partial | null = {} - let newProps: Partial | null = {} - if (selection == null && properties == null) { + if (selection != null) { + this.setSelection(props) return - } else if (properties == null) { - newProps = null - prevProps = selection - } else if (selection == null) { - newProps = { isFocused: false, ...properties } - prevProps = null - - if (!Selection.isSelection(newProps)) { - throw new Error( - `When setting new selection properties and the current selection is \`null\` you must provide a full selection, but you passed: ${properties}` - ) - } - } else { - let isChange = false - - // Remove any properties that aren't different from the existing selection. - for (const k in properties) { - const isPoint = k === 'anchor' || k === 'focus' - - if ( - (isPoint && !Point.equals(properties[k], selection[k])) || - (!isPoint && properties[k] !== selection[k]) - ) { - isChange = true - newProps[k] = properties[k] - prevProps[k] = selection[k] - } - } + } + + if (!Range.isRange(props)) { + throw new Error( + `When setting the selection and the current selection is \`null\` you must provide at least an \`anchor\` and \`focus\`, but you passed: ${JSON.stringify( + props + )}` + ) + } - // If the selection moves, clear any marks, unless the new selection - // properties change the marks in some way. + this.apply({ + type: 'set_selection', + properties: selection, + newProperties: { isFocused: false, marks: null, ...props }, + }) + } + + /** + * Set new props on the selection. + */ + + setSelection(this: Editor, props: Partial) { + const { selection } = this.value + let oldProps: Partial | null = {} + let newProps: Partial = {} + + if (selection == null) { + this.select(props) + return + } + + // Remove any props that aren't different from the existing selection. + for (const k in props) { if ( - selection.marks && - !newProps.marks && - (newProps.anchor || newProps.focus) + (k === 'anchor' && + props.anchor != null && + !Point.equals(props.anchor, selection.anchor)) || + (k === 'focus' && + props.focus != null && + !Point.equals(props.focus, selection.focus)) || + props[k] !== selection[k] ) { - isChange = true - newProps.marks = null - prevProps.marks = selection.marks + oldProps[k] = selection[k] + newProps[k] = props[k] } + } - if (!isChange) { - return - } + // If the selection moves, clear any marks, unless the new selection + // props change the marks in some way. + if ( + selection.marks != null && + newProps.marks === undefined && + (newProps.anchor || newProps.focus) + ) { + newProps.marks = null + oldProps.marks = selection.marks + } + + // If nothing has changed, don't apply any operations. + if (Object.keys(oldProps).length === 0) { + return } this.apply({ type: 'set_selection', - properties: prevProps, + properties: oldProps, newProperties: newProps, }) } diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 79b7f1e477..1caaea2209 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -15,6 +15,69 @@ import { import { PATH_REFS } from '../../symbols' class PathQueries { + hasVoidAncestor(this: Editor, path: Path): boolean { + const furthestVoid = this.getFurthestVoid(path) + + if (furthestVoid) { + const [, voidPath] = furthestVoid + return Path.isAncestor(voidPath, path) + } + + return false + } + + getText(this: Editor, path: Path): string { + const { value } = this + const node = Node.get(value, path) + + if (this.hasVoidAncestor(path)) { + return '' + } else if (Element.isElement(node) && this.isVoid(node)) { + return '' + } else if (Text.isText(node)) { + return node.text + } else { + return node.nodes.map((n, i) => this.getText(path.concat(i))).join('') + } + } + + getOffset( + this: Editor, + path: Path, + options: { + depth?: number + } = {} + ): number { + const { value } = this + const { depth = 0 } = options + + if (path.length === depth) { + return 0 + } + + const rootPath = path.slice(0, depth) + const root = Node.get(value, rootPath) + const relPath = Path.relative(path, rootPath) + + if (Text.isText(root)) { + throw new Error( + `Cannot get the offset into a root text node: ${JSON.stringify(root)}` + ) + } + + const [index] = relPath + let o = 0 + + for (let i = 0; i < index; i++) { + const text = this.getText(rootPath.concat(i)) + o += text.length + } + + const relOffset = this.getOffset(path, { depth: depth + 1 }) + o += relOffset + return o + } + /** * Create a mutable ref for a `Path` object, which will stay in sync as new * operations are applied to the this. @@ -316,8 +379,8 @@ class PathQueries { */ getStart(this: Editor, path: Path): Point { - const [firstNode, firstPath] = this.getFirstText(path) - const point = { path: firstPath, offset: firstNode.text.length } + const [, firstPath] = this.getFirstText(path) + const point = { path: firstPath, offset: 0 } return point } } diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 1ac5c8450a..b218787300 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -3,13 +3,16 @@ import { reverse as reverseText } from 'esrever' import { Ancestor, Editor, + Element, ElementEntry, Mark, Node, + NodeEntry, Path, Point, Range, String, + Text, TextEntry, } from '../..' @@ -18,12 +21,37 @@ class ValueQueries { * Iterate through all of the block nodes in the editor. */ - *blocks(this: Editor, options: {} = {}): Iterable { - for (const [n, p] of Node.elements(this.value, options)) { - if (!this.isInline(n)) { - yield [n, p] - } - } + *blocks( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { + yield* Node.elements(this.value, { + ...options, + pass: ([n]) => + Element.isElement(n) && (this.isVoid(n) || this.hasInlines(n)), + }) + } + + /** + * Iterate through all of the nodes in the editor. + */ + + *entries( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { + yield* Node.entries(this.value, { + ...options, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) } /** @@ -59,29 +87,27 @@ class ValueQueries { let range: Range = selection let result: Mark[] = [] let first = true + const { anchor } = range // If the range is collapsed at the start of a text node, it should carry // over the marks from the previous text node in the same block. if ( Range.isCollapsed(range) && // PERF: If the offset isn't zero we know it's not at the start. - range.anchor.offset === 0 + anchor.offset === 0 && + // PERF: If it's the first sibling, we know it can't carry over. + anchor.path[anchor.path.length - 1] !== 0 ) { - const { anchor } = range - const closestBlock = this.getClosestBlock(anchor.path) - const prevText = this.getPreviousText(anchor.path) + const prevPath = Path.previous(anchor.path) + const prevNode = Node.get(value, prevPath) - if (closestBlock && prevText) { - const [, blockPath] = closestBlock - const [, prevPath] = prevText - - if (Path.isAncestor(blockPath, prevPath)) { - range = this.getRange(prevPath) - } + if (Text.isText(prevNode)) { + range = this.getRange(prevPath) } } - for (const [node] of Node.texts(value, { range })) { + for (const [node] of this.texts({ range })) { + debugger const { marks } = node if (first) { @@ -98,13 +124,12 @@ class ValueQueries { if (union) { for (const mark of marks) { - if (!Mark.exists(mark, marks)) { + if (!Mark.exists(mark, result)) { result.push(mark) } } } else { - // When intersecting, iterate backwards so that removing marks doesn't - // impact indexing. + // Iterate backwards so that removing marks doesn't impact indexing. for (let i = result.length - 1; i >= 0; i--) { const existing = result[i] @@ -123,7 +148,12 @@ class ValueQueries { */ *inlines(this: Editor, options: {} = {}): Iterable { - for (const [n, p] of Node.elements(this.value, options)) { + const iterable = Node.elements(this.value, { + ...options, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) + + for (const [n, p] of iterable) { if (this.isInline(n)) { yield [n, p] } @@ -134,9 +164,16 @@ class ValueQueries { * Iterate through all of the leaf block nodes in the editor. */ - *leafBlocks(this: Editor, options: {} = {}): Iterable { + *leafBlocks( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { for (const [n, p] of this.blocks(options)) { - if (this.hasInlines(n)) { + if (this.hasInlines(n) || this.isVoid(n)) { yield [n, p] } } @@ -146,9 +183,16 @@ class ValueQueries { * Iterate through all of the leaf inline nodes in the editor. */ - *leafInlines(this: Editor, options: {} = {}): Iterable { + *leafInlines( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { for (const [n, p] of this.inlines(options)) { - if (this.hasTexts(n)) { + if (this.hasTexts(n) || this.isVoid(n)) { yield [n, p] } } @@ -170,121 +214,83 @@ class ValueQueries { this: Editor, options: { point?: Point - unit?: 'offset' | 'character' | 'word' | 'line' + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' reverse?: boolean allowZeroWidth?: boolean } = {} ): Iterable { - const { unit = 'offset', reverse = false } = options - const { value } = this - let { point } = options - - if (point == null) { - const [entry] = Node.texts(value, { reverse }) - const [textNode, textPath] = entry - const textOffset = reverse ? textNode.text.length : 0 - point = { path: textPath, offset: textOffset } + const { + unit = 'offset', + reverse = false, + point = reverse ? this.getEnd([]) : this.getStart([]), + } = options + + if (unit !== 'offset') { + yield point } - while (true) { - const { path, offset } = point - const furthestVoid = this.getFurthestVoid(path) - const closestBlock = this.getClosestBlock(path) - let skipPath: Path | void - - if (furthestVoid) { - const [, voidPath] = furthestVoid - skipPath = voidPath - } else if (closestBlock) { - const [, blockPath] = closestBlock - - if ( - (!reverse && this.isAtEndOfPath(point, blockPath)) || - (reverse && this.isAtStartOfPath(point, blockPath)) - ) { - skipPath = blockPath - } - } - - if (skipPath) { - const textEntry = reverse - ? this.getPreviousText(skipPath) - : this.getNextText(skipPath) + const { path, offset } = point + let string = '' + let distance = 0 - if (!textEntry) { - break - } - - const [textNode, textPath] = textEntry - const textOffset = reverse ? textNode.text.length : 0 - point = produce(point, p => { - p.path = textPath - p.offset = textOffset - }) - - yield point - } - - const node = Node.leaf(value, path) - let root: Ancestor = value - let rootPath: Path = [] - - if (closestBlock) { - const [block, blockPath] = closestBlock - root = block - rootPath = blockPath + const advance = () => { + if (unit === 'character') { + distance = String.getCharacterDistance(string) + } else if (unit === 'word') { + distance = String.getWordDistance(string) + } else if (unit === 'line' || unit === 'block') { + // COMPAT: We equate 'line' in core to 'block'. This can be overriden in + // environments with rendered lines that can be calculated. + distance = string.length + } else { + distance = Math.min(string.length, 1) } - const rootText = Node.text(root) - const relPath = Path.relative(path, rootPath) - const relOffset = Node.offset(root, relPath) - const rootOffset = relOffset + offset - const remainingText = reverse - ? reverseText(rootText.slice(0, rootOffset)) - : rootText.slice(rootOffset) + string = string.slice(distance) + } - let d = 1 + for (const [n, p] of this.entries({ + path, + reverse, + })) { + if (Element.isElement(n)) { + if (this.isVoid(n)) { + yield this.getStart(p) + continue + } - if (unit === 'character') { - d = String.getCharacterDistance(remainingText) - } else if (unit === 'word') { - d = String.getWordDistance(remainingText) - } else if (unit === 'line') { - // COMPAT: If we're moving by line, we approximate it in core by moving - // by the entire block. This can be overriden in environments where you - // have rendered lines that can be calculated. - d = remainingText.length - } + if (!this.isInline(n) && this.hasInlines(n)) { + let text = this.getText(p) - const newOffset = reverse ? offset - d : offset + d + if (Path.isAncestor(p, path)) { + const before = this.getOffset(path, { depth: p.length }) + const o = before + offset + text = reverse ? text.slice(0, o) : text.slice(o) + } - // If the travel distance is all inside the current text node, just - // move the existing point's offset. - if ( - (!reverse && newOffset <= node.text.length) || - (reverse && newOffset >= 0) - ) { - point = produce(point, p => { - p.offset = newOffset - }) + string = reverse ? reverseText(text) : text + distance = 0 - yield point + if (unit !== 'offset') { + advance() + } + } } - let t = reverse ? offset : node.text.length - offset - - // Otherwise, we need to iterate the text nodes of the block until we've - // traveled the correct offset amount. - for (const [textNode, textPath] of this.texts({ path, reverse })) { - const { length } = textNode.text + if (Text.isText(n)) { + let remaining = n.text.length + let o = reverse ? remaining : 0 - if (t + length >= d) { - point = produce(point, p => { - p.path = textPath - p.offset = reverse ? length - (d - t) : d - t - }) + if (Path.equals(p, path)) { + remaining = reverse ? offset : remaining - offset + o = offset + } - yield point + while (remaining > 0) { + o = reverse ? o - distance : o + distance + remaining -= distance + yield { path: p, offset: o } + advance() } } } @@ -294,7 +300,14 @@ class ValueQueries { * Iterate through all of the root block nodes in the editor. */ - *rootBlocks(this: Editor, options: {} = {}): Iterable { + *rootBlocks( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { for (const [n, p] of this.blocks(options)) { if (p.length === 1) { yield [n, p] @@ -306,7 +319,14 @@ class ValueQueries { * Iterate through all of the root inline nodes in the editor. */ - *rootInlines(this: Editor, options: {} = {}): Iterable { + *rootInlines( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { for (const [n, p] of this.inlines(options)) { const parent = Node.parent(this.value, p) @@ -320,8 +340,18 @@ class ValueQueries { * Iterate through all of the text nodes in the editor. */ - *texts(this: Editor, options: {} = {}): Iterable { - yield* Node.texts(this.value, options) + *texts( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { + yield* Node.texts(this.value, { + ...options, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) } } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 777fc56826..8a2de6afa0 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -160,6 +160,7 @@ namespace Node { path?: Path range?: Range reverse?: boolean + pass?: (node: NodeEntry) => boolean } = {} ): Iterable { for (const [node, path] of Node.entries(root, options)) { @@ -183,6 +184,7 @@ namespace Node { path?: Path range?: Range reverse?: boolean + pass?: (node: NodeEntry) => boolean } = {} ): Iterable { for (const [node, path] of Node.entries(root, options)) { @@ -204,100 +206,104 @@ namespace Node { path?: Path range?: Range reverse?: boolean + pass?: (entry: NodeEntry) => boolean } = {} ): Iterable { - const { path, range, reverse = false } = options - let startPath: Path = [] - let endPath: Path | null = null + const { path = [], range, reverse = false, pass = () => false } = options + let fromPath + let toPath if (range != null) { - const [start, end] = Range.points(range) - startPath = start.path - endPath = end.path - } else if (path != null) { - startPath = path + const [s, e] = Range.points(range) + fromPath = reverse ? e.path : s.path + toPath = reverse ? s.path : e.path + } else { + const [, f] = reverse ? Node.last(root, path) : Node.first(root, path) + fromPath = f + toPath = null } - const startNode = Node.get(root, startPath) const visited = new Set() - let p = startPath - let n = startNode - let includedStart = false - let includingStart = false + let p: Path = [] + let n = root + yield [n, p] while (true) { - // When iterating over a range, we need to include the specific - // ancestors in the start path of the range manually. - if (!includedStart) { - if (!includingStart) { - includingStart = true - p = [] - n = root - yield [n, p] - continue - } + if (toPath != null && Path.equals(p, toPath)) { + break + } - if (p.length === startPath.length) { - includedStart = true - continue + // If we're allowed to go downward and we haven't decsended yet, do. + if ( + !visited.has(n) && + !Text.isText(n) && + n.nodes.length !== 0 && + !pass([n, p]) + ) { + visited.add(n) + let nextIndex = reverse ? n.nodes.length - 1 : 0 + + if (Path.isAncestor(p, fromPath)) { + nextIndex = fromPath[p.length] } - p = startPath.slice(0, p.length + 1) + p = p.concat(nextIndex) n = Node.get(root, p) yield [n, p] continue } - // When iterating over a range, if we get to the end path then exit. - if (endPath && Path.equals(p, endPath)) { + // If we're at the root and we can't go down, we're done. + if (p.length === 0) { break } - // If we're allowed to go downward and we haven't decsended yet, do. - if (!Text.isText(n) && n.nodes.length && !visited.has(n)) { - visited.add(n) - const nextIndex = reverse ? n.nodes.length - 1 : 0 - p = p.concat(nextIndex) + // If we're going forward... + if (!reverse) { + const newPath = Path.next(p) + + if (Node.has(root, newPath)) { + p = newPath + n = Node.get(root, p) + yield [n, p] + continue + } + } + + // If we're going backward... + if (reverse && p[p.length - 1] !== 0) { + const newPath = Path.previous(p) + p = newPath n = Node.get(root, p) yield [n, p] continue } - // To go forward, backward or upward we can't be at the root already. - if (p.length !== 0) { - // If we're going forward... - if (!reverse) { - const newPath = Path.next(p) - - if (Node.has(root, newPath)) { - p = newPath - n = Node.get(root, newPath) - yield [n, p] - continue - } - } + // Otherwise we're going upward... + p = Path.parent(p) + n = Node.get(root, p) + visited.add(n) + } + } - // If we're going backward... - if (reverse && p[p.length - 1] !== 0) { - const newPath = Path.previous(p) + /** + * Get the first node entry in a root node from a path. + */ - if (Node.has(root, newPath)) { - p = newPath - n = Node.get(root, newPath) - yield [n, p] - continue - } - } + export const first = (root: Node, path: Path): NodeEntry => { + const p = path.slice() + let n = Node.get(root, p) - // Otherwise we're going upward... - p = Path.parent(p) - n = Node.get(root, p) - visited.add(n) - continue + while (n) { + if (Text.isText(n) || n.nodes.length === 0) { + break + } else { + n = n.nodes[0] + p.push(0) } - - break } + + return [n, p] } /** @@ -415,6 +421,27 @@ namespace Node { return Array.isArray(value) && (value.length === 0 || Node.isNode(value[0])) } + /** + * Get the lash node entry in a root node from a path. + */ + + export const last = (root: Node, path: Path): NodeEntry => { + const p = path.slice() + let n = Node.get(root, p) + + while (n) { + if (Text.isText(n) || n.nodes.length === 0) { + break + } else { + const i = n.nodes.length - 1 + n = n.nodes[i] + p.push(i) + } + } + + return [n, p] + } + /** * Get the node at a specific path, ensuring it's a leaf text node. */ @@ -461,6 +488,7 @@ namespace Node { path?: Path range?: Range reverse?: boolean + pass?: (node: NodeEntry) => boolean } = {} ): Iterable { for (const [node, path] of Node.texts(root, options)) { @@ -477,7 +505,7 @@ namespace Node { export const offset = (root: Node, path: Path): number => { // PERF: We can exit early if the path is empty. - if (!path.length) { + if (path.length === 0) { return 0 } @@ -530,7 +558,7 @@ namespace Node { if (Text.isText(node)) { return node.text } else { - return node.nodes.map(text).join('') + return node.nodes.map(Node.text).join('') } } @@ -544,6 +572,7 @@ namespace Node { path?: Path range?: Range reverse?: boolean + pass?: (node: NodeEntry) => boolean } = {} ): Iterable { for (const [node, path] of Node.entries(root, options)) { diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index 95a71dc202..68bd55d8a0 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -1,28 +1,28 @@ -import { Annotation, Mark, Node, Path } from '..' +import { Annotation, Mark, Node, Path, Selection, Value } from '..' import isPlainObject from 'is-plain-object' -interface AddAnnotationOperation { +type AddAnnotationOperation = { type: 'add_annotation' key: string annotation: Annotation [key: string]: any } -interface AddMarkOperation { +type AddMarkOperation = { type: 'add_mark' path: Path mark: Mark [key: string]: any } -interface InsertNodeOperation { +type InsertNodeOperation = { type: 'insert_node' path: Path node: Node [key: string]: any } -interface InsertTextOperation { +type InsertTextOperation = { type: 'insert_text' path: Path offset: number @@ -30,44 +30,44 @@ interface InsertTextOperation { [key: string]: any } -interface MergeNodeOperation { +type MergeNodeOperation = { type: 'merge_node' path: Path position: number target: number | null - properties: {} + properties: Partial [key: string]: any } -interface MoveNodeOperation { +type MoveNodeOperation = { type: 'move_node' path: Path newPath: Path [key: string]: any } -interface RemoveAnnotationOperation { +type RemoveAnnotationOperation = { type: 'remove_annotation' key: string annotation: Annotation [key: string]: any } -interface RemoveMarkOperation { +type RemoveMarkOperation = { type: 'remove_mark' path: Path mark: Mark [key: string]: any } -interface RemoveNodeOperation { +type RemoveNodeOperation = { type: 'remove_node' path: Path node: Node [key: string]: any } -interface RemoveTextOperation { +type RemoveTextOperation = { type: 'remove_text' path: Path offset: number @@ -75,50 +75,63 @@ interface RemoveTextOperation { [key: string]: any } -interface SetAnnotationOperation { +type SetAnnotationOperation = { type: 'set_annotation' key: string - properties: {} - newProperties: {} + properties: Partial + newProperties: Partial [key: string]: any } -interface SetMarkOperation { +type SetMarkOperation = { type: 'set_mark' path: Path - properties: {} - newProperties: {} + properties: Partial + newProperties: Partial [key: string]: any } -interface SetNodeOperation { +type SetNodeOperation = { type: 'set_node' path: Path - properties: {} - newProperties: {} + properties: Partial + newProperties: Partial [key: string]: any } -interface SetSelectionOperation { - type: 'set_selection' - properties: {} | null - newProperties: {} | null - [key: string]: any -} +type SetSelectionOperation = + | { + type: 'set_selection' + [key: string]: any + properties: null + newProperties: Selection + } + | { + type: 'set_selection' + [key: string]: any + properties: Partial + newProperties: Partial + } + | { + type: 'set_selection' + [key: string]: any + properties: Selection + newProperties: null + } -interface SetValueOperation { +type SetValueOperation = { type: 'set_value' - properties: {} - newProperties: {} + properties: Partial + newProperties: Partial [key: string]: any } -interface SplitNodeOperation { +type SplitNodeOperation = { type: 'split_node' path: Path position: number target: number | null - properties: {} + properties: Partial [key: string]: any } @@ -412,7 +425,22 @@ namespace Operation { case 'set_selection': { const { properties, newProperties } = op - return { ...op, properties: newProperties, newProperties: properties } + + if (properties == null) { + return { + ...op, + properties: newProperties as Selection, + newProperties: null, + } + } else if (newProperties == null) { + return { + ...op, + properties: null, + newProperties: properties as Selection, + } + } else { + return { ...op, properties: newProperties, newProperties: properties } + } } case 'split_node': { diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index c6e21ae88e..ee21035bf2 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -277,7 +277,23 @@ namespace Value { case 'set_selection': { const { newProperties } = op - Object.assign(v.selection, newProperties) + + if (newProperties == null) { + v.selection = newProperties + } else if (v.selection == null) { + if (!Selection.isSelection(newProperties)) { + throw new Error( + `Cannot apply an incomplete "set_selection" operation properties ${JSON.stringify( + newProperties + )} when there is no current selection.` + ) + } + + v.selection = newProperties + } else { + Object.assign(v.selection, newProperties) + } + break } diff --git a/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js b/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js deleted file mode 100644 index bc9b8dfe2d..0000000000 --- a/packages/slate/test/commands/at-range/delete-backward-at-range/from-offset.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import { Point, Range } from 'slate' - -import { h } from '../../../helpers' - -export const run = editor => { - const { value: { document } } = editor - const [firstText, firstPath] = document.firstText() - const point = Point.create({ key: firstText.key, offset: 2, path: firstPath }) - const range = Range.create({ anchor: point, focus: point }) - editor.deleteBackwardAtRange(range, 2) -} - -export const input = ( - - - - - onetwo - - - - -) - -export const output = ( - - - - - etwo - - - - -) diff --git a/packages/slate/test/commands/on-selection/blur/basic.js b/packages/slate/test/commands/on-selection/blur/basic.js index d95ab534b4..62b46adf76 100644 --- a/packages/slate/test/commands/on-selection/blur/basic.js +++ b/packages/slate/test/commands/on-selection/blur/basic.js @@ -8,18 +8,16 @@ export const run = editor => { export const input = ( - - - one - - + + one + ) export const output = ( - - one - + + one + ) diff --git a/packages/slate/test/commands/on-selection/deselect/basic.js b/packages/slate/test/commands/on-selection/deselect/basic.js new file mode 100644 index 0000000000..93ac7f5654 --- /dev/null +++ b/packages/slate/test/commands/on-selection/deselect/basic.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.deselect() +} + +export const input = ( + + + one + + +) + +export const output = ( + + one + +) diff --git a/packages/slate/test/commands/on-selection/deselect/unfocused.js b/packages/slate/test/commands/on-selection/deselect/unfocused.js new file mode 100644 index 0000000000..26f357a0ee --- /dev/null +++ b/packages/slate/test/commands/on-selection/deselect/unfocused.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.deselect() +} + +export const input = ( + + + one + + +) + +export const output = ( + + one + +) diff --git a/packages/slate/test/commands/on-selection/focus/basic.js b/packages/slate/test/commands/on-selection/focus/basic.js index a22c25d73d..7823baff5a 100644 --- a/packages/slate/test/commands/on-selection/focus/basic.js +++ b/packages/slate/test/commands/on-selection/focus/basic.js @@ -8,18 +8,16 @@ export const run = editor => { export const input = ( - - one - + + one + ) export const output = ( - - - one - - + + one + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/default.js b/packages/slate/test/commands/on-selection/move-anchor-backward/default.js index 66266b9984..ab1c5e9af9 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchorBackward() + editor.moveAnchor({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js index 8a2045d7f0..f3700afb10 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchorBackward() + editor.moveAnchor({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js index 193e783207..0f15801a6a 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchorBackward(8) + editor.moveAnchor({ reverse: true, distance: 8 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/param.js b/packages/slate/test/commands/on-selection/move-anchor-backward/param.js index cc9c1162ac..616fe2b42d 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchorBackward(3) + editor.moveAnchor({ reverse: true, distance: 3 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/index.js b/packages/slate/test/index.js index 32720a8cdb..f97da278bd 100644 --- a/packages/slate/test/index.js +++ b/packages/slate/test/index.js @@ -30,6 +30,14 @@ describe('slate', () => { assert.deepEqual(editor.value, output) }) + fixtures(__dirname, 'queries', ({ module }) => { + const { input, run, output } = module + const TestEditor = TestPlugin(Editor) + const editor = new TestEditor({ value: input }) + const result = run(editor) + assert.deepEqual(result, output) + }) + fixtures(__dirname, 'commands', ({ module }) => { const { input, run, output } = module const TestEditor = TestPlugin(Editor) diff --git a/packages/slate/test/interfaces/Node/entries/pass.js b/packages/slate/test/interfaces/Node/entries/pass.js new file mode 100644 index 0000000000..695ab4cc54 --- /dev/null +++ b/packages/slate/test/interfaces/Node/entries/pass.js @@ -0,0 +1,45 @@ +/** @jsx h */ + +import { Node } from 'slate' +import h from 'slate-hyperscript' + +export const input = ( + + + + + + + +) + +export const test = value => { + return Array.from(Node.entries(value, { pass: ([n, p]) => p.length > 1 })) +} + +export const output = [ + [ + + + + + + + , + [], + ], + [ + + + + + , + [0], + ], + [ + + + , + [0, 0], + ], +] diff --git a/packages/slate/test/interfaces/Node/entries/reverse.js b/packages/slate/test/interfaces/Node/entries/reverse.js index fc59bed7ee..2c438c7cce 100644 --- a/packages/slate/test/interfaces/Node/entries/reverse.js +++ b/packages/slate/test/interfaces/Node/entries/reverse.js @@ -9,6 +9,10 @@ export const input = ( + + + + ) @@ -23,9 +27,22 @@ export const output = [ + + + + , [], ], + [ + + + + , + [1], + ], + [, [1, 1]], + [, [1, 0]], [ diff --git a/packages/slate/test/queries/value/blocks/block-multiple.js b/packages/slate/test/queries/value/blocks/block-multiple.js new file mode 100644 index 0000000000..e894ada442 --- /dev/null +++ b/packages/slate/test/queries/value/blocks/block-multiple.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.blocks()) +} + +export const output = [ + [one, [0]], + [two, [1]], + [three, [2]], +] diff --git a/packages/slate/test/queries/value/blocks/block-nested.js b/packages/slate/test/queries/value/blocks/block-nested.js new file mode 100644 index 0000000000..0d942b8166 --- /dev/null +++ b/packages/slate/test/queries/value/blocks/block-nested.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.blocks()) +} + +export const output = [ + [ + + one + , + [0], + ], + [one, [0, 0]], + [ + + two + , + [1], + ], + + [two, [1, 0]], +] diff --git a/packages/slate/test/queries/value/blocks/block-reverse.js b/packages/slate/test/queries/value/blocks/block-reverse.js new file mode 100644 index 0000000000..1900aa9148 --- /dev/null +++ b/packages/slate/test/queries/value/blocks/block-reverse.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.blocks({ reverse: true })) +} + +export const output = [ + [three, [2]], + [two, [1]], + [one, [0]], +] diff --git a/packages/slate/test/queries/value/blocks/block-void.js b/packages/slate/test/queries/value/blocks/block-void.js new file mode 100644 index 0000000000..6e1608f077 --- /dev/null +++ b/packages/slate/test/queries/value/blocks/block-void.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + return Array.from(editor.blocks()) +} + +export const output = [ + [ + + one + , + [0], + ], +] diff --git a/packages/slate/test/queries/value/blocks/block.js b/packages/slate/test/queries/value/blocks/block.js new file mode 100644 index 0000000000..9215e63fa0 --- /dev/null +++ b/packages/slate/test/queries/value/blocks/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.blocks()) +} + +export const output = [[one, [0]]] diff --git a/packages/slate/test/queries/value/blocks/inline.js b/packages/slate/test/queries/value/blocks/inline.js new file mode 100644 index 0000000000..3d5934ec94 --- /dev/null +++ b/packages/slate/test/queries/value/blocks/inline.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.blocks()) +} + +export const output = [ + [ + + onetwothree + , + [0], + ], +] diff --git a/packages/slate/test/queries/value/entries/block-multiple.js b/packages/slate/test/queries/value/entries/block-multiple.js new file mode 100644 index 0000000000..333a755fdc --- /dev/null +++ b/packages/slate/test/queries/value/entries/block-multiple.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + one + two + , + [], + ], + [one, [0]], + [one, [0, 0]], + [two, [1]], + [two, [1, 0]], +] diff --git a/packages/slate/test/queries/value/entries/block-nested.js b/packages/slate/test/queries/value/entries/block-nested.js new file mode 100644 index 0000000000..a4d8e4ceb5 --- /dev/null +++ b/packages/slate/test/queries/value/entries/block-nested.js @@ -0,0 +1,48 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + + one + + + two + + , + [], + ], + [ + + one + , + [0], + ], + [one, [0, 0]], + [one, [0, 0, 0]], + [ + + two + , + [1], + ], + [two, [1, 0]], + [two, [1, 0, 0]], +] diff --git a/packages/slate/test/queries/value/entries/block-reverse.js b/packages/slate/test/queries/value/entries/block-reverse.js new file mode 100644 index 0000000000..f19c4b15ce --- /dev/null +++ b/packages/slate/test/queries/value/entries/block-reverse.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return Array.from(editor.entries({ reverse: true })) +} + +export const output = [ + [ + + one + two + , + [], + ], + [two, [1]], + [two, [1, 0]], + [one, [0]], + [one, [0, 0]], +] diff --git a/packages/slate/test/queries/value/entries/block-void.js b/packages/slate/test/queries/value/entries/block-void.js new file mode 100644 index 0000000000..14f23c0610 --- /dev/null +++ b/packages/slate/test/queries/value/entries/block-void.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + one + , + [], + ], + [one, [0]], +] diff --git a/packages/slate/test/queries/value/entries/block.js b/packages/slate/test/queries/value/entries/block.js new file mode 100644 index 0000000000..8b4ec5fa89 --- /dev/null +++ b/packages/slate/test/queries/value/entries/block.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + one + , + [], + ], + [one, [0]], + [one, [0, 0]], +] diff --git a/packages/slate/test/queries/value/entries/inline-multiple.js b/packages/slate/test/queries/value/entries/inline-multiple.js new file mode 100644 index 0000000000..db2c4132c9 --- /dev/null +++ b/packages/slate/test/queries/value/entries/inline-multiple.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + + onetwothreefourfive + + , + [], + ], + [ + + onetwothreefourfive + , + [0], + ], + [one, [0, 0]], + [two, [0, 1]], + [two, [0, 1, 0]], + [three, [0, 2]], + [four, [0, 3]], + [four, [0, 3, 0]], + [five, [0, 4]], +] diff --git a/packages/slate/test/queries/value/entries/inline-nested.js b/packages/slate/test/queries/value/entries/inline-nested.js new file mode 100644 index 0000000000..e754fd5f95 --- /dev/null +++ b/packages/slate/test/queries/value/entries/inline-nested.js @@ -0,0 +1,50 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + + one + twothreefour + five + + , + [], + ], + [ + + one + twothreefour + five + , + [0], + ], + [one, [0, 0]], + [ + + twothreefour + , + [0, 1], + ], + [two, [0, 1, 0]], + [three, [0, 1, 1]], + [three, [0, 1, 1, 0]], + [four, [0, 1, 2]], + [five, [0, 2]], +] diff --git a/packages/slate/test/queries/value/entries/inline-reverse.js b/packages/slate/test/queries/value/entries/inline-reverse.js new file mode 100644 index 0000000000..aaac86a1ad --- /dev/null +++ b/packages/slate/test/queries/value/entries/inline-reverse.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.entries({ reverse: true })) +} + +export const output = [ + [ + + + onetwothreefourfive + + , + [], + ], + [ + + onetwothreefourfive + , + [0], + ], + [five, [0, 4]], + [four, [0, 3]], + [four, [0, 3, 0]], + [three, [0, 2]], + [two, [0, 1]], + [two, [0, 1, 0]], + [one, [0, 0]], +] diff --git a/packages/slate/test/queries/value/entries/inline-void.js b/packages/slate/test/queries/value/entries/inline-void.js new file mode 100644 index 0000000000..cf7ca3f30f --- /dev/null +++ b/packages/slate/test/queries/value/entries/inline-void.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + + onetwothree + + , + [], + ], + [ + + onetwothree + , + [0], + ], + [one, [0, 0]], + [two, [0, 1]], + [three, [0, 2]], +] diff --git a/packages/slate/test/queries/value/entries/inline.js b/packages/slate/test/queries/value/entries/inline.js new file mode 100644 index 0000000000..dc80e76902 --- /dev/null +++ b/packages/slate/test/queries/value/entries/inline.js @@ -0,0 +1,36 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.entries()) +} + +export const output = [ + [ + + + onetwothree + + , + [], + ], + [ + + onetwothree + , + [0], + ], + [one, [0, 0]], + [two, [0, 1]], + [two, [0, 1, 0]], + [three, [0, 2]], +] diff --git a/packages/slate/test/queries/value/getActiveMarks/block-across.js b/packages/slate/test/queries/value/getActiveMarks/block-across.js new file mode 100644 index 0000000000..5b385647c7 --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/block-across.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + + one + + + + + + + one + + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [{ key: 'b' }, { key: 'a' }] diff --git a/packages/slate/test/queries/value/getActiveMarks/block-start.js b/packages/slate/test/queries/value/getActiveMarks/block-start.js new file mode 100644 index 0000000000..f778f68783 --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/block-start.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/getActiveMarks/inline-start.js b/packages/slate/test/queries/value/getActiveMarks/inline-start.js new file mode 100644 index 0000000000..e5bb69b06e --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/inline-start.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + two + + three + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/getActiveMarks/intersection.js b/packages/slate/test/queries/value/getActiveMarks/intersection.js new file mode 100644 index 0000000000..fd69719632 --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/intersection.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + o + n + e + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/getActiveMarks/multiple.js b/packages/slate/test/queries/value/getActiveMarks/multiple.js new file mode 100644 index 0000000000..b3aa4bb67c --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/multiple.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + + one + + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [{ key: 'b' }, { key: 'a' }] diff --git a/packages/slate/test/queries/value/getActiveMarks/none.js b/packages/slate/test/queries/value/getActiveMarks/none.js new file mode 100644 index 0000000000..fd06db2291 --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/none.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/getActiveMarks/one.js b/packages/slate/test/queries/value/getActiveMarks/one.js new file mode 100644 index 0000000000..5e8d89911b --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/one.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + one + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [{ key: 'a' }] diff --git a/packages/slate/test/queries/value/getActiveMarks/selection-marks.js b/packages/slate/test/queries/value/getActiveMarks/selection-marks.js new file mode 100644 index 0000000000..0dc2d973fb --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/selection-marks.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + one + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [{ key: 'b' }] diff --git a/packages/slate/test/queries/value/getActiveMarks/selection-null.js b/packages/slate/test/queries/value/getActiveMarks/selection-null.js new file mode 100644 index 0000000000..28b1803655 --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/selection-null.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/getActiveMarks/text-start.js b/packages/slate/test/queries/value/getActiveMarks/text-start.js new file mode 100644 index 0000000000..9e3ccf9e69 --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/text-start.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + two + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks()) +} + +export const output = [{ key: 'a' }] diff --git a/packages/slate/test/queries/value/getActiveMarks/union.js b/packages/slate/test/queries/value/getActiveMarks/union.js new file mode 100644 index 0000000000..d523710f79 --- /dev/null +++ b/packages/slate/test/queries/value/getActiveMarks/union.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + o + n + e + + + +) + +export const run = editor => { + return Array.from(editor.getActiveMarks({ union: true })) +} + +export const output = [{ key: 'a' }, { key: 'b' }] diff --git a/packages/slate/test/queries/value/inlines/block.js b/packages/slate/test/queries/value/inlines/block.js new file mode 100644 index 0000000000..b7a6348635 --- /dev/null +++ b/packages/slate/test/queries/value/inlines/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.inlines()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/inlines/inline-multiple.js b/packages/slate/test/queries/value/inlines/inline-multiple.js new file mode 100644 index 0000000000..92eb234e4f --- /dev/null +++ b/packages/slate/test/queries/value/inlines/inline-multiple.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.inlines()) +} + +export const output = [ + [two, [0, 1]], + [four, [0, 3]], +] diff --git a/packages/slate/test/queries/value/inlines/inline-nested.js b/packages/slate/test/queries/value/inlines/inline-nested.js new file mode 100644 index 0000000000..d878d533af --- /dev/null +++ b/packages/slate/test/queries/value/inlines/inline-nested.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + return Array.from(editor.inlines()) +} + +export const output = [ + [ + + twothreefour + , + [0, 1], + ], + [three, [0, 1, 1]], +] diff --git a/packages/slate/test/queries/value/inlines/inline-reverse.js b/packages/slate/test/queries/value/inlines/inline-reverse.js new file mode 100644 index 0000000000..6f6af63231 --- /dev/null +++ b/packages/slate/test/queries/value/inlines/inline-reverse.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.inlines({ reverse: true })) +} + +export const output = [ + [four, [0, 3]], + [two, [0, 1]], +] diff --git a/packages/slate/test/queries/value/inlines/inline-void.js b/packages/slate/test/queries/value/inlines/inline-void.js new file mode 100644 index 0000000000..1e2083ad9b --- /dev/null +++ b/packages/slate/test/queries/value/inlines/inline-void.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.inlines()) +} + +export const output = [[two, [0, 1]]] diff --git a/packages/slate/test/queries/value/inlines/inline.js b/packages/slate/test/queries/value/inlines/inline.js new file mode 100644 index 0000000000..92b455cd79 --- /dev/null +++ b/packages/slate/test/queries/value/inlines/inline.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.inlines()) +} + +export const output = [[two, [0, 1]]] diff --git a/packages/slate/test/queries/value/leafBlocks/block-multiple.js b/packages/slate/test/queries/value/leafBlocks/block-multiple.js new file mode 100644 index 0000000000..9c91c8e8f6 --- /dev/null +++ b/packages/slate/test/queries/value/leafBlocks/block-multiple.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.leafBlocks()) +} + +export const output = [ + [one, [0]], + [two, [1]], + [three, [2]], +] diff --git a/packages/slate/test/queries/value/leafBlocks/block-nested.js b/packages/slate/test/queries/value/leafBlocks/block-nested.js new file mode 100644 index 0000000000..6cccc38e9c --- /dev/null +++ b/packages/slate/test/queries/value/leafBlocks/block-nested.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.leafBlocks()) +} + +export const output = [ + [one, [0, 0]], + [two, [1, 0]], +] diff --git a/packages/slate/test/queries/value/leafBlocks/block-reverse.js b/packages/slate/test/queries/value/leafBlocks/block-reverse.js new file mode 100644 index 0000000000..c759987dc9 --- /dev/null +++ b/packages/slate/test/queries/value/leafBlocks/block-reverse.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.leafBlocks({ reverse: true })) +} + +export const output = [ + [three, [2]], + [two, [1]], + [one, [0]], +] diff --git a/packages/slate/test/queries/value/leafBlocks/block-void.js b/packages/slate/test/queries/value/leafBlocks/block-void.js new file mode 100644 index 0000000000..2550f933d3 --- /dev/null +++ b/packages/slate/test/queries/value/leafBlocks/block-void.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + return Array.from(editor.leafBlocks()) +} + +export const output = [ + [ + + one + , + [0], + ], +] diff --git a/packages/slate/test/queries/value/leafBlocks/block.js b/packages/slate/test/queries/value/leafBlocks/block.js new file mode 100644 index 0000000000..cb19ac37f4 --- /dev/null +++ b/packages/slate/test/queries/value/leafBlocks/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.leafBlocks()) +} + +export const output = [[one, [0]]] diff --git a/packages/slate/test/queries/value/leafBlocks/inline.js b/packages/slate/test/queries/value/leafBlocks/inline.js new file mode 100644 index 0000000000..d16cf8a366 --- /dev/null +++ b/packages/slate/test/queries/value/leafBlocks/inline.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.leafBlocks()) +} + +export const output = [ + [ + + onetwothree + , + [0], + ], +] diff --git a/packages/slate/test/queries/value/leafInlines/block.js b/packages/slate/test/queries/value/leafInlines/block.js new file mode 100644 index 0000000000..42ae6aab77 --- /dev/null +++ b/packages/slate/test/queries/value/leafInlines/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.leafInlines()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/leafInlines/inline-multiple.js b/packages/slate/test/queries/value/leafInlines/inline-multiple.js new file mode 100644 index 0000000000..b0971ee01a --- /dev/null +++ b/packages/slate/test/queries/value/leafInlines/inline-multiple.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.leafInlines()) +} + +export const output = [ + [two, [0, 1]], + [four, [0, 3]], +] diff --git a/packages/slate/test/queries/value/leafInlines/inline-nested.js b/packages/slate/test/queries/value/leafInlines/inline-nested.js new file mode 100644 index 0000000000..d77eaf9cb6 --- /dev/null +++ b/packages/slate/test/queries/value/leafInlines/inline-nested.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + return Array.from(editor.leafInlines()) +} + +export const output = [[three, [0, 1, 1]]] diff --git a/packages/slate/test/queries/value/leafInlines/inline-reverse.js b/packages/slate/test/queries/value/leafInlines/inline-reverse.js new file mode 100644 index 0000000000..19071ccd6c --- /dev/null +++ b/packages/slate/test/queries/value/leafInlines/inline-reverse.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.leafInlines({ reverse: true })) +} + +export const output = [ + [four, [0, 3]], + [two, [0, 1]], +] diff --git a/packages/slate/test/queries/value/leafInlines/inline-void.js b/packages/slate/test/queries/value/leafInlines/inline-void.js new file mode 100644 index 0000000000..545bd4b026 --- /dev/null +++ b/packages/slate/test/queries/value/leafInlines/inline-void.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.leafInlines()) +} + +export const output = [[two, [0, 1]]] diff --git a/packages/slate/test/queries/value/leafInlines/inline.js b/packages/slate/test/queries/value/leafInlines/inline.js new file mode 100644 index 0000000000..0d6421d81f --- /dev/null +++ b/packages/slate/test/queries/value/leafInlines/inline.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.leafInlines()) +} + +export const output = [[two, [0, 1]]] diff --git a/packages/slate/test/queries/value/positions/block-multiple.js b/packages/slate/test/queries/value/positions/block-multiple.js new file mode 100644 index 0000000000..57161e9e46 --- /dev/null +++ b/packages/slate/test/queries/value/positions/block-multiple.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.positions()) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [1, 0], offset: 0 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 3 }, + { path: [2, 0], offset: 0 }, + { path: [2, 0], offset: 1 }, + { path: [2, 0], offset: 2 }, + { path: [2, 0], offset: 3 }, + { path: [2, 0], offset: 4 }, + { path: [2, 0], offset: 5 }, +] diff --git a/packages/slate/test/queries/value/positions/block-nested.js b/packages/slate/test/queries/value/positions/block-nested.js new file mode 100644 index 0000000000..7ea1c3b575 --- /dev/null +++ b/packages/slate/test/queries/value/positions/block-nested.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.positions()) +} + +export const output = [ + { path: [0, 0, 0], offset: 0 }, + { path: [0, 0, 0], offset: 1 }, + { path: [0, 0, 0], offset: 2 }, + { path: [0, 0, 0], offset: 3 }, + { path: [1, 0, 0], offset: 0 }, + { path: [1, 0, 0], offset: 1 }, + { path: [1, 0, 0], offset: 2 }, + { path: [1, 0, 0], offset: 3 }, +] diff --git a/packages/slate/test/queries/value/positions/block-reverse.js b/packages/slate/test/queries/value/positions/block-reverse.js new file mode 100644 index 0000000000..fc1d861094 --- /dev/null +++ b/packages/slate/test/queries/value/positions/block-reverse.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.positions({ reverse: true })) +} + +export const output = [ + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/block.js b/packages/slate/test/queries/value/positions/block.js new file mode 100644 index 0000000000..35369ef9e8 --- /dev/null +++ b/packages/slate/test/queries/value/positions/block.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.positions()) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, +] diff --git a/packages/slate/test/queries/value/positions/inline-multiple.js b/packages/slate/test/queries/value/positions/inline-multiple.js new file mode 100644 index 0000000000..9d601c8ccc --- /dev/null +++ b/packages/slate/test/queries/value/positions/inline-multiple.js @@ -0,0 +1,38 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.positions()) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 5 }, + { path: [0, 3, 0], offset: 1 }, + { path: [0, 3, 0], offset: 2 }, + { path: [0, 3, 0], offset: 3 }, + { path: [0, 3, 0], offset: 4 }, + { path: [0, 4], offset: 1 }, + { path: [0, 4], offset: 2 }, + { path: [0, 4], offset: 3 }, + { path: [0, 4], offset: 4 }, +] diff --git a/packages/slate/test/queries/value/positions/inline-nested.js b/packages/slate/test/queries/value/positions/inline-nested.js new file mode 100644 index 0000000000..f2ef851952 --- /dev/null +++ b/packages/slate/test/queries/value/positions/inline-nested.js @@ -0,0 +1,40 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + return Array.from(editor.positions()) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 1, 1, 0], offset: 1 }, + { path: [0, 1, 1, 0], offset: 2 }, + { path: [0, 1, 1, 0], offset: 3 }, + { path: [0, 1, 1, 0], offset: 4 }, + { path: [0, 1, 1, 0], offset: 5 }, + { path: [0, 1, 2], offset: 1 }, + { path: [0, 1, 2], offset: 2 }, + { path: [0, 1, 2], offset: 3 }, + { path: [0, 1, 2], offset: 4 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, +] diff --git a/packages/slate/test/queries/value/positions/inline-reverse.js b/packages/slate/test/queries/value/positions/inline-reverse.js new file mode 100644 index 0000000000..8b85183fad --- /dev/null +++ b/packages/slate/test/queries/value/positions/inline-reverse.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.positions({ reverse: true })) +} + +export const output = [ + { path: [0, 2], offset: 5 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 0 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/inline.js b/packages/slate/test/queries/value/positions/inline.js new file mode 100644 index 0000000000..a8ec4f91da --- /dev/null +++ b/packages/slate/test/queries/value/positions/inline.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.positions()) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 5 }, +] diff --git a/packages/slate/test/queries/value/positions/point.js b/packages/slate/test/queries/value/positions/point.js new file mode 100644 index 0000000000..c2ca765a4b --- /dev/null +++ b/packages/slate/test/queries/value/positions/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) +} + +export const output = [{ path: [0, 0], offset: 2 }, { path: [0, 0], offset: 3 }] diff --git a/packages/slate/test/queries/value/positions/unit-block-reverse.js b/packages/slate/test/queries/value/positions/unit-block-reverse.js new file mode 100644 index 0000000000..34ed90a8ab --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-block-reverse.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'block', reverse: true })) +} + +export const output = [ + { path: [1, 0], offset: 13 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/unit-block.js b/packages/slate/test/queries/value/positions/unit-block.js new file mode 100644 index 0000000000..c8e151e15a --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-block.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'block' })) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 13 }, +] diff --git a/packages/slate/test/queries/value/positions/unit-character-reverse.js b/packages/slate/test/queries/value/positions/unit-character-reverse.js new file mode 100644 index 0000000000..edd89344ed --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-character-reverse.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'character', reverse: true })) +} + +export const output = [ + { path: [0, 2], offset: 5 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 0 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/unit-character.js b/packages/slate/test/queries/value/positions/unit-character.js new file mode 100644 index 0000000000..b2381edd8f --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-character.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'character' })) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 5 }, +] diff --git a/packages/slate/test/queries/value/positions/unit-line-reverse.js b/packages/slate/test/queries/value/positions/unit-line-reverse.js new file mode 100644 index 0000000000..8979a9d110 --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-line-reverse.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'line', reverse: true })) +} + +export const output = [ + { path: [1, 0], offset: 13 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/unit-line.js b/packages/slate/test/queries/value/positions/unit-line.js new file mode 100644 index 0000000000..cf4bc97ac1 --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-line.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'line' })) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 13 }, +] diff --git a/packages/slate/test/queries/value/positions/unit-word-reverse.js b/packages/slate/test/queries/value/positions/unit-word-reverse.js new file mode 100644 index 0000000000..736354eddb --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-word-reverse.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'word', reverse: true })) +} + +export const output = [ + { path: [1, 0], offset: 13 }, + { path: [1, 0], offset: 10 }, + { path: [1, 0], offset: 5 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 8 }, + { path: [0, 0], offset: 4 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/unit-word.js b/packages/slate/test/queries/value/positions/unit-word.js new file mode 100644 index 0000000000..d27be1d981 --- /dev/null +++ b/packages/slate/test/queries/value/positions/unit-word.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from(editor.positions({ unit: 'word' })) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 7 }, + { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 4 }, + { path: [1, 0], offset: 9 }, + { path: [1, 0], offset: 13 }, +] diff --git a/packages/slate/test/queries/value/rootBlocks/block-multiple.js b/packages/slate/test/queries/value/rootBlocks/block-multiple.js new file mode 100644 index 0000000000..4c62835797 --- /dev/null +++ b/packages/slate/test/queries/value/rootBlocks/block-multiple.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.rootBlocks()) +} + +export const output = [ + [one, [0]], + [two, [1]], + [three, [2]], +] diff --git a/packages/slate/test/queries/value/rootBlocks/block-nested.js b/packages/slate/test/queries/value/rootBlocks/block-nested.js new file mode 100644 index 0000000000..ebd9996144 --- /dev/null +++ b/packages/slate/test/queries/value/rootBlocks/block-nested.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.rootBlocks()) +} + +export const output = [ + [ + + one + , + [0], + ], + [ + + two + , + [1], + ], +] diff --git a/packages/slate/test/queries/value/rootBlocks/block-reverse.js b/packages/slate/test/queries/value/rootBlocks/block-reverse.js new file mode 100644 index 0000000000..4a6fb99b2a --- /dev/null +++ b/packages/slate/test/queries/value/rootBlocks/block-reverse.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.rootBlocks({ reverse: true })) +} + +export const output = [ + [three, [2]], + [two, [1]], + [one, [0]], +] diff --git a/packages/slate/test/queries/value/rootBlocks/block-void.js b/packages/slate/test/queries/value/rootBlocks/block-void.js new file mode 100644 index 0000000000..16cbcd9bff --- /dev/null +++ b/packages/slate/test/queries/value/rootBlocks/block-void.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + return Array.from(editor.rootBlocks()) +} + +export const output = [ + [ + + one + , + [0], + ], +] diff --git a/packages/slate/test/queries/value/rootBlocks/block.js b/packages/slate/test/queries/value/rootBlocks/block.js new file mode 100644 index 0000000000..0fa7903637 --- /dev/null +++ b/packages/slate/test/queries/value/rootBlocks/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.rootBlocks()) +} + +export const output = [[one, [0]]] diff --git a/packages/slate/test/queries/value/rootBlocks/inline.js b/packages/slate/test/queries/value/rootBlocks/inline.js new file mode 100644 index 0000000000..359c506804 --- /dev/null +++ b/packages/slate/test/queries/value/rootBlocks/inline.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.rootBlocks()) +} + +export const output = [ + [ + + onetwothree + , + [0], + ], +] diff --git a/packages/slate/test/queries/value/rootInlines/block.js b/packages/slate/test/queries/value/rootInlines/block.js new file mode 100644 index 0000000000..41a5b8b2d5 --- /dev/null +++ b/packages/slate/test/queries/value/rootInlines/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.rootInlines()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/rootInlines/inline-multiple.js b/packages/slate/test/queries/value/rootInlines/inline-multiple.js new file mode 100644 index 0000000000..fca59f22bc --- /dev/null +++ b/packages/slate/test/queries/value/rootInlines/inline-multiple.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.rootInlines()) +} + +export const output = [ + [two, [0, 1]], + [four, [0, 3]], +] diff --git a/packages/slate/test/queries/value/rootInlines/inline-nested.js b/packages/slate/test/queries/value/rootInlines/inline-nested.js new file mode 100644 index 0000000000..cf98b8d4d5 --- /dev/null +++ b/packages/slate/test/queries/value/rootInlines/inline-nested.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + return Array.from(editor.rootInlines()) +} + +export const output = [ + [ + + twothreefour + , + [0, 1], + ], +] diff --git a/packages/slate/test/queries/value/rootInlines/inline-reverse.js b/packages/slate/test/queries/value/rootInlines/inline-reverse.js new file mode 100644 index 0000000000..a1e4af7d46 --- /dev/null +++ b/packages/slate/test/queries/value/rootInlines/inline-reverse.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.rootInlines({ reverse: true })) +} + +export const output = [ + [four, [0, 3]], + [two, [0, 1]], +] diff --git a/packages/slate/test/queries/value/rootInlines/inline-void.js b/packages/slate/test/queries/value/rootInlines/inline-void.js new file mode 100644 index 0000000000..5a91539bc2 --- /dev/null +++ b/packages/slate/test/queries/value/rootInlines/inline-void.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.rootInlines()) +} + +export const output = [[two, [0, 1]]] diff --git a/packages/slate/test/queries/value/rootInlines/inline.js b/packages/slate/test/queries/value/rootInlines/inline.js new file mode 100644 index 0000000000..edb9f350ee --- /dev/null +++ b/packages/slate/test/queries/value/rootInlines/inline.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.rootInlines()) +} + +export const output = [[two, [0, 1]]] diff --git a/packages/slate/test/queries/value/texts/block-multiple.js b/packages/slate/test/queries/value/texts/block-multiple.js new file mode 100644 index 0000000000..5d3ecb98bb --- /dev/null +++ b/packages/slate/test/queries/value/texts/block-multiple.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [[one, [0, 0]], [two, [1, 0]]] diff --git a/packages/slate/test/queries/value/texts/block-nested.js b/packages/slate/test/queries/value/texts/block-nested.js new file mode 100644 index 0000000000..5287539bfd --- /dev/null +++ b/packages/slate/test/queries/value/texts/block-nested.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [ + [one, [0, 0, 0]], + [two, [1, 0, 0]], +] diff --git a/packages/slate/test/queries/value/texts/block-reverse.js b/packages/slate/test/queries/value/texts/block-reverse.js new file mode 100644 index 0000000000..57a9b9c456 --- /dev/null +++ b/packages/slate/test/queries/value/texts/block-reverse.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return Array.from(editor.texts({ reverse: true })) +} + +export const output = [[two, [1, 0]], [one, [0, 0]]] diff --git a/packages/slate/test/queries/value/texts/block-void.js b/packages/slate/test/queries/value/texts/block-void.js new file mode 100644 index 0000000000..c1b3b75493 --- /dev/null +++ b/packages/slate/test/queries/value/texts/block-void.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [] diff --git a/packages/slate/test/queries/value/texts/block.js b/packages/slate/test/queries/value/texts/block.js new file mode 100644 index 0000000000..bc7f4e0348 --- /dev/null +++ b/packages/slate/test/queries/value/texts/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [[one, [0, 0]]] diff --git a/packages/slate/test/queries/value/texts/inline-multiple.js b/packages/slate/test/queries/value/texts/inline-multiple.js new file mode 100644 index 0000000000..823531a7cf --- /dev/null +++ b/packages/slate/test/queries/value/texts/inline-multiple.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [ + [one, [0, 0]], + [two, [0, 1, 0]], + [three, [0, 2]], + [four, [0, 3, 0]], + [five, [0, 4]], +] diff --git a/packages/slate/test/queries/value/texts/inline-nested.js b/packages/slate/test/queries/value/texts/inline-nested.js new file mode 100644 index 0000000000..62b00986dd --- /dev/null +++ b/packages/slate/test/queries/value/texts/inline-nested.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [ + [one, [0, 0]], + [two, [0, 1, 0]], + [three, [0, 1, 1, 0]], + [four, [0, 1, 2]], + [five, [0, 2]], +] diff --git a/packages/slate/test/queries/value/texts/inline-reverse.js b/packages/slate/test/queries/value/texts/inline-reverse.js new file mode 100644 index 0000000000..c47fc23bca --- /dev/null +++ b/packages/slate/test/queries/value/texts/inline-reverse.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.texts({ reverse: true })) +} + +export const output = [ + [five, [0, 4]], + [four, [0, 3, 0]], + [three, [0, 2]], + [two, [0, 1, 0]], + [one, [0, 0]], +] diff --git a/packages/slate/test/queries/value/texts/inline-void.js b/packages/slate/test/queries/value/texts/inline-void.js new file mode 100644 index 0000000000..febeec7c26 --- /dev/null +++ b/packages/slate/test/queries/value/texts/inline-void.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [[one, [0, 0]], [three, [0, 2]]] diff --git a/packages/slate/test/queries/value/texts/inline.js b/packages/slate/test/queries/value/texts/inline.js new file mode 100644 index 0000000000..86cf7d24bd --- /dev/null +++ b/packages/slate/test/queries/value/texts/inline.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.texts()) +} + +export const output = [ + [one, [0, 0]], + [two, [0, 1, 0]], + [three, [0, 2]], +] From 140d5899f66a1f8f1da9e2f3ccf51bf212dc5c51 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 21 Oct 2019 15:51:30 -0400 Subject: [PATCH 040/165] add element, mark and path queries tests --- packages/slate/src/classes/queries/path.ts | 248 ++++++++---------- packages/slate/src/classes/queries/point.ts | 122 ++++----- packages/slate/src/classes/queries/range.ts | 4 +- packages/slate/src/classes/queries/value.ts | 34 ++- packages/slate/test/helpers/index.js | 15 +- .../queries/element/hasBlocks/block-nested.js | 18 ++ .../test/queries/element/hasBlocks/block.js | 16 ++ .../element/hasBlocks/inline-nested.js | 20 ++ .../test/queries/element/hasBlocks/inline.js | 18 ++ .../element/hasInlines/block-nested.js | 18 ++ .../test/queries/element/hasInlines/block.js | 16 ++ .../element/hasInlines/inline-nested.js | 20 ++ .../test/queries/element/hasInlines/inline.js | 18 ++ .../queries/element/hasTexts/block-nested.js | 18 ++ .../test/queries/element/hasTexts/block.js | 16 ++ .../queries/element/hasTexts/inline-nested.js | 20 ++ .../test/queries/element/hasTexts/inline.js | 18 ++ .../test/queries/element/isInline/block.js | 16 ++ .../queries/element/isInline/inline-void.js | 18 ++ .../test/queries/element/isInline/inline.js | 18 ++ .../test/queries/element/isInline/text.js | 16 ++ .../test/queries/element/isInline/value.js | 16 ++ .../test/queries/element/isVoid/block-void.js | 16 ++ .../test/queries/element/isVoid/block.js | 16 ++ .../queries/element/isVoid/inline-void.js | 18 ++ .../test/queries/element/isVoid/inline.js | 18 ++ .../slate/test/queries/element/isVoid/text.js | 16 ++ .../test/queries/element/isVoid/value.js | 16 ++ .../test/queries/mark/isAtomic/atomic.js | 18 ++ .../test/queries/mark/isAtomic/non-atomic.js | 18 ++ .../path/getClosestBlock/block-nested.js | 17 ++ .../queries/path/getClosestBlock/block.js | 15 ++ .../queries/path/getClosestBlock/inline.js | 22 ++ .../test/queries/path/getText/block-across.js | 22 ++ .../test/queries/path/getText/block-void.js | 18 ++ .../slate/test/queries/path/getText/block.js | 22 ++ .../slate/test/queries/path/getText/inline.js | 17 ++ .../slate/test/queries/path/getText/text.js | 18 ++ 38 files changed, 772 insertions(+), 238 deletions(-) create mode 100644 packages/slate/test/queries/element/hasBlocks/block-nested.js create mode 100644 packages/slate/test/queries/element/hasBlocks/block.js create mode 100644 packages/slate/test/queries/element/hasBlocks/inline-nested.js create mode 100644 packages/slate/test/queries/element/hasBlocks/inline.js create mode 100644 packages/slate/test/queries/element/hasInlines/block-nested.js create mode 100644 packages/slate/test/queries/element/hasInlines/block.js create mode 100644 packages/slate/test/queries/element/hasInlines/inline-nested.js create mode 100644 packages/slate/test/queries/element/hasInlines/inline.js create mode 100644 packages/slate/test/queries/element/hasTexts/block-nested.js create mode 100644 packages/slate/test/queries/element/hasTexts/block.js create mode 100644 packages/slate/test/queries/element/hasTexts/inline-nested.js create mode 100644 packages/slate/test/queries/element/hasTexts/inline.js create mode 100644 packages/slate/test/queries/element/isInline/block.js create mode 100644 packages/slate/test/queries/element/isInline/inline-void.js create mode 100644 packages/slate/test/queries/element/isInline/inline.js create mode 100644 packages/slate/test/queries/element/isInline/text.js create mode 100644 packages/slate/test/queries/element/isInline/value.js create mode 100644 packages/slate/test/queries/element/isVoid/block-void.js create mode 100644 packages/slate/test/queries/element/isVoid/block.js create mode 100644 packages/slate/test/queries/element/isVoid/inline-void.js create mode 100644 packages/slate/test/queries/element/isVoid/inline.js create mode 100644 packages/slate/test/queries/element/isVoid/text.js create mode 100644 packages/slate/test/queries/element/isVoid/value.js create mode 100644 packages/slate/test/queries/mark/isAtomic/atomic.js create mode 100644 packages/slate/test/queries/mark/isAtomic/non-atomic.js create mode 100644 packages/slate/test/queries/path/getClosestBlock/block-nested.js create mode 100644 packages/slate/test/queries/path/getClosestBlock/block.js create mode 100644 packages/slate/test/queries/path/getClosestBlock/inline.js create mode 100644 packages/slate/test/queries/path/getText/block-across.js create mode 100644 packages/slate/test/queries/path/getText/block-void.js create mode 100644 packages/slate/test/queries/path/getText/block.js create mode 100644 packages/slate/test/queries/path/getText/inline.js create mode 100644 packages/slate/test/queries/path/getText/text.js diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 1caaea2209..db4f52aaf7 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -4,7 +4,6 @@ import { Element, ElementEntry, Node, - Operation, Point, Path, PathRef, @@ -15,69 +14,6 @@ import { import { PATH_REFS } from '../../symbols' class PathQueries { - hasVoidAncestor(this: Editor, path: Path): boolean { - const furthestVoid = this.getFurthestVoid(path) - - if (furthestVoid) { - const [, voidPath] = furthestVoid - return Path.isAncestor(voidPath, path) - } - - return false - } - - getText(this: Editor, path: Path): string { - const { value } = this - const node = Node.get(value, path) - - if (this.hasVoidAncestor(path)) { - return '' - } else if (Element.isElement(node) && this.isVoid(node)) { - return '' - } else if (Text.isText(node)) { - return node.text - } else { - return node.nodes.map((n, i) => this.getText(path.concat(i))).join('') - } - } - - getOffset( - this: Editor, - path: Path, - options: { - depth?: number - } = {} - ): number { - const { value } = this - const { depth = 0 } = options - - if (path.length === depth) { - return 0 - } - - const rootPath = path.slice(0, depth) - const root = Node.get(value, rootPath) - const relPath = Path.relative(path, rootPath) - - if (Text.isText(root)) { - throw new Error( - `Cannot get the offset into a root text node: ${JSON.stringify(root)}` - ) - } - - const [index] = relPath - let o = 0 - - for (let i = 0; i < index; i++) { - const text = this.getText(rootPath.concat(i)) - o += text.length - } - - const relOffset = this.getOffset(path, { depth: depth + 1 }) - o += relOffset - return o - } - /** * Create a mutable ref for a `Path` object, which will stay in sync as new * operations are applied to the this. @@ -139,32 +75,22 @@ class PathQueries { * Get the end point of the node at path. */ - getEnd(this: Editor, path: Path): Point { - const [lastNode, lastPath] = this.getLastText(path) - const point = { path: lastPath, offset: lastNode.text.length } - return point + getEnd(this: Editor, path: Path): Point | undefined { + const last = this.getLastText(path) + + if (last) { + const [node, path] = last + const point = { path, offset: node.text.length } + return point + } } /** * Get the first text node from a node at path. */ - getFirstText(this: Editor, path: Path): TextEntry { - const { value } = this - const node = Node.get(value, path) - - if (Text.isText(node)) { - return [node, path] - } - - const [first] = Node.texts(value, { path }) - - if (!first) { - throw new Error( - `Unable to get the first text node of a node at path ${path} because it has no text nodes.` - ) - } - + getFirstText(this: Editor, path: Path): TextEntry | undefined { + const [first] = this.texts({ path }) return first } @@ -208,22 +134,8 @@ class PathQueries { * Get the last text node from a node at path. */ - getLastText(this: Editor, path: Path): TextEntry { - const { value } = this - const node = Node.get(value, path) - - if (Text.isText(node)) { - return [node, path] - } - - const [last] = Node.texts(value, { path, reverse: true }) - - if (!last) { - throw new Error( - `Unable to get the last text node of a node at path ${path} because it has no text nodes.` - ) - } - + getLastText(this: Editor, path: Path): TextEntry | undefined { + const [last] = this.texts({ path, reverse: true }) return last } @@ -232,8 +144,8 @@ class PathQueries { */ getNextLeafBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path })) { - if (!this.isInline(n) && this.hasInlines(n)) { + for (const [n, p] of this.leafBlocks({ path })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } } @@ -244,8 +156,8 @@ class PathQueries { */ getNextLeafInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path })) { - if (this.isInline(n) && this.hasTexts(n)) { + for (const [n, p] of this.leafInlines({ path })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } } @@ -256,8 +168,8 @@ class PathQueries { */ getNextRootBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path })) { - if (!this.isInline(n) && p.length === 1) { + for (const [n, p] of this.rootBlocks({ path })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } } @@ -268,13 +180,9 @@ class PathQueries { */ getNextRootInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path })) { - if (Element.isElement(n) && this.isInline(n)) { - const parent = Node.parent(this.value, p) - - if (Element.isElement(parent) && !this.isInline(parent)) { - return [n, p] - } + for (const [n, p] of this.rootInlines({ path })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { + return [n, p] } } } @@ -284,18 +192,61 @@ class PathQueries { */ getNextText(this: Editor, path: Path): TextEntry | undefined { - const { value } = this - const [, next] = Node.texts(value, { path }) + const [, next] = this.texts({ path }) return next } + /** + * Get the relative offset to a node at a path in the document. + * + * Note: this ignores void nodes in calculating the offset, as their text + * content is presumed to be an empty string. + */ + + getOffset( + this: Editor, + path: Path, + options: { + depth?: number + } = {} + ): number { + const { value } = this + const { depth = 0 } = options + + if (path.length === depth) { + return 0 + } + + const rootPath = path.slice(0, depth) + const root = Node.get(value, rootPath) + const relPath = Path.relative(path, rootPath) + + if (Text.isText(root)) { + throw new Error( + `Cannot get the offset into a root text node: ${JSON.stringify(root)}` + ) + } + + const [index] = relPath + let o = 0 + + for (let i = 0; i < index; i++) { + const text = this.getText(rootPath.concat(i)) + o += text.length + } + + const relOffset = this.getOffset(path, { depth: depth + 1 }) + o += relOffset + return o + } + /** * Get the previous leaf block node entry starting from a path. */ getPreviousLeafBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (!this.isInline(n) && this.hasInlines(n)) { + for (const [n, p] of this.leafBlocks({ path, reverse: true })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } } @@ -306,8 +257,8 @@ class PathQueries { */ getPreviousLeafInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (this.isInline(n) && this.hasTexts(n)) { + for (const [n, p] of this.leafInlines({ path, reverse: true })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } } @@ -318,8 +269,8 @@ class PathQueries { */ getPreviousRootBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (!this.isInline(n) && p.length === 1) { + for (const [n, p] of this.rootBlocks({ path, reverse: true })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } } @@ -330,13 +281,9 @@ class PathQueries { */ getPreviousRootInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.elements(this.value, { path, reverse: true })) { - if (Element.isElement(n) && this.isInline(n)) { - const parent = Node.parent(this.value, p) - - if (Element.isElement(parent) && !this.isInline(parent)) { - return [n, p] - } + for (const [n, p] of this.rootInlines({ path, reverse: true })) { + if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { + return [n, p] } } } @@ -346,8 +293,7 @@ class PathQueries { */ getPreviousText(this: Editor, path: Path): TextEntry | undefined { - const { value } = this - const [, prev] = Node.texts(value, { path, reverse: true }) + const [, prev] = this.texts({ path, reverse: true }) return prev } @@ -356,13 +302,12 @@ class PathQueries { */ getRange(this: Editor, path: Path): Range { - const { value } = this - const [first] = Node.texts(value, { path }) - const [last] = Node.texts(value, { path, reverse: true }) + const first = this.getFirstText(path) + const last = this.getLastText(path) if (!first || !last) { throw new Error( - `Unable to get a range for the node at path ${path} because it has not text nodes.` + `Unable to get a range for the node at path ${path} because it has no text nodes.` ) } @@ -370,18 +315,41 @@ class PathQueries { const [lastNode, lastPath] = last const anchor = { path: firstPath, offset: 0 } const focus = { path: lastPath, offset: lastNode.text.length } - const range = produce({ anchor, focus }, () => {}) - return range + return { anchor, focus } } /** * Get the start point of the node at path. */ - getStart(this: Editor, path: Path): Point { - const [, firstPath] = this.getFirstText(path) - const point = { path: firstPath, offset: 0 } - return point + getStart(this: Editor, path: Path): Point | undefined { + const first = this.getLastText(path) + + if (first) { + const [node, path] = first + const point = { path, offset: 0 } + return point + } + } + /** + * Get the text content of a node at path. + * + * Note: the text of void nodes is presumed to be an empty string, regardless + * of what their actual content is. + */ + + getText(this: Editor, path: Path): string { + const { value } = this + const node = Node.get(value, path) + const furthestVoid = this.getFurthestVoid(path) + + if (furthestVoid) { + return '' + } else if (Text.isText(node)) { + return node.text + } else { + return node.nodes.map((n, i) => this.getText(path.concat(i))).join('') + } } } diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index eeb2c08953..5538333852 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -23,48 +23,6 @@ class PointQueries { return ref } - /** - * Check if a point is at the start of a path. - */ - - isAtStartOfPath(this: Editor, point: Point, path: Path): boolean { - const { value } = this - const [first] = Node.texts(value, { path }) - - if (!first) { - return false - } - - const [, firstPath] = first - return point.offset === 0 && Path.equals(point.path, firstPath) - } - - /** - * Check if a point is at the end of a path. - */ - - isAtEndOfPath(this: Editor, point: Point, path: Path): boolean { - const { value } = this - const [last] = Node.texts(value, { path, reverse: true }) - - if (!last) { - return false - } - - const [lastNode, lastPath] = last - return ( - point.offset === lastNode.text.length && Path.equals(point.path, lastPath) - ) - } - - /** - * Check if a point is at either edge of a path. - */ - - isAtEdgeOfPath(this: Editor, point: Point, path: Path): boolean { - return this.isAtStartOfPath(point, path) || this.isAtEndOfPath(point, path) - } - /** * Calculate the next point forward in the document from a starting point. */ @@ -74,44 +32,28 @@ class PointQueries { point: Point, options: { distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' - allowZeroWidth?: boolean + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' } = {} ): Point | undefined { const { distance = 1 } = options let d = 0 - let target: Point | undefined + let target for (const p of this.positions({ ...options, point })) { if (d >= distance) { break } - target = p + if (d !== 0) { + target = p + } + d++ } return target } - /** - * Get the next point in the document that is not inside a void node. - */ - - getNextNonVoidPoint(this: Editor, point: Point): Point | undefined { - let next: Point | undefined = point - - while (next) { - const closestVoid = this.getClosestVoid(next.path) - - if (closestVoid) { - next = this.getNextPoint(next, { allowZeroWidth: true }) - } else { - return next - } - } - } - /** * Calculate the previous point backward from a starting point. */ @@ -121,20 +63,22 @@ class PointQueries { point: Point, options: { distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' - allowZeroWidth?: boolean + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' } = {} ): Point | undefined { const { distance = 1 } = options let d = 0 - let target: Point | undefined + let target for (const p of this.positions({ ...options, point, reverse: true })) { if (d >= distance) { break } - target = p + if (d !== 0) { + target = p + } + d++ } @@ -142,21 +86,43 @@ class PointQueries { } /** - * Get the previous point in the document that is not inside a void node. + * Check if a point is at the start of a path. */ - getPreviousNonVoidPoint(this: Editor, point: Point): Point | undefined { - let prev: Point | undefined = point + isAtStart(this: Editor, point: Point, path: Path): boolean { + const first = this.getFirstText(path) - while (prev) { - const closestVoid = this.getClosestVoid(prev.path) + if (!first) { + return false + } - if (closestVoid) { - prev = this.getPreviousPoint(prev, { allowZeroWidth: true }) - } else { - return prev - } + const [, firstPath] = first + return point.offset === 0 && Path.equals(point.path, firstPath) + } + + /** + * Check if a point is at the end of a path. + */ + + isAtEnd(this: Editor, point: Point, path: Path): boolean { + const last = this.getLastText(path) + + if (!last) { + return false } + + const [lastNode, lastPath] = last + return ( + point.offset === lastNode.text.length && Path.equals(point.path, lastPath) + ) + } + + /** + * Check if a point is at either edge of a path. + */ + + isAtEdge(this: Editor, point: Point, path: Path): boolean { + return this.isAtStart(point, path) || this.isAtEnd(point, path) } } diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts index 2ec842ddbb..fb2b299fb3 100644 --- a/packages/slate/src/classes/queries/range.ts +++ b/packages/slate/src/classes/queries/range.ts @@ -107,7 +107,7 @@ class RangeQueries { } const [, endBlockPath] = closestBlock - return this.isAtStartOfPath(end, endBlockPath) + return this.isAtStart(end, endBlockPath) } /** @@ -127,7 +127,7 @@ class RangeQueries { } const [, endInlinePath] = closestInline - return this.isAtStartOfPath(end, endInlinePath) + return this.isAtStart(end, endInlinePath) } /** diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index b218787300..4acc777a05 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -1,13 +1,12 @@ -import { produce } from 'immer' import { reverse as reverseText } from 'esrever' import { - Ancestor, Editor, Element, ElementEntry, Mark, Node, NodeEntry, + MarkEntry, Path, Point, Range, @@ -107,7 +106,6 @@ class ValueQueries { } for (const [node] of this.texts({ range })) { - debugger const { marks } = node if (first) { @@ -160,6 +158,24 @@ class ValueQueries { } } + /** + * Iterate through all of the text nodes in the editor. + */ + + *marks( + this: Editor, + options: { + path?: Path + range?: Range + reverse?: boolean + } = {} + ): Iterable { + yield* Node.marks(this.value, { + ...options, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) + } + /** * Iterate through all of the leaf block nodes in the editor. */ @@ -216,7 +232,6 @@ class ValueQueries { point?: Point unit?: 'offset' | 'character' | 'word' | 'line' | 'block' reverse?: boolean - allowZeroWidth?: boolean } = {} ): Iterable { const { @@ -225,6 +240,10 @@ class ValueQueries { point = reverse ? this.getEnd([]) : this.getStart([]), } = options + if (point == null) { + return + } + if (unit !== 'offset') { yield point } @@ -255,7 +274,12 @@ class ValueQueries { })) { if (Element.isElement(n)) { if (this.isVoid(n)) { - yield this.getStart(p) + const start = this.getStart(p) + + if (start) { + yield start + } + continue } diff --git a/packages/slate/test/helpers/index.js b/packages/slate/test/helpers/index.js index fec56e21aa..2f25f7efd4 100644 --- a/packages/slate/test/helpers/index.js +++ b/packages/slate/test/helpers/index.js @@ -1,4 +1,3 @@ -import { Element } from 'slate' import { createHyperscript } from 'slate-hyperscript' const h = createHyperscript({ @@ -14,22 +13,12 @@ const TestPlugin = Editor => { return mark.atomic === true ? true : super.isAtomic(mark) } - isBlock(node) { - return Element.isElement(node) && node.inline !== true - ? true - : super.isBlock(node) - } - isInline(node) { - return Element.isElement(node) && node.inline === true - ? true - : super.isInline(node) + return node.inline === true ? true : super.isInline(node) } isVoid(node) { - return Element.isElement(node) && node.void === true - ? true - : super.isVoid(node) + return node.void === true ? true : super.isVoid(node) } } } diff --git a/packages/slate/test/queries/element/hasBlocks/block-nested.js b/packages/slate/test/queries/element/hasBlocks/block-nested.js new file mode 100644 index 0000000000..fa5ea1a4e6 --- /dev/null +++ b/packages/slate/test/queries/element/hasBlocks/block-nested.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasBlocks(block) +} + +export const output = true diff --git a/packages/slate/test/queries/element/hasBlocks/block.js b/packages/slate/test/queries/element/hasBlocks/block.js new file mode 100644 index 0000000000..57ca875732 --- /dev/null +++ b/packages/slate/test/queries/element/hasBlocks/block.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasBlocks(block) +} + +export const output = false diff --git a/packages/slate/test/queries/element/hasBlocks/inline-nested.js b/packages/slate/test/queries/element/hasBlocks/inline-nested.js new file mode 100644 index 0000000000..6d2dce1dc3 --- /dev/null +++ b/packages/slate/test/queries/element/hasBlocks/inline-nested.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.hasBlocks(inline) +} + +export const output = false diff --git a/packages/slate/test/queries/element/hasBlocks/inline.js b/packages/slate/test/queries/element/hasBlocks/inline.js new file mode 100644 index 0000000000..f8ec307bc2 --- /dev/null +++ b/packages/slate/test/queries/element/hasBlocks/inline.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasBlocks(block) +} + +export const output = false diff --git a/packages/slate/test/queries/element/hasInlines/block-nested.js b/packages/slate/test/queries/element/hasInlines/block-nested.js new file mode 100644 index 0000000000..0c22a20186 --- /dev/null +++ b/packages/slate/test/queries/element/hasInlines/block-nested.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasInlines(block) +} + +export const output = false diff --git a/packages/slate/test/queries/element/hasInlines/block.js b/packages/slate/test/queries/element/hasInlines/block.js new file mode 100644 index 0000000000..787b2c9514 --- /dev/null +++ b/packages/slate/test/queries/element/hasInlines/block.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasInlines(block) +} + +export const output = true diff --git a/packages/slate/test/queries/element/hasInlines/inline-nested.js b/packages/slate/test/queries/element/hasInlines/inline-nested.js new file mode 100644 index 0000000000..f5d3a517bb --- /dev/null +++ b/packages/slate/test/queries/element/hasInlines/inline-nested.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.hasInlines(inline) +} + +export const output = true diff --git a/packages/slate/test/queries/element/hasInlines/inline.js b/packages/slate/test/queries/element/hasInlines/inline.js new file mode 100644 index 0000000000..8e85af55b9 --- /dev/null +++ b/packages/slate/test/queries/element/hasInlines/inline.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasInlines(block) +} + +export const output = true diff --git a/packages/slate/test/queries/element/hasTexts/block-nested.js b/packages/slate/test/queries/element/hasTexts/block-nested.js new file mode 100644 index 0000000000..089264b1b9 --- /dev/null +++ b/packages/slate/test/queries/element/hasTexts/block-nested.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasTexts(block) +} + +export const output = false diff --git a/packages/slate/test/queries/element/hasTexts/block.js b/packages/slate/test/queries/element/hasTexts/block.js new file mode 100644 index 0000000000..58f8a67e84 --- /dev/null +++ b/packages/slate/test/queries/element/hasTexts/block.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.hasTexts(block) +} + +export const output = true diff --git a/packages/slate/test/queries/element/hasTexts/inline-nested.js b/packages/slate/test/queries/element/hasTexts/inline-nested.js new file mode 100644 index 0000000000..10d5d1c7af --- /dev/null +++ b/packages/slate/test/queries/element/hasTexts/inline-nested.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.hasTexts(inline) +} + +export const output = false diff --git a/packages/slate/test/queries/element/hasTexts/inline.js b/packages/slate/test/queries/element/hasTexts/inline.js new file mode 100644 index 0000000000..f47f65e60f --- /dev/null +++ b/packages/slate/test/queries/element/hasTexts/inline.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.hasTexts(inline) +} + +export const output = true diff --git a/packages/slate/test/queries/element/isInline/block.js b/packages/slate/test/queries/element/isInline/block.js new file mode 100644 index 0000000000..255b4a4581 --- /dev/null +++ b/packages/slate/test/queries/element/isInline/block.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.isInline(block) +} + +export const output = false diff --git a/packages/slate/test/queries/element/isInline/inline-void.js b/packages/slate/test/queries/element/isInline/inline-void.js new file mode 100644 index 0000000000..885f414476 --- /dev/null +++ b/packages/slate/test/queries/element/isInline/inline-void.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.isInline(inline) +} + +export const output = true diff --git a/packages/slate/test/queries/element/isInline/inline.js b/packages/slate/test/queries/element/isInline/inline.js new file mode 100644 index 0000000000..9f7ccf3046 --- /dev/null +++ b/packages/slate/test/queries/element/isInline/inline.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.isInline(inline) +} + +export const output = true diff --git a/packages/slate/test/queries/element/isInline/text.js b/packages/slate/test/queries/element/isInline/text.js new file mode 100644 index 0000000000..8ff1a9b17d --- /dev/null +++ b/packages/slate/test/queries/element/isInline/text.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const text = editor.value.nodes[0].nodes[0] + return editor.isInline(text) +} + +export const output = false diff --git a/packages/slate/test/queries/element/isInline/value.js b/packages/slate/test/queries/element/isInline/value.js new file mode 100644 index 0000000000..9015edf444 --- /dev/null +++ b/packages/slate/test/queries/element/isInline/value.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const { value } = editor + return editor.isInline(value) +} + +export const output = false diff --git a/packages/slate/test/queries/element/isVoid/block-void.js b/packages/slate/test/queries/element/isVoid/block-void.js new file mode 100644 index 0000000000..d3ec4368de --- /dev/null +++ b/packages/slate/test/queries/element/isVoid/block-void.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.isVoid(block) +} + +export const output = true diff --git a/packages/slate/test/queries/element/isVoid/block.js b/packages/slate/test/queries/element/isVoid/block.js new file mode 100644 index 0000000000..06261160ae --- /dev/null +++ b/packages/slate/test/queries/element/isVoid/block.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.isVoid(block) +} + +export const output = false diff --git a/packages/slate/test/queries/element/isVoid/inline-void.js b/packages/slate/test/queries/element/isVoid/inline-void.js new file mode 100644 index 0000000000..9398494ed1 --- /dev/null +++ b/packages/slate/test/queries/element/isVoid/inline-void.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.isVoid(inline) +} + +export const output = true diff --git a/packages/slate/test/queries/element/isVoid/inline.js b/packages/slate/test/queries/element/isVoid/inline.js new file mode 100644 index 0000000000..21eff3669b --- /dev/null +++ b/packages/slate/test/queries/element/isVoid/inline.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.isVoid(inline) +} + +export const output = false diff --git a/packages/slate/test/queries/element/isVoid/text.js b/packages/slate/test/queries/element/isVoid/text.js new file mode 100644 index 0000000000..c4efa18d0a --- /dev/null +++ b/packages/slate/test/queries/element/isVoid/text.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const text = editor.value.nodes[0].nodes[0] + return editor.isVoid(text) +} + +export const output = false diff --git a/packages/slate/test/queries/element/isVoid/value.js b/packages/slate/test/queries/element/isVoid/value.js new file mode 100644 index 0000000000..d19f550bba --- /dev/null +++ b/packages/slate/test/queries/element/isVoid/value.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const { value } = editor + return editor.isVoid(value) +} + +export const output = false diff --git a/packages/slate/test/queries/mark/isAtomic/atomic.js b/packages/slate/test/queries/mark/isAtomic/atomic.js new file mode 100644 index 0000000000..666d8d523c --- /dev/null +++ b/packages/slate/test/queries/mark/isAtomic/atomic.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const [[mark]] = editor.marks() + return editor.isAtomic(mark) +} + +export const output = true diff --git a/packages/slate/test/queries/mark/isAtomic/non-atomic.js b/packages/slate/test/queries/mark/isAtomic/non-atomic.js new file mode 100644 index 0000000000..6bffa13ac8 --- /dev/null +++ b/packages/slate/test/queries/mark/isAtomic/non-atomic.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const [[mark]] = editor.marks() + return editor.isAtomic(mark) +} + +export const output = false diff --git a/packages/slate/test/queries/path/getClosestBlock/block-nested.js b/packages/slate/test/queries/path/getClosestBlock/block-nested.js new file mode 100644 index 0000000000..2947d14266 --- /dev/null +++ b/packages/slate/test/queries/path/getClosestBlock/block-nested.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + return editor.getClosestBlock([0, 0, 0]) +} + +export const output = [one, [0, 0]] diff --git a/packages/slate/test/queries/path/getClosestBlock/block.js b/packages/slate/test/queries/path/getClosestBlock/block.js new file mode 100644 index 0000000000..88e8a747df --- /dev/null +++ b/packages/slate/test/queries/path/getClosestBlock/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getClosestBlock([0, 0]) +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/path/getClosestBlock/inline.js b/packages/slate/test/queries/path/getClosestBlock/inline.js new file mode 100644 index 0000000000..d81d7eca82 --- /dev/null +++ b/packages/slate/test/queries/path/getClosestBlock/inline.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return editor.getClosestBlock([0, 1, 0]) +} + +export const output = [ + + onetwothree + , + [0], +] diff --git a/packages/slate/test/queries/path/getText/block-across.js b/packages/slate/test/queries/path/getText/block-across.js new file mode 100644 index 0000000000..8e2ba1214d --- /dev/null +++ b/packages/slate/test/queries/path/getText/block-across.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + two + + + three + four + + +) + +export const run = editor => { + return editor.getText([]) +} + +export const output = `onetwothreefour` diff --git a/packages/slate/test/queries/path/getText/block-void.js b/packages/slate/test/queries/path/getText/block-void.js new file mode 100644 index 0000000000..0488bc8b9d --- /dev/null +++ b/packages/slate/test/queries/path/getText/block-void.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + two + + +) + +export const run = editor => { + return editor.getText([0]) +} + +export const output = `` diff --git a/packages/slate/test/queries/path/getText/block.js b/packages/slate/test/queries/path/getText/block.js new file mode 100644 index 0000000000..c1bbe832a2 --- /dev/null +++ b/packages/slate/test/queries/path/getText/block.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + two + + + three + four + + +) + +export const run = editor => { + return editor.getText([0]) +} + +export const output = `onetwo` diff --git a/packages/slate/test/queries/path/getText/inline.js b/packages/slate/test/queries/path/getText/inline.js new file mode 100644 index 0000000000..fb0fc3a1f1 --- /dev/null +++ b/packages/slate/test/queries/path/getText/inline.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return editor.getText([0, 1]) +} + +export const output = `two` diff --git a/packages/slate/test/queries/path/getText/text.js b/packages/slate/test/queries/path/getText/text.js new file mode 100644 index 0000000000..c9a64792ed --- /dev/null +++ b/packages/slate/test/queries/path/getText/text.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + two + + +) + +export const run = editor => { + return editor.getText([0, 0]) +} + +export const output = `one` From 38503bfcb688ee61621d02b0dccd3aadec239a89 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 21 Oct 2019 16:10:23 -0400 Subject: [PATCH 041/165] convert most on-selection tests --- .../slate/src/classes/commands/selection.ts | 2 +- packages/slate/src/classes/queries/point.ts | 4 +-- .../{out-of-reverse.js => backward.js} | 4 +-- .../{default.js => basic.js} | 0 .../{from-collapsed.js => collapsed.js} | 0 .../{param.js => distance.js} | 0 .../backward.js} | 18 ++++------ .../basic.js} | 18 ++++------ .../collapsed.js} | 18 ++++------ .../move-anchor-forward/default.js | 27 --------------- .../distance.js} | 18 ++++------ .../move-anchor-forward/from-collapsed.js | 27 --------------- .../move-anchor-forward/into-reverse.js | 27 --------------- .../on-selection/move-anchor-forward/param.js | 27 --------------- .../on-selection/move-backward/default.js | 18 ++++------ .../on-selection/move-backward/expanded.js | 18 ++++------ .../on-selection/move-backward/param.js | 18 ++++------ .../on-selection/move-backward/reversed.js | 18 ++++------ .../on-selection/move-end-backward/default.js | 18 ++++------ .../move-end-backward/from-collapsed.js | 18 ++++------ .../move-end-backward/into-reverse.js | 18 ++++------ .../move-end-backward/out-of-reverse.js | 18 ++++------ .../on-selection/move-end-backward/param.js | 18 ++++------ .../move-end-backward/reversed.js | 18 ++++------ .../on-selection/move-end-forward/default.js | 18 ++++------ .../move-end-forward/from-collapsed.js | 18 ++++------ .../on-selection/move-end-forward/param.js | 18 ++++------ .../on-selection/move-end-forward/reversed.js | 18 ++++------ .../move-focus-backward/default.js | 18 ++++------ .../move-focus-backward/from-collapsed.js | 18 ++++------ .../move-focus-backward/into-reverse.js | 18 ++++------ .../on-selection/move-focus-backward/param.js | 18 ++++------ .../move-focus-forward/default.js | 18 ++++------ .../move-focus-forward/from-collapsed.js | 18 ++++------ .../move-focus-forward/out-of-reverse.js | 18 ++++------ .../on-selection/move-focus-forward/param.js | 18 ++++------ .../on-selection/move-forward/default.js | 18 ++++------ .../on-selection/move-forward/expanded.js | 18 ++++------ .../on-selection/move-forward/param.js | 18 ++++------ .../on-selection/move-forward/reversed.js | 18 ++++------ .../move-start-backward/default.js | 18 ++++------ .../move-start-backward/from-collapsed.js | 18 ++++------ .../on-selection/move-start-backward/param.js | 18 ++++------ .../move-start-backward/reversed.js | 18 ++++------ .../move-start-forward/default.js | 18 ++++------ .../move-start-forward/from-collapsed.js | 18 ++++------ .../move-start-forward/into-reverse.js | 18 ++++------ .../move-start-forward/out-of-reverse.js | 18 ++++------ .../on-selection/move-start-forward/param.js | 18 ++++------ .../move-start-forward/reversed.js | 18 ++++------ .../on-selection/move-to-end-of-block/end.js | 31 ----------------- .../move-to-end-of-block/middle.js | 31 ----------------- .../move-to-end-of-block/start.js | 31 ----------------- .../move-to-end-of-document/block-end.js | 31 ----------------- .../move-to-end-of-document/block-middle.js | 31 ----------------- .../move-to-end-of-document/block-start.js | 31 ----------------- .../move-to-end-of-document/document-end.js | 31 ----------------- .../move-to-end-of-document/document-start.js | 31 ----------------- .../move-to-end-of-next-block/block-end.js | 31 ----------------- .../move-to-end-of-next-block/block-middle.js | 31 ----------------- .../move-to-end-of-next-block/block-start.js | 31 ----------------- .../move-to-end-of-next-block/document-end.js | 31 ----------------- .../document-start.js | 31 ----------------- .../block-end.js | 31 ----------------- .../block-middle.js | 31 ----------------- .../block-start.js | 31 ----------------- .../document-end.js | 31 ----------------- .../document-start.js | 31 ----------------- .../on-selection/move-to-end/basic.js | 27 --------------- .../commands/on-selection/move-to-end/void.js | 28 ---------------- .../on-selection/move-to-focus/basic.js | 27 --------------- .../move-to-range-of-document/basic.js | 33 ------------------- .../move-to-start-of-document/block-end.js | 31 ----------------- .../move-to-start-of-document/block-middle.js | 31 ----------------- .../move-to-start-of-document/block-start.js | 31 ----------------- .../move-to-start-of-document/document-end.js | 31 ----------------- .../document-start.js | 31 ----------------- .../move-to-start/already-collapsed.js | 27 --------------- .../on-selection/move-to-start/basic.js | 27 --------------- .../on-selection/move-to-start/void.js | 27 --------------- 80 files changed, 285 insertions(+), 1462 deletions(-) rename packages/slate/test/commands/on-selection/move-anchor-backward/{out-of-reverse.js => backward.js} (74%) rename packages/slate/test/commands/on-selection/move-anchor-backward/{default.js => basic.js} (100%) rename packages/slate/test/commands/on-selection/move-anchor-backward/{from-collapsed.js => collapsed.js} (100%) rename packages/slate/test/commands/on-selection/move-anchor-backward/{param.js => distance.js} (100%) rename packages/slate/test/commands/on-selection/{move-to-focus/already-collapsed.js => move-anchor-forward/backward.js} (54%) rename packages/slate/test/commands/on-selection/{move-to-anchor/already-collapsed.js => move-anchor-forward/basic.js} (54%) rename packages/slate/test/commands/on-selection/{move-to-end/already-collapsed.js => move-anchor-forward/collapsed.js} (55%) delete mode 100644 packages/slate/test/commands/on-selection/move-anchor-forward/default.js rename packages/slate/test/commands/on-selection/{move-to-anchor/basic.js => move-anchor-forward/distance.js} (52%) delete mode 100644 packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js delete mode 100644 packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js delete mode 100644 packages/slate/test/commands/on-selection/move-anchor-forward/param.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-block/end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-block/start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end/basic.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-end/void.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-focus/basic.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start/basic.js delete mode 100644 packages/slate/test/commands/on-selection/move-to-start/void.js diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index 09366ff02f..f3a4682efd 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -186,7 +186,7 @@ class SelectionCommands { */ moveFocusTo(this: Editor, point: Point) { - this.setSelection({ anchor: point }) + this.setSelection({ focus: point }) } /** diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index 5538333852..c7e85a87b8 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -40,7 +40,7 @@ class PointQueries { let target for (const p of this.positions({ ...options, point })) { - if (d >= distance) { + if (d > distance) { break } @@ -71,7 +71,7 @@ class PointQueries { let target for (const p of this.positions({ ...options, point, reverse: true })) { - if (d >= distance) { + if (d > distance) { break } diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-anchor-backward/backward.js similarity index 74% rename from packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js rename to packages/slate/test/commands/on-selection/move-anchor-backward/backward.js index 0f15801a6a..78b2f55c70 100644 --- a/packages/slate/test/commands/on-selection/move-anchor-backward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-anchor-backward/backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor({ reverse: true, distance: 8 }) + editor.moveAnchor({ reverse: true }) } export const input = ( @@ -17,7 +17,7 @@ export const input = ( export const output = ( - one two three + one two three ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/default.js b/packages/slate/test/commands/on-selection/move-anchor-backward/basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-backward/default.js rename to packages/slate/test/commands/on-selection/move-anchor-backward/basic.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-backward/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-backward/from-collapsed.js rename to packages/slate/test/commands/on-selection/move-anchor-backward/collapsed.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/param.js b/packages/slate/test/commands/on-selection/move-anchor-backward/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-backward/param.js rename to packages/slate/test/commands/on-selection/move-anchor-backward/distance.js diff --git a/packages/slate/test/commands/on-selection/move-to-focus/already-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-forward/backward.js similarity index 54% rename from packages/slate/test/commands/on-selection/move-to-focus/already-collapsed.js rename to packages/slate/test/commands/on-selection/move-anchor-forward/backward.js index 24bdd7d622..be6fef861b 100644 --- a/packages/slate/test/commands/on-selection/move-to-focus/already-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/backward.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveToFocus() + editor.moveAnchor() } export const input = ( - - - one - - + + one two three + ) export const output = ( - - - one - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-anchor/already-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-forward/basic.js similarity index 54% rename from packages/slate/test/commands/on-selection/move-to-anchor/already-collapsed.js rename to packages/slate/test/commands/on-selection/move-anchor-forward/basic.js index d403888545..ce86cad1ca 100644 --- a/packages/slate/test/commands/on-selection/move-to-anchor/already-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/basic.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveToAnchor() + editor.moveAnchor() } export const input = ( - - - one - - + + one two three + ) export const output = ( - - - one - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end/already-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-forward/collapsed.js similarity index 55% rename from packages/slate/test/commands/on-selection/move-to-end/already-collapsed.js rename to packages/slate/test/commands/on-selection/move-anchor-forward/collapsed.js index f22091478d..93d28c53e8 100644 --- a/packages/slate/test/commands/on-selection/move-to-end/already-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveToEnd() + editor.moveAnchor() } export const input = ( - - - one - - + + one two three + ) export const output = ( - - - one - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/default.js b/packages/slate/test/commands/on-selection/move-anchor-forward/default.js deleted file mode 100644 index 0780525dde..0000000000 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/default.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveAnchorForward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one two three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-anchor/basic.js b/packages/slate/test/commands/on-selection/move-anchor-forward/distance.js similarity index 52% rename from packages/slate/test/commands/on-selection/move-to-anchor/basic.js rename to packages/slate/test/commands/on-selection/move-anchor-forward/distance.js index 403b028d8c..59f364d705 100644 --- a/packages/slate/test/commands/on-selection/move-to-anchor/basic.js +++ b/packages/slate/test/commands/on-selection/move-anchor-forward/distance.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveToAnchor() + editor.moveAnchor({ distance: 3 }) } export const input = ( - - - one - - + + one two three + ) export const output = ( - - - one - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js deleted file mode 100644 index 3c39503591..0000000000 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/from-collapsed.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveAnchorForward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one two three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js b/packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js deleted file mode 100644 index 12de63d147..0000000000 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/into-reverse.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveAnchorForward(8) -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one two three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/param.js b/packages/slate/test/commands/on-selection/move-anchor-forward/param.js deleted file mode 100644 index 9d885421bd..0000000000 --- a/packages/slate/test/commands/on-selection/move-anchor-forward/param.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveAnchorForward(3) -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one two three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-backward/default.js b/packages/slate/test/commands/on-selection/move-backward/default.js index cfcc8577ef..5f642e34bd 100644 --- a/packages/slate/test/commands/on-selection/move-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-backward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveBackward() + editor.move({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-backward/expanded.js b/packages/slate/test/commands/on-selection/move-backward/expanded.js index da098e0c9f..1328bb8622 100644 --- a/packages/slate/test/commands/on-selection/move-backward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-backward/expanded.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveBackward() + editor.move({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-backward/param.js b/packages/slate/test/commands/on-selection/move-backward/param.js index 70c51f6288..511676543f 100644 --- a/packages/slate/test/commands/on-selection/move-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-backward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveBackward(6) + editor.move({ reverse: true, distance: 6 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-backward/reversed.js b/packages/slate/test/commands/on-selection/move-backward/reversed.js index 1c13b910e2..f412103ef7 100644 --- a/packages/slate/test/commands/on-selection/move-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-backward/reversed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveBackward() + editor.move({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/default.js b/packages/slate/test/commands/on-selection/move-end-backward/default.js index 073d523257..38e51b8841 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndBackward() + editor.moveEnd({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js index d64b341932..c25027dc1e 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndBackward() + editor.moveEnd({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js b/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js index 7bab223835..467f85106d 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndBackward(6) + editor.moveEnd({ reverse: true, distance: 6 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js index b62e65aa28..98f35e5076 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndBackward(7) + editor.moveEnd({ reverse: true, distance: 7 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/param.js b/packages/slate/test/commands/on-selection/move-end-backward/param.js index 2efff1a07a..9b7740df8f 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndBackward(3) + editor.moveEnd({ reverse: true, distance: 3 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-backward/reversed.js b/packages/slate/test/commands/on-selection/move-end-backward/reversed.js index 4460b21e39..591eae22d4 100644 --- a/packages/slate/test/commands/on-selection/move-end-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-end-backward/reversed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndBackward() + editor.moveEnd({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/default.js b/packages/slate/test/commands/on-selection/move-end-forward/default.js index 8d4d359dfc..b4f3ebec58 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndForward() + editor.moveEnd() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js index a2d7684ad7..48b2edc7a0 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndForward() + editor.moveEnd() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/param.js b/packages/slate/test/commands/on-selection/move-end-forward/param.js index 37dd15e9ba..ed5c163ef9 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndForward(3) + editor.moveEnd({ distance: 3 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-end-forward/reversed.js b/packages/slate/test/commands/on-selection/move-end-forward/reversed.js index 1ae2138406..320756252b 100644 --- a/packages/slate/test/commands/on-selection/move-end-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-end-forward/reversed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEndForward() + editor.moveEnd() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/default.js b/packages/slate/test/commands/on-selection/move-focus-backward/default.js index ae553fcc8e..dcf63da818 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusBackward() + editor.moveFocus({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js index 45d6efcea0..a36cd87d36 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusBackward() + editor.moveFocus({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js b/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js index d7119ed1da..5e043cf8d4 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusBackward(10) + editor.moveFocus({ reverse: true, distance: 10 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/param.js b/packages/slate/test/commands/on-selection/move-focus-backward/param.js index 7b7d7d77b3..418889933b 100644 --- a/packages/slate/test/commands/on-selection/move-focus-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-focus-backward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusBackward(6) + editor.moveFocus({ reverse: true, distance: 6 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/default.js b/packages/slate/test/commands/on-selection/move-focus-forward/default.js index 67e7032cfe..8ec46256d6 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusForward() + editor.moveFocus() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js index e13f2ce6ff..b7a3279248 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusForward() + editor.moveFocus() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js index 2b0496670d..ab6ce6dccc 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusForward(7) + editor.moveFocus({ distance: 7 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/param.js b/packages/slate/test/commands/on-selection/move-focus-forward/param.js index d3acbb46b8..72d38c3ec4 100644 --- a/packages/slate/test/commands/on-selection/move-focus-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-focus-forward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocusForward(4) + editor.moveFocus({ distance: 4 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/default.js b/packages/slate/test/commands/on-selection/move-forward/default.js index 5233abb4c6..8730b6ddb1 100644 --- a/packages/slate/test/commands/on-selection/move-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-forward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveForward() + editor.move() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/expanded.js b/packages/slate/test/commands/on-selection/move-forward/expanded.js index eb7d713901..5e8737d7b0 100644 --- a/packages/slate/test/commands/on-selection/move-forward/expanded.js +++ b/packages/slate/test/commands/on-selection/move-forward/expanded.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveForward() + editor.move() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/param.js b/packages/slate/test/commands/on-selection/move-forward/param.js index 5062a3f1fe..13fc2ea266 100644 --- a/packages/slate/test/commands/on-selection/move-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-forward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveForward(6) + editor.move({ distance: 6 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-forward/reversed.js b/packages/slate/test/commands/on-selection/move-forward/reversed.js index 62a587ed8e..42260150fc 100644 --- a/packages/slate/test/commands/on-selection/move-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-forward/reversed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveForward() + editor.move() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/default.js b/packages/slate/test/commands/on-selection/move-start-backward/default.js index ef61da9829..5acbf1b2a2 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/default.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartBackward() + editor.moveStart({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js index 57461909f8..a89b62e067 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartBackward() + editor.moveStart({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/param.js b/packages/slate/test/commands/on-selection/move-start-backward/param.js index 9d8d0e7749..0750e36676 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/param.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartBackward(3) + editor.moveStart({ reverse: true, distance: 3 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-backward/reversed.js b/packages/slate/test/commands/on-selection/move-start-backward/reversed.js index f1c043077e..3b26dec3b4 100644 --- a/packages/slate/test/commands/on-selection/move-start-backward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-start-backward/reversed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartBackward() + editor.moveStart({ reverse: true }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/default.js b/packages/slate/test/commands/on-selection/move-start-forward/default.js index ed0511d579..d7d074c3aa 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/default.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/default.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartForward() + editor.moveStart() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js index 70d59cf3dc..503f5f4096 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartForward() + editor.moveStart() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js b/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js index 4629b685ad..ddc0f0d4fe 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartForward(8) + editor.moveStart({ distance: 8 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js b/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js index 9518282686..d1f7de4c4f 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartForward(7) + editor.moveStart({ distance: 7 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/param.js b/packages/slate/test/commands/on-selection/move-start-forward/param.js index 23242e92d0..bc1c3808b2 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/param.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/param.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartForward(3) + editor.moveStart({ distance: 3 }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-start-forward/reversed.js b/packages/slate/test/commands/on-selection/move-start-forward/reversed.js index 0af4ce3eb0..f499c23335 100644 --- a/packages/slate/test/commands/on-selection/move-start-forward/reversed.js +++ b/packages/slate/test/commands/on-selection/move-start-forward/reversed.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStartForward() + editor.moveStart() } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-block/end.js b/packages/slate/test/commands/on-selection/move-to-end-of-block/end.js deleted file mode 100644 index 6778f02137..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-block/end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - - two - - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js deleted file mode 100644 index b0823919e4..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-block/middle.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - - two - - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-block/start.js b/packages/slate/test/commands/on-selection/move-to-end-of-block/start.js deleted file mode 100644 index e62d5b77bc..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-block/start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - - two - - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js deleted file mode 100644 index ab43103095..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfDocument() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js deleted file mode 100644 index eec88b4b58..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-middle.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfDocument() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js deleted file mode 100644 index daeb3d1c23..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/block-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfDocument() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js deleted file mode 100644 index bb820a4c16..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfDocument() -} - -export const input = ( - - - one - two - - three - - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js deleted file mode 100644 index 779ea8e279..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-document/document-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfDocument() -} - -export const input = ( - - - - one - - two - three - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js deleted file mode 100644 index 6b8e9de346..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfNextBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js deleted file mode 100644 index 74d35fb928..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-middle.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfNextBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js deleted file mode 100644 index a78a9c0e59..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/block-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfNextBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js deleted file mode 100644 index f472520c0a..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfNextBlock() -} - -export const input = ( - - - one - two - - three - - - -) - -export const output = ( - - - one - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js deleted file mode 100644 index a97f6452b5..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-next-block/document-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfNextBlock() -} - -export const input = ( - - - - one - - two - three - - -) - -export const output = ( - - - one - - two - - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js deleted file mode 100644 index f7f95c0106..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfPreviousBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js deleted file mode 100644 index e73a82e0a0..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-middle.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfPreviousBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js deleted file mode 100644 index 29cf383de9..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/block-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfPreviousBlock() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js deleted file mode 100644 index b9fa5853de..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfPreviousBlock() -} - -export const input = ( - - - one - two - - three - - - -) - -export const output = ( - - - one - - two - - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js b/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js deleted file mode 100644 index 48d2e083f2..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end-of-previous-block/document-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEndOfPreviousBlock() -} - -export const input = ( - - - - one - - two - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end/basic.js b/packages/slate/test/commands/on-selection/move-to-end/basic.js deleted file mode 100644 index 3ac11d6319..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end/basic.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEnd() -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - one - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-end/void.js b/packages/slate/test/commands/on-selection/move-to-end/void.js deleted file mode 100644 index 29a512a097..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-end/void.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToEnd() -} - -export const input = ( - - - - - - - -) - -export const output = ( - - - - {' '} - - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-focus/basic.js b/packages/slate/test/commands/on-selection/move-to-focus/basic.js deleted file mode 100644 index 9e724a7d75..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-focus/basic.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToFocus() -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - one - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js b/packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js deleted file mode 100644 index 2cb5ec6281..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-range-of-document/basic.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToRangeOfDocument() -} - -export const input = ( - - - - one - - two - three - - -) - -export const output = ( - - - - one - - two - - three - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js deleted file mode 100644 index b74189b149..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStartOfDocument() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js deleted file mode 100644 index 94d7eb4ded..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-middle.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStartOfDocument() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js deleted file mode 100644 index 4b024a7865..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/block-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStartOfDocument() -} - -export const input = ( - - - one - - two - - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js deleted file mode 100644 index f67872d6b2..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-end.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStartOfDocument() -} - -export const input = ( - - - one - two - - three - - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js b/packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js deleted file mode 100644 index 6ca276c24f..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start-of-document/document-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStartOfDocument() -} - -export const input = ( - - - - one - - two - three - - -) - -export const output = ( - - - - one - - two - three - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js b/packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js deleted file mode 100644 index 9ae5c4ca05..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start/already-collapsed.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStart() -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - one - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start/basic.js b/packages/slate/test/commands/on-selection/move-to-start/basic.js deleted file mode 100644 index faf9e84d4a..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start/basic.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStart() -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - one - - - -) diff --git a/packages/slate/test/commands/on-selection/move-to-start/void.js b/packages/slate/test/commands/on-selection/move-to-start/void.js deleted file mode 100644 index 8e415a81b1..0000000000 --- a/packages/slate/test/commands/on-selection/move-to-start/void.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveToStart() -} - -export const input = ( - - - - - - - -) - -export const output = ( - - - - {' '} - - - -) From bb5ce9d217bfa6a8408841a6fad8cd9a803a365e Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 21 Oct 2019 16:18:14 -0400 Subject: [PATCH 042/165] convert on-selection commands --- .../move-word-backward/expanded.js | 27 ------------ .../move-word-backward/reversed.js | 27 ------------ .../move-word-forward/expanded.js | 28 ------------ .../move-word-forward/reversed.js | 28 ------------ .../reversed.js => move/backward-reverse.js} | 0 .../reversed.js => move/backward.js} | 0 .../default.js => move/basic-reverse.js} | 0 .../default.js => move/collapsed.js} | 0 .../param.js => move/distance-reverse.js} | 0 .../param.js => move/distance.js} | 0 .../expanded.js => move/expanded-reverse.js} | 0 .../{move-forward => move}/expanded.js | 0 .../unit-word-reverse.js} | 18 +++----- .../collapsed.js => move/unit-word.js} | 18 +++----- .../backward.js | 0 .../basic.js | 0 .../collapsed.js | 0 .../distance.js | 0 .../reverse-backward.js} | 0 .../basic.js => moveAnchor/reverse-basic.js} | 0 .../reverse-collapsed.js} | 0 .../reverse-distance.js} | 0 .../backward-reverse.js} | 0 .../reversed.js => moveEnd/backward.js} | 0 .../collapsed-reverse.js} | 0 .../collapsed.js} | 0 .../param.js => moveEnd/distance-reverse.js} | 0 .../param.js => moveEnd/distance.js} | 0 .../expanded-reverse.js} | 0 .../default.js => moveEnd/expanded.js} | 0 .../from-backward-reverse.js} | 0 .../to-backward-reverse.js} | 0 .../backward.js} | 0 .../collapsed-reverse.js} | 0 .../collapsed.js} | 0 .../distance-reverse.js} | 0 .../param.js => moveFocus/distance.js} | 0 .../expanded-reverse.js} | 0 .../default.js => moveFocus/expanded.js} | 0 .../to-backward-reverse.js} | 0 .../backward-reverse.js} | 0 .../reversed.js => moveStart/backward.js} | 0 .../collapsed-reverse.js} | 0 .../collapsed.js} | 0 .../distance-reverse.js} | 0 .../param.js => moveStart/distance.js} | 0 .../expanded-reverse.js} | 0 .../default.js => moveStart/expanded.js} | 0 .../from-backward.js} | 0 .../to-backward.js} | 0 .../select/{with-object.js => basic.js} | 23 +++------- .../on-selection/select/with-selection.js | 43 ------------------- 52 files changed, 21 insertions(+), 191 deletions(-) delete mode 100644 packages/slate/test/commands/on-selection/move-word-backward/expanded.js delete mode 100644 packages/slate/test/commands/on-selection/move-word-backward/reversed.js delete mode 100644 packages/slate/test/commands/on-selection/move-word-forward/expanded.js delete mode 100644 packages/slate/test/commands/on-selection/move-word-forward/reversed.js rename packages/slate/test/commands/on-selection/{move-backward/reversed.js => move/backward-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-forward/reversed.js => move/backward.js} (100%) rename packages/slate/test/commands/on-selection/{move-backward/default.js => move/basic-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-forward/default.js => move/collapsed.js} (100%) rename packages/slate/test/commands/on-selection/{move-backward/param.js => move/distance-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-forward/param.js => move/distance.js} (100%) rename packages/slate/test/commands/on-selection/{move-backward/expanded.js => move/expanded-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-forward => move}/expanded.js (100%) rename packages/slate/test/commands/on-selection/{move-word-forward/collapsed.js => move/unit-word-reverse.js} (51%) rename packages/slate/test/commands/on-selection/{move-word-backward/collapsed.js => move/unit-word.js} (51%) rename packages/slate/test/commands/on-selection/{move-anchor-forward => moveAnchor}/backward.js (100%) rename packages/slate/test/commands/on-selection/{move-anchor-forward => moveAnchor}/basic.js (100%) rename packages/slate/test/commands/on-selection/{move-anchor-forward => moveAnchor}/collapsed.js (100%) rename packages/slate/test/commands/on-selection/{move-anchor-forward => moveAnchor}/distance.js (100%) rename packages/slate/test/commands/on-selection/{move-anchor-backward/backward.js => moveAnchor/reverse-backward.js} (100%) rename packages/slate/test/commands/on-selection/{move-anchor-backward/basic.js => moveAnchor/reverse-basic.js} (100%) rename packages/slate/test/commands/on-selection/{move-anchor-backward/collapsed.js => moveAnchor/reverse-collapsed.js} (100%) rename packages/slate/test/commands/on-selection/{move-anchor-backward/distance.js => moveAnchor/reverse-distance.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-backward/reversed.js => moveEnd/backward-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-forward/reversed.js => moveEnd/backward.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-backward/from-collapsed.js => moveEnd/collapsed-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-forward/from-collapsed.js => moveEnd/collapsed.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-backward/param.js => moveEnd/distance-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-forward/param.js => moveEnd/distance.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-backward/default.js => moveEnd/expanded-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-forward/default.js => moveEnd/expanded.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-backward/out-of-reverse.js => moveEnd/from-backward-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-end-backward/into-reverse.js => moveEnd/to-backward-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-forward/out-of-reverse.js => moveFocus/backward.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-backward/from-collapsed.js => moveFocus/collapsed-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-forward/from-collapsed.js => moveFocus/collapsed.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-backward/param.js => moveFocus/distance-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-forward/param.js => moveFocus/distance.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-backward/default.js => moveFocus/expanded-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-forward/default.js => moveFocus/expanded.js} (100%) rename packages/slate/test/commands/on-selection/{move-focus-backward/into-reverse.js => moveFocus/to-backward-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-backward/reversed.js => moveStart/backward-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-forward/reversed.js => moveStart/backward.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-backward/from-collapsed.js => moveStart/collapsed-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-forward/from-collapsed.js => moveStart/collapsed.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-backward/param.js => moveStart/distance-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-forward/param.js => moveStart/distance.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-backward/default.js => moveStart/expanded-reverse.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-forward/default.js => moveStart/expanded.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-forward/out-of-reverse.js => moveStart/from-backward.js} (100%) rename packages/slate/test/commands/on-selection/{move-start-forward/into-reverse.js => moveStart/to-backward.js} (100%) rename packages/slate/test/commands/on-selection/select/{with-object.js => basic.js} (51%) delete mode 100644 packages/slate/test/commands/on-selection/select/with-selection.js diff --git a/packages/slate/test/commands/on-selection/move-word-backward/expanded.js b/packages/slate/test/commands/on-selection/move-word-backward/expanded.js deleted file mode 100644 index 8837570698..0000000000 --- a/packages/slate/test/commands/on-selection/move-word-backward/expanded.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveWordBackward() -} - -export const input = ( - - - - one two three four five six - - - -) - -export const output = ( - - - - one two three four five six - - - -) diff --git a/packages/slate/test/commands/on-selection/move-word-backward/reversed.js b/packages/slate/test/commands/on-selection/move-word-backward/reversed.js deleted file mode 100644 index 30218d775e..0000000000 --- a/packages/slate/test/commands/on-selection/move-word-backward/reversed.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveWordBackward() -} - -export const input = ( - - - - one two three four five six - - - -) - -export const output = ( - - - - one two three four five six - - - -) diff --git a/packages/slate/test/commands/on-selection/move-word-forward/expanded.js b/packages/slate/test/commands/on-selection/move-word-forward/expanded.js deleted file mode 100644 index 3ead686788..0000000000 --- a/packages/slate/test/commands/on-selection/move-word-forward/expanded.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveWordForward() -} - -export const input = ( - - - - one two three four five six - - - -) - -// Should move to next word after focus and collapse -export const output = ( - - - - one two three four five six - - - -) diff --git a/packages/slate/test/commands/on-selection/move-word-forward/reversed.js b/packages/slate/test/commands/on-selection/move-word-forward/reversed.js deleted file mode 100644 index ea0d70634a..0000000000 --- a/packages/slate/test/commands/on-selection/move-word-forward/reversed.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.moveWordForward() -} - -export const input = ( - - - - one two three four five six - - - -) - -// Should move to next word after focus and collapse -export const output = ( - - - - one two three four five six - - - -) diff --git a/packages/slate/test/commands/on-selection/move-backward/reversed.js b/packages/slate/test/commands/on-selection/move/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-backward/reversed.js rename to packages/slate/test/commands/on-selection/move/backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-forward/reversed.js b/packages/slate/test/commands/on-selection/move/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-forward/reversed.js rename to packages/slate/test/commands/on-selection/move/backward.js diff --git a/packages/slate/test/commands/on-selection/move-backward/default.js b/packages/slate/test/commands/on-selection/move/basic-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-backward/default.js rename to packages/slate/test/commands/on-selection/move/basic-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-forward/default.js b/packages/slate/test/commands/on-selection/move/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-forward/default.js rename to packages/slate/test/commands/on-selection/move/collapsed.js diff --git a/packages/slate/test/commands/on-selection/move-backward/param.js b/packages/slate/test/commands/on-selection/move/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-backward/param.js rename to packages/slate/test/commands/on-selection/move/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-forward/param.js b/packages/slate/test/commands/on-selection/move/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-forward/param.js rename to packages/slate/test/commands/on-selection/move/distance.js diff --git a/packages/slate/test/commands/on-selection/move-backward/expanded.js b/packages/slate/test/commands/on-selection/move/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-backward/expanded.js rename to packages/slate/test/commands/on-selection/move/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-forward/expanded.js b/packages/slate/test/commands/on-selection/move/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-forward/expanded.js rename to packages/slate/test/commands/on-selection/move/expanded.js diff --git a/packages/slate/test/commands/on-selection/move-word-forward/collapsed.js b/packages/slate/test/commands/on-selection/move/unit-word-reverse.js similarity index 51% rename from packages/slate/test/commands/on-selection/move-word-forward/collapsed.js rename to packages/slate/test/commands/on-selection/move/unit-word-reverse.js index 76526e4ee9..3df3ddb635 100644 --- a/packages/slate/test/commands/on-selection/move-word-forward/collapsed.js +++ b/packages/slate/test/commands/on-selection/move/unit-word-reverse.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveWordForward() + editor.move({ reverse: true, unit: 'word' }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-word-backward/collapsed.js b/packages/slate/test/commands/on-selection/move/unit-word.js similarity index 51% rename from packages/slate/test/commands/on-selection/move-word-backward/collapsed.js rename to packages/slate/test/commands/on-selection/move/unit-word.js index d258b3a020..5dec2fbcae 100644 --- a/packages/slate/test/commands/on-selection/move-word-backward/collapsed.js +++ b/packages/slate/test/commands/on-selection/move/unit-word.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveWordBackward() + editor.move({ unit: 'word' }) } export const input = ( - - - one two three - - + + one two three + ) export const output = ( - - - one two three - - + + one two three + ) diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/backward.js b/packages/slate/test/commands/on-selection/moveAnchor/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-forward/backward.js rename to packages/slate/test/commands/on-selection/moveAnchor/backward.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/basic.js b/packages/slate/test/commands/on-selection/moveAnchor/basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-forward/basic.js rename to packages/slate/test/commands/on-selection/moveAnchor/basic.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/collapsed.js b/packages/slate/test/commands/on-selection/moveAnchor/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-forward/collapsed.js rename to packages/slate/test/commands/on-selection/moveAnchor/collapsed.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-forward/distance.js b/packages/slate/test/commands/on-selection/moveAnchor/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-forward/distance.js rename to packages/slate/test/commands/on-selection/moveAnchor/distance.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/backward.js b/packages/slate/test/commands/on-selection/moveAnchor/reverse-backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-backward/backward.js rename to packages/slate/test/commands/on-selection/moveAnchor/reverse-backward.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/basic.js b/packages/slate/test/commands/on-selection/moveAnchor/reverse-basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-backward/basic.js rename to packages/slate/test/commands/on-selection/moveAnchor/reverse-basic.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/collapsed.js b/packages/slate/test/commands/on-selection/moveAnchor/reverse-collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-backward/collapsed.js rename to packages/slate/test/commands/on-selection/moveAnchor/reverse-collapsed.js diff --git a/packages/slate/test/commands/on-selection/move-anchor-backward/distance.js b/packages/slate/test/commands/on-selection/moveAnchor/reverse-distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-anchor-backward/distance.js rename to packages/slate/test/commands/on-selection/moveAnchor/reverse-distance.js diff --git a/packages/slate/test/commands/on-selection/move-end-backward/reversed.js b/packages/slate/test/commands/on-selection/moveEnd/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-backward/reversed.js rename to packages/slate/test/commands/on-selection/moveEnd/backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-end-forward/reversed.js b/packages/slate/test/commands/on-selection/moveEnd/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-forward/reversed.js rename to packages/slate/test/commands/on-selection/moveEnd/backward.js diff --git a/packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/moveEnd/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-backward/from-collapsed.js rename to packages/slate/test/commands/on-selection/moveEnd/collapsed-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/moveEnd/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-forward/from-collapsed.js rename to packages/slate/test/commands/on-selection/moveEnd/collapsed.js diff --git a/packages/slate/test/commands/on-selection/move-end-backward/param.js b/packages/slate/test/commands/on-selection/moveEnd/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-backward/param.js rename to packages/slate/test/commands/on-selection/moveEnd/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-end-forward/param.js b/packages/slate/test/commands/on-selection/moveEnd/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-forward/param.js rename to packages/slate/test/commands/on-selection/moveEnd/distance.js diff --git a/packages/slate/test/commands/on-selection/move-end-backward/default.js b/packages/slate/test/commands/on-selection/moveEnd/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-backward/default.js rename to packages/slate/test/commands/on-selection/moveEnd/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-end-forward/default.js b/packages/slate/test/commands/on-selection/moveEnd/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-forward/default.js rename to packages/slate/test/commands/on-selection/moveEnd/expanded.js diff --git a/packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js b/packages/slate/test/commands/on-selection/moveEnd/from-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-backward/out-of-reverse.js rename to packages/slate/test/commands/on-selection/moveEnd/from-backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js b/packages/slate/test/commands/on-selection/moveEnd/to-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-end-backward/into-reverse.js rename to packages/slate/test/commands/on-selection/moveEnd/to-backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js b/packages/slate/test/commands/on-selection/moveFocus/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-forward/out-of-reverse.js rename to packages/slate/test/commands/on-selection/moveFocus/backward.js diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/moveFocus/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-backward/from-collapsed.js rename to packages/slate/test/commands/on-selection/moveFocus/collapsed-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/moveFocus/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-forward/from-collapsed.js rename to packages/slate/test/commands/on-selection/moveFocus/collapsed.js diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/param.js b/packages/slate/test/commands/on-selection/moveFocus/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-backward/param.js rename to packages/slate/test/commands/on-selection/moveFocus/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/param.js b/packages/slate/test/commands/on-selection/moveFocus/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-forward/param.js rename to packages/slate/test/commands/on-selection/moveFocus/distance.js diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/default.js b/packages/slate/test/commands/on-selection/moveFocus/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-backward/default.js rename to packages/slate/test/commands/on-selection/moveFocus/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-focus-forward/default.js b/packages/slate/test/commands/on-selection/moveFocus/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-forward/default.js rename to packages/slate/test/commands/on-selection/moveFocus/expanded.js diff --git a/packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js b/packages/slate/test/commands/on-selection/moveFocus/to-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-focus-backward/into-reverse.js rename to packages/slate/test/commands/on-selection/moveFocus/to-backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-start-backward/reversed.js b/packages/slate/test/commands/on-selection/moveStart/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-backward/reversed.js rename to packages/slate/test/commands/on-selection/moveStart/backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-start-forward/reversed.js b/packages/slate/test/commands/on-selection/moveStart/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-forward/reversed.js rename to packages/slate/test/commands/on-selection/moveStart/backward.js diff --git a/packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js b/packages/slate/test/commands/on-selection/moveStart/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-backward/from-collapsed.js rename to packages/slate/test/commands/on-selection/moveStart/collapsed-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js b/packages/slate/test/commands/on-selection/moveStart/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-forward/from-collapsed.js rename to packages/slate/test/commands/on-selection/moveStart/collapsed.js diff --git a/packages/slate/test/commands/on-selection/move-start-backward/param.js b/packages/slate/test/commands/on-selection/moveStart/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-backward/param.js rename to packages/slate/test/commands/on-selection/moveStart/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-start-forward/param.js b/packages/slate/test/commands/on-selection/moveStart/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-forward/param.js rename to packages/slate/test/commands/on-selection/moveStart/distance.js diff --git a/packages/slate/test/commands/on-selection/move-start-backward/default.js b/packages/slate/test/commands/on-selection/moveStart/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-backward/default.js rename to packages/slate/test/commands/on-selection/moveStart/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/move-start-forward/default.js b/packages/slate/test/commands/on-selection/moveStart/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-forward/default.js rename to packages/slate/test/commands/on-selection/moveStart/expanded.js diff --git a/packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js b/packages/slate/test/commands/on-selection/moveStart/from-backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-forward/out-of-reverse.js rename to packages/slate/test/commands/on-selection/moveStart/from-backward.js diff --git a/packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js b/packages/slate/test/commands/on-selection/moveStart/to-backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move-start-forward/into-reverse.js rename to packages/slate/test/commands/on-selection/moveStart/to-backward.js diff --git a/packages/slate/test/commands/on-selection/select/with-object.js b/packages/slate/test/commands/on-selection/select/basic.js similarity index 51% rename from packages/slate/test/commands/on-selection/select/with-object.js rename to packages/slate/test/commands/on-selection/select/basic.js index e2b0a6ef9a..1a39b532f3 100644 --- a/packages/slate/test/commands/on-selection/select/with-object.js +++ b/packages/slate/test/commands/on-selection/select/basic.js @@ -3,39 +3,30 @@ import { h } from '../../../helpers' export const run = editor => { - const { value: { document } } = editor - const [[node]] = document.texts() - editor.select({ anchor: { path: [0, 0], - key: node.key, offset: 0, }, focus: { path: [0, 0], - key: node.key, - offset: node.text.length, + offset: 3, }, }) } export const input = ( - - - one - - + + one + ) export const output = ( - - - one - - + + one + ) diff --git a/packages/slate/test/commands/on-selection/select/with-selection.js b/packages/slate/test/commands/on-selection/select/with-selection.js deleted file mode 100644 index 1bee4fe3ae..0000000000 --- a/packages/slate/test/commands/on-selection/select/with-selection.js +++ /dev/null @@ -1,43 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - const { value: { document, selection } } = editor - const [[node]] = document.texts() - - const next = selection.setProperties({ - anchor: { - path: [0, 0], - key: node.key, - offset: 0, - }, - focus: { - path: [0, 0], - key: node.key, - offset: node.text.length, - }, - }) - - editor.select(next) -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - one - - - -) From 4a6864d112d55fd8893e0e735e76b2bc57e20510 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 21 Oct 2019 16:18:26 -0400 Subject: [PATCH 043/165] rename --- .../slate/test/commands/{on-selection => selection}/blur/basic.js | 0 .../test/commands/{on-selection => selection}/deselect/basic.js | 0 .../commands/{on-selection => selection}/deselect/unfocused.js | 0 .../test/commands/{on-selection => selection}/focus/basic.js | 0 .../commands/{on-selection => selection}/move/backward-reverse.js | 0 .../test/commands/{on-selection => selection}/move/backward.js | 0 .../commands/{on-selection => selection}/move/basic-reverse.js | 0 .../test/commands/{on-selection => selection}/move/collapsed.js | 0 .../commands/{on-selection => selection}/move/distance-reverse.js | 0 .../test/commands/{on-selection => selection}/move/distance.js | 0 .../commands/{on-selection => selection}/move/expanded-reverse.js | 0 .../test/commands/{on-selection => selection}/move/expanded.js | 0 .../{on-selection => selection}/move/unit-word-reverse.js | 0 .../test/commands/{on-selection => selection}/move/unit-word.js | 0 .../commands/{on-selection => selection}/moveAnchor/backward.js | 0 .../test/commands/{on-selection => selection}/moveAnchor/basic.js | 0 .../commands/{on-selection => selection}/moveAnchor/collapsed.js | 0 .../commands/{on-selection => selection}/moveAnchor/distance.js | 0 .../{on-selection => selection}/moveAnchor/reverse-backward.js | 0 .../{on-selection => selection}/moveAnchor/reverse-basic.js | 0 .../{on-selection => selection}/moveAnchor/reverse-collapsed.js | 0 .../{on-selection => selection}/moveAnchor/reverse-distance.js | 0 .../{on-selection => selection}/moveEnd/backward-reverse.js | 0 .../test/commands/{on-selection => selection}/moveEnd/backward.js | 0 .../{on-selection => selection}/moveEnd/collapsed-reverse.js | 0 .../commands/{on-selection => selection}/moveEnd/collapsed.js | 0 .../{on-selection => selection}/moveEnd/distance-reverse.js | 0 .../test/commands/{on-selection => selection}/moveEnd/distance.js | 0 .../{on-selection => selection}/moveEnd/expanded-reverse.js | 0 .../test/commands/{on-selection => selection}/moveEnd/expanded.js | 0 .../{on-selection => selection}/moveEnd/from-backward-reverse.js | 0 .../{on-selection => selection}/moveEnd/to-backward-reverse.js | 0 .../commands/{on-selection => selection}/moveFocus/backward.js | 0 .../{on-selection => selection}/moveFocus/collapsed-reverse.js | 0 .../commands/{on-selection => selection}/moveFocus/collapsed.js | 0 .../{on-selection => selection}/moveFocus/distance-reverse.js | 0 .../commands/{on-selection => selection}/moveFocus/distance.js | 0 .../{on-selection => selection}/moveFocus/expanded-reverse.js | 0 .../commands/{on-selection => selection}/moveFocus/expanded.js | 0 .../{on-selection => selection}/moveFocus/to-backward-reverse.js | 0 .../{on-selection => selection}/moveStart/backward-reverse.js | 0 .../commands/{on-selection => selection}/moveStart/backward.js | 0 .../{on-selection => selection}/moveStart/collapsed-reverse.js | 0 .../commands/{on-selection => selection}/moveStart/collapsed.js | 0 .../{on-selection => selection}/moveStart/distance-reverse.js | 0 .../commands/{on-selection => selection}/moveStart/distance.js | 0 .../{on-selection => selection}/moveStart/expanded-reverse.js | 0 .../commands/{on-selection => selection}/moveStart/expanded.js | 0 .../{on-selection => selection}/moveStart/from-backward.js | 0 .../commands/{on-selection => selection}/moveStart/to-backward.js | 0 .../test/commands/{on-selection => selection}/select/basic.js | 0 51 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/commands/{on-selection => selection}/blur/basic.js (100%) rename packages/slate/test/commands/{on-selection => selection}/deselect/basic.js (100%) rename packages/slate/test/commands/{on-selection => selection}/deselect/unfocused.js (100%) rename packages/slate/test/commands/{on-selection => selection}/focus/basic.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/backward-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/basic-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/collapsed.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/distance-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/distance.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/expanded-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/expanded.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/unit-word-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/move/unit-word.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/basic.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/collapsed.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/distance.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/reverse-backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/reverse-basic.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/reverse-collapsed.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveAnchor/reverse-distance.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/backward-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/collapsed-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/collapsed.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/distance-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/distance.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/expanded-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/expanded.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/from-backward-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveEnd/to-backward-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/collapsed-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/collapsed.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/distance-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/distance.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/expanded-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/expanded.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveFocus/to-backward-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/backward-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/collapsed-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/collapsed.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/distance-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/distance.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/expanded-reverse.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/expanded.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/from-backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/moveStart/to-backward.js (100%) rename packages/slate/test/commands/{on-selection => selection}/select/basic.js (100%) diff --git a/packages/slate/test/commands/on-selection/blur/basic.js b/packages/slate/test/commands/selection/blur/basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/blur/basic.js rename to packages/slate/test/commands/selection/blur/basic.js diff --git a/packages/slate/test/commands/on-selection/deselect/basic.js b/packages/slate/test/commands/selection/deselect/basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/deselect/basic.js rename to packages/slate/test/commands/selection/deselect/basic.js diff --git a/packages/slate/test/commands/on-selection/deselect/unfocused.js b/packages/slate/test/commands/selection/deselect/unfocused.js similarity index 100% rename from packages/slate/test/commands/on-selection/deselect/unfocused.js rename to packages/slate/test/commands/selection/deselect/unfocused.js diff --git a/packages/slate/test/commands/on-selection/focus/basic.js b/packages/slate/test/commands/selection/focus/basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/focus/basic.js rename to packages/slate/test/commands/selection/focus/basic.js diff --git a/packages/slate/test/commands/on-selection/move/backward-reverse.js b/packages/slate/test/commands/selection/move/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/backward-reverse.js rename to packages/slate/test/commands/selection/move/backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/move/backward.js b/packages/slate/test/commands/selection/move/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/backward.js rename to packages/slate/test/commands/selection/move/backward.js diff --git a/packages/slate/test/commands/on-selection/move/basic-reverse.js b/packages/slate/test/commands/selection/move/basic-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/basic-reverse.js rename to packages/slate/test/commands/selection/move/basic-reverse.js diff --git a/packages/slate/test/commands/on-selection/move/collapsed.js b/packages/slate/test/commands/selection/move/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/collapsed.js rename to packages/slate/test/commands/selection/move/collapsed.js diff --git a/packages/slate/test/commands/on-selection/move/distance-reverse.js b/packages/slate/test/commands/selection/move/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/distance-reverse.js rename to packages/slate/test/commands/selection/move/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/move/distance.js b/packages/slate/test/commands/selection/move/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/distance.js rename to packages/slate/test/commands/selection/move/distance.js diff --git a/packages/slate/test/commands/on-selection/move/expanded-reverse.js b/packages/slate/test/commands/selection/move/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/expanded-reverse.js rename to packages/slate/test/commands/selection/move/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/move/expanded.js b/packages/slate/test/commands/selection/move/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/expanded.js rename to packages/slate/test/commands/selection/move/expanded.js diff --git a/packages/slate/test/commands/on-selection/move/unit-word-reverse.js b/packages/slate/test/commands/selection/move/unit-word-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/unit-word-reverse.js rename to packages/slate/test/commands/selection/move/unit-word-reverse.js diff --git a/packages/slate/test/commands/on-selection/move/unit-word.js b/packages/slate/test/commands/selection/move/unit-word.js similarity index 100% rename from packages/slate/test/commands/on-selection/move/unit-word.js rename to packages/slate/test/commands/selection/move/unit-word.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/backward.js b/packages/slate/test/commands/selection/moveAnchor/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/backward.js rename to packages/slate/test/commands/selection/moveAnchor/backward.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/basic.js b/packages/slate/test/commands/selection/moveAnchor/basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/basic.js rename to packages/slate/test/commands/selection/moveAnchor/basic.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/collapsed.js b/packages/slate/test/commands/selection/moveAnchor/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/collapsed.js rename to packages/slate/test/commands/selection/moveAnchor/collapsed.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/distance.js b/packages/slate/test/commands/selection/moveAnchor/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/distance.js rename to packages/slate/test/commands/selection/moveAnchor/distance.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/reverse-backward.js b/packages/slate/test/commands/selection/moveAnchor/reverse-backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/reverse-backward.js rename to packages/slate/test/commands/selection/moveAnchor/reverse-backward.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/reverse-basic.js b/packages/slate/test/commands/selection/moveAnchor/reverse-basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/reverse-basic.js rename to packages/slate/test/commands/selection/moveAnchor/reverse-basic.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/reverse-collapsed.js b/packages/slate/test/commands/selection/moveAnchor/reverse-collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/reverse-collapsed.js rename to packages/slate/test/commands/selection/moveAnchor/reverse-collapsed.js diff --git a/packages/slate/test/commands/on-selection/moveAnchor/reverse-distance.js b/packages/slate/test/commands/selection/moveAnchor/reverse-distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveAnchor/reverse-distance.js rename to packages/slate/test/commands/selection/moveAnchor/reverse-distance.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/backward-reverse.js b/packages/slate/test/commands/selection/moveEnd/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/backward-reverse.js rename to packages/slate/test/commands/selection/moveEnd/backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/backward.js b/packages/slate/test/commands/selection/moveEnd/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/backward.js rename to packages/slate/test/commands/selection/moveEnd/backward.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/collapsed-reverse.js b/packages/slate/test/commands/selection/moveEnd/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/collapsed-reverse.js rename to packages/slate/test/commands/selection/moveEnd/collapsed-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/collapsed.js b/packages/slate/test/commands/selection/moveEnd/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/collapsed.js rename to packages/slate/test/commands/selection/moveEnd/collapsed.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/distance-reverse.js b/packages/slate/test/commands/selection/moveEnd/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/distance-reverse.js rename to packages/slate/test/commands/selection/moveEnd/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/distance.js b/packages/slate/test/commands/selection/moveEnd/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/distance.js rename to packages/slate/test/commands/selection/moveEnd/distance.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/expanded-reverse.js b/packages/slate/test/commands/selection/moveEnd/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/expanded-reverse.js rename to packages/slate/test/commands/selection/moveEnd/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/expanded.js b/packages/slate/test/commands/selection/moveEnd/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/expanded.js rename to packages/slate/test/commands/selection/moveEnd/expanded.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/from-backward-reverse.js b/packages/slate/test/commands/selection/moveEnd/from-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/from-backward-reverse.js rename to packages/slate/test/commands/selection/moveEnd/from-backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveEnd/to-backward-reverse.js b/packages/slate/test/commands/selection/moveEnd/to-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveEnd/to-backward-reverse.js rename to packages/slate/test/commands/selection/moveEnd/to-backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/backward.js b/packages/slate/test/commands/selection/moveFocus/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/backward.js rename to packages/slate/test/commands/selection/moveFocus/backward.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/collapsed-reverse.js b/packages/slate/test/commands/selection/moveFocus/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/collapsed-reverse.js rename to packages/slate/test/commands/selection/moveFocus/collapsed-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/collapsed.js b/packages/slate/test/commands/selection/moveFocus/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/collapsed.js rename to packages/slate/test/commands/selection/moveFocus/collapsed.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/distance-reverse.js b/packages/slate/test/commands/selection/moveFocus/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/distance-reverse.js rename to packages/slate/test/commands/selection/moveFocus/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/distance.js b/packages/slate/test/commands/selection/moveFocus/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/distance.js rename to packages/slate/test/commands/selection/moveFocus/distance.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/expanded-reverse.js b/packages/slate/test/commands/selection/moveFocus/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/expanded-reverse.js rename to packages/slate/test/commands/selection/moveFocus/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/expanded.js b/packages/slate/test/commands/selection/moveFocus/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/expanded.js rename to packages/slate/test/commands/selection/moveFocus/expanded.js diff --git a/packages/slate/test/commands/on-selection/moveFocus/to-backward-reverse.js b/packages/slate/test/commands/selection/moveFocus/to-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveFocus/to-backward-reverse.js rename to packages/slate/test/commands/selection/moveFocus/to-backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveStart/backward-reverse.js b/packages/slate/test/commands/selection/moveStart/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/backward-reverse.js rename to packages/slate/test/commands/selection/moveStart/backward-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveStart/backward.js b/packages/slate/test/commands/selection/moveStart/backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/backward.js rename to packages/slate/test/commands/selection/moveStart/backward.js diff --git a/packages/slate/test/commands/on-selection/moveStart/collapsed-reverse.js b/packages/slate/test/commands/selection/moveStart/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/collapsed-reverse.js rename to packages/slate/test/commands/selection/moveStart/collapsed-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveStart/collapsed.js b/packages/slate/test/commands/selection/moveStart/collapsed.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/collapsed.js rename to packages/slate/test/commands/selection/moveStart/collapsed.js diff --git a/packages/slate/test/commands/on-selection/moveStart/distance-reverse.js b/packages/slate/test/commands/selection/moveStart/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/distance-reverse.js rename to packages/slate/test/commands/selection/moveStart/distance-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveStart/distance.js b/packages/slate/test/commands/selection/moveStart/distance.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/distance.js rename to packages/slate/test/commands/selection/moveStart/distance.js diff --git a/packages/slate/test/commands/on-selection/moveStart/expanded-reverse.js b/packages/slate/test/commands/selection/moveStart/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/expanded-reverse.js rename to packages/slate/test/commands/selection/moveStart/expanded-reverse.js diff --git a/packages/slate/test/commands/on-selection/moveStart/expanded.js b/packages/slate/test/commands/selection/moveStart/expanded.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/expanded.js rename to packages/slate/test/commands/selection/moveStart/expanded.js diff --git a/packages/slate/test/commands/on-selection/moveStart/from-backward.js b/packages/slate/test/commands/selection/moveStart/from-backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/from-backward.js rename to packages/slate/test/commands/selection/moveStart/from-backward.js diff --git a/packages/slate/test/commands/on-selection/moveStart/to-backward.js b/packages/slate/test/commands/selection/moveStart/to-backward.js similarity index 100% rename from packages/slate/test/commands/on-selection/moveStart/to-backward.js rename to packages/slate/test/commands/selection/moveStart/to-backward.js diff --git a/packages/slate/test/commands/on-selection/select/basic.js b/packages/slate/test/commands/selection/select/basic.js similarity index 100% rename from packages/slate/test/commands/on-selection/select/basic.js rename to packages/slate/test/commands/selection/select/basic.js From 93cced019ff1cc1bce2ef15aa147ff9a6e65cb4b Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 10:54:30 -0400 Subject: [PATCH 044/165] get addMarks and delete commands working --- packages/slate-hyperscript/src/creators.ts | 13 +- packages/slate/src/classes/commands/path.ts | 220 +++++++++++------- packages/slate/src/classes/commands/point.ts | 35 ++- packages/slate/src/classes/commands/range.ts | 138 ++++++++--- .../slate/src/classes/commands/selection.ts | 59 +++-- packages/slate/src/classes/commands/value.ts | 86 +++---- packages/slate/src/classes/path-ref.ts | 4 +- packages/slate/src/classes/point-ref.ts | 4 +- packages/slate/src/classes/queries/range.ts | 12 +- packages/slate/src/classes/range-ref.ts | 4 +- packages/slate/src/index.ts | 1 - packages/slate/src/interfaces/operation.ts | 14 +- packages/slate/src/interfaces/point.ts | 5 +- packages/slate/src/interfaces/selection.ts | 38 --- packages/slate/src/interfaces/value.ts | 37 ++- packages/slate/src/plugins/history/plugin.ts | 19 +- .../commands/value/add-mark/across-blocks.js | 38 ++- .../commands/value/add-mark/across-inlines.js | 70 +++--- .../value/add-mark/collapsed-selection-end.js | 30 --- .../add-mark/collapsed-selection-middle.js | 29 --- .../add-mark/collapsed-selection-start.js | 29 --- .../existing-marks-across-blocks-at-edge.js | 52 ++--- .../add-mark/existing-marks-across-blocks.js | 58 +++-- .../commands/value/add-mark/existing-marks.js | 36 ++- .../value/add-mark/first-character.js | 24 +- .../commands/value/add-mark/last-character.js | 24 +- .../value/add-mark/middle-character.js | 26 +-- .../commands/value/add-mark/whole-word.js | 22 +- .../value/add-mark/with-mark-object.js | 37 --- .../value/add-mark/with-plain-object.js | 33 --- .../commands/value/add-marks/across-blocks.js | 41 ---- .../value/add-marks/across-inlines.js | 57 ----- .../commands/value/add-marks/across-marks.js | 47 ---- .../add-marks/collapsed-selection-end.js | 33 --- .../add-marks/collapsed-selection-middle.js | 31 --- .../add-marks/collapsed-selection-start.js | 31 --- .../value/add-marks/first-character.js | 32 --- .../commands/value/add-marks/inside-mark.js | 38 --- .../value/add-marks/last-character.js | 32 --- .../value/add-marks/middle-character.js | 33 --- .../commands/value/add-marks/whole-word.js | 31 --- .../value/add-marks/with-mark-object.js | 43 ---- .../value/add-marks/with-plain-object.js | 42 ---- .../delete-backward/empty-after-void-block.js | 20 +- .../join-nested-blocks-different-depth.js | 24 +- .../delete-backward/single-void-block.js | 4 +- .../delete-forward/empty-before-void-block.js | 20 +- .../value/delete-forward/single-void-block.js | 4 +- .../commands/value/delete/across-blocks.js | 22 +- .../commands/value/delete/across-depths.js | 22 +- .../value/delete/across-texts-and-inlines.js | 16 +- .../value/delete/all-nested-blocks.js | 24 +- .../value/delete/before-inline-sibling.js | 24 +- .../delete/expanded-across-whole-mark.js | 28 +-- .../commands/value/delete/first-character.js | 16 +- .../commands/value/delete/first-position.js | 18 +- .../hanging-selection-multiple-blocks.js | 24 +- .../value/delete/inside-inline-sibling.js | 4 +- .../commands/value/delete/inside-inline.js | 28 +-- .../value/delete/join-blocks-with-inlines.js | 22 +- ...-first-with-void-siblings-only-non-void.js | 26 +-- ...tially-non-void-and-up-to-start-of-void.js | 4 +- ...id-siblings-partially-non-void-and-void.js | 4 +- ...t-with-void-siblings-partially-non-void.js | 28 +-- ...ock-as-first-with-non-void-siblings-all.js | 24 +- ...on-void-siblings-backward-selection-all.js | 4 +- ...-first-with-non-void-siblings-only-void.js | 4 +- ...void-siblings-select-void-and-next-word.js | 22 +- ...-siblings-select-void-end-and-next-word.js | 4 +- .../value/delete/void-block-as-only.js | 13 +- ...-with-non-void-siblings-only-first-void.js | 28 +-- ...first-with-non-void-siblings-only-voids.js | 30 ++- ...nline-as-first-with-non-void-block-next.js | 2 + ...d-inline-as-first-with-non-void-sibling.js | 2 + ...as-last-with-non-void-previous-siblings.js | 2 + .../commands/value/delete/whole-inline.js | 7 +- .../commands/value/delete/whole-word-mark.js | 8 +- .../value/insert-block/is-void-end.js | 6 +- .../value/insert-block/is-void-start.js | 6 +- .../fragment-multiple-marks.js | 40 ++-- .../fragment-single-child-block.js | 38 +-- .../insert-fragment/fragment-single-inline.js | 40 ++-- .../insert-fragment/fragment-single-mark.js | 42 ++-- .../insert-fragment/inlines/middle-block.js | 40 ++-- .../insert-fragment/lists/merge-lists.js | 46 ++-- .../insert-fragment/marks/middle-block.js | 42 ++-- .../marks/multiple-marks-middle-block.js | 40 ++-- .../insert-fragment/merge-deep-nested.js | 62 ++--- .../value/insert-fragment/merge-lists.js | 46 ++-- .../end-block-nested.js | 46 ++-- .../start-block.js | 40 ++-- .../tables/merge-cells-with-nested-blocks.js | 64 ++--- .../tables/merge-into-empty-cells.js | 70 +++--- .../tables/merge-into-full-cells.js | 72 +++--- .../commands/value/insert-inline/is-void.js | 8 +- .../commands/value/insert-text/after-mark.js | 8 +- .../commands/value/insert-text/before-mark.js | 4 +- .../blocks-with-overlapping-marks.js | 44 ++-- .../commands/value/insert-text/during-mark.js | 8 +- .../insert-text/empty-block-with-mark.js | 8 +- .../value/insert-text/expanded-with-mark.js | 4 +- .../commands/value/insert-text/inside-void.js | 8 +- .../commands/value/insert-text/with-marks.js | 2 +- .../value/remove-mark/across-blocks.js | 4 +- .../value/remove-mark/across-inlines.js | 4 +- .../value/remove-mark/collapsed-selection.js | 18 +- .../value/remove-mark/existing-marks.js | 32 ++- .../value/remove-mark/first-character.js | 2 +- .../value/remove-mark/last-character.js | 4 +- .../value/remove-mark/middle-character.js | 4 +- .../remove-mark/part-of-mark-backward.js | 6 +- .../value/remove-mark/part-of-mark.js | 6 +- .../commands/value/remove-mark/whole-word.js | 2 +- .../value/remove-mark/with-mark-object.js | 2 +- .../value/remove-mark/with-plain-object.js | 2 +- .../value/replace-mark/across-blocks.js | 44 ++-- .../value/replace-mark/across-inlines.js | 76 +++--- .../value/replace-mark/existing-marks.js | 28 +-- .../value/replace-mark/first-character.js | 24 +- .../value/replace-mark/last-character.js | 28 +-- .../value/replace-mark/middle-character.js | 32 ++- .../commands/value/replace-mark/whole-word.js | 24 +- .../value/replace-mark/with-mark-object.js | 6 +- .../value/replace-mark/with-plain-object.js | 6 +- .../commands/value/set-block/across-blocks.js | 28 +-- .../value/set-block/across-inlines.js | 8 +- .../hanging-selection-across-inlines.js | 4 +- .../value/set-block/hanging-selection.js | 26 +-- .../commands/value/set-block/nested-block.js | 22 +- .../single-block-string-shorthand.js | 18 +- .../commands/value/set-block/single-block.js | 18 +- .../value/set-block/with-data-as-map.js | 18 +- .../value/set-block/with-data-as-object.js | 18 +- .../commands/value/set-block/with-is-void.js | 4 +- .../value/set-inline/nested-inline.js | 22 +- .../commands/value/split-block/with-marks.js | 34 ++- .../commands/value/split-inline/with-marks.js | 10 +- .../value/toggle-mark/add-across-blocks.js | 6 +- .../value/toggle-mark/add-across-inlines.js | 10 +- .../add-collapsed-selection-start.js | 2 +- .../toggle-mark/add-collapsed-selection.js | 4 +- .../add-existing-marks-partially-marked.js | 42 ++-- .../value/toggle-mark/add-existing-marks.js | 34 ++- .../value/toggle-mark/add-first-character.js | 4 +- .../value/toggle-mark/add-last-character.js | 4 +- .../value/toggle-mark/add-middle-character.js | 4 +- .../value/toggle-mark/add-partially-marked.js | 8 +- .../value/toggle-mark/add-whole-word.js | 4 +- .../value/toggle-mark/add-with-mark-object.js | 2 +- .../toggle-mark/add-with-plain-object.js | 2 +- .../value/toggle-mark/remove-across-blocks.js | 6 +- .../toggle-mark/remove-across-inlines.js | 6 +- .../toggle-mark/remove-existing-marks.js | 34 ++- .../toggle-mark/remove-first-character.js | 4 +- .../toggle-mark/remove-last-character.js | 4 +- .../toggle-mark/remove-middle-character.js | 4 +- .../value/toggle-mark/remove-whole-word.js | 4 +- .../toggle-mark/remove-with-mark-object.js | 2 +- .../toggle-mark/remove-with-plain-object.js | 2 +- .../wrap-inline/inline-middle-with-marks.js | 14 +- .../history/undo/add-mark-across-blocks.js | 12 +- .../history/undo/add-mark-across-marks.js | 12 +- .../history/undo/add-mark-across-same-mark.js | 12 +- packages/slate/test/history/undo/add-mark.js | 8 +- .../test/history/undo/delete-across-blocks.js | 6 +- .../history/undo/delete-across-inlines.js | 14 +- .../test/history/undo/delete-across-marks.js | 14 +- .../undo/delete-backward-nested-blocks.js | 22 +- .../test/history/undo/delete-backward.js | 14 +- packages/slate/test/history/undo/delete.js | 6 +- .../slate/test/history/undo/insert-block.js | 6 +- .../test/history/undo/insert-fragment.js | 18 +- .../history/undo/insert-text-contiguous.js | 6 +- .../undo/insert-text-not-contiguous.js | 10 +- .../slate/test/history/undo/insert-text.js | 6 +- .../history/undo/move-node-affecting-path.js | 12 +- .../history/undo/move-node-before-itself.js | 20 +- ...move-node-by-path-ancestor-left-sibling.js | 12 +- .../test/history/undo/move-node-by-path.js | 14 +- .../slate/test/history/undo/remove-mark.js | 10 +- .../test/history/undo/remove-node-by-path.js | 4 +- .../slate/test/history/undo/remove-text.js | 10 +- .../undo/set-node-by-path-with-data.js | 4 +- .../history/undo/split-node-by-path-block.js | 8 +- .../slate/test/history/undo/toggle-mark.js | 16 +- .../test/history/undo/unwrap-node-by-path.js | 10 +- .../history/undo/wrap-inline-across-blocks.js | 10 +- .../Selection/isSelection/boolean.js | 9 - .../Selection/isSelection/custom-property.js | 21 -- .../Selection/isSelection/is-focused-false.js | 20 -- .../Selection/isSelection/marks-empty.js | 20 -- .../Selection/isSelection/marks-full.js | 20 -- .../Selection/isSelection/object.js | 9 - .../Selection/isSelection/selection.js | 20 -- .../Selection/isSelection/without-anchor.js | 16 -- .../Selection/isSelection/without-focus.js | 16 -- .../isSelection/without-isFocused.js | 19 -- .../Selection/isSelection/without-marks.js | 19 -- ...hild-kind-invalid-custom-optional-first.js | 2 +- .../custom/child-kind-invalid-custom.js | 2 +- .../custom/child-kind-invalid-default.js | 2 +- .../custom/child-kind-invalid-function.js | 2 +- .../child-max-invalid-at-end-default.js | 12 +- .../schema/custom/child-max-invalid-custom.js | 8 +- .../custom/child-max-invalid-default.js | 8 +- .../custom/child-min-invalid-at-end-custom.js | 12 +- .../schema/custom/child-min-invalid-custom.js | 8 +- .../custom/child-min-invalid-default.js | 4 +- .../child-min-invalid-with-invalid-default.js | 16 +- .../custom/child-min-max-invalid-default.js | 8 +- .../custom/child-min-max-invalid-valid.js | 4 +- .../custom/child-type-invalid-custom.js | 12 +- .../custom/child-type-invalid-default.js | 4 +- .../custom/child-type-invalid-function.js | 4 +- .../schema/custom/child-unknown-custom.js | 4 +- .../schema/custom/child-unknown-default.js | 4 +- .../custom/first-child-kind-invalid-custom.js | 2 +- .../first-child-kind-invalid-default.js | 4 +- .../first-child-kind-invalid-function.js | 4 +- .../custom/first-child-type-invalid-custom.js | 28 +-- .../first-child-type-invalid-default.js | 20 +- .../first-child-type-invalid-function.js | 20 +- .../custom/last-child-kind-invalid-custom.js | 2 +- .../custom/last-child-kind-invalid-default.js | 4 +- .../last-child-kind-invalid-function.js | 4 +- .../custom/last-child-type-invalid-custom.js | 28 +-- .../custom/last-child-type-invalid-default.js | 20 +- .../last-child-type-invalid-function.js | 20 +- .../slate/test/schema/custom/match-data.js | 2 +- .../slate/test/schema/custom/match-object.js | 4 +- .../slate/test/schema/custom/match-type.js | 2 +- .../schema/custom/next-kind-invalid-custom.js | 16 +- .../custom/next-kind-invalid-default.js | 16 +- .../custom/next-kind-invalid-function.js | 16 +- .../schema/custom/next-type-invalid-custom.js | 20 +- .../custom/next-type-invalid-default.js | 12 +- .../custom/next-type-invalid-function.js | 12 +- .../schema/custom/node-data-invalid-custom.js | 6 +- .../node-data-invalid-default-undefined.js | 4 +- .../custom/node-data-invalid-default.js | 6 +- .../custom/node-data-invalid-function.js | 6 +- .../schema/custom/node-mark-invalid-custom.js | 10 +- .../custom/node-mark-invalid-default.js | 8 +- .../custom/node-mark-invalid-function.js | 12 +- .../schema/custom/node-mark-valid-default.js | 12 +- .../custom/node-object-invalid-default.js | 2 +- .../custom/node-object-invalid-function.js | 2 +- .../schema/custom/node-text-invalid-custom.js | 6 +- .../custom/node-text-invalid-default.js | 2 +- .../custom/node-text-invalid-function.js | 2 +- .../schema/custom/node-text-valid-function.js | 4 +- .../test/schema/custom/node-text-valid.js | 4 +- .../custom/node-type-invalid-default.js | 2 +- .../custom/node-type-invalid-function.js | 2 +- .../custom/parent-kind-invalid-custom.js | 4 +- .../custom/parent-kind-invalid-default.js | 18 +- .../custom/parent-kind-invalid-function.js | 18 +- .../custom/parent-type-invalid-custom.js | 20 +- .../custom/parent-type-invalid-default.js | 12 +- .../custom/parent-type-invalid-function.js | 12 +- .../custom/previous-kind-invalid-custom.js | 16 +- .../custom/previous-kind-invalid-default.js | 16 +- .../custom/previous-kind-invalid-function.js | 16 +- .../custom/previous-type-invalid-custom.js | 20 +- .../custom/previous-type-invalid-default.js | 12 +- .../custom/previous-type-invalid-function.js | 12 +- support/fixtures.js | 2 +- 267 files changed, 2032 insertions(+), 2937 deletions(-) delete mode 100755 packages/slate/src/interfaces/selection.ts delete mode 100644 packages/slate/test/commands/value/add-mark/collapsed-selection-end.js delete mode 100644 packages/slate/test/commands/value/add-mark/collapsed-selection-middle.js delete mode 100644 packages/slate/test/commands/value/add-mark/collapsed-selection-start.js delete mode 100644 packages/slate/test/commands/value/add-mark/with-mark-object.js delete mode 100644 packages/slate/test/commands/value/add-mark/with-plain-object.js delete mode 100644 packages/slate/test/commands/value/add-marks/across-blocks.js delete mode 100644 packages/slate/test/commands/value/add-marks/across-inlines.js delete mode 100644 packages/slate/test/commands/value/add-marks/across-marks.js delete mode 100644 packages/slate/test/commands/value/add-marks/collapsed-selection-end.js delete mode 100644 packages/slate/test/commands/value/add-marks/collapsed-selection-middle.js delete mode 100644 packages/slate/test/commands/value/add-marks/collapsed-selection-start.js delete mode 100644 packages/slate/test/commands/value/add-marks/first-character.js delete mode 100644 packages/slate/test/commands/value/add-marks/inside-mark.js delete mode 100644 packages/slate/test/commands/value/add-marks/last-character.js delete mode 100644 packages/slate/test/commands/value/add-marks/middle-character.js delete mode 100644 packages/slate/test/commands/value/add-marks/whole-word.js delete mode 100644 packages/slate/test/commands/value/add-marks/with-mark-object.js delete mode 100644 packages/slate/test/commands/value/add-marks/with-plain-object.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/boolean.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/custom-property.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/marks-empty.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/marks-full.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/object.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/selection.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-anchor.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-focus.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js delete mode 100644 packages/slate/test/interfaces/Selection/isSelection/without-marks.js diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts index 765dc44f4a..b1f20ec7e0 100644 --- a/packages/slate-hyperscript/src/creators.ts +++ b/packages/slate-hyperscript/src/creators.ts @@ -5,7 +5,7 @@ import { Mark, Node, Path, - Selection, + Range, Text, Value, } from 'slate' @@ -217,7 +217,7 @@ export function createSelection( tagName: string, attributes: { [key: string]: any }, children: any[] -): Selection { +): Range { const anchor: AnchorToken = children.find(c => c instanceof AnchorToken) const focus: FocusToken = children.find(c => c instanceof FocusToken) @@ -242,8 +242,7 @@ export function createSelection( offset: focus.offset, path: focus.path, }, - isFocused: 'focused' in attributes ? attributes.focused : false, - marks: 'marks' in attributes ? attributes.marks : null, + ...attributes, } } @@ -293,10 +292,10 @@ export function createValue( children: any[] ) { const otherChildren: any[] = [] - let selectionChild: Selection | undefined + let selectionChild: Range | undefined for (const child of children) { - if (Selection.isSelection(child)) { + if (Range.isRange(child)) { selectionChild = child } else { otherChildren.push(child) @@ -380,7 +379,7 @@ export function createValue( if (selectionChild != null) { value.selection = selectionChild - } else if (Selection.isSelection(selection)) { + } else if (Range.isRange(selection)) { value.selection = selection } diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 7bd30855dd..8c649cb7ff 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -51,6 +51,54 @@ class PathCommands { this.apply({ type: 'insert_node', path, node }) } + /** + * Unwrap a single node from its parent. + * + * If the node is surrounded with siblings, its parent will be split. If the + * node is the only child, the parent is removed, and simply replaced by the + * node itself. + */ + + liftNodeAtPath(this: Editor, path: Path): void { + const { value } = this + const parent = Node.parent(value, path) + const parentPath = Path.parent(path) + const index = path[path.length - 1] + const parentIndex = parentPath[parentPath.length - 1] + const grandPath = Path.parent(parentPath) + const isFirst = index === 0 + const isLast = index === parent.nodes.length - 1 + + this.withoutNormalizing(() => { + let targetPath = path + let newPath = grandPath.concat(parentIndex + 1) + + // If the parent has multiple nodes and we're unwrapping the first one, we + // will just move it before the parent instead. + if (parent.nodes.length > 1 && isFirst) { + newPath = grandPath.concat(parentIndex) + } + + // If there are multiple children, and we're unwrapping one of the middle + // children, we need to split the parent in half first. + if (parent.nodes.length > 1 && !isFirst && !isLast) { + targetPath = produce(path, p => { + p[parentPath.length - 1] += 1 + p[targetPath.length - 1] = 0 + }) + + this.splitNodeAtPath(parentPath, index) + } + + this.moveNodeAtPath(targetPath, newPath) + + // If there was only one child, the parent gets removed. + if (parent.nodes.length === 1) { + this.removeNodeAtPath(parentPath) + } + }) + } + /** * Merge the leaf block at a path with the previous leaf block. */ @@ -76,20 +124,34 @@ class PathCommands { const [, blockPath] = closestBlock const [, prevPath] = prevBlock const newPath = Path.next(prevPath) - const commonAncestorPath = Path.common(blockPath, prevPath) + const commonPath = Path.common(blockPath, prevPath) + const furthest = Node.furthest(value, blockPath, ([n, p]) => { + return ( + Path.isDescendant(p, commonPath) && + Path.isAncestor(p, blockPath) && + Element.isElement(n) && + n.nodes.length === 1 + ) + }) + + const furthestRef = furthest ? this.createPathRef(furthest[1]) : null + debugger this.moveNodeAtPath(blockPath, newPath) - this.mergeNodeAtPath(newPath) - - for (const [ancestor, ancestorPath] of Node.ancestors(value, blockPath)) { - if ( - Path.equals(ancestorPath, commonAncestorPath) || - ancestor.nodes.length !== 1 - ) { - break - } - this.removeNodeAtPath(ancestorPath) + debugger + if (furthestRef) { + this.removeNodeAtPath(furthestRef.unref()!) + } + + // If the target block is empty, remove it instead of merging. This is a + // rich text editor common behavior to prevent losing block formatting + // when deleting the entire previous block (with a hanging selection). + debugger + if (this.getText(prevPath) === '') { + this.removeNodeAtPath(prevPath) + } else { + this.mergeNodeAtPath(newPath) } }) } @@ -209,9 +271,9 @@ class PathCommands { // index that accounts for any added/removed nodes. let n = 0 - for (let i = 0; i < node.nodes.length; i++, n++) { + for (let i = 0; i < node.nodes.length; i++ , n++) { const child = node.nodes[i] as Descendant - const prev: Descendant | undefined = node.nodes[i - 1] + const prev = node.nodes[i - 1] const isLast = i === node.nodes.length - 1 if (Element.isElement(child)) { @@ -243,20 +305,52 @@ class PathCommands { } else { // Merge adjacent text nodes that are empty or have matching marks. if (prev != null && Text.isText(prev)) { - if ( - prev.text === '' || - child.text === '' || - Text.matches(child, prev) - ) { + if (Text.matches(child, prev)) { this.mergeNodeAtPath(path.concat(n)) n-- continue + } else if (prev.text === '') { + this.removeNodeAtPath(path.concat(n - 1)) + n-- + continue + } else if (isLast && child.text === '') { + this.removeNodeAtPath(path.concat(n)) + n-- + continue } } } } } + /** + * Removing a node at a path, replacing it with its children. + */ + + pluckNodeAtPath(this: Editor, path: Path): void { + const { value } = this + const node = Node.get(value, path) + + if (Text.isText(node)) { + throw new Error( + `Cannot pluck a node at [${path}] because it is a text node and has no children.` + ) + } + + this.withoutNormalizing(() => { + const parentPath = Path.parent(path) + const index = path[path.length - 1] + + for (let i = 0; i < node.nodes.length; i++) { + const targetPath = path.concat(0) + const newPath = parentPath.concat(index + i + 1) + this.moveNodeAtPath(targetPath, newPath) + } + + this.removeNodeAtPath(path) + }) + } + /** * Remove all of the children from the node at a path. */ @@ -312,10 +406,15 @@ class PathCommands { * Replace a mark on the text node at a path. */ - replaceMarkAtPath(this: Editor, path: Path, before: Mark, after: Mark): void { + replaceMarkAtPath( + this: Editor, + path: Path, + oldMark: Mark, + newMark: Mark + ): void { this.withoutNormalizing(() => { - this.removeMarkAtPath(path, before) - this.addMarkAtPath(path, after) + this.removeMarkAtPath(path, oldMark) + this.addMarkAtPath(path, newMark) }) } @@ -345,7 +444,7 @@ class PathCommands { } /** - * Set new properties on the node at a path. + * Set new properties on the mark at a path. */ setMarkAtPath( @@ -445,6 +544,10 @@ class PathCommands { throw new Error(`Cannot split the root node.`) } + if (this.getFurthestVoid(path)) { + return + } + const { target = null } = options const { value } = this const node = Node.get(value, path) @@ -468,79 +571,18 @@ class PathCommands { } /** - * Removing a node at a path, replacing it with its children. + * Toggle a mark on or off on the text node at a path. */ - pluckNodeAtPath(this: Editor, path: Path): void { + toggleMarkAtPath(this: Editor, path: Path, mark: Mark): void { const { value } = this const node = Node.get(value, path) - if (Text.isText(node)) { - throw new Error( - `Cannot pluck a node at [${path}] because it is a text node and has no children.` - ) + if (Mark.exists(mark, node.marks)) { + this.removeMarkAtPath(path, mark) + } else { + this.addMarkAtPath(path, mark) } - - this.withoutNormalizing(() => { - const parentPath = Path.parent(path) - const index = path[path.length - 1] - - for (let i = 0; i < node.nodes.length; i++) { - const targetPath = path.concat(0) - const newPath = parentPath.concat(index + i + 1) - this.moveNodeAtPath(targetPath, newPath) - } - - this.removeNodeAtPath(path) - }) - } - - /** - * Unwrap a single node from its parent. - * - * If the node is surrounded with siblings, its parent will be split. If the - * node is the only child, the parent is removed, and simply replaced by the - * node itself. - */ - - liftNodeAtPath(this: Editor, path: Path): void { - const { value } = this - const parent = Node.parent(value, path) - const parentPath = Path.parent(path) - const index = path[path.length - 1] - const parentIndex = parentPath[parentPath.length - 1] - const grandPath = Path.parent(parentPath) - const isFirst = index === 0 - const isLast = index === parent.nodes.length - 1 - - this.withoutNormalizing(() => { - let targetPath = path - let newPath = grandPath.concat(parentIndex + 1) - - // If the parent has multiple nodes and we're unwrapping the first one, we - // will just move it before the parent instead. - if (parent.nodes.length > 1 && isFirst) { - newPath = grandPath.concat(parentIndex) - } - - // If there are multiple children, and we're unwrapping one of the middle - // children, we need to split the parent in half first. - if (parent.nodes.length > 1 && !isFirst && !isLast) { - targetPath = produce(path, p => { - p[parentPath.length - 1] += 1 - p[targetPath.length - 1] = 0 - }) - - this.splitNodeAtPath(parentPath, index) - } - - this.moveNodeAtPath(targetPath, newPath) - - // If there was only one child, the parent gets removed. - if (parent.nodes.length === 1) { - this.removeNodeAtPath(parentPath) - } - }) } /** diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index 5e0995604e..bf5109303f 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -15,6 +15,14 @@ class PointCommands { reverse?: boolean } = {} ): void { + const furthestVoid = this.getFurthestVoid(point.path) + + if (furthestVoid) { + const [, voidPath] = furthestVoid + this.removeNodeAtPath(voidPath) + return + } + const { reverse = false, ...rest } = options const target = reverse ? this.getPreviousPoint(point, rest) @@ -250,16 +258,28 @@ class PointCommands { const { path, offset } = point const { height = 0, always = true } = options - if (height > path.length) { + if (height < 0) { throw new Error( - `Cannot split the leaf node at path [${path}] to a height of \`${height}\` because it does not have that many ancestors.` + `Cannot split the node at path [${path}] to a negative height of \`${height}\`.` ) } this.withoutNormalizing(() => { + const furthestVoid = this.getFurthestVoid(point.path) let position = offset let target: number | undefined let h = 0 + debugger + + // If the point it inside a void node, we still want to split up to a + // `height`, but we need to start after the void node in the tree. + if (furthestVoid) { + const [, voidPath] = furthestVoid + const relPath = Path.relative(point.path, voidPath) + h = relPath.length + 1 + position = voidPath[voidPath.length - 1] + } + // Create a ref that tracks the split point as we move up the ancestors. // Stick backwards because we're splitting and we want to remain inside @@ -270,13 +290,18 @@ class PointCommands { while (h <= height) { const depth = path.length - h const p = path.slice(0, depth) + h++ + + if (p.length === 0) { + break + } // With the `always: false` option, we will instead split the nodes only // when the point isn't already at it's edge. if ( !always && pointRef.current != null && - this.isAtEdgeOfPath(pointRef.current, Path.parent(p)) + this.isAtEdge(pointRef.current, Path.parent(p)) ) { continue } @@ -284,9 +309,11 @@ class PointCommands { this.splitNodeAtPath(p, position, { target }) target = position position = path[depth - 1] + 1 - h++ } + + pointRef.unref() }) + } } diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index 8d4c4987ef..f6d3f96c9b 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -1,12 +1,21 @@ -import { Editor, Fragment, Mark, Element, Path, Range } from '../..' +import { + Value, + Editor, + Fragment, + Mark, + Node, + Element, + Path, + Range, +} from '../..' class RangeCommands { /** - * Add a mark to all of the spans of text in a range, splitting the individual + * Add a set of marks to all of the spans of text in a range, splitting the individual * text nodes if the range intersects them. */ - addMarkAtRange(this: Editor, range: Range, mark: Mark): void { + addMarksAtRange(this: Editor, range: Range, marks: Mark[]): void { this.withoutNormalizing(() => { const rangeRef = this.createRangeRef(range, { stick: 'inward' }) const [start, end] = Range.points(range) @@ -14,9 +23,9 @@ class RangeCommands { this.splitNodeAtPoint(start, { always: false }) range = rangeRef.unref()! - for (const [node, path] of this.texts({ range })) { - if (!Mark.exists(mark, node.marks)) { - this.apply({ type: 'add_mark', path, mark }) + for (const [, path] of this.texts({ range })) { + for (const mark of marks) { + this.addMarkAtPath(path, mark) } } }) @@ -46,31 +55,56 @@ class RangeCommands { } this.withoutNormalizing(() => { - if (hanging === false) { - // To obey common rich text editor behavior, if the range is "hanging" - // into the end block, we move it backwards so that it's not. - range = this.getNonHangingRange(range) - } + // To obey common rich text editor behavior, if the range is "hanging" + // into the end block, we move it backwards so that it's not. + // if (hanging === false) { + // range = this.getNonHangingRange(range) + // } const [start, end] = Range.points(range) + const beforeRef = this.createPointRef(start, { stick: 'backward' }) const startRef = this.createPointRef(start) const endRef = this.createPointRef(end, { stick: 'backward' }) const afterRef = this.createPointRef(end) + let commonPath = Path.common(start.path, end.path) + let startHeight = start.path.length - commonPath.length - 1 + let endHeight = end.path.length - commonPath.length - 1 + + if (Path.equals(start.path, end.path)) { + commonPath = Path.parent(commonPath) + startHeight = 0 + endHeight = 0 + } + + debugger + this.splitNodeAtPoint(end, { height: Math.max(0, endHeight) }) + this.splitNodeAtPoint(start, { height: Math.max(0, startHeight) }) - this.splitBlockAtRange(range, { height: Infinity }) + const startIndex = startRef.unref()!.path[commonPath.length] + const endIndex = endRef.unref()!.path[commonPath.length] + debugger + + for (let i = endIndex; i >= startIndex; i--) { + debugger + this.removeNodeAtPath(commonPath.concat(i)) + } - const startIndex = startRef.current!.path[0] - const endIndex = endRef.current!.path[0] + const beforePoint = beforeRef.unref() + const afterPoint = afterRef.unref() - for (let i = endIndex; i <= startIndex; i--) { - this.removeNodeAtPath([i]) + if (beforePoint == null || afterPoint == null) { + return } - const afterClosest = this.getClosestBlock(afterRef.current!.path) + debugger + const ancestor = Node.get(this.value, commonPath) + debugger - if (afterClosest) { - const [, afterBlockPath] = afterClosest - this.mergeBlockAtPath(afterBlockPath) + if ( + (Value.isValue(ancestor) || Element.isElement(ancestor)) && + this.hasBlocks(ancestor) + ) { + this.mergeBlockAtPath(afterPoint.path) } }) } @@ -83,7 +117,11 @@ class RangeCommands { this.withoutNormalizing(() => { const [start] = Range.points(range) const pointRef = this.createPointRef(start) - this.deleteAtRange(range) + + if (Range.isExpanded(range)) { + this.deleteAtRange(range) + } + this.insertBlockAtPoint(pointRef.current!, block) pointRef.unref() }) @@ -97,7 +135,11 @@ class RangeCommands { this.withoutNormalizing(() => { const [start] = Range.points(range) const pointRef = this.createPointRef(start) - this.deleteAtRange(range) + + if (Range.isExpanded(range)) { + this.deleteAtRange(range) + } + this.insertFragmentAtPoint(pointRef.current!, fragment) pointRef.unref() }) @@ -111,7 +153,11 @@ class RangeCommands { this.withoutNormalizing(() => { const [start] = Range.points(range) const pointRef = this.createPointRef(start) - this.deleteAtRange(range) + + if (Range.isExpanded(range)) { + this.deleteAtRange(range) + } + this.insertInlineAtPoint(pointRef.current!, inline) pointRef.unref() }) @@ -125,21 +171,25 @@ class RangeCommands { this.withoutNormalizing(() => { const [start] = Range.points(range) const pointRef = this.createPointRef(start) - this.deleteAtRange(range) + + if (Range.isExpanded(range)) { + this.deleteAtRange(range) + } + this.insertTextAtPoint(pointRef.current!, text) pointRef.unref() }) } /** - * Remove a mark from all of the spans of text in a range. + * Remove a set of marks from all of the spans of text in a range. */ - removeMarkAtRange(this: Editor, range: Range, mark: Mark): void { + removeMarksAtRange(this: Editor, range: Range, marks: Mark[]): void { this.withoutNormalizing(() => { - for (const [node, path] of this.texts({ range })) { - if (Mark.exists(mark, node.marks)) { - this.apply({ type: 'remove_mark', path, mark }) + for (const [, path] of this.texts({ range })) { + for (const mark of marks) { + this.removeMarkAtPath(path, mark) } } }) @@ -268,7 +318,11 @@ class RangeCommands { this.withoutNormalizing(() => { const [, end] = Range.points(range) const pointRef = this.createPointRef(end) - this.deleteAtRange(range) + + if (Range.isExpanded(range)) { + this.deleteAtRange(range) + } + const point = pointRef.unref() this.splitBlockAtPoint(point!, options) }) @@ -289,7 +343,11 @@ class RangeCommands { this.withoutNormalizing(() => { const [, end] = Range.points(range) const pointRef = this.createPointRef(end) - this.deleteAtRange(range) + + if (Range.isExpanded(range)) { + this.deleteAtRange(range) + } + const point = pointRef.unref() this.splitInlineAtPoint(point!, options) }) @@ -299,14 +357,18 @@ class RangeCommands { * Toggle a mark on or off for all of the spans of text in a range. */ - toggleMarkAtRange(this: Editor, range: Range, mark: Mark): void { + toggleMarksAtRange(this: Editor, range: Range, marks: Mark[]): void { this.withoutNormalizing(() => { - for (const [text, path] of this.texts({ range })) { - this.apply({ - type: Mark.exists(mark, text.marks) ? 'remove_mark' : 'add_mark', - path, - mark, - }) + const rangeRef = this.createRangeRef(range, { stick: 'inward' }) + const [start, end] = Range.points(range) + this.splitNodeAtPoint(end, { always: false }) + this.splitNodeAtPoint(start, { always: false }) + range = rangeRef.unref()! + + for (const [, path] of this.texts({ range })) { + for (const mark of marks) { + this.toggleMarkAtPath(path, mark) + } } }) } diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index f3a4682efd..96c02a4496 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -1,15 +1,31 @@ -import { Editor, Point, Range, Selection } from '../..' +import { Editor, Point, Range } from '../..' class SelectionCommands { /** - * Blur the selection. + * Collapse the selection. */ - blur(this: Editor) { + collapse( + this: Editor, + options: { + edge?: 'anchor' | 'focus' | 'start' | 'end' + } = {} + ) { + const { edge = 'anchor' } = options const { selection } = this.value - if (selection != null) { - this.select({ isFocused: false }) + if (selection == null) { + return + } else if (edge === 'anchor') { + this.moveTo(selection.anchor) + } else if (edge === 'focus') { + this.moveTo(selection.focus) + } else if (edge === 'start') { + const [start] = Range.points(selection) + this.moveTo(start) + } else if (edge === 'end') { + const [, end] = Range.points(selection) + this.moveTo(end) } } @@ -29,18 +45,6 @@ class SelectionCommands { } } - /** - * Focus the selection. - */ - - focus(this: Editor) { - const { selection } = this.value - - if (selection != null) { - this.select({ isFocused: true }) - } - } - /** * Flip the selection's anchor and focus points. */ @@ -240,7 +244,7 @@ class SelectionCommands { * Set the selection to a new value. */ - select(this: Editor, props: Partial) { + select(this: Editor, props: Partial) { const { selection } = this.value if (selection != null) { @@ -259,7 +263,7 @@ class SelectionCommands { this.apply({ type: 'set_selection', properties: selection, - newProperties: { isFocused: false, marks: null, ...props }, + newProperties: props, }) } @@ -267,10 +271,10 @@ class SelectionCommands { * Set new props on the selection. */ - setSelection(this: Editor, props: Partial) { + setSelection(this: Editor, props: Partial) { const { selection } = this.value - let oldProps: Partial | null = {} - let newProps: Partial = {} + let oldProps: Partial | null = {} + let newProps: Partial = {} if (selection == null) { this.select(props) @@ -293,17 +297,6 @@ class SelectionCommands { } } - // If the selection moves, clear any marks, unless the new selection - // props change the marks in some way. - if ( - selection.marks != null && - newProps.marks === undefined && - (newProps.anchor || newProps.focus) - ) { - newProps.marks = null - oldProps.marks = selection.marks - } - // If nothing has changed, don't apply any operations. if (Object.keys(oldProps).length === 0) { return diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts index 446860214c..1327755fde 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/value.ts @@ -25,23 +25,14 @@ const RESTRICTED_PROPERTIES = ['annotations', 'history', 'nodes', 'selection'] class ValueCommands { /** - * Add a mark to the span of text that is currently selected. + * Add a set of marks to the span of text that is currently selected. */ - addMark(this: Editor, mark: Mark): void { + addMarks(this: Editor, marks: Mark[]): void { const { selection } = this.value - if (selection == null) { - return - } else if (Range.isExpanded(selection)) { - this.addMarkAtRange(selection, mark) - } else { - const activeMarks = this.getActiveMarks() - - if (!Mark.exists(mark, activeMarks)) { - const marks = activeMarks.concat(mark) - this.select({ marks }) - } + if (selection != null) { + this.addMarksAtRange(selection, marks) } } @@ -117,11 +108,11 @@ class ValueCommands { return } - const [start] = Range.points(selection) - const pointRef = this.createPointRef(start) this.deleteAtRange(selection, options) - this.moveTo(pointRef.current!) - pointRef.unref() + // After deleting, the selection can end up still expanded across a + // zero-width offset if it had one edge in an inline node. So to ensure that + // it's always collapsed after deleting, we collapse it to the end point. + this.collapse({ edge: 'end' }) } /** @@ -207,8 +198,13 @@ class ValueCommands { const [start] = Range.points(selection) const pointRef = this.createPointRef(start) this.insertTextAtRange(selection, text) - this.moveTo(pointRef.current!) - pointRef.unref() + const end = pointRef.unref()! + this.moveTo(end) + + if (selection.marks) { + const range = { anchor: start, focus: end } + this.addMarksAtRange(range, selection.marks) + } } /** @@ -256,24 +252,14 @@ class ValueCommands { } /** - * Remove a mark from all of the spans of text in the current selection. + * Remove a set of marks from all of the spans of text in the current selection. */ - removeMark(this: Editor, mark: Mark): void { - const { value } = this - const { selection } = value + removeMarks(this: Editor, marks: Mark[]): void { + const { selection } = this.value - if (selection == null) { - return - } else if (Range.isExpanded(selection)) { - this.removeMarkAtRange(selection, mark) - } else { - const activeMarks = this.getActiveMarks() - - if (Mark.exists(mark, activeMarks)) { - const marks = activeMarks.filter(m => !Mark.matches(m, mark)) - this.select({ marks }) - } + if (selection != null) { + this.removeMarksAtRange(selection, marks) } } @@ -281,10 +267,10 @@ class ValueCommands { * Replace a mark on all of the spans of text in the selection with a new one. */ - replaceMark(this: Editor, oldMark: Mark, newMark: Mark): void { + replaceMarks(this: Editor, oldMarks: Mark[], newMarks: Mark[]): void { this.withoutNormalizing(() => { - this.removeMark(oldMark) - this.addMark(newMark) + this.removeMarks(oldMarks) + this.addMarks(newMarks) }) } @@ -437,13 +423,11 @@ class ValueCommands { * Toggle a mark on or off for all the spans of text in the selection. */ - toggleMark(this: Editor, mark: Mark): void { - const activeMarks = this.getActiveMarks() + toggleMarks(this: Editor, marks: Mark[]): void { + const { selection } = this.value - if (Mark.exists(mark, activeMarks)) { - this.removeMark(mark) - } else { - this.addMark(mark) + if (selection != null) { + this.toggleMarksAtRange(selection, marks) } } @@ -460,8 +444,8 @@ class ValueCommands { const rangeRef = this.createRangeRef(selection) this.unwrapBlockAtRange(selection, props) - this.select(rangeRef.current) - rangeRef.unref() + const range = rangeRef.unref()! + this.select(range) } /** @@ -477,8 +461,8 @@ class ValueCommands { const rangeRef = this.createRangeRef(selection) this.unwrapInlineAtRange(selection, props) - this.select(rangeRef.current) - rangeRef.unref() + const range = rangeRef.unref()! + this.select(range) } /** @@ -507,8 +491,8 @@ class ValueCommands { const rangeRef = this.createRangeRef(selection) this.wrapBlockAtRange(selection, block) - this.select(rangeRef.current) - rangeRef.unref() + const range = rangeRef.unref()! + this.select(range) } /** @@ -524,8 +508,8 @@ class ValueCommands { const rangeRef = this.createRangeRef(selection) this.wrapInlineAtRange(selection, inline) - this.select(rangeRef.current) - rangeRef.unref() + const range = rangeRef.unref()! + this.select(range) } } diff --git a/packages/slate/src/classes/path-ref.ts b/packages/slate/src/classes/path-ref.ts index ece3207410..4a47fda712 100644 --- a/packages/slate/src/classes/path-ref.ts +++ b/packages/slate/src/classes/path-ref.ts @@ -55,7 +55,9 @@ class PathRef { unref(): Path | null { this.onUnref() - return this.current + const { current } = this + this.current = null + return current } } diff --git a/packages/slate/src/classes/point-ref.ts b/packages/slate/src/classes/point-ref.ts index caaf282c00..466c8ea67f 100644 --- a/packages/slate/src/classes/point-ref.ts +++ b/packages/slate/src/classes/point-ref.ts @@ -55,7 +55,9 @@ class PointRef { unref(): Point | null { this.onUnref() - return this.current + const { current } = this + this.current = null + return current } } diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts index fb2b299fb3..e55aed9c17 100644 --- a/packages/slate/src/classes/queries/range.ts +++ b/packages/slate/src/classes/queries/range.ts @@ -99,15 +99,17 @@ class RangeQueries { return false } - const [, end] = Range.points(range) - const closestBlock = this.getClosestBlock(end.path) + const [start, end] = Range.points(range) + const startClosest = this.getClosestBlock(start.path) + const endClosest = this.getClosestBlock(end.path) - if (!closestBlock) { + if (!startClosest || !endClosest) { return false } - const [, endBlockPath] = closestBlock - return this.isAtStart(end, endBlockPath) + const [, startPath] = startClosest + const [, endPath] = endClosest + return this.isAtStart(start, startPath) && this.isAtStart(end, endPath) } /** diff --git a/packages/slate/src/classes/range-ref.ts b/packages/slate/src/classes/range-ref.ts index 59be4bad1b..a9a2983269 100644 --- a/packages/slate/src/classes/range-ref.ts +++ b/packages/slate/src/classes/range-ref.ts @@ -55,7 +55,9 @@ class RangeRef { unref(): Range | null { this.onUnref() - return this.current + const { current } = this + this.current = null + return current } } diff --git a/packages/slate/src/index.ts b/packages/slate/src/index.ts index df5ba8a15d..105fd44bfc 100755 --- a/packages/slate/src/index.ts +++ b/packages/slate/src/index.ts @@ -13,7 +13,6 @@ export * from './interfaces/operation' export * from './interfaces/path' export * from './interfaces/point' export * from './interfaces/range' -export * from './interfaces/selection' export * from './interfaces/string' export * from './interfaces/text' export * from './interfaces/value' diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index 68bd55d8a0..b4a814dcf9 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -1,4 +1,4 @@ -import { Annotation, Mark, Node, Path, Selection, Value } from '..' +import { Annotation, Mark, Node, Path, Range, Value } from '..' import isPlainObject from 'is-plain-object' type AddAnnotationOperation = { @@ -104,18 +104,18 @@ type SetSelectionOperation = type: 'set_selection' [key: string]: any properties: null - newProperties: Selection + newProperties: Range } | { type: 'set_selection' [key: string]: any - properties: Partial - newProperties: Partial + properties: Partial + newProperties: Partial } | { type: 'set_selection' [key: string]: any - properties: Selection + properties: Range newProperties: null } @@ -429,14 +429,14 @@ namespace Operation { if (properties == null) { return { ...op, - properties: newProperties as Selection, + properties: newProperties as Range, newProperties: null, } } else if (newProperties == null) { return { ...op, properties: null, - newProperties: properties as Selection, + newProperties: properties as Range, } } else { return { ...op, properties: newProperties, newProperties: properties } diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts index 46191991ae..42f2cc4aa5 100755 --- a/packages/slate/src/interfaces/point.ts +++ b/packages/slate/src/interfaces/point.ts @@ -142,7 +142,10 @@ namespace Point { (op.position === offset && stick === 'forward') ) { p.offset -= op.position - p.path = Path.transform(path, op, options)! + p.path = Path.transform(path, op, { + ...options, + stick: 'forward', + })! } } else { p.path = Path.transform(path, op, options)! diff --git a/packages/slate/src/interfaces/selection.ts b/packages/slate/src/interfaces/selection.ts deleted file mode 100755 index bc2828e9ee..0000000000 --- a/packages/slate/src/interfaces/selection.ts +++ /dev/null @@ -1,38 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Mark, Point, PointKey, Range } from '..' - -/** - * `Selection` objects represent the range in a document that a user has - * selected with their cursor. They implement the `Range` interface, with an - * extra property denoting whether the editor is currently focused or not. - */ - -interface Selection extends Range { - isFocused: boolean - marks: Mark[] | null - [key: string]: any -} - -/** - * `SelectionPointEntry` objects are returned when iterating over `Point` - * objects that belong to an `Selection`. - */ - -type SelectionPointEntry = [Point, PointKey, Selection] - -namespace Selection { - /** - * Check if a value implements the `Selection` interface. - */ - - export const isSelection = (value: any): value is Selection => { - return ( - isPlainObject(value) && - typeof value.isFocused === 'boolean' && - (value.marks === null || Mark.isMarkSet(value.marks)) && - Range.isRange(value) - ) - } -} - -export { Selection, SelectionPointEntry } diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index ee21035bf2..0991a22bc1 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -9,8 +9,9 @@ import { Operation, Path, Point, - Selection, - SelectionPointEntry, + PointKey, + Range, + Descendant, Text, } from '..' @@ -20,7 +21,7 @@ import { */ interface Value extends Element { - selection: Selection | null + selection: Range | null annotations: Record [key: string]: any } @@ -32,6 +33,13 @@ interface Value extends Element { type ValueEntry = [Value, Path] +/** + * `SelectionPointEntry` objects are returned when iterating over `Point` + * objects that belong to a selection. + */ + +type SelectionPointEntry = [Point, PointKey, Range] + namespace Value { /** * Check if a value implements the `Value` interface. @@ -40,7 +48,7 @@ namespace Value { export const isValue = (value: any): value is Value => { return ( isPlainObject(value) && - (value.selection === null || Selection.isSelection(value.selection)) && + (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.nodes) && Annotation.isAnnotationMap(value.annotations) ) @@ -139,6 +147,7 @@ namespace Value { parent.nodes.splice(index, 1) for (const [point, key, range] of Value.points(v)) { + debugger range[key] = Point.transform(point, op)! } @@ -201,8 +210,10 @@ namespace Value { const { path } = op const index = path[path.length - 1] const parent = Node.parent(v, path) - const [, next] = Node.texts(v, { path }) - const [, prev] = Node.texts(v, { path, reverse: true }) + const [, first] = Node.first(v, path) + const [, last] = Node.last(v, path) + const [, prev] = Node.texts(v, { path: first, reverse: true }) + const [, next] = Node.texts(v, { path: last }) parent.nodes.splice(index, 1) // Transform all of the points in the value, but if the point was in the @@ -220,7 +231,7 @@ namespace Value { const newNextPath = Path.transform(nextPath, op)! point.path = newNextPath point.offset = 0 - } else if (Selection.isSelection(range)) { + } else if (Range.isRange(range)) { v.selection = null } else if (Annotation.isAnnotation(range)) { delete v.annotations[key!] @@ -281,7 +292,7 @@ namespace Value { if (newProperties == null) { v.selection = newProperties } else if (v.selection == null) { - if (!Selection.isSelection(newProperties)) { + if (!Range.isRange(newProperties)) { throw new Error( `Cannot apply an incomplete "set_selection" operation properties ${JSON.stringify( newProperties @@ -315,18 +326,22 @@ namespace Value { const node = Node.get(v, path) const parent = Node.parent(v, path) const index = path[path.length - 1] - let newNode: Node + let newNode: Descendant if (Text.isText(node)) { const before = node.text.slice(0, position) const after = node.text.slice(position) node.text = before - newNode = { ...node, ...properties, text: after } + newNode = { ...node, ...(properties as Partial), text: after } } else { const before = node.nodes.slice(0, position) const after = node.nodes.slice(position) node.nodes = before - newNode = { ...node, ...properties, nodes: after } + newNode = { + ...node, + ...(properties as Partial), + nodes: after, + } } parent.nodes.splice(index + 1, 0, newNode) diff --git a/packages/slate/src/plugins/history/plugin.ts b/packages/slate/src/plugins/history/plugin.ts index abf245aa8a..5398e51ae8 100644 --- a/packages/slate/src/plugins/history/plugin.ts +++ b/packages/slate/src/plugins/history/plugin.ts @@ -211,20 +211,15 @@ const shouldMerge = (op: Operation, into: Operation | null): boolean => { */ const shouldSave = (op: Operation): boolean => { - if (op.type === 'set_selection') { - const { newProperties } = op - - if ( - newProperties != null && - 'isFocused' in newProperties && - !('anchor' in newProperties) && - !('focus' in newProperties) - ) { - return false + switch (op.type) { + case 'set_selection': { + return op.newProperties != null } - } - return true + default: { + return true + } + } } export { HistoryPlugin } diff --git a/packages/slate/test/commands/value/add-mark/across-blocks.js b/packages/slate/test/commands/value/add-mark/across-blocks.js index 058284561a..f7e9d4c762 100644 --- a/packages/slate/test/commands/value/add-mark/across-blocks.js +++ b/packages/slate/test/commands/value/add-mark/across-blocks.js @@ -3,35 +3,33 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - word - - - another - - + + word + + + another + ) export const output = ( - - - wo - - rd - - - - an + + wo + + rd + + + + an + other - - + + ) diff --git a/packages/slate/test/commands/value/add-mark/across-inlines.js b/packages/slate/test/commands/value/add-mark/across-inlines.js index 1e45efdbaa..1c33a1a060 100644 --- a/packages/slate/test/commands/value/add-mark/across-inlines.js +++ b/packages/slate/test/commands/value/add-mark/across-inlines.js @@ -3,51 +3,49 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - - - word - - - - - - - another - - - - + + + + word + + + + + + + another + + + ) export const output = ( - - - - - wo - - rd - - - - - - - - an + + + + wo + + rd + + + + + + + + an + other - - - - + + + + ) diff --git a/packages/slate/test/commands/value/add-mark/collapsed-selection-end.js b/packages/slate/test/commands/value/add-mark/collapsed-selection-end.js deleted file mode 100644 index bd769efab3..0000000000 --- a/packages/slate/test/commands/value/add-mark/collapsed-selection-end.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMark('bold') - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - a - - - - -) diff --git a/packages/slate/test/commands/value/add-mark/collapsed-selection-middle.js b/packages/slate/test/commands/value/add-mark/collapsed-selection-middle.js deleted file mode 100644 index ef21ec3484..0000000000 --- a/packages/slate/test/commands/value/add-mark/collapsed-selection-middle.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMark('bold') - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - woa - rd - - - -) diff --git a/packages/slate/test/commands/value/add-mark/collapsed-selection-start.js b/packages/slate/test/commands/value/add-mark/collapsed-selection-start.js deleted file mode 100644 index ca26f34341..0000000000 --- a/packages/slate/test/commands/value/add-mark/collapsed-selection-start.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMark('bold') - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - a - word - - - -) diff --git a/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js b/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js index 2f0d155e37..96a0f4ce5a 100644 --- a/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js +++ b/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js @@ -3,42 +3,38 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - wo - rd - - - - an - other - - + + wo + rd + + + + an + other + ) export const output = ( - - - wo - - - rd - - - - - - an - - other - - + + wo + + + rd + + + + + + an + + other + ) diff --git a/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js b/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js index 6fc2ed16a2..0d576e249a 100644 --- a/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js +++ b/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js @@ -3,45 +3,41 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - - word - - - - - another - - - + + + word + + + + + another + + ) export const output = ( - - - wo - - - rd - - - - - - an - - - other - - - + + wo + + + rd + + + + + + an + + + other + + ) diff --git a/packages/slate/test/commands/value/add-mark/existing-marks.js b/packages/slate/test/commands/value/add-mark/existing-marks.js index cb40bec804..e818fa2f2f 100644 --- a/packages/slate/test/commands/value/add-mark/existing-marks.js +++ b/packages/slate/test/commands/value/add-mark/existing-marks.js @@ -3,34 +3,30 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - - wo - - - - rd - - - + + + + wo + + + + rd + + ) diff --git a/packages/slate/test/commands/value/add-mark/first-character.js b/packages/slate/test/commands/value/add-mark/first-character.js index acf124f497..5c80224d4c 100644 --- a/packages/slate/test/commands/value/add-mark/first-character.js +++ b/packages/slate/test/commands/value/add-mark/first-character.js @@ -3,28 +3,26 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - word - - + + word + ) export const output = ( - - - - w - + + + w + + ord - - + + ) diff --git a/packages/slate/test/commands/value/add-mark/last-character.js b/packages/slate/test/commands/value/add-mark/last-character.js index 6589c0fa8a..9b3c7997d3 100644 --- a/packages/slate/test/commands/value/add-mark/last-character.js +++ b/packages/slate/test/commands/value/add-mark/last-character.js @@ -3,28 +3,24 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wor - - d - - - + + wor + + d + + ) diff --git a/packages/slate/test/commands/value/add-mark/middle-character.js b/packages/slate/test/commands/value/add-mark/middle-character.js index b13e2d6bc9..d6bf2f998a 100644 --- a/packages/slate/test/commands/value/add-mark/middle-character.js +++ b/packages/slate/test/commands/value/add-mark/middle-character.js @@ -3,29 +3,27 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - word - - + + word + ) export const output = ( - - - w - - o - + + w + + o + + rd - - + + ) diff --git a/packages/slate/test/commands/value/add-mark/whole-word.js b/packages/slate/test/commands/value/add-mark/whole-word.js index e5ee812249..7a14ec1517 100644 --- a/packages/slate/test/commands/value/add-mark/whole-word.js +++ b/packages/slate/test/commands/value/add-mark/whole-word.js @@ -3,27 +3,23 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) } export const input = ( - - - word - - + + word + ) export const output = ( - - - - word - - - + + + word + + ) diff --git a/packages/slate/test/commands/value/add-mark/with-mark-object.js b/packages/slate/test/commands/value/add-mark/with-mark-object.js deleted file mode 100644 index 08feb50ff0..0000000000 --- a/packages/slate/test/commands/value/add-mark/with-mark-object.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -import { Mark } from 'slate' - -export const run = editor => { - editor.addMark( - Mark.create({ - type: 'bold', - data: { thing: 'value' }, - }) - ) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - w - - ord - - - -) diff --git a/packages/slate/test/commands/value/add-mark/with-plain-object.js b/packages/slate/test/commands/value/add-mark/with-plain-object.js deleted file mode 100644 index 1c7d8b2e72..0000000000 --- a/packages/slate/test/commands/value/add-mark/with-plain-object.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMark({ - type: 'bold', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - w - - ord - - - -) diff --git a/packages/slate/test/commands/value/add-marks/across-blocks.js b/packages/slate/test/commands/value/add-marks/across-blocks.js deleted file mode 100644 index 885768a4c1..0000000000 --- a/packages/slate/test/commands/value/add-marks/across-blocks.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) -} - -export const input = ( - - - - word - - - another - - - -) - -export const output = ( - - - - wo - - - rd - - - - - - an - - other - - - -) diff --git a/packages/slate/test/commands/value/add-marks/across-inlines.js b/packages/slate/test/commands/value/add-marks/across-inlines.js deleted file mode 100644 index 551dfd644e..0000000000 --- a/packages/slate/test/commands/value/add-marks/across-inlines.js +++ /dev/null @@ -1,57 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) -} - -export const input = ( - - - - - word - - - - - - - another - - - - -) - -export const output = ( - - - - - wo - - - rd - - - - - - - - - - - - - - an - - other - - - - -) diff --git a/packages/slate/test/commands/value/add-marks/across-marks.js b/packages/slate/test/commands/value/add-marks/across-marks.js deleted file mode 100644 index ca46f88a0e..0000000000 --- a/packages/slate/test/commands/value/add-marks/across-marks.js +++ /dev/null @@ -1,47 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['underline']) -} - -export const input = ( - - - - Some{' '} - - bold - {' '} - and some{' '} - - italic - - - - -) - -export const output = ( - - - - Some{' '} - - - - bold - - - and some - - ita - - - lic - - - - -) diff --git a/packages/slate/test/commands/value/add-marks/collapsed-selection-end.js b/packages/slate/test/commands/value/add-marks/collapsed-selection-end.js deleted file mode 100644 index 423437cbcf..0000000000 --- a/packages/slate/test/commands/value/add-marks/collapsed-selection-end.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - - - a - - - - - -) diff --git a/packages/slate/test/commands/value/add-marks/collapsed-selection-middle.js b/packages/slate/test/commands/value/add-marks/collapsed-selection-middle.js deleted file mode 100644 index 4a81731b44..0000000000 --- a/packages/slate/test/commands/value/add-marks/collapsed-selection-middle.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - wo - a - - rd - - - -) diff --git a/packages/slate/test/commands/value/add-marks/collapsed-selection-start.js b/packages/slate/test/commands/value/add-marks/collapsed-selection-start.js deleted file mode 100644 index 69558a16c4..0000000000 --- a/packages/slate/test/commands/value/add-marks/collapsed-selection-start.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - a - - word - - - -) diff --git a/packages/slate/test/commands/value/add-marks/first-character.js b/packages/slate/test/commands/value/add-marks/first-character.js deleted file mode 100644 index f73b91051e..0000000000 --- a/packages/slate/test/commands/value/add-marks/first-character.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - - w - - - ord - - - -) diff --git a/packages/slate/test/commands/value/add-marks/inside-mark.js b/packages/slate/test/commands/value/add-marks/inside-mark.js deleted file mode 100644 index 937f6f754a..0000000000 --- a/packages/slate/test/commands/value/add-marks/inside-mark.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'underline']) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - - - wo - - - - - rd - - - - -) diff --git a/packages/slate/test/commands/value/add-marks/last-character.js b/packages/slate/test/commands/value/add-marks/last-character.js deleted file mode 100644 index 25b9eaf0f2..0000000000 --- a/packages/slate/test/commands/value/add-marks/last-character.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - wor - - - d - - - - - -) diff --git a/packages/slate/test/commands/value/add-marks/middle-character.js b/packages/slate/test/commands/value/add-marks/middle-character.js deleted file mode 100644 index 5438b19af6..0000000000 --- a/packages/slate/test/commands/value/add-marks/middle-character.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w - - - o - - - rd - - - -) diff --git a/packages/slate/test/commands/value/add-marks/whole-word.js b/packages/slate/test/commands/value/add-marks/whole-word.js deleted file mode 100644 index 8a1d9745d2..0000000000 --- a/packages/slate/test/commands/value/add-marks/whole-word.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks(['bold', 'italic']) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - - word - - - - - -) diff --git a/packages/slate/test/commands/value/add-marks/with-mark-object.js b/packages/slate/test/commands/value/add-marks/with-mark-object.js deleted file mode 100644 index 5a49159a9f..0000000000 --- a/packages/slate/test/commands/value/add-marks/with-mark-object.js +++ /dev/null @@ -1,43 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -import { Mark } from 'slate' - -export const run = editor => { - editor.addMarks([ - Mark.create({ - type: 'bold', - data: { thing: 'value' }, - }), - Mark.create({ - type: 'italic', - data: { thing2: 'value2' }, - }), - ]) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - - w - - - ord - - - -) diff --git a/packages/slate/test/commands/value/add-marks/with-plain-object.js b/packages/slate/test/commands/value/add-marks/with-plain-object.js deleted file mode 100644 index 6344f661c4..0000000000 --- a/packages/slate/test/commands/value/add-marks/with-plain-object.js +++ /dev/null @@ -1,42 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks([ - { - type: 'bold', - data: { thing: 'value' }, - }, - - { - type: 'italic', - data: { thing2: 'value2' }, - }, - ]) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - - w - - - ord - - - -) diff --git a/packages/slate/test/commands/value/delete-backward/empty-after-void-block.js b/packages/slate/test/commands/value/delete-backward/empty-after-void-block.js index 881405b4ef..eb18f15083 100644 --- a/packages/slate/test/commands/value/delete-backward/empty-after-void-block.js +++ b/packages/slate/test/commands/value/delete-backward/empty-after-void-block.js @@ -8,21 +8,19 @@ export const run = editor => { export const input = ( - - - - - - + + + + + + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js b/packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js index cc57146783..5df529fce0 100644 --- a/packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js +++ b/packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js @@ -8,23 +8,23 @@ export const run = editor => { export const input = ( - - Hello - - - world! - - - + + Hello + + + world! + + + ) export const output = ( - - - Helloworld! + + + Helloworld! - + ) diff --git a/packages/slate/test/commands/value/delete-backward/single-void-block.js b/packages/slate/test/commands/value/delete-backward/single-void-block.js index 82fe98e458..623f235224 100644 --- a/packages/slate/test/commands/value/delete-backward/single-void-block.js +++ b/packages/slate/test/commands/value/delete-backward/single-void-block.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + {' '} - + ) diff --git a/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js b/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js index 0610c09341..3fd1d7d82f 100644 --- a/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js +++ b/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js @@ -8,21 +8,19 @@ export const run = editor => { export const input = ( - - - - - - + + + + + + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/value/delete-forward/single-void-block.js b/packages/slate/test/commands/value/delete-forward/single-void-block.js index c0b1cfead6..73fc1559e9 100644 --- a/packages/slate/test/commands/value/delete-forward/single-void-block.js +++ b/packages/slate/test/commands/value/delete-forward/single-void-block.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + {' '} - + ) diff --git a/packages/slate/test/commands/value/delete/across-blocks.js b/packages/slate/test/commands/value/delete/across-blocks.js index 4428c797d4..700e28d6ea 100644 --- a/packages/slate/test/commands/value/delete/across-blocks.js +++ b/packages/slate/test/commands/value/delete/across-blocks.js @@ -8,23 +8,19 @@ export const run = editor => { export const input = ( - - - word - - - another - - + + word + + + another + ) export const output = ( - - - woother - - + + woother + ) diff --git a/packages/slate/test/commands/value/delete/across-depths.js b/packages/slate/test/commands/value/delete/across-depths.js index 1aa0e9b96a..4dfa410c62 100644 --- a/packages/slate/test/commands/value/delete/across-depths.js +++ b/packages/slate/test/commands/value/delete/across-depths.js @@ -8,27 +8,23 @@ export const run = editor => { export const input = ( - + - - one - + one - - two - - + + + two + ) export const output = ( - + - - onetwo - + onetwo - + ) diff --git a/packages/slate/test/commands/value/delete/across-texts-and-inlines.js b/packages/slate/test/commands/value/delete/across-texts-and-inlines.js index 341e06a59d..697cb3f86e 100644 --- a/packages/slate/test/commands/value/delete/across-texts-and-inlines.js +++ b/packages/slate/test/commands/value/delete/across-texts-and-inlines.js @@ -8,20 +8,16 @@ export const run = editor => { export const input = ( - - - onetwothree - - + + onetwothree + ) export const output = ( - - - oe - - + + oe + ) diff --git a/packages/slate/test/commands/value/delete/all-nested-blocks.js b/packages/slate/test/commands/value/delete/all-nested-blocks.js index 122b42db06..6640f0059d 100644 --- a/packages/slate/test/commands/value/delete/all-nested-blocks.js +++ b/packages/slate/test/commands/value/delete/all-nested-blocks.js @@ -8,32 +8,28 @@ export const run = editor => { export const input = ( - + + one + + + two - one - - - two - - three - + three - + ) export const output = ( - + - - - + - + ) diff --git a/packages/slate/test/commands/value/delete/before-inline-sibling.js b/packages/slate/test/commands/value/delete/before-inline-sibling.js index 6ec0e68035..e60962a60f 100644 --- a/packages/slate/test/commands/value/delete/before-inline-sibling.js +++ b/packages/slate/test/commands/value/delete/before-inline-sibling.js @@ -8,24 +8,20 @@ export const run = editor => { export const input = ( - - - onetwo - a - - + + onetwo + a + ) export const output = ( - - - one - two - - - - + + onetwo + + + + ) diff --git a/packages/slate/test/commands/value/delete/expanded-across-whole-mark.js b/packages/slate/test/commands/value/delete/expanded-across-whole-mark.js index 142ed8bc91..0fdcc358b3 100644 --- a/packages/slate/test/commands/value/delete/expanded-across-whole-mark.js +++ b/packages/slate/test/commands/value/delete/expanded-across-whole-mark.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - - wo - - rd - - - two - - + + + wo + + rd + + + two + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/value/delete/first-character.js b/packages/slate/test/commands/value/delete/first-character.js index 140bbf956e..469a3639a4 100644 --- a/packages/slate/test/commands/value/delete/first-character.js +++ b/packages/slate/test/commands/value/delete/first-character.js @@ -8,20 +8,16 @@ export const run = editor => { export const input = ( - - - word - - + + word + ) export const output = ( - - - ord - - + + ord + ) diff --git a/packages/slate/test/commands/value/delete/first-position.js b/packages/slate/test/commands/value/delete/first-position.js index 980a2d5150..ca8940d599 100644 --- a/packages/slate/test/commands/value/delete/first-position.js +++ b/packages/slate/test/commands/value/delete/first-position.js @@ -8,22 +8,16 @@ export const run = editor => { export const input = ( - - - - word - - + + word + ) export const output = ( - - - - word - - + + ord + ) diff --git a/packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js index 17abc6d6cb..549db4b30a 100644 --- a/packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js +++ b/packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js @@ -8,24 +8,20 @@ export const run = editor => { export const input = ( - - - one - - two - - three - - + + one + + two + + three + ) export const output = ( - - - three - - + + three + ) diff --git a/packages/slate/test/commands/value/delete/inside-inline-sibling.js b/packages/slate/test/commands/value/delete/inside-inline-sibling.js index b87faa8847..5e0005f3c9 100644 --- a/packages/slate/test/commands/value/delete/inside-inline-sibling.js +++ b/packages/slate/test/commands/value/delete/inside-inline-sibling.js @@ -19,9 +19,9 @@ export const input = ( export const output = ( - one + one - + two diff --git a/packages/slate/test/commands/value/delete/inside-inline.js b/packages/slate/test/commands/value/delete/inside-inline.js index c88ff0259c..0bcb198090 100644 --- a/packages/slate/test/commands/value/delete/inside-inline.js +++ b/packages/slate/test/commands/value/delete/inside-inline.js @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - - - - word - - - + + + + word + + + ) export const output = ( - - - - wod - - - + + + + wod + + + ) diff --git a/packages/slate/test/commands/value/delete/join-blocks-with-inlines.js b/packages/slate/test/commands/value/delete/join-blocks-with-inlines.js index 06ed28adc9..bbb7f9e59c 100644 --- a/packages/slate/test/commands/value/delete/join-blocks-with-inlines.js +++ b/packages/slate/test/commands/value/delete/join-blocks-with-inlines.js @@ -8,23 +8,19 @@ export const run = editor => { export const input = ( - - - one - - - twothreefour - - + + one + + + twothreefour + ) export const output = ( - - - onetwothreefour - - + + onetwothreefour + ) diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js index 374e8c94ad..93f7abad7c 100644 --- a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js +++ b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js @@ -8,25 +8,21 @@ export const run = editor => { export const input = ( - - - one - - - - - two - + + one + + + + + two ) export const output = ( - - - - - two - + + + + two ) diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js index 0462eff862..9dcc0fd8cb 100644 --- a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js +++ b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js @@ -12,9 +12,9 @@ export const input = ( one - + - + three diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js index 0462eff862..9dcc0fd8cb 100644 --- a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js +++ b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js @@ -12,9 +12,9 @@ export const input = ( one - + - + three diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js index 18d189fa29..8c0215f4ac 100644 --- a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js +++ b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - - - one - - - three - + + one + + + + + three ) export const output = ( - - - on - - - three - + + on + + + + + three ) diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js index 6c13835158..a046eb4881 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js +++ b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js @@ -8,24 +8,20 @@ export const run = editor => { export const input = ( - - - - - one - - two - - + + + + one + + two + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js index 70bfeba857..fb173012fe 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js +++ b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + - + one two diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js index 5bc3cec4c5..9ebfa3d0ce 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js +++ b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + - + one diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js index 14050b2eb8..1b3120c8b4 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js +++ b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js @@ -8,25 +8,21 @@ export const run = editor => { export const input = ( - - - - - - two + + + + + two - three - + three ) export const output = ( - - - o + + o - three - + three ) diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js index 14050b2eb8..5f612d9147 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js +++ b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + - + two diff --git a/packages/slate/test/commands/value/delete/void-block-as-only.js b/packages/slate/test/commands/value/delete/void-block-as-only.js index 5386b69fa2..332b3d7dad 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-only.js +++ b/packages/slate/test/commands/value/delete/void-block-as-only.js @@ -8,17 +8,12 @@ export const run = editor => { export const input = ( - - - - - + + + ) export const output = ( - - - - + ) diff --git a/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js b/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js index e6d3d5d041..e72b73db9e 100644 --- a/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js +++ b/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - - - - - - one - two - + + + + + + + one + two ) export const output = ( - - - one - - two - + + one + + two ) diff --git a/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js b/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js index afe45571f7..1b8ab4d3bc 100644 --- a/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js +++ b/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js @@ -8,26 +8,24 @@ export const run = editor => { export const input = ( - - - - - - - one - - two - + + + + + + + + one + + two ) export const output = ( - - - one - - two - + + one + + two ) diff --git a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js b/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js index 6173a7d1d0..26c1c94943 100644 --- a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js +++ b/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js @@ -26,3 +26,5 @@ export const output = ( ) + +export const skip = true \ No newline at end of file diff --git a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js b/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js index 5765ca2f07..5fe0e0e66e 100644 --- a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js +++ b/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js @@ -24,3 +24,5 @@ export const output = ( ) + +export const skip = true \ No newline at end of file diff --git a/packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js b/packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js index ed59b1abdf..d705ad1e5a 100644 --- a/packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js +++ b/packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js @@ -28,3 +28,5 @@ export const output = ( ) + +export const skip = true \ No newline at end of file diff --git a/packages/slate/test/commands/value/delete/whole-inline.js b/packages/slate/test/commands/value/delete/whole-inline.js index 74697485a6..93c43ec015 100644 --- a/packages/slate/test/commands/value/delete/whole-inline.js +++ b/packages/slate/test/commands/value/delete/whole-inline.js @@ -9,9 +9,11 @@ export const run = editor => { export const input = ( + word + ) @@ -19,10 +21,11 @@ export const input = ( export const output = ( - + - + + ) diff --git a/packages/slate/test/commands/value/delete/whole-word-mark.js b/packages/slate/test/commands/value/delete/whole-word-mark.js index 128c2e9c61..27e28ba79d 100644 --- a/packages/slate/test/commands/value/delete/whole-word-mark.js +++ b/packages/slate/test/commands/value/delete/whole-word-mark.js @@ -10,9 +10,9 @@ export const input = ( - + word - +
@@ -22,9 +22,9 @@ export const output = ( - + - +
diff --git a/packages/slate/test/commands/value/insert-block/is-void-end.js b/packages/slate/test/commands/value/insert-block/is-void-end.js index 62beff7669..fb9431c122 100644 --- a/packages/slate/test/commands/value/insert-block/is-void-end.js +++ b/packages/slate/test/commands/value/insert-block/is-void-end.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + text - + text @@ -20,7 +20,7 @@ export const input = ( export const output = ( - text + text diff --git a/packages/slate/test/commands/value/insert-block/is-void-start.js b/packages/slate/test/commands/value/insert-block/is-void-start.js index a1161424b8..c1fb127a7f 100644 --- a/packages/slate/test/commands/value/insert-block/is-void-start.js +++ b/packages/slate/test/commands/value/insert-block/is-void-start.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + text - + text @@ -23,7 +23,7 @@ export const output = ( - text + text text diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js b/packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js index 4c404dc1be..7ecb501455 100644 --- a/packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js +++ b/packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js @@ -4,38 +4,32 @@ import { h } from '../../../helpers' export const run = editor => { editor.insertFragment( - - - b - u - i - - + + b + u + i + ) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wo - b - u - - i - - rd - - + + wo + b + u + + i + + rd + ) diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js b/packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js index cd470f2984..54322e52c3 100644 --- a/packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js +++ b/packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js @@ -4,34 +4,34 @@ import { h } from '../../../helpers' export const run = editor => { editor.insertFragment( - - - 2 - - + + + 2 + + ) } export const input = ( - - - - 1 - - - + + + + 1 + + + ) export const output = ( - - - - 12 - - - + + + + 12 + + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js b/packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js index 1723ee9cee..c503e8d19c 100644 --- a/packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js +++ b/packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js @@ -4,38 +4,38 @@ import { h } from '../../../helpers' export const run = editor => { editor.insertFragment( - - - bar - - + + + bar + + ) } export const input = ( - - - - Foobaz + + + + Foobaz - - + + ) export const output = ( - - - - Foo + + + + Foo - bar - - baz + bar + + baz - - + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js b/packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js index ece06d4594..b1f71e78ee 100644 --- a/packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js +++ b/packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js @@ -4,38 +4,38 @@ import { h } from '../../../helpers' export const run = editor => { editor.insertFragment( - - - bar - - + + + bar + + ) } export const input = ( - - - - Foobaz + + + + Foobaz - - + + ) export const output = ( - - - - Foo - - bar - - baz + + + + Foo + + bar + + baz - - + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js b/packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js index 24cc079b54..a69512f35d 100644 --- a/packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js +++ b/packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js @@ -4,38 +4,38 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - bar - - + + + bar + + ) } export const input = ( - - - - Foobaz + + + + Foobaz - - + + ) export const output = ( - - - - Foo + + + + Foo - bar - - baz + bar + + baz - - + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js b/packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js index 457f4ad090..61d18a0173 100644 --- a/packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js +++ b/packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js @@ -4,39 +4,39 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - 3 - 4 - - + + + 3 + 4 + + ) } export const input = ( - - - 1 - - 2 - - - + + + 1 + + 2 + + + ) export const output = ( - - - 1 - 23 - - 4 - - - + + + 1 + 23 + + 4 + + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/marks/middle-block.js b/packages/slate/test/commands/value/insert-fragment/marks/middle-block.js index a9be2b4223..7bb266072b 100644 --- a/packages/slate/test/commands/value/insert-fragment/marks/middle-block.js +++ b/packages/slate/test/commands/value/insert-fragment/marks/middle-block.js @@ -4,38 +4,38 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - bar - - + + + bar + + ) } export const input = ( - - - - Foobaz + + + + Foobaz - - + + ) export const output = ( - - - - Foo - - bar - - baz + + + + Foo + + bar + + baz - - + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js b/packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js index cbf26637eb..3dcfec34a5 100644 --- a/packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js +++ b/packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js @@ -4,38 +4,32 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - b - u - i - - + + b + u + i + ) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wo - b - u - - i - - rd - - + + wo + b + u + + i + + rd + ) diff --git a/packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js b/packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js index bdac1f7e63..f38245ab3e 100644 --- a/packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js +++ b/packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js @@ -4,47 +4,47 @@ import { h } from '../../../helpers' export const run = editor => { editor.insertFragment( - - - - 2 - - - 3 - - - + + + + 2 + + + 3 + + + ) } export const input = ( - - - - - 1 - - - - + + + + + 1 + + + + ) export const output = ( - - - - 12 - - - - 3 - - - - + + + + 12 + + + + 3 + + + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/merge-lists.js b/packages/slate/test/commands/value/insert-fragment/merge-lists.js index 6463ead4cc..f7aa6e4fa1 100644 --- a/packages/slate/test/commands/value/insert-fragment/merge-lists.js +++ b/packages/slate/test/commands/value/insert-fragment/merge-lists.js @@ -4,38 +4,38 @@ import { h } from '../../../helpers' export const run = editor => { editor.insertFragment( - - - 3 - 4 - - + + + 3 + 4 + + ) } export const input = ( - - - 1 - - 2 - - - + + + 1 + + 2 + + + ) export const output = ( - - - 1 - 23 - - 4 - - - + + + 1 + 23 + + 4 + + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js index 63088a10d3..a2dd095ee1 100644 --- a/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js +++ b/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js @@ -4,47 +4,47 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - - 2 - 3 - - - + + + + 2 + 3 + + + ) } export const input = ( - + + - + - - 1 - + 1 - + - + + ) export const output = ( - + + - + + 12 - 12 - - 3 - + 3 - + - + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js b/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js index 718b60b259..8e758dd256 100644 --- a/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js +++ b/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js @@ -4,36 +4,36 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - 2 - - + + + 2 + + ) } export const input = ( - - - - {'1 '} - - - - + + + + {'1 '} + + + + ) export const output = ( - - - - 1 2 - - - + + + + 1 2 + + + ) diff --git a/packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js b/packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js index f0ed510f9a..78ed272553 100644 --- a/packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js +++ b/packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js @@ -4,39 +4,39 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - - + + + + 1 - - + + 2 - - - -
+ + + + ) } export const input = ( - - - - + + + + - - + + - - - -
+ + + +
) @@ -44,25 +44,25 @@ export const input = ( // ideally, paragraph with "2" goes into second cell export const output = ( - - - - + + + + 1 - + 2 - - - + + + - - - -
+ + + +
) diff --git a/packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js b/packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js index 14be69aa5f..f4a374e816 100644 --- a/packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js +++ b/packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js @@ -4,52 +4,52 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - - - 1 - 2 - - -
- + + + + + 1 + 2 + + + + ) } export const input = ( - - - - - - - - - - -
- + + + + + + + + + + + +
) // TODO: paste "2" into second cell instead of creating new one? export const output = ( - - - - - 1 - - 2 - - - - -
- + + + + + 1 + + 2 + + + + + +
) diff --git a/packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js b/packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js index f3646d4905..71a4616cdd 100644 --- a/packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js +++ b/packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js @@ -4,53 +4,53 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - - - - - New 1 - New 2 - - -
- + + + + + New 1 + New 2 + + + + ) } export const input = ( - - - - - - {'Existing 1 '} - - - Existing 2 - - -
- + + + + + + {'Existing 1 '} + + + Existing 2 + + + +
) // TODO: paste "Existing 2" before / after "New 2" in second cell? export const output = ( - - - - - Existing 1 New 1 - - New 2 - - Existing 2 - - -
- + + + + + Existing 1 New 1 + + New 2 + + Existing 2 + + + +
) diff --git a/packages/slate/test/commands/value/insert-inline/is-void.js b/packages/slate/test/commands/value/insert-inline/is-void.js index b6235a95e2..6ef3f1406f 100644 --- a/packages/slate/test/commands/value/insert-inline/is-void.js +++ b/packages/slate/test/commands/value/insert-inline/is-void.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + - + ) @@ -19,9 +19,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/commands/value/insert-text/after-mark.js b/packages/slate/test/commands/value/insert-text/after-mark.js index d0a4f4b812..2a14edce7d 100644 --- a/packages/slate/test/commands/value/insert-text/after-mark.js +++ b/packages/slate/test/commands/value/insert-text/after-mark.js @@ -10,9 +10,9 @@ export const input = ( - w + w or - d +
d @@ -22,9 +22,9 @@ export const output = ( - w + w ora - d +
d diff --git a/packages/slate/test/commands/value/insert-text/before-mark.js b/packages/slate/test/commands/value/insert-text/before-mark.js index 5046ac9ec7..c92d1a735a 100644 --- a/packages/slate/test/commands/value/insert-text/before-mark.js +++ b/packages/slate/test/commands/value/insert-text/before-mark.js @@ -11,7 +11,7 @@ export const input = ( w - ord + ord @@ -22,7 +22,7 @@ export const output = ( wa - ord + ord diff --git a/packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js b/packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js index 69cfeb8eb1..07915d1107 100644 --- a/packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js +++ b/packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js @@ -8,34 +8,30 @@ export const run = editor => { export const input = ( - - - - Cat - - - - - Cute - - - + + + Cat + + + + + Cute + + ) export const output = ( - - - - Cat - - - - - is Cute - - - + + + Cat + + + + + is Cute + + ) diff --git a/packages/slate/test/commands/value/insert-text/during-mark.js b/packages/slate/test/commands/value/insert-text/during-mark.js index 7c43ab2d49..7d6d2efc65 100644 --- a/packages/slate/test/commands/value/insert-text/during-mark.js +++ b/packages/slate/test/commands/value/insert-text/during-mark.js @@ -10,9 +10,9 @@ export const input = ( - w + w or - d +
d @@ -22,9 +22,9 @@ export const output = ( - w + w oar - d +
d diff --git a/packages/slate/test/commands/value/insert-text/empty-block-with-mark.js b/packages/slate/test/commands/value/insert-text/empty-block-with-mark.js index da51140373..7ef1b5294a 100644 --- a/packages/slate/test/commands/value/insert-text/empty-block-with-mark.js +++ b/packages/slate/test/commands/value/insert-text/empty-block-with-mark.js @@ -10,9 +10,9 @@ export const input = ( - + - +
@@ -22,9 +22,9 @@ export const output = ( - + Cat - +
diff --git a/packages/slate/test/commands/value/insert-text/expanded-with-mark.js b/packages/slate/test/commands/value/insert-text/expanded-with-mark.js index d41dfd3029..dedf2eca41 100644 --- a/packages/slate/test/commands/value/insert-text/expanded-with-mark.js +++ b/packages/slate/test/commands/value/insert-text/expanded-with-mark.js @@ -11,9 +11,9 @@ export const input = ( - + lorem - + ipsum diff --git a/packages/slate/test/commands/value/insert-text/inside-void.js b/packages/slate/test/commands/value/insert-text/inside-void.js index 6a85366c06..d095709541 100644 --- a/packages/slate/test/commands/value/insert-text/inside-void.js +++ b/packages/slate/test/commands/value/insert-text/inside-void.js @@ -9,9 +9,9 @@ export const run = editor => { export const input = ( - + - + ) @@ -19,9 +19,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/commands/value/insert-text/with-marks.js b/packages/slate/test/commands/value/insert-text/with-marks.js index 09fb6d261b..48a50366c7 100644 --- a/packages/slate/test/commands/value/insert-text/with-marks.js +++ b/packages/slate/test/commands/value/insert-text/with-marks.js @@ -22,7 +22,7 @@ export const output = ( - worda + worda diff --git a/packages/slate/test/commands/value/remove-mark/across-blocks.js b/packages/slate/test/commands/value/remove-mark/across-blocks.js index 415d5437cf..7f4d33916a 100644 --- a/packages/slate/test/commands/value/remove-mark/across-blocks.js +++ b/packages/slate/test/commands/value/remove-mark/across-blocks.js @@ -11,10 +11,10 @@ export const input = ( wo - rd + rd - an + an other diff --git a/packages/slate/test/commands/value/remove-mark/across-inlines.js b/packages/slate/test/commands/value/remove-mark/across-inlines.js index 4d8522c4e0..3ef729d3f4 100644 --- a/packages/slate/test/commands/value/remove-mark/across-inlines.js +++ b/packages/slate/test/commands/value/remove-mark/across-inlines.js @@ -12,12 +12,12 @@ export const input = ( wo - rd + rd - an + an other diff --git a/packages/slate/test/commands/value/remove-mark/collapsed-selection.js b/packages/slate/test/commands/value/remove-mark/collapsed-selection.js index 044c4c492f..216686bbf8 100644 --- a/packages/slate/test/commands/value/remove-mark/collapsed-selection.js +++ b/packages/slate/test/commands/value/remove-mark/collapsed-selection.js @@ -3,27 +3,23 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('bold') + editor.addMarks([{ key: 'a' }]) editor.removeMark('bold') editor.insertText('a') } export const input = ( - - - word - - + + word + ) export const output = ( - - - aword - - + + aword + ) diff --git a/packages/slate/test/commands/value/remove-mark/existing-marks.js b/packages/slate/test/commands/value/remove-mark/existing-marks.js index f0e11f6006..87f73f54fd 100644 --- a/packages/slate/test/commands/value/remove-mark/existing-marks.js +++ b/packages/slate/test/commands/value/remove-mark/existing-marks.js @@ -8,28 +8,24 @@ export const run = editor => { export const input = ( - - - - - wo - - - rd - - - + + + + wo + + + rd + + ) export const output = ( - - - - word - - - + + + word + + ) diff --git a/packages/slate/test/commands/value/remove-mark/first-character.js b/packages/slate/test/commands/value/remove-mark/first-character.js index c4ddd4e775..e74a87b614 100644 --- a/packages/slate/test/commands/value/remove-mark/first-character.js +++ b/packages/slate/test/commands/value/remove-mark/first-character.js @@ -11,7 +11,7 @@ export const input = ( - w + w ord diff --git a/packages/slate/test/commands/value/remove-mark/last-character.js b/packages/slate/test/commands/value/remove-mark/last-character.js index 08958e5ab5..5c5d0e72cf 100644 --- a/packages/slate/test/commands/value/remove-mark/last-character.js +++ b/packages/slate/test/commands/value/remove-mark/last-character.js @@ -11,9 +11,9 @@ export const input = ( wor - + d - + diff --git a/packages/slate/test/commands/value/remove-mark/middle-character.js b/packages/slate/test/commands/value/remove-mark/middle-character.js index d1df242c12..00fbb14560 100644 --- a/packages/slate/test/commands/value/remove-mark/middle-character.js +++ b/packages/slate/test/commands/value/remove-mark/middle-character.js @@ -11,9 +11,9 @@ export const input = ( w - + o - + rd diff --git a/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js b/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js index 6563a055a9..4afb60a4ff 100644 --- a/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js +++ b/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js @@ -10,9 +10,9 @@ export const input = ( - + word - + @@ -22,7 +22,7 @@ export const output = ( - wor + wor d diff --git a/packages/slate/test/commands/value/remove-mark/part-of-mark.js b/packages/slate/test/commands/value/remove-mark/part-of-mark.js index 5e6bfd6f91..c7a7b7daf4 100644 --- a/packages/slate/test/commands/value/remove-mark/part-of-mark.js +++ b/packages/slate/test/commands/value/remove-mark/part-of-mark.js @@ -10,9 +10,9 @@ export const input = ( - + word - + @@ -22,7 +22,7 @@ export const output = ( - wor + wor d diff --git a/packages/slate/test/commands/value/remove-mark/whole-word.js b/packages/slate/test/commands/value/remove-mark/whole-word.js index 3a5a3e0de4..b1f27efedc 100644 --- a/packages/slate/test/commands/value/remove-mark/whole-word.js +++ b/packages/slate/test/commands/value/remove-mark/whole-word.js @@ -11,7 +11,7 @@ export const input = ( - word + word diff --git a/packages/slate/test/commands/value/remove-mark/with-mark-object.js b/packages/slate/test/commands/value/remove-mark/with-mark-object.js index 44cc6e7e81..fffe165ffd 100644 --- a/packages/slate/test/commands/value/remove-mark/with-mark-object.js +++ b/packages/slate/test/commands/value/remove-mark/with-mark-object.js @@ -17,7 +17,7 @@ export const input = ( - w + w ord diff --git a/packages/slate/test/commands/value/remove-mark/with-plain-object.js b/packages/slate/test/commands/value/remove-mark/with-plain-object.js index d4dc93d4fb..088c99afcc 100644 --- a/packages/slate/test/commands/value/remove-mark/with-plain-object.js +++ b/packages/slate/test/commands/value/remove-mark/with-plain-object.js @@ -15,7 +15,7 @@ export const input = ( w - ord + ord diff --git a/packages/slate/test/commands/value/replace-mark/across-blocks.js b/packages/slate/test/commands/value/replace-mark/across-blocks.js index 6553592a1a..dd668f95e5 100644 --- a/packages/slate/test/commands/value/replace-mark/across-blocks.js +++ b/packages/slate/test/commands/value/replace-mark/across-blocks.js @@ -8,34 +8,30 @@ export const run = editor => { export const input = ( - - - wo - - rd - - - - an - other - - + + wo + + rd + + + + an + other + ) export const output = ( - - - wo - - rd - - - - an - other - - + + wo + + rd + + + + an + other + ) diff --git a/packages/slate/test/commands/value/replace-mark/across-inlines.js b/packages/slate/test/commands/value/replace-mark/across-inlines.js index 6fa140be58..e3f1ea786e 100644 --- a/packages/slate/test/commands/value/replace-mark/across-inlines.js +++ b/packages/slate/test/commands/value/replace-mark/across-inlines.js @@ -8,50 +8,46 @@ export const run = editor => { export const input = ( - - - - - wo - - rd - - - - - - - - an - other - - - - + + + + wo + + rd + + + + + + + + an + other + + + ) export const output = ( - - - - - wo - - rd - - - - - - - - an - other - - - - + + + + wo + + rd + + + + + + + + an + other + + + ) diff --git a/packages/slate/test/commands/value/replace-mark/existing-marks.js b/packages/slate/test/commands/value/replace-mark/existing-marks.js index dd589775e3..46de594fc6 100644 --- a/packages/slate/test/commands/value/replace-mark/existing-marks.js +++ b/packages/slate/test/commands/value/replace-mark/existing-marks.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - wo - - rd - - - + + + wo + + rd + + ) diff --git a/packages/slate/test/commands/value/replace-mark/first-character.js b/packages/slate/test/commands/value/replace-mark/first-character.js index 3605388a8c..05a48f3ecf 100644 --- a/packages/slate/test/commands/value/replace-mark/first-character.js +++ b/packages/slate/test/commands/value/replace-mark/first-character.js @@ -8,24 +8,20 @@ export const run = editor => { export const input = ( - - - - w - ord - - + + + w + ord + ) export const output = ( - - - - w - ord - - + + + w + ord + ) diff --git a/packages/slate/test/commands/value/replace-mark/last-character.js b/packages/slate/test/commands/value/replace-mark/last-character.js index f0fe948ab7..c592127b31 100644 --- a/packages/slate/test/commands/value/replace-mark/last-character.js +++ b/packages/slate/test/commands/value/replace-mark/last-character.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - - - wor - - d - - - + + wor + + d + + ) export const output = ( - - - wor - - d - - - + + wor + + d + + ) diff --git a/packages/slate/test/commands/value/replace-mark/middle-character.js b/packages/slate/test/commands/value/replace-mark/middle-character.js index 027e5ac5d3..1fc1224975 100644 --- a/packages/slate/test/commands/value/replace-mark/middle-character.js +++ b/packages/slate/test/commands/value/replace-mark/middle-character.js @@ -8,28 +8,24 @@ export const run = editor => { export const input = ( - - - w - - o - - rd - - + + w + + o + + rd + ) export const output = ( - - - w - - o - - rd - - + + w + + o + + rd + ) diff --git a/packages/slate/test/commands/value/replace-mark/whole-word.js b/packages/slate/test/commands/value/replace-mark/whole-word.js index 86b2666a18..241db14bf9 100644 --- a/packages/slate/test/commands/value/replace-mark/whole-word.js +++ b/packages/slate/test/commands/value/replace-mark/whole-word.js @@ -8,24 +8,20 @@ export const run = editor => { export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - word - - - + + + word + + ) diff --git a/packages/slate/test/commands/value/replace-mark/with-mark-object.js b/packages/slate/test/commands/value/replace-mark/with-mark-object.js index 7f9dad4ca6..610f79075e 100644 --- a/packages/slate/test/commands/value/replace-mark/with-mark-object.js +++ b/packages/slate/test/commands/value/replace-mark/with-mark-object.js @@ -18,9 +18,9 @@ export const input = ( - + w - + ord @@ -33,7 +33,7 @@ export const output = ( w - + ord diff --git a/packages/slate/test/commands/value/replace-mark/with-plain-object.js b/packages/slate/test/commands/value/replace-mark/with-plain-object.js index 97cb070abe..512f660443 100644 --- a/packages/slate/test/commands/value/replace-mark/with-plain-object.js +++ b/packages/slate/test/commands/value/replace-mark/with-plain-object.js @@ -13,9 +13,9 @@ export const input = ( - + w - + ord @@ -28,7 +28,7 @@ export const output = ( w - + ord diff --git a/packages/slate/test/commands/value/set-block/across-blocks.js b/packages/slate/test/commands/value/set-block/across-blocks.js index 741cac49ea..019ed31030 100644 --- a/packages/slate/test/commands/value/set-block/across-blocks.js +++ b/packages/slate/test/commands/value/set-block/across-blocks.js @@ -8,26 +8,26 @@ export const run = editor => { export const input = ( - - - word + + + word - - another + + another - + ) export const output = ( - - - word - - - another - - + + + word + + + another + + ) diff --git a/packages/slate/test/commands/value/set-block/across-inlines.js b/packages/slate/test/commands/value/set-block/across-inlines.js index 7801b45adb..d0e177aae9 100644 --- a/packages/slate/test/commands/value/set-block/across-inlines.js +++ b/packages/slate/test/commands/value/set-block/across-inlines.js @@ -23,15 +23,15 @@ export const input = ( export const output = ( - + word - - + + another - + ) diff --git a/packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js b/packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js index 715d9f867a..95b5609fbb 100644 --- a/packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js +++ b/packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js @@ -23,11 +23,11 @@ export const input = ( export const output = ( - + word - + another diff --git a/packages/slate/test/commands/value/set-block/hanging-selection.js b/packages/slate/test/commands/value/set-block/hanging-selection.js index ce01abb3b1..cbb890927f 100644 --- a/packages/slate/test/commands/value/set-block/hanging-selection.js +++ b/packages/slate/test/commands/value/set-block/hanging-selection.js @@ -8,26 +8,26 @@ export const run = editor => { export const input = ( - - - word + + + word - - another + + another - + ) export const output = ( - - - word - - - another + + + word - + + another + + ) diff --git a/packages/slate/test/commands/value/set-block/nested-block.js b/packages/slate/test/commands/value/set-block/nested-block.js index ecddb2bbec..91a10275bc 100644 --- a/packages/slate/test/commands/value/set-block/nested-block.js +++ b/packages/slate/test/commands/value/set-block/nested-block.js @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - + + - - word + word - - + + ) export const output = ( - + + - - word - - - + word + + + ) diff --git a/packages/slate/test/commands/value/set-block/single-block-string-shorthand.js b/packages/slate/test/commands/value/set-block/single-block-string-shorthand.js index 5f2ccc6939..bff9cf2aba 100644 --- a/packages/slate/test/commands/value/set-block/single-block-string-shorthand.js +++ b/packages/slate/test/commands/value/set-block/single-block-string-shorthand.js @@ -8,20 +8,20 @@ export const run = editor => { export const input = ( - - - word + + + word - + ) export const output = ( - - - word - - + + + word + + ) diff --git a/packages/slate/test/commands/value/set-block/single-block.js b/packages/slate/test/commands/value/set-block/single-block.js index 45837478ed..85f2af1857 100644 --- a/packages/slate/test/commands/value/set-block/single-block.js +++ b/packages/slate/test/commands/value/set-block/single-block.js @@ -8,20 +8,20 @@ export const run = editor => { export const input = ( - - - word + + + word - + ) export const output = ( - - - word - - + + + word + + ) diff --git a/packages/slate/test/commands/value/set-block/with-data-as-map.js b/packages/slate/test/commands/value/set-block/with-data-as-map.js index d333db09b2..c46bc4d868 100644 --- a/packages/slate/test/commands/value/set-block/with-data-as-map.js +++ b/packages/slate/test/commands/value/set-block/with-data-as-map.js @@ -12,20 +12,20 @@ export const run = editor => { export const input = ( - - - word + + + word - + ) export const output = ( - - - word - - + + + word + + ) diff --git a/packages/slate/test/commands/value/set-block/with-data-as-object.js b/packages/slate/test/commands/value/set-block/with-data-as-object.js index 523efab745..83424a793b 100644 --- a/packages/slate/test/commands/value/set-block/with-data-as-object.js +++ b/packages/slate/test/commands/value/set-block/with-data-as-object.js @@ -11,20 +11,20 @@ export const run = editor => { export const input = ( - - - word + + + word - + ) export const output = ( - - - word - - + + + word + + ) diff --git a/packages/slate/test/commands/value/set-block/with-is-void.js b/packages/slate/test/commands/value/set-block/with-is-void.js index 64c81324b4..58cccfabaf 100644 --- a/packages/slate/test/commands/value/set-block/with-is-void.js +++ b/packages/slate/test/commands/value/set-block/with-is-void.js @@ -19,9 +19,9 @@ export const input = ( export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/value/set-inline/nested-inline.js b/packages/slate/test/commands/value/set-inline/nested-inline.js index b707bc8bed..70bc04eb39 100644 --- a/packages/slate/test/commands/value/set-inline/nested-inline.js +++ b/packages/slate/test/commands/value/set-inline/nested-inline.js @@ -9,13 +9,13 @@ export const run = editor => { export const input = ( - + + - - word + word - - + + ) @@ -23,13 +23,13 @@ export const input = ( export const output = ( - + + - - word - - - + word + + + ) diff --git a/packages/slate/test/commands/value/split-block/with-marks.js b/packages/slate/test/commands/value/split-block/with-marks.js index aa35e2051e..873ebdf1dc 100644 --- a/packages/slate/test/commands/value/split-block/with-marks.js +++ b/packages/slate/test/commands/value/split-block/with-marks.js @@ -3,35 +3,31 @@ import { h } from '../../../helpers' export const run = editor => { - editor.addMark('italic') + editor.addMarks([{ key: 'b' }]) editor.splitBlock() editor.insertText('cat is cute') } export const input = ( - - - word - - - + + word + + ) export const output = ( - - - word - - - - - cat is cute - - - - + + word + + + + + cat is cute + + + ) diff --git a/packages/slate/test/commands/value/split-inline/with-marks.js b/packages/slate/test/commands/value/split-inline/with-marks.js index 037ac5dac0..4032e24ea5 100644 --- a/packages/slate/test/commands/value/split-inline/with-marks.js +++ b/packages/slate/test/commands/value/split-inline/with-marks.js @@ -10,9 +10,9 @@ export const input = ( - + word - + @@ -22,12 +22,12 @@ export const output = ( - wo + wo - + rd - + diff --git a/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js b/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js index 8ad56ff2f2..c811dfbc48 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js +++ b/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js @@ -24,12 +24,12 @@ export const output = ( wo - + rd - + - an + an other diff --git a/packages/slate/test/commands/value/toggle-mark/add-across-inlines.js b/packages/slate/test/commands/value/toggle-mark/add-across-inlines.js index a7e9d1f65a..125e61f791 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-across-inlines.js +++ b/packages/slate/test/commands/value/toggle-mark/add-across-inlines.js @@ -31,16 +31,16 @@ export const output = ( wo - + rd - + - + - + - an + an other diff --git a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js index 872dff91f9..707caf3317 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js +++ b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js @@ -21,7 +21,7 @@ export const output = ( - a + a word diff --git a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js index b5c60bb12d..73d1b75c5c 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js +++ b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js @@ -21,9 +21,9 @@ export const output = ( - word + word s - + diff --git a/packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js b/packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js index 2a2c5594f6..9a3802c376 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js +++ b/packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js @@ -8,33 +8,29 @@ export const run = editor => { export const input = ( - - - - a - - - word - - - + + + a + + + word + + ) export const output = ( - - - - a - - - wo - - - rd - - - + + + a + + + wo + + + rd + + ) diff --git a/packages/slate/test/commands/value/toggle-mark/add-existing-marks.js b/packages/slate/test/commands/value/toggle-mark/add-existing-marks.js index a6c69502ea..f5fe953eb0 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-existing-marks.js +++ b/packages/slate/test/commands/value/toggle-mark/add-existing-marks.js @@ -8,29 +8,25 @@ export const run = editor => { export const input = ( - - - - word - - - + + + word + + ) export const output = ( - - - - - wo - - - - rd - - - + + + + wo + + + + rd + + ) diff --git a/packages/slate/test/commands/value/toggle-mark/add-first-character.js b/packages/slate/test/commands/value/toggle-mark/add-first-character.js index 304c517350..64a5097856 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-first-character.js +++ b/packages/slate/test/commands/value/toggle-mark/add-first-character.js @@ -20,9 +20,9 @@ export const output = ( - + w - + ord diff --git a/packages/slate/test/commands/value/toggle-mark/add-last-character.js b/packages/slate/test/commands/value/toggle-mark/add-last-character.js index 26d78cdef5..2a39040a5e 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-last-character.js +++ b/packages/slate/test/commands/value/toggle-mark/add-last-character.js @@ -21,9 +21,9 @@ export const output = ( wor - + d - + diff --git a/packages/slate/test/commands/value/toggle-mark/add-middle-character.js b/packages/slate/test/commands/value/toggle-mark/add-middle-character.js index e34fe4355d..c8493df4d7 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-middle-character.js +++ b/packages/slate/test/commands/value/toggle-mark/add-middle-character.js @@ -21,9 +21,9 @@ export const output = ( w - + o - + rd diff --git a/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js b/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js index 4d5c6f1a1b..11458010c1 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js +++ b/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js @@ -10,9 +10,9 @@ export const input = ( - a + a word - + @@ -22,9 +22,9 @@ export const output = ( - + aword - + diff --git a/packages/slate/test/commands/value/toggle-mark/add-whole-word.js b/packages/slate/test/commands/value/toggle-mark/add-whole-word.js index ee5fed3734..65764c4934 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-whole-word.js +++ b/packages/slate/test/commands/value/toggle-mark/add-whole-word.js @@ -20,9 +20,9 @@ export const output = ( - + word - + diff --git a/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js b/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js index 6f900d6620..34fe3acde3 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js +++ b/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js @@ -28,7 +28,7 @@ export const output = ( w - + ord diff --git a/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js b/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js index 70679e0ddb..b4895a0c7b 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js +++ b/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js @@ -25,7 +25,7 @@ export const output = ( w - + ord diff --git a/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js b/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js index b75322c74a..2ec1c7fb53 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js @@ -11,12 +11,12 @@ export const input = ( wo - + rd - + - an + an other diff --git a/packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js b/packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js index 6bacfb328f..878ca7f750 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js @@ -11,16 +11,16 @@ export const input = ( - wo + wo rd - + - an + an other diff --git a/packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js b/packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js index 8a6a25165f..18436241c0 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js @@ -8,29 +8,25 @@ export const run = editor => { export const input = ( - - - - - wo - - - - rd - - - + + + + wo + + + + rd + + ) export const output = ( - - - - word - - - + + + word + + ) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-first-character.js b/packages/slate/test/commands/value/toggle-mark/remove-first-character.js index 426378a0b2..10dde2f211 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-first-character.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-first-character.js @@ -10,9 +10,9 @@ export const input = ( - + w - + ord diff --git a/packages/slate/test/commands/value/toggle-mark/remove-last-character.js b/packages/slate/test/commands/value/toggle-mark/remove-last-character.js index 28db502993..89ecfdcdb3 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-last-character.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-last-character.js @@ -11,9 +11,9 @@ export const input = ( wor - + d - + diff --git a/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js b/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js index eb00badafc..4d2b8413f5 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js @@ -11,9 +11,9 @@ export const input = ( w - + o - + rd diff --git a/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js b/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js index eac798ff5f..47b2df843c 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js @@ -10,9 +10,9 @@ export const input = ( - + word - + diff --git a/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js b/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js index 814aa99eca..8e3fda2c97 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js @@ -18,7 +18,7 @@ export const input = ( w - + ord diff --git a/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js b/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js index 58288e047d..1a376d06a3 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js +++ b/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js @@ -15,7 +15,7 @@ export const input = ( w - + ord diff --git a/packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js b/packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js index fa887e6f42..c883a42173 100644 --- a/packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js +++ b/packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js @@ -12,9 +12,9 @@ export const input = ( - + hello - + @@ -29,21 +29,21 @@ export const output = ( - he + he - + ll - + - + o - + diff --git a/packages/slate/test/history/undo/add-mark-across-blocks.js b/packages/slate/test/history/undo/add-mark-across-blocks.js index 7f37eac94f..ca514925f3 100644 --- a/packages/slate/test/history/undo/add-mark-across-blocks.js +++ b/packages/slate/test/history/undo/add-mark-across-blocks.js @@ -2,8 +2,8 @@ import h from '../../helpers/h' -export default function(editor) { - editor.addMark('bold') +export default function (editor) { + editor.addMarks([{ key: 'a' }]) editor.flush() editor.undo() } @@ -11,12 +11,12 @@ export default function(editor) { export const input = ( - + one - - + + two - + ) diff --git a/packages/slate/test/history/undo/add-mark-across-marks.js b/packages/slate/test/history/undo/add-mark-across-marks.js index 434c4fb99a..a2a0c9e3fd 100644 --- a/packages/slate/test/history/undo/add-mark-across-marks.js +++ b/packages/slate/test/history/undo/add-mark-across-marks.js @@ -2,8 +2,8 @@ import h from '../../helpers/h' -export default function(editor) { - editor.addMark('bold') +export default function (editor) { + editor.addMarks([{ key: 'a' }]) editor.flush() editor.undo() } @@ -11,11 +11,11 @@ export default function(editor) { export const input = ( - - + + wo - rd - + rd + ) diff --git a/packages/slate/test/history/undo/add-mark-across-same-mark.js b/packages/slate/test/history/undo/add-mark-across-same-mark.js index 9f0c6e1b64..4d16bf27b8 100644 --- a/packages/slate/test/history/undo/add-mark-across-same-mark.js +++ b/packages/slate/test/history/undo/add-mark-across-same-mark.js @@ -2,8 +2,8 @@ import h from '../../helpers/h' -export default function(editor) { - editor.addMark('bold') +export default function (editor) { + editor.addMarks([{ key: 'a' }]) editor.flush() editor.undo() } @@ -11,11 +11,11 @@ export default function(editor) { export const input = ( - - + + wo - rd - + rd + ) diff --git a/packages/slate/test/history/undo/add-mark.js b/packages/slate/test/history/undo/add-mark.js index efddf6dd39..236fc83094 100644 --- a/packages/slate/test/history/undo/add-mark.js +++ b/packages/slate/test/history/undo/add-mark.js @@ -2,8 +2,8 @@ import h from '../../helpers/h' -export default function(editor) { - editor.addMark('bold') +export default function (editor) { + editor.addMarks([{ key: 'a' }]) editor.flush() editor.undo() } @@ -11,9 +11,9 @@ export default function(editor) { export const input = ( - + word - + ) diff --git a/packages/slate/test/history/undo/delete-across-blocks.js b/packages/slate/test/history/undo/delete-across-blocks.js index f257340e1e..106ad26a24 100644 --- a/packages/slate/test/history/undo/delete-across-blocks.js +++ b/packages/slate/test/history/undo/delete-across-blocks.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.delete() editor.flush() editor.undo() @@ -15,10 +15,10 @@ export const input = ( one - + two - + ) diff --git a/packages/slate/test/history/undo/delete-across-inlines.js b/packages/slate/test/history/undo/delete-across-inlines.js index b573ea546b..aeed2562ec 100644 --- a/packages/slate/test/history/undo/delete-across-inlines.js +++ b/packages/slate/test/history/undo/delete-across-inlines.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.delete() editor.flush() editor.undo() @@ -11,20 +11,20 @@ export default function(editor) { export const input = ( - + one - + - - + + two - + - + ) diff --git a/packages/slate/test/history/undo/delete-across-marks.js b/packages/slate/test/history/undo/delete-across-marks.js index 2ea9eceb1a..0f85d20bdc 100644 --- a/packages/slate/test/history/undo/delete-across-marks.js +++ b/packages/slate/test/history/undo/delete-across-marks.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.delete() editor.flush() editor.undo() @@ -11,14 +11,14 @@ export default function(editor) { export const input = ( - - + + one - - + + two - - + + ) diff --git a/packages/slate/test/history/undo/delete-backward-nested-blocks.js b/packages/slate/test/history/undo/delete-backward-nested-blocks.js index 9ff9012dc1..71da483ccd 100644 --- a/packages/slate/test/history/undo/delete-backward-nested-blocks.js +++ b/packages/slate/test/history/undo/delete-backward-nested-blocks.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.deleteBackward() editor.undo() } @@ -10,12 +10,12 @@ export default function(editor) { export const input = ( - Hello - - + Hello + + world! - - + + ) @@ -23,12 +23,12 @@ export const input = ( export const output = ( - Hello - - + Hello + + world! - - + + ) diff --git a/packages/slate/test/history/undo/delete-backward.js b/packages/slate/test/history/undo/delete-backward.js index eae8de6874..840d2572db 100644 --- a/packages/slate/test/history/undo/delete-backward.js +++ b/packages/slate/test/history/undo/delete-backward.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.deleteBackward() editor.undo() } @@ -10,10 +10,10 @@ export default function(editor) { export const input = ( - Hello - + Hello + world! - + ) @@ -21,10 +21,10 @@ export const input = ( export const output = ( - Hello - + Hello + world! - + ) diff --git a/packages/slate/test/history/undo/delete.js b/packages/slate/test/history/undo/delete.js index 2ae6806520..25df4beb00 100644 --- a/packages/slate/test/history/undo/delete.js +++ b/packages/slate/test/history/undo/delete.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.delete() editor.flush() editor.undo() @@ -11,9 +11,9 @@ export default function(editor) { export const input = ( - + word - + ) diff --git a/packages/slate/test/history/undo/insert-block.js b/packages/slate/test/history/undo/insert-block.js index 5011a7f81a..c9f06c2d7d 100644 --- a/packages/slate/test/history/undo/insert-block.js +++ b/packages/slate/test/history/undo/insert-block.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.insertBlock('quote') editor.flush() editor.undo() @@ -11,9 +11,9 @@ export default function(editor) { export const input = ( - + one - + ) diff --git a/packages/slate/test/history/undo/insert-fragment.js b/packages/slate/test/history/undo/insert-fragment.js index f151066a34..354353cd78 100644 --- a/packages/slate/test/history/undo/insert-fragment.js +++ b/packages/slate/test/history/undo/insert-fragment.js @@ -5,25 +5,25 @@ import h from '../../helpers/h' const fragment = ( - A + A - B - + B + - C + C - + - D + D ) -export default function(editor) { +export default function (editor) { editor.insertFragment(fragment) editor.flush() editor.undo() @@ -33,11 +33,11 @@ export const input = ( - + - + diff --git a/packages/slate/test/history/undo/insert-text-contiguous.js b/packages/slate/test/history/undo/insert-text-contiguous.js index cae034da0e..8ebebbcb8c 100644 --- a/packages/slate/test/history/undo/insert-text-contiguous.js +++ b/packages/slate/test/history/undo/insert-text-contiguous.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.insertText('t') editor.flush() editor.insertText('w') @@ -15,9 +15,9 @@ export default function(editor) { export const input = ( - + one - + ) diff --git a/packages/slate/test/history/undo/insert-text-not-contiguous.js b/packages/slate/test/history/undo/insert-text-not-contiguous.js index def6c4beab..368a0a4e0f 100644 --- a/packages/slate/test/history/undo/insert-text-not-contiguous.js +++ b/packages/slate/test/history/undo/insert-text-not-contiguous.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.insertText('t') editor.flush() @@ -20,9 +20,9 @@ export default function(editor) { export const input = ( - + one - + ) @@ -30,9 +30,9 @@ export const input = ( export const output = ( - + onewt - + ) diff --git a/packages/slate/test/history/undo/insert-text.js b/packages/slate/test/history/undo/insert-text.js index 98d78c4bb0..f857404a39 100644 --- a/packages/slate/test/history/undo/insert-text.js +++ b/packages/slate/test/history/undo/insert-text.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.insertText('text') editor.flush() editor.undo() @@ -11,9 +11,9 @@ export default function(editor) { export const input = ( - + one - + ) diff --git a/packages/slate/test/history/undo/move-node-affecting-path.js b/packages/slate/test/history/undo/move-node-affecting-path.js index dd587fbf65..d1d8f7f14f 100644 --- a/packages/slate/test/history/undo/move-node-affecting-path.js +++ b/packages/slate/test/history/undo/move-node-affecting-path.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.moveNodeByPath(PathUtils.create([1]), PathUtils.create([2, 1])) editor.flush() editor.undo() @@ -12,12 +12,12 @@ export default function(editor) { export const input = ( - one - two + one + two - three - - four + three + + four ) diff --git a/packages/slate/test/history/undo/move-node-before-itself.js b/packages/slate/test/history/undo/move-node-before-itself.js index 39d1fcc10f..61c5aca2f6 100644 --- a/packages/slate/test/history/undo/move-node-before-itself.js +++ b/packages/slate/test/history/undo/move-node-before-itself.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.moveNodeByPath(PathUtils.create([1, 1, 2]), PathUtils.create([0])) editor.flush() editor.undo() @@ -12,17 +12,17 @@ export default function(editor) { export const input = ( - one + one - two + two - three - four - five - - - six - seven + three + four + five + + + six + seven ) diff --git a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js b/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js index 4e54465267..aadd933151 100644 --- a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js +++ b/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1, 1])) editor.flush() editor.undo() @@ -12,12 +12,12 @@ export default function(editor) { export const input = ( - + I am gonna move - - - I am an existing node in newParent - + + + I am an existing node in newParent + ) diff --git a/packages/slate/test/history/undo/move-node-by-path.js b/packages/slate/test/history/undo/move-node-by-path.js index 662c7eecc7..b267f27dda 100644 --- a/packages/slate/test/history/undo/move-node-by-path.js +++ b/packages/slate/test/history/undo/move-node-by-path.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.moveNodeByPath(PathUtils.create([0, 0]), PathUtils.create([1, 1])) editor.flush() editor.undo() @@ -12,12 +12,12 @@ export default function(editor) { export const input = ( - - I am gonna move - - - I am an existing node at newPath - + + I am gonna move + + + I am an existing node at newPath + ) diff --git a/packages/slate/test/history/undo/remove-mark.js b/packages/slate/test/history/undo/remove-mark.js index 5dd751bea2..e1dbad4f8c 100644 --- a/packages/slate/test/history/undo/remove-mark.js +++ b/packages/slate/test/history/undo/remove-mark.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.removeMark('bold') editor.flush() editor.undo() @@ -11,11 +11,11 @@ export default function(editor) { export const input = ( - - + + one - - + + ) diff --git a/packages/slate/test/history/undo/remove-node-by-path.js b/packages/slate/test/history/undo/remove-node-by-path.js index 5fd84229db..8fddc626d7 100644 --- a/packages/slate/test/history/undo/remove-node-by-path.js +++ b/packages/slate/test/history/undo/remove-node-by-path.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.removeNodeByPath(PathUtils.create([0])) editor.flush() editor.undo() @@ -12,7 +12,7 @@ export default function(editor) { export const input = ( - one + one ) diff --git a/packages/slate/test/history/undo/remove-text.js b/packages/slate/test/history/undo/remove-text.js index 77f9d7493f..6e03eca531 100644 --- a/packages/slate/test/history/undo/remove-text.js +++ b/packages/slate/test/history/undo/remove-text.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.moveAnchorForward(4) editor.moveFocusForward(7) editor.delete() @@ -13,9 +13,9 @@ export default function(editor) { export const input = ( - + one two - + ) @@ -23,9 +23,9 @@ export const input = ( export const output = ( - + one two - + ) diff --git a/packages/slate/test/history/undo/set-node-by-path-with-data.js b/packages/slate/test/history/undo/set-node-by-path-with-data.js index 81bf2fc734..99011e5634 100644 --- a/packages/slate/test/history/undo/set-node-by-path-with-data.js +++ b/packages/slate/test/history/undo/set-node-by-path-with-data.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.setNodeByPath(PathUtils.create([0]), { data: { thing: 'value' }, }) @@ -15,7 +15,7 @@ export default function(editor) { export const input = ( - one + one ) diff --git a/packages/slate/test/history/undo/split-node-by-path-block.js b/packages/slate/test/history/undo/split-node-by-path-block.js index c5db5582d2..e445f8c173 100644 --- a/packages/slate/test/history/undo/split-node-by-path-block.js +++ b/packages/slate/test/history/undo/split-node-by-path-block.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.splitNodeByPath(PathUtils.create([0]), 2) editor.flush() editor.undo() @@ -14,13 +14,13 @@ export const input = ( - one + one - two + two - + ) diff --git a/packages/slate/test/history/undo/toggle-mark.js b/packages/slate/test/history/undo/toggle-mark.js index 74d446dc30..8b4204e4cc 100644 --- a/packages/slate/test/history/undo/toggle-mark.js +++ b/packages/slate/test/history/undo/toggle-mark.js @@ -2,8 +2,8 @@ import h from '../../helpers/h' -export default function(editor) { - editor.addMark('bold') +export default function (editor) { + editor.addMarks([{ key: 'a' }]) editor.flush() editor.removeMark('bold') editor.flush() @@ -13,9 +13,9 @@ export default function(editor) { export const input = ( - + one two three - + ) @@ -23,13 +23,13 @@ export const input = ( export const output = ( - + one{' '} - + two - + three - + ) diff --git a/packages/slate/test/history/undo/unwrap-node-by-path.js b/packages/slate/test/history/undo/unwrap-node-by-path.js index 421bdff407..12e978da81 100644 --- a/packages/slate/test/history/undo/unwrap-node-by-path.js +++ b/packages/slate/test/history/undo/unwrap-node-by-path.js @@ -3,7 +3,7 @@ import h from '../../helpers/h' import { PathUtils } from 'slate' -export default function(editor) { +export default function (editor) { editor.unwrapNodeByPath(PathUtils.create([0, 0])) editor.flush() editor.undo() @@ -13,11 +13,11 @@ export const input = ( - + one - - two - three + + two + three diff --git a/packages/slate/test/history/undo/wrap-inline-across-blocks.js b/packages/slate/test/history/undo/wrap-inline-across-blocks.js index c84c55e2a6..9ffd57de51 100644 --- a/packages/slate/test/history/undo/wrap-inline-across-blocks.js +++ b/packages/slate/test/history/undo/wrap-inline-across-blocks.js @@ -2,7 +2,7 @@ import h from '../../helpers/h' -export default function(editor) { +export default function (editor) { editor.wrapInline('hashtag') editor.flush() editor.undo() @@ -11,12 +11,12 @@ export default function(editor) { export const input = ( - + word - - + + another - + ) diff --git a/packages/slate/test/interfaces/Selection/isSelection/boolean.js b/packages/slate/test/interfaces/Selection/isSelection/boolean.js deleted file mode 100644 index 90f3c77e53..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/boolean.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Selection } from 'slate' - -export const input = true - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/custom-property.js b/packages/slate/test/interfaces/Selection/isSelection/custom-property.js deleted file mode 100644 index 2927a075aa..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/custom-property.js +++ /dev/null @@ -1,21 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: true, - marks: null, - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, - custom: true, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js b/packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js deleted file mode 100644 index c005fa2753..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/is-focused-false.js +++ /dev/null @@ -1,20 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: false, - marks: null, - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/marks-empty.js b/packages/slate/test/interfaces/Selection/isSelection/marks-empty.js deleted file mode 100644 index ed90e2b19e..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/marks-empty.js +++ /dev/null @@ -1,20 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: true, - marks: [], - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/marks-full.js b/packages/slate/test/interfaces/Selection/isSelection/marks-full.js deleted file mode 100644 index 7efe99d290..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/marks-full.js +++ /dev/null @@ -1,20 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: true, - marks: [{}], - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/object.js b/packages/slate/test/interfaces/Selection/isSelection/object.js deleted file mode 100644 index 8842bf23af..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/object.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Selection } from 'slate' - -export const input = {} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/selection.js b/packages/slate/test/interfaces/Selection/isSelection/selection.js deleted file mode 100644 index c0cd9dc185..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/selection.js +++ /dev/null @@ -1,20 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: true, - marks: null, - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-anchor.js b/packages/slate/test/interfaces/Selection/isSelection/without-anchor.js deleted file mode 100644 index f77cd93b13..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/without-anchor.js +++ /dev/null @@ -1,16 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: true, - marks: null, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-focus.js b/packages/slate/test/interfaces/Selection/isSelection/without-focus.js deleted file mode 100644 index 86c3ad3160..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/without-focus.js +++ /dev/null @@ -1,16 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: true, - marks: null, - anchor: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js b/packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js deleted file mode 100644 index db60b18698..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/without-isFocused.js +++ /dev/null @@ -1,19 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - marks: null, - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Selection/isSelection/without-marks.js b/packages/slate/test/interfaces/Selection/isSelection/without-marks.js deleted file mode 100644 index 9f408c2e84..0000000000 --- a/packages/slate/test/interfaces/Selection/isSelection/without-marks.js +++ /dev/null @@ -1,19 +0,0 @@ -import { Selection } from 'slate' - -export const input = { - isFocused: true, - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Selection.isSelection(value) -} - -export const output = false diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js b/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js index aba40acdac..7e6ef24f3c 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js @@ -38,7 +38,7 @@ export const output = ( - text + text diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom.js b/packages/slate/test/schema/custom/child-kind-invalid-custom.js index 82c3131ccd..209547e582 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-custom.js @@ -32,7 +32,7 @@ export const output = ( - text + text diff --git a/packages/slate/test/schema/custom/child-kind-invalid-default.js b/packages/slate/test/schema/custom/child-kind-invalid-default.js index 0cde78f2fa..a81c1dd9f4 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-default.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-default.js @@ -19,7 +19,7 @@ export const input = ( - text + text diff --git a/packages/slate/test/schema/custom/child-kind-invalid-function.js b/packages/slate/test/schema/custom/child-kind-invalid-function.js index ee2ba76598..8fa36ae7bc 100644 --- a/packages/slate/test/schema/custom/child-kind-invalid-function.js +++ b/packages/slate/test/schema/custom/child-kind-invalid-function.js @@ -19,7 +19,7 @@ export const input = ( - text + text diff --git a/packages/slate/test/schema/custom/child-max-invalid-at-end-default.js b/packages/slate/test/schema/custom/child-max-invalid-at-end-default.js index 5fe55d4465..2aaec1f250 100644 --- a/packages/slate/test/schema/custom/child-max-invalid-at-end-default.js +++ b/packages/slate/test/schema/custom/child-max-invalid-at-end-default.js @@ -20,12 +20,12 @@ export const input = ( - + - - + + - + @@ -35,9 +35,9 @@ export const output = ( - + - + diff --git a/packages/slate/test/schema/custom/child-max-invalid-custom.js b/packages/slate/test/schema/custom/child-max-invalid-custom.js index 3f1cc836d8..cf80062374 100644 --- a/packages/slate/test/schema/custom/child-max-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-max-invalid-custom.js @@ -30,9 +30,9 @@ export const input = ( One Two - + - + @@ -43,9 +43,9 @@ export const output = ( OneTwo - + - + diff --git a/packages/slate/test/schema/custom/child-max-invalid-default.js b/packages/slate/test/schema/custom/child-max-invalid-default.js index 49c31b68a2..e134284375 100644 --- a/packages/slate/test/schema/custom/child-max-invalid-default.js +++ b/packages/slate/test/schema/custom/child-max-invalid-default.js @@ -25,9 +25,9 @@ export const input = ( One Two - + - + @@ -38,9 +38,9 @@ export const output = ( One - + - + diff --git a/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js b/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js index 949a1a51cf..2b57048f36 100644 --- a/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js +++ b/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js @@ -28,9 +28,9 @@ export const input = ( - + - + @@ -40,12 +40,12 @@ export const output = ( - + - - + + - + diff --git a/packages/slate/test/schema/custom/child-min-invalid-custom.js b/packages/slate/test/schema/custom/child-min-invalid-custom.js index ff44791063..c6a578419c 100644 --- a/packages/slate/test/schema/custom/child-min-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-min-invalid-custom.js @@ -32,9 +32,9 @@ export const input = ( - + - + @@ -47,9 +47,9 @@ export const output = ( - + - + diff --git a/packages/slate/test/schema/custom/child-min-invalid-default.js b/packages/slate/test/schema/custom/child-min-invalid-default.js index d78cce9646..680392660b 100644 --- a/packages/slate/test/schema/custom/child-min-invalid-default.js +++ b/packages/slate/test/schema/custom/child-min-invalid-default.js @@ -24,9 +24,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/child-min-invalid-with-invalid-default.js b/packages/slate/test/schema/custom/child-min-invalid-with-invalid-default.js index d97cc63e68..3f0bc4bb6f 100644 --- a/packages/slate/test/schema/custom/child-min-invalid-with-invalid-default.js +++ b/packages/slate/test/schema/custom/child-min-invalid-with-invalid-default.js @@ -23,15 +23,15 @@ export const input = ( - + - + - + - + @@ -44,12 +44,12 @@ export const output = ( - + - - + + - + diff --git a/packages/slate/test/schema/custom/child-min-max-invalid-default.js b/packages/slate/test/schema/custom/child-min-max-invalid-default.js index 2e44188d2c..d8c07f84d4 100644 --- a/packages/slate/test/schema/custom/child-min-max-invalid-default.js +++ b/packages/slate/test/schema/custom/child-min-max-invalid-default.js @@ -31,9 +31,9 @@ export const input = ( - + - + @@ -46,9 +46,9 @@ export const output = ( - + - + diff --git a/packages/slate/test/schema/custom/child-min-max-invalid-valid.js b/packages/slate/test/schema/custom/child-min-max-invalid-valid.js index 4893db1cb4..7ccec2e80f 100644 --- a/packages/slate/test/schema/custom/child-min-max-invalid-valid.js +++ b/packages/slate/test/schema/custom/child-min-max-invalid-valid.js @@ -28,9 +28,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/child-type-invalid-custom.js b/packages/slate/test/schema/custom/child-type-invalid-custom.js index 8f853ff106..8ab1a1a931 100644 --- a/packages/slate/test/schema/custom/child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/child-type-invalid-custom.js @@ -24,9 +24,9 @@ export const input = ( - + - + @@ -36,11 +36,11 @@ export const output = ( - - + + - - + + diff --git a/packages/slate/test/schema/custom/child-type-invalid-default.js b/packages/slate/test/schema/custom/child-type-invalid-default.js index 0f92713801..e6819d7298 100644 --- a/packages/slate/test/schema/custom/child-type-invalid-default.js +++ b/packages/slate/test/schema/custom/child-type-invalid-default.js @@ -19,9 +19,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/child-type-invalid-function.js b/packages/slate/test/schema/custom/child-type-invalid-function.js index 95d86943ea..75d4953419 100644 --- a/packages/slate/test/schema/custom/child-type-invalid-function.js +++ b/packages/slate/test/schema/custom/child-type-invalid-function.js @@ -19,9 +19,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/child-unknown-custom.js b/packages/slate/test/schema/custom/child-unknown-custom.js index 62e4674811..f39be3f2e6 100644 --- a/packages/slate/test/schema/custom/child-unknown-custom.js +++ b/packages/slate/test/schema/custom/child-unknown-custom.js @@ -25,7 +25,7 @@ export const input = ( - one + one two @@ -36,7 +36,7 @@ export const output = ( - onetwo + onetwo diff --git a/packages/slate/test/schema/custom/child-unknown-default.js b/packages/slate/test/schema/custom/child-unknown-default.js index 7629d2160f..031f2c4bc8 100644 --- a/packages/slate/test/schema/custom/child-unknown-default.js +++ b/packages/slate/test/schema/custom/child-unknown-default.js @@ -20,7 +20,7 @@ export const input = ( - one + one two @@ -31,7 +31,7 @@ export const output = ( - one + one diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js b/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js index 86ff482fc2..7bfe567e2b 100644 --- a/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js @@ -28,7 +28,7 @@ export const output = ( - text + text diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-default.js b/packages/slate/test/schema/custom/first-child-kind-invalid-default.js index e408a48167..c35a9e467f 100644 --- a/packages/slate/test/schema/custom/first-child-kind-invalid-default.js +++ b/packages/slate/test/schema/custom/first-child-kind-invalid-default.js @@ -15,9 +15,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-function.js b/packages/slate/test/schema/custom/first-child-kind-invalid-function.js index 8faa287084..52a8bfd18b 100644 --- a/packages/slate/test/schema/custom/first-child-kind-invalid-function.js +++ b/packages/slate/test/schema/custom/first-child-kind-invalid-function.js @@ -15,9 +15,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-custom.js b/packages/slate/test/schema/custom/first-child-type-invalid-custom.js index a1c4078dc7..7b4074b2af 100644 --- a/packages/slate/test/schema/custom/first-child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/first-child-type-invalid-custom.js @@ -20,15 +20,15 @@ export const input = ( - + - - + + - - + + - + @@ -38,17 +38,17 @@ export const output = ( - - + + - - - + + + - - + + - + diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-default.js b/packages/slate/test/schema/custom/first-child-type-invalid-default.js index 020ee374c5..f8673da1f5 100644 --- a/packages/slate/test/schema/custom/first-child-type-invalid-default.js +++ b/packages/slate/test/schema/custom/first-child-type-invalid-default.js @@ -15,15 +15,15 @@ export const input = ( - + - - + + - - + + - + @@ -33,12 +33,12 @@ export const output = ( - + - - + + - + diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-function.js b/packages/slate/test/schema/custom/first-child-type-invalid-function.js index b6c57e25e7..82377c7e82 100644 --- a/packages/slate/test/schema/custom/first-child-type-invalid-function.js +++ b/packages/slate/test/schema/custom/first-child-type-invalid-function.js @@ -15,15 +15,15 @@ export const input = ( - + - - + + - - + + - + @@ -33,12 +33,12 @@ export const output = ( - + - - + + - + diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js b/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js index 9d91bb239a..38b0bb6b88 100644 --- a/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js @@ -28,7 +28,7 @@ export const output = ( - text + text diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-default.js b/packages/slate/test/schema/custom/last-child-kind-invalid-default.js index 1955d073e9..3069215821 100644 --- a/packages/slate/test/schema/custom/last-child-kind-invalid-default.js +++ b/packages/slate/test/schema/custom/last-child-kind-invalid-default.js @@ -15,9 +15,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-function.js b/packages/slate/test/schema/custom/last-child-kind-invalid-function.js index e8a7e1356c..ab13fcc833 100644 --- a/packages/slate/test/schema/custom/last-child-kind-invalid-function.js +++ b/packages/slate/test/schema/custom/last-child-kind-invalid-function.js @@ -15,9 +15,9 @@ export const input = ( - + - + diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-custom.js b/packages/slate/test/schema/custom/last-child-type-invalid-custom.js index 6eb48ab014..481018854e 100644 --- a/packages/slate/test/schema/custom/last-child-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/last-child-type-invalid-custom.js @@ -20,15 +20,15 @@ export const input = ( - + - - + + - - + + - + @@ -38,17 +38,17 @@ export const output = ( - + - - + + - - - + + + - - + + diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-default.js b/packages/slate/test/schema/custom/last-child-type-invalid-default.js index 8d33499fed..a388d0d811 100644 --- a/packages/slate/test/schema/custom/last-child-type-invalid-default.js +++ b/packages/slate/test/schema/custom/last-child-type-invalid-default.js @@ -15,15 +15,15 @@ export const input = ( - + - - + + - - + + - + @@ -33,12 +33,12 @@ export const output = ( - + - - + + - + diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-function.js b/packages/slate/test/schema/custom/last-child-type-invalid-function.js index 1e4880933e..850bd47cdd 100644 --- a/packages/slate/test/schema/custom/last-child-type-invalid-function.js +++ b/packages/slate/test/schema/custom/last-child-type-invalid-function.js @@ -15,15 +15,15 @@ export const input = ( - + - - + + - - + + - + @@ -33,12 +33,12 @@ export const output = ( - + - - + + - + diff --git a/packages/slate/test/schema/custom/match-data.js b/packages/slate/test/schema/custom/match-data.js index f1149a6f8b..a4a5e17441 100644 --- a/packages/slate/test/schema/custom/match-data.js +++ b/packages/slate/test/schema/custom/match-data.js @@ -16,7 +16,7 @@ export const input = ( - + ) diff --git a/packages/slate/test/schema/custom/match-object.js b/packages/slate/test/schema/custom/match-object.js index 9a6c78903e..52383bdffd 100644 --- a/packages/slate/test/schema/custom/match-object.js +++ b/packages/slate/test/schema/custom/match-object.js @@ -16,9 +16,9 @@ export const schema = { export const input = ( - + - + ) diff --git a/packages/slate/test/schema/custom/match-type.js b/packages/slate/test/schema/custom/match-type.js index ea26da9628..876d5a074d 100644 --- a/packages/slate/test/schema/custom/match-type.js +++ b/packages/slate/test/schema/custom/match-type.js @@ -14,7 +14,7 @@ export const schema = { export const input = ( - invalid + invalid ) diff --git a/packages/slate/test/schema/custom/next-kind-invalid-custom.js b/packages/slate/test/schema/custom/next-kind-invalid-custom.js index 1b917e81c6..a75b7c994b 100644 --- a/packages/slate/test/schema/custom/next-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/next-kind-invalid-custom.js @@ -18,14 +18,14 @@ export const schema = { export const input = ( - - + + - + - + ) @@ -33,11 +33,11 @@ export const input = ( export const output = ( - - + + - - + + diff --git a/packages/slate/test/schema/custom/next-kind-invalid-default.js b/packages/slate/test/schema/custom/next-kind-invalid-default.js index df5f62b6bc..27b00cf38c 100644 --- a/packages/slate/test/schema/custom/next-kind-invalid-default.js +++ b/packages/slate/test/schema/custom/next-kind-invalid-default.js @@ -13,14 +13,14 @@ export const schema = { export const input = ( - - + + - + - + ) @@ -28,11 +28,11 @@ export const input = ( export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/schema/custom/next-kind-invalid-function.js b/packages/slate/test/schema/custom/next-kind-invalid-function.js index f865aac529..ebda9df1c3 100644 --- a/packages/slate/test/schema/custom/next-kind-invalid-function.js +++ b/packages/slate/test/schema/custom/next-kind-invalid-function.js @@ -13,14 +13,14 @@ export const schema = { export const input = ( - - + + - + - + ) @@ -28,11 +28,11 @@ export const input = ( export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/schema/custom/next-type-invalid-custom.js b/packages/slate/test/schema/custom/next-type-invalid-custom.js index 550aca4c91..abb888fe7b 100644 --- a/packages/slate/test/schema/custom/next-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/next-type-invalid-custom.js @@ -18,12 +18,12 @@ export const schema = { export const input = ( - + - - + + - + ) @@ -31,14 +31,14 @@ export const input = ( export const output = ( - + - - - + + + - - + + ) diff --git a/packages/slate/test/schema/custom/next-type-invalid-default.js b/packages/slate/test/schema/custom/next-type-invalid-default.js index 4f34ce7b0d..b3ce6f264d 100644 --- a/packages/slate/test/schema/custom/next-type-invalid-default.js +++ b/packages/slate/test/schema/custom/next-type-invalid-default.js @@ -13,12 +13,12 @@ export const schema = { export const input = ( - + - - + + - + ) @@ -26,9 +26,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/next-type-invalid-function.js b/packages/slate/test/schema/custom/next-type-invalid-function.js index da4af3b423..85b8438325 100644 --- a/packages/slate/test/schema/custom/next-type-invalid-function.js +++ b/packages/slate/test/schema/custom/next-type-invalid-function.js @@ -13,12 +13,12 @@ export const schema = { export const input = ( - + - - + + - + ) @@ -26,9 +26,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/node-data-invalid-custom.js b/packages/slate/test/schema/custom/node-data-invalid-custom.js index 00977aa0b1..32671fed54 100644 --- a/packages/slate/test/schema/custom/node-data-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-data-invalid-custom.js @@ -20,9 +20,9 @@ export const schema = { export const input = ( - + - + ) @@ -32,7 +32,7 @@ export const output = ( - + ) diff --git a/packages/slate/test/schema/custom/node-data-invalid-default-undefined.js b/packages/slate/test/schema/custom/node-data-invalid-default-undefined.js index 6a76433474..e58a50a84f 100644 --- a/packages/slate/test/schema/custom/node-data-invalid-default-undefined.js +++ b/packages/slate/test/schema/custom/node-data-invalid-default-undefined.js @@ -15,9 +15,9 @@ export const schema = { export const input = ( - + - + ) diff --git a/packages/slate/test/schema/custom/node-data-invalid-default.js b/packages/slate/test/schema/custom/node-data-invalid-default.js index a17574f0fd..30fd8bcd2f 100644 --- a/packages/slate/test/schema/custom/node-data-invalid-default.js +++ b/packages/slate/test/schema/custom/node-data-invalid-default.js @@ -17,7 +17,7 @@ export const input = ( - + ) @@ -25,9 +25,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/node-data-invalid-function.js b/packages/slate/test/schema/custom/node-data-invalid-function.js index 5ea66f98dd..b49f30726b 100644 --- a/packages/slate/test/schema/custom/node-data-invalid-function.js +++ b/packages/slate/test/schema/custom/node-data-invalid-function.js @@ -15,10 +15,10 @@ export const input = ( - + - + ) @@ -28,7 +28,7 @@ export const output = ( - + ) diff --git a/packages/slate/test/schema/custom/node-mark-invalid-custom.js b/packages/slate/test/schema/custom/node-mark-invalid-custom.js index 3d1b582fca..49cfdd826a 100644 --- a/packages/slate/test/schema/custom/node-mark-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-mark-invalid-custom.js @@ -18,9 +18,9 @@ export const schema = { export const input = ( - - one two three - + + one two three + ) @@ -28,9 +28,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/node-mark-invalid-default.js b/packages/slate/test/schema/custom/node-mark-invalid-default.js index 60ef73c975..ac8e4223e7 100644 --- a/packages/slate/test/schema/custom/node-mark-invalid-default.js +++ b/packages/slate/test/schema/custom/node-mark-invalid-default.js @@ -13,9 +13,9 @@ export const schema = { export const input = ( - - one two three - + + one two three + ) @@ -23,7 +23,7 @@ export const input = ( export const output = ( - one two three + one two three ) diff --git a/packages/slate/test/schema/custom/node-mark-invalid-function.js b/packages/slate/test/schema/custom/node-mark-invalid-function.js index fb38335de5..fce20458e7 100644 --- a/packages/slate/test/schema/custom/node-mark-invalid-function.js +++ b/packages/slate/test/schema/custom/node-mark-invalid-function.js @@ -13,9 +13,9 @@ export const schema = { export const input = ( - - one two three - + + one two three + ) @@ -23,9 +23,9 @@ export const input = ( export const output = ( - - one two three - + + one two three + ) diff --git a/packages/slate/test/schema/custom/node-mark-valid-default.js b/packages/slate/test/schema/custom/node-mark-valid-default.js index b07cb76a93..837951f8ae 100644 --- a/packages/slate/test/schema/custom/node-mark-valid-default.js +++ b/packages/slate/test/schema/custom/node-mark-valid-default.js @@ -13,9 +13,9 @@ export const schema = { export const input = ( - - one two three - + + one two three + ) @@ -23,9 +23,9 @@ export const input = ( export const output = ( - - one two three - + + one two three + ) diff --git a/packages/slate/test/schema/custom/node-object-invalid-default.js b/packages/slate/test/schema/custom/node-object-invalid-default.js index 12533644cf..092b705b62 100644 --- a/packages/slate/test/schema/custom/node-object-invalid-default.js +++ b/packages/slate/test/schema/custom/node-object-invalid-default.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - invalid + invalid ) diff --git a/packages/slate/test/schema/custom/node-object-invalid-function.js b/packages/slate/test/schema/custom/node-object-invalid-function.js index e4df5b24ec..8ae79be94c 100644 --- a/packages/slate/test/schema/custom/node-object-invalid-function.js +++ b/packages/slate/test/schema/custom/node-object-invalid-function.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - invalid + invalid ) diff --git a/packages/slate/test/schema/custom/node-text-invalid-custom.js b/packages/slate/test/schema/custom/node-text-invalid-custom.js index 6efd103eb8..2ee886bd89 100644 --- a/packages/slate/test/schema/custom/node-text-invalid-custom.js +++ b/packages/slate/test/schema/custom/node-text-invalid-custom.js @@ -18,7 +18,7 @@ export const schema = { export const input = ( - invalid + invalid ) @@ -26,9 +26,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/node-text-invalid-default.js b/packages/slate/test/schema/custom/node-text-invalid-default.js index 99a2a4ef7f..e2b9cd2cca 100644 --- a/packages/slate/test/schema/custom/node-text-invalid-default.js +++ b/packages/slate/test/schema/custom/node-text-invalid-default.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - invalid + invalid ) diff --git a/packages/slate/test/schema/custom/node-text-invalid-function.js b/packages/slate/test/schema/custom/node-text-invalid-function.js index 3d82cd3fbc..51217eb7c5 100644 --- a/packages/slate/test/schema/custom/node-text-invalid-function.js +++ b/packages/slate/test/schema/custom/node-text-invalid-function.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - invalid + invalid ) diff --git a/packages/slate/test/schema/custom/node-text-valid-function.js b/packages/slate/test/schema/custom/node-text-valid-function.js index daaf0529a0..621d0f0d2d 100644 --- a/packages/slate/test/schema/custom/node-text-valid-function.js +++ b/packages/slate/test/schema/custom/node-text-valid-function.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - valid + valid ) @@ -21,7 +21,7 @@ export const input = ( export const output = ( - valid + valid ) diff --git a/packages/slate/test/schema/custom/node-text-valid.js b/packages/slate/test/schema/custom/node-text-valid.js index ae8bd99023..ad91bf377b 100644 --- a/packages/slate/test/schema/custom/node-text-valid.js +++ b/packages/slate/test/schema/custom/node-text-valid.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - 123 + 123 ) @@ -21,7 +21,7 @@ export const input = ( export const output = ( - 123 + 123 ) diff --git a/packages/slate/test/schema/custom/node-type-invalid-default.js b/packages/slate/test/schema/custom/node-type-invalid-default.js index d460e8faad..244dd859eb 100644 --- a/packages/slate/test/schema/custom/node-type-invalid-default.js +++ b/packages/slate/test/schema/custom/node-type-invalid-default.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - invalid + invalid ) diff --git a/packages/slate/test/schema/custom/node-type-invalid-function.js b/packages/slate/test/schema/custom/node-type-invalid-function.js index 64c7e521c1..5b0709caaa 100644 --- a/packages/slate/test/schema/custom/node-type-invalid-function.js +++ b/packages/slate/test/schema/custom/node-type-invalid-function.js @@ -13,7 +13,7 @@ export const schema = { export const input = ( - invalid + invalid ) diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-custom.js b/packages/slate/test/schema/custom/parent-kind-invalid-custom.js index 3fcefb5249..bfacb6f083 100644 --- a/packages/slate/test/schema/custom/parent-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/parent-kind-invalid-custom.js @@ -19,7 +19,7 @@ export const input = ( - one + one @@ -28,7 +28,7 @@ export const input = ( export const output = ( - one + one ) diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-default.js b/packages/slate/test/schema/custom/parent-kind-invalid-default.js index 7680be5d93..e8036e3e8e 100644 --- a/packages/slate/test/schema/custom/parent-kind-invalid-default.js +++ b/packages/slate/test/schema/custom/parent-kind-invalid-default.js @@ -13,15 +13,15 @@ export const schema = { export const input = ( - + - + - one + one - + - + ) @@ -29,13 +29,13 @@ export const input = ( export const output = ( - + - + - + - + ) diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-function.js b/packages/slate/test/schema/custom/parent-kind-invalid-function.js index 5df115e557..d731eaf68b 100644 --- a/packages/slate/test/schema/custom/parent-kind-invalid-function.js +++ b/packages/slate/test/schema/custom/parent-kind-invalid-function.js @@ -13,15 +13,15 @@ export const schema = { export const input = ( - + - + - one + one - + - + ) @@ -29,13 +29,13 @@ export const input = ( export const output = ( - + - + - + - + ) diff --git a/packages/slate/test/schema/custom/parent-type-invalid-custom.js b/packages/slate/test/schema/custom/parent-type-invalid-custom.js index e2f2f078aa..c280b9d0fa 100644 --- a/packages/slate/test/schema/custom/parent-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/parent-type-invalid-custom.js @@ -19,11 +19,11 @@ export const schema = { export const input = ( - - + + - - + + ) @@ -31,13 +31,13 @@ export const input = ( export const output = ( - - - + + + - - - + + + ) diff --git a/packages/slate/test/schema/custom/parent-type-invalid-default.js b/packages/slate/test/schema/custom/parent-type-invalid-default.js index 6fb9d7d97b..86e4f9f8e7 100644 --- a/packages/slate/test/schema/custom/parent-type-invalid-default.js +++ b/packages/slate/test/schema/custom/parent-type-invalid-default.js @@ -14,11 +14,11 @@ export const schema = { export const input = ( - - + + - - + + ) @@ -26,9 +26,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/parent-type-invalid-function.js b/packages/slate/test/schema/custom/parent-type-invalid-function.js index 1f2910896c..173b0b1a56 100644 --- a/packages/slate/test/schema/custom/parent-type-invalid-function.js +++ b/packages/slate/test/schema/custom/parent-type-invalid-function.js @@ -14,11 +14,11 @@ export const schema = { export const input = ( - - + + - - + + ) @@ -26,9 +26,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/previous-kind-invalid-custom.js b/packages/slate/test/schema/custom/previous-kind-invalid-custom.js index 7bba930272..f40ab511a9 100644 --- a/packages/slate/test/schema/custom/previous-kind-invalid-custom.js +++ b/packages/slate/test/schema/custom/previous-kind-invalid-custom.js @@ -18,14 +18,14 @@ export const schema = { export const input = ( - + - + - - + + ) @@ -36,11 +36,11 @@ export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/schema/custom/previous-kind-invalid-default.js b/packages/slate/test/schema/custom/previous-kind-invalid-default.js index 9857039a41..fccbd04dc0 100644 --- a/packages/slate/test/schema/custom/previous-kind-invalid-default.js +++ b/packages/slate/test/schema/custom/previous-kind-invalid-default.js @@ -13,14 +13,14 @@ export const schema = { export const input = ( - + - + - - + + ) @@ -28,11 +28,11 @@ export const input = ( export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/schema/custom/previous-kind-invalid-function.js b/packages/slate/test/schema/custom/previous-kind-invalid-function.js index b5101a240d..700cf58bf4 100644 --- a/packages/slate/test/schema/custom/previous-kind-invalid-function.js +++ b/packages/slate/test/schema/custom/previous-kind-invalid-function.js @@ -13,14 +13,14 @@ export const schema = { export const input = ( - + - + - - + + ) @@ -28,11 +28,11 @@ export const input = ( export const output = ( - - + + - - + + ) diff --git a/packages/slate/test/schema/custom/previous-type-invalid-custom.js b/packages/slate/test/schema/custom/previous-type-invalid-custom.js index 6b40a83c56..b4b1bdeda3 100644 --- a/packages/slate/test/schema/custom/previous-type-invalid-custom.js +++ b/packages/slate/test/schema/custom/previous-type-invalid-custom.js @@ -18,12 +18,12 @@ export const schema = { export const input = ( - + - - + + - + ) @@ -31,14 +31,14 @@ export const input = ( export const output = ( - - + + - - - + + + - + ) diff --git a/packages/slate/test/schema/custom/previous-type-invalid-default.js b/packages/slate/test/schema/custom/previous-type-invalid-default.js index dd1e48fbc1..0a03c1fccd 100644 --- a/packages/slate/test/schema/custom/previous-type-invalid-default.js +++ b/packages/slate/test/schema/custom/previous-type-invalid-default.js @@ -13,12 +13,12 @@ export const schema = { export const input = ( - + - - + + - + ) @@ -26,9 +26,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/packages/slate/test/schema/custom/previous-type-invalid-function.js b/packages/slate/test/schema/custom/previous-type-invalid-function.js index b4b5c974bf..d0cb0ce154 100644 --- a/packages/slate/test/schema/custom/previous-type-invalid-function.js +++ b/packages/slate/test/schema/custom/previous-type-invalid-function.js @@ -13,12 +13,12 @@ export const schema = { export const input = ( - + - - + + - + ) @@ -26,9 +26,9 @@ export const input = ( export const output = ( - + - + ) diff --git a/support/fixtures.js b/support/fixtures.js index 3613bcee03..0fb89d35e1 100644 --- a/support/fixtures.js +++ b/support/fixtures.js @@ -35,7 +35,7 @@ export const fixtures = (...args) => { const name = basename(file, extname(file)) // This needs to be a non-arrow function to use `this.skip()`. - it(name, function() { + it(`${name} `, function() { const module = require(p) if (module.skip) { From a0406c34beecdd68804f8a97ea48ad5c422b2d18 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 11:07:24 -0400 Subject: [PATCH 045/165] rename --- .../block-across-edge-existing.js} | 0 .../block-across-existing.js} | 0 .../block-across.js} | 0 .../existing.js} | 0 .../{add-mark => addMarks}/first-character.js | 0 .../inline-across.js} | 0 .../{add-mark => addMarks}/last-character.js | 0 .../middle-character.js | 0 .../whole-word.js => addMarks/word.js} | 0 ...blings-all.js => block-across-multiple.js} | 15 +++++--- ...ested-blocks.js => block-across-nested.js} | 0 .../{across-blocks.js => block-across.js} | 0 ...cross-depths.js => block-depths-nested.js} | 0 .../{nested-block.js => block-depths.js} | 0 ...nly-void.js => block-hanging-from-void.js} | 0 ...non-void.js => block-hanging-into-void.js} | 0 ...le-blocks.js => block-hanging-multiple.js} | 0 ...ingle-block.js => block-hanging-single.js} | 0 ...ocks-inlines.js => block-inline-across.js} | 0 .../{join-blocks.js => block-join-edges.js} | 0 ...s-with-inlines.js => block-join-inline.js} | 0 ...-nested-blocks.js => block-join-nested.js} | 0 .../{all-nested-blocks.js => block-nested.js} | 0 ...election-all.js => block-void-backward.js} | 0 ...ially-non-void.js => block-void-before.js} | 0 ...-only-first-void.js => block-void-both.js} | 0 ...-to-start-of-void.js => block-void-end.js} | 0 ...id-block-as-only.js => block-void-only.js} | 0 ...-voids.js => block-void-start-multiple.js} | 0 ...d-and-next-word.js => block-void-start.js} | 5 +-- .../{last-character.js => character-end.js} | 0 ...iddle-character.js => character-middle.js} | 0 ...{first-character.js => character-start.js} | 0 .../{first-position.js => collapsed-start.js} | 0 ...fore-inline-sibling.js => inline-after.js} | 0 .../{inside-inline.js => inline-inside.js} | 0 ...ss-texts-and-inlines.js => inline-over.js} | 0 ...evious-siblings.js => inline-void-over.js} | 0 ...ck-next.js => inline-void-start-across.js} | 6 ++-- ...n-void-sibling.js => inline-void-start.js} | 7 ++-- .../{whole-inline.js => inline-whole.js} | 0 .../value/delete/inside-inline-sibling.js | 28 --------------- .../value/delete/join-blocks-and-trim.js | 30 ---------------- .../value/delete/join-nested-blocks.js | 34 ------------------- ...ed-across-whole-mark.js => mark-across.js} | 0 .../{whole-word-mark.js => mark-whole.js} | 0 ...id-siblings-partially-non-void-and-void.js | 32 ----------------- .../commands/value/delete/non-void-triple.js | 31 ----------------- ...-siblings-select-void-end-and-next-word.js | 32 ----------------- .../value/delete/{whole-word.js => word.js} | 0 50 files changed, 22 insertions(+), 198 deletions(-) rename packages/slate/test/commands/value/{add-mark/existing-marks-across-blocks-at-edge.js => addMarks/block-across-edge-existing.js} (100%) rename packages/slate/test/commands/value/{add-mark/existing-marks-across-blocks.js => addMarks/block-across-existing.js} (100%) rename packages/slate/test/commands/value/{add-mark/across-blocks.js => addMarks/block-across.js} (100%) rename packages/slate/test/commands/value/{add-mark/existing-marks.js => addMarks/existing.js} (100%) rename packages/slate/test/commands/value/{add-mark => addMarks}/first-character.js (100%) rename packages/slate/test/commands/value/{add-mark/across-inlines.js => addMarks/inline-across.js} (100%) rename packages/slate/test/commands/value/{add-mark => addMarks}/last-character.js (100%) rename packages/slate/test/commands/value/{add-mark => addMarks}/middle-character.js (100%) rename packages/slate/test/commands/value/{add-mark/whole-word.js => addMarks/word.js} (100%) rename packages/slate/test/commands/value/delete/{void-block-as-first-with-non-void-siblings-all.js => block-across-multiple.js} (69%) rename packages/slate/test/commands/value/delete/{across-nested-blocks.js => block-across-nested.js} (100%) rename packages/slate/test/commands/value/delete/{across-blocks.js => block-across.js} (100%) rename packages/slate/test/commands/value/delete/{across-depths.js => block-depths-nested.js} (100%) rename packages/slate/test/commands/value/delete/{nested-block.js => block-depths.js} (100%) rename packages/slate/test/commands/value/delete/{void-block-as-first-with-non-void-siblings-only-void.js => block-hanging-from-void.js} (100%) rename packages/slate/test/commands/value/delete/{non-void-block-as-first-with-void-siblings-only-non-void.js => block-hanging-into-void.js} (100%) rename packages/slate/test/commands/value/delete/{hanging-selection-multiple-blocks.js => block-hanging-multiple.js} (100%) rename packages/slate/test/commands/value/delete/{hanging-selection-single-block.js => block-hanging-single.js} (100%) rename packages/slate/test/commands/value/delete/{across-blocks-inlines.js => block-inline-across.js} (100%) rename packages/slate/test/commands/value/delete/{join-blocks.js => block-join-edges.js} (100%) rename packages/slate/test/commands/value/delete/{join-blocks-with-inlines.js => block-join-inline.js} (100%) rename packages/slate/test/commands/value/delete/{join-double-nested-blocks.js => block-join-nested.js} (100%) rename packages/slate/test/commands/value/delete/{all-nested-blocks.js => block-nested.js} (100%) rename packages/slate/test/commands/value/delete/{void-block-as-first-with-non-void-siblings-backward-selection-all.js => block-void-backward.js} (100%) rename packages/slate/test/commands/value/delete/{non-void-block-as-first-with-void-siblings-partially-non-void.js => block-void-before.js} (100%) rename packages/slate/test/commands/value/delete/{void-blocks-as-first-with-non-void-siblings-only-first-void.js => block-void-both.js} (100%) rename packages/slate/test/commands/value/delete/{non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js => block-void-end.js} (100%) rename packages/slate/test/commands/value/delete/{void-block-as-only.js => block-void-only.js} (100%) rename packages/slate/test/commands/value/delete/{void-blocks-as-first-with-non-void-siblings-only-voids.js => block-void-start-multiple.js} (100%) rename packages/slate/test/commands/value/delete/{void-block-as-first-with-non-void-siblings-select-void-and-next-word.js => block-void-start.js} (87%) rename packages/slate/test/commands/value/delete/{last-character.js => character-end.js} (100%) rename packages/slate/test/commands/value/delete/{middle-character.js => character-middle.js} (100%) rename packages/slate/test/commands/value/delete/{first-character.js => character-start.js} (100%) rename packages/slate/test/commands/value/delete/{first-position.js => collapsed-start.js} (100%) rename packages/slate/test/commands/value/delete/{before-inline-sibling.js => inline-after.js} (100%) rename packages/slate/test/commands/value/delete/{inside-inline.js => inline-inside.js} (100%) rename packages/slate/test/commands/value/delete/{across-texts-and-inlines.js => inline-over.js} (100%) rename packages/slate/test/commands/value/delete/{void-inline-as-last-with-non-void-previous-siblings.js => inline-void-over.js} (100%) rename packages/slate/test/commands/value/delete/{void-inline-as-first-with-non-void-block-next.js => inline-void-start-across.js} (86%) rename packages/slate/test/commands/value/delete/{void-inline-as-first-with-non-void-sibling.js => inline-void-start.js} (83%) rename packages/slate/test/commands/value/delete/{whole-inline.js => inline-whole.js} (100%) delete mode 100644 packages/slate/test/commands/value/delete/inside-inline-sibling.js delete mode 100644 packages/slate/test/commands/value/delete/join-blocks-and-trim.js delete mode 100644 packages/slate/test/commands/value/delete/join-nested-blocks.js rename packages/slate/test/commands/value/delete/{expanded-across-whole-mark.js => mark-across.js} (100%) rename packages/slate/test/commands/value/delete/{whole-word-mark.js => mark-whole.js} (100%) delete mode 100644 packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js delete mode 100644 packages/slate/test/commands/value/delete/non-void-triple.js delete mode 100644 packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js rename packages/slate/test/commands/value/delete/{whole-word.js => word.js} (100%) diff --git a/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js b/packages/slate/test/commands/value/addMarks/block-across-edge-existing.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/existing-marks-across-blocks-at-edge.js rename to packages/slate/test/commands/value/addMarks/block-across-edge-existing.js diff --git a/packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js b/packages/slate/test/commands/value/addMarks/block-across-existing.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/existing-marks-across-blocks.js rename to packages/slate/test/commands/value/addMarks/block-across-existing.js diff --git a/packages/slate/test/commands/value/add-mark/across-blocks.js b/packages/slate/test/commands/value/addMarks/block-across.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/across-blocks.js rename to packages/slate/test/commands/value/addMarks/block-across.js diff --git a/packages/slate/test/commands/value/add-mark/existing-marks.js b/packages/slate/test/commands/value/addMarks/existing.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/existing-marks.js rename to packages/slate/test/commands/value/addMarks/existing.js diff --git a/packages/slate/test/commands/value/add-mark/first-character.js b/packages/slate/test/commands/value/addMarks/first-character.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/first-character.js rename to packages/slate/test/commands/value/addMarks/first-character.js diff --git a/packages/slate/test/commands/value/add-mark/across-inlines.js b/packages/slate/test/commands/value/addMarks/inline-across.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/across-inlines.js rename to packages/slate/test/commands/value/addMarks/inline-across.js diff --git a/packages/slate/test/commands/value/add-mark/last-character.js b/packages/slate/test/commands/value/addMarks/last-character.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/last-character.js rename to packages/slate/test/commands/value/addMarks/last-character.js diff --git a/packages/slate/test/commands/value/add-mark/middle-character.js b/packages/slate/test/commands/value/addMarks/middle-character.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/middle-character.js rename to packages/slate/test/commands/value/addMarks/middle-character.js diff --git a/packages/slate/test/commands/value/add-mark/whole-word.js b/packages/slate/test/commands/value/addMarks/word.js similarity index 100% rename from packages/slate/test/commands/value/add-mark/whole-word.js rename to packages/slate/test/commands/value/addMarks/word.js diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js b/packages/slate/test/commands/value/delete/block-across-multiple.js similarity index 69% rename from packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js rename to packages/slate/test/commands/value/delete/block-across-multiple.js index a046eb4881..d62030248e 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-all.js +++ b/packages/slate/test/commands/value/delete/block-across-multiple.js @@ -8,20 +8,25 @@ export const run = editor => { export const input = ( - - - - one + + + one + + two + three - two + four + ) export const output = ( + + ) diff --git a/packages/slate/test/commands/value/delete/across-nested-blocks.js b/packages/slate/test/commands/value/delete/block-across-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/across-nested-blocks.js rename to packages/slate/test/commands/value/delete/block-across-nested.js diff --git a/packages/slate/test/commands/value/delete/across-blocks.js b/packages/slate/test/commands/value/delete/block-across.js similarity index 100% rename from packages/slate/test/commands/value/delete/across-blocks.js rename to packages/slate/test/commands/value/delete/block-across.js diff --git a/packages/slate/test/commands/value/delete/across-depths.js b/packages/slate/test/commands/value/delete/block-depths-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/across-depths.js rename to packages/slate/test/commands/value/delete/block-depths-nested.js diff --git a/packages/slate/test/commands/value/delete/nested-block.js b/packages/slate/test/commands/value/delete/block-depths.js similarity index 100% rename from packages/slate/test/commands/value/delete/nested-block.js rename to packages/slate/test/commands/value/delete/block-depths.js diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js b/packages/slate/test/commands/value/delete/block-hanging-from-void.js similarity index 100% rename from packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-only-void.js rename to packages/slate/test/commands/value/delete/block-hanging-from-void.js diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js b/packages/slate/test/commands/value/delete/block-hanging-into-void.js similarity index 100% rename from packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-only-non-void.js rename to packages/slate/test/commands/value/delete/block-hanging-into-void.js diff --git a/packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/value/delete/block-hanging-multiple.js similarity index 100% rename from packages/slate/test/commands/value/delete/hanging-selection-multiple-blocks.js rename to packages/slate/test/commands/value/delete/block-hanging-multiple.js diff --git a/packages/slate/test/commands/value/delete/hanging-selection-single-block.js b/packages/slate/test/commands/value/delete/block-hanging-single.js similarity index 100% rename from packages/slate/test/commands/value/delete/hanging-selection-single-block.js rename to packages/slate/test/commands/value/delete/block-hanging-single.js diff --git a/packages/slate/test/commands/value/delete/across-blocks-inlines.js b/packages/slate/test/commands/value/delete/block-inline-across.js similarity index 100% rename from packages/slate/test/commands/value/delete/across-blocks-inlines.js rename to packages/slate/test/commands/value/delete/block-inline-across.js diff --git a/packages/slate/test/commands/value/delete/join-blocks.js b/packages/slate/test/commands/value/delete/block-join-edges.js similarity index 100% rename from packages/slate/test/commands/value/delete/join-blocks.js rename to packages/slate/test/commands/value/delete/block-join-edges.js diff --git a/packages/slate/test/commands/value/delete/join-blocks-with-inlines.js b/packages/slate/test/commands/value/delete/block-join-inline.js similarity index 100% rename from packages/slate/test/commands/value/delete/join-blocks-with-inlines.js rename to packages/slate/test/commands/value/delete/block-join-inline.js diff --git a/packages/slate/test/commands/value/delete/join-double-nested-blocks.js b/packages/slate/test/commands/value/delete/block-join-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/join-double-nested-blocks.js rename to packages/slate/test/commands/value/delete/block-join-nested.js diff --git a/packages/slate/test/commands/value/delete/all-nested-blocks.js b/packages/slate/test/commands/value/delete/block-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/all-nested-blocks.js rename to packages/slate/test/commands/value/delete/block-nested.js diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js b/packages/slate/test/commands/value/delete/block-void-backward.js similarity index 100% rename from packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-backward-selection-all.js rename to packages/slate/test/commands/value/delete/block-void-backward.js diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js b/packages/slate/test/commands/value/delete/block-void-before.js similarity index 100% rename from packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void.js rename to packages/slate/test/commands/value/delete/block-void-before.js diff --git a/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js b/packages/slate/test/commands/value/delete/block-void-both.js similarity index 100% rename from packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-first-void.js rename to packages/slate/test/commands/value/delete/block-void-both.js diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js b/packages/slate/test/commands/value/delete/block-void-end.js similarity index 100% rename from packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-up-to-start-of-void.js rename to packages/slate/test/commands/value/delete/block-void-end.js diff --git a/packages/slate/test/commands/value/delete/void-block-as-only.js b/packages/slate/test/commands/value/delete/block-void-only.js similarity index 100% rename from packages/slate/test/commands/value/delete/void-block-as-only.js rename to packages/slate/test/commands/value/delete/block-void-only.js diff --git a/packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js b/packages/slate/test/commands/value/delete/block-void-start-multiple.js similarity index 100% rename from packages/slate/test/commands/value/delete/void-blocks-as-first-with-non-void-siblings-only-voids.js rename to packages/slate/test/commands/value/delete/block-void-start-multiple.js diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js b/packages/slate/test/commands/value/delete/block-void-start.js similarity index 87% rename from packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js rename to packages/slate/test/commands/value/delete/block-void-start.js index 1b3120c8b4..69ca95c504 100644 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-and-next-word.js +++ b/packages/slate/test/commands/value/delete/block-void-start.js @@ -11,9 +11,10 @@ export const input = ( + one two - + three ) @@ -22,7 +23,7 @@ export const output = ( o - + three ) diff --git a/packages/slate/test/commands/value/delete/last-character.js b/packages/slate/test/commands/value/delete/character-end.js similarity index 100% rename from packages/slate/test/commands/value/delete/last-character.js rename to packages/slate/test/commands/value/delete/character-end.js diff --git a/packages/slate/test/commands/value/delete/middle-character.js b/packages/slate/test/commands/value/delete/character-middle.js similarity index 100% rename from packages/slate/test/commands/value/delete/middle-character.js rename to packages/slate/test/commands/value/delete/character-middle.js diff --git a/packages/slate/test/commands/value/delete/first-character.js b/packages/slate/test/commands/value/delete/character-start.js similarity index 100% rename from packages/slate/test/commands/value/delete/first-character.js rename to packages/slate/test/commands/value/delete/character-start.js diff --git a/packages/slate/test/commands/value/delete/first-position.js b/packages/slate/test/commands/value/delete/collapsed-start.js similarity index 100% rename from packages/slate/test/commands/value/delete/first-position.js rename to packages/slate/test/commands/value/delete/collapsed-start.js diff --git a/packages/slate/test/commands/value/delete/before-inline-sibling.js b/packages/slate/test/commands/value/delete/inline-after.js similarity index 100% rename from packages/slate/test/commands/value/delete/before-inline-sibling.js rename to packages/slate/test/commands/value/delete/inline-after.js diff --git a/packages/slate/test/commands/value/delete/inside-inline.js b/packages/slate/test/commands/value/delete/inline-inside.js similarity index 100% rename from packages/slate/test/commands/value/delete/inside-inline.js rename to packages/slate/test/commands/value/delete/inline-inside.js diff --git a/packages/slate/test/commands/value/delete/across-texts-and-inlines.js b/packages/slate/test/commands/value/delete/inline-over.js similarity index 100% rename from packages/slate/test/commands/value/delete/across-texts-and-inlines.js rename to packages/slate/test/commands/value/delete/inline-over.js diff --git a/packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js b/packages/slate/test/commands/value/delete/inline-void-over.js similarity index 100% rename from packages/slate/test/commands/value/delete/void-inline-as-last-with-non-void-previous-siblings.js rename to packages/slate/test/commands/value/delete/inline-void-over.js diff --git a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js b/packages/slate/test/commands/value/delete/inline-void-start-across.js similarity index 86% rename from packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js rename to packages/slate/test/commands/value/delete/inline-void-start-across.js index 26c1c94943..6d016715c7 100644 --- a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-block-next.js +++ b/packages/slate/test/commands/value/delete/inline-void-start-across.js @@ -9,9 +9,11 @@ export const run = editor => { export const input = ( - one + one + - two + + two three diff --git a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js b/packages/slate/test/commands/value/delete/inline-void-start.js similarity index 83% rename from packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js rename to packages/slate/test/commands/value/delete/inline-void-start.js index 5fe0e0e66e..5c89427502 100644 --- a/packages/slate/test/commands/value/delete/void-inline-as-first-with-non-void-sibling.js +++ b/packages/slate/test/commands/value/delete/inline-void-start.js @@ -9,10 +9,11 @@ export const run = editor => { export const input = ( + one - abc + two ) @@ -20,7 +21,9 @@ export const input = ( export const output = ( - abc + one + + two ) diff --git a/packages/slate/test/commands/value/delete/whole-inline.js b/packages/slate/test/commands/value/delete/inline-whole.js similarity index 100% rename from packages/slate/test/commands/value/delete/whole-inline.js rename to packages/slate/test/commands/value/delete/inline-whole.js diff --git a/packages/slate/test/commands/value/delete/inside-inline-sibling.js b/packages/slate/test/commands/value/delete/inside-inline-sibling.js deleted file mode 100644 index 5e0005f3c9..0000000000 --- a/packages/slate/test/commands/value/delete/inside-inline-sibling.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - one - a - two - - -) - -export const output = ( - - - one - - - two - - -) diff --git a/packages/slate/test/commands/value/delete/join-blocks-and-trim.js b/packages/slate/test/commands/value/delete/join-blocks-and-trim.js deleted file mode 100644 index 4428c797d4..0000000000 --- a/packages/slate/test/commands/value/delete/join-blocks-and-trim.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - - word - - - another - - - -) - -export const output = ( - - - - woother - - - -) diff --git a/packages/slate/test/commands/value/delete/join-nested-blocks.js b/packages/slate/test/commands/value/delete/join-nested-blocks.js deleted file mode 100644 index 029a926aca..0000000000 --- a/packages/slate/test/commands/value/delete/join-nested-blocks.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - - - word - - - another - - - - -) - -export const output = ( - - - - - wordanother - - - - -) diff --git a/packages/slate/test/commands/value/delete/expanded-across-whole-mark.js b/packages/slate/test/commands/value/delete/mark-across.js similarity index 100% rename from packages/slate/test/commands/value/delete/expanded-across-whole-mark.js rename to packages/slate/test/commands/value/delete/mark-across.js diff --git a/packages/slate/test/commands/value/delete/whole-word-mark.js b/packages/slate/test/commands/value/delete/mark-whole.js similarity index 100% rename from packages/slate/test/commands/value/delete/whole-word-mark.js rename to packages/slate/test/commands/value/delete/mark-whole.js diff --git a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js b/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js deleted file mode 100644 index 9dcc0fd8cb..0000000000 --- a/packages/slate/test/commands/value/delete/non-void-block-as-first-with-void-siblings-partially-non-void-and-void.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - - one - - - - - three - - -) - -export const output = ( - - - - on - - three - - -) diff --git a/packages/slate/test/commands/value/delete/non-void-triple.js b/packages/slate/test/commands/value/delete/non-void-triple.js deleted file mode 100644 index 6a97ded345..0000000000 --- a/packages/slate/test/commands/value/delete/non-void-triple.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - - 1 - - 2 - - 3 - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js b/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js deleted file mode 100644 index 5f612d9147..0000000000 --- a/packages/slate/test/commands/value/delete/void-block-as-first-with-non-void-siblings-select-void-end-and-next-word.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - - - - - two - - three - - -) - -export const output = ( - - - - o - - three - - -) diff --git a/packages/slate/test/commands/value/delete/whole-word.js b/packages/slate/test/commands/value/delete/word.js similarity index 100% rename from packages/slate/test/commands/value/delete/whole-word.js rename to packages/slate/test/commands/value/delete/word.js From 51c763aa2a62c2102ee7e895f1765370783f438b Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 11:11:12 -0400 Subject: [PATCH 046/165] rename --- .../value/delete/{collapsed-start.js => character/start.js} | 0 .../commands/value/delete/{ => expanded}/block-across-multiple.js | 0 .../commands/value/delete/{ => expanded}/block-across-nested.js | 0 .../test/commands/value/delete/{ => expanded}/block-across.js | 0 .../commands/value/delete/{ => expanded}/block-depths-nested.js | 0 .../test/commands/value/delete/{ => expanded}/block-depths.js | 0 .../value/delete/{ => expanded}/block-hanging-multiple.js | 0 .../commands/value/delete/{ => expanded}/block-hanging-single.js | 0 .../commands/value/delete/{ => expanded}/block-inline-across.js | 0 .../test/commands/value/delete/{ => expanded}/block-join-edges.js | 0 .../commands/value/delete/{ => expanded}/block-join-inline.js | 0 .../commands/value/delete/{ => expanded}/block-join-nested.js | 0 .../test/commands/value/delete/{ => expanded}/block-nested.js | 0 .../test/commands/value/delete/{ => expanded}/character-end.js | 0 .../test/commands/value/delete/{ => expanded}/character-middle.js | 0 .../test/commands/value/delete/{ => expanded}/character-start.js | 0 .../test/commands/value/delete/{ => expanded}/inline-after.js | 0 .../test/commands/value/delete/{ => expanded}/inline-inside.js | 0 .../test/commands/value/delete/{ => expanded}/inline-over.js | 0 .../test/commands/value/delete/{ => expanded}/inline-whole.js | 0 .../test/commands/value/delete/{ => expanded}/mark-across.js | 0 .../slate/test/commands/value/delete/{ => expanded}/mark-whole.js | 0 packages/slate/test/commands/value/delete/{ => expanded}/word.js | 0 .../delete/{block-void-backward.js => voids/block-backward.js} | 0 .../value/delete/{block-void-before.js => voids/block-before.js} | 0 .../value/delete/{block-void-both.js => voids/block-both.js} | 0 .../value/delete/{block-void-end.js => voids/block-end.js} | 0 .../{block-hanging-from-void.js => voids/block-hanging-from.js} | 0 .../{block-hanging-into-void.js => voids/block-hanging-into.js} | 0 .../value/delete/{block-void-only.js => voids/block-only.js} | 0 .../block-start-multiple.js} | 0 .../value/delete/{block-void-start.js => voids/block-start.js} | 0 .../value/delete/{inline-void-over.js => voids/inline-over.js} | 0 .../{inline-void-start-across.js => voids/inline-start-across.js} | 0 .../value/delete/{inline-void-start.js => voids/inline-start.js} | 0 35 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/commands/value/delete/{collapsed-start.js => character/start.js} (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-across-multiple.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-across-nested.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-across.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-depths-nested.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-depths.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-hanging-multiple.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-hanging-single.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-inline-across.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-join-edges.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-join-inline.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-join-nested.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/block-nested.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/character-end.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/character-middle.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/character-start.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/inline-after.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/inline-inside.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/inline-over.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/inline-whole.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/mark-across.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/mark-whole.js (100%) rename packages/slate/test/commands/value/delete/{ => expanded}/word.js (100%) rename packages/slate/test/commands/value/delete/{block-void-backward.js => voids/block-backward.js} (100%) rename packages/slate/test/commands/value/delete/{block-void-before.js => voids/block-before.js} (100%) rename packages/slate/test/commands/value/delete/{block-void-both.js => voids/block-both.js} (100%) rename packages/slate/test/commands/value/delete/{block-void-end.js => voids/block-end.js} (100%) rename packages/slate/test/commands/value/delete/{block-hanging-from-void.js => voids/block-hanging-from.js} (100%) rename packages/slate/test/commands/value/delete/{block-hanging-into-void.js => voids/block-hanging-into.js} (100%) rename packages/slate/test/commands/value/delete/{block-void-only.js => voids/block-only.js} (100%) rename packages/slate/test/commands/value/delete/{block-void-start-multiple.js => voids/block-start-multiple.js} (100%) rename packages/slate/test/commands/value/delete/{block-void-start.js => voids/block-start.js} (100%) rename packages/slate/test/commands/value/delete/{inline-void-over.js => voids/inline-over.js} (100%) rename packages/slate/test/commands/value/delete/{inline-void-start-across.js => voids/inline-start-across.js} (100%) rename packages/slate/test/commands/value/delete/{inline-void-start.js => voids/inline-start.js} (100%) diff --git a/packages/slate/test/commands/value/delete/collapsed-start.js b/packages/slate/test/commands/value/delete/character/start.js similarity index 100% rename from packages/slate/test/commands/value/delete/collapsed-start.js rename to packages/slate/test/commands/value/delete/character/start.js diff --git a/packages/slate/test/commands/value/delete/block-across-multiple.js b/packages/slate/test/commands/value/delete/expanded/block-across-multiple.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-across-multiple.js rename to packages/slate/test/commands/value/delete/expanded/block-across-multiple.js diff --git a/packages/slate/test/commands/value/delete/block-across-nested.js b/packages/slate/test/commands/value/delete/expanded/block-across-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-across-nested.js rename to packages/slate/test/commands/value/delete/expanded/block-across-nested.js diff --git a/packages/slate/test/commands/value/delete/block-across.js b/packages/slate/test/commands/value/delete/expanded/block-across.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-across.js rename to packages/slate/test/commands/value/delete/expanded/block-across.js diff --git a/packages/slate/test/commands/value/delete/block-depths-nested.js b/packages/slate/test/commands/value/delete/expanded/block-depths-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-depths-nested.js rename to packages/slate/test/commands/value/delete/expanded/block-depths-nested.js diff --git a/packages/slate/test/commands/value/delete/block-depths.js b/packages/slate/test/commands/value/delete/expanded/block-depths.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-depths.js rename to packages/slate/test/commands/value/delete/expanded/block-depths.js diff --git a/packages/slate/test/commands/value/delete/block-hanging-multiple.js b/packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-hanging-multiple.js rename to packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js diff --git a/packages/slate/test/commands/value/delete/block-hanging-single.js b/packages/slate/test/commands/value/delete/expanded/block-hanging-single.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-hanging-single.js rename to packages/slate/test/commands/value/delete/expanded/block-hanging-single.js diff --git a/packages/slate/test/commands/value/delete/block-inline-across.js b/packages/slate/test/commands/value/delete/expanded/block-inline-across.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-inline-across.js rename to packages/slate/test/commands/value/delete/expanded/block-inline-across.js diff --git a/packages/slate/test/commands/value/delete/block-join-edges.js b/packages/slate/test/commands/value/delete/expanded/block-join-edges.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-join-edges.js rename to packages/slate/test/commands/value/delete/expanded/block-join-edges.js diff --git a/packages/slate/test/commands/value/delete/block-join-inline.js b/packages/slate/test/commands/value/delete/expanded/block-join-inline.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-join-inline.js rename to packages/slate/test/commands/value/delete/expanded/block-join-inline.js diff --git a/packages/slate/test/commands/value/delete/block-join-nested.js b/packages/slate/test/commands/value/delete/expanded/block-join-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-join-nested.js rename to packages/slate/test/commands/value/delete/expanded/block-join-nested.js diff --git a/packages/slate/test/commands/value/delete/block-nested.js b/packages/slate/test/commands/value/delete/expanded/block-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-nested.js rename to packages/slate/test/commands/value/delete/expanded/block-nested.js diff --git a/packages/slate/test/commands/value/delete/character-end.js b/packages/slate/test/commands/value/delete/expanded/character-end.js similarity index 100% rename from packages/slate/test/commands/value/delete/character-end.js rename to packages/slate/test/commands/value/delete/expanded/character-end.js diff --git a/packages/slate/test/commands/value/delete/character-middle.js b/packages/slate/test/commands/value/delete/expanded/character-middle.js similarity index 100% rename from packages/slate/test/commands/value/delete/character-middle.js rename to packages/slate/test/commands/value/delete/expanded/character-middle.js diff --git a/packages/slate/test/commands/value/delete/character-start.js b/packages/slate/test/commands/value/delete/expanded/character-start.js similarity index 100% rename from packages/slate/test/commands/value/delete/character-start.js rename to packages/slate/test/commands/value/delete/expanded/character-start.js diff --git a/packages/slate/test/commands/value/delete/inline-after.js b/packages/slate/test/commands/value/delete/expanded/inline-after.js similarity index 100% rename from packages/slate/test/commands/value/delete/inline-after.js rename to packages/slate/test/commands/value/delete/expanded/inline-after.js diff --git a/packages/slate/test/commands/value/delete/inline-inside.js b/packages/slate/test/commands/value/delete/expanded/inline-inside.js similarity index 100% rename from packages/slate/test/commands/value/delete/inline-inside.js rename to packages/slate/test/commands/value/delete/expanded/inline-inside.js diff --git a/packages/slate/test/commands/value/delete/inline-over.js b/packages/slate/test/commands/value/delete/expanded/inline-over.js similarity index 100% rename from packages/slate/test/commands/value/delete/inline-over.js rename to packages/slate/test/commands/value/delete/expanded/inline-over.js diff --git a/packages/slate/test/commands/value/delete/inline-whole.js b/packages/slate/test/commands/value/delete/expanded/inline-whole.js similarity index 100% rename from packages/slate/test/commands/value/delete/inline-whole.js rename to packages/slate/test/commands/value/delete/expanded/inline-whole.js diff --git a/packages/slate/test/commands/value/delete/mark-across.js b/packages/slate/test/commands/value/delete/expanded/mark-across.js similarity index 100% rename from packages/slate/test/commands/value/delete/mark-across.js rename to packages/slate/test/commands/value/delete/expanded/mark-across.js diff --git a/packages/slate/test/commands/value/delete/mark-whole.js b/packages/slate/test/commands/value/delete/expanded/mark-whole.js similarity index 100% rename from packages/slate/test/commands/value/delete/mark-whole.js rename to packages/slate/test/commands/value/delete/expanded/mark-whole.js diff --git a/packages/slate/test/commands/value/delete/word.js b/packages/slate/test/commands/value/delete/expanded/word.js similarity index 100% rename from packages/slate/test/commands/value/delete/word.js rename to packages/slate/test/commands/value/delete/expanded/word.js diff --git a/packages/slate/test/commands/value/delete/block-void-backward.js b/packages/slate/test/commands/value/delete/voids/block-backward.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-void-backward.js rename to packages/slate/test/commands/value/delete/voids/block-backward.js diff --git a/packages/slate/test/commands/value/delete/block-void-before.js b/packages/slate/test/commands/value/delete/voids/block-before.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-void-before.js rename to packages/slate/test/commands/value/delete/voids/block-before.js diff --git a/packages/slate/test/commands/value/delete/block-void-both.js b/packages/slate/test/commands/value/delete/voids/block-both.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-void-both.js rename to packages/slate/test/commands/value/delete/voids/block-both.js diff --git a/packages/slate/test/commands/value/delete/block-void-end.js b/packages/slate/test/commands/value/delete/voids/block-end.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-void-end.js rename to packages/slate/test/commands/value/delete/voids/block-end.js diff --git a/packages/slate/test/commands/value/delete/block-hanging-from-void.js b/packages/slate/test/commands/value/delete/voids/block-hanging-from.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-hanging-from-void.js rename to packages/slate/test/commands/value/delete/voids/block-hanging-from.js diff --git a/packages/slate/test/commands/value/delete/block-hanging-into-void.js b/packages/slate/test/commands/value/delete/voids/block-hanging-into.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-hanging-into-void.js rename to packages/slate/test/commands/value/delete/voids/block-hanging-into.js diff --git a/packages/slate/test/commands/value/delete/block-void-only.js b/packages/slate/test/commands/value/delete/voids/block-only.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-void-only.js rename to packages/slate/test/commands/value/delete/voids/block-only.js diff --git a/packages/slate/test/commands/value/delete/block-void-start-multiple.js b/packages/slate/test/commands/value/delete/voids/block-start-multiple.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-void-start-multiple.js rename to packages/slate/test/commands/value/delete/voids/block-start-multiple.js diff --git a/packages/slate/test/commands/value/delete/block-void-start.js b/packages/slate/test/commands/value/delete/voids/block-start.js similarity index 100% rename from packages/slate/test/commands/value/delete/block-void-start.js rename to packages/slate/test/commands/value/delete/voids/block-start.js diff --git a/packages/slate/test/commands/value/delete/inline-void-over.js b/packages/slate/test/commands/value/delete/voids/inline-over.js similarity index 100% rename from packages/slate/test/commands/value/delete/inline-void-over.js rename to packages/slate/test/commands/value/delete/voids/inline-over.js diff --git a/packages/slate/test/commands/value/delete/inline-void-start-across.js b/packages/slate/test/commands/value/delete/voids/inline-start-across.js similarity index 100% rename from packages/slate/test/commands/value/delete/inline-void-start-across.js rename to packages/slate/test/commands/value/delete/voids/inline-start-across.js diff --git a/packages/slate/test/commands/value/delete/inline-void-start.js b/packages/slate/test/commands/value/delete/voids/inline-start.js similarity index 100% rename from packages/slate/test/commands/value/delete/inline-void-start.js rename to packages/slate/test/commands/value/delete/voids/inline-start.js From fa776c6ed1d1246c7e8959ee6cd87da7214c66d5 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 11:32:52 -0400 Subject: [PATCH 047/165] rename --- .../delete-backward/single-void-block.js | 24 ----------------- .../value/delete-char-backward/text-middle.js | 27 ------------------- .../value/delete-char-backward/text-start.js | 27 ------------------- .../value/delete-char-forward/text-start.js | 27 ------------------- .../character/end-reverse.js} | 0 .../character/first-reverse.js} | 0 .../delete/character/{start.js => first.js} | 0 .../character/inline-after-reverse.js} | 0 .../character/inline-before-reverse.js} | 0 .../character/inline-end-reverse.js} | 0 .../character/inline-inside-reverse.js} | 0 .../character/last-reverse.js} | 0 .../text-last.js => delete/character/last.js} | 0 .../character/middle-reverse.js} | 0 .../character/middle.js} | 0 .../character/multiple-reverse.js} | 0 .../character/start-reverse.js} | 0 .../collapsed/block-empty.js} | 0 .../collapsed/block-join-depths.js} | 0 .../collapsed/block-join-inline-before.js} | 0 .../collapsed/block-join-inline-inside.js} | 0 .../collapsed/block-join-inline-void.js} | 0 .../collapsed/block-join-nested.js} | 0 .../collapsed/block-join.js} | 0 .../emojis/inline-after-emoji-reverse.js} | 0 .../emojis}/inline-before-emoji.js | 0 .../emojis/inline-end-emoji-reverse.js} | 0 .../emojis/inline-inside-emoji-reverse.js} | 0 .../emojis}/inline-middle-emoji.js | 0 .../emojis/inline-only-emoji-reverse.js} | 0 .../emojis}/inline-start-emoji.js | 0 .../voids/collapsed-after.js} | 0 .../voids/collapsed-before.js} | 0 33 files changed, 105 deletions(-) delete mode 100644 packages/slate/test/commands/value/delete-backward/single-void-block.js delete mode 100644 packages/slate/test/commands/value/delete-char-backward/text-middle.js delete mode 100644 packages/slate/test/commands/value/delete-char-backward/text-start.js delete mode 100644 packages/slate/test/commands/value/delete-char-forward/text-start.js rename packages/slate/test/commands/value/{delete-char-backward/text-end.js => delete/character/end-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-backward/first-character.js => delete/character/first-reverse.js} (100%) rename packages/slate/test/commands/value/delete/character/{start.js => first.js} (100%) rename packages/slate/test/commands/value/{delete-backward/inline-after.js => delete/character/inline-after-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-backward/inline-before.js => delete/character/inline-before-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-backward/inline-end.js => delete/character/inline-end-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-backward/inline-inside.js => delete/character/inline-inside-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-backward/last-character.js => delete/character/last-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-char-forward/text-last.js => delete/character/last.js} (100%) rename packages/slate/test/commands/value/{delete-backward/middle-character.js => delete/character/middle-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-char-forward/text-middle.js => delete/character/middle.js} (100%) rename packages/slate/test/commands/value/{delete-backward/multiple-characters.js => delete/character/multiple-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-backward/start-of-document.js => delete/character/start-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-backward/single-non-void-block.js => delete/collapsed/block-empty.js} (100%) rename packages/slate/test/commands/value/{delete-backward/join-nested-blocks-different-depth.js => delete/collapsed/block-join-depths.js} (100%) rename packages/slate/test/commands/value/{delete-backward/join-blocks-with-inline.js => delete/collapsed/block-join-inline-before.js} (100%) rename packages/slate/test/commands/value/{delete-backward/join-blocks-from-inline.js => delete/collapsed/block-join-inline-inside.js} (100%) rename packages/slate/test/commands/value/{delete-backward/join-blocks-with-inline-void.js => delete/collapsed/block-join-inline-void.js} (100%) rename packages/slate/test/commands/value/{delete-backward/join-nested-blocks.js => delete/collapsed/block-join-nested.js} (100%) rename packages/slate/test/commands/value/{delete-backward/join-blocks.js => delete/collapsed/block-join.js} (100%) rename packages/slate/test/commands/value/{delete-char-backward/inline-after-emoji.js => delete/emojis/inline-after-emoji-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-char-forward => delete/emojis}/inline-before-emoji.js (100%) rename packages/slate/test/commands/value/{delete-char-backward/inline-end-emoji.js => delete/emojis/inline-end-emoji-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-char-backward/inline-inside-emoji.js => delete/emojis/inline-inside-emoji-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-char-forward => delete/emojis}/inline-middle-emoji.js (100%) rename packages/slate/test/commands/value/{delete-char-backward/inline-only-emoji.js => delete/emojis/inline-only-emoji-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-char-forward => delete/emojis}/inline-start-emoji.js (100%) rename packages/slate/test/commands/value/{delete-backward/empty-after-void-block.js => delete/voids/collapsed-after.js} (100%) rename packages/slate/test/commands/value/{delete-backward/empty-after-void-inline.js => delete/voids/collapsed-before.js} (100%) diff --git a/packages/slate/test/commands/value/delete-backward/single-void-block.js b/packages/slate/test/commands/value/delete-backward/single-void-block.js deleted file mode 100644 index 623f235224..0000000000 --- a/packages/slate/test/commands/value/delete-backward/single-void-block.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteBackward() -} - -export const input = ( - - - - {' '} - - - -) - -export const output = ( - - - - -) diff --git a/packages/slate/test/commands/value/delete-char-backward/text-middle.js b/packages/slate/test/commands/value/delete-char-backward/text-middle.js deleted file mode 100644 index 4774397f24..0000000000 --- a/packages/slate/test/commands/value/delete-char-backward/text-middle.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharBackward() -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - wod - - - -) diff --git a/packages/slate/test/commands/value/delete-char-backward/text-start.js b/packages/slate/test/commands/value/delete-char-backward/text-start.js deleted file mode 100644 index 15d94a853b..0000000000 --- a/packages/slate/test/commands/value/delete-char-backward/text-start.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharBackward() -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - ord - - - -) diff --git a/packages/slate/test/commands/value/delete-char-forward/text-start.js b/packages/slate/test/commands/value/delete-char-forward/text-start.js deleted file mode 100644 index ce88ea260f..0000000000 --- a/packages/slate/test/commands/value/delete-char-forward/text-start.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharForward() -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - ord - - - -) diff --git a/packages/slate/test/commands/value/delete-char-backward/text-end.js b/packages/slate/test/commands/value/delete/character/end-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-backward/text-end.js rename to packages/slate/test/commands/value/delete/character/end-reverse.js diff --git a/packages/slate/test/commands/value/delete-backward/first-character.js b/packages/slate/test/commands/value/delete/character/first-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/first-character.js rename to packages/slate/test/commands/value/delete/character/first-reverse.js diff --git a/packages/slate/test/commands/value/delete/character/start.js b/packages/slate/test/commands/value/delete/character/first.js similarity index 100% rename from packages/slate/test/commands/value/delete/character/start.js rename to packages/slate/test/commands/value/delete/character/first.js diff --git a/packages/slate/test/commands/value/delete-backward/inline-after.js b/packages/slate/test/commands/value/delete/character/inline-after-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/inline-after.js rename to packages/slate/test/commands/value/delete/character/inline-after-reverse.js diff --git a/packages/slate/test/commands/value/delete-backward/inline-before.js b/packages/slate/test/commands/value/delete/character/inline-before-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/inline-before.js rename to packages/slate/test/commands/value/delete/character/inline-before-reverse.js diff --git a/packages/slate/test/commands/value/delete-backward/inline-end.js b/packages/slate/test/commands/value/delete/character/inline-end-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/inline-end.js rename to packages/slate/test/commands/value/delete/character/inline-end-reverse.js diff --git a/packages/slate/test/commands/value/delete-backward/inline-inside.js b/packages/slate/test/commands/value/delete/character/inline-inside-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/inline-inside.js rename to packages/slate/test/commands/value/delete/character/inline-inside-reverse.js diff --git a/packages/slate/test/commands/value/delete-backward/last-character.js b/packages/slate/test/commands/value/delete/character/last-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/last-character.js rename to packages/slate/test/commands/value/delete/character/last-reverse.js diff --git a/packages/slate/test/commands/value/delete-char-forward/text-last.js b/packages/slate/test/commands/value/delete/character/last.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-forward/text-last.js rename to packages/slate/test/commands/value/delete/character/last.js diff --git a/packages/slate/test/commands/value/delete-backward/middle-character.js b/packages/slate/test/commands/value/delete/character/middle-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/middle-character.js rename to packages/slate/test/commands/value/delete/character/middle-reverse.js diff --git a/packages/slate/test/commands/value/delete-char-forward/text-middle.js b/packages/slate/test/commands/value/delete/character/middle.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-forward/text-middle.js rename to packages/slate/test/commands/value/delete/character/middle.js diff --git a/packages/slate/test/commands/value/delete-backward/multiple-characters.js b/packages/slate/test/commands/value/delete/character/multiple-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/multiple-characters.js rename to packages/slate/test/commands/value/delete/character/multiple-reverse.js diff --git a/packages/slate/test/commands/value/delete-backward/start-of-document.js b/packages/slate/test/commands/value/delete/character/start-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/start-of-document.js rename to packages/slate/test/commands/value/delete/character/start-reverse.js diff --git a/packages/slate/test/commands/value/delete-backward/single-non-void-block.js b/packages/slate/test/commands/value/delete/collapsed/block-empty.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/single-non-void-block.js rename to packages/slate/test/commands/value/delete/collapsed/block-empty.js diff --git a/packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js b/packages/slate/test/commands/value/delete/collapsed/block-join-depths.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/join-nested-blocks-different-depth.js rename to packages/slate/test/commands/value/delete/collapsed/block-join-depths.js diff --git a/packages/slate/test/commands/value/delete-backward/join-blocks-with-inline.js b/packages/slate/test/commands/value/delete/collapsed/block-join-inline-before.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/join-blocks-with-inline.js rename to packages/slate/test/commands/value/delete/collapsed/block-join-inline-before.js diff --git a/packages/slate/test/commands/value/delete-backward/join-blocks-from-inline.js b/packages/slate/test/commands/value/delete/collapsed/block-join-inline-inside.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/join-blocks-from-inline.js rename to packages/slate/test/commands/value/delete/collapsed/block-join-inline-inside.js diff --git a/packages/slate/test/commands/value/delete-backward/join-blocks-with-inline-void.js b/packages/slate/test/commands/value/delete/collapsed/block-join-inline-void.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/join-blocks-with-inline-void.js rename to packages/slate/test/commands/value/delete/collapsed/block-join-inline-void.js diff --git a/packages/slate/test/commands/value/delete-backward/join-nested-blocks.js b/packages/slate/test/commands/value/delete/collapsed/block-join-nested.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/join-nested-blocks.js rename to packages/slate/test/commands/value/delete/collapsed/block-join-nested.js diff --git a/packages/slate/test/commands/value/delete-backward/join-blocks.js b/packages/slate/test/commands/value/delete/collapsed/block-join.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/join-blocks.js rename to packages/slate/test/commands/value/delete/collapsed/block-join.js diff --git a/packages/slate/test/commands/value/delete-char-backward/inline-after-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-after-emoji-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-backward/inline-after-emoji.js rename to packages/slate/test/commands/value/delete/emojis/inline-after-emoji-reverse.js diff --git a/packages/slate/test/commands/value/delete-char-forward/inline-before-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-before-emoji.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-forward/inline-before-emoji.js rename to packages/slate/test/commands/value/delete/emojis/inline-before-emoji.js diff --git a/packages/slate/test/commands/value/delete-char-backward/inline-end-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-end-emoji-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-backward/inline-end-emoji.js rename to packages/slate/test/commands/value/delete/emojis/inline-end-emoji-reverse.js diff --git a/packages/slate/test/commands/value/delete-char-backward/inline-inside-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-inside-emoji-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-backward/inline-inside-emoji.js rename to packages/slate/test/commands/value/delete/emojis/inline-inside-emoji-reverse.js diff --git a/packages/slate/test/commands/value/delete-char-forward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-middle-emoji.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-forward/inline-middle-emoji.js rename to packages/slate/test/commands/value/delete/emojis/inline-middle-emoji.js diff --git a/packages/slate/test/commands/value/delete-char-backward/inline-only-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-only-emoji-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-backward/inline-only-emoji.js rename to packages/slate/test/commands/value/delete/emojis/inline-only-emoji-reverse.js diff --git a/packages/slate/test/commands/value/delete-char-forward/inline-start-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-start-emoji.js similarity index 100% rename from packages/slate/test/commands/value/delete-char-forward/inline-start-emoji.js rename to packages/slate/test/commands/value/delete/emojis/inline-start-emoji.js diff --git a/packages/slate/test/commands/value/delete-backward/empty-after-void-block.js b/packages/slate/test/commands/value/delete/voids/collapsed-after.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/empty-after-void-block.js rename to packages/slate/test/commands/value/delete/voids/collapsed-after.js diff --git a/packages/slate/test/commands/value/delete-backward/empty-after-void-inline.js b/packages/slate/test/commands/value/delete/voids/collapsed-before.js similarity index 100% rename from packages/slate/test/commands/value/delete-backward/empty-after-void-inline.js rename to packages/slate/test/commands/value/delete/voids/collapsed-before.js From fec20b963405b2fd3cfb3808ca131f58768ebe7e Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 13:28:39 -0400 Subject: [PATCH 048/165] refactor value.positions(), work on delete tests --- packages/slate/src/classes/commands/point.ts | 14 +-- packages/slate/src/classes/commands/range.ts | 12 +- packages/slate/src/classes/queries/path.ts | 4 +- packages/slate/src/classes/queries/point.ts | 1 + packages/slate/src/classes/queries/value.ts | 111 ++++++++++-------- .../delete-forward/before-inline-sibling.js | 2 +- .../delete-forward/empty-before-void-block.js | 2 +- .../empty-before-void-inline.js | 2 +- .../value/delete-forward/end-of-document.js | 18 ++- .../value/delete-forward/first-character.js | 18 ++- .../delete-forward/inside-inline-sibling.js | 2 +- .../join-blocks-with-inline-void.js | 2 +- .../delete-forward/join-blocks-with-inline.js | 2 +- .../value/delete-forward/join-blocks.js | 20 ++-- .../delete-forward/join-nested-blocks.js | 20 ++-- .../value/delete-forward/last-character.js | 18 ++- .../value/delete-forward/middle-character.js | 18 ++- .../delete-forward/single-non-void-block.js | 18 ++- .../value/delete-forward/single-void-block.js | 10 +- .../start-text-middle-inline.js | 2 +- .../value/delete/character/end-reverse.js | 20 ++-- .../commands/value/delete/character/end.js | 23 ++++ .../value/delete/character/first-reverse.js | 20 ++-- .../commands/value/delete/character/first.js | 4 +- .../delete/character/inline-after-reverse.js | 26 ++-- .../delete/character/inline-before-reverse.js | 30 ++--- .../delete/character/inline-end-reverse.js | 26 ++-- .../delete/character/inline-inside-reverse.js | 15 +-- .../value/delete/character/last-reverse.js | 20 ++-- .../commands/value/delete/character/last.js | 20 ++-- .../value/delete/character/middle-reverse.js | 20 ++-- .../commands/value/delete/character/middle.js | 20 ++-- .../delete/character/multiple-reverse.js | 20 ++-- .../value/delete/character/multiple.js | 23 ++++ .../value/delete/character/start-reverse.js | 20 ++-- .../value/delete/collapsed/block-empty.js | 27 ----- .../collapsed/block-join-inline-before.js | 28 ----- .../collapsed/block-join-inline-inside.js | 38 ------ .../delete/collapsed/block-join-nested.js | 32 ----- .../emojis/inline-after-emoji-reverse.js | 29 ----- .../delete/emojis/inline-before-emoji.js | 29 ----- .../delete/emojis/inline-end-emoji-reverse.js | 31 ----- .../value/delete/emojis/inline-end-reverse.js | 31 +++++ .../emojis/inline-inside-emoji-reverse.js | 31 ----- .../delete/emojis/inline-middle-emoji.js | 31 ----- .../delete/emojis/inline-middle-reverse.js | 31 +++++ .../value/delete/emojis/inline-middle.js | 31 +++++ ...moji-reverse.js => inline-only-reverse.js} | 11 +- .../value/delete/emojis/inline-start-emoji.js | 30 ----- .../value/delete/emojis/inline-start.js | 31 +++++ .../value/delete/emojis/text-end-reverse.js | 23 ++++ .../value/delete/emojis/text-start.js | 23 ++++ .../delete/expanded/block-across-multiple.js | 2 +- .../delete/expanded/block-across-nested.js | 38 +++--- .../value/delete/expanded/block-across.js | 2 +- .../delete/expanded/block-depths-nested.js | 2 +- .../value/delete/expanded/block-depths.js | 26 ++-- .../delete/expanded/block-hanging-multiple.js | 2 +- .../delete/expanded/block-hanging-single.js | 22 ++-- .../delete/expanded/block-inline-across.js | 2 +- .../value/delete/expanded/block-join-edges.js | 24 ++-- .../delete/expanded/block-join-inline.js | 2 +- .../delete/expanded/block-join-nested.js | 28 ++--- .../value/delete/expanded/block-nested.js | 2 +- .../value/delete/expanded/character-end.js | 22 ++-- .../value/delete/expanded/character-middle.js | 18 +-- .../value/delete/expanded/character-start.js | 2 +- .../value/delete/expanded/inline-after.js | 2 +- .../value/delete/expanded/inline-inside.js | 2 +- .../value/delete/expanded/inline-over.js | 2 +- .../value/delete/expanded/inline-whole.js | 2 +- .../value/delete/expanded/mark-across.js | 2 +- .../value/delete/expanded/mark-whole.js | 30 ++--- .../commands/value/delete/expanded/word.js | 22 ++-- .../value/delete/offset/block-empty.js | 23 ++++ .../block-join-depths.js | 12 +- .../delete/offset/block-join-inline-before.js | 28 +++++ .../delete/offset/block-join-inline-inside.js | 38 ++++++ .../block-join-inline-void.js | 7 +- .../block-join-nested.js} | 12 +- .../value/delete/offset/block-join.js | 24 ++++ .../value/delete/voids/block-backward.js | 30 ++--- .../value/delete/voids/block-before.js | 2 +- .../commands/value/delete/voids/block-both.js | 2 +- .../commands/value/delete/voids/block-end.js | 30 ++--- .../value/delete/voids/block-hanging-from.js | 28 ++--- .../value/delete/voids/block-hanging-into.js | 2 +- .../commands/value/delete/voids/block-only.js | 2 +- .../delete/voids/block-start-multiple.js | 2 +- .../value/delete/voids/block-start.js | 2 +- .../value/delete/voids/collapsed-after.js | 4 +- .../value/delete/voids/collapsed-before.js | 4 +- .../value/delete/voids/inline-over.js | 2 +- .../value/delete/voids/inline-start-across.js | 2 +- .../value/delete/voids/inline-start.js | 2 +- .../positions/all/block-multiple-reverse.js | 32 +++++ .../positions/{ => all}/block-multiple.js | 2 +- .../value/positions/{ => all}/block-nested.js | 2 +- .../positions/{ => all}/block-reverse.js | 2 +- .../value/positions/{ => all}/block.js | 2 +- .../positions/{ => all}/inline-multiple.js | 6 +- .../positions/{ => all}/inline-nested.js | 6 +- .../positions/{ => all}/inline-reverse.js | 4 +- .../value/positions/{ => all}/inline.js | 4 +- .../positions/{ => all}/unit-block-reverse.js | 2 +- .../value/positions/{ => all}/unit-block.js | 2 +- .../{ => all}/unit-character-reverse.js | 2 +- .../positions/{ => all}/unit-character.js | 2 +- .../positions/{ => all}/unit-line-reverse.js | 2 +- .../value/positions/{ => all}/unit-line.js | 2 +- .../positions/{ => all}/unit-word-reverse.js | 2 +- .../value/positions/{ => all}/unit-word.js | 2 +- .../positions/point/block-edge-reverse.js | 24 ++++ .../value/positions/point/block-edge.js | 22 ++++ .../positions/point/block-multiple-reverse.js | 31 +++++ .../value/positions/point/block-multiple.js | 30 +++++ .../value/positions/point/block-nested.js | 27 +++++ .../value/positions/point/block-reverse.js | 21 ++++ .../positions/{point.js => point/block.js} | 10 +- .../value/positions/point/inline-multiple.js | 40 +++++++ .../value/positions/point/inline-nested.js | 42 +++++++ .../value/positions/point/inline-reverse.js | 31 +++++ .../queries/value/positions/point/inline.js | 32 +++++ .../positions/point/unit-block-reverse.js | 26 ++++ .../value/positions/point/unit-block.js | 22 ++++ .../positions/point/unit-character-reverse.js | 34 ++++++ .../value/positions/point/unit-character.js | 30 +++++ .../positions/point/unit-line-reverse.js | 26 ++++ .../value/positions/point/unit-line.js | 22 ++++ .../positions/point/unit-word-reverse.js | 30 +++++ .../value/positions/point/unit-word.js | 26 ++++ 131 files changed, 1367 insertions(+), 839 deletions(-) create mode 100644 packages/slate/test/commands/value/delete/character/end.js create mode 100644 packages/slate/test/commands/value/delete/character/multiple.js delete mode 100644 packages/slate/test/commands/value/delete/collapsed/block-empty.js delete mode 100644 packages/slate/test/commands/value/delete/collapsed/block-join-inline-before.js delete mode 100644 packages/slate/test/commands/value/delete/collapsed/block-join-inline-inside.js delete mode 100644 packages/slate/test/commands/value/delete/collapsed/block-join-nested.js delete mode 100644 packages/slate/test/commands/value/delete/emojis/inline-after-emoji-reverse.js delete mode 100644 packages/slate/test/commands/value/delete/emojis/inline-before-emoji.js delete mode 100644 packages/slate/test/commands/value/delete/emojis/inline-end-emoji-reverse.js create mode 100644 packages/slate/test/commands/value/delete/emojis/inline-end-reverse.js delete mode 100644 packages/slate/test/commands/value/delete/emojis/inline-inside-emoji-reverse.js delete mode 100644 packages/slate/test/commands/value/delete/emojis/inline-middle-emoji.js create mode 100644 packages/slate/test/commands/value/delete/emojis/inline-middle-reverse.js create mode 100644 packages/slate/test/commands/value/delete/emojis/inline-middle.js rename packages/slate/test/commands/value/delete/emojis/{inline-only-emoji-reverse.js => inline-only-reverse.js} (61%) delete mode 100644 packages/slate/test/commands/value/delete/emojis/inline-start-emoji.js create mode 100644 packages/slate/test/commands/value/delete/emojis/inline-start.js create mode 100644 packages/slate/test/commands/value/delete/emojis/text-end-reverse.js create mode 100644 packages/slate/test/commands/value/delete/emojis/text-start.js create mode 100644 packages/slate/test/commands/value/delete/offset/block-empty.js rename packages/slate/test/commands/value/delete/{collapsed => offset}/block-join-depths.js (76%) create mode 100644 packages/slate/test/commands/value/delete/offset/block-join-inline-before.js create mode 100644 packages/slate/test/commands/value/delete/offset/block-join-inline-inside.js rename packages/slate/test/commands/value/delete/{collapsed => offset}/block-join-inline-void.js (75%) rename packages/slate/test/commands/value/delete/{collapsed/block-join.js => offset/block-join-nested.js} (69%) create mode 100644 packages/slate/test/commands/value/delete/offset/block-join.js create mode 100644 packages/slate/test/queries/value/positions/all/block-multiple-reverse.js rename packages/slate/test/queries/value/positions/{ => all}/block-multiple.js (94%) rename packages/slate/test/queries/value/positions/{ => all}/block-nested.js (93%) rename packages/slate/test/queries/value/positions/{ => all}/block-reverse.js (89%) rename packages/slate/test/queries/value/positions/{ => all}/block.js (88%) rename packages/slate/test/queries/value/positions/{ => all}/inline-multiple.js (83%) rename packages/slate/test/queries/value/positions/{ => all}/inline-nested.js (84%) rename packages/slate/test/queries/value/positions/{ => all}/inline-reverse.js (85%) rename packages/slate/test/queries/value/positions/{ => all}/inline.js (85%) rename packages/slate/test/queries/value/positions/{ => all}/unit-block-reverse.js (89%) rename packages/slate/test/queries/value/positions/{ => all}/unit-block.js (89%) rename packages/slate/test/queries/value/positions/{ => all}/unit-character-reverse.js (94%) rename packages/slate/test/queries/value/positions/{ => all}/unit-character.js (93%) rename packages/slate/test/queries/value/positions/{ => all}/unit-line-reverse.js (89%) rename packages/slate/test/queries/value/positions/{ => all}/unit-line.js (89%) rename packages/slate/test/queries/value/positions/{ => all}/unit-word-reverse.js (92%) rename packages/slate/test/queries/value/positions/{ => all}/unit-word.js (92%) create mode 100644 packages/slate/test/queries/value/positions/point/block-edge-reverse.js create mode 100644 packages/slate/test/queries/value/positions/point/block-edge.js create mode 100644 packages/slate/test/queries/value/positions/point/block-multiple-reverse.js create mode 100644 packages/slate/test/queries/value/positions/point/block-multiple.js create mode 100644 packages/slate/test/queries/value/positions/point/block-nested.js create mode 100644 packages/slate/test/queries/value/positions/point/block-reverse.js rename packages/slate/test/queries/value/positions/{point.js => point/block.js} (51%) create mode 100644 packages/slate/test/queries/value/positions/point/inline-multiple.js create mode 100644 packages/slate/test/queries/value/positions/point/inline-nested.js create mode 100644 packages/slate/test/queries/value/positions/point/inline-reverse.js create mode 100644 packages/slate/test/queries/value/positions/point/inline.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-block-reverse.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-block.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-character-reverse.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-character.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-line-reverse.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-line.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-word-reverse.js create mode 100644 packages/slate/test/queries/value/positions/point/unit-word.js diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index bf5109303f..4f8356a1b7 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -11,7 +11,7 @@ class PointCommands { point: Point, options: { distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' reverse?: boolean } = {} ): void { @@ -23,10 +23,12 @@ class PointCommands { return } - const { reverse = false, ...rest } = options + const { reverse = false, unit = 'offset', ...rest } = options const target = reverse - ? this.getPreviousPoint(point, rest) - : this.getNextPoint(point, rest) + ? this.getPreviousPoint(point, { unit, ...rest }) + : this.getNextPoint(point, { unit, ...rest }) + + debugger if (target) { this.deleteAtRange({ anchor: point, focus: target }) @@ -271,7 +273,7 @@ class PointCommands { let h = 0 debugger - // If the point it inside a void node, we still want to split up to a + // If the point it inside a void node, we still want to split up to a // `height`, but we need to start after the void node in the tree. if (furthestVoid) { const [, voidPath] = furthestVoid @@ -280,7 +282,6 @@ class PointCommands { position = voidPath[voidPath.length - 1] } - // Create a ref that tracks the split point as we move up the ancestors. // Stick backwards because we're splitting and we want to remain inside // the ancestor branch. @@ -313,7 +314,6 @@ class PointCommands { pointRef.unref() }) - } } diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index f6d3f96c9b..b89f4e226b 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -40,27 +40,17 @@ class RangeCommands { range: Range, options: { amount?: number - unit?: 'offset' | 'character' | 'word' | 'line' + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' reverse?: boolean hanging?: boolean } = {} ): void { - const { hanging = false } = options - - // If the range is collapsed, the delete functions like a backspace button - // or delete button would, by deleting in a direction. if (Range.isCollapsed(range)) { this.deleteAtPoint(range.anchor, options) return } this.withoutNormalizing(() => { - // To obey common rich text editor behavior, if the range is "hanging" - // into the end block, we move it backwards so that it's not. - // if (hanging === false) { - // range = this.getNonHangingRange(range) - // } - const [start, end] = Range.points(range) const beforeRef = this.createPointRef(start, { stick: 'backward' }) const startRef = this.createPointRef(start) diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index db4f52aaf7..cac289c461 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -323,10 +323,10 @@ class PathQueries { */ getStart(this: Editor, path: Path): Point | undefined { - const first = this.getLastText(path) + const first = this.getFirstText(path) if (first) { - const [node, path] = first + const [, path] = first const point = { path, offset: 0 } return point } diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index c7e85a87b8..582e0c3d09 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -70,6 +70,7 @@ class PointQueries { let d = 0 let target + debugger for (const p of this.positions({ ...options, point, reverse: true })) { if (d > distance) { break diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 4acc777a05..332d1f7c17 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -244,77 +244,96 @@ class ValueQueries { return } - if (unit !== 'offset') { - yield point - } - - const { path, offset } = point let string = '' - let distance = 0 + let available = 0 + let offset = 0 + let distance: number | null = null const advance = () => { - if (unit === 'character') { - distance = String.getCharacterDistance(string) - } else if (unit === 'word') { - distance = String.getWordDistance(string) - } else if (unit === 'line' || unit === 'block') { - // COMPAT: We equate 'line' in core to 'block'. This can be overriden in - // environments with rendered lines that can be calculated. - distance = string.length - } else { - distance = Math.min(string.length, 1) + if (distance == null) { + if (unit === 'character') { + distance = String.getCharacterDistance(string) + } else if (unit === 'word') { + distance = String.getWordDistance(string) + } else if (unit === 'line' || unit === 'block') { + distance = string.length + } else { + distance = 1 + } + + string = string.slice(distance) } - string = string.slice(distance) + // Add or substract the offset. + offset = reverse ? offset - distance : offset + distance + // Subtract the distance traveled from the available text. + available = available - distance! + // If the available had room to spare, reset the distance so that it will + // advance again next time. Otherwise, set it to the overflow amount. + distance = available >= 0 ? null : 0 - available } - for (const [n, p] of this.entries({ - path, + for (const [node, path] of this.entries({ + path: point.path, reverse, })) { - if (Element.isElement(n)) { - if (this.isVoid(n)) { - const start = this.getStart(p) - - if (start) { - yield start + if (Element.isElement(node)) { + // Void nodes are a special case, since we don't want to iterate over + // their content. We instead always just yield their first point. + if (this.isVoid(node)) { + const first = this.getFirstText(path) + + if (first) { + const [, firstPath] = first + yield { path: firstPath, offset: 0 } } continue } - if (!this.isInline(n) && this.hasInlines(n)) { - let text = this.getText(p) + if (!this.isInline(node) && this.hasInlines(node)) { + let text = this.getText(path) - if (Path.isAncestor(p, path)) { - const before = this.getOffset(path, { depth: p.length }) - const o = before + offset + if (Path.isAncestor(path, point.path)) { + const before = this.getOffset(point.path, { depth: path.length }) + const o = before + point.offset text = reverse ? text.slice(0, o) : text.slice(o) } string = reverse ? reverseText(text) : text - distance = 0 - - if (unit !== 'offset') { - advance() - } } } - if (Text.isText(n)) { - let remaining = n.text.length - let o = reverse ? remaining : 0 + if (Text.isText(node)) { + const isStart = Path.equals(path, point.path) + available = node.text.length + offset = reverse ? available : 0 + + if (isStart) { + available = reverse ? point.offset : available - point.offset + offset = point.offset + } - if (Path.equals(p, path)) { - remaining = reverse ? offset : remaining - offset - o = offset + // Always yield the start point. When advancing by offset, yield every + // text's start point before advancing, to get every potential point. + if (isStart || unit === 'offset') { + yield { path, offset } } - while (remaining > 0) { - o = reverse ? o - distance : o + distance - remaining -= distance - yield { path: p, offset: o } - advance() + while (true) { + if (string === '') { + break + } else { + advance() + } + + // If the available space hasn't overflow, we have another point to + // yield in the current text node. + if (available >= 0) { + yield { path, offset } + } else { + break + } } } } diff --git a/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js b/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js index f2c60719d4..cd429a55f2 100644 --- a/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js +++ b/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( diff --git a/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js b/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js index 3fd1d7d82f..572fec9e63 100644 --- a/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js +++ b/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( diff --git a/packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js b/packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js index 8ad7b3b2d1..a02262c6a4 100644 --- a/packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js +++ b/packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( diff --git a/packages/slate/test/commands/value/delete-forward/end-of-document.js b/packages/slate/test/commands/value/delete-forward/end-of-document.js index 8eef8e345a..92f32e09b8 100644 --- a/packages/slate/test/commands/value/delete-forward/end-of-document.js +++ b/packages/slate/test/commands/value/delete-forward/end-of-document.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - - - word - - + + word + ) export const output = ( - - - word - - + + word + ) diff --git a/packages/slate/test/commands/value/delete-forward/first-character.js b/packages/slate/test/commands/value/delete-forward/first-character.js index 465ffd5e69..ca8940d599 100644 --- a/packages/slate/test/commands/value/delete-forward/first-character.js +++ b/packages/slate/test/commands/value/delete-forward/first-character.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - - - word - - + + word + ) export const output = ( - - - ord - - + + ord + ) diff --git a/packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js b/packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js index 3d76ecee1d..90d09d46fb 100644 --- a/packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js +++ b/packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( diff --git a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js b/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js index b9af8646a1..2919eea66c 100644 --- a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js +++ b/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( diff --git a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js b/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js index a16d57ca42..1b37350206 100644 --- a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js +++ b/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( diff --git a/packages/slate/test/commands/value/delete-forward/join-blocks.js b/packages/slate/test/commands/value/delete-forward/join-blocks.js index ac3d28c109..408352aef8 100644 --- a/packages/slate/test/commands/value/delete-forward/join-blocks.js +++ b/packages/slate/test/commands/value/delete-forward/join-blocks.js @@ -3,26 +3,22 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - - - word - - another - + + word + + another ) export const output = ( - - - wordanother - - + + wordanother + ) diff --git a/packages/slate/test/commands/value/delete-forward/join-nested-blocks.js b/packages/slate/test/commands/value/delete-forward/join-nested-blocks.js index 89d74e449c..7176d778d8 100644 --- a/packages/slate/test/commands/value/delete-forward/join-nested-blocks.js +++ b/packages/slate/test/commands/value/delete-forward/join-nested-blocks.js @@ -3,30 +3,26 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - + - - word - - another + word - + another + ) export const output = ( - + - - wordanother - + wordanother - + ) diff --git a/packages/slate/test/commands/value/delete-forward/last-character.js b/packages/slate/test/commands/value/delete-forward/last-character.js index a99b19a574..a09e8f2fd7 100644 --- a/packages/slate/test/commands/value/delete-forward/last-character.js +++ b/packages/slate/test/commands/value/delete-forward/last-character.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - - - word - - + + word + ) export const output = ( - - - wor - - + + wor + ) diff --git a/packages/slate/test/commands/value/delete-forward/middle-character.js b/packages/slate/test/commands/value/delete-forward/middle-character.js index 1304f759c5..198aad4c0d 100644 --- a/packages/slate/test/commands/value/delete-forward/middle-character.js +++ b/packages/slate/test/commands/value/delete-forward/middle-character.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - - - word - - + + word + ) export const output = ( - - - wrd - - + + wrd + ) diff --git a/packages/slate/test/commands/value/delete-forward/single-non-void-block.js b/packages/slate/test/commands/value/delete-forward/single-non-void-block.js index bc8254cab5..2993e1ba4f 100644 --- a/packages/slate/test/commands/value/delete-forward/single-non-void-block.js +++ b/packages/slate/test/commands/value/delete-forward/single-non-void-block.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - - - - - + + + ) export const output = ( - - - - - + + + ) diff --git a/packages/slate/test/commands/value/delete-forward/single-void-block.js b/packages/slate/test/commands/value/delete-forward/single-void-block.js index 73fc1559e9..3a06057d44 100644 --- a/packages/slate/test/commands/value/delete-forward/single-void-block.js +++ b/packages/slate/test/commands/value/delete-forward/single-void-block.js @@ -3,16 +3,14 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( - - - {' '} - - + + {' '} + ) diff --git a/packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js b/packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js index b197d99eee..357c014f7e 100644 --- a/packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js +++ b/packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.deleteForward() + editor.delete() } export const input = ( diff --git a/packages/slate/test/commands/value/delete/character/end-reverse.js b/packages/slate/test/commands/value/delete/character/end-reverse.js index eac59d7cb4..024b58cece 100644 --- a/packages/slate/test/commands/value/delete/character/end-reverse.js +++ b/packages/slate/test/commands/value/delete/character/end-reverse.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteCharBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wor - - + + wor + ) diff --git a/packages/slate/test/commands/value/delete/character/end.js b/packages/slate/test/commands/value/delete/character/end.js new file mode 100644 index 0000000000..858bf9672d --- /dev/null +++ b/packages/slate/test/commands/value/delete/character/end.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character' }) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + wor + + +) diff --git a/packages/slate/test/commands/value/delete/character/first-reverse.js b/packages/slate/test/commands/value/delete/character/first-reverse.js index 6c001ac35c..c432f0682a 100644 --- a/packages/slate/test/commands/value/delete/character/first-reverse.js +++ b/packages/slate/test/commands/value/delete/character/first-reverse.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - ord - - + + ord + ) diff --git a/packages/slate/test/commands/value/delete/character/first.js b/packages/slate/test/commands/value/delete/character/first.js index ca8940d599..3dd2cb082a 100644 --- a/packages/slate/test/commands/value/delete/character/first.js +++ b/packages/slate/test/commands/value/delete/character/first.js @@ -1,9 +1,9 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.delete() + editor.delete({ unit: 'character' }) } export const input = ( diff --git a/packages/slate/test/commands/value/delete/character/inline-after-reverse.js b/packages/slate/test/commands/value/delete/character/inline-after-reverse.js index 1d05038145..8604892d19 100644 --- a/packages/slate/test/commands/value/delete/character/inline-after-reverse.js +++ b/packages/slate/test/commands/value/delete/character/inline-after-reverse.js @@ -1,29 +1,27 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - onetwoa - - + + one + two + a + ) export const output = ( - - - one - two - - - + + one + two + + ) diff --git a/packages/slate/test/commands/value/delete/character/inline-before-reverse.js b/packages/slate/test/commands/value/delete/character/inline-before-reverse.js index bb42489178..727b5090da 100644 --- a/packages/slate/test/commands/value/delete/character/inline-before-reverse.js +++ b/packages/slate/test/commands/value/delete/character/inline-before-reverse.js @@ -1,33 +1,27 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - a - two - - - + + a + two + three + ) export const output = ( - - - - - two - - - - + + + two + three + ) diff --git a/packages/slate/test/commands/value/delete/character/inline-end-reverse.js b/packages/slate/test/commands/value/delete/character/inline-end-reverse.js index 183fee82b4..3226d8804f 100644 --- a/packages/slate/test/commands/value/delete/character/inline-end-reverse.js +++ b/packages/slate/test/commands/value/delete/character/inline-end-reverse.js @@ -1,29 +1,27 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - onetwo - - - + + one + two + + ) export const output = ( - - - onetw - - - + + one + tw + + ) diff --git a/packages/slate/test/commands/value/delete/character/inline-inside-reverse.js b/packages/slate/test/commands/value/delete/character/inline-inside-reverse.js index 54f1f9fba6..c70abf1c2d 100644 --- a/packages/slate/test/commands/value/delete/character/inline-inside-reverse.js +++ b/packages/slate/test/commands/value/delete/character/inline-inside-reverse.js @@ -1,17 +1,19 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - one + one + a - two + + three ) @@ -20,11 +22,10 @@ export const output = ( one - - + - two + three ) diff --git a/packages/slate/test/commands/value/delete/character/last-reverse.js b/packages/slate/test/commands/value/delete/character/last-reverse.js index 64aa82eaac..024b58cece 100644 --- a/packages/slate/test/commands/value/delete/character/last-reverse.js +++ b/packages/slate/test/commands/value/delete/character/last-reverse.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wor - - + + wor + ) diff --git a/packages/slate/test/commands/value/delete/character/last.js b/packages/slate/test/commands/value/delete/character/last.js index 1dc75799e9..858bf9672d 100644 --- a/packages/slate/test/commands/value/delete/character/last.js +++ b/packages/slate/test/commands/value/delete/character/last.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteCharForward() + editor.delete({ unit: 'character' }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wor - - + + wor + ) diff --git a/packages/slate/test/commands/value/delete/character/middle-reverse.js b/packages/slate/test/commands/value/delete/character/middle-reverse.js index f72a13254f..e145bfa3b4 100644 --- a/packages/slate/test/commands/value/delete/character/middle-reverse.js +++ b/packages/slate/test/commands/value/delete/character/middle-reverse.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wrd - - + + wrd + ) diff --git a/packages/slate/test/commands/value/delete/character/middle.js b/packages/slate/test/commands/value/delete/character/middle.js index 0975a25c8c..4752de8a2f 100644 --- a/packages/slate/test/commands/value/delete/character/middle.js +++ b/packages/slate/test/commands/value/delete/character/middle.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteCharForward() + editor.delete({ unit: 'character' }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - wod - - + + wod + ) diff --git a/packages/slate/test/commands/value/delete/character/multiple-reverse.js b/packages/slate/test/commands/value/delete/character/multiple-reverse.js index 15f02b3e9a..d7eae70a9d 100644 --- a/packages/slate/test/commands/value/delete/character/multiple-reverse.js +++ b/packages/slate/test/commands/value/delete/character/multiple-reverse.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward(3) + editor.delete({ unit: 'character', distance: 3, reverse: true }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - w - - + + w + ) diff --git a/packages/slate/test/commands/value/delete/character/multiple.js b/packages/slate/test/commands/value/delete/character/multiple.js new file mode 100644 index 0000000000..9072e5f701 --- /dev/null +++ b/packages/slate/test/commands/value/delete/character/multiple.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character', distance: 3 }) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + d + + +) diff --git a/packages/slate/test/commands/value/delete/character/start-reverse.js b/packages/slate/test/commands/value/delete/character/start-reverse.js index b87a5d4cd4..04dac778be 100644 --- a/packages/slate/test/commands/value/delete/character/start-reverse.js +++ b/packages/slate/test/commands/value/delete/character/start-reverse.js @@ -1,27 +1,23 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( - - - word - - + + word + ) export const output = ( - - - word - - + + word + ) diff --git a/packages/slate/test/commands/value/delete/collapsed/block-empty.js b/packages/slate/test/commands/value/delete/collapsed/block-empty.js deleted file mode 100644 index 4a53764d0d..0000000000 --- a/packages/slate/test/commands/value/delete/collapsed/block-empty.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteBackward() -} - -export const input = ( - - - - - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete/collapsed/block-join-inline-before.js b/packages/slate/test/commands/value/delete/collapsed/block-join-inline-before.js deleted file mode 100644 index 2e0c17e7fb..0000000000 --- a/packages/slate/test/commands/value/delete/collapsed/block-join-inline-before.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteBackward() -} - -export const input = ( - - - one - - twothreefour - - - -) - -export const output = ( - - - - onetwothreefour - - - -) diff --git a/packages/slate/test/commands/value/delete/collapsed/block-join-inline-inside.js b/packages/slate/test/commands/value/delete/collapsed/block-join-inline-inside.js deleted file mode 100644 index 22a80019fc..0000000000 --- a/packages/slate/test/commands/value/delete/collapsed/block-join-inline-inside.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteBackward() -} - -export const input = ( - - - - onetwo - - - - - - three - four - - - -) - -export const output = ( - - - - onetwo - - - three - four - - - -) diff --git a/packages/slate/test/commands/value/delete/collapsed/block-join-nested.js b/packages/slate/test/commands/value/delete/collapsed/block-join-nested.js deleted file mode 100644 index 635b8aea9d..0000000000 --- a/packages/slate/test/commands/value/delete/collapsed/block-join-nested.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteBackward() -} - -export const input = ( - - - - word - - another - - - - -) - -export const output = ( - - - - - wordanother - - - - -) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-after-emoji-reverse.js b/packages/slate/test/commands/value/delete/emojis/inline-after-emoji-reverse.js deleted file mode 100644 index 2c2d2c0844..0000000000 --- a/packages/slate/test/commands/value/delete/emojis/inline-after-emoji-reverse.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharBackward() -} - -export const input = ( - - - - word📛 - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-before-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-before-emoji.js deleted file mode 100644 index 041a39690b..0000000000 --- a/packages/slate/test/commands/value/delete/emojis/inline-before-emoji.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharForward() -} - -export const input = ( - - - - 📛word - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-end-emoji-reverse.js b/packages/slate/test/commands/value/delete/emojis/inline-end-emoji-reverse.js deleted file mode 100644 index 0049e54973..0000000000 --- a/packages/slate/test/commands/value/delete/emojis/inline-end-emoji-reverse.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharBackward() -} - -export const input = ( - - - - - word📛 - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-end-reverse.js b/packages/slate/test/commands/value/delete/emojis/inline-end-reverse.js new file mode 100644 index 0000000000..4100c1b994 --- /dev/null +++ b/packages/slate/test/commands/value/delete/emojis/inline-end-reverse.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character', reverse: true }) +} + +export const input = ( + + + + + word📛 + + + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-inside-emoji-reverse.js b/packages/slate/test/commands/value/delete/emojis/inline-inside-emoji-reverse.js deleted file mode 100644 index 703edc2a14..0000000000 --- a/packages/slate/test/commands/value/delete/emojis/inline-inside-emoji-reverse.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharBackward() -} - -export const input = ( - - - - - wor📛d - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-middle-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-middle-emoji.js deleted file mode 100644 index d3acc1aba9..0000000000 --- a/packages/slate/test/commands/value/delete/emojis/inline-middle-emoji.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharForward() -} - -export const input = ( - - - - - wo📛rd - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-middle-reverse.js b/packages/slate/test/commands/value/delete/emojis/inline-middle-reverse.js new file mode 100644 index 0000000000..397e9a5896 --- /dev/null +++ b/packages/slate/test/commands/value/delete/emojis/inline-middle-reverse.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character', reverse: true }) +} + +export const input = ( + + + + + wor📛d + + + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-middle.js b/packages/slate/test/commands/value/delete/emojis/inline-middle.js new file mode 100644 index 0000000000..c19c0a708b --- /dev/null +++ b/packages/slate/test/commands/value/delete/emojis/inline-middle.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character' }) +} + +export const input = ( + + + + + wo📛rd + + + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-only-emoji-reverse.js b/packages/slate/test/commands/value/delete/emojis/inline-only-reverse.js similarity index 61% rename from packages/slate/test/commands/value/delete/emojis/inline-only-emoji-reverse.js rename to packages/slate/test/commands/value/delete/emojis/inline-only-reverse.js index 36adec6039..a0a0648301 100644 --- a/packages/slate/test/commands/value/delete/emojis/inline-only-emoji-reverse.js +++ b/packages/slate/test/commands/value/delete/emojis/inline-only-reverse.js @@ -1,17 +1,19 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteCharBackward() + editor.delete({ unit: 'character', reverse: true }) } export const input = ( + 📛 + ) @@ -19,10 +21,11 @@ export const input = ( export const output = ( - + - + + ) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-start-emoji.js b/packages/slate/test/commands/value/delete/emojis/inline-start-emoji.js deleted file mode 100644 index 4bd48481bb..0000000000 --- a/packages/slate/test/commands/value/delete/emojis/inline-start-emoji.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteCharForward() -} - -export const input = ( - - - - - 📛word - - - - -) - -export const output = ( - - - - - word - - - -) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-start.js b/packages/slate/test/commands/value/delete/emojis/inline-start.js new file mode 100644 index 0000000000..e5107daca7 --- /dev/null +++ b/packages/slate/test/commands/value/delete/emojis/inline-start.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character' }) +} + +export const input = ( + + + + + 📛word + + + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/value/delete/emojis/text-end-reverse.js b/packages/slate/test/commands/value/delete/emojis/text-end-reverse.js new file mode 100644 index 0000000000..5aece929ce --- /dev/null +++ b/packages/slate/test/commands/value/delete/emojis/text-end-reverse.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character', reverse: true }) +} + +export const input = ( + + + word📛 + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/value/delete/emojis/text-start.js b/packages/slate/test/commands/value/delete/emojis/text-start.js new file mode 100644 index 0000000000..8442b87a48 --- /dev/null +++ b/packages/slate/test/commands/value/delete/emojis/text-start.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'character' }) +} + +export const input = ( + + + 📛word + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/value/delete/expanded/block-across-multiple.js b/packages/slate/test/commands/value/delete/expanded/block-across-multiple.js index d62030248e..85ec344fd3 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-across-multiple.js +++ b/packages/slate/test/commands/value/delete/expanded/block-across-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-across-nested.js b/packages/slate/test/commands/value/delete/expanded/block-across-nested.js index c05edfa503..7a900eed53 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-across-nested.js +++ b/packages/slate/test/commands/value/delete/expanded/block-across-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,34 +8,34 @@ export const run = editor => { export const input = ( - + + - - one - - two + one + two + + - - three + three - four - - + four + + ) export const output = ( - + + - - onethree + onethree - - - four - - + + + four + + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-across.js b/packages/slate/test/commands/value/delete/expanded/block-across.js index 700e28d6ea..41319a384d 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-across.js +++ b/packages/slate/test/commands/value/delete/expanded/block-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-depths-nested.js b/packages/slate/test/commands/value/delete/expanded/block-depths-nested.js index 4dfa410c62..6a2f154ae8 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-depths-nested.js +++ b/packages/slate/test/commands/value/delete/expanded/block-depths-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-depths.js b/packages/slate/test/commands/value/delete/expanded/block-depths.js index e66b8feb94..97451ea3a2 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-depths.js +++ b/packages/slate/test/commands/value/delete/expanded/block-depths.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,26 +8,26 @@ export const run = editor => { export const input = ( - - - word + + + word + + middle - middle - - another + another - - + + ) export const output = ( - - - woother + + + woother - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js b/packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js index 549db4b30a..f06abf228e 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js +++ b/packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-hanging-single.js b/packages/slate/test/commands/value/delete/expanded/block-hanging-single.js index 4d8d010a6c..90cab64c9b 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-hanging-single.js +++ b/packages/slate/test/commands/value/delete/expanded/block-hanging-single.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,23 +8,23 @@ export const run = editor => { export const input = ( - - - one + + + one - - two + + two - + ) export const output = ( - - - two + + + two - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-inline-across.js b/packages/slate/test/commands/value/delete/expanded/block-inline-across.js index e5e89fbe88..a7a5f9613d 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-inline-across.js +++ b/packages/slate/test/commands/value/delete/expanded/block-inline-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-join-edges.js b/packages/slate/test/commands/value/delete/expanded/block-join-edges.js index 8401a48aae..5f70ec6103 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-join-edges.js +++ b/packages/slate/test/commands/value/delete/expanded/block-join-edges.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,23 +8,23 @@ export const run = editor => { export const input = ( - - - word - - - another + + + word + + + another - + ) export const output = ( - - - wordanother + + + wordanother - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-join-inline.js b/packages/slate/test/commands/value/delete/expanded/block-join-inline.js index bbb7f9e59c..ad76a8a6ca 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-join-inline.js +++ b/packages/slate/test/commands/value/delete/expanded/block-join-inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-join-nested.js b/packages/slate/test/commands/value/delete/expanded/block-join-nested.js index f71eeea35f..9fd1f046b4 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-join-nested.js +++ b/packages/slate/test/commands/value/delete/expanded/block-join-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,31 +8,31 @@ export const run = editor => { export const input = ( - + + - - word - - - another - + word + + another + - + + ) export const output = ( - + + - - wordanother + wordanother - - + + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-nested.js b/packages/slate/test/commands/value/delete/expanded/block-nested.js index 6640f0059d..a0a2c187b6 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-nested.js +++ b/packages/slate/test/commands/value/delete/expanded/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/character-end.js b/packages/slate/test/commands/value/delete/expanded/character-end.js index 65d05485d9..0a9e4b8a56 100644 --- a/packages/slate/test/commands/value/delete/expanded/character-end.js +++ b/packages/slate/test/commands/value/delete/expanded/character-end.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,20 +8,20 @@ export const run = editor => { export const input = ( - - - word - - + + + word + + ) export const output = ( - - - wor - - + + + wor + + ) diff --git a/packages/slate/test/commands/value/delete/expanded/character-middle.js b/packages/slate/test/commands/value/delete/expanded/character-middle.js index 100a1b2d34..3db53dd92a 100644 --- a/packages/slate/test/commands/value/delete/expanded/character-middle.js +++ b/packages/slate/test/commands/value/delete/expanded/character-middle.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,20 +8,20 @@ export const run = editor => { export const input = ( - - - word + + + word - + ) export const output = ( - - - wrd + + + wrd - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/character-start.js b/packages/slate/test/commands/value/delete/expanded/character-start.js index 469a3639a4..35ce9b4d24 100644 --- a/packages/slate/test/commands/value/delete/expanded/character-start.js +++ b/packages/slate/test/commands/value/delete/expanded/character-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-after.js b/packages/slate/test/commands/value/delete/expanded/inline-after.js index e60962a60f..dd10b73d9d 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-after.js +++ b/packages/slate/test/commands/value/delete/expanded/inline-after.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-inside.js b/packages/slate/test/commands/value/delete/expanded/inline-inside.js index 0bcb198090..1512c05c95 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-inside.js +++ b/packages/slate/test/commands/value/delete/expanded/inline-inside.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-over.js b/packages/slate/test/commands/value/delete/expanded/inline-over.js index 697cb3f86e..0e0c7f6e23 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-over.js +++ b/packages/slate/test/commands/value/delete/expanded/inline-over.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-whole.js b/packages/slate/test/commands/value/delete/expanded/inline-whole.js index 93c43ec015..8900159c34 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-whole.js +++ b/packages/slate/test/commands/value/delete/expanded/inline-whole.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/mark-across.js b/packages/slate/test/commands/value/delete/expanded/mark-across.js index 0fdcc358b3..00f50e937f 100644 --- a/packages/slate/test/commands/value/delete/expanded/mark-across.js +++ b/packages/slate/test/commands/value/delete/expanded/mark-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/mark-whole.js b/packages/slate/test/commands/value/delete/expanded/mark-whole.js index 27e28ba79d..783a80986f 100644 --- a/packages/slate/test/commands/value/delete/expanded/mark-whole.js +++ b/packages/slate/test/commands/value/delete/expanded/mark-whole.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - - - - word - - - + + + + word + + + ) export const output = ( - - - - - - - + + + + + + + ) diff --git a/packages/slate/test/commands/value/delete/expanded/word.js b/packages/slate/test/commands/value/delete/expanded/word.js index df0676da0e..4fc6801602 100644 --- a/packages/slate/test/commands/value/delete/expanded/word.js +++ b/packages/slate/test/commands/value/delete/expanded/word.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,20 +8,20 @@ export const run = editor => { export const input = ( - - - word - - + + + word + + ) export const output = ( - - - - - + + + + + ) diff --git a/packages/slate/test/commands/value/delete/offset/block-empty.js b/packages/slate/test/commands/value/delete/offset/block-empty.js new file mode 100644 index 0000000000..abd59b201c --- /dev/null +++ b/packages/slate/test/commands/value/delete/offset/block-empty.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ reverse: true }) +} + +export const input = ( + + + + + +) + +export const output = ( + + + + + +) diff --git a/packages/slate/test/commands/value/delete/collapsed/block-join-depths.js b/packages/slate/test/commands/value/delete/offset/block-join-depths.js similarity index 76% rename from packages/slate/test/commands/value/delete/collapsed/block-join-depths.js rename to packages/slate/test/commands/value/delete/offset/block-join-depths.js index 5df529fce0..680937dee3 100644 --- a/packages/slate/test/commands/value/delete/collapsed/block-join-depths.js +++ b/packages/slate/test/commands/value/delete/offset/block-join-depths.js @@ -1,30 +1,26 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ reverse: true }) } export const input = ( - Hello world! - + - ) export const output = ( - Helloworld! - - + ) diff --git a/packages/slate/test/commands/value/delete/offset/block-join-inline-before.js b/packages/slate/test/commands/value/delete/offset/block-join-inline-before.js new file mode 100644 index 0000000000..403a887b7b --- /dev/null +++ b/packages/slate/test/commands/value/delete/offset/block-join-inline-before.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ reverse: true }) +} + +export const input = ( + + one + + two + three + four + + +) + +export const output = ( + + + onetwo + three + four + + +) diff --git a/packages/slate/test/commands/value/delete/offset/block-join-inline-inside.js b/packages/slate/test/commands/value/delete/offset/block-join-inline-inside.js new file mode 100644 index 0000000000..caaebdd03d --- /dev/null +++ b/packages/slate/test/commands/value/delete/offset/block-join-inline-inside.js @@ -0,0 +1,38 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ reverse: true }) +} + +export const input = ( + + + one + two + + + + + + three + + four + + +) + +export const output = ( + + + one + two + + + three + + four + + +) diff --git a/packages/slate/test/commands/value/delete/collapsed/block-join-inline-void.js b/packages/slate/test/commands/value/delete/offset/block-join-inline-void.js similarity index 75% rename from packages/slate/test/commands/value/delete/collapsed/block-join-inline-void.js rename to packages/slate/test/commands/value/delete/offset/block-join-inline-void.js index 51039a307d..34f631df0b 100644 --- a/packages/slate/test/commands/value/delete/collapsed/block-join-inline-void.js +++ b/packages/slate/test/commands/value/delete/offset/block-join-inline-void.js @@ -1,17 +1,19 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ reverse: true }) } export const input = ( + + word @@ -22,6 +24,7 @@ export const input = ( export const output = ( + diff --git a/packages/slate/test/commands/value/delete/collapsed/block-join.js b/packages/slate/test/commands/value/delete/offset/block-join-nested.js similarity index 69% rename from packages/slate/test/commands/value/delete/collapsed/block-join.js rename to packages/slate/test/commands/value/delete/offset/block-join-nested.js index 1f804318fa..daf9257dd2 100644 --- a/packages/slate/test/commands/value/delete/collapsed/block-join.js +++ b/packages/slate/test/commands/value/delete/offset/block-join-nested.js @@ -1,28 +1,28 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ reverse: true }) } export const input = ( - + word another - + ) export const output = ( - + wordanother - + ) diff --git a/packages/slate/test/commands/value/delete/offset/block-join.js b/packages/slate/test/commands/value/delete/offset/block-join.js new file mode 100644 index 0000000000..3a815ce370 --- /dev/null +++ b/packages/slate/test/commands/value/delete/offset/block-join.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ reverse: true }) +} + +export const input = ( + + one + + two + + +) + +export const output = ( + + + onetwo + + +) diff --git a/packages/slate/test/commands/value/delete/voids/block-backward.js b/packages/slate/test/commands/value/delete/voids/block-backward.js index fb173012fe..6dc5453fcc 100644 --- a/packages/slate/test/commands/value/delete/voids/block-backward.js +++ b/packages/slate/test/commands/value/delete/voids/block-backward.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,24 +8,24 @@ export const run = editor => { export const input = ( - - - - - one - - two - - + + + + + one + + two + + ) export const output = ( - - - - - + + + + + ) diff --git a/packages/slate/test/commands/value/delete/voids/block-before.js b/packages/slate/test/commands/value/delete/voids/block-before.js index 8c0215f4ac..255be677ac 100644 --- a/packages/slate/test/commands/value/delete/voids/block-before.js +++ b/packages/slate/test/commands/value/delete/voids/block-before.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-both.js b/packages/slate/test/commands/value/delete/voids/block-both.js index e72b73db9e..7b66407c3f 100644 --- a/packages/slate/test/commands/value/delete/voids/block-both.js +++ b/packages/slate/test/commands/value/delete/voids/block-both.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-end.js b/packages/slate/test/commands/value/delete/voids/block-end.js index 9dcc0fd8cb..d10ffe1e68 100644 --- a/packages/slate/test/commands/value/delete/voids/block-end.js +++ b/packages/slate/test/commands/value/delete/voids/block-end.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,25 +8,25 @@ export const run = editor => { export const input = ( - - - one - - - + + + one - three - + + + + three + ) export const output = ( - - - on - - three - + + + on + + three + ) diff --git a/packages/slate/test/commands/value/delete/voids/block-hanging-from.js b/packages/slate/test/commands/value/delete/voids/block-hanging-from.js index 9ebfa3d0ce..9d850e947c 100644 --- a/packages/slate/test/commands/value/delete/voids/block-hanging-from.js +++ b/packages/slate/test/commands/value/delete/voids/block-hanging-from.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -8,25 +8,25 @@ export const run = editor => { export const input = ( - - - - - - one + + + + + + one - two - + two + ) export const output = ( - - - one + + + one - two - + two + ) diff --git a/packages/slate/test/commands/value/delete/voids/block-hanging-into.js b/packages/slate/test/commands/value/delete/voids/block-hanging-into.js index 93f7abad7c..1b515c3b09 100644 --- a/packages/slate/test/commands/value/delete/voids/block-hanging-into.js +++ b/packages/slate/test/commands/value/delete/voids/block-hanging-into.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-only.js b/packages/slate/test/commands/value/delete/voids/block-only.js index 332b3d7dad..578a0da901 100644 --- a/packages/slate/test/commands/value/delete/voids/block-only.js +++ b/packages/slate/test/commands/value/delete/voids/block-only.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-start-multiple.js b/packages/slate/test/commands/value/delete/voids/block-start-multiple.js index 1b8ab4d3bc..0137315b8d 100644 --- a/packages/slate/test/commands/value/delete/voids/block-start-multiple.js +++ b/packages/slate/test/commands/value/delete/voids/block-start-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-start.js b/packages/slate/test/commands/value/delete/voids/block-start.js index 69ca95c504..080a7d3a33 100644 --- a/packages/slate/test/commands/value/delete/voids/block-start.js +++ b/packages/slate/test/commands/value/delete/voids/block-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/collapsed-after.js b/packages/slate/test/commands/value/delete/voids/collapsed-after.js index eb18f15083..9c62e6b951 100644 --- a/packages/slate/test/commands/value/delete/voids/collapsed-after.js +++ b/packages/slate/test/commands/value/delete/voids/collapsed-after.js @@ -1,9 +1,9 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/value/delete/voids/collapsed-before.js b/packages/slate/test/commands/value/delete/voids/collapsed-before.js index ca0081772a..94dfdd5e57 100644 --- a/packages/slate/test/commands/value/delete/voids/collapsed-before.js +++ b/packages/slate/test/commands/value/delete/voids/collapsed-before.js @@ -1,9 +1,9 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteBackward() + editor.delete({ reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/value/delete/voids/inline-over.js b/packages/slate/test/commands/value/delete/voids/inline-over.js index d705ad1e5a..16d985089f 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-over.js +++ b/packages/slate/test/commands/value/delete/voids/inline-over.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/inline-start-across.js b/packages/slate/test/commands/value/delete/voids/inline-start-across.js index 6d016715c7..c0212656e8 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-start-across.js +++ b/packages/slate/test/commands/value/delete/voids/inline-start-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/inline-start.js b/packages/slate/test/commands/value/delete/voids/inline-start.js index 5c89427502..44463bf882 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-start.js +++ b/packages/slate/test/commands/value/delete/voids/inline-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/queries/value/positions/all/block-multiple-reverse.js b/packages/slate/test/queries/value/positions/all/block-multiple-reverse.js new file mode 100644 index 0000000000..9f14aca6c0 --- /dev/null +++ b/packages/slate/test/queries/value/positions/all/block-multiple-reverse.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.positions({ reverse: true })) +} + +export const output = [ + { path: [2, 0], offset: 5 }, + { path: [2, 0], offset: 4 }, + { path: [2, 0], offset: 3 }, + { path: [2, 0], offset: 2 }, + { path: [2, 0], offset: 1 }, + { path: [2, 0], offset: 0 }, + { path: [1, 0], offset: 3 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/block-multiple.js b/packages/slate/test/queries/value/positions/all/block-multiple.js similarity index 94% rename from packages/slate/test/queries/value/positions/block-multiple.js rename to packages/slate/test/queries/value/positions/all/block-multiple.js index 57161e9e46..9ad9e0a36c 100644 --- a/packages/slate/test/queries/value/positions/block-multiple.js +++ b/packages/slate/test/queries/value/positions/all/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/block-nested.js b/packages/slate/test/queries/value/positions/all/block-nested.js similarity index 93% rename from packages/slate/test/queries/value/positions/block-nested.js rename to packages/slate/test/queries/value/positions/all/block-nested.js index 7ea1c3b575..b3acda204e 100644 --- a/packages/slate/test/queries/value/positions/block-nested.js +++ b/packages/slate/test/queries/value/positions/all/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/block-reverse.js b/packages/slate/test/queries/value/positions/all/block-reverse.js similarity index 89% rename from packages/slate/test/queries/value/positions/block-reverse.js rename to packages/slate/test/queries/value/positions/all/block-reverse.js index fc1d861094..534574327b 100644 --- a/packages/slate/test/queries/value/positions/block-reverse.js +++ b/packages/slate/test/queries/value/positions/all/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/block.js b/packages/slate/test/queries/value/positions/all/block.js similarity index 88% rename from packages/slate/test/queries/value/positions/block.js rename to packages/slate/test/queries/value/positions/all/block.js index 35369ef9e8..e2659bf62c 100644 --- a/packages/slate/test/queries/value/positions/block.js +++ b/packages/slate/test/queries/value/positions/all/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/inline-multiple.js b/packages/slate/test/queries/value/positions/all/inline-multiple.js similarity index 83% rename from packages/slate/test/queries/value/positions/inline-multiple.js rename to packages/slate/test/queries/value/positions/all/inline-multiple.js index 9d601c8ccc..f1a4acf56f 100644 --- a/packages/slate/test/queries/value/positions/inline-multiple.js +++ b/packages/slate/test/queries/value/positions/all/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( @@ -19,18 +19,22 @@ export const output = [ { path: [0, 0], offset: 1 }, { path: [0, 0], offset: 2 }, { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 0 }, { path: [0, 1, 0], offset: 1 }, { path: [0, 1, 0], offset: 2 }, { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 0 }, { path: [0, 2], offset: 1 }, { path: [0, 2], offset: 2 }, { path: [0, 2], offset: 3 }, { path: [0, 2], offset: 4 }, { path: [0, 2], offset: 5 }, + { path: [0, 3, 0], offset: 0 }, { path: [0, 3, 0], offset: 1 }, { path: [0, 3, 0], offset: 2 }, { path: [0, 3, 0], offset: 3 }, { path: [0, 3, 0], offset: 4 }, + { path: [0, 4], offset: 0 }, { path: [0, 4], offset: 1 }, { path: [0, 4], offset: 2 }, { path: [0, 4], offset: 3 }, diff --git a/packages/slate/test/queries/value/positions/inline-nested.js b/packages/slate/test/queries/value/positions/all/inline-nested.js similarity index 84% rename from packages/slate/test/queries/value/positions/inline-nested.js rename to packages/slate/test/queries/value/positions/all/inline-nested.js index f2ef851952..44f3d5e4ed 100644 --- a/packages/slate/test/queries/value/positions/inline-nested.js +++ b/packages/slate/test/queries/value/positions/all/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( @@ -21,18 +21,22 @@ export const output = [ { path: [0, 0], offset: 1 }, { path: [0, 0], offset: 2 }, { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 0 }, { path: [0, 1, 0], offset: 1 }, { path: [0, 1, 0], offset: 2 }, { path: [0, 1, 0], offset: 3 }, + { path: [0, 1, 1, 0], offset: 0 }, { path: [0, 1, 1, 0], offset: 1 }, { path: [0, 1, 1, 0], offset: 2 }, { path: [0, 1, 1, 0], offset: 3 }, { path: [0, 1, 1, 0], offset: 4 }, { path: [0, 1, 1, 0], offset: 5 }, + { path: [0, 1, 2], offset: 0 }, { path: [0, 1, 2], offset: 1 }, { path: [0, 1, 2], offset: 2 }, { path: [0, 1, 2], offset: 3 }, { path: [0, 1, 2], offset: 4 }, + { path: [0, 2], offset: 0 }, { path: [0, 2], offset: 1 }, { path: [0, 2], offset: 2 }, { path: [0, 2], offset: 3 }, diff --git a/packages/slate/test/queries/value/positions/inline-reverse.js b/packages/slate/test/queries/value/positions/all/inline-reverse.js similarity index 85% rename from packages/slate/test/queries/value/positions/inline-reverse.js rename to packages/slate/test/queries/value/positions/all/inline-reverse.js index 8b85183fad..669ff477ee 100644 --- a/packages/slate/test/queries/value/positions/inline-reverse.js +++ b/packages/slate/test/queries/value/positions/all/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( @@ -21,9 +21,11 @@ export const output = [ { path: [0, 2], offset: 2 }, { path: [0, 2], offset: 1 }, { path: [0, 2], offset: 0 }, + { path: [0, 1, 0], offset: 3 }, { path: [0, 1, 0], offset: 2 }, { path: [0, 1, 0], offset: 1 }, { path: [0, 1, 0], offset: 0 }, + { path: [0, 0], offset: 3 }, { path: [0, 0], offset: 2 }, { path: [0, 0], offset: 1 }, { path: [0, 0], offset: 0 }, diff --git a/packages/slate/test/queries/value/positions/inline.js b/packages/slate/test/queries/value/positions/all/inline.js similarity index 85% rename from packages/slate/test/queries/value/positions/inline.js rename to packages/slate/test/queries/value/positions/all/inline.js index a8ec4f91da..a296b7c7b1 100644 --- a/packages/slate/test/queries/value/positions/inline.js +++ b/packages/slate/test/queries/value/positions/all/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( @@ -19,9 +19,11 @@ export const output = [ { path: [0, 0], offset: 1 }, { path: [0, 0], offset: 2 }, { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 0 }, { path: [0, 1, 0], offset: 1 }, { path: [0, 1, 0], offset: 2 }, { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 0 }, { path: [0, 2], offset: 1 }, { path: [0, 2], offset: 2 }, { path: [0, 2], offset: 3 }, diff --git a/packages/slate/test/queries/value/positions/unit-block-reverse.js b/packages/slate/test/queries/value/positions/all/unit-block-reverse.js similarity index 89% rename from packages/slate/test/queries/value/positions/unit-block-reverse.js rename to packages/slate/test/queries/value/positions/all/unit-block-reverse.js index 34ed90a8ab..50e1a3d10c 100644 --- a/packages/slate/test/queries/value/positions/unit-block-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/unit-block.js b/packages/slate/test/queries/value/positions/all/unit-block.js similarity index 89% rename from packages/slate/test/queries/value/positions/unit-block.js rename to packages/slate/test/queries/value/positions/all/unit-block.js index c8e151e15a..3e06293651 100644 --- a/packages/slate/test/queries/value/positions/unit-block.js +++ b/packages/slate/test/queries/value/positions/all/unit-block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/unit-character-reverse.js b/packages/slate/test/queries/value/positions/all/unit-character-reverse.js similarity index 94% rename from packages/slate/test/queries/value/positions/unit-character-reverse.js rename to packages/slate/test/queries/value/positions/all/unit-character-reverse.js index edd89344ed..d1814c3eb0 100644 --- a/packages/slate/test/queries/value/positions/unit-character-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-character-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/unit-character.js b/packages/slate/test/queries/value/positions/all/unit-character.js similarity index 93% rename from packages/slate/test/queries/value/positions/unit-character.js rename to packages/slate/test/queries/value/positions/all/unit-character.js index b2381edd8f..81eb621dcd 100644 --- a/packages/slate/test/queries/value/positions/unit-character.js +++ b/packages/slate/test/queries/value/positions/all/unit-character.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/unit-line-reverse.js b/packages/slate/test/queries/value/positions/all/unit-line-reverse.js similarity index 89% rename from packages/slate/test/queries/value/positions/unit-line-reverse.js rename to packages/slate/test/queries/value/positions/all/unit-line-reverse.js index 8979a9d110..669989f418 100644 --- a/packages/slate/test/queries/value/positions/unit-line-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-line-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/unit-line.js b/packages/slate/test/queries/value/positions/all/unit-line.js similarity index 89% rename from packages/slate/test/queries/value/positions/unit-line.js rename to packages/slate/test/queries/value/positions/all/unit-line.js index cf4bc97ac1..8a75a9b758 100644 --- a/packages/slate/test/queries/value/positions/unit-line.js +++ b/packages/slate/test/queries/value/positions/all/unit-line.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/unit-word-reverse.js b/packages/slate/test/queries/value/positions/all/unit-word-reverse.js similarity index 92% rename from packages/slate/test/queries/value/positions/unit-word-reverse.js rename to packages/slate/test/queries/value/positions/all/unit-word-reverse.js index 736354eddb..cf9ef80e6d 100644 --- a/packages/slate/test/queries/value/positions/unit-word-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-word-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/unit-word.js b/packages/slate/test/queries/value/positions/all/unit-word.js similarity index 92% rename from packages/slate/test/queries/value/positions/unit-word.js rename to packages/slate/test/queries/value/positions/all/unit-word.js index d27be1d981..fb6715ee0e 100644 --- a/packages/slate/test/queries/value/positions/unit-word.js +++ b/packages/slate/test/queries/value/positions/all/unit-word.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/value/positions/point/block-edge-reverse.js b/packages/slate/test/queries/value/positions/point/block-edge-reverse.js new file mode 100644 index 0000000000..ae3c87f009 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/block-edge-reverse.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return Array.from( + editor.positions({ reverse: true, point: { path: [1, 0], offset: 0 } }) + ) +} + +export const output = [ + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point/block-edge.js b/packages/slate/test/queries/value/positions/point/block-edge.js new file mode 100644 index 0000000000..b464de97e8 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/block-edge.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return Array.from(editor.positions({ point: { path: [0, 0], offset: 3 } })) +} + +export const output = [ + { path: [0, 0], offset: 3 }, + { path: [1, 0], offset: 0 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 3 }, +] diff --git a/packages/slate/test/queries/value/positions/point/block-multiple-reverse.js b/packages/slate/test/queries/value/positions/point/block-multiple-reverse.js new file mode 100644 index 0000000000..1a20c6f484 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/block-multiple-reverse.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from( + editor.positions({ reverse: true, point: { path: [2, 0], offset: 2 } }) + ) +} + +export const output = [ + { path: [2, 0], offset: 2 }, + { path: [2, 0], offset: 1 }, + { path: [2, 0], offset: 0 }, + { path: [1, 0], offset: 3 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point/block-multiple.js b/packages/slate/test/queries/value/positions/point/block-multiple.js new file mode 100644 index 0000000000..4a6ca82783 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/block-multiple.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) +} + +export const output = [ + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [1, 0], offset: 0 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 3 }, + { path: [2, 0], offset: 0 }, + { path: [2, 0], offset: 1 }, + { path: [2, 0], offset: 2 }, + { path: [2, 0], offset: 3 }, + { path: [2, 0], offset: 4 }, + { path: [2, 0], offset: 5 }, +] diff --git a/packages/slate/test/queries/value/positions/point/block-nested.js b/packages/slate/test/queries/value/positions/point/block-nested.js new file mode 100644 index 0000000000..fc5718cb63 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/block-nested.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + return Array.from(editor.positions({ point: { path: [0, 0, 0], offset: 2 } })) +} + +export const output = [ + { path: [0, 0, 0], offset: 2 }, + { path: [0, 0, 0], offset: 3 }, + { path: [1, 0, 0], offset: 0 }, + { path: [1, 0, 0], offset: 1 }, + { path: [1, 0, 0], offset: 2 }, + { path: [1, 0, 0], offset: 3 }, +] diff --git a/packages/slate/test/queries/value/positions/point/block-reverse.js b/packages/slate/test/queries/value/positions/point/block-reverse.js new file mode 100644 index 0000000000..23ac2504fd --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/block-reverse.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from( + editor.positions({ reverse: true, point: { path: [0, 0], offset: 2 } }) + ) +} + +export const output = [ + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point.js b/packages/slate/test/queries/value/positions/point/block.js similarity index 51% rename from packages/slate/test/queries/value/positions/point.js rename to packages/slate/test/queries/value/positions/point/block.js index c2ca765a4b..341ae6e587 100644 --- a/packages/slate/test/queries/value/positions/point.js +++ b/packages/slate/test/queries/value/positions/point/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const input = ( @@ -9,7 +9,11 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) + return Array.from(editor.positions({ point: { path: [0, 0], offset: 1 } })) } -export const output = [{ path: [0, 0], offset: 2 }, { path: [0, 0], offset: 3 }] +export const output = [ + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, +] diff --git a/packages/slate/test/queries/value/positions/point/inline-multiple.js b/packages/slate/test/queries/value/positions/point/inline-multiple.js new file mode 100644 index 0000000000..d28f326670 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/inline-multiple.js @@ -0,0 +1,40 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + + onetwothreefourfive + + +) + +export const run = editor => { + return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) +} + +export const output = [ + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 0 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 5 }, + { path: [0, 3, 0], offset: 0 }, + { path: [0, 3, 0], offset: 1 }, + { path: [0, 3, 0], offset: 2 }, + { path: [0, 3, 0], offset: 3 }, + { path: [0, 3, 0], offset: 4 }, + { path: [0, 4], offset: 0 }, + { path: [0, 4], offset: 1 }, + { path: [0, 4], offset: 2 }, + { path: [0, 4], offset: 3 }, + { path: [0, 4], offset: 4 }, +] diff --git a/packages/slate/test/queries/value/positions/point/inline-nested.js b/packages/slate/test/queries/value/positions/point/inline-nested.js new file mode 100644 index 0000000000..6d677a4803 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/inline-nested.js @@ -0,0 +1,42 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + + one + twothreefour + five + + +) + +export const run = editor => { + return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) +} + +export const output = [ + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 1, 1, 0], offset: 0 }, + { path: [0, 1, 1, 0], offset: 1 }, + { path: [0, 1, 1, 0], offset: 2 }, + { path: [0, 1, 1, 0], offset: 3 }, + { path: [0, 1, 1, 0], offset: 4 }, + { path: [0, 1, 1, 0], offset: 5 }, + { path: [0, 1, 2], offset: 0 }, + { path: [0, 1, 2], offset: 1 }, + { path: [0, 1, 2], offset: 2 }, + { path: [0, 1, 2], offset: 3 }, + { path: [0, 1, 2], offset: 4 }, + { path: [0, 2], offset: 0 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, +] diff --git a/packages/slate/test/queries/value/positions/point/inline-reverse.js b/packages/slate/test/queries/value/positions/point/inline-reverse.js new file mode 100644 index 0000000000..97a16e73ab --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/inline-reverse.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from( + editor.positions({ reverse: true, point: { path: [0, 2], offset: 2 } }) + ) +} + +export const output = [ + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 0 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point/inline.js b/packages/slate/test/queries/value/positions/point/inline.js new file mode 100644 index 0000000000..a296b7c7b1 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/inline.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.positions()) +} + +export const output = [ + { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 0 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 5 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-block-reverse.js b/packages/slate/test/queries/value/positions/point/unit-block-reverse.js new file mode 100644 index 0000000000..3a57af2535 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-block-reverse.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from( + editor.positions({ + unit: 'block', + reverse: true, + point: { path: [1, 0], offset: 4 }, + }) + ) +} + +export const output = [ + { path: [1, 0], offset: 4 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-block.js b/packages/slate/test/queries/value/positions/point/unit-block.js new file mode 100644 index 0000000000..3a831e2158 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-block.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from( + editor.positions({ unit: 'block', point: { path: [0, 0], offset: 3 } }) + ) +} + +export const output = [ + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 13 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-character-reverse.js b/packages/slate/test/queries/value/positions/point/unit-character-reverse.js new file mode 100644 index 0000000000..a5b70bf978 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-character-reverse.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from( + editor.positions({ + unit: 'character', + reverse: true, + point: { path: [0, 2], offset: 3 }, + }) + ) +} + +export const output = [ + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 0 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-character.js b/packages/slate/test/queries/value/positions/point/unit-character.js new file mode 100644 index 0000000000..30be6af250 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-character.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from( + editor.positions({ unit: 'character', point: { path: [0, 0], offset: 2 } }) + ) +} + +export const output = [ + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, + { path: [0, 2], offset: 1 }, + { path: [0, 2], offset: 2 }, + { path: [0, 2], offset: 3 }, + { path: [0, 2], offset: 4 }, + { path: [0, 2], offset: 5 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-line-reverse.js b/packages/slate/test/queries/value/positions/point/unit-line-reverse.js new file mode 100644 index 0000000000..b1bb19064c --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-line-reverse.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from( + editor.positions({ + unit: 'line', + reverse: true, + point: { path: [1, 0], offset: 3 }, + }) + ) +} + +export const output = [ + { path: [1, 0], offset: 3 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-line.js b/packages/slate/test/queries/value/positions/point/unit-line.js new file mode 100644 index 0000000000..07b91419e7 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-line.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from( + editor.positions({ unit: 'line', point: { path: [0, 0], offset: 3 } }) + ) +} + +export const output = [ + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 13 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-word-reverse.js b/packages/slate/test/queries/value/positions/point/unit-word-reverse.js new file mode 100644 index 0000000000..ca0bb80268 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-word-reverse.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from( + editor.positions({ + unit: 'word', + reverse: true, + point: { path: [1, 0], offset: 11 }, + }) + ) +} + +export const output = [ + { path: [1, 0], offset: 11 }, + { path: [1, 0], offset: 10 }, + { path: [1, 0], offset: 5 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 8 }, + { path: [0, 0], offset: 4 }, + { path: [0, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/value/positions/point/unit-word.js b/packages/slate/test/queries/value/positions/point/unit-word.js new file mode 100644 index 0000000000..107fd652f0 --- /dev/null +++ b/packages/slate/test/queries/value/positions/point/unit-word.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const input = ( + + one two three + four five six + +) + +export const run = editor => { + return Array.from( + editor.positions({ unit: 'word', point: { path: [0, 0], offset: 1 } }) + ) +} + +export const output = [ + { path: [0, 0], offset: 1 }, + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 7 }, + { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 4 }, + { path: [1, 0], offset: 9 }, + { path: [1, 0], offset: 13 }, +] From a777c16358fef2b3407bbc2f08e1816139746704 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 15:05:30 -0400 Subject: [PATCH 049/165] progress on delete tests --- packages/slate/src/classes/commands/path.ts | 6 +++--- packages/slate/src/classes/commands/point.ts | 5 ++--- packages/slate/src/classes/commands/range.ts | 2 +- packages/slate/src/classes/queries/element.ts | 15 +++++++++++++++ packages/slate/src/classes/queries/value.ts | 13 ++++++++++--- .../voids/{collapsed-after.js => block-after.js} | 2 ++ .../commands/value/delete/voids/block-before.js | 2 +- .../{collapsed-before.js => inline-after.js} | 6 +++--- .../value/positions/all/unit-character-reverse.js | 15 +++++++++++++++ .../queries/value/positions/all/unit-character.js | 15 +++++++++++++++ 10 files changed, 67 insertions(+), 14 deletions(-) rename packages/slate/test/commands/value/delete/voids/{collapsed-after.js => block-after.js} (93%) rename packages/slate/test/commands/value/delete/voids/{collapsed-before.js => inline-after.js} (89%) diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 8c649cb7ff..9f5e3bff1c 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -122,7 +122,7 @@ class PathCommands { } const [, blockPath] = closestBlock - const [, prevPath] = prevBlock + const [prev, prevPath] = prevBlock const newPath = Path.next(prevPath) const commonPath = Path.common(blockPath, prevPath) const furthest = Node.furthest(value, blockPath, ([n, p]) => { @@ -148,7 +148,7 @@ class PathCommands { // rich text editor common behavior to prevent losing block formatting // when deleting the entire previous block (with a hanging selection). debugger - if (this.getText(prevPath) === '') { + if (this.isEmpty(prev)) { this.removeNodeAtPath(prevPath) } else { this.mergeNodeAtPath(newPath) @@ -271,7 +271,7 @@ class PathCommands { // index that accounts for any added/removed nodes. let n = 0 - for (let i = 0; i < node.nodes.length; i++ , n++) { + for (let i = 0; i < node.nodes.length; i++, n++) { const child = node.nodes[i] as Descendant const prev = node.nodes[i - 1] const isLast = i === node.nodes.length - 1 diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index 4f8356a1b7..d836ea76f6 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -11,10 +11,11 @@ class PointCommands { point: Point, options: { distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' | 'block' + unit?: 'character' | 'word' | 'line' | 'block' reverse?: boolean } = {} ): void { + const { reverse = false, unit = 'character', ...rest } = options const furthestVoid = this.getFurthestVoid(point.path) if (furthestVoid) { @@ -23,13 +24,11 @@ class PointCommands { return } - const { reverse = false, unit = 'offset', ...rest } = options const target = reverse ? this.getPreviousPoint(point, { unit, ...rest }) : this.getNextPoint(point, { unit, ...rest }) debugger - if (target) { this.deleteAtRange({ anchor: point, focus: target }) } diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index b89f4e226b..70ec1ee843 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -40,7 +40,7 @@ class RangeCommands { range: Range, options: { amount?: number - unit?: 'offset' | 'character' | 'word' | 'line' | 'block' + unit?: 'character' | 'word' | 'line' | 'block' reverse?: boolean hanging?: boolean } = {} diff --git a/packages/slate/src/classes/queries/element.ts b/packages/slate/src/classes/queries/element.ts index 5b3cd929d1..2c08a3efe2 100644 --- a/packages/slate/src/classes/queries/element.ts +++ b/packages/slate/src/classes/queries/element.ts @@ -27,6 +27,21 @@ class ElementQueries { return element.nodes.every(n => Text.isText(n)) } + /** + * Check if an element is empty, accounting for void nodes. + */ + + isEmpty(this: Editor, element: Element): boolean { + const { nodes } = element + const [first] = nodes + return ( + nodes.length === 1 && + Text.isText(first) && + first.text === '' && + !this.isVoid(element) + ) + } + /** * Check if a node is an inline, meaning that it lives intermixed with text * nodes in the document tree. diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 332d1f7c17..cd416808ae 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -248,6 +248,7 @@ class ValueQueries { let available = 0 let offset = 0 let distance: number | null = null + let isBlockStart = true const advance = () => { if (distance == null) { @@ -301,6 +302,7 @@ class ValueQueries { } string = reverse ? reverseText(text) : text + isBlockStart = true } } @@ -314,13 +316,16 @@ class ValueQueries { offset = point.offset } - // Always yield the start point. When advancing by offset, yield every - // text's start point before advancing, to get every potential point. - if (isStart || unit === 'offset') { + if ( + isStart || + unit === 'offset' || + (unit === 'character' && isBlockStart) + ) { yield { path, offset } } while (true) { + // If there's no more string, continue to the next block. if (string === '') { break } else { @@ -335,6 +340,8 @@ class ValueQueries { break } } + + isBlockStart = false } } } diff --git a/packages/slate/test/commands/value/delete/voids/collapsed-after.js b/packages/slate/test/commands/value/delete/voids/block-after.js similarity index 93% rename from packages/slate/test/commands/value/delete/voids/collapsed-after.js rename to packages/slate/test/commands/value/delete/voids/block-after.js index 9c62e6b951..949cc14c8b 100644 --- a/packages/slate/test/commands/value/delete/voids/collapsed-after.js +++ b/packages/slate/test/commands/value/delete/voids/block-after.js @@ -24,3 +24,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/value/delete/voids/block-before.js b/packages/slate/test/commands/value/delete/voids/block-before.js index 255be677ac..d4e91fdac0 100644 --- a/packages/slate/test/commands/value/delete/voids/block-before.js +++ b/packages/slate/test/commands/value/delete/voids/block-before.js @@ -9,7 +9,7 @@ export const run = editor => { export const input = ( - one + one diff --git a/packages/slate/test/commands/value/delete/voids/collapsed-before.js b/packages/slate/test/commands/value/delete/voids/inline-after.js similarity index 89% rename from packages/slate/test/commands/value/delete/voids/collapsed-before.js rename to packages/slate/test/commands/value/delete/voids/inline-after.js index 94dfdd5e57..e99c405532 100644 --- a/packages/slate/test/commands/value/delete/voids/collapsed-before.js +++ b/packages/slate/test/commands/value/delete/voids/inline-after.js @@ -13,9 +13,7 @@ export const input = ( - - - + ) @@ -29,3 +27,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/queries/value/positions/all/unit-character-reverse.js b/packages/slate/test/queries/value/positions/all/unit-character-reverse.js index d1814c3eb0..3acf1a1c57 100644 --- a/packages/slate/test/queries/value/positions/all/unit-character-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-character-reverse.js @@ -7,6 +7,9 @@ export const input = ( onetwothree + + fourfivesix + ) @@ -15,6 +18,18 @@ export const run = editor => { } export const output = [ + { path: [1, 2], offset: 3 }, + { path: [1, 2], offset: 2 }, + { path: [1, 2], offset: 1 }, + { path: [1, 2], offset: 0 }, + { path: [1, 1, 0], offset: 3 }, + { path: [1, 1, 0], offset: 2 }, + { path: [1, 1, 0], offset: 1 }, + { path: [1, 1, 0], offset: 0 }, + { path: [1, 0], offset: 3 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 0 }, { path: [0, 2], offset: 5 }, { path: [0, 2], offset: 4 }, { path: [0, 2], offset: 3 }, diff --git a/packages/slate/test/queries/value/positions/all/unit-character.js b/packages/slate/test/queries/value/positions/all/unit-character.js index 81eb621dcd..c4b93144b6 100644 --- a/packages/slate/test/queries/value/positions/all/unit-character.js +++ b/packages/slate/test/queries/value/positions/all/unit-character.js @@ -7,6 +7,9 @@ export const input = ( onetwothree + + fourfivesix + ) @@ -27,4 +30,16 @@ export const output = [ { path: [0, 2], offset: 3 }, { path: [0, 2], offset: 4 }, { path: [0, 2], offset: 5 }, + { path: [1, 0], offset: 0 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 3 }, + { path: [1, 0], offset: 4 }, + { path: [1, 1, 0], offset: 1 }, + { path: [1, 1, 0], offset: 2 }, + { path: [1, 1, 0], offset: 3 }, + { path: [1, 1, 0], offset: 4 }, + { path: [1, 2], offset: 1 }, + { path: [1, 2], offset: 2 }, + { path: [1, 2], offset: 3 }, ] From 6944426c1b95ea96a1838f879a99804567685a8a Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 15:17:09 -0400 Subject: [PATCH 050/165] more delete work --- packages/slate/src/classes/commands/point.ts | 1 - .../delete-forward/before-inline-sibling.js | 27 ------------------- .../delete-forward/empty-before-void-block.js | 26 ------------------ .../value/delete-forward/first-character.js | 23 ---------------- .../value/delete-forward/last-character.js | 23 ---------------- .../value/delete-forward/middle-character.js | 23 ---------------- .../delete-forward/multiple-characters.js | 27 ------------------- .../value/delete-forward/single-void-block.js | 22 --------------- .../character/document-end.js} | 2 +- ...t-reverse.js => document-start-reverse.js} | 0 .../empty-reverse.js} | 0 .../character/empty.js} | 2 +- .../inline-before.js} | 17 +++++------- .../character/inline-inside.js} | 14 +++++----- .../block-join.js => join/basic-reverse.js} | 0 .../join-blocks.js => delete/join/basic.js} | 2 +- .../depths-reverse.js} | 0 .../inline-before-reverse.js} | 0 .../join/inline-before.js} | 7 ++++- .../inline-inside-reverse.js} | 0 .../inline-void-reverse.js} | 0 .../join/inline.js} | 2 +- .../nested-reverse.js} | 0 .../join/nested.js} | 2 +- ...k-backward.js => block-across-backward.js} | 4 --- ...{block-after.js => block-after-reverse.js} | 0 .../value/delete/voids/block-before.js | 11 +++----- .../value/delete/voids/block-hanging-from.js | 8 ++---- .../commands/value/delete/voids/block-only.js | 4 +-- ...nline-after.js => inline-after-reverse.js} | 0 .../voids/inline-before.js} | 2 +- .../voids/inline-into.js} | 9 ++++--- 32 files changed, 39 insertions(+), 219 deletions(-) delete mode 100644 packages/slate/test/commands/value/delete-forward/before-inline-sibling.js delete mode 100644 packages/slate/test/commands/value/delete-forward/empty-before-void-block.js delete mode 100644 packages/slate/test/commands/value/delete-forward/first-character.js delete mode 100644 packages/slate/test/commands/value/delete-forward/last-character.js delete mode 100644 packages/slate/test/commands/value/delete-forward/middle-character.js delete mode 100644 packages/slate/test/commands/value/delete-forward/multiple-characters.js delete mode 100644 packages/slate/test/commands/value/delete-forward/single-void-block.js rename packages/slate/test/commands/value/{delete-forward/end-of-document.js => delete/character/document-end.js} (86%) rename packages/slate/test/commands/value/delete/character/{start-reverse.js => document-start-reverse.js} (100%) rename packages/slate/test/commands/value/delete/{offset/block-empty.js => character/empty-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-forward/single-non-void-block.js => delete/character/empty.js} (86%) rename packages/slate/test/commands/value/delete/{voids/block-end.js => character/inline-before.js} (64%) rename packages/slate/test/commands/value/{delete-forward/inside-inline-sibling.js => delete/character/inline-inside.js} (65%) rename packages/slate/test/commands/value/delete/{offset/block-join.js => join/basic-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-forward/join-blocks.js => delete/join/basic.js} (87%) rename packages/slate/test/commands/value/delete/{offset/block-join-depths.js => join/depths-reverse.js} (100%) rename packages/slate/test/commands/value/delete/{offset/block-join-inline-before.js => join/inline-before-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-forward/join-blocks-with-inline-void.js => delete/join/inline-before.js} (77%) rename packages/slate/test/commands/value/delete/{offset/block-join-inline-inside.js => join/inline-inside-reverse.js} (100%) rename packages/slate/test/commands/value/delete/{offset/block-join-inline-void.js => join/inline-void-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-forward/join-blocks-with-inline.js => delete/join/inline.js} (89%) rename packages/slate/test/commands/value/delete/{offset/block-join-nested.js => join/nested-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-forward/join-nested-blocks.js => delete/join/nested.js} (89%) rename packages/slate/test/commands/value/delete/voids/{block-backward.js => block-across-backward.js} (98%) rename packages/slate/test/commands/value/delete/voids/{block-after.js => block-after-reverse.js} (100%) rename packages/slate/test/commands/value/delete/voids/{inline-after.js => inline-after-reverse.js} (100%) rename packages/slate/test/commands/value/{delete-forward/empty-before-void-inline.js => delete/voids/inline-before.js} (90%) rename packages/slate/test/commands/value/{delete-forward/start-text-middle-inline.js => delete/voids/inline-into.js} (71%) diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index d836ea76f6..1dbaf33b23 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -28,7 +28,6 @@ class PointCommands { ? this.getPreviousPoint(point, { unit, ...rest }) : this.getNextPoint(point, { unit, ...rest }) - debugger if (target) { this.deleteAtRange({ anchor: point, focus: target }) } diff --git a/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js b/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js deleted file mode 100644 index cd429a55f2..0000000000 --- a/packages/slate/test/commands/value/delete-forward/before-inline-sibling.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - onetwo - a - - -) - -export const output = ( - - - one - two - - - - -) diff --git a/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js b/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js deleted file mode 100644 index 572fec9e63..0000000000 --- a/packages/slate/test/commands/value/delete-forward/empty-before-void-block.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - - - - - - -) - -export const output = ( - - - - - -) diff --git a/packages/slate/test/commands/value/delete-forward/first-character.js b/packages/slate/test/commands/value/delete-forward/first-character.js deleted file mode 100644 index ca8940d599..0000000000 --- a/packages/slate/test/commands/value/delete-forward/first-character.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - word - - -) - -export const output = ( - - - ord - - -) diff --git a/packages/slate/test/commands/value/delete-forward/last-character.js b/packages/slate/test/commands/value/delete-forward/last-character.js deleted file mode 100644 index a09e8f2fd7..0000000000 --- a/packages/slate/test/commands/value/delete-forward/last-character.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - word - - -) - -export const output = ( - - - wor - - -) diff --git a/packages/slate/test/commands/value/delete-forward/middle-character.js b/packages/slate/test/commands/value/delete-forward/middle-character.js deleted file mode 100644 index 198aad4c0d..0000000000 --- a/packages/slate/test/commands/value/delete-forward/middle-character.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - word - - -) - -export const output = ( - - - wrd - - -) diff --git a/packages/slate/test/commands/value/delete-forward/multiple-characters.js b/packages/slate/test/commands/value/delete-forward/multiple-characters.js deleted file mode 100644 index e30d7f927f..0000000000 --- a/packages/slate/test/commands/value/delete-forward/multiple-characters.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteForward(3) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - d - - - -) diff --git a/packages/slate/test/commands/value/delete-forward/single-void-block.js b/packages/slate/test/commands/value/delete-forward/single-void-block.js deleted file mode 100644 index 3a06057d44..0000000000 --- a/packages/slate/test/commands/value/delete-forward/single-void-block.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.delete() -} - -export const input = ( - - - {' '} - - -) - -export const output = ( - - - - -) diff --git a/packages/slate/test/commands/value/delete-forward/end-of-document.js b/packages/slate/test/commands/value/delete/character/document-end.js similarity index 86% rename from packages/slate/test/commands/value/delete-forward/end-of-document.js rename to packages/slate/test/commands/value/delete/character/document-end.js index 92f32e09b8..ac29cff853 100644 --- a/packages/slate/test/commands/value/delete-forward/end-of-document.js +++ b/packages/slate/test/commands/value/delete/character/document-end.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/character/start-reverse.js b/packages/slate/test/commands/value/delete/character/document-start-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/character/start-reverse.js rename to packages/slate/test/commands/value/delete/character/document-start-reverse.js diff --git a/packages/slate/test/commands/value/delete/offset/block-empty.js b/packages/slate/test/commands/value/delete/character/empty-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/offset/block-empty.js rename to packages/slate/test/commands/value/delete/character/empty-reverse.js diff --git a/packages/slate/test/commands/value/delete-forward/single-non-void-block.js b/packages/slate/test/commands/value/delete/character/empty.js similarity index 86% rename from packages/slate/test/commands/value/delete-forward/single-non-void-block.js rename to packages/slate/test/commands/value/delete/character/empty.js index 2993e1ba4f..471c00ef16 100644 --- a/packages/slate/test/commands/value/delete-forward/single-non-void-block.js +++ b/packages/slate/test/commands/value/delete/character/empty.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-end.js b/packages/slate/test/commands/value/delete/character/inline-before.js similarity index 64% rename from packages/slate/test/commands/value/delete/voids/block-end.js rename to packages/slate/test/commands/value/delete/character/inline-before.js index d10ffe1e68..41bed9b48e 100644 --- a/packages/slate/test/commands/value/delete/voids/block-end.js +++ b/packages/slate/test/commands/value/delete/character/inline-before.js @@ -8,25 +8,20 @@ export const run = editor => { export const input = ( - - one - - - + one + two + a - three - ) export const output = ( - - on + one + two + - three - ) diff --git a/packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js b/packages/slate/test/commands/value/delete/character/inline-inside.js similarity index 65% rename from packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js rename to packages/slate/test/commands/value/delete/character/inline-inside.js index 90d09d46fb..f4ce065742 100644 --- a/packages/slate/test/commands/value/delete-forward/inside-inline-sibling.js +++ b/packages/slate/test/commands/value/delete/character/inline-inside.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -9,9 +9,11 @@ export const run = editor => { export const input = ( - one + one + a - two + + two ) @@ -20,10 +22,10 @@ export const output = ( one - - - two + + + two ) diff --git a/packages/slate/test/commands/value/delete/offset/block-join.js b/packages/slate/test/commands/value/delete/join/basic-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/offset/block-join.js rename to packages/slate/test/commands/value/delete/join/basic-reverse.js diff --git a/packages/slate/test/commands/value/delete-forward/join-blocks.js b/packages/slate/test/commands/value/delete/join/basic.js similarity index 87% rename from packages/slate/test/commands/value/delete-forward/join-blocks.js rename to packages/slate/test/commands/value/delete/join/basic.js index 408352aef8..79717c9320 100644 --- a/packages/slate/test/commands/value/delete-forward/join-blocks.js +++ b/packages/slate/test/commands/value/delete/join/basic.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/offset/block-join-depths.js b/packages/slate/test/commands/value/delete/join/depths-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/offset/block-join-depths.js rename to packages/slate/test/commands/value/delete/join/depths-reverse.js diff --git a/packages/slate/test/commands/value/delete/offset/block-join-inline-before.js b/packages/slate/test/commands/value/delete/join/inline-before-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/offset/block-join-inline-before.js rename to packages/slate/test/commands/value/delete/join/inline-before-reverse.js diff --git a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js b/packages/slate/test/commands/value/delete/join/inline-before.js similarity index 77% rename from packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js rename to packages/slate/test/commands/value/delete/join/inline-before.js index 2919eea66c..10f993e36e 100644 --- a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline-void.js +++ b/packages/slate/test/commands/value/delete/join/inline-before.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -12,9 +12,11 @@ export const input = ( word + + ) @@ -26,6 +28,9 @@ export const output = ( + ) + +export const skip = true diff --git a/packages/slate/test/commands/value/delete/offset/block-join-inline-inside.js b/packages/slate/test/commands/value/delete/join/inline-inside-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/offset/block-join-inline-inside.js rename to packages/slate/test/commands/value/delete/join/inline-inside-reverse.js diff --git a/packages/slate/test/commands/value/delete/offset/block-join-inline-void.js b/packages/slate/test/commands/value/delete/join/inline-void-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/offset/block-join-inline-void.js rename to packages/slate/test/commands/value/delete/join/inline-void-reverse.js diff --git a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js b/packages/slate/test/commands/value/delete/join/inline.js similarity index 89% rename from packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js rename to packages/slate/test/commands/value/delete/join/inline.js index 1b37350206..7c8f0dd5a0 100644 --- a/packages/slate/test/commands/value/delete-forward/join-blocks-with-inline.js +++ b/packages/slate/test/commands/value/delete/join/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/offset/block-join-nested.js b/packages/slate/test/commands/value/delete/join/nested-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/offset/block-join-nested.js rename to packages/slate/test/commands/value/delete/join/nested-reverse.js diff --git a/packages/slate/test/commands/value/delete-forward/join-nested-blocks.js b/packages/slate/test/commands/value/delete/join/nested.js similarity index 89% rename from packages/slate/test/commands/value/delete-forward/join-nested-blocks.js rename to packages/slate/test/commands/value/delete/join/nested.js index 7176d778d8..17cf5179d6 100644 --- a/packages/slate/test/commands/value/delete-forward/join-nested-blocks.js +++ b/packages/slate/test/commands/value/delete/join/nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-backward.js b/packages/slate/test/commands/value/delete/voids/block-across-backward.js similarity index 98% rename from packages/slate/test/commands/value/delete/voids/block-backward.js rename to packages/slate/test/commands/value/delete/voids/block-across-backward.js index 6dc5453fcc..971dea5f6d 100644 --- a/packages/slate/test/commands/value/delete/voids/block-backward.js +++ b/packages/slate/test/commands/value/delete/voids/block-across-backward.js @@ -8,7 +8,6 @@ export const run = editor => { export const input = ( - @@ -16,16 +15,13 @@ export const input = ( two - ) export const output = ( - - ) diff --git a/packages/slate/test/commands/value/delete/voids/block-after.js b/packages/slate/test/commands/value/delete/voids/block-after-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/voids/block-after.js rename to packages/slate/test/commands/value/delete/voids/block-after-reverse.js diff --git a/packages/slate/test/commands/value/delete/voids/block-before.js b/packages/slate/test/commands/value/delete/voids/block-before.js index d4e91fdac0..de8a75ab9c 100644 --- a/packages/slate/test/commands/value/delete/voids/block-before.js +++ b/packages/slate/test/commands/value/delete/voids/block-before.js @@ -9,23 +9,20 @@ export const run = editor => { export const input = ( - one + - three ) export const output = ( - - on - - + - three ) + +export const skip = true diff --git a/packages/slate/test/commands/value/delete/voids/block-hanging-from.js b/packages/slate/test/commands/value/delete/voids/block-hanging-from.js index 9d850e947c..ba1f035c40 100644 --- a/packages/slate/test/commands/value/delete/voids/block-hanging-from.js +++ b/packages/slate/test/commands/value/delete/voids/block-hanging-from.js @@ -8,25 +8,21 @@ export const run = editor => { export const input = ( - one - + two - ) export const output = ( - one - + two - ) diff --git a/packages/slate/test/commands/value/delete/voids/block-only.js b/packages/slate/test/commands/value/delete/voids/block-only.js index 578a0da901..cd61bbbf96 100644 --- a/packages/slate/test/commands/value/delete/voids/block-only.js +++ b/packages/slate/test/commands/value/delete/voids/block-only.js @@ -14,6 +14,4 @@ export const input = ( ) -export const output = ( - -) +export const output = diff --git a/packages/slate/test/commands/value/delete/voids/inline-after.js b/packages/slate/test/commands/value/delete/voids/inline-after-reverse.js similarity index 100% rename from packages/slate/test/commands/value/delete/voids/inline-after.js rename to packages/slate/test/commands/value/delete/voids/inline-after-reverse.js diff --git a/packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js b/packages/slate/test/commands/value/delete/voids/inline-before.js similarity index 90% rename from packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js rename to packages/slate/test/commands/value/delete/voids/inline-before.js index a02262c6a4..23f4aa7e71 100644 --- a/packages/slate/test/commands/value/delete-forward/empty-before-void-inline.js +++ b/packages/slate/test/commands/value/delete/voids/inline-before.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js b/packages/slate/test/commands/value/delete/voids/inline-into.js similarity index 71% rename from packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js rename to packages/slate/test/commands/value/delete/voids/inline-into.js index 357c014f7e..a4bc2bf91e 100644 --- a/packages/slate/test/commands/value/delete-forward/start-text-middle-inline.js +++ b/packages/slate/test/commands/value/delete/voids/inline-into.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { editor.delete() @@ -9,20 +9,23 @@ export const run = editor => { export const input = ( - one + one + two + ) -// TODO: this output selection seems bad export const output = ( + wo + ) From ee94ad9dc25c2b5a374d264e28e149d0fa443b84 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Oct 2019 15:24:49 -0400 Subject: [PATCH 051/165] finish delete tests --- packages/slate/src/classes/queries/value.ts | 6 +--- .../inline-middle-emoji.js | 28 ------------------ .../inline-multi-voids.js | 29 ------------------- .../value/delete-line-backward/text-end.js | 27 ----------------- .../value/delete-line-backward/text-start.js | 20 ------------- .../value/delete-line-backward/word-middle.js | 27 ----------------- .../delete-line-forward/inline-multi-voids.js | 29 ------------------- .../value/delete-line-forward/text-end.js | 20 ------------- .../value/delete-line-forward/text-start.js | 28 ------------------ .../value/delete-line-forward/word-middle.js | 27 ----------------- .../inline-middle-emoji.js | 28 ------------------ .../value/delete-word-backward/join-blocks.js | 28 ------------------ .../value/delete-word-backward/text-end.js | 27 ----------------- .../value/delete-word-backward/word-middle.js | 27 ----------------- .../delete-word-forward/inline-after-emoji.js | 28 ------------------ .../inline-middle-emoji.js | 28 ------------------ .../value/delete-word-forward/join-blocks.js | 28 ------------------ .../value/delete-word-forward/word-middle.js | 27 ----------------- .../value/delete-word-forward/word-start.js | 27 ----------------- .../line/text-end-reverse.js} | 6 ++-- .../commands/value/delete/line/text-end.js | 18 ++++++++++++ .../line/text-middle-reverse.js} | 8 ++--- .../line/text-middle.js} | 9 +++--- .../value/delete/line/text-start-reverse.js | 18 ++++++++++++ .../line/text-start.js} | 6 ++-- .../value/delete/word/block-join-reverse.js | 24 +++++++++++++++ .../commands/value/delete/word/block-join.js | 24 +++++++++++++++ .../value/delete/word/text-end-reverse.js | 23 +++++++++++++++ .../value/delete/word/text-middle-reverse.js | 23 +++++++++++++++ .../commands/value/delete/word/text-middle.js | 23 +++++++++++++++ .../commands/value/delete/word/text-start.js | 23 +++++++++++++++ .../value/positions/all/unit-block-reverse.js | 1 + .../queries/value/positions/all/unit-block.js | 1 + .../value/positions/all/unit-line-reverse.js | 1 + .../queries/value/positions/all/unit-line.js | 1 + .../value/positions/all/unit-word-reverse.js | 1 + .../queries/value/positions/all/unit-word.js | 1 + .../positions/point/unit-block-reverse.js | 1 + .../value/positions/point/unit-block.js | 1 + .../positions/point/unit-line-reverse.js | 1 + .../value/positions/point/unit-line.js | 1 + .../positions/point/unit-word-reverse.js | 1 + .../value/positions/point/unit-word.js | 1 + 43 files changed, 203 insertions(+), 503 deletions(-) delete mode 100644 packages/slate/test/commands/value/delete-line-backward/inline-middle-emoji.js delete mode 100644 packages/slate/test/commands/value/delete-line-backward/inline-multi-voids.js delete mode 100644 packages/slate/test/commands/value/delete-line-backward/text-end.js delete mode 100644 packages/slate/test/commands/value/delete-line-backward/text-start.js delete mode 100644 packages/slate/test/commands/value/delete-line-backward/word-middle.js delete mode 100644 packages/slate/test/commands/value/delete-line-forward/inline-multi-voids.js delete mode 100644 packages/slate/test/commands/value/delete-line-forward/text-end.js delete mode 100644 packages/slate/test/commands/value/delete-line-forward/text-start.js delete mode 100644 packages/slate/test/commands/value/delete-line-forward/word-middle.js delete mode 100644 packages/slate/test/commands/value/delete-word-backward/inline-middle-emoji.js delete mode 100644 packages/slate/test/commands/value/delete-word-backward/join-blocks.js delete mode 100644 packages/slate/test/commands/value/delete-word-backward/text-end.js delete mode 100644 packages/slate/test/commands/value/delete-word-backward/word-middle.js delete mode 100644 packages/slate/test/commands/value/delete-word-forward/inline-after-emoji.js delete mode 100644 packages/slate/test/commands/value/delete-word-forward/inline-middle-emoji.js delete mode 100644 packages/slate/test/commands/value/delete-word-forward/join-blocks.js delete mode 100644 packages/slate/test/commands/value/delete-word-forward/word-middle.js delete mode 100644 packages/slate/test/commands/value/delete-word-forward/word-start.js rename packages/slate/test/commands/value/{delete-word-backward/inline-after-emoji.js => delete/line/text-end-reverse.js} (63%) create mode 100644 packages/slate/test/commands/value/delete/line/text-end.js rename packages/slate/test/commands/value/{delete-line-backward/inline-void-first.js => delete/line/text-middle-reverse.js} (58%) rename packages/slate/test/commands/value/{delete-line-forward/inline-void-end.js => delete/line/text-middle.js} (57%) create mode 100644 packages/slate/test/commands/value/delete/line/text-start-reverse.js rename packages/slate/test/commands/value/{delete-line-forward/inline-middle-emoji.js => delete/line/text-start.js} (69%) create mode 100644 packages/slate/test/commands/value/delete/word/block-join-reverse.js create mode 100644 packages/slate/test/commands/value/delete/word/block-join.js create mode 100644 packages/slate/test/commands/value/delete/word/text-end-reverse.js create mode 100644 packages/slate/test/commands/value/delete/word/text-middle-reverse.js create mode 100644 packages/slate/test/commands/value/delete/word/text-middle.js create mode 100644 packages/slate/test/commands/value/delete/word/text-start.js diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index cd416808ae..7b176c7927 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -316,11 +316,7 @@ class ValueQueries { offset = point.offset } - if ( - isStart || - unit === 'offset' || - (unit === 'character' && isBlockStart) - ) { + if (isStart || isBlockStart || unit === 'offset') { yield { path, offset } } diff --git a/packages/slate/test/commands/value/delete-line-backward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-line-backward/inline-middle-emoji.js deleted file mode 100644 index 82e83be80d..0000000000 --- a/packages/slate/test/commands/value/delete-line-backward/inline-middle-emoji.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineBackward() -} - -export const input = ( - - - - one wo📛rd - - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete-line-backward/inline-multi-voids.js b/packages/slate/test/commands/value/delete-line-backward/inline-multi-voids.js deleted file mode 100644 index c28b4c8aec..0000000000 --- a/packages/slate/test/commands/value/delete-line-backward/inline-multi-voids.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineBackward() -} - -export const input = ( - - - 😊 - one - 😊 - two - 😀 - three - - - -) - -export const output = ( - - - - - -) diff --git a/packages/slate/test/commands/value/delete-line-backward/text-end.js b/packages/slate/test/commands/value/delete-line-backward/text-end.js deleted file mode 100644 index 37177af149..0000000000 --- a/packages/slate/test/commands/value/delete-line-backward/text-end.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineBackward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete-line-backward/text-start.js b/packages/slate/test/commands/value/delete-line-backward/text-start.js deleted file mode 100644 index 1a314c3638..0000000000 --- a/packages/slate/test/commands/value/delete-line-backward/text-start.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineBackward() -} - -export const input = ( - - - - - one two three - - - -) - -export const output = input diff --git a/packages/slate/test/commands/value/delete-line-backward/word-middle.js b/packages/slate/test/commands/value/delete-line-backward/word-middle.js deleted file mode 100644 index 8dc4a97313..0000000000 --- a/packages/slate/test/commands/value/delete-line-backward/word-middle.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineBackward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - ee - - - -) diff --git a/packages/slate/test/commands/value/delete-line-forward/inline-multi-voids.js b/packages/slate/test/commands/value/delete-line-forward/inline-multi-voids.js deleted file mode 100644 index 4a901f7689..0000000000 --- a/packages/slate/test/commands/value/delete-line-forward/inline-multi-voids.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineForward() -} - -export const input = ( - - - - one - 😊 - two - 😊 - three - 😀 - - -) - -export const output = ( - - - - - -) diff --git a/packages/slate/test/commands/value/delete-line-forward/text-end.js b/packages/slate/test/commands/value/delete-line-forward/text-end.js deleted file mode 100644 index 09408d9b59..0000000000 --- a/packages/slate/test/commands/value/delete-line-forward/text-end.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineForward() -} - -export const input = ( - - - - one two three - - - - -) - -export const output = input diff --git a/packages/slate/test/commands/value/delete-line-forward/text-start.js b/packages/slate/test/commands/value/delete-line-forward/text-start.js deleted file mode 100644 index 4e725229b0..0000000000 --- a/packages/slate/test/commands/value/delete-line-forward/text-start.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineForward() -} - -export const input = ( - - - - - one two three - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete-line-forward/word-middle.js b/packages/slate/test/commands/value/delete-line-forward/word-middle.js deleted file mode 100644 index f9cbd1195a..0000000000 --- a/packages/slate/test/commands/value/delete-line-forward/word-middle.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteLineForward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one two thr - - - -) diff --git a/packages/slate/test/commands/value/delete-word-backward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-word-backward/inline-middle-emoji.js deleted file mode 100644 index fabd99b3b4..0000000000 --- a/packages/slate/test/commands/value/delete-word-backward/inline-middle-emoji.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordBackward() -} - -export const input = ( - - - - wo📛rd - - - -) - -export const output = ( - - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete-word-backward/join-blocks.js b/packages/slate/test/commands/value/delete-word-backward/join-blocks.js deleted file mode 100644 index aa91a9908c..0000000000 --- a/packages/slate/test/commands/value/delete-word-backward/join-blocks.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordBackward() -} - -export const input = ( - - - word - - another - - - -) - -export const output = ( - - - - wordanother - - - -) diff --git a/packages/slate/test/commands/value/delete-word-backward/text-end.js b/packages/slate/test/commands/value/delete-word-backward/text-end.js deleted file mode 100644 index c20d1d0c31..0000000000 --- a/packages/slate/test/commands/value/delete-word-backward/text-end.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordBackward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one two - - - -) diff --git a/packages/slate/test/commands/value/delete-word-backward/word-middle.js b/packages/slate/test/commands/value/delete-word-backward/word-middle.js deleted file mode 100644 index 3ce94becec..0000000000 --- a/packages/slate/test/commands/value/delete-word-backward/word-middle.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordBackward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one two ee - - - -) diff --git a/packages/slate/test/commands/value/delete-word-forward/inline-after-emoji.js b/packages/slate/test/commands/value/delete-word-forward/inline-after-emoji.js deleted file mode 100644 index c556450cef..0000000000 --- a/packages/slate/test/commands/value/delete-word-forward/inline-after-emoji.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordForward() -} - -export const input = ( - - - - - word📛 - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete-word-forward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete-word-forward/inline-middle-emoji.js deleted file mode 100644 index 444bab1fc2..0000000000 --- a/packages/slate/test/commands/value/delete-word-forward/inline-middle-emoji.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordForward() -} - -export const input = ( - - - - - wo📛rd - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/delete-word-forward/join-blocks.js b/packages/slate/test/commands/value/delete-word-forward/join-blocks.js deleted file mode 100644 index 6e4f9c5af1..0000000000 --- a/packages/slate/test/commands/value/delete-word-forward/join-blocks.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordForward() -} - -export const input = ( - - - - word - - another - - -) - -export const output = ( - - - - wordanother - - - -) diff --git a/packages/slate/test/commands/value/delete-word-forward/word-middle.js b/packages/slate/test/commands/value/delete-word-forward/word-middle.js deleted file mode 100644 index 887003e602..0000000000 --- a/packages/slate/test/commands/value/delete-word-forward/word-middle.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordForward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - o two three - - - -) diff --git a/packages/slate/test/commands/value/delete-word-forward/word-start.js b/packages/slate/test/commands/value/delete-word-forward/word-start.js deleted file mode 100644 index 9839331133..0000000000 --- a/packages/slate/test/commands/value/delete-word-forward/word-start.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.deleteWordForward() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - two three - - - -) diff --git a/packages/slate/test/commands/value/delete-word-backward/inline-after-emoji.js b/packages/slate/test/commands/value/delete/line/text-end-reverse.js similarity index 63% rename from packages/slate/test/commands/value/delete-word-backward/inline-after-emoji.js rename to packages/slate/test/commands/value/delete/line/text-end-reverse.js index 8af168dfda..cdaf289333 100644 --- a/packages/slate/test/commands/value/delete-word-backward/inline-after-emoji.js +++ b/packages/slate/test/commands/value/delete/line/text-end-reverse.js @@ -1,15 +1,15 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteWordBackward() + editor.delete({ unit: 'line', reverse: true }) } export const input = ( - word📛 + one two three ) diff --git a/packages/slate/test/commands/value/delete/line/text-end.js b/packages/slate/test/commands/value/delete/line/text-end.js new file mode 100644 index 0000000000..13c4af70a8 --- /dev/null +++ b/packages/slate/test/commands/value/delete/line/text-end.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'line' }) +} + +export const input = ( + + + one two three + + + +) + +export const output = input diff --git a/packages/slate/test/commands/value/delete-line-backward/inline-void-first.js b/packages/slate/test/commands/value/delete/line/text-middle-reverse.js similarity index 58% rename from packages/slate/test/commands/value/delete-line-backward/inline-void-first.js rename to packages/slate/test/commands/value/delete/line/text-middle-reverse.js index d01a99aa18..529c7cd6d7 100644 --- a/packages/slate/test/commands/value/delete-line-backward/inline-void-first.js +++ b/packages/slate/test/commands/value/delete/line/text-middle-reverse.js @@ -1,15 +1,15 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteLineBackward() + editor.delete({ unit: 'line', reverse: true }) } export const input = ( - 😊one two three + one two three ) @@ -17,7 +17,7 @@ export const input = ( export const output = ( - + ee ) diff --git a/packages/slate/test/commands/value/delete-line-forward/inline-void-end.js b/packages/slate/test/commands/value/delete/line/text-middle.js similarity index 57% rename from packages/slate/test/commands/value/delete-line-forward/inline-void-end.js rename to packages/slate/test/commands/value/delete/line/text-middle.js index fe6d3ae5b1..098b837dc4 100644 --- a/packages/slate/test/commands/value/delete-line-forward/inline-void-end.js +++ b/packages/slate/test/commands/value/delete/line/text-middle.js @@ -1,16 +1,15 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteLineForward() + editor.delete({ unit: 'line' }) } export const input = ( - - one two three😊 + one two three ) @@ -18,7 +17,7 @@ export const input = ( export const output = ( - + one two thr ) diff --git a/packages/slate/test/commands/value/delete/line/text-start-reverse.js b/packages/slate/test/commands/value/delete/line/text-start-reverse.js new file mode 100644 index 0000000000..eb44b485f0 --- /dev/null +++ b/packages/slate/test/commands/value/delete/line/text-start-reverse.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'line', reverse: true }) +} + +export const input = ( + + + + one two three + + +) + +export const output = input diff --git a/packages/slate/test/commands/value/delete-line-forward/inline-middle-emoji.js b/packages/slate/test/commands/value/delete/line/text-start.js similarity index 69% rename from packages/slate/test/commands/value/delete-line-forward/inline-middle-emoji.js rename to packages/slate/test/commands/value/delete/line/text-start.js index 7d9a8d92f2..2b3cef52de 100644 --- a/packages/slate/test/commands/value/delete-line-forward/inline-middle-emoji.js +++ b/packages/slate/test/commands/value/delete/line/text-start.js @@ -1,16 +1,16 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../../../helpers' export const run = editor => { - editor.deleteLineForward() + editor.delete({ unit: 'line' }) } export const input = ( - one wo📛rd + one two three ) diff --git a/packages/slate/test/commands/value/delete/word/block-join-reverse.js b/packages/slate/test/commands/value/delete/word/block-join-reverse.js new file mode 100644 index 0000000000..2c365b5c78 --- /dev/null +++ b/packages/slate/test/commands/value/delete/word/block-join-reverse.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'word', reverse: true }) +} + +export const input = ( + + word + + another + + +) + +export const output = ( + + + wordanother + + +) diff --git a/packages/slate/test/commands/value/delete/word/block-join.js b/packages/slate/test/commands/value/delete/word/block-join.js new file mode 100644 index 0000000000..ea52f00a6a --- /dev/null +++ b/packages/slate/test/commands/value/delete/word/block-join.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'word' }) +} + +export const input = ( + + + word + + another + +) + +export const output = ( + + + wordanother + + +) diff --git a/packages/slate/test/commands/value/delete/word/text-end-reverse.js b/packages/slate/test/commands/value/delete/word/text-end-reverse.js new file mode 100644 index 0000000000..c31dc5b544 --- /dev/null +++ b/packages/slate/test/commands/value/delete/word/text-end-reverse.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'word', reverse: true }) +} + +export const input = ( + + + one two three + + +) + +export const output = ( + + + one two + + +) diff --git a/packages/slate/test/commands/value/delete/word/text-middle-reverse.js b/packages/slate/test/commands/value/delete/word/text-middle-reverse.js new file mode 100644 index 0000000000..50055bf2bc --- /dev/null +++ b/packages/slate/test/commands/value/delete/word/text-middle-reverse.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'word', reverse: true }) +} + +export const input = ( + + + one two three + + +) + +export const output = ( + + + one two ee + + +) diff --git a/packages/slate/test/commands/value/delete/word/text-middle.js b/packages/slate/test/commands/value/delete/word/text-middle.js new file mode 100644 index 0000000000..85db1bac1d --- /dev/null +++ b/packages/slate/test/commands/value/delete/word/text-middle.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'word' }) +} + +export const input = ( + + + one two three + + +) + +export const output = ( + + + o two three + + +) diff --git a/packages/slate/test/commands/value/delete/word/text-start.js b/packages/slate/test/commands/value/delete/word/text-start.js new file mode 100644 index 0000000000..e02118d110 --- /dev/null +++ b/packages/slate/test/commands/value/delete/word/text-start.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../../helpers' + +export const run = editor => { + editor.delete({ unit: 'word' }) +} + +export const input = ( + + + one two three + + +) + +export const output = ( + + + two three + + +) diff --git a/packages/slate/test/queries/value/positions/all/unit-block-reverse.js b/packages/slate/test/queries/value/positions/all/unit-block-reverse.js index 50e1a3d10c..b4e13e68ff 100644 --- a/packages/slate/test/queries/value/positions/all/unit-block-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-block-reverse.js @@ -16,5 +16,6 @@ export const run = editor => { export const output = [ { path: [1, 0], offset: 13 }, { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, { path: [0, 0], offset: 0 }, ] diff --git a/packages/slate/test/queries/value/positions/all/unit-block.js b/packages/slate/test/queries/value/positions/all/unit-block.js index 3e06293651..199fbeab11 100644 --- a/packages/slate/test/queries/value/positions/all/unit-block.js +++ b/packages/slate/test/queries/value/positions/all/unit-block.js @@ -16,5 +16,6 @@ export const run = editor => { export const output = [ { path: [0, 0], offset: 0 }, { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 0 }, { path: [1, 0], offset: 13 }, ] diff --git a/packages/slate/test/queries/value/positions/all/unit-line-reverse.js b/packages/slate/test/queries/value/positions/all/unit-line-reverse.js index 669989f418..88e761a894 100644 --- a/packages/slate/test/queries/value/positions/all/unit-line-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-line-reverse.js @@ -16,5 +16,6 @@ export const run = editor => { export const output = [ { path: [1, 0], offset: 13 }, { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, { path: [0, 0], offset: 0 }, ] diff --git a/packages/slate/test/queries/value/positions/all/unit-line.js b/packages/slate/test/queries/value/positions/all/unit-line.js index 8a75a9b758..0ec17522fc 100644 --- a/packages/slate/test/queries/value/positions/all/unit-line.js +++ b/packages/slate/test/queries/value/positions/all/unit-line.js @@ -16,5 +16,6 @@ export const run = editor => { export const output = [ { path: [0, 0], offset: 0 }, { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 0 }, { path: [1, 0], offset: 13 }, ] diff --git a/packages/slate/test/queries/value/positions/all/unit-word-reverse.js b/packages/slate/test/queries/value/positions/all/unit-word-reverse.js index cf9ef80e6d..63fbe6b4d0 100644 --- a/packages/slate/test/queries/value/positions/all/unit-word-reverse.js +++ b/packages/slate/test/queries/value/positions/all/unit-word-reverse.js @@ -18,6 +18,7 @@ export const output = [ { path: [1, 0], offset: 10 }, { path: [1, 0], offset: 5 }, { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, { path: [0, 0], offset: 8 }, { path: [0, 0], offset: 4 }, { path: [0, 0], offset: 0 }, diff --git a/packages/slate/test/queries/value/positions/all/unit-word.js b/packages/slate/test/queries/value/positions/all/unit-word.js index fb6715ee0e..9d29d5d23f 100644 --- a/packages/slate/test/queries/value/positions/all/unit-word.js +++ b/packages/slate/test/queries/value/positions/all/unit-word.js @@ -18,6 +18,7 @@ export const output = [ { path: [0, 0], offset: 3 }, { path: [0, 0], offset: 7 }, { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 0 }, { path: [1, 0], offset: 4 }, { path: [1, 0], offset: 9 }, { path: [1, 0], offset: 13 }, diff --git a/packages/slate/test/queries/value/positions/point/unit-block-reverse.js b/packages/slate/test/queries/value/positions/point/unit-block-reverse.js index 3a57af2535..9985e4d3ac 100644 --- a/packages/slate/test/queries/value/positions/point/unit-block-reverse.js +++ b/packages/slate/test/queries/value/positions/point/unit-block-reverse.js @@ -22,5 +22,6 @@ export const run = editor => { export const output = [ { path: [1, 0], offset: 4 }, { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, { path: [0, 0], offset: 0 }, ] diff --git a/packages/slate/test/queries/value/positions/point/unit-block.js b/packages/slate/test/queries/value/positions/point/unit-block.js index 3a831e2158..4625c4475d 100644 --- a/packages/slate/test/queries/value/positions/point/unit-block.js +++ b/packages/slate/test/queries/value/positions/point/unit-block.js @@ -18,5 +18,6 @@ export const run = editor => { export const output = [ { path: [0, 0], offset: 3 }, { path: [0, 0], offset: 13 }, + { path: [0, 0], offset: 0 }, { path: [1, 0], offset: 13 }, ] diff --git a/packages/slate/test/queries/value/positions/point/unit-line-reverse.js b/packages/slate/test/queries/value/positions/point/unit-line-reverse.js index b1bb19064c..a608cbbaa0 100644 --- a/packages/slate/test/queries/value/positions/point/unit-line-reverse.js +++ b/packages/slate/test/queries/value/positions/point/unit-line-reverse.js @@ -22,5 +22,6 @@ export const run = editor => { export const output = [ { path: [1, 0], offset: 3 }, { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, { path: [0, 0], offset: 0 }, ] diff --git a/packages/slate/test/queries/value/positions/point/unit-line.js b/packages/slate/test/queries/value/positions/point/unit-line.js index 07b91419e7..f525831007 100644 --- a/packages/slate/test/queries/value/positions/point/unit-line.js +++ b/packages/slate/test/queries/value/positions/point/unit-line.js @@ -18,5 +18,6 @@ export const run = editor => { export const output = [ { path: [0, 0], offset: 3 }, { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 0 }, { path: [1, 0], offset: 13 }, ] diff --git a/packages/slate/test/queries/value/positions/point/unit-word-reverse.js b/packages/slate/test/queries/value/positions/point/unit-word-reverse.js index ca0bb80268..e3c749eb51 100644 --- a/packages/slate/test/queries/value/positions/point/unit-word-reverse.js +++ b/packages/slate/test/queries/value/positions/point/unit-word-reverse.js @@ -24,6 +24,7 @@ export const output = [ { path: [1, 0], offset: 10 }, { path: [1, 0], offset: 5 }, { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 13 }, { path: [0, 0], offset: 8 }, { path: [0, 0], offset: 4 }, { path: [0, 0], offset: 0 }, diff --git a/packages/slate/test/queries/value/positions/point/unit-word.js b/packages/slate/test/queries/value/positions/point/unit-word.js index 107fd652f0..89340701f5 100644 --- a/packages/slate/test/queries/value/positions/point/unit-word.js +++ b/packages/slate/test/queries/value/positions/point/unit-word.js @@ -20,6 +20,7 @@ export const output = [ { path: [0, 0], offset: 3 }, { path: [0, 0], offset: 7 }, { path: [0, 0], offset: 13 }, + { path: [1, 0], offset: 0 }, { path: [1, 0], offset: 4 }, { path: [1, 0], offset: 9 }, { path: [1, 0], offset: 13 }, From 7032b490134af53f704d2310b85aa0084124cb60 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 23 Oct 2019 14:39:36 -0400 Subject: [PATCH 052/165] start converting to at-based commands --- packages/slate-hyperscript/src/creators.ts | 14 +- packages/slate/src/classes/commands/path.ts | 117 ----- packages/slate/src/classes/commands/point.ts | 59 +-- packages/slate/src/classes/commands/range.ts | 113 +---- .../slate/src/classes/commands/selection.ts | 256 ++++------- packages/slate/src/classes/commands/value.ts | 435 ++++++++++++++---- packages/slate/src/classes/queries/path.ts | 39 +- packages/slate/src/classes/queries/point.ts | 5 +- packages/slate/src/classes/queries/range.ts | 14 +- packages/slate/src/classes/queries/value.ts | 202 ++++---- packages/slate/src/index.ts | 6 +- packages/slate/src/interfaces/annotation.ts | 9 +- packages/slate/src/interfaces/node.ts | 33 +- packages/slate/src/interfaces/range.ts | 30 +- packages/slate/src/interfaces/value.ts | 5 +- .../focus => addMarks/path}/basic.js | 8 +- .../test/commands/addMarks/range/basic.js | 28 ++ .../selection}/block-across-edge-existing.js | 3 +- .../selection}/block-across-existing.js | 8 +- .../selection}/block-across.js | 8 +- .../selection}/existing.js | 6 +- .../selection}/first-character.js | 6 +- .../selection}/inline-across.js | 8 +- .../selection}/last-character.js | 0 .../selection}/middle-character.js | 6 +- .../addMarks => addMarks/selection}/word.js | 0 .../delete/emojis/inline-end-reverse.js | 2 +- .../delete/emojis/inline-middle-reverse.js | 2 +- .../delete/emojis/inline-middle.js | 2 +- .../delete/emojis/inline-only-reverse.js | 2 +- .../{value => }/delete/emojis/inline-start.js | 2 +- .../delete/emojis/text-end-reverse.js | 2 +- .../{value => }/delete/emojis/text-start.js | 2 +- .../removeNodeAtPath => delete/path}/block.js | 2 +- .../path}/inline.js | 2 +- .../path}/selection-inside.js | 2 +- .../removeNodeAtPath => delete/path}/text.js | 2 +- .../join => delete/point}/basic-reverse.js | 2 +- .../delete/join => delete/point}/basic.js | 2 +- .../join => delete/point}/depths-reverse.js | 2 +- .../point}/inline-before-reverse.js | 2 +- .../join => delete/point}/inline-before.js | 2 +- .../point}/inline-inside-reverse.js | 2 +- .../point}/inline-void-reverse.js | 2 +- .../delete/join => delete/point}/inline.js | 2 +- .../join => delete/point}/nested-reverse.js | 2 +- .../delete/join => delete/point}/nested.js | 2 +- .../selection}/block-across-multiple.js | 8 +- .../selection}/block-across-nested.js | 10 +- .../selection}/block-across.js | 2 +- .../selection}/block-depths-nested.js | 2 +- .../selection}/block-depths.js | 12 +- .../selection}/block-hanging-multiple.js | 2 +- .../selection}/block-hanging-single.js | 12 +- .../selection}/block-inline-across.js | 2 +- .../selection}/block-join-edges.js | 10 +- .../selection}/block-join-inline.js | 2 +- .../selection}/block-join-nested.js | 10 +- .../selection}/block-nested.js | 2 +- .../selection}/character-end.js | 6 +- .../selection}/character-middle.js | 10 +- .../selection}/character-start.js | 2 +- .../selection}/inline-after.js | 2 +- .../selection}/inline-inside.js | 2 +- .../selection}/inline-over.js | 2 +- .../selection}/inline-whole.js | 2 +- .../selection}/mark-across.js | 2 +- .../selection}/mark-whole.js | 6 +- .../expanded => delete/selection}/word.js | 6 +- .../unit-character}/document-end.js | 2 +- .../unit-character}/document-start-reverse.js | 2 +- .../unit-character}/empty-reverse.js | 2 +- .../unit-character}/empty.js | 2 +- .../unit-character}/end-reverse.js | 2 +- .../unit-character}/end.js | 2 +- .../unit-character}/first-reverse.js | 2 +- .../unit-character}/first.js | 2 +- .../unit-character}/inline-after-reverse.js | 2 +- .../unit-character}/inline-before-reverse.js | 2 +- .../unit-character}/inline-before.js | 2 +- .../unit-character}/inline-end-reverse.js | 2 +- .../unit-character}/inline-inside-reverse.js | 2 +- .../unit-character}/inline-inside.js | 2 +- .../unit-character}/last-reverse.js | 2 +- .../unit-character}/last.js | 2 +- .../unit-character}/middle-reverse.js | 2 +- .../unit-character}/middle.js | 2 +- .../unit-character}/multiple-reverse.js | 2 +- .../unit-character}/multiple.js | 2 +- .../unit-line}/text-end-reverse.js | 2 +- .../line => delete/unit-line}/text-end.js | 2 +- .../unit-line}/text-middle-reverse.js | 2 +- .../line => delete/unit-line}/text-middle.js | 2 +- .../unit-line}/text-start-reverse.js | 2 +- .../line => delete/unit-line}/text-start.js | 2 +- .../unit-word}/block-join-reverse.js | 2 +- .../word => delete/unit-word}/block-join.js | 2 +- .../unit-word}/text-end-reverse.js | 2 +- .../unit-word}/text-middle-reverse.js | 2 +- .../word => delete/unit-word}/text-middle.js | 2 +- .../word => delete/unit-word}/text-start.js | 2 +- .../delete/voids/block-across-backward.js | 2 +- .../delete/voids/block-after-reverse.js | 2 +- .../{value => }/delete/voids/block-before.js | 2 +- .../{value => }/delete/voids/block-both.js | 2 +- .../delete/voids/block-hanging-from.js | 2 +- .../delete/voids/block-hanging-into.js | 2 +- .../{value => }/delete/voids/block-only.js | 2 +- .../delete/voids/block-start-multiple.js | 2 +- .../{value => }/delete/voids/block-start.js | 2 +- .../delete/voids/inline-after-reverse.js | 2 +- .../{value => }/delete/voids/inline-before.js | 2 +- .../{value => }/delete/voids/inline-into.js | 2 +- .../{value => }/delete/voids/inline-over.js | 4 +- .../delete/voids/inline-start-across.js | 4 +- .../{value => }/delete/voids/inline-start.js | 4 +- .../{selection => }/deselect/basic.js | 0 .../{selection => }/deselect/unfocused.js | 0 .../selection/block-empty.js} | 6 +- .../insertBlock/selection/block-end.js | 28 ++ .../insertBlock/selection/block-middle.js | 29 ++ .../insertBlock/selection/block-start.js | 28 ++ .../insertBlock/selection/block-void.js | 32 ++ .../selection/inline-void.js} | 8 +- .../path}/end-of-target.js | 0 .../path}/middle-of-target.js | 0 .../path}/start-of-target.js | 0 .../selection}/block-empty.js | 0 .../selection}/block-end.js | 0 .../selection}/block-middle.js | 0 .../selection}/block-start.js | 0 .../selection}/end-block-multiple-blocks.js | 0 .../selection}/end-block.js | 0 .../selection}/end-inline.js | 0 .../selection}/flat-blocks/end-block.js | 0 .../hanging-selection-mixed-types.js | 0 .../selection}/flat-blocks/start-block.js | 0 .../selection}/fragment-adjacent-texts.js | 0 .../selection}/fragment-inline-node.js | 0 .../selection}/fragment-multiple-blocks.js | 0 .../selection}/fragment-multiple-marks.js | 0 .../fragment-nested-blocks-end-of-node.js | 0 .../fragment-nested-blocks-start-of-node.js | 0 .../selection}/fragment-nested-blocks.js | 0 .../selection}/fragment-single-child-block.js | 0 .../selection}/fragment-single-inline.js | 0 .../selection}/fragment-single-mark.js | 0 .../selection}/hanging-block.js | 0 .../hanging-selection-single-block.js | 0 .../selection}/inline-middle.js | 0 .../selection}/inline-start.js | 0 .../between-texts-into-middle-block.js | 0 .../selection}/inlines/middle-block.js | 0 .../selection}/inlines/middle-inline.js | 0 .../selection}/insert-block.js | 0 .../insert-inline-at-inline-middle.js | 0 .../selection}/insert-inline.js | 0 .../insert-multiple-blocks-at-middle.js | 0 .../insert-multiple-blocks-at-start.js | 0 .../selection}/insert-multiple-texts.js | 0 .../selection}/insert-nested-blocks-at-end.js | 0 .../insert-nested-blocks-at-middle.js | 0 .../insert-nested-blocks-at-start.js | 0 .../last-block-fragment-multiple.js | 0 .../selection}/last-block-fragment-single.js | 0 .../last-block-inline-fragment-single.js | 0 .../selection}/lists/merge-lists.js | 0 .../selection}/marks/middle-block.js | 0 .../marks/multiple-marks-middle-block.js | 0 .../selection}/merge-deep-nested.js | 0 .../selection}/merge-lists.js | 0 .../selection}/middle-block.js | 0 .../middle-fragment-adjacent-texts.js | 0 .../middle-inline-fragment-inline.js | 0 .../selection}/middle-inline.js | 0 .../nested-block-fragment-nested-blocks.js | 0 .../end-block.js | 0 .../middle-block-nested.js | 0 .../middle-block.js | 0 .../start-block.js | 0 .../end-block-nested.js | 0 .../start-block.js | 0 .../selection}/start-block-multiple-blocks.js | 0 .../start-block-with-void-no-text.js | 0 .../selection}/start-block.js | 0 .../selection}/start-inline.js | 0 .../selection}/start-second-block.js | 0 .../tables/merge-cells-with-nested-blocks.js | 0 .../tables/merge-into-empty-cells.js | 0 .../tables/merge-into-full-cells.js | 0 .../selection}/with-delete-across-blocks.js | 0 .../selection}/with-previous-block.js | 0 .../words/adjacent-texts-after-void.js | 0 .../words/adjacent-texts-end-first-block.js | 0 .../words/adjacent-texts-into-empty-block.js | 0 .../selection}/words/after-inline.js | 0 .../selection}/words/before-inline.js | 0 .../selection}/words/end-block.js | 0 .../selection}/words/end-inline.js | 0 .../selection}/words/middle-block.js | 0 .../selection}/words/middle-inline.js | 0 .../selection}/words/start-block.js | 0 .../selection}/words/start-second-block.js | 0 .../words/with-delete-across-blocks.js | 0 .../selection}/block-end.js | 0 .../selection}/block-middle.js | 0 .../selection}/block-start.js | 0 .../selection}/inline-middle.js | 0 .../selection}/is-empty.js | 0 .../selection}/is-void.js | 0 .../selection}/with-inline.js | 0 .../path}/block.js | 0 .../path}/inline.js | 0 .../path}/text.js | 0 .../point}/decoration-after-atomic.js | 0 .../point}/decoration-before-atomic.js | 0 .../point}/decoration-middle-atomic.js | 0 .../point}/selection-after.js | 0 .../point}/selection-before.js | 0 .../point}/selection-end.js | 0 .../point}/selection-middle.js | 0 .../point}/selection-start.js | 0 .../point}/text-end.js | 0 .../point}/text-middle.js | 0 .../point}/text-start.js | 0 .../commands/insertText/range/after-mark.js | 31 ++ .../range}/before-mark.js | 0 .../range}/blocks-with-overlapping-marks.js | 0 .../range}/during-mark.js | 0 .../range}/empty-block-with-mark.js | 0 .../insertText/range/expanded-with-mark.js | 32 ++ .../range}/first-character.js | 0 .../range}/first-space.js | 0 .../range}/first-words.js | 0 .../hanging-selection-multiple-blocks.js | 0 .../range}/hanging-selection-single-block.js | 0 .../range/inside-void.js} | 10 +- .../range}/last-character.js | 0 .../range}/last-space.js | 0 .../range}/last-words.js | 0 .../range}/middle-character.js | 0 .../range}/middle-space.js | 0 .../range}/middle-words.js | 0 .../liftNodeAtPath => liftNode/path}/block.js | 0 .../path}/first-block.js | 0 .../path}/last-block.js | 0 .../path}/middle-block.js | 0 .../path}/block.js | 0 .../moveAnchor => move/anchor}/backward.js | 0 .../moveAnchor => move/anchor}/basic.js | 0 .../moveAnchor => move/anchor}/collapsed.js | 0 .../moveAnchor => move/anchor}/distance.js | 0 .../anchor}/reverse-backward.js | 0 .../anchor}/reverse-basic.js | 0 .../anchor}/reverse-collapsed.js | 0 .../anchor}/reverse-distance.js | 0 .../move => move/both}/backward-reverse.js | 0 .../{selection/move => move/both}/backward.js | 0 .../move => move/both}/basic-reverse.js | 0 .../move => move/both}/collapsed.js | 0 .../move => move/both}/distance-reverse.js | 0 .../{selection/move => move/both}/distance.js | 0 .../move => move/both}/expanded-reverse.js | 0 .../{selection/move => move/both}/expanded.js | 0 .../move => move/both}/unit-word-reverse.js | 0 .../move => move/both}/unit-word.js | 0 .../moveEnd => move/end}/backward-reverse.js | 0 .../moveEnd => move/end}/backward.js | 0 .../moveEnd => move/end}/collapsed-reverse.js | 0 .../moveEnd => move/end}/collapsed.js | 0 .../moveEnd => move/end}/distance-reverse.js | 0 .../moveEnd => move/end}/distance.js | 0 .../moveEnd => move/end}/expanded-reverse.js | 0 .../moveEnd => move/end}/expanded.js | 0 .../end}/from-backward-reverse.js | 0 .../end}/to-backward-reverse.js | 0 .../moveFocus => move/focus}/backward.js | 0 .../focus}/collapsed-reverse.js | 0 .../moveFocus => move/focus}/collapsed.js | 0 .../focus}/distance-reverse.js | 0 .../moveFocus => move/focus}/distance.js | 0 .../focus}/expanded-reverse.js | 0 .../moveFocus => move/focus}/expanded.js | 0 .../focus}/to-backward-reverse.js | 0 .../start}/backward-reverse.js | 0 .../moveStart => move/start}/backward.js | 0 .../start}/collapsed-reverse.js | 0 .../moveStart => move/start}/collapsed.js | 0 .../start}/distance-reverse.js | 0 .../moveStart => move/start}/distance.js | 0 .../start}/expanded-reverse.js | 0 .../moveStart => move/start}/expanded.js | 0 .../moveStart => move/start}/from-backward.js | 0 .../moveStart => move/start}/to-backward.js | 0 .../moveNodeAtPath => moveNode/path}/block.js | 0 .../path}/inline.js | 0 .../path}/inside-next.js | 0 .../path}/nested.js | 0 .../path}/noop-equal.js | 0 .../path}/sibling-swap.js | 0 .../path}/text-nodes.js | 0 .../moveNodeAtPath => moveNode/path}/text.js | 0 .../path}/to-sibling.js | 0 .../commands/path/replaceNodeAtPath/block.js | 21 - .../commands/path/replaceNodeAtPath/inline.js | 27 -- .../commands/path/replaceNodeAtPath/text.js | 21 - .../path}/block-multiple.js | 0 .../path}/block.js | 0 .../adjacent-non-void-inlines.js | 31 -- .../decoration-after-atomic.js | 29 -- .../decoration-before-atomic.js | 29 -- .../decoration-middle-atomic.js | 25 - .../inline-last-character.js | 31 -- .../inline-nested-last-character.js | 41 -- .../point/removeTextAtPoint/inline-void.js | 33 -- .../point/removeTextAtPoint/inline.js | 29 -- .../removeTextAtPoint/next-void-inline.js | 35 -- .../removeTextAtPoint/previous-void-inline.js | 35 -- .../removeTextAtPoint/selection-after.js | 25 - .../removeTextAtPoint/selection-before.js | 25 - .../removeTextAtPoint/selection-start.js | 25 - .../path}/basic.js | 8 +- .../test/commands/removeMarks/range/basic.js | 28 ++ .../removeMarks/selection/across-blocks.js | 31 ++ .../selection}/across-inlines.js | 22 +- .../selection}/collapsed-selection.js | 2 +- .../selection}/existing-marks.js | 2 +- .../selection}/first-character.js | 8 +- .../selection}/last-character.js | 9 +- .../selection}/middle-character.js | 10 +- .../selection/part-of-mark-backward.js | 28 ++ .../removeMarks/selection/part-of-mark.js | 28 ++ .../removeMarks/selection/whole-word.js | 25 + .../commands/{selection => }/select/basic.js | 0 .../selection}/across-blocks.js | 0 .../selection}/across-inlines.js | 0 .../selection}/data-only.js | 0 .../hanging-selection-across-inlines.js | 0 .../selection}/hanging-selection.js | 0 .../selection}/nested-block.js | 0 .../single-block-string-shorthand.js | 0 .../selection}/single-block.js | 0 .../selection}/with-is-void.js | 0 .../selection}/across-inlines.js | 0 .../selection}/data-only.js | 0 .../selection}/nested-inline.js | 0 .../single-inline-string-shorthand.js | 0 .../selection}/single-inline.js | 0 .../selection}/with-data-object.js | 0 .../selection}/with-data.js | 0 .../selection}/with-is-void.js | 0 .../setMarkAtPath => setMarks/path}/basic.js | 14 +- .../test/commands/setMarks/range/basic.js | 38 ++ .../selection/basic.js} | 6 +- .../setNodeAtPath => setNode/path}/block.js | 0 .../setNodeAtPath => setNode/path}/inline.js | 0 .../setNodeAtPath => setNode/path}/text.js | 0 .../{value/set-data => setValue}/simple.js | 0 .../point}/block.js | 0 .../point}/selection.js | 0 .../selection}/after-inline-void.js | 0 .../selection}/after-inline.js | 0 .../selection}/before-inline.js | 0 .../selection}/block-end.js | 0 .../selection}/block-middle.js | 0 .../selection}/block-start.js | 0 .../selection}/depth.js | 0 .../with-delete-across-blocks-and-inlines.js | 0 .../selection}/with-delete-across-blocks.js | 0 .../with-delete-hanging-selection.js | 0 .../selection}/with-delete.js | 0 .../selection}/with-inline.js | 0 .../selection}/with-marks.js | 0 .../point}/inline.js | 0 .../selection}/block-end.js | 0 .../selection}/block-middle.js | 0 .../selection}/block-start.js | 0 .../selection}/height.js | 0 .../selection}/with-delete.js | 0 .../selection}/with-marks.js | 0 .../path}/block.js | 0 .../path}/selection.js | 0 .../point}/block.js | 0 .../point}/inline.js | 0 .../point}/selection.js | 0 .../text.js => toggleMarks/path/add.js} | 12 +- .../test/commands/toggleMarks/path/remove.js | 23 + .../toggleMarks/range/add-text-middle.js | 28 ++ .../toggleMarks/range/remove-text-middle.js | 28 ++ .../selection/add-across-blocks.js} | 10 +- .../selection}/add-across-inlines.js | 2 +- .../add-existing-marks-partially-marked.js | 10 +- .../selection}/add-existing-marks.js | 8 +- .../selection/add-first-character.js | 26 ++ .../selection/add-last-character.js | 26 ++ .../selection/add-middle-character.js | 27 ++ .../selection/add-partially-marked.js | 27 ++ .../selection/add-whole-word.js} | 10 +- .../selection/remove-across-blocks.js | 33 ++ .../selection}/remove-across-inlines.js | 4 +- .../selection}/remove-existing-marks.js | 2 +- .../selection/remove-first-character.js | 26 ++ .../selection/remove-last-character.js | 26 ++ .../selection/remove-middle-character.js | 27 ++ .../selection/remove-whole-word.js | 25 + .../selection}/across-blocks.js | 0 .../selection}/across-inlines.js | 0 .../selection}/ending-child-blocks.js | 0 ...le-child-blocks-with-backward-selection.js | 0 .../selection}/middle-child-blocks.js | 0 .../selection}/nested-block.js | 0 .../selection}/single-block.js | 0 .../selection}/starting-child-blocks.js | 0 .../selection}/with-object.js | 0 .../selection}/across-blocks.js | 0 .../selection}/across-inlines-and-text.js | 0 .../selection}/across-inlines.js | 0 .../selection}/nested-block.js | 0 .../selection}/only-one.js | 0 .../selection}/single-block.js | 0 .../selection}/with-object.js | 0 .../commands/value/insert-block/block-end.js | 28 -- .../value/insert-block/block-middle.js | 29 -- .../value/insert-block/block-start.js | 28 -- .../value/insert-block/is-void-end.js | 30 -- .../value/insert-block/is-void-start.js | 30 -- .../commands/value/insert-block/with-block.js | 29 -- .../value/insert-block/with-object.js | 28 -- .../commands/value/insert-text/after-mark.js | 31 -- .../value/insert-text/expanded-with-mark.js | 34 -- .../commands/value/insert-text/inside-void.js | 27 -- .../commands/value/insert-text/with-marks.js | 30 -- .../value/remove-mark/across-blocks.js | 35 -- .../value/remove-mark/across-inlines.js | 43 -- .../value/remove-mark/first-character.js | 29 -- .../value/remove-mark/last-character.js | 30 -- .../value/remove-mark/middle-character.js | 31 -- .../remove-mark/part-of-mark-backward.js | 30 -- .../value/remove-mark/part-of-mark.js | 30 -- .../commands/value/remove-mark/whole-word.js | 29 -- .../value/remove-mark/with-mark-object.js | 35 -- .../value/remove-mark/with-plain-object.js | 32 -- .../value/replace-mark/existing-marks.js | 29 -- .../value/replace-mark/with-mark-object.js | 41 -- .../value/replace-mark/with-plain-object.js | 36 -- .../value/set-block/with-data-as-map.js | 31 -- .../value/set-block/with-data-as-object.js | 30 -- .../value/toggle-mark/add-across-blocks.js | 37 -- .../add-collapsed-selection-start.js | 29 -- .../toggle-mark/add-collapsed-selection.js | 30 -- .../value/toggle-mark/add-first-character.js | 30 -- .../value/toggle-mark/add-last-character.js | 30 -- .../value/toggle-mark/add-middle-character.js | 31 -- .../value/toggle-mark/add-partially-marked.js | 31 -- .../value/toggle-mark/add-whole-word.js | 29 -- .../value/toggle-mark/add-with-mark-object.js | 36 -- .../toggle-mark/add-with-plain-object.js | 33 -- .../value/toggle-mark/remove-across-blocks.js | 37 -- .../remove-collapsed-selection-beginning.js | 29 -- .../toggle-mark/remove-collapsed-selection.js | 29 -- .../toggle-mark/remove-first-character.js | 30 -- .../toggle-mark/remove-last-character.js | 30 -- .../toggle-mark/remove-middle-character.js | 31 -- .../value/toggle-mark/remove-whole-word.js | 29 -- .../toggle-mark/remove-with-mark-object.js | 36 -- .../toggle-mark/remove-with-plain-object.js | 33 -- .../commands/value/wrap-text/across-blocks.js | 33 -- .../value/wrap-text/across-inlines.js | 37 -- .../value/wrap-text/backwards-selection.js | 27 -- .../commands/value/wrap-text/empty-block.js | 27 -- .../commands/value/wrap-text/end-of-block.js | 27 -- .../value/wrap-text/middle-of-block.js | 27 -- .../value/wrap-text/start-of-block.js | 27 -- .../commands/value/wrap-text/whole-block.js | 27 -- .../value/wrap-text/without-suffix.js | 27 -- .../selection}/across-blocks.js | 0 .../selection}/across-inlines.js | 0 .../selection}/nested-block-with-object.js | 0 .../selection}/nested-block.js | 0 .../selection}/single-block.js | 0 .../selection}/with-object.js | 0 .../selection}/across-blocks.js | 0 .../selection}/across-inlines.js | 0 .../selection}/collapsed.js | 0 .../selection}/inline-end.js | 0 .../selection}/inline-middle-with-marks.js | 0 .../selection}/inline-middle.js | 0 .../selection}/inline-start.js | 0 .../selection}/inline-void.js | 0 .../selection}/nested-block.js | 0 .../selection}/single-block.js | 0 .../selection}/twice.js | 0 .../selection}/whole-block.js | 0 .../selection}/with-object.js | 0 .../wrapNodeAtPath => wrapNode/path}/block.js | 0 .../wrapNodeAtPath => wrapNode/path}/text.js | 0 .../insert-text/annotation-before.js | 0 .../merge-node/annotation-across-blocks.js | 0 .../move-node/path-equals-new-path.js | 0 .../remove-node/annotation-across-blocks.js | 0 .../{apply => }/remove-text/anchor-after.js | 0 .../{apply => }/remove-text/anchor-before.js | 0 .../{apply => }/remove-text/anchor-middle.js | 0 .../remove-text/annotation-after.js | 0 .../remove-text/annotation-before.js | 0 .../remove-text/annotation-middle.js | 0 .../{apply => }/remove-text/cursor-after.js | 0 .../{apply => }/remove-text/cursor-before.js | 0 .../{apply => }/remove-text/cursor-middle.js | 0 .../{apply => }/remove-text/focus-after.js | 0 .../{apply => }/remove-text/focus-before.js | 0 .../{apply => }/remove-text/focus-middle.js | 0 512 files changed, 1574 insertions(+), 3079 deletions(-) rename packages/slate/test/commands/{selection/focus => addMarks/path}/basic.js (66%) create mode 100644 packages/slate/test/commands/addMarks/range/basic.js rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/block-across-edge-existing.js (95%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/block-across-existing.js (86%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/block-across.js (84%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/existing.js (83%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/first-character.js (82%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/inline-across.js (88%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/last-character.js (100%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/middle-character.js (83%) rename packages/slate/test/commands/{value/addMarks => addMarks/selection}/word.js (100%) rename packages/slate/test/commands/{value => }/delete/emojis/inline-end-reverse.js (91%) rename packages/slate/test/commands/{value => }/delete/emojis/inline-middle-reverse.js (91%) rename packages/slate/test/commands/{value => }/delete/emojis/inline-middle.js (91%) rename packages/slate/test/commands/{value => }/delete/emojis/inline-only-reverse.js (91%) rename packages/slate/test/commands/{value => }/delete/emojis/inline-start.js (91%) rename packages/slate/test/commands/{value => }/delete/emojis/text-end-reverse.js (88%) rename packages/slate/test/commands/{value => }/delete/emojis/text-start.js (87%) rename packages/slate/test/commands/{path/removeNodeAtPath => delete/path}/block.js (88%) rename packages/slate/test/commands/{path/removeNodeAtPath => delete/path}/inline.js (89%) rename packages/slate/test/commands/{path/removeNodeAtPath => delete/path}/selection-inside.js (91%) rename packages/slate/test/commands/{path/removeNodeAtPath => delete/path}/text.js (88%) rename packages/slate/test/commands/{value/delete/join => delete/point}/basic-reverse.js (88%) rename packages/slate/test/commands/{value/delete/join => delete/point}/basic.js (87%) rename packages/slate/test/commands/{value/delete/join => delete/point}/depths-reverse.js (89%) rename packages/slate/test/commands/{value/delete/join => delete/point}/inline-before-reverse.js (90%) rename packages/slate/test/commands/{value/delete/join => delete/point}/inline-before.js (91%) rename packages/slate/test/commands/{value/delete/join => delete/point}/inline-inside-reverse.js (92%) rename packages/slate/test/commands/{value/delete/join => delete/point}/inline-void-reverse.js (91%) rename packages/slate/test/commands/{value/delete/join => delete/point}/inline.js (89%) rename packages/slate/test/commands/{value/delete/join => delete/point}/nested-reverse.js (90%) rename packages/slate/test/commands/{value/delete/join => delete/point}/nested.js (89%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-across-multiple.js (84%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-across-nested.js (85%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-across.js (88%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-depths-nested.js (90%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-depths.js (81%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-hanging-multiple.js (88%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-hanging-single.js (74%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-inline-across.js (93%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-join-edges.js (79%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-join-inline.js (89%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-join-nested.js (83%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/block-nested.js (92%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/character-end.js (85%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/character-middle.js (76%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/character-start.js (86%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/inline-after.js (89%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/inline-inside.js (90%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/inline-over.js (87%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/inline-whole.js (90%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/mark-across.js (89%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/mark-whole.js (88%) rename packages/slate/test/commands/{value/delete/expanded => delete/selection}/word.js (85%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/document-end.js (86%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/document-start-reverse.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/empty-reverse.js (86%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/empty.js (86%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/end-reverse.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/end.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/first-reverse.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/first.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/inline-after-reverse.js (89%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/inline-before-reverse.js (90%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/inline-before.js (88%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/inline-end-reverse.js (89%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/inline-inside-reverse.js (90%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/inline-inside.js (89%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/last-reverse.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/last.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/middle-reverse.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/middle.js (87%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/multiple-reverse.js (88%) rename packages/slate/test/commands/{value/delete/character => delete/unit-character}/multiple.js (87%) rename packages/slate/test/commands/{value/delete/line => delete/unit-line}/text-end-reverse.js (87%) rename packages/slate/test/commands/{value/delete/line => delete/unit-line}/text-end.js (84%) rename packages/slate/test/commands/{value/delete/line => delete/unit-line}/text-middle-reverse.js (87%) rename packages/slate/test/commands/{value/delete/line => delete/unit-line}/text-middle.js (87%) rename packages/slate/test/commands/{value/delete/line => delete/unit-line}/text-start-reverse.js (85%) rename packages/slate/test/commands/{value/delete/line => delete/unit-line}/text-start.js (87%) rename packages/slate/test/commands/{value/delete/word => delete/unit-word}/block-join-reverse.js (88%) rename packages/slate/test/commands/{value/delete/word => delete/unit-word}/block-join.js (88%) rename packages/slate/test/commands/{value/delete/word => delete/unit-word}/text-end-reverse.js (88%) rename packages/slate/test/commands/{value/delete/word => delete/unit-word}/text-middle-reverse.js (88%) rename packages/slate/test/commands/{value/delete/word => delete/unit-word}/text-middle.js (87%) rename packages/slate/test/commands/{value/delete/word => delete/unit-word}/text-start.js (87%) rename packages/slate/test/commands/{value => }/delete/voids/block-across-backward.js (88%) rename packages/slate/test/commands/{value => }/delete/voids/block-after-reverse.js (89%) rename packages/slate/test/commands/{value => }/delete/voids/block-before.js (88%) rename packages/slate/test/commands/{value => }/delete/voids/block-both.js (90%) rename packages/slate/test/commands/{value => }/delete/voids/block-hanging-from.js (89%) rename packages/slate/test/commands/{value => }/delete/voids/block-hanging-into.js (89%) rename packages/slate/test/commands/{value => }/delete/voids/block-only.js (82%) rename packages/slate/test/commands/{value => }/delete/voids/block-start-multiple.js (90%) rename packages/slate/test/commands/{value => }/delete/voids/block-start.js (90%) rename packages/slate/test/commands/{value => }/delete/voids/inline-after-reverse.js (90%) rename packages/slate/test/commands/{value => }/delete/voids/inline-before.js (90%) rename packages/slate/test/commands/{value => }/delete/voids/inline-into.js (90%) rename packages/slate/test/commands/{value => }/delete/voids/inline-over.js (85%) rename packages/slate/test/commands/{value => }/delete/voids/inline-start-across.js (84%) rename packages/slate/test/commands/{value => }/delete/voids/inline-start.js (83%) rename packages/slate/test/commands/{selection => }/deselect/basic.js (100%) rename packages/slate/test/commands/{selection => }/deselect/unfocused.js (100%) rename packages/slate/test/commands/{value/insert-block/is-empty.js => insertBlock/selection/block-empty.js} (84%) create mode 100644 packages/slate/test/commands/insertBlock/selection/block-end.js create mode 100644 packages/slate/test/commands/insertBlock/selection/block-middle.js create mode 100644 packages/slate/test/commands/insertBlock/selection/block-start.js create mode 100644 packages/slate/test/commands/insertBlock/selection/block-void.js rename packages/slate/test/commands/{value/insert-block/is-inline-void.js => insertBlock/selection/inline-void.js} (83%) rename packages/slate/test/commands/{path/insertFragmentAtPath => insertFragment/path}/end-of-target.js (100%) rename packages/slate/test/commands/{path/insertFragmentAtPath => insertFragment/path}/middle-of-target.js (100%) rename packages/slate/test/commands/{path/insertFragmentAtPath => insertFragment/path}/start-of-target.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/block-empty.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/block-end.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/block-middle.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/block-start.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/end-block-multiple-blocks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/end-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/end-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/flat-blocks/end-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/flat-blocks/hanging-selection-mixed-types.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/flat-blocks/start-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-adjacent-texts.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-inline-node.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-multiple-blocks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-multiple-marks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-nested-blocks-end-of-node.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-nested-blocks-start-of-node.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-nested-blocks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-single-child-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-single-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/fragment-single-mark.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/hanging-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/inline-middle.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/inline-start.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/inlines/between-texts-into-middle-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/inlines/middle-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/inlines/middle-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-inline-at-inline-middle.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-multiple-blocks-at-middle.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-multiple-blocks-at-start.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-multiple-texts.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-nested-blocks-at-end.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-nested-blocks-at-middle.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/insert-nested-blocks-at-start.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/last-block-fragment-multiple.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/last-block-fragment-single.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/last-block-inline-fragment-single.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/lists/merge-lists.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/marks/middle-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/marks/multiple-marks-middle-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/merge-deep-nested.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/merge-lists.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/middle-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/middle-fragment-adjacent-texts.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/middle-inline-fragment-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/middle-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/nested-block-fragment-nested-blocks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/nested-blocks-different-structure/end-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/nested-blocks-different-structure/middle-block-nested.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/nested-blocks-different-structure/middle-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/nested-blocks-different-structure/start-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/nested-blocks-same-structure/end-block-nested.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/nested-blocks-same-structure/start-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/start-block-multiple-blocks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/start-block-with-void-no-text.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/start-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/start-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/start-second-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/tables/merge-cells-with-nested-blocks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/tables/merge-into-empty-cells.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/tables/merge-into-full-cells.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/with-previous-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/adjacent-texts-after-void.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/adjacent-texts-end-first-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/adjacent-texts-into-empty-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/after-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/before-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/end-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/end-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/middle-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/middle-inline.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/start-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/start-second-block.js (100%) rename packages/slate/test/commands/{value/insert-fragment => insertFragment/selection}/words/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{value/insert-inline => insertInline/selection}/block-end.js (100%) rename packages/slate/test/commands/{value/insert-inline => insertInline/selection}/block-middle.js (100%) rename packages/slate/test/commands/{value/insert-inline => insertInline/selection}/block-start.js (100%) rename packages/slate/test/commands/{value/insert-inline => insertInline/selection}/inline-middle.js (100%) rename packages/slate/test/commands/{value/insert-inline => insertInline/selection}/is-empty.js (100%) rename packages/slate/test/commands/{value/insert-inline => insertInline/selection}/is-void.js (100%) rename packages/slate/test/commands/{value/insert-inline => insertInline/selection}/with-inline.js (100%) rename packages/slate/test/commands/{path/insertNodeAtPath => insertNode/path}/block.js (100%) rename packages/slate/test/commands/{path/insertNodeAtPath => insertNode/path}/inline.js (100%) rename packages/slate/test/commands/{path/insertNodeAtPath => insertNode/path}/text.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/decoration-after-atomic.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/decoration-before-atomic.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/decoration-middle-atomic.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/selection-after.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/selection-before.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/selection-end.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/selection-middle.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/selection-start.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/text-end.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/text-middle.js (100%) rename packages/slate/test/commands/{point/insertTextAtPoint => insertText/point}/text-start.js (100%) create mode 100644 packages/slate/test/commands/insertText/range/after-mark.js rename packages/slate/test/commands/{value/insert-text => insertText/range}/before-mark.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/blocks-with-overlapping-marks.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/during-mark.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/empty-block-with-mark.js (100%) create mode 100644 packages/slate/test/commands/insertText/range/expanded-with-mark.js rename packages/slate/test/commands/{value/insert-text => insertText/range}/first-character.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/first-space.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/first-words.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/hanging-selection-multiple-blocks.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/hanging-selection-single-block.js (100%) rename packages/slate/test/commands/{selection/blur/basic.js => insertText/range/inside-void.js} (68%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/last-character.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/last-space.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/last-words.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/middle-character.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/middle-space.js (100%) rename packages/slate/test/commands/{value/insert-text => insertText/range}/middle-words.js (100%) rename packages/slate/test/commands/{path/liftNodeAtPath => liftNode/path}/block.js (100%) rename packages/slate/test/commands/{path/liftNodeAtPath => liftNode/path}/first-block.js (100%) rename packages/slate/test/commands/{path/liftNodeAtPath => liftNode/path}/last-block.js (100%) rename packages/slate/test/commands/{path/liftNodeAtPath => liftNode/path}/middle-block.js (100%) rename packages/slate/test/commands/{path/mergeNodeAtPath => mergeNode/path}/block.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/backward.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/basic.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/collapsed.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/distance.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/reverse-backward.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/reverse-basic.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/reverse-collapsed.js (100%) rename packages/slate/test/commands/{selection/moveAnchor => move/anchor}/reverse-distance.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/backward-reverse.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/backward.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/basic-reverse.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/collapsed.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/distance-reverse.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/distance.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/expanded-reverse.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/expanded.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/unit-word-reverse.js (100%) rename packages/slate/test/commands/{selection/move => move/both}/unit-word.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/backward-reverse.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/backward.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/collapsed-reverse.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/collapsed.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/distance-reverse.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/distance.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/expanded-reverse.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/expanded.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/from-backward-reverse.js (100%) rename packages/slate/test/commands/{selection/moveEnd => move/end}/to-backward-reverse.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/backward.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/collapsed-reverse.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/collapsed.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/distance-reverse.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/distance.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/expanded-reverse.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/expanded.js (100%) rename packages/slate/test/commands/{selection/moveFocus => move/focus}/to-backward-reverse.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/backward-reverse.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/backward.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/collapsed-reverse.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/collapsed.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/distance-reverse.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/distance.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/expanded-reverse.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/expanded.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/from-backward.js (100%) rename packages/slate/test/commands/{selection/moveStart => move/start}/to-backward.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/block.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/inline.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/inside-next.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/nested.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/noop-equal.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/sibling-swap.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/text-nodes.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/text.js (100%) rename packages/slate/test/commands/{path/moveNodeAtPath => moveNode/path}/to-sibling.js (100%) delete mode 100644 packages/slate/test/commands/path/replaceNodeAtPath/block.js delete mode 100644 packages/slate/test/commands/path/replaceNodeAtPath/inline.js delete mode 100644 packages/slate/test/commands/path/replaceNodeAtPath/text.js rename packages/slate/test/commands/{path/pluckNodeAtPath => pluckNode/path}/block-multiple.js (100%) rename packages/slate/test/commands/{path/pluckNodeAtPath => pluckNode/path}/block.js (100%) delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/adjacent-non-void-inlines.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/decoration-after-atomic.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/decoration-before-atomic.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/decoration-middle-atomic.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/inline-last-character.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/inline-nested-last-character.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/inline-void.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/inline.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/next-void-inline.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/previous-void-inline.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/selection-after.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/selection-before.js delete mode 100644 packages/slate/test/commands/point/removeTextAtPoint/selection-start.js rename packages/slate/test/commands/{path/replaceTextAtPath => removeMarks/path}/basic.js (65%) create mode 100644 packages/slate/test/commands/removeMarks/range/basic.js create mode 100644 packages/slate/test/commands/removeMarks/selection/across-blocks.js rename packages/slate/test/commands/{value/replace-mark => removeMarks/selection}/across-inlines.js (65%) rename packages/slate/test/commands/{value/remove-mark => removeMarks/selection}/collapsed-selection.js (90%) rename packages/slate/test/commands/{value/remove-mark => removeMarks/selection}/existing-marks.js (92%) rename packages/slate/test/commands/{value/replace-mark => removeMarks/selection}/first-character.js (74%) rename packages/slate/test/commands/{value/replace-mark => removeMarks/selection}/last-character.js (72%) rename packages/slate/test/commands/{value/replace-mark => removeMarks/selection}/middle-character.js (72%) create mode 100644 packages/slate/test/commands/removeMarks/selection/part-of-mark-backward.js create mode 100644 packages/slate/test/commands/removeMarks/selection/part-of-mark.js create mode 100644 packages/slate/test/commands/removeMarks/selection/whole-word.js rename packages/slate/test/commands/{selection => }/select/basic.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/across-blocks.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/across-inlines.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/data-only.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/hanging-selection-across-inlines.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/hanging-selection.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/nested-block.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/single-block-string-shorthand.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/single-block.js (100%) rename packages/slate/test/commands/{value/set-block => setBlocks/selection}/with-is-void.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/across-inlines.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/data-only.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/nested-inline.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/single-inline-string-shorthand.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/single-inline.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/with-data-object.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/with-data.js (100%) rename packages/slate/test/commands/{value/set-inline => setInlines/selection}/with-is-void.js (100%) rename packages/slate/test/commands/{path/setMarkAtPath => setMarks/path}/basic.js (67%) create mode 100644 packages/slate/test/commands/setMarks/range/basic.js rename packages/slate/test/commands/{value/replace-mark/whole-word.js => setMarks/selection/basic.js} (81%) rename packages/slate/test/commands/{path/setNodeAtPath => setNode/path}/block.js (100%) rename packages/slate/test/commands/{path/setNodeAtPath => setNode/path}/inline.js (100%) rename packages/slate/test/commands/{path/setNodeAtPath => setNode/path}/text.js (100%) rename packages/slate/test/commands/{value/set-data => setValue}/simple.js (100%) rename packages/slate/test/commands/{point/splitBlockAtPoint => splitBlock/point}/block.js (100%) rename packages/slate/test/commands/{point/splitBlockAtPoint => splitBlock/point}/selection.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/after-inline-void.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/after-inline.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/before-inline.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/block-end.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/block-middle.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/block-start.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/depth.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/with-delete-across-blocks-and-inlines.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/with-delete-across-blocks.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/with-delete-hanging-selection.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/with-delete.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/with-inline.js (100%) rename packages/slate/test/commands/{value/split-block => splitBlock/selection}/with-marks.js (100%) rename packages/slate/test/commands/{point/splitInlineAtPoint => splitInline/point}/inline.js (100%) rename packages/slate/test/commands/{value/split-inline => splitInline/selection}/block-end.js (100%) rename packages/slate/test/commands/{value/split-inline => splitInline/selection}/block-middle.js (100%) rename packages/slate/test/commands/{value/split-inline => splitInline/selection}/block-start.js (100%) rename packages/slate/test/commands/{value/split-inline => splitInline/selection}/height.js (100%) rename packages/slate/test/commands/{value/split-inline => splitInline/selection}/with-delete.js (100%) rename packages/slate/test/commands/{value/split-inline => splitInline/selection}/with-marks.js (100%) rename packages/slate/test/commands/{path/splitNodeAtPath => splitNode/path}/block.js (100%) rename packages/slate/test/commands/{path/splitNodeAtPath => splitNode/path}/selection.js (100%) rename packages/slate/test/commands/{point/splitNodeAtPoint => splitNode/point}/block.js (100%) rename packages/slate/test/commands/{point/splitNodeAtPoint => splitNode/point}/inline.js (100%) rename packages/slate/test/commands/{point/splitNodeAtPoint => splitNode/point}/selection.js (100%) rename packages/slate/test/commands/{point/removeTextAtPoint/text.js => toggleMarks/path/add.js} (63%) create mode 100644 packages/slate/test/commands/toggleMarks/path/remove.js create mode 100644 packages/slate/test/commands/toggleMarks/range/add-text-middle.js create mode 100644 packages/slate/test/commands/toggleMarks/range/remove-text-middle.js rename packages/slate/test/commands/{value/replace-mark/across-blocks.js => toggleMarks/selection/add-across-blocks.js} (71%) rename packages/slate/test/commands/{value/toggle-mark => toggleMarks/selection}/add-across-inlines.js (95%) rename packages/slate/test/commands/{value/toggle-mark => toggleMarks/selection}/add-existing-marks-partially-marked.js (77%) rename packages/slate/test/commands/{value/toggle-mark => toggleMarks/selection}/add-existing-marks.js (77%) create mode 100644 packages/slate/test/commands/toggleMarks/selection/add-first-character.js create mode 100644 packages/slate/test/commands/toggleMarks/selection/add-last-character.js create mode 100644 packages/slate/test/commands/toggleMarks/selection/add-middle-character.js create mode 100644 packages/slate/test/commands/toggleMarks/selection/add-partially-marked.js rename packages/slate/test/commands/{point/removeTextAtPoint/selection-middle.js => toggleMarks/selection/add-whole-word.js} (69%) create mode 100644 packages/slate/test/commands/toggleMarks/selection/remove-across-blocks.js rename packages/slate/test/commands/{value/toggle-mark => toggleMarks/selection}/remove-across-inlines.js (91%) rename packages/slate/test/commands/{value/toggle-mark => toggleMarks/selection}/remove-existing-marks.js (92%) create mode 100644 packages/slate/test/commands/toggleMarks/selection/remove-first-character.js create mode 100644 packages/slate/test/commands/toggleMarks/selection/remove-last-character.js create mode 100644 packages/slate/test/commands/toggleMarks/selection/remove-middle-character.js create mode 100644 packages/slate/test/commands/toggleMarks/selection/remove-whole-word.js rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/across-blocks.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/across-inlines.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/ending-child-blocks.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/middle-child-blocks-with-backward-selection.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/middle-child-blocks.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/nested-block.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/single-block.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/starting-child-blocks.js (100%) rename packages/slate/test/commands/{value/unwrap-block => unwrapBlock/selection}/with-object.js (100%) rename packages/slate/test/commands/{value/unwrap-inline => unwrapInline/selection}/across-blocks.js (100%) rename packages/slate/test/commands/{value/unwrap-inline => unwrapInline/selection}/across-inlines-and-text.js (100%) rename packages/slate/test/commands/{value/unwrap-inline => unwrapInline/selection}/across-inlines.js (100%) rename packages/slate/test/commands/{value/unwrap-inline => unwrapInline/selection}/nested-block.js (100%) rename packages/slate/test/commands/{value/unwrap-inline => unwrapInline/selection}/only-one.js (100%) rename packages/slate/test/commands/{value/unwrap-inline => unwrapInline/selection}/single-block.js (100%) rename packages/slate/test/commands/{value/unwrap-inline => unwrapInline/selection}/with-object.js (100%) delete mode 100644 packages/slate/test/commands/value/insert-block/block-end.js delete mode 100644 packages/slate/test/commands/value/insert-block/block-middle.js delete mode 100644 packages/slate/test/commands/value/insert-block/block-start.js delete mode 100644 packages/slate/test/commands/value/insert-block/is-void-end.js delete mode 100644 packages/slate/test/commands/value/insert-block/is-void-start.js delete mode 100644 packages/slate/test/commands/value/insert-block/with-block.js delete mode 100644 packages/slate/test/commands/value/insert-block/with-object.js delete mode 100644 packages/slate/test/commands/value/insert-text/after-mark.js delete mode 100644 packages/slate/test/commands/value/insert-text/expanded-with-mark.js delete mode 100644 packages/slate/test/commands/value/insert-text/inside-void.js delete mode 100644 packages/slate/test/commands/value/insert-text/with-marks.js delete mode 100644 packages/slate/test/commands/value/remove-mark/across-blocks.js delete mode 100644 packages/slate/test/commands/value/remove-mark/across-inlines.js delete mode 100644 packages/slate/test/commands/value/remove-mark/first-character.js delete mode 100644 packages/slate/test/commands/value/remove-mark/last-character.js delete mode 100644 packages/slate/test/commands/value/remove-mark/middle-character.js delete mode 100644 packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js delete mode 100644 packages/slate/test/commands/value/remove-mark/part-of-mark.js delete mode 100644 packages/slate/test/commands/value/remove-mark/whole-word.js delete mode 100644 packages/slate/test/commands/value/remove-mark/with-mark-object.js delete mode 100644 packages/slate/test/commands/value/remove-mark/with-plain-object.js delete mode 100644 packages/slate/test/commands/value/replace-mark/existing-marks.js delete mode 100644 packages/slate/test/commands/value/replace-mark/with-mark-object.js delete mode 100644 packages/slate/test/commands/value/replace-mark/with-plain-object.js delete mode 100644 packages/slate/test/commands/value/set-block/with-data-as-map.js delete mode 100644 packages/slate/test/commands/value/set-block/with-data-as-object.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-across-blocks.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-first-character.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-last-character.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-middle-character.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-partially-marked.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-whole-word.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection-beginning.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-first-character.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-last-character.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-middle-character.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-whole-word.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js delete mode 100644 packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js delete mode 100644 packages/slate/test/commands/value/wrap-text/across-blocks.js delete mode 100644 packages/slate/test/commands/value/wrap-text/across-inlines.js delete mode 100644 packages/slate/test/commands/value/wrap-text/backwards-selection.js delete mode 100644 packages/slate/test/commands/value/wrap-text/empty-block.js delete mode 100644 packages/slate/test/commands/value/wrap-text/end-of-block.js delete mode 100644 packages/slate/test/commands/value/wrap-text/middle-of-block.js delete mode 100644 packages/slate/test/commands/value/wrap-text/start-of-block.js delete mode 100644 packages/slate/test/commands/value/wrap-text/whole-block.js delete mode 100644 packages/slate/test/commands/value/wrap-text/without-suffix.js rename packages/slate/test/commands/{value/wrap-block => wrapBlock/selection}/across-blocks.js (100%) rename packages/slate/test/commands/{value/wrap-block => wrapBlock/selection}/across-inlines.js (100%) rename packages/slate/test/commands/{value/wrap-block => wrapBlock/selection}/nested-block-with-object.js (100%) rename packages/slate/test/commands/{value/wrap-block => wrapBlock/selection}/nested-block.js (100%) rename packages/slate/test/commands/{value/wrap-block => wrapBlock/selection}/single-block.js (100%) rename packages/slate/test/commands/{value/wrap-block => wrapBlock/selection}/with-object.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/across-blocks.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/across-inlines.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/collapsed.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/inline-end.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/inline-middle-with-marks.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/inline-middle.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/inline-start.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/inline-void.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/nested-block.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/single-block.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/twice.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/whole-block.js (100%) rename packages/slate/test/commands/{value/wrap-inline => wrapInline/selection}/with-object.js (100%) rename packages/slate/test/commands/{path/wrapNodeAtPath => wrapNode/path}/block.js (100%) rename packages/slate/test/commands/{path/wrapNodeAtPath => wrapNode/path}/text.js (100%) rename packages/slate/test/operations/{apply => }/insert-text/annotation-before.js (100%) rename packages/slate/test/operations/{apply => }/merge-node/annotation-across-blocks.js (100%) rename packages/slate/test/operations/{apply => }/move-node/path-equals-new-path.js (100%) rename packages/slate/test/operations/{apply => }/remove-node/annotation-across-blocks.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/anchor-after.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/anchor-before.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/anchor-middle.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/annotation-after.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/annotation-before.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/annotation-middle.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/cursor-after.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/cursor-before.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/cursor-middle.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/focus-after.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/focus-before.js (100%) rename packages/slate/test/operations/{apply => }/remove-text/focus-middle.js (100%) diff --git a/packages/slate-hyperscript/src/creators.ts b/packages/slate-hyperscript/src/creators.ts index b1f20ec7e0..81f2762d46 100644 --- a/packages/slate-hyperscript/src/creators.ts +++ b/packages/slate-hyperscript/src/creators.ts @@ -310,11 +310,7 @@ export function createValue( ...attributes, } - const selection: any = { - isFocused: false, - marks: null, - } - + const selection: Partial = {} const partials: Record = {} // Search the document's texts to see if any of them have tokens associated @@ -325,17 +321,13 @@ export function createValue( const anns = getAnnotationOffsets(node) if (anchor != null) { - const [offset, token] = anchor + const [offset] = anchor selection.anchor = { path, offset } - selection.isFocused = token.focused - selection.marks = token.marks } if (focus != null) { - const [offset, token] = focus + const [offset] = focus selection.focus = { path, offset } - selection.isFocused = token.focused - selection.marks = token.marks } for (const o in anns) { diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 9f5e3bff1c..19c677b43d 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -13,19 +13,6 @@ import { } from '../..' class PathCommands { - /** - * Add a mark to the node at a path. - */ - - addMarkAtPath(this: Editor, path: Path, mark: Mark): void { - const { value } = this - const leaf = Node.leaf(value, path) - - if (!Mark.exists(mark, leaf.marks)) { - this.apply({ type: 'add_mark', path, mark }) - } - } - /** * Insert a fragment starting at a path. */ @@ -136,10 +123,8 @@ class PathCommands { const furthestRef = furthest ? this.createPathRef(furthest[1]) : null - debugger this.moveNodeAtPath(blockPath, newPath) - debugger if (furthestRef) { this.removeNodeAtPath(furthestRef.unref()!) } @@ -147,7 +132,6 @@ class PathCommands { // If the target block is empty, remove it instead of merging. This is a // rich text editor common behavior to prevent losing block formatting // when deleting the entire previous block (with a hanging selection). - debugger if (this.isEmpty(prev)) { this.removeNodeAtPath(prevPath) } else { @@ -368,19 +352,6 @@ class PathCommands { }) } - /** - * Remove a mark on the node at a path. - */ - - removeMarkAtPath(this: Editor, path: Path, mark: Mark): void { - const { value } = this - const leaf = Node.leaf(value, path) - - if (Mark.exists(mark, leaf.marks)) { - this.apply({ type: 'remove_mark', path, mark }) - } - } - /** * Remove the node at a path. */ @@ -402,22 +373,6 @@ class PathCommands { this.apply({ type: 'remove_node', path: parentPath, node: parent }) } - /** - * Replace a mark on the text node at a path. - */ - - replaceMarkAtPath( - this: Editor, - path: Path, - oldMark: Mark, - newMark: Mark - ): void { - this.withoutNormalizing(() => { - this.removeMarkAtPath(path, oldMark) - this.addMarkAtPath(path, newMark) - }) - } - /** * Replace the node at a path with a new node. */ @@ -429,63 +384,6 @@ class PathCommands { }) } - /** - * Replace all of the text in a node at a path. - */ - - replaceTextAtPath(this: Editor, path: Path, text: string): void { - this.withoutNormalizing(() => { - const { value } = this - const node = Node.leaf(value, path) - const point = { path, offset: 0 } - this.removeTextAtPoint(point, node.text.length) - this.insertTextAtPoint(point, text) - }) - } - - /** - * Set new properties on the mark at a path. - */ - - setMarkAtPath( - this: Editor, - path: Path, - mark: Partial, - props: {} - ): void { - const { value } = this - const node = Node.leaf(value, path) - const match = node.marks.find(m => Mark.matches(m, mark)) - - if (match == null) { - throw new Error( - `Cannot set new properties on mark ${JSON.stringify( - mark - )} at path [${path}] because the mark does not exist.` - ) - } - - const newProps = {} - - for (const k in props) { - if (props[k] !== match[k]) { - newProps[k] = props[k] - } - } - - // If no properties have changed don't apply an operation at all. - if (Object.keys(newProps).length !== 0) { - return - } - - this.apply({ - type: 'set_mark', - path, - properties: match, - newProperties: newProps, - }) - } - /** * Set new properties on the node at a path. */ @@ -570,21 +468,6 @@ class PathCommands { }) } - /** - * Toggle a mark on or off on the text node at a path. - */ - - toggleMarkAtPath(this: Editor, path: Path, mark: Mark): void { - const { value } = this - const node = Node.get(value, path) - - if (Mark.exists(mark, node.marks)) { - this.removeMarkAtPath(path, mark) - } else { - this.addMarkAtPath(path, mark) - } - } - /** * Wrap the node at a path in a new parent node. */ diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index 1dbaf33b23..072a424e1f 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -33,22 +33,6 @@ class PointCommands { } } - /** - * Insert a block node at a point. - */ - - insertBlockAtPoint(this: Editor, point: Point, block: Element): void { - this.withoutNormalizing(() => { - const pointRef = this.createPointRef(point) - this.splitBlockAtPoint(point, { always: false }) - - if (pointRef.current != null) { - this.insertNodeAtPath(pointRef.current.path, block) - pointRef.unref() - } - }) - } - /** * Insert a fragment of nodes at a point. */ @@ -100,46 +84,6 @@ class PointCommands { }) } - /** - * Insert a string of text at a specific point in the document. - */ - - insertTextAtPoint(this: Editor, point: Point, text: string): Point { - const { value } = this - const { annotations } = value - const { path, offset } = point - - this.withoutNormalizing(() => { - for (const key in annotations) { - const annotation = annotations[key] - - if (this.isAtomic(annotation)) { - const [start] = Range.points(annotation) - const [, end] = Range.points(annotation) - - if ( - start.offset < offset && - Path.equals(start.path, path) && - (!Path.equals(end.path, path) || offset < end.offset) - ) { - this.removeAnnotation(key) - } - } - } - - this.apply({ - type: 'insert_text', - path, - offset, - text, - }) - }) - - return produce(point, p => { - p.offset += text.length - }) - } - /** * Remove a string of text by length from a specific point in the document. */ @@ -269,7 +213,6 @@ class PointCommands { let position = offset let target: number | undefined let h = 0 - debugger // If the point it inside a void node, we still want to split up to a // `height`, but we need to start after the void node in the tree. @@ -300,7 +243,7 @@ class PointCommands { if ( !always && pointRef.current != null && - this.isAtEdge(pointRef.current, Path.parent(p)) + this.isAtEdge(pointRef.current, p) ) { continue } diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index 70ec1ee843..f2cca3565a 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -10,27 +10,6 @@ import { } from '../..' class RangeCommands { - /** - * Add a set of marks to all of the spans of text in a range, splitting the individual - * text nodes if the range intersects them. - */ - - addMarksAtRange(this: Editor, range: Range, marks: Mark[]): void { - this.withoutNormalizing(() => { - const rangeRef = this.createRangeRef(range, { stick: 'inward' }) - const [start, end] = Range.points(range) - this.splitNodeAtPoint(end, { always: false }) - this.splitNodeAtPoint(start, { always: false }) - range = rangeRef.unref()! - - for (const [, path] of this.texts({ range })) { - for (const mark of marks) { - this.addMarkAtPath(path, mark) - } - } - }) - } - /** * Delete the content in a range. */ @@ -66,16 +45,13 @@ class RangeCommands { endHeight = 0 } - debugger this.splitNodeAtPoint(end, { height: Math.max(0, endHeight) }) this.splitNodeAtPoint(start, { height: Math.max(0, startHeight) }) const startIndex = startRef.unref()!.path[commonPath.length] const endIndex = endRef.unref()!.path[commonPath.length] - debugger for (let i = endIndex; i >= startIndex; i--) { - debugger this.removeNodeAtPath(commonPath.concat(i)) } @@ -86,9 +62,7 @@ class RangeCommands { return } - debugger const ancestor = Node.get(this.value, commonPath) - debugger if ( (Value.isValue(ancestor) || Element.isElement(ancestor)) && @@ -99,24 +73,6 @@ class RangeCommands { }) } - /** - * Insert a block node at a range. - */ - - insertBlockAtRange(this: Editor, range: Range, block: Element): void { - this.withoutNormalizing(() => { - const [start] = Range.points(range) - const pointRef = this.createPointRef(start) - - if (Range.isExpanded(range)) { - this.deleteAtRange(range) - } - - this.insertBlockAtPoint(pointRef.current!, block) - pointRef.unref() - }) - } - /** * Insert a fragment of nodes at a range. */ @@ -153,38 +109,6 @@ class RangeCommands { }) } - /** - * Insert a string of text at a range. - */ - - insertTextAtRange(this: Editor, range: Range, text: string): void { - this.withoutNormalizing(() => { - const [start] = Range.points(range) - const pointRef = this.createPointRef(start) - - if (Range.isExpanded(range)) { - this.deleteAtRange(range) - } - - this.insertTextAtPoint(pointRef.current!, text) - pointRef.unref() - }) - } - - /** - * Remove a set of marks from all of the spans of text in a range. - */ - - removeMarksAtRange(this: Editor, range: Range, marks: Mark[]): void { - this.withoutNormalizing(() => { - for (const [, path] of this.texts({ range })) { - for (const mark of marks) { - this.removeMarkAtPath(path, mark) - } - } - }) - } - /** * Set new properties on all of the leaf blocks in a range. */ @@ -206,7 +130,7 @@ class RangeCommands { range = this.getNonHangingRange(range) } - for (const [, path] of this.leafBlocks({ range })) { + for (const [, path] of this.leafBlocks({ at: range })) { this.setNodeAtPath(path, props) } }) @@ -233,7 +157,7 @@ class RangeCommands { range = this.getNonHangingRange(range) } - for (const [, path] of this.leafInlines({ range })) { + for (const [, path] of this.leafInlines({ at: range })) { this.setNodeAtPath(path, props) } }) @@ -260,7 +184,7 @@ class RangeCommands { range = this.getNonHangingRange(range) } - for (const [, path] of this.rootBlocks({ range })) { + for (const [, path] of this.rootBlocks({ at: range })) { this.setNodeAtPath(path, props) } }) @@ -287,7 +211,7 @@ class RangeCommands { range = this.getNonHangingRange(range) } - for (const [, path] of this.rootInlines({ range })) { + for (const [, path] of this.rootInlines({ at: range })) { this.setNodeAtPath(path, props) } }) @@ -343,26 +267,6 @@ class RangeCommands { }) } - /** - * Toggle a mark on or off for all of the spans of text in a range. - */ - - toggleMarksAtRange(this: Editor, range: Range, marks: Mark[]): void { - this.withoutNormalizing(() => { - const rangeRef = this.createRangeRef(range, { stick: 'inward' }) - const [start, end] = Range.points(range) - this.splitNodeAtPoint(end, { always: false }) - this.splitNodeAtPoint(start, { always: false }) - range = rangeRef.unref()! - - for (const [, path] of this.texts({ range })) { - for (const mark of marks) { - this.toggleMarkAtPath(path, mark) - } - } - }) - } - /** * Unwrap the block nodes in a range that match a set of properties. */ @@ -370,7 +274,7 @@ class RangeCommands { unwrapBlockAtRange(this: Editor, range: Range, props: {}) { this.withoutNormalizing(() => { // Iterate in reverse to ensure unwrapping doesn't affect path lookups. - for (const [element, path] of this.blocks({ range, reverse: true })) { + for (const [element, path] of this.blocks({ at: range, reverse: true })) { if (Element.matches(element, props)) { this.pluckNodeAtPath(path) } @@ -385,7 +289,10 @@ class RangeCommands { unwrapInlineAtRange(this: Editor, range: Range, props: {}) { this.withoutNormalizing(() => { // Iterate in reverse to ensure unwrapping doesn't affect path lookups. - for (const [element, path] of this.inlines({ range, reverse: true })) { + for (const [element, path] of this.inlines({ + at: range, + reverse: true, + })) { if (Element.matches(element, props)) { this.pluckNodeAtPath(path) } @@ -437,7 +344,7 @@ class RangeCommands { range = rangeRef.current! const [start, end] = Range.points(range) - for (const [block, blockPath] of this.leafBlocks({ range })) { + for (const [block, blockPath] of this.leafBlocks({ at: range })) { const isStart = Path.isAncestor(blockPath, start.path) const isEnd = Path.isAncestor(blockPath, end.path) const startIndex = isStart ? start.path[blockPath.length] : 0 diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index 96c02a4496..ae161f80c8 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -14,29 +14,29 @@ class SelectionCommands { const { edge = 'anchor' } = options const { selection } = this.value - if (selection == null) { + if (!selection) { return } else if (edge === 'anchor') { - this.moveTo(selection.anchor) + this.select(selection.anchor) } else if (edge === 'focus') { - this.moveTo(selection.focus) + this.select(selection.focus) } else if (edge === 'start') { const [start] = Range.points(selection) - this.moveTo(start) + this.select(start) } else if (edge === 'end') { const [, end] = Range.points(selection) - this.moveTo(end) + this.select(end) } } /** - * Deselect the selection. + * Unset the selection. */ deselect(this: Editor) { const { selection } = this.value - if (selection != null) { + if (selection) { this.apply({ type: 'set_selection', properties: selection, @@ -46,22 +46,7 @@ class SelectionCommands { } /** - * Flip the selection's anchor and focus points. - */ - - flip(this: Editor) { - const { selection } = this.value - - if (selection != null) { - const { anchor, focus } = selection - this.setSelection({ anchor: focus, focus: anchor }) - } - } - - /** - * Move the selection. - * - * @param {Number} n + * Move the selection's point forward or backward. */ move( @@ -70,214 +55,133 @@ class SelectionCommands { distance?: number unit?: 'offset' | 'character' | 'word' | 'line' reverse?: boolean - } = {} - ) { - this.moveAnchor(options) - this.moveFocus(options) - } - - /** - * Move the selection's anchor point. - * - * @param {Number} n - */ - - moveAnchor( - this: Editor, - options: { - distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' - reverse?: boolean + edge?: 'anchor' | 'focus' | 'start' | 'end' } = {} ) { const { selection } = this.value + const { distance = 1, unit = 'character', reverse = false } = options + let { edge = null } = options - if (selection == null) { + if (!selection) { return } - const { anchor } = selection - const { reverse = false, ...rest } = options - const point = reverse - ? this.getPreviousPoint(anchor, rest) - : this.getNextPoint(anchor, rest) + if (edge === 'start') { + edge = Range.isBackward(selection) ? 'focus' : 'anchor' + } - if (point) { - this.moveAnchorTo(point) + if (edge === 'end') { + edge = Range.isBackward(selection) ? 'anchor' : 'focus' } - } - /** - * Move the selection's anchor point to a new point. - */ + const { anchor, focus } = selection + const opts = { distance, unit } + const props: Partial = {} - moveAnchorTo(this: Editor, point: Point) { - this.setSelection({ anchor: point }) - } + if (edge == null || edge === 'anchor') { + const point = reverse + ? this.getPreviousPoint(anchor, opts) + : this.getNextPoint(anchor, opts) - /** - * Move the selection's end point. - */ + if (point) { + props.anchor = point + } + } - moveEnd( - this: Editor, - options: { - distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' - allowZeroWidth?: boolean - } = {} - ) { - const { selection } = this.value + if (edge == null || edge === 'focus') { + const point = reverse + ? this.getPreviousPoint(focus, opts) + : this.getNextPoint(focus, opts) - if (selection == null) { - return - } else if (Range.isForward(selection)) { - this.moveFocus(options) - } else { - this.moveAnchor(options) + if (point) { + props.focus = point + } } + + this.setSelection(props) } /** - * Move the selection's end point to a new point. + * Set the selection to a new value. */ - moveEndTo(this: Editor, point: Point) { + select(this: Editor, target: Point | Range | Partial) { const { selection } = this.value - if (selection == null) { - return - } else if (Range.isForward(selection)) { - this.moveFocusTo(point) - } else { - this.moveAnchorTo(point) + if (Point.isPoint(target)) { + target = { + anchor: target, + focus: target, + } } - } - - /** - * Move the selection's focus point. - * - * @param {Number} n - */ - - moveFocus( - this: Editor, - options: { - distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' - reverse?: boolean - } = {} - ) { - const { selection } = this.value - if (selection == null) { + if (selection) { + this.setSelection(target) return } - const { focus } = selection - const { reverse = false, ...rest } = options - const point = reverse - ? this.getPreviousPoint(focus, rest) - : this.getNextPoint(focus, rest) - - if (point) { - this.moveFocusTo(point) + if (!Range.isRange(target)) { + throw new Error( + `When setting the selection and the current selection is \`null\` you must provide at least an \`anchor\` and \`focus\`, but you passed: ${JSON.stringify( + target + )}` + ) } - } - /** - * Move the selection's focus point to a new point. - */ - - moveFocusTo(this: Editor, point: Point) { - this.setSelection({ focus: point }) + this.apply({ + type: 'set_selection', + properties: selection, + newProperties: target, + }) } /** - * Move the selection's start point. + * Set new properties on one of the selection's points. */ - moveStart( + setPoint( this: Editor, + props: Partial, options: { - distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' - reverse?: boolean - } = {} + edge?: 'anchor' | 'focus' | 'start' | 'end' + } ) { const { selection } = this.value + let { edge = 'both' } = options - if (selection == null) { + if (!selection) { return - } else if (Range.isForward(selection)) { - this.moveAnchor(options) - } else { - this.moveFocus(options) } - } - /** - * Move the selection's start point to a new point. - */ - - moveStartTo(this: Editor, point: Point) { - const { selection } = this.value - - if (selection == null) { - return - } else if (Range.isForward(selection)) { - this.moveAnchorTo(point) - } else { - this.moveFocusTo(point) + if (edge === 'start') { + edge = Range.isBackward(selection) ? 'focus' : 'anchor' } - } - - /** - * Move the cursor to a specific point. - */ - moveTo(this: Editor, point: Point) { - this.setSelection({ anchor: point, focus: point }) - } - - /** - * Set the selection to a new value. - */ - - select(this: Editor, props: Partial) { - const { selection } = this.value - - if (selection != null) { - this.setSelection(props) - return + if (edge === 'end') { + edge = Range.isBackward(selection) ? 'anchor' : 'focus' } - if (!Range.isRange(props)) { - throw new Error( - `When setting the selection and the current selection is \`null\` you must provide at least an \`anchor\` and \`focus\`, but you passed: ${JSON.stringify( - props - )}` - ) - } + const { anchor, focus } = selection + const point = edge === 'anchor' ? anchor : focus + const newPoint = Object.assign(point, props) - this.apply({ - type: 'set_selection', - properties: selection, - newProperties: props, - }) + if (edge === 'anchor') { + this.setSelection({ anchor: newPoint }) + } else { + this.setSelection({ focus: newPoint }) + } } /** - * Set new props on the selection. + * Set new properties on the selection. */ setSelection(this: Editor, props: Partial) { const { selection } = this.value - let oldProps: Partial | null = {} - let newProps: Partial = {} + const oldProps: Partial | null = {} + const newProps: Partial = {} - if (selection == null) { - this.select(props) + if (!selection) { return } diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts index 1327755fde..0511945c66 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/value.ts @@ -9,6 +9,7 @@ import { Path, Text, Range, + Point, Value, } from '../..' import { @@ -20,20 +21,63 @@ import { NORMALIZING, } from '../../symbols' -// Properties that are restricted, and that can't be set directly on a `Value`. -const RESTRICTED_PROPERTIES = ['annotations', 'history', 'nodes', 'selection'] - class ValueCommands { /** - * Add a set of marks to the span of text that is currently selected. + * Add a set of marks at a location. You can add them to the content of + * specific node at a path, or to all of the text content in a range. */ - addMarks(this: Editor, marks: Mark[]): void { - const { selection } = this.value + addMarks( + this: Editor, + marks: Mark[], + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false - if (selection != null) { - this.addMarksAtRange(selection, marks) - } + if (!at && selection) { + at = selection + isSelection = true + } + + if (Path.isPath(at)) { + at = this.getRange(at) + } + + if (Range.isRange(at)) { + // Split the text nodes at the range's edges if necessary. + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + this.splitNodeAtPoint(end, { always: false }) + this.splitNodeAtPoint(start, { always: false }) + at = rangeRef.unref()! + + // De-dupe the marks being added to ensure the set is unique. + const set: Mark[] = [] + + for (const mark of marks) { + if (!Mark.exists(mark, set)) { + set.push(mark) + } + } + + for (const [node, path] of this.texts({ at })) { + for (const mark of set) { + if (!Mark.exists(mark, node.marks)) { + this.apply({ type: 'add_mark', path, mark }) + } + } + } + + if (isSelection) { + this.select(at) + } + } + }) } /** @@ -97,22 +141,103 @@ class ValueCommands { delete( this: Editor, options: { - amount?: number - unit?: 'offset' | 'character' | 'word' | 'line' + at?: Path | Point | Range + distance?: number + unit?: 'character' | 'word' | 'line' | 'block' reverse?: boolean } = {} ) { - const { selection } = this.value + this.withoutNormalizing(() => { + const { selection } = this.value + const { reverse = false, unit = 'character', distance = 1 } = options + let { at } = options + let isSelection = false + let ancestorPath: Path = [] + let ancestor: Node = this.value + + if (!at && selection) { + at = selection + isSelection = true + } - if (selection == null) { - return - } + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } - this.deleteAtRange(selection, options) - // After deleting, the selection can end up still expanded across a - // zero-width offset if it had one edge in an inline node. So to ensure that - // it's always collapsed after deleting, we collapse it to the end point. - this.collapse({ edge: 'end' }) + if (Point.isPoint(at)) { + const furthestVoid = this.getFurthestVoid(at.path) + + if (furthestVoid) { + const [, voidPath] = furthestVoid + at = voidPath + } else { + const opts = { unit, distance } + const target = reverse + ? this.getPreviousPoint(at, opts) + : this.getNextPoint(at, opts) + + if (target) { + at = { anchor: at, focus: target } + } + } + } + + if (Range.isRange(at)) { + const [start, end] = Range.points(at) + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [common, commonPath] = this.getCommon(start.path, end.path) + let startHeight = start.path.length - commonPath.length - 1 + let endHeight = end.path.length - commonPath.length - 1 + + if (Path.equals(start.path, end.path)) { + ancestorPath = Path.parent(commonPath) + ancestor = Node.get(this.value, ancestorPath) + startHeight = 0 + endHeight = 0 + } else { + ancestorPath = commonPath + ancestor = common + } + + this.splitNodeAtPoint(end, { height: Math.max(0, endHeight) }) + this.splitNodeAtPoint(start, { height: Math.max(0, startHeight) }) + at = rangeRef.unref()! + } + + if (Path.isPath(at)) { + const node = Node.get(this.value, at) + this.apply({ type: 'remove_node', path: at, node }) + } + + if (Range.isRange(at)) { + const [start, end] = Range.points(at) + const after = this.getNextPoint(end)! + const afterRef = this.createPointRef(after) + const l = ancestorPath.length + const startIndex = start.path[l] + const endIndex = end.path[l] + const hasBlocks = + Value.isValue(ancestor) || + (Element.isElement(ancestor) && this.hasBlocks(ancestor)) + + // Iterate backwards so the paths are unaffected. + for (let i = endIndex; i >= startIndex; i--) { + const path = ancestorPath.concat(i) + const node = Node.get(this.value, path) + this.apply({ type: 'remove_node', path, node }) + } + + if (hasBlocks) { + this.mergeBlockAtPath(afterRef.current!.path) + } + + if (isSelection) { + this.select(afterRef.current!) + } + + afterRef.unref() + } + }) } /** @@ -134,18 +259,55 @@ class ValueCommands { * Insert a block node at the cursor. */ - insertBlock(this: Editor, block: Element) { - const { selection } = this.value + insertBlock( + this: Editor, + block: Element, + options: { + at?: Path | Point | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false + let isAtEnd = false - if (selection == null) { - return - } + if (!at && selection) { + at = selection + isSelection = true + } - const [start] = Range.points(selection) - const pointRef = this.createPointRef(start) - this.insertBlockAtRange(selection, block) - this.moveTo(pointRef.current!) - pointRef.unref() + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (Point.isPoint(at)) { + const [, blockPath] = this.getClosestBlock(at.path)! + isAtEnd = this.isAtEnd(at, blockPath) + const pointRef = this.createPointRef(at) + this.splitBlockAtPoint(at, { always: false }) + const point = pointRef.unref()! + at = point.path + } + + if (Path.isPath(at)) { + const [, blockPath] = this.getClosestBlock(at)! + const path = isAtEnd ? Path.next(blockPath) : blockPath + this.insertNodeAtPath(path, block) + + if (isSelection) { + const point = this.getStart(path)! + this.select(point) + } + } + }) } /** @@ -162,7 +324,7 @@ class ValueCommands { const [start] = Range.points(selection) const pointRef = this.createPointRef(start) this.insertFragmentAtRange(selection, fragment) - this.moveTo(pointRef.current!) + this.select(pointRef.current!) pointRef.unref() } @@ -180,7 +342,7 @@ class ValueCommands { const [start] = Range.points(selection) const pointRef = this.createPointRef(start) this.insertInlineAtRange(selection, inline) - this.moveTo(pointRef.current!) + this.select(pointRef.current!) pointRef.unref() } @@ -188,23 +350,43 @@ class ValueCommands { * Insert a string of text at the current selection. */ - insertText(this: Editor, text: string) { - const { selection } = this.value + insertText( + this: Editor, + text: string, + options: { + at?: Point | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options - if (selection == null) { - return - } + if (!at && selection) { + at = selection + } - const [start] = Range.points(selection) - const pointRef = this.createPointRef(start) - this.insertTextAtRange(selection, text) - const end = pointRef.unref()! - this.moveTo(end) + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } - if (selection.marks) { - const range = { anchor: start, focus: end } - this.addMarksAtRange(range, selection.marks) - } + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (Point.isPoint(at) && !this.getFurthestVoid(at.path)) { + for (const [annotation, key] of this.annotations({ at })) { + if (this.isAtomic(annotation)) { + this.removeAnnotation(key) + } + } + + const { path, offset } = at + this.apply({ type: 'insert_text', path, offset, text }) + } + }) } /** @@ -251,26 +433,44 @@ class ValueCommands { }) } - /** - * Remove a set of marks from all of the spans of text in the current selection. - */ + removeMarks( + this: Editor, + marks: Mark[], + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false - removeMarks(this: Editor, marks: Mark[]): void { - const { selection } = this.value + if (!at && selection) { + at = selection + isSelection = true + } - if (selection != null) { - this.removeMarksAtRange(selection, marks) - } - } + if (Path.isPath(at)) { + at = this.getRange(at) + } - /** - * Replace a mark on all of the spans of text in the selection with a new one. - */ + if (Range.isRange(at)) { + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + this.splitNodeAtPoint(end, { always: false }) + this.splitNodeAtPoint(start, { always: false }) + at = rangeRef.unref()! + + for (const [mark, i, node, path] of this.marks({ at })) { + if (Mark.exists(mark, marks)) { + this.apply({ type: 'remove_mark', path, mark }) + } + } - replaceMarks(this: Editor, oldMarks: Mark[], newMarks: Mark[]): void { - this.withoutNormalizing(() => { - this.removeMarks(oldMarks) - this.addMarks(newMarks) + if (isSelection) { + this.select(at) + } + } }) } @@ -334,29 +534,25 @@ class ValueCommands { * Set new properties on the top-level `Value` object. */ - setValue(this: Editor, props: {}) { + setValue(this: Editor, props: Partial) { const { value } = this const newProps = {} const oldProps = {} - let isChange = false // Dedupe new and old properties to avoid unnecessary sets. for (const k in props) { - if (RESTRICTED_PROPERTIES.includes(k)) { - throw new Error( - `Cannot set the restricted property "${k}" on a value. You must use one of the purpose-built editor methods instead.` - ) + if (k === 'annotations' || k === 'nodes' || k === 'selection') { + continue } if (props[k] !== value[k]) { - isChange = true newProps[k] = props[k] oldProps[k] = value[k] } } // PERF: If no properties have changed don't apply an operation at all. - if (!isChange) { + if (Object.keys(newProps).length === 0) { return } @@ -367,6 +563,77 @@ class ValueCommands { }) } + /** + * Set new properties on a set of marks. + */ + + setMarks( + this: Editor, + marks: Mark[], + props: Partial, + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false + + if (!at && selection) { + at = selection + isSelection = true + } + + // PERF: Do this before the path coercion logic since we're guaranteed not + // to need to split in that case. + if (Range.isRange(at)) { + // Split the text nodes at the range's edges if necessary. + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + this.splitNodeAtPoint(end, { always: false }) + this.splitNodeAtPoint(start, { always: false }) + at = rangeRef.unref()! + } + + if (Path.isPath(at)) { + at = this.getRange(at) + } + + if (Range.isRange(at)) { + for (const [mark, i, node, path] of this.marks({ at })) { + if (!Mark.exists(mark, marks)) { + continue + } + + const newProps = {} + + for (const k in props) { + if (props[k] !== mark[k]) { + newProps[k] = props[k] + } + } + + // If no properties have changed don't apply an operation at all. + if (Object.keys(newProps).length === 0) { + continue + } + + this.apply({ + type: 'set_mark', + path, + properties: mark, + newProperties: newProps, + }) + } + + if (isSelection) { + this.select(at) + } + } + }) + } + /** * Split the block at the cursor, up to a height. */ @@ -388,7 +655,7 @@ class ValueCommands { const [, end] = Range.points(selection) const pointRef = this.createPointRef(end) this.splitBlockAtRange(selection, options) - this.moveTo(pointRef.current!) + this.select(pointRef.current!) pointRef.unref() }) } @@ -414,7 +681,7 @@ class ValueCommands { const [, end] = Range.points(selection) const pointRef = this.createPointRef(end) this.splitInlineAtRange(selection, options) - this.moveTo(pointRef.current!) + this.select(pointRef.current!) pointRef.unref() }) } @@ -423,12 +690,24 @@ class ValueCommands { * Toggle a mark on or off for all the spans of text in the selection. */ - toggleMarks(this: Editor, marks: Mark[]): void { - const { selection } = this.value - - if (selection != null) { - this.toggleMarksAtRange(selection, marks) - } + toggleMarks( + this: Editor, + marks: Mark[], + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { at } = options + const existing = this.getActiveMarks({ at }) + const exists = marks.every(m => Mark.exists(m, existing)) + + if (exists) { + this.removeMarks(marks, { at }) + } else { + this.addMarks(marks, { at }) + } + }) } /** diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index cac289c461..77b03f4910 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -1,9 +1,10 @@ -import { produce } from 'immer' import { + Ancestor, Editor, Element, ElementEntry, Node, + NodeEntry, Point, Path, PathRef, @@ -14,6 +15,18 @@ import { import { PATH_REFS } from '../../symbols' class PathQueries { + getCommon(this: Editor, path: Path, another: Path): NodeEntry { + return Node.common(this.value, path, another) + } + + getLeaf(this: Editor, path: Path): Text { + return Node.leaf(this.value, path) + } + + getNode(this: Editor, path: Path): Node { + return Node.get(this.value, path) + } + /** * Create a mutable ref for a `Path` object, which will stay in sync as new * operations are applied to the this. @@ -90,7 +103,7 @@ class PathQueries { */ getFirstText(this: Editor, path: Path): TextEntry | undefined { - const [first] = this.texts({ path }) + const [first] = this.texts({ at: path }) return first } @@ -135,7 +148,7 @@ class PathQueries { */ getLastText(this: Editor, path: Path): TextEntry | undefined { - const [last] = this.texts({ path, reverse: true }) + const [last] = this.texts({ at: path, reverse: true }) return last } @@ -144,7 +157,7 @@ class PathQueries { */ getNextLeafBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafBlocks({ path })) { + for (const [n, p] of this.leafBlocks({ at: path })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -156,7 +169,7 @@ class PathQueries { */ getNextLeafInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafInlines({ path })) { + for (const [n, p] of this.leafInlines({ at: path })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -168,7 +181,7 @@ class PathQueries { */ getNextRootBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootBlocks({ path })) { + for (const [n, p] of this.rootBlocks({ at: path })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -180,7 +193,7 @@ class PathQueries { */ getNextRootInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootInlines({ path })) { + for (const [n, p] of this.rootInlines({ at: path })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -192,7 +205,7 @@ class PathQueries { */ getNextText(this: Editor, path: Path): TextEntry | undefined { - const [, next] = this.texts({ path }) + const [, next] = this.texts({ at: path }) return next } @@ -245,7 +258,7 @@ class PathQueries { */ getPreviousLeafBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafBlocks({ path, reverse: true })) { + for (const [n, p] of this.leafBlocks({ at: path, reverse: true })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -257,7 +270,7 @@ class PathQueries { */ getPreviousLeafInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafInlines({ path, reverse: true })) { + for (const [n, p] of this.leafInlines({ at: path, reverse: true })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -269,7 +282,7 @@ class PathQueries { */ getPreviousRootBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootBlocks({ path, reverse: true })) { + for (const [n, p] of this.rootBlocks({ at: path, reverse: true })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -281,7 +294,7 @@ class PathQueries { */ getPreviousRootInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootInlines({ path, reverse: true })) { + for (const [n, p] of this.rootInlines({ at: path, reverse: true })) { if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { return [n, p] } @@ -293,7 +306,7 @@ class PathQueries { */ getPreviousText(this: Editor, path: Path): TextEntry | undefined { - const [, prev] = this.texts({ path, reverse: true }) + const [, prev] = this.texts({ at: path, reverse: true }) return prev } diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index 582e0c3d09..2de6a94e5d 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -39,7 +39,7 @@ class PointQueries { let d = 0 let target - for (const p of this.positions({ ...options, point })) { + for (const p of this.positions({ ...options, at: point })) { if (d > distance) { break } @@ -70,8 +70,7 @@ class PointQueries { let d = 0 let target - debugger - for (const p of this.positions({ ...options, point, reverse: true })) { + for (const p of this.positions({ ...options, at: point, reverse: true })) { if (d > distance) { break } diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts index e55aed9c17..aaa24ba8e0 100644 --- a/packages/slate/src/classes/queries/range.ts +++ b/packages/slate/src/classes/queries/range.ts @@ -53,7 +53,7 @@ class RangeQueries { } /** - * Get a range, ensuring that it is not hanging into an inline node. + * Get a range, ensuring that it is not hanging into an inline or text node. * * @param {Range} range * @return {Range} @@ -113,7 +113,7 @@ class RangeQueries { } /** - * Check whether a range is hanging in an inline. + * Check whether a range is hanging in an inline or text node. */ isInlineHanging(this: Editor, range: Range): boolean { @@ -124,12 +124,12 @@ class RangeQueries { const [, end] = Range.points(range) const closestInline = this.getClosestInline(end.path) - if (!closestInline) { - return false + if (closestInline) { + const [, endInlinePath] = closestInline + return this.isAtStart(end, endInlinePath) + } else { + return end.offset === 0 } - - const [, endInlinePath] = closestInline - return this.isAtStart(end, endInlinePath) } /** diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 7b176c7927..b9458b1ca7 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -1,5 +1,6 @@ import { reverse as reverseText } from 'esrever' import { + AnnotationEntry, Editor, Element, ElementEntry, @@ -16,6 +17,38 @@ import { } from '../..' class ValueQueries { + /** + * Iterate through all of the annotations in the editor. + */ + + *annotations( + this: Editor, + options: { + at?: Path | Point | Range + } = {} + ): Iterable { + const { annotations } = this.value + let { at } = options + + if (Path.isPath(at)) { + at = this.getRange(at) + } + + if (Point.isPoint(at)) { + at = { anchor: at, focus: at } + } + + for (const key in annotations) { + const annotation = annotations[key] + + if (at && !Range.includes(at, annotation)) { + continue + } + + yield [annotation, key] + } + } + /** * Iterate through all of the block nodes in the editor. */ @@ -23,8 +56,7 @@ class ValueQueries { *blocks( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { @@ -42,8 +74,7 @@ class ValueQueries { *entries( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { @@ -54,7 +85,7 @@ class ValueQueries { } /** - * Get the marks that are "active" in the current selection. These are the + * Get the marks that are "active" at a location. These are the * marks that will be added to any text that is inserted. * * The `union: true` option can be passed to create a union of marks across @@ -65,87 +96,102 @@ class ValueQueries { * the start of a text node and there are previous text nodes in the same * block, it will carry those marks forward from the previous text node. This * allows for continuation of marks from previous words. - * - * Note: when `selection.marks` is not null, it is always returned. */ - getActiveMarks(this: Editor, options: { union?: boolean } = {}): Mark[] { - const { union = false } = options + getActiveMarks( + this: Editor, + options: { + at?: Path | Point | Range + union?: boolean + } = {} + ): Mark[] { const { value } = this - const { selection } = value + const { selection } = this.value + let { at, union = false } = options + let isSelection = false - if (selection == null) { - return [] + if (!at && selection) { + at = selection + isSelection = true } - // If the selection has explicitly defined marks, those override everything. - if (selection.marks != null) { - return selection.marks + if (Path.isPath(at)) { + at = this.getRange(at) } - let range: Range = selection - let result: Mark[] = [] - let first = true - const { anchor } = range - - // If the range is collapsed at the start of a text node, it should carry - // over the marks from the previous text node in the same block. - if ( - Range.isCollapsed(range) && - // PERF: If the offset isn't zero we know it's not at the start. - anchor.offset === 0 && - // PERF: If it's the first sibling, we know it can't carry over. - anchor.path[anchor.path.length - 1] !== 0 - ) { - const prevPath = Path.previous(anchor.path) - const prevNode = Node.get(value, prevPath) - - if (Text.isText(prevNode)) { - range = this.getRange(prevPath) - } + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor } - for (const [node] of this.texts({ range })) { - const { marks } = node + if (Point.isPoint(at)) { + let { path, offset } = at - if (first) { - result = marks - first = false - continue - } + // If the range is collapsed at the start of a text node, it should carry + // over the marks from the previous text node in the same block. + if (offset === 0 && path[path.length - 1] !== 0) { + const prevPath = Path.previous(path) + const prevNode = Node.get(value, prevPath) - // PERF: If we're doing an intersection and the result hits zero it can - // never increase again, so we can exit early. - if (!union && result.length === 0) { - break + if (Text.isText(prevNode)) { + path = prevPath + } } - if (union) { - for (const mark of marks) { - if (!Mark.exists(mark, result)) { - result.push(mark) - } + at = this.getRange(path) + } + + const marks: Mark[] = [] + let first = true + + if (Range.isRange(at)) { + at = this.getNonHangingRange(at) + + for (const [node] of this.texts({ at })) { + if (first) { + marks.push(...node.marks) + first = false + continue } - } else { - // Iterate backwards so that removing marks doesn't impact indexing. - for (let i = result.length - 1; i >= 0; i--) { - const existing = result[i] - if (!Mark.exists(existing, marks)) { - result.splice(i, 1) + if (union) { + for (const mark of node.marks) { + if (!Mark.exists(mark, marks)) { + marks.push(mark) + } + } + } else { + // PERF: If we're doing an intersection and the result hits zero it can + // never increase again, so we can exit early. + if (marks.length === 0) { + break + } + + // Iterate backwards so that removing marks doesn't impact indexing. + for (let i = marks.length - 1; i >= 0; i--) { + const existing = marks[i] + + if (!Mark.exists(existing, node.marks)) { + marks.splice(i, 1) + } } } } } - return result + return marks } /** * Iterate through all of the inline nodes in the editor. */ - *inlines(this: Editor, options: {} = {}): Iterable { + *inlines( + this: Editor, + options: { + at?: Path | Range + reverse?: boolean + } = {} + ): Iterable { const iterable = Node.elements(this.value, { ...options, pass: ([n]) => Element.isElement(n) && this.isVoid(n), @@ -165,8 +211,7 @@ class ValueQueries { *marks( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { @@ -183,8 +228,7 @@ class ValueQueries { *leafBlocks( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { @@ -202,8 +246,7 @@ class ValueQueries { *leafInlines( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { @@ -229,7 +272,7 @@ class ValueQueries { *positions( this: Editor, options: { - point?: Point + at?: Point unit?: 'offset' | 'character' | 'word' | 'line' | 'block' reverse?: boolean } = {} @@ -237,10 +280,10 @@ class ValueQueries { const { unit = 'offset', reverse = false, - point = reverse ? this.getEnd([]) : this.getStart([]), + at = reverse ? this.getEnd([]) : this.getStart([]), } = options - if (point == null) { + if (at == null) { return } @@ -275,7 +318,7 @@ class ValueQueries { } for (const [node, path] of this.entries({ - path: point.path, + at: at.path, reverse, })) { if (Element.isElement(node)) { @@ -295,9 +338,9 @@ class ValueQueries { if (!this.isInline(node) && this.hasInlines(node)) { let text = this.getText(path) - if (Path.isAncestor(path, point.path)) { - const before = this.getOffset(point.path, { depth: path.length }) - const o = before + point.offset + if (Path.isAncestor(path, at.path)) { + const before = this.getOffset(at.path, { depth: path.length }) + const o = before + at.offset text = reverse ? text.slice(0, o) : text.slice(o) } @@ -307,13 +350,13 @@ class ValueQueries { } if (Text.isText(node)) { - const isStart = Path.equals(path, point.path) + const isStart = Path.equals(path, at.path) available = node.text.length offset = reverse ? available : 0 if (isStart) { - available = reverse ? point.offset : available - point.offset - offset = point.offset + available = reverse ? at.offset : available - at.offset + offset = at.offset } if (isStart || isBlockStart || unit === 'offset') { @@ -349,8 +392,7 @@ class ValueQueries { *rootBlocks( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { @@ -368,8 +410,7 @@ class ValueQueries { *rootInlines( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { @@ -389,8 +430,7 @@ class ValueQueries { *texts( this: Editor, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean } = {} ): Iterable { diff --git a/packages/slate/src/index.ts b/packages/slate/src/index.ts index 105fd44bfc..ea389cbd99 100755 --- a/packages/slate/src/index.ts +++ b/packages/slate/src/index.ts @@ -3,7 +3,11 @@ export { PathRef } from './classes/path-ref' export { PointRef } from './classes/point-ref' export { RangeRef } from './classes/range-ref' -export { Annotation, AnnotationPointEntry } from './interfaces/annotation' +export { + Annotation, + AnnotationEntry, + AnnotationPointEntry, +} from './interfaces/annotation' export * from './interfaces/change' export * from './interfaces/element' export * from './interfaces/fragment' diff --git a/packages/slate/src/interfaces/annotation.ts b/packages/slate/src/interfaces/annotation.ts index 46669d9971..59ec2f1ae2 100755 --- a/packages/slate/src/interfaces/annotation.ts +++ b/packages/slate/src/interfaces/annotation.ts @@ -10,6 +10,13 @@ import { Mark, Point, PointKey, Range } from '..' interface Annotation extends Mark, Range {} +/** + * `AnnotationEntry` objects are returned when iterating over `Annotation` + * objects in the top-level value. + */ + +type AnnotationEntry = [Annotation, string] + /** * `AnnotationPointEntry` objects are returned when iterating over `Point` * objects that belong to an `Annotation`. @@ -45,4 +52,4 @@ namespace Annotation { } } -export { Annotation, AnnotationPointEntry } +export { Annotation, AnnotationEntry, AnnotationPointEntry } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 8a2de6afa0..79a14790a3 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -134,6 +134,16 @@ namespace Node { } } + /** + * Get an entry for the common ancesetor node of two paths. + */ + + export const common = (root: Node, path: Path, another: Path): NodeEntry => { + const p = Path.common(path, another) + const n = Node.get(root, p) + return [n, p] + } + /** * Get the node at a specific path, asserting that it's a descendant node. */ @@ -157,8 +167,7 @@ namespace Node { export function* descendants( root: Node, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -181,8 +190,7 @@ namespace Node { export function* elements( root: Node, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -203,22 +211,21 @@ namespace Node { export function* entries( root: Node, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean pass?: (entry: NodeEntry) => boolean } = {} ): Iterable { - const { path = [], range, reverse = false, pass = () => false } = options + const { at = [], reverse = false, pass = () => false } = options let fromPath let toPath - if (range != null) { - const [s, e] = Range.points(range) + if (Range.isRange(at)) { + const [s, e] = Range.points(at) fromPath = reverse ? e.path : s.path toPath = reverse ? s.path : e.path } else { - const [, f] = reverse ? Node.last(root, path) : Node.first(root, path) + const [, f] = reverse ? Node.last(root, at) : Node.first(root, at) fromPath = f toPath = null } @@ -485,8 +492,7 @@ namespace Node { export function* marks( root: Node, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -569,8 +575,7 @@ namespace Node { export function* texts( root: Node, options: { - path?: Path - range?: Range + at?: Path | Range reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index 2442cc000d..2ae88a3bb0 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -27,23 +27,33 @@ namespace Range { } /** - * Check if a range includes a path or a point. + * Check if a range includes a path, a point or part of another range. */ - export const includes = (range: Range, target: Path | Point): boolean => { + export const includes = ( + range: Range, + target: Path | Point | Range + ): boolean => { + if (Range.isRange(target)) { + return ( + Range.includes(range, target.anchor) || + Range.includes(range, target.focus) + ) + } + const [start, end] = Range.points(range) + let isAfterStart = false + let isBeforeEnd = false if (Point.isPoint(target)) { - return ( - (Point.equals(target, start) || Point.isAfter(target, start)) && - (Point.equals(target, end) || Point.isBefore(target, end)) - ) + isAfterStart = Point.compare(target, start) >= 0 + isBeforeEnd = Point.compare(target, end) <= 0 } else { - return ( - (Path.equals(target, start.path) || Path.isAfter(target, start.path)) && - (Path.equals(target, end.path) || Path.isBefore(target, end.path)) - ) + isAfterStart = Path.compare(target, start.path) >= 0 + isBeforeEnd = Path.compare(target, end.path) <= 0 } + + return isAfterStart && isBeforeEnd } /** diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 0991a22bc1..3593cd1645 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -147,7 +147,6 @@ namespace Value { parent.nodes.splice(index, 1) for (const [point, key, range] of Value.points(v)) { - debugger range[key] = Point.transform(point, op)! } @@ -212,8 +211,8 @@ namespace Value { const parent = Node.parent(v, path) const [, first] = Node.first(v, path) const [, last] = Node.last(v, path) - const [, prev] = Node.texts(v, { path: first, reverse: true }) - const [, next] = Node.texts(v, { path: last }) + const [, prev] = Node.texts(v, { at: first, reverse: true }) + const [, next] = Node.texts(v, { at: last }) parent.nodes.splice(index, 1) // Transform all of the points in the value, but if the point was in the diff --git a/packages/slate/test/commands/selection/focus/basic.js b/packages/slate/test/commands/addMarks/path/basic.js similarity index 66% rename from packages/slate/test/commands/selection/focus/basic.js rename to packages/slate/test/commands/addMarks/path/basic.js index 7823baff5a..f423b03018 100644 --- a/packages/slate/test/commands/selection/focus/basic.js +++ b/packages/slate/test/commands/addMarks/path/basic.js @@ -3,21 +3,19 @@ import { h } from '../../../helpers' export const run = editor => { - editor.focus() + editor.addMarks([{ key: 'a' }], { at: [0, 0] }) } export const input = ( - - one - + word ) export const output = ( - one + word ) diff --git a/packages/slate/test/commands/addMarks/range/basic.js b/packages/slate/test/commands/addMarks/range/basic.js new file mode 100644 index 0000000000..a2d863d629 --- /dev/null +++ b/packages/slate/test/commands/addMarks/range/basic.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.addMarks([{ key: 'a' }], { + at: { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 3 }, + }, + }) +} + +export const input = ( + + word + +) + +export const output = ( + + + w + or + d + + +) diff --git a/packages/slate/test/commands/value/addMarks/block-across-edge-existing.js b/packages/slate/test/commands/addMarks/selection/block-across-edge-existing.js similarity index 95% rename from packages/slate/test/commands/value/addMarks/block-across-edge-existing.js rename to packages/slate/test/commands/addMarks/selection/block-across-edge-existing.js index 96a0f4ce5a..093566b9c7 100644 --- a/packages/slate/test/commands/value/addMarks/block-across-edge-existing.js +++ b/packages/slate/test/commands/addMarks/selection/block-across-edge-existing.js @@ -9,7 +9,8 @@ export const run = editor => { export const input = ( - wo + wo + rd diff --git a/packages/slate/test/commands/value/addMarks/block-across-existing.js b/packages/slate/test/commands/addMarks/selection/block-across-existing.js similarity index 86% rename from packages/slate/test/commands/value/addMarks/block-across-existing.js rename to packages/slate/test/commands/addMarks/selection/block-across-existing.js index 0d576e249a..3d16dfcd7a 100644 --- a/packages/slate/test/commands/value/addMarks/block-across-existing.js +++ b/packages/slate/test/commands/addMarks/selection/block-across-existing.js @@ -33,11 +33,11 @@ export const output = ( - an - - - other + + an + + other ) diff --git a/packages/slate/test/commands/value/addMarks/block-across.js b/packages/slate/test/commands/addMarks/selection/block-across.js similarity index 84% rename from packages/slate/test/commands/value/addMarks/block-across.js rename to packages/slate/test/commands/addMarks/selection/block-across.js index f7e9d4c762..b4ff283d4e 100644 --- a/packages/slate/test/commands/value/addMarks/block-across.js +++ b/packages/slate/test/commands/addMarks/selection/block-across.js @@ -26,10 +26,10 @@ export const output = ( - an - - other - + + an + + other ) diff --git a/packages/slate/test/commands/value/addMarks/existing.js b/packages/slate/test/commands/addMarks/selection/existing.js similarity index 83% rename from packages/slate/test/commands/value/addMarks/existing.js rename to packages/slate/test/commands/addMarks/selection/existing.js index e818fa2f2f..65a46e3977 100644 --- a/packages/slate/test/commands/value/addMarks/existing.js +++ b/packages/slate/test/commands/addMarks/selection/existing.js @@ -21,12 +21,10 @@ export const output = ( - wo + wo - - rd - + rd ) diff --git a/packages/slate/test/commands/value/addMarks/first-character.js b/packages/slate/test/commands/addMarks/selection/first-character.js similarity index 82% rename from packages/slate/test/commands/value/addMarks/first-character.js rename to packages/slate/test/commands/addMarks/selection/first-character.js index 5c80224d4c..bd6fca8e78 100644 --- a/packages/slate/test/commands/value/addMarks/first-character.js +++ b/packages/slate/test/commands/addMarks/selection/first-character.js @@ -18,11 +18,9 @@ export const output = ( - w + w - - ord - + ord ) diff --git a/packages/slate/test/commands/value/addMarks/inline-across.js b/packages/slate/test/commands/addMarks/selection/inline-across.js similarity index 88% rename from packages/slate/test/commands/value/addMarks/inline-across.js rename to packages/slate/test/commands/addMarks/selection/inline-across.js index 1c33a1a060..354849d4a3 100644 --- a/packages/slate/test/commands/value/addMarks/inline-across.js +++ b/packages/slate/test/commands/addMarks/selection/inline-across.js @@ -40,10 +40,10 @@ export const output = ( - an - - other - + + an + + other diff --git a/packages/slate/test/commands/value/addMarks/last-character.js b/packages/slate/test/commands/addMarks/selection/last-character.js similarity index 100% rename from packages/slate/test/commands/value/addMarks/last-character.js rename to packages/slate/test/commands/addMarks/selection/last-character.js diff --git a/packages/slate/test/commands/value/addMarks/middle-character.js b/packages/slate/test/commands/addMarks/selection/middle-character.js similarity index 83% rename from packages/slate/test/commands/value/addMarks/middle-character.js rename to packages/slate/test/commands/addMarks/selection/middle-character.js index d6bf2f998a..92efafd296 100644 --- a/packages/slate/test/commands/value/addMarks/middle-character.js +++ b/packages/slate/test/commands/addMarks/selection/middle-character.js @@ -19,11 +19,9 @@ export const output = ( w - o + o - - rd - + rd ) diff --git a/packages/slate/test/commands/value/addMarks/word.js b/packages/slate/test/commands/addMarks/selection/word.js similarity index 100% rename from packages/slate/test/commands/value/addMarks/word.js rename to packages/slate/test/commands/addMarks/selection/word.js diff --git a/packages/slate/test/commands/value/delete/emojis/inline-end-reverse.js b/packages/slate/test/commands/delete/emojis/inline-end-reverse.js similarity index 91% rename from packages/slate/test/commands/value/delete/emojis/inline-end-reverse.js rename to packages/slate/test/commands/delete/emojis/inline-end-reverse.js index 4100c1b994..831ff38fc7 100644 --- a/packages/slate/test/commands/value/delete/emojis/inline-end-reverse.js +++ b/packages/slate/test/commands/delete/emojis/inline-end-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-middle-reverse.js b/packages/slate/test/commands/delete/emojis/inline-middle-reverse.js similarity index 91% rename from packages/slate/test/commands/value/delete/emojis/inline-middle-reverse.js rename to packages/slate/test/commands/delete/emojis/inline-middle-reverse.js index 397e9a5896..a01514e074 100644 --- a/packages/slate/test/commands/value/delete/emojis/inline-middle-reverse.js +++ b/packages/slate/test/commands/delete/emojis/inline-middle-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-middle.js b/packages/slate/test/commands/delete/emojis/inline-middle.js similarity index 91% rename from packages/slate/test/commands/value/delete/emojis/inline-middle.js rename to packages/slate/test/commands/delete/emojis/inline-middle.js index c19c0a708b..9c0e6f1fd6 100644 --- a/packages/slate/test/commands/value/delete/emojis/inline-middle.js +++ b/packages/slate/test/commands/delete/emojis/inline-middle.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character' }) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-only-reverse.js b/packages/slate/test/commands/delete/emojis/inline-only-reverse.js similarity index 91% rename from packages/slate/test/commands/value/delete/emojis/inline-only-reverse.js rename to packages/slate/test/commands/delete/emojis/inline-only-reverse.js index a0a0648301..e15747b01a 100644 --- a/packages/slate/test/commands/value/delete/emojis/inline-only-reverse.js +++ b/packages/slate/test/commands/delete/emojis/inline-only-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/emojis/inline-start.js b/packages/slate/test/commands/delete/emojis/inline-start.js similarity index 91% rename from packages/slate/test/commands/value/delete/emojis/inline-start.js rename to packages/slate/test/commands/delete/emojis/inline-start.js index e5107daca7..e05c0b8044 100644 --- a/packages/slate/test/commands/value/delete/emojis/inline-start.js +++ b/packages/slate/test/commands/delete/emojis/inline-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character' }) diff --git a/packages/slate/test/commands/value/delete/emojis/text-end-reverse.js b/packages/slate/test/commands/delete/emojis/text-end-reverse.js similarity index 88% rename from packages/slate/test/commands/value/delete/emojis/text-end-reverse.js rename to packages/slate/test/commands/delete/emojis/text-end-reverse.js index 5aece929ce..f3230231cd 100644 --- a/packages/slate/test/commands/value/delete/emojis/text-end-reverse.js +++ b/packages/slate/test/commands/delete/emojis/text-end-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/emojis/text-start.js b/packages/slate/test/commands/delete/emojis/text-start.js similarity index 87% rename from packages/slate/test/commands/value/delete/emojis/text-start.js rename to packages/slate/test/commands/delete/emojis/text-start.js index 8442b87a48..5117ec537f 100644 --- a/packages/slate/test/commands/value/delete/emojis/text-start.js +++ b/packages/slate/test/commands/delete/emojis/text-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character' }) diff --git a/packages/slate/test/commands/path/removeNodeAtPath/block.js b/packages/slate/test/commands/delete/path/block.js similarity index 88% rename from packages/slate/test/commands/path/removeNodeAtPath/block.js rename to packages/slate/test/commands/delete/path/block.js index e1ed811fc1..f571c5add1 100644 --- a/packages/slate/test/commands/path/removeNodeAtPath/block.js +++ b/packages/slate/test/commands/delete/path/block.js @@ -10,7 +10,7 @@ export const input = ( ) export const run = editor => { - editor.removeNodeAtPath([1]) + editor.delete({ at: [1] }) } export const output = ( diff --git a/packages/slate/test/commands/path/removeNodeAtPath/inline.js b/packages/slate/test/commands/delete/path/inline.js similarity index 89% rename from packages/slate/test/commands/path/removeNodeAtPath/inline.js rename to packages/slate/test/commands/delete/path/inline.js index 1297e6a96e..f0b10ac4e3 100644 --- a/packages/slate/test/commands/path/removeNodeAtPath/inline.js +++ b/packages/slate/test/commands/delete/path/inline.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - editor.removeNodeAtPath([0, 1]) + editor.delete({ at: [0, 1] }) } export const output = ( diff --git a/packages/slate/test/commands/path/removeNodeAtPath/selection-inside.js b/packages/slate/test/commands/delete/path/selection-inside.js similarity index 91% rename from packages/slate/test/commands/path/removeNodeAtPath/selection-inside.js rename to packages/slate/test/commands/delete/path/selection-inside.js index e1e9d395aa..dc3d382687 100644 --- a/packages/slate/test/commands/path/removeNodeAtPath/selection-inside.js +++ b/packages/slate/test/commands/delete/path/selection-inside.js @@ -14,7 +14,7 @@ export const input = ( ) export const run = editor => { - editor.removeNodeAtPath([1, 0]) + editor.delete({ at: [1, 0] }) } export const output = ( diff --git a/packages/slate/test/commands/path/removeNodeAtPath/text.js b/packages/slate/test/commands/delete/path/text.js similarity index 88% rename from packages/slate/test/commands/path/removeNodeAtPath/text.js rename to packages/slate/test/commands/delete/path/text.js index 9e0a385c0e..50a5f1f08c 100644 --- a/packages/slate/test/commands/path/removeNodeAtPath/text.js +++ b/packages/slate/test/commands/delete/path/text.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeNodeAtPath([0, 0]) + editor.delete({ at: [0, 0] }) } export const input = ( diff --git a/packages/slate/test/commands/value/delete/join/basic-reverse.js b/packages/slate/test/commands/delete/point/basic-reverse.js similarity index 88% rename from packages/slate/test/commands/value/delete/join/basic-reverse.js rename to packages/slate/test/commands/delete/point/basic-reverse.js index 3a815ce370..48953729ae 100644 --- a/packages/slate/test/commands/value/delete/join/basic-reverse.js +++ b/packages/slate/test/commands/delete/point/basic-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/join/basic.js b/packages/slate/test/commands/delete/point/basic.js similarity index 87% rename from packages/slate/test/commands/value/delete/join/basic.js rename to packages/slate/test/commands/delete/point/basic.js index 79717c9320..408352aef8 100644 --- a/packages/slate/test/commands/value/delete/join/basic.js +++ b/packages/slate/test/commands/delete/point/basic.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/join/depths-reverse.js b/packages/slate/test/commands/delete/point/depths-reverse.js similarity index 89% rename from packages/slate/test/commands/value/delete/join/depths-reverse.js rename to packages/slate/test/commands/delete/point/depths-reverse.js index 680937dee3..9304ffa5b4 100644 --- a/packages/slate/test/commands/value/delete/join/depths-reverse.js +++ b/packages/slate/test/commands/delete/point/depths-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/join/inline-before-reverse.js b/packages/slate/test/commands/delete/point/inline-before-reverse.js similarity index 90% rename from packages/slate/test/commands/value/delete/join/inline-before-reverse.js rename to packages/slate/test/commands/delete/point/inline-before-reverse.js index 403a887b7b..8c7a3bb194 100644 --- a/packages/slate/test/commands/value/delete/join/inline-before-reverse.js +++ b/packages/slate/test/commands/delete/point/inline-before-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/join/inline-before.js b/packages/slate/test/commands/delete/point/inline-before.js similarity index 91% rename from packages/slate/test/commands/value/delete/join/inline-before.js rename to packages/slate/test/commands/delete/point/inline-before.js index 10f993e36e..6cd8749361 100644 --- a/packages/slate/test/commands/value/delete/join/inline-before.js +++ b/packages/slate/test/commands/delete/point/inline-before.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/join/inline-inside-reverse.js b/packages/slate/test/commands/delete/point/inline-inside-reverse.js similarity index 92% rename from packages/slate/test/commands/value/delete/join/inline-inside-reverse.js rename to packages/slate/test/commands/delete/point/inline-inside-reverse.js index caaebdd03d..72c21102d4 100644 --- a/packages/slate/test/commands/value/delete/join/inline-inside-reverse.js +++ b/packages/slate/test/commands/delete/point/inline-inside-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/join/inline-void-reverse.js b/packages/slate/test/commands/delete/point/inline-void-reverse.js similarity index 91% rename from packages/slate/test/commands/value/delete/join/inline-void-reverse.js rename to packages/slate/test/commands/delete/point/inline-void-reverse.js index 34f631df0b..37860db96b 100644 --- a/packages/slate/test/commands/value/delete/join/inline-void-reverse.js +++ b/packages/slate/test/commands/delete/point/inline-void-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/join/inline.js b/packages/slate/test/commands/delete/point/inline.js similarity index 89% rename from packages/slate/test/commands/value/delete/join/inline.js rename to packages/slate/test/commands/delete/point/inline.js index 7c8f0dd5a0..1b37350206 100644 --- a/packages/slate/test/commands/value/delete/join/inline.js +++ b/packages/slate/test/commands/delete/point/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/join/nested-reverse.js b/packages/slate/test/commands/delete/point/nested-reverse.js similarity index 90% rename from packages/slate/test/commands/value/delete/join/nested-reverse.js rename to packages/slate/test/commands/delete/point/nested-reverse.js index daf9257dd2..4010e1158f 100644 --- a/packages/slate/test/commands/value/delete/join/nested-reverse.js +++ b/packages/slate/test/commands/delete/point/nested-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/join/nested.js b/packages/slate/test/commands/delete/point/nested.js similarity index 89% rename from packages/slate/test/commands/value/delete/join/nested.js rename to packages/slate/test/commands/delete/point/nested.js index 17cf5179d6..7176d778d8 100644 --- a/packages/slate/test/commands/value/delete/join/nested.js +++ b/packages/slate/test/commands/delete/point/nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-across-multiple.js b/packages/slate/test/commands/delete/selection/block-across-multiple.js similarity index 84% rename from packages/slate/test/commands/value/delete/expanded/block-across-multiple.js rename to packages/slate/test/commands/delete/selection/block-across-multiple.js index 85ec344fd3..94ab1f6f68 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-across-multiple.js +++ b/packages/slate/test/commands/delete/selection/block-across-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,25 +8,21 @@ export const run = editor => { export const input = ( - one - + two three four - ) export const output = ( - - ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-across-nested.js b/packages/slate/test/commands/delete/selection/block-across-nested.js similarity index 85% rename from packages/slate/test/commands/value/delete/expanded/block-across-nested.js rename to packages/slate/test/commands/delete/selection/block-across-nested.js index 7a900eed53..4c04ad6995 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-across-nested.js +++ b/packages/slate/test/commands/delete/selection/block-across-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,7 +8,6 @@ export const run = editor => { export const input = ( - one @@ -18,24 +17,21 @@ export const input = ( three - + four - ) export const output = ( - onethree - + four - ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-across.js b/packages/slate/test/commands/delete/selection/block-across.js similarity index 88% rename from packages/slate/test/commands/value/delete/expanded/block-across.js rename to packages/slate/test/commands/delete/selection/block-across.js index 41319a384d..700e28d6ea 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-across.js +++ b/packages/slate/test/commands/delete/selection/block-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-depths-nested.js b/packages/slate/test/commands/delete/selection/block-depths-nested.js similarity index 90% rename from packages/slate/test/commands/value/delete/expanded/block-depths-nested.js rename to packages/slate/test/commands/delete/selection/block-depths-nested.js index 6a2f154ae8..4dfa410c62 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-depths-nested.js +++ b/packages/slate/test/commands/delete/selection/block-depths-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-depths.js b/packages/slate/test/commands/delete/selection/block-depths.js similarity index 81% rename from packages/slate/test/commands/value/delete/expanded/block-depths.js rename to packages/slate/test/commands/delete/selection/block-depths.js index 97451ea3a2..3cdbc66495 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-depths.js +++ b/packages/slate/test/commands/delete/selection/block-depths.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - word - + middle another - + - ) export const output = ( - woother - - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js b/packages/slate/test/commands/delete/selection/block-hanging-multiple.js similarity index 88% rename from packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js rename to packages/slate/test/commands/delete/selection/block-hanging-multiple.js index f06abf228e..549db4b30a 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-hanging-multiple.js +++ b/packages/slate/test/commands/delete/selection/block-hanging-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-hanging-single.js b/packages/slate/test/commands/delete/selection/block-hanging-single.js similarity index 74% rename from packages/slate/test/commands/value/delete/expanded/block-hanging-single.js rename to packages/slate/test/commands/delete/selection/block-hanging-single.js index 90cab64c9b..804f8756b0 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-hanging-single.js +++ b/packages/slate/test/commands/delete/selection/block-hanging-single.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,23 +8,19 @@ export const run = editor => { export const input = ( - one - + two - - + ) export const output = ( - two - - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-inline-across.js b/packages/slate/test/commands/delete/selection/block-inline-across.js similarity index 93% rename from packages/slate/test/commands/value/delete/expanded/block-inline-across.js rename to packages/slate/test/commands/delete/selection/block-inline-across.js index a7a5f9613d..e5e89fbe88 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-inline-across.js +++ b/packages/slate/test/commands/delete/selection/block-inline-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-join-edges.js b/packages/slate/test/commands/delete/selection/block-join-edges.js similarity index 79% rename from packages/slate/test/commands/value/delete/expanded/block-join-edges.js rename to packages/slate/test/commands/delete/selection/block-join-edges.js index 5f70ec6103..d1f7e38c3a 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-join-edges.js +++ b/packages/slate/test/commands/delete/selection/block-join-edges.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,23 +8,19 @@ export const run = editor => { export const input = ( - word another - - + ) export const output = ( - wordanother - - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-join-inline.js b/packages/slate/test/commands/delete/selection/block-join-inline.js similarity index 89% rename from packages/slate/test/commands/value/delete/expanded/block-join-inline.js rename to packages/slate/test/commands/delete/selection/block-join-inline.js index ad76a8a6ca..bbb7f9e59c 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-join-inline.js +++ b/packages/slate/test/commands/delete/selection/block-join-inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/block-join-nested.js b/packages/slate/test/commands/delete/selection/block-join-nested.js similarity index 83% rename from packages/slate/test/commands/value/delete/expanded/block-join-nested.js rename to packages/slate/test/commands/delete/selection/block-join-nested.js index 9fd1f046b4..dbe01cdd07 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-join-nested.js +++ b/packages/slate/test/commands/delete/selection/block-join-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,7 +8,6 @@ export const run = editor => { export const input = ( - @@ -16,23 +15,20 @@ export const input = ( another - + - ) export const output = ( - wordanother - + - ) diff --git a/packages/slate/test/commands/value/delete/expanded/block-nested.js b/packages/slate/test/commands/delete/selection/block-nested.js similarity index 92% rename from packages/slate/test/commands/value/delete/expanded/block-nested.js rename to packages/slate/test/commands/delete/selection/block-nested.js index a0a2c187b6..6640f0059d 100644 --- a/packages/slate/test/commands/value/delete/expanded/block-nested.js +++ b/packages/slate/test/commands/delete/selection/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/character-end.js b/packages/slate/test/commands/delete/selection/character-end.js similarity index 85% rename from packages/slate/test/commands/value/delete/expanded/character-end.js rename to packages/slate/test/commands/delete/selection/character-end.js index 0a9e4b8a56..7ab79ffff9 100644 --- a/packages/slate/test/commands/value/delete/expanded/character-end.js +++ b/packages/slate/test/commands/delete/selection/character-end.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,20 +8,16 @@ export const run = editor => { export const input = ( - word - ) export const output = ( - wor - ) diff --git a/packages/slate/test/commands/value/delete/expanded/character-middle.js b/packages/slate/test/commands/delete/selection/character-middle.js similarity index 76% rename from packages/slate/test/commands/value/delete/expanded/character-middle.js rename to packages/slate/test/commands/delete/selection/character-middle.js index 3db53dd92a..64e5f4d29f 100644 --- a/packages/slate/test/commands/value/delete/expanded/character-middle.js +++ b/packages/slate/test/commands/delete/selection/character-middle.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,20 +8,16 @@ export const run = editor => { export const input = ( - word - - + ) export const output = ( - wrd - - + ) diff --git a/packages/slate/test/commands/value/delete/expanded/character-start.js b/packages/slate/test/commands/delete/selection/character-start.js similarity index 86% rename from packages/slate/test/commands/value/delete/expanded/character-start.js rename to packages/slate/test/commands/delete/selection/character-start.js index 35ce9b4d24..469a3639a4 100644 --- a/packages/slate/test/commands/value/delete/expanded/character-start.js +++ b/packages/slate/test/commands/delete/selection/character-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-after.js b/packages/slate/test/commands/delete/selection/inline-after.js similarity index 89% rename from packages/slate/test/commands/value/delete/expanded/inline-after.js rename to packages/slate/test/commands/delete/selection/inline-after.js index dd10b73d9d..e60962a60f 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-after.js +++ b/packages/slate/test/commands/delete/selection/inline-after.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-inside.js b/packages/slate/test/commands/delete/selection/inline-inside.js similarity index 90% rename from packages/slate/test/commands/value/delete/expanded/inline-inside.js rename to packages/slate/test/commands/delete/selection/inline-inside.js index 1512c05c95..0bcb198090 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-inside.js +++ b/packages/slate/test/commands/delete/selection/inline-inside.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-over.js b/packages/slate/test/commands/delete/selection/inline-over.js similarity index 87% rename from packages/slate/test/commands/value/delete/expanded/inline-over.js rename to packages/slate/test/commands/delete/selection/inline-over.js index 0e0c7f6e23..697cb3f86e 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-over.js +++ b/packages/slate/test/commands/delete/selection/inline-over.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/inline-whole.js b/packages/slate/test/commands/delete/selection/inline-whole.js similarity index 90% rename from packages/slate/test/commands/value/delete/expanded/inline-whole.js rename to packages/slate/test/commands/delete/selection/inline-whole.js index 8900159c34..93c43ec015 100644 --- a/packages/slate/test/commands/value/delete/expanded/inline-whole.js +++ b/packages/slate/test/commands/delete/selection/inline-whole.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/mark-across.js b/packages/slate/test/commands/delete/selection/mark-across.js similarity index 89% rename from packages/slate/test/commands/value/delete/expanded/mark-across.js rename to packages/slate/test/commands/delete/selection/mark-across.js index 00f50e937f..0fdcc358b3 100644 --- a/packages/slate/test/commands/value/delete/expanded/mark-across.js +++ b/packages/slate/test/commands/delete/selection/mark-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/expanded/mark-whole.js b/packages/slate/test/commands/delete/selection/mark-whole.js similarity index 88% rename from packages/slate/test/commands/value/delete/expanded/mark-whole.js rename to packages/slate/test/commands/delete/selection/mark-whole.js index 783a80986f..ef0289a1ee 100644 --- a/packages/slate/test/commands/value/delete/expanded/mark-whole.js +++ b/packages/slate/test/commands/delete/selection/mark-whole.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,24 +8,20 @@ export const run = editor => { export const input = ( - word - ) export const output = ( - - ) diff --git a/packages/slate/test/commands/value/delete/expanded/word.js b/packages/slate/test/commands/delete/selection/word.js similarity index 85% rename from packages/slate/test/commands/value/delete/expanded/word.js rename to packages/slate/test/commands/delete/selection/word.js index 4fc6801602..c606e0d2f1 100644 --- a/packages/slate/test/commands/value/delete/expanded/word.js +++ b/packages/slate/test/commands/delete/selection/word.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -8,20 +8,16 @@ export const run = editor => { export const input = ( - word - ) export const output = ( - - ) diff --git a/packages/slate/test/commands/value/delete/character/document-end.js b/packages/slate/test/commands/delete/unit-character/document-end.js similarity index 86% rename from packages/slate/test/commands/value/delete/character/document-end.js rename to packages/slate/test/commands/delete/unit-character/document-end.js index ac29cff853..92f32e09b8 100644 --- a/packages/slate/test/commands/value/delete/character/document-end.js +++ b/packages/slate/test/commands/delete/unit-character/document-end.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/character/document-start-reverse.js b/packages/slate/test/commands/delete/unit-character/document-start-reverse.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/document-start-reverse.js rename to packages/slate/test/commands/delete/unit-character/document-start-reverse.js index 04dac778be..1ef239a6ec 100644 --- a/packages/slate/test/commands/value/delete/character/document-start-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/document-start-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/empty-reverse.js b/packages/slate/test/commands/delete/unit-character/empty-reverse.js similarity index 86% rename from packages/slate/test/commands/value/delete/character/empty-reverse.js rename to packages/slate/test/commands/delete/unit-character/empty-reverse.js index abd59b201c..91f4ef0ac3 100644 --- a/packages/slate/test/commands/value/delete/character/empty-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/empty-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/empty.js b/packages/slate/test/commands/delete/unit-character/empty.js similarity index 86% rename from packages/slate/test/commands/value/delete/character/empty.js rename to packages/slate/test/commands/delete/unit-character/empty.js index 471c00ef16..2993e1ba4f 100644 --- a/packages/slate/test/commands/value/delete/character/empty.js +++ b/packages/slate/test/commands/delete/unit-character/empty.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/character/end-reverse.js b/packages/slate/test/commands/delete/unit-character/end-reverse.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/end-reverse.js rename to packages/slate/test/commands/delete/unit-character/end-reverse.js index 024b58cece..353936cc2f 100644 --- a/packages/slate/test/commands/value/delete/character/end-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/end-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/end.js b/packages/slate/test/commands/delete/unit-character/end.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/end.js rename to packages/slate/test/commands/delete/unit-character/end.js index 858bf9672d..9a989f77db 100644 --- a/packages/slate/test/commands/value/delete/character/end.js +++ b/packages/slate/test/commands/delete/unit-character/end.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character' }) diff --git a/packages/slate/test/commands/value/delete/character/first-reverse.js b/packages/slate/test/commands/delete/unit-character/first-reverse.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/first-reverse.js rename to packages/slate/test/commands/delete/unit-character/first-reverse.js index c432f0682a..7d71308613 100644 --- a/packages/slate/test/commands/value/delete/character/first-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/first-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/first.js b/packages/slate/test/commands/delete/unit-character/first.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/first.js rename to packages/slate/test/commands/delete/unit-character/first.js index 3dd2cb082a..9c405465c5 100644 --- a/packages/slate/test/commands/value/delete/character/first.js +++ b/packages/slate/test/commands/delete/unit-character/first.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character' }) diff --git a/packages/slate/test/commands/value/delete/character/inline-after-reverse.js b/packages/slate/test/commands/delete/unit-character/inline-after-reverse.js similarity index 89% rename from packages/slate/test/commands/value/delete/character/inline-after-reverse.js rename to packages/slate/test/commands/delete/unit-character/inline-after-reverse.js index 8604892d19..7615d7aafd 100644 --- a/packages/slate/test/commands/value/delete/character/inline-after-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/inline-after-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/inline-before-reverse.js b/packages/slate/test/commands/delete/unit-character/inline-before-reverse.js similarity index 90% rename from packages/slate/test/commands/value/delete/character/inline-before-reverse.js rename to packages/slate/test/commands/delete/unit-character/inline-before-reverse.js index 727b5090da..23a2282b92 100644 --- a/packages/slate/test/commands/value/delete/character/inline-before-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/inline-before-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/inline-before.js b/packages/slate/test/commands/delete/unit-character/inline-before.js similarity index 88% rename from packages/slate/test/commands/value/delete/character/inline-before.js rename to packages/slate/test/commands/delete/unit-character/inline-before.js index 41bed9b48e..2239ea3360 100644 --- a/packages/slate/test/commands/value/delete/character/inline-before.js +++ b/packages/slate/test/commands/delete/unit-character/inline-before.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/character/inline-end-reverse.js b/packages/slate/test/commands/delete/unit-character/inline-end-reverse.js similarity index 89% rename from packages/slate/test/commands/value/delete/character/inline-end-reverse.js rename to packages/slate/test/commands/delete/unit-character/inline-end-reverse.js index 3226d8804f..96ca189f49 100644 --- a/packages/slate/test/commands/value/delete/character/inline-end-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/inline-end-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/inline-inside-reverse.js b/packages/slate/test/commands/delete/unit-character/inline-inside-reverse.js similarity index 90% rename from packages/slate/test/commands/value/delete/character/inline-inside-reverse.js rename to packages/slate/test/commands/delete/unit-character/inline-inside-reverse.js index c70abf1c2d..44d3918087 100644 --- a/packages/slate/test/commands/value/delete/character/inline-inside-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/inline-inside-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/inline-inside.js b/packages/slate/test/commands/delete/unit-character/inline-inside.js similarity index 89% rename from packages/slate/test/commands/value/delete/character/inline-inside.js rename to packages/slate/test/commands/delete/unit-character/inline-inside.js index f4ce065742..111b69354e 100644 --- a/packages/slate/test/commands/value/delete/character/inline-inside.js +++ b/packages/slate/test/commands/delete/unit-character/inline-inside.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/character/last-reverse.js b/packages/slate/test/commands/delete/unit-character/last-reverse.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/last-reverse.js rename to packages/slate/test/commands/delete/unit-character/last-reverse.js index 024b58cece..353936cc2f 100644 --- a/packages/slate/test/commands/value/delete/character/last-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/last-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/last.js b/packages/slate/test/commands/delete/unit-character/last.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/last.js rename to packages/slate/test/commands/delete/unit-character/last.js index 858bf9672d..9a989f77db 100644 --- a/packages/slate/test/commands/value/delete/character/last.js +++ b/packages/slate/test/commands/delete/unit-character/last.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character' }) diff --git a/packages/slate/test/commands/value/delete/character/middle-reverse.js b/packages/slate/test/commands/delete/unit-character/middle-reverse.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/middle-reverse.js rename to packages/slate/test/commands/delete/unit-character/middle-reverse.js index e145bfa3b4..3b17e9d5c2 100644 --- a/packages/slate/test/commands/value/delete/character/middle-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/middle-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/middle.js b/packages/slate/test/commands/delete/unit-character/middle.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/middle.js rename to packages/slate/test/commands/delete/unit-character/middle.js index 4752de8a2f..521cc6a093 100644 --- a/packages/slate/test/commands/value/delete/character/middle.js +++ b/packages/slate/test/commands/delete/unit-character/middle.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character' }) diff --git a/packages/slate/test/commands/value/delete/character/multiple-reverse.js b/packages/slate/test/commands/delete/unit-character/multiple-reverse.js similarity index 88% rename from packages/slate/test/commands/value/delete/character/multiple-reverse.js rename to packages/slate/test/commands/delete/unit-character/multiple-reverse.js index d7eae70a9d..b7e36f7c74 100644 --- a/packages/slate/test/commands/value/delete/character/multiple-reverse.js +++ b/packages/slate/test/commands/delete/unit-character/multiple-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', distance: 3, reverse: true }) diff --git a/packages/slate/test/commands/value/delete/character/multiple.js b/packages/slate/test/commands/delete/unit-character/multiple.js similarity index 87% rename from packages/slate/test/commands/value/delete/character/multiple.js rename to packages/slate/test/commands/delete/unit-character/multiple.js index 9072e5f701..408a9c9809 100644 --- a/packages/slate/test/commands/value/delete/character/multiple.js +++ b/packages/slate/test/commands/delete/unit-character/multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'character', distance: 3 }) diff --git a/packages/slate/test/commands/value/delete/line/text-end-reverse.js b/packages/slate/test/commands/delete/unit-line/text-end-reverse.js similarity index 87% rename from packages/slate/test/commands/value/delete/line/text-end-reverse.js rename to packages/slate/test/commands/delete/unit-line/text-end-reverse.js index cdaf289333..5f0db7e498 100644 --- a/packages/slate/test/commands/value/delete/line/text-end-reverse.js +++ b/packages/slate/test/commands/delete/unit-line/text-end-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'line', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/line/text-end.js b/packages/slate/test/commands/delete/unit-line/text-end.js similarity index 84% rename from packages/slate/test/commands/value/delete/line/text-end.js rename to packages/slate/test/commands/delete/unit-line/text-end.js index 13c4af70a8..503dc69e20 100644 --- a/packages/slate/test/commands/value/delete/line/text-end.js +++ b/packages/slate/test/commands/delete/unit-line/text-end.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'line' }) diff --git a/packages/slate/test/commands/value/delete/line/text-middle-reverse.js b/packages/slate/test/commands/delete/unit-line/text-middle-reverse.js similarity index 87% rename from packages/slate/test/commands/value/delete/line/text-middle-reverse.js rename to packages/slate/test/commands/delete/unit-line/text-middle-reverse.js index 529c7cd6d7..f612e19259 100644 --- a/packages/slate/test/commands/value/delete/line/text-middle-reverse.js +++ b/packages/slate/test/commands/delete/unit-line/text-middle-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'line', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/line/text-middle.js b/packages/slate/test/commands/delete/unit-line/text-middle.js similarity index 87% rename from packages/slate/test/commands/value/delete/line/text-middle.js rename to packages/slate/test/commands/delete/unit-line/text-middle.js index 098b837dc4..cf35e695a3 100644 --- a/packages/slate/test/commands/value/delete/line/text-middle.js +++ b/packages/slate/test/commands/delete/unit-line/text-middle.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'line' }) diff --git a/packages/slate/test/commands/value/delete/line/text-start-reverse.js b/packages/slate/test/commands/delete/unit-line/text-start-reverse.js similarity index 85% rename from packages/slate/test/commands/value/delete/line/text-start-reverse.js rename to packages/slate/test/commands/delete/unit-line/text-start-reverse.js index eb44b485f0..0d15eb7a97 100644 --- a/packages/slate/test/commands/value/delete/line/text-start-reverse.js +++ b/packages/slate/test/commands/delete/unit-line/text-start-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'line', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/line/text-start.js b/packages/slate/test/commands/delete/unit-line/text-start.js similarity index 87% rename from packages/slate/test/commands/value/delete/line/text-start.js rename to packages/slate/test/commands/delete/unit-line/text-start.js index 2b3cef52de..5f374aa9ae 100644 --- a/packages/slate/test/commands/value/delete/line/text-start.js +++ b/packages/slate/test/commands/delete/unit-line/text-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'line' }) diff --git a/packages/slate/test/commands/value/delete/word/block-join-reverse.js b/packages/slate/test/commands/delete/unit-word/block-join-reverse.js similarity index 88% rename from packages/slate/test/commands/value/delete/word/block-join-reverse.js rename to packages/slate/test/commands/delete/unit-word/block-join-reverse.js index 2c365b5c78..3afe67c8b3 100644 --- a/packages/slate/test/commands/value/delete/word/block-join-reverse.js +++ b/packages/slate/test/commands/delete/unit-word/block-join-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'word', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/word/block-join.js b/packages/slate/test/commands/delete/unit-word/block-join.js similarity index 88% rename from packages/slate/test/commands/value/delete/word/block-join.js rename to packages/slate/test/commands/delete/unit-word/block-join.js index ea52f00a6a..ed9c3fed7a 100644 --- a/packages/slate/test/commands/value/delete/word/block-join.js +++ b/packages/slate/test/commands/delete/unit-word/block-join.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'word' }) diff --git a/packages/slate/test/commands/value/delete/word/text-end-reverse.js b/packages/slate/test/commands/delete/unit-word/text-end-reverse.js similarity index 88% rename from packages/slate/test/commands/value/delete/word/text-end-reverse.js rename to packages/slate/test/commands/delete/unit-word/text-end-reverse.js index c31dc5b544..3cf1fadc46 100644 --- a/packages/slate/test/commands/value/delete/word/text-end-reverse.js +++ b/packages/slate/test/commands/delete/unit-word/text-end-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'word', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/word/text-middle-reverse.js b/packages/slate/test/commands/delete/unit-word/text-middle-reverse.js similarity index 88% rename from packages/slate/test/commands/value/delete/word/text-middle-reverse.js rename to packages/slate/test/commands/delete/unit-word/text-middle-reverse.js index 50055bf2bc..d71dbcd1c8 100644 --- a/packages/slate/test/commands/value/delete/word/text-middle-reverse.js +++ b/packages/slate/test/commands/delete/unit-word/text-middle-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'word', reverse: true }) diff --git a/packages/slate/test/commands/value/delete/word/text-middle.js b/packages/slate/test/commands/delete/unit-word/text-middle.js similarity index 87% rename from packages/slate/test/commands/value/delete/word/text-middle.js rename to packages/slate/test/commands/delete/unit-word/text-middle.js index 85db1bac1d..c9991b4ccd 100644 --- a/packages/slate/test/commands/value/delete/word/text-middle.js +++ b/packages/slate/test/commands/delete/unit-word/text-middle.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'word' }) diff --git a/packages/slate/test/commands/value/delete/word/text-start.js b/packages/slate/test/commands/delete/unit-word/text-start.js similarity index 87% rename from packages/slate/test/commands/value/delete/word/text-start.js rename to packages/slate/test/commands/delete/unit-word/text-start.js index e02118d110..fdc322fbc3 100644 --- a/packages/slate/test/commands/value/delete/word/text-start.js +++ b/packages/slate/test/commands/delete/unit-word/text-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ unit: 'word' }) diff --git a/packages/slate/test/commands/value/delete/voids/block-across-backward.js b/packages/slate/test/commands/delete/voids/block-across-backward.js similarity index 88% rename from packages/slate/test/commands/value/delete/voids/block-across-backward.js rename to packages/slate/test/commands/delete/voids/block-across-backward.js index 971dea5f6d..eeb8c148e6 100644 --- a/packages/slate/test/commands/value/delete/voids/block-across-backward.js +++ b/packages/slate/test/commands/delete/voids/block-across-backward.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-after-reverse.js b/packages/slate/test/commands/delete/voids/block-after-reverse.js similarity index 89% rename from packages/slate/test/commands/value/delete/voids/block-after-reverse.js rename to packages/slate/test/commands/delete/voids/block-after-reverse.js index 949cc14c8b..37ce0bc82f 100644 --- a/packages/slate/test/commands/value/delete/voids/block-after-reverse.js +++ b/packages/slate/test/commands/delete/voids/block-after-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/voids/block-before.js b/packages/slate/test/commands/delete/voids/block-before.js similarity index 88% rename from packages/slate/test/commands/value/delete/voids/block-before.js rename to packages/slate/test/commands/delete/voids/block-before.js index de8a75ab9c..19d9997eca 100644 --- a/packages/slate/test/commands/value/delete/voids/block-before.js +++ b/packages/slate/test/commands/delete/voids/block-before.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-both.js b/packages/slate/test/commands/delete/voids/block-both.js similarity index 90% rename from packages/slate/test/commands/value/delete/voids/block-both.js rename to packages/slate/test/commands/delete/voids/block-both.js index 7b66407c3f..e72b73db9e 100644 --- a/packages/slate/test/commands/value/delete/voids/block-both.js +++ b/packages/slate/test/commands/delete/voids/block-both.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-hanging-from.js b/packages/slate/test/commands/delete/voids/block-hanging-from.js similarity index 89% rename from packages/slate/test/commands/value/delete/voids/block-hanging-from.js rename to packages/slate/test/commands/delete/voids/block-hanging-from.js index ba1f035c40..f9f7c075c7 100644 --- a/packages/slate/test/commands/value/delete/voids/block-hanging-from.js +++ b/packages/slate/test/commands/delete/voids/block-hanging-from.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-hanging-into.js b/packages/slate/test/commands/delete/voids/block-hanging-into.js similarity index 89% rename from packages/slate/test/commands/value/delete/voids/block-hanging-into.js rename to packages/slate/test/commands/delete/voids/block-hanging-into.js index 1b515c3b09..93f7abad7c 100644 --- a/packages/slate/test/commands/value/delete/voids/block-hanging-into.js +++ b/packages/slate/test/commands/delete/voids/block-hanging-into.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-only.js b/packages/slate/test/commands/delete/voids/block-only.js similarity index 82% rename from packages/slate/test/commands/value/delete/voids/block-only.js rename to packages/slate/test/commands/delete/voids/block-only.js index cd61bbbf96..77c9bbf837 100644 --- a/packages/slate/test/commands/value/delete/voids/block-only.js +++ b/packages/slate/test/commands/delete/voids/block-only.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-start-multiple.js b/packages/slate/test/commands/delete/voids/block-start-multiple.js similarity index 90% rename from packages/slate/test/commands/value/delete/voids/block-start-multiple.js rename to packages/slate/test/commands/delete/voids/block-start-multiple.js index 0137315b8d..1b8ab4d3bc 100644 --- a/packages/slate/test/commands/value/delete/voids/block-start-multiple.js +++ b/packages/slate/test/commands/delete/voids/block-start-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/block-start.js b/packages/slate/test/commands/delete/voids/block-start.js similarity index 90% rename from packages/slate/test/commands/value/delete/voids/block-start.js rename to packages/slate/test/commands/delete/voids/block-start.js index 080a7d3a33..69ca95c504 100644 --- a/packages/slate/test/commands/value/delete/voids/block-start.js +++ b/packages/slate/test/commands/delete/voids/block-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/inline-after-reverse.js b/packages/slate/test/commands/delete/voids/inline-after-reverse.js similarity index 90% rename from packages/slate/test/commands/value/delete/voids/inline-after-reverse.js rename to packages/slate/test/commands/delete/voids/inline-after-reverse.js index e99c405532..dfce0d085f 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-after-reverse.js +++ b/packages/slate/test/commands/delete/voids/inline-after-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete({ reverse: true }) diff --git a/packages/slate/test/commands/value/delete/voids/inline-before.js b/packages/slate/test/commands/delete/voids/inline-before.js similarity index 90% rename from packages/slate/test/commands/value/delete/voids/inline-before.js rename to packages/slate/test/commands/delete/voids/inline-before.js index 23f4aa7e71..a02262c6a4 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-before.js +++ b/packages/slate/test/commands/delete/voids/inline-before.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/inline-into.js b/packages/slate/test/commands/delete/voids/inline-into.js similarity index 90% rename from packages/slate/test/commands/value/delete/voids/inline-into.js rename to packages/slate/test/commands/delete/voids/inline-into.js index a4bc2bf91e..b4fbadca2e 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-into.js +++ b/packages/slate/test/commands/delete/voids/inline-into.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() diff --git a/packages/slate/test/commands/value/delete/voids/inline-over.js b/packages/slate/test/commands/delete/voids/inline-over.js similarity index 85% rename from packages/slate/test/commands/value/delete/voids/inline-over.js rename to packages/slate/test/commands/delete/voids/inline-over.js index 16d985089f..976711bd55 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-over.js +++ b/packages/slate/test/commands/delete/voids/inline-over.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -29,4 +29,4 @@ export const output = ( ) -export const skip = true \ No newline at end of file +export const skip = true diff --git a/packages/slate/test/commands/value/delete/voids/inline-start-across.js b/packages/slate/test/commands/delete/voids/inline-start-across.js similarity index 84% rename from packages/slate/test/commands/value/delete/voids/inline-start-across.js rename to packages/slate/test/commands/delete/voids/inline-start-across.js index c0212656e8..241d58b8ca 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-start-across.js +++ b/packages/slate/test/commands/delete/voids/inline-start-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -29,4 +29,4 @@ export const output = ( ) -export const skip = true \ No newline at end of file +export const skip = true diff --git a/packages/slate/test/commands/value/delete/voids/inline-start.js b/packages/slate/test/commands/delete/voids/inline-start.js similarity index 83% rename from packages/slate/test/commands/value/delete/voids/inline-start.js rename to packages/slate/test/commands/delete/voids/inline-start.js index 44463bf882..501e79e4b3 100644 --- a/packages/slate/test/commands/value/delete/voids/inline-start.js +++ b/packages/slate/test/commands/delete/voids/inline-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const run = editor => { editor.delete() @@ -28,4 +28,4 @@ export const output = ( ) -export const skip = true \ No newline at end of file +export const skip = true diff --git a/packages/slate/test/commands/selection/deselect/basic.js b/packages/slate/test/commands/deselect/basic.js similarity index 100% rename from packages/slate/test/commands/selection/deselect/basic.js rename to packages/slate/test/commands/deselect/basic.js diff --git a/packages/slate/test/commands/selection/deselect/unfocused.js b/packages/slate/test/commands/deselect/unfocused.js similarity index 100% rename from packages/slate/test/commands/selection/deselect/unfocused.js rename to packages/slate/test/commands/deselect/unfocused.js diff --git a/packages/slate/test/commands/value/insert-block/is-empty.js b/packages/slate/test/commands/insertBlock/selection/block-empty.js similarity index 84% rename from packages/slate/test/commands/value/insert-block/is-empty.js rename to packages/slate/test/commands/insertBlock/selection/block-empty.js index b97ffb4953..bb6f78b091 100644 --- a/packages/slate/test/commands/value/insert-block/is-empty.js +++ b/packages/slate/test/commands/insertBlock/selection/block-empty.js @@ -3,7 +3,11 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertBlock('quote') + editor.insertBlock( + + + + ) } export const input = ( diff --git a/packages/slate/test/commands/insertBlock/selection/block-end.js b/packages/slate/test/commands/insertBlock/selection/block-end.js new file mode 100644 index 0000000000..8c229a4444 --- /dev/null +++ b/packages/slate/test/commands/insertBlock/selection/block-end.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + word + + +) + +export const run = editor => { + editor.insertBlock( + + + + ) +} + +export const output = ( + + word + + + + +) diff --git a/packages/slate/test/commands/insertBlock/selection/block-middle.js b/packages/slate/test/commands/insertBlock/selection/block-middle.js new file mode 100644 index 0000000000..1a9ae5b49b --- /dev/null +++ b/packages/slate/test/commands/insertBlock/selection/block-middle.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertBlock( + + + + ) +} + +export const input = ( + + + word + + +) + +export const output = ( + + wo + + + + rd + +) diff --git a/packages/slate/test/commands/insertBlock/selection/block-start.js b/packages/slate/test/commands/insertBlock/selection/block-start.js new file mode 100644 index 0000000000..84e47f5137 --- /dev/null +++ b/packages/slate/test/commands/insertBlock/selection/block-start.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertBlock( + + + + ) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + + + word + +) diff --git a/packages/slate/test/commands/insertBlock/selection/block-void.js b/packages/slate/test/commands/insertBlock/selection/block-void.js new file mode 100644 index 0000000000..2f9d45c709 --- /dev/null +++ b/packages/slate/test/commands/insertBlock/selection/block-void.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertBlock( + + + + ) +} + +export const input = ( + + + text + + text + +) + +export const output = ( + + text + + + + text + +) + +export const skip = true diff --git a/packages/slate/test/commands/value/insert-block/is-inline-void.js b/packages/slate/test/commands/insertBlock/selection/inline-void.js similarity index 83% rename from packages/slate/test/commands/value/insert-block/is-inline-void.js rename to packages/slate/test/commands/insertBlock/selection/inline-void.js index 2f7ffdc119..0d58c40165 100644 --- a/packages/slate/test/commands/value/insert-block/is-inline-void.js +++ b/packages/slate/test/commands/insertBlock/selection/inline-void.js @@ -3,7 +3,11 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertBlock('quote') + editor.insertBlock( + + + + ) } export const input = ( @@ -35,3 +39,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/path/insertFragmentAtPath/end-of-target.js b/packages/slate/test/commands/insertFragment/path/end-of-target.js similarity index 100% rename from packages/slate/test/commands/path/insertFragmentAtPath/end-of-target.js rename to packages/slate/test/commands/insertFragment/path/end-of-target.js diff --git a/packages/slate/test/commands/path/insertFragmentAtPath/middle-of-target.js b/packages/slate/test/commands/insertFragment/path/middle-of-target.js similarity index 100% rename from packages/slate/test/commands/path/insertFragmentAtPath/middle-of-target.js rename to packages/slate/test/commands/insertFragment/path/middle-of-target.js diff --git a/packages/slate/test/commands/path/insertFragmentAtPath/start-of-target.js b/packages/slate/test/commands/insertFragment/path/start-of-target.js similarity index 100% rename from packages/slate/test/commands/path/insertFragmentAtPath/start-of-target.js rename to packages/slate/test/commands/insertFragment/path/start-of-target.js diff --git a/packages/slate/test/commands/value/insert-fragment/block-empty.js b/packages/slate/test/commands/insertFragment/selection/block-empty.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/block-empty.js rename to packages/slate/test/commands/insertFragment/selection/block-empty.js diff --git a/packages/slate/test/commands/value/insert-fragment/block-end.js b/packages/slate/test/commands/insertFragment/selection/block-end.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/block-end.js rename to packages/slate/test/commands/insertFragment/selection/block-end.js diff --git a/packages/slate/test/commands/value/insert-fragment/block-middle.js b/packages/slate/test/commands/insertFragment/selection/block-middle.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/block-middle.js rename to packages/slate/test/commands/insertFragment/selection/block-middle.js diff --git a/packages/slate/test/commands/value/insert-fragment/block-start.js b/packages/slate/test/commands/insertFragment/selection/block-start.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/block-start.js rename to packages/slate/test/commands/insertFragment/selection/block-start.js diff --git a/packages/slate/test/commands/value/insert-fragment/end-block-multiple-blocks.js b/packages/slate/test/commands/insertFragment/selection/end-block-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/end-block-multiple-blocks.js rename to packages/slate/test/commands/insertFragment/selection/end-block-multiple-blocks.js diff --git a/packages/slate/test/commands/value/insert-fragment/end-block.js b/packages/slate/test/commands/insertFragment/selection/end-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/end-block.js rename to packages/slate/test/commands/insertFragment/selection/end-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/end-inline.js b/packages/slate/test/commands/insertFragment/selection/end-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/end-inline.js rename to packages/slate/test/commands/insertFragment/selection/end-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/flat-blocks/end-block.js b/packages/slate/test/commands/insertFragment/selection/flat-blocks/end-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/flat-blocks/end-block.js rename to packages/slate/test/commands/insertFragment/selection/flat-blocks/end-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/flat-blocks/hanging-selection-mixed-types.js b/packages/slate/test/commands/insertFragment/selection/flat-blocks/hanging-selection-mixed-types.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/flat-blocks/hanging-selection-mixed-types.js rename to packages/slate/test/commands/insertFragment/selection/flat-blocks/hanging-selection-mixed-types.js diff --git a/packages/slate/test/commands/value/insert-fragment/flat-blocks/start-block.js b/packages/slate/test/commands/insertFragment/selection/flat-blocks/start-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/flat-blocks/start-block.js rename to packages/slate/test/commands/insertFragment/selection/flat-blocks/start-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-adjacent-texts.js b/packages/slate/test/commands/insertFragment/selection/fragment-adjacent-texts.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-adjacent-texts.js rename to packages/slate/test/commands/insertFragment/selection/fragment-adjacent-texts.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-inline-node.js b/packages/slate/test/commands/insertFragment/selection/fragment-inline-node.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-inline-node.js rename to packages/slate/test/commands/insertFragment/selection/fragment-inline-node.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-multiple-blocks.js b/packages/slate/test/commands/insertFragment/selection/fragment-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-multiple-blocks.js rename to packages/slate/test/commands/insertFragment/selection/fragment-multiple-blocks.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js b/packages/slate/test/commands/insertFragment/selection/fragment-multiple-marks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-multiple-marks.js rename to packages/slate/test/commands/insertFragment/selection/fragment-multiple-marks.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-end-of-node.js b/packages/slate/test/commands/insertFragment/selection/fragment-nested-blocks-end-of-node.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-end-of-node.js rename to packages/slate/test/commands/insertFragment/selection/fragment-nested-blocks-end-of-node.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-start-of-node.js b/packages/slate/test/commands/insertFragment/selection/fragment-nested-blocks-start-of-node.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks-start-of-node.js rename to packages/slate/test/commands/insertFragment/selection/fragment-nested-blocks-start-of-node.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks.js b/packages/slate/test/commands/insertFragment/selection/fragment-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-nested-blocks.js rename to packages/slate/test/commands/insertFragment/selection/fragment-nested-blocks.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js b/packages/slate/test/commands/insertFragment/selection/fragment-single-child-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-single-child-block.js rename to packages/slate/test/commands/insertFragment/selection/fragment-single-child-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js b/packages/slate/test/commands/insertFragment/selection/fragment-single-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-single-inline.js rename to packages/slate/test/commands/insertFragment/selection/fragment-single-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js b/packages/slate/test/commands/insertFragment/selection/fragment-single-mark.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/fragment-single-mark.js rename to packages/slate/test/commands/insertFragment/selection/fragment-single-mark.js diff --git a/packages/slate/test/commands/value/insert-fragment/hanging-block.js b/packages/slate/test/commands/insertFragment/selection/hanging-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/hanging-block.js rename to packages/slate/test/commands/insertFragment/selection/hanging-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/hanging-selection-single-block.js b/packages/slate/test/commands/insertFragment/selection/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/hanging-selection-single-block.js rename to packages/slate/test/commands/insertFragment/selection/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/inline-middle.js b/packages/slate/test/commands/insertFragment/selection/inline-middle.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/inline-middle.js rename to packages/slate/test/commands/insertFragment/selection/inline-middle.js diff --git a/packages/slate/test/commands/value/insert-fragment/inline-start.js b/packages/slate/test/commands/insertFragment/selection/inline-start.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/inline-start.js rename to packages/slate/test/commands/insertFragment/selection/inline-start.js diff --git a/packages/slate/test/commands/value/insert-fragment/inlines/between-texts-into-middle-block.js b/packages/slate/test/commands/insertFragment/selection/inlines/between-texts-into-middle-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/inlines/between-texts-into-middle-block.js rename to packages/slate/test/commands/insertFragment/selection/inlines/between-texts-into-middle-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js b/packages/slate/test/commands/insertFragment/selection/inlines/middle-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/inlines/middle-block.js rename to packages/slate/test/commands/insertFragment/selection/inlines/middle-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/inlines/middle-inline.js b/packages/slate/test/commands/insertFragment/selection/inlines/middle-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/inlines/middle-inline.js rename to packages/slate/test/commands/insertFragment/selection/inlines/middle-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-block.js b/packages/slate/test/commands/insertFragment/selection/insert-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-block.js rename to packages/slate/test/commands/insertFragment/selection/insert-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-inline-at-inline-middle.js b/packages/slate/test/commands/insertFragment/selection/insert-inline-at-inline-middle.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-inline-at-inline-middle.js rename to packages/slate/test/commands/insertFragment/selection/insert-inline-at-inline-middle.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-inline.js b/packages/slate/test/commands/insertFragment/selection/insert-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-inline.js rename to packages/slate/test/commands/insertFragment/selection/insert-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-middle.js b/packages/slate/test/commands/insertFragment/selection/insert-multiple-blocks-at-middle.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-middle.js rename to packages/slate/test/commands/insertFragment/selection/insert-multiple-blocks-at-middle.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-start.js b/packages/slate/test/commands/insertFragment/selection/insert-multiple-blocks-at-start.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-multiple-blocks-at-start.js rename to packages/slate/test/commands/insertFragment/selection/insert-multiple-blocks-at-start.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-multiple-texts.js b/packages/slate/test/commands/insertFragment/selection/insert-multiple-texts.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-multiple-texts.js rename to packages/slate/test/commands/insertFragment/selection/insert-multiple-texts.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-end.js b/packages/slate/test/commands/insertFragment/selection/insert-nested-blocks-at-end.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-end.js rename to packages/slate/test/commands/insertFragment/selection/insert-nested-blocks-at-end.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-middle.js b/packages/slate/test/commands/insertFragment/selection/insert-nested-blocks-at-middle.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-middle.js rename to packages/slate/test/commands/insertFragment/selection/insert-nested-blocks-at-middle.js diff --git a/packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-start.js b/packages/slate/test/commands/insertFragment/selection/insert-nested-blocks-at-start.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/insert-nested-blocks-at-start.js rename to packages/slate/test/commands/insertFragment/selection/insert-nested-blocks-at-start.js diff --git a/packages/slate/test/commands/value/insert-fragment/last-block-fragment-multiple.js b/packages/slate/test/commands/insertFragment/selection/last-block-fragment-multiple.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/last-block-fragment-multiple.js rename to packages/slate/test/commands/insertFragment/selection/last-block-fragment-multiple.js diff --git a/packages/slate/test/commands/value/insert-fragment/last-block-fragment-single.js b/packages/slate/test/commands/insertFragment/selection/last-block-fragment-single.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/last-block-fragment-single.js rename to packages/slate/test/commands/insertFragment/selection/last-block-fragment-single.js diff --git a/packages/slate/test/commands/value/insert-fragment/last-block-inline-fragment-single.js b/packages/slate/test/commands/insertFragment/selection/last-block-inline-fragment-single.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/last-block-inline-fragment-single.js rename to packages/slate/test/commands/insertFragment/selection/last-block-inline-fragment-single.js diff --git a/packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js b/packages/slate/test/commands/insertFragment/selection/lists/merge-lists.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/lists/merge-lists.js rename to packages/slate/test/commands/insertFragment/selection/lists/merge-lists.js diff --git a/packages/slate/test/commands/value/insert-fragment/marks/middle-block.js b/packages/slate/test/commands/insertFragment/selection/marks/middle-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/marks/middle-block.js rename to packages/slate/test/commands/insertFragment/selection/marks/middle-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js b/packages/slate/test/commands/insertFragment/selection/marks/multiple-marks-middle-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/marks/multiple-marks-middle-block.js rename to packages/slate/test/commands/insertFragment/selection/marks/multiple-marks-middle-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js b/packages/slate/test/commands/insertFragment/selection/merge-deep-nested.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/merge-deep-nested.js rename to packages/slate/test/commands/insertFragment/selection/merge-deep-nested.js diff --git a/packages/slate/test/commands/value/insert-fragment/merge-lists.js b/packages/slate/test/commands/insertFragment/selection/merge-lists.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/merge-lists.js rename to packages/slate/test/commands/insertFragment/selection/merge-lists.js diff --git a/packages/slate/test/commands/value/insert-fragment/middle-block.js b/packages/slate/test/commands/insertFragment/selection/middle-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/middle-block.js rename to packages/slate/test/commands/insertFragment/selection/middle-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/middle-fragment-adjacent-texts.js b/packages/slate/test/commands/insertFragment/selection/middle-fragment-adjacent-texts.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/middle-fragment-adjacent-texts.js rename to packages/slate/test/commands/insertFragment/selection/middle-fragment-adjacent-texts.js diff --git a/packages/slate/test/commands/value/insert-fragment/middle-inline-fragment-inline.js b/packages/slate/test/commands/insertFragment/selection/middle-inline-fragment-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/middle-inline-fragment-inline.js rename to packages/slate/test/commands/insertFragment/selection/middle-inline-fragment-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/middle-inline.js b/packages/slate/test/commands/insertFragment/selection/middle-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/middle-inline.js rename to packages/slate/test/commands/insertFragment/selection/middle-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/nested-block-fragment-nested-blocks.js b/packages/slate/test/commands/insertFragment/selection/nested-block-fragment-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/nested-block-fragment-nested-blocks.js rename to packages/slate/test/commands/insertFragment/selection/nested-block-fragment-nested-blocks.js diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/end-block.js b/packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/end-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/end-block.js rename to packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/end-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block-nested.js b/packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/middle-block-nested.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block-nested.js rename to packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/middle-block-nested.js diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block.js b/packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/middle-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/middle-block.js rename to packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/middle-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/start-block.js b/packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/start-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/nested-blocks-different-structure/start-block.js rename to packages/slate/test/commands/insertFragment/selection/nested-blocks-different-structure/start-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js b/packages/slate/test/commands/insertFragment/selection/nested-blocks-same-structure/end-block-nested.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/end-block-nested.js rename to packages/slate/test/commands/insertFragment/selection/nested-blocks-same-structure/end-block-nested.js diff --git a/packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js b/packages/slate/test/commands/insertFragment/selection/nested-blocks-same-structure/start-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/nested-blocks-same-structure/start-block.js rename to packages/slate/test/commands/insertFragment/selection/nested-blocks-same-structure/start-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/start-block-multiple-blocks.js b/packages/slate/test/commands/insertFragment/selection/start-block-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/start-block-multiple-blocks.js rename to packages/slate/test/commands/insertFragment/selection/start-block-multiple-blocks.js diff --git a/packages/slate/test/commands/value/insert-fragment/start-block-with-void-no-text.js b/packages/slate/test/commands/insertFragment/selection/start-block-with-void-no-text.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/start-block-with-void-no-text.js rename to packages/slate/test/commands/insertFragment/selection/start-block-with-void-no-text.js diff --git a/packages/slate/test/commands/value/insert-fragment/start-block.js b/packages/slate/test/commands/insertFragment/selection/start-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/start-block.js rename to packages/slate/test/commands/insertFragment/selection/start-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/start-inline.js b/packages/slate/test/commands/insertFragment/selection/start-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/start-inline.js rename to packages/slate/test/commands/insertFragment/selection/start-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/start-second-block.js b/packages/slate/test/commands/insertFragment/selection/start-second-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/start-second-block.js rename to packages/slate/test/commands/insertFragment/selection/start-second-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js b/packages/slate/test/commands/insertFragment/selection/tables/merge-cells-with-nested-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/tables/merge-cells-with-nested-blocks.js rename to packages/slate/test/commands/insertFragment/selection/tables/merge-cells-with-nested-blocks.js diff --git a/packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js b/packages/slate/test/commands/insertFragment/selection/tables/merge-into-empty-cells.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/tables/merge-into-empty-cells.js rename to packages/slate/test/commands/insertFragment/selection/tables/merge-into-empty-cells.js diff --git a/packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js b/packages/slate/test/commands/insertFragment/selection/tables/merge-into-full-cells.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/tables/merge-into-full-cells.js rename to packages/slate/test/commands/insertFragment/selection/tables/merge-into-full-cells.js diff --git a/packages/slate/test/commands/value/insert-fragment/with-delete-across-blocks.js b/packages/slate/test/commands/insertFragment/selection/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/with-delete-across-blocks.js rename to packages/slate/test/commands/insertFragment/selection/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/value/insert-fragment/with-previous-block.js b/packages/slate/test/commands/insertFragment/selection/with-previous-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/with-previous-block.js rename to packages/slate/test/commands/insertFragment/selection/with-previous-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-after-void.js b/packages/slate/test/commands/insertFragment/selection/words/adjacent-texts-after-void.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-after-void.js rename to packages/slate/test/commands/insertFragment/selection/words/adjacent-texts-after-void.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-end-first-block.js b/packages/slate/test/commands/insertFragment/selection/words/adjacent-texts-end-first-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-end-first-block.js rename to packages/slate/test/commands/insertFragment/selection/words/adjacent-texts-end-first-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-into-empty-block.js b/packages/slate/test/commands/insertFragment/selection/words/adjacent-texts-into-empty-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/adjacent-texts-into-empty-block.js rename to packages/slate/test/commands/insertFragment/selection/words/adjacent-texts-into-empty-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/after-inline.js b/packages/slate/test/commands/insertFragment/selection/words/after-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/after-inline.js rename to packages/slate/test/commands/insertFragment/selection/words/after-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/before-inline.js b/packages/slate/test/commands/insertFragment/selection/words/before-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/before-inline.js rename to packages/slate/test/commands/insertFragment/selection/words/before-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/end-block.js b/packages/slate/test/commands/insertFragment/selection/words/end-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/end-block.js rename to packages/slate/test/commands/insertFragment/selection/words/end-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/end-inline.js b/packages/slate/test/commands/insertFragment/selection/words/end-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/end-inline.js rename to packages/slate/test/commands/insertFragment/selection/words/end-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/middle-block.js b/packages/slate/test/commands/insertFragment/selection/words/middle-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/middle-block.js rename to packages/slate/test/commands/insertFragment/selection/words/middle-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/middle-inline.js b/packages/slate/test/commands/insertFragment/selection/words/middle-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/middle-inline.js rename to packages/slate/test/commands/insertFragment/selection/words/middle-inline.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/start-block.js b/packages/slate/test/commands/insertFragment/selection/words/start-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/start-block.js rename to packages/slate/test/commands/insertFragment/selection/words/start-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/start-second-block.js b/packages/slate/test/commands/insertFragment/selection/words/start-second-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/start-second-block.js rename to packages/slate/test/commands/insertFragment/selection/words/start-second-block.js diff --git a/packages/slate/test/commands/value/insert-fragment/words/with-delete-across-blocks.js b/packages/slate/test/commands/insertFragment/selection/words/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-fragment/words/with-delete-across-blocks.js rename to packages/slate/test/commands/insertFragment/selection/words/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/value/insert-inline/block-end.js b/packages/slate/test/commands/insertInline/selection/block-end.js similarity index 100% rename from packages/slate/test/commands/value/insert-inline/block-end.js rename to packages/slate/test/commands/insertInline/selection/block-end.js diff --git a/packages/slate/test/commands/value/insert-inline/block-middle.js b/packages/slate/test/commands/insertInline/selection/block-middle.js similarity index 100% rename from packages/slate/test/commands/value/insert-inline/block-middle.js rename to packages/slate/test/commands/insertInline/selection/block-middle.js diff --git a/packages/slate/test/commands/value/insert-inline/block-start.js b/packages/slate/test/commands/insertInline/selection/block-start.js similarity index 100% rename from packages/slate/test/commands/value/insert-inline/block-start.js rename to packages/slate/test/commands/insertInline/selection/block-start.js diff --git a/packages/slate/test/commands/value/insert-inline/inline-middle.js b/packages/slate/test/commands/insertInline/selection/inline-middle.js similarity index 100% rename from packages/slate/test/commands/value/insert-inline/inline-middle.js rename to packages/slate/test/commands/insertInline/selection/inline-middle.js diff --git a/packages/slate/test/commands/value/insert-inline/is-empty.js b/packages/slate/test/commands/insertInline/selection/is-empty.js similarity index 100% rename from packages/slate/test/commands/value/insert-inline/is-empty.js rename to packages/slate/test/commands/insertInline/selection/is-empty.js diff --git a/packages/slate/test/commands/value/insert-inline/is-void.js b/packages/slate/test/commands/insertInline/selection/is-void.js similarity index 100% rename from packages/slate/test/commands/value/insert-inline/is-void.js rename to packages/slate/test/commands/insertInline/selection/is-void.js diff --git a/packages/slate/test/commands/value/insert-inline/with-inline.js b/packages/slate/test/commands/insertInline/selection/with-inline.js similarity index 100% rename from packages/slate/test/commands/value/insert-inline/with-inline.js rename to packages/slate/test/commands/insertInline/selection/with-inline.js diff --git a/packages/slate/test/commands/path/insertNodeAtPath/block.js b/packages/slate/test/commands/insertNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/insertNodeAtPath/block.js rename to packages/slate/test/commands/insertNode/path/block.js diff --git a/packages/slate/test/commands/path/insertNodeAtPath/inline.js b/packages/slate/test/commands/insertNode/path/inline.js similarity index 100% rename from packages/slate/test/commands/path/insertNodeAtPath/inline.js rename to packages/slate/test/commands/insertNode/path/inline.js diff --git a/packages/slate/test/commands/path/insertNodeAtPath/text.js b/packages/slate/test/commands/insertNode/path/text.js similarity index 100% rename from packages/slate/test/commands/path/insertNodeAtPath/text.js rename to packages/slate/test/commands/insertNode/path/text.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/decoration-after-atomic.js b/packages/slate/test/commands/insertText/point/decoration-after-atomic.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/decoration-after-atomic.js rename to packages/slate/test/commands/insertText/point/decoration-after-atomic.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/decoration-before-atomic.js b/packages/slate/test/commands/insertText/point/decoration-before-atomic.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/decoration-before-atomic.js rename to packages/slate/test/commands/insertText/point/decoration-before-atomic.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/decoration-middle-atomic.js b/packages/slate/test/commands/insertText/point/decoration-middle-atomic.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/decoration-middle-atomic.js rename to packages/slate/test/commands/insertText/point/decoration-middle-atomic.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/selection-after.js b/packages/slate/test/commands/insertText/point/selection-after.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/selection-after.js rename to packages/slate/test/commands/insertText/point/selection-after.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/selection-before.js b/packages/slate/test/commands/insertText/point/selection-before.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/selection-before.js rename to packages/slate/test/commands/insertText/point/selection-before.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/selection-end.js b/packages/slate/test/commands/insertText/point/selection-end.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/selection-end.js rename to packages/slate/test/commands/insertText/point/selection-end.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/selection-middle.js b/packages/slate/test/commands/insertText/point/selection-middle.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/selection-middle.js rename to packages/slate/test/commands/insertText/point/selection-middle.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/selection-start.js b/packages/slate/test/commands/insertText/point/selection-start.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/selection-start.js rename to packages/slate/test/commands/insertText/point/selection-start.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/text-end.js b/packages/slate/test/commands/insertText/point/text-end.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/text-end.js rename to packages/slate/test/commands/insertText/point/text-end.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/text-middle.js b/packages/slate/test/commands/insertText/point/text-middle.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/text-middle.js rename to packages/slate/test/commands/insertText/point/text-middle.js diff --git a/packages/slate/test/commands/point/insertTextAtPoint/text-start.js b/packages/slate/test/commands/insertText/point/text-start.js similarity index 100% rename from packages/slate/test/commands/point/insertTextAtPoint/text-start.js rename to packages/slate/test/commands/insertText/point/text-start.js diff --git a/packages/slate/test/commands/insertText/range/after-mark.js b/packages/slate/test/commands/insertText/range/after-mark.js new file mode 100644 index 0000000000..8aff831545 --- /dev/null +++ b/packages/slate/test/commands/insertText/range/after-mark.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.insertText('a') +} + +export const input = ( + + + w + + or + + d + + +) + +export const output = ( + + + w + + ora + + d + + +) diff --git a/packages/slate/test/commands/value/insert-text/before-mark.js b/packages/slate/test/commands/insertText/range/before-mark.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/before-mark.js rename to packages/slate/test/commands/insertText/range/before-mark.js diff --git a/packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js b/packages/slate/test/commands/insertText/range/blocks-with-overlapping-marks.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/blocks-with-overlapping-marks.js rename to packages/slate/test/commands/insertText/range/blocks-with-overlapping-marks.js diff --git a/packages/slate/test/commands/value/insert-text/during-mark.js b/packages/slate/test/commands/insertText/range/during-mark.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/during-mark.js rename to packages/slate/test/commands/insertText/range/during-mark.js diff --git a/packages/slate/test/commands/value/insert-text/empty-block-with-mark.js b/packages/slate/test/commands/insertText/range/empty-block-with-mark.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/empty-block-with-mark.js rename to packages/slate/test/commands/insertText/range/empty-block-with-mark.js diff --git a/packages/slate/test/commands/insertText/range/expanded-with-mark.js b/packages/slate/test/commands/insertText/range/expanded-with-mark.js new file mode 100644 index 0000000000..c019573790 --- /dev/null +++ b/packages/slate/test/commands/insertText/range/expanded-with-mark.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + debugger + editor.insertText('a') + debugger + editor.insertText('b') + debugger +} + +export const input = ( + + + + one + + + + two + + +) + +export const output = ( + + + ab + + +) diff --git a/packages/slate/test/commands/value/insert-text/first-character.js b/packages/slate/test/commands/insertText/range/first-character.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/first-character.js rename to packages/slate/test/commands/insertText/range/first-character.js diff --git a/packages/slate/test/commands/value/insert-text/first-space.js b/packages/slate/test/commands/insertText/range/first-space.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/first-space.js rename to packages/slate/test/commands/insertText/range/first-space.js diff --git a/packages/slate/test/commands/value/insert-text/first-words.js b/packages/slate/test/commands/insertText/range/first-words.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/first-words.js rename to packages/slate/test/commands/insertText/range/first-words.js diff --git a/packages/slate/test/commands/value/insert-text/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/insertText/range/hanging-selection-multiple-blocks.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/hanging-selection-multiple-blocks.js rename to packages/slate/test/commands/insertText/range/hanging-selection-multiple-blocks.js diff --git a/packages/slate/test/commands/value/insert-text/hanging-selection-single-block.js b/packages/slate/test/commands/insertText/range/hanging-selection-single-block.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/hanging-selection-single-block.js rename to packages/slate/test/commands/insertText/range/hanging-selection-single-block.js diff --git a/packages/slate/test/commands/selection/blur/basic.js b/packages/slate/test/commands/insertText/range/inside-void.js similarity index 68% rename from packages/slate/test/commands/selection/blur/basic.js rename to packages/slate/test/commands/insertText/range/inside-void.js index 62b46adf76..019604ea6b 100644 --- a/packages/slate/test/commands/selection/blur/basic.js +++ b/packages/slate/test/commands/insertText/range/inside-void.js @@ -3,21 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.blur() + editor.insertText('a') } export const input = ( - - one + + ) export const output = ( - - one + + ) diff --git a/packages/slate/test/commands/value/insert-text/last-character.js b/packages/slate/test/commands/insertText/range/last-character.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/last-character.js rename to packages/slate/test/commands/insertText/range/last-character.js diff --git a/packages/slate/test/commands/value/insert-text/last-space.js b/packages/slate/test/commands/insertText/range/last-space.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/last-space.js rename to packages/slate/test/commands/insertText/range/last-space.js diff --git a/packages/slate/test/commands/value/insert-text/last-words.js b/packages/slate/test/commands/insertText/range/last-words.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/last-words.js rename to packages/slate/test/commands/insertText/range/last-words.js diff --git a/packages/slate/test/commands/value/insert-text/middle-character.js b/packages/slate/test/commands/insertText/range/middle-character.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/middle-character.js rename to packages/slate/test/commands/insertText/range/middle-character.js diff --git a/packages/slate/test/commands/value/insert-text/middle-space.js b/packages/slate/test/commands/insertText/range/middle-space.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/middle-space.js rename to packages/slate/test/commands/insertText/range/middle-space.js diff --git a/packages/slate/test/commands/value/insert-text/middle-words.js b/packages/slate/test/commands/insertText/range/middle-words.js similarity index 100% rename from packages/slate/test/commands/value/insert-text/middle-words.js rename to packages/slate/test/commands/insertText/range/middle-words.js diff --git a/packages/slate/test/commands/path/liftNodeAtPath/block.js b/packages/slate/test/commands/liftNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/liftNodeAtPath/block.js rename to packages/slate/test/commands/liftNode/path/block.js diff --git a/packages/slate/test/commands/path/liftNodeAtPath/first-block.js b/packages/slate/test/commands/liftNode/path/first-block.js similarity index 100% rename from packages/slate/test/commands/path/liftNodeAtPath/first-block.js rename to packages/slate/test/commands/liftNode/path/first-block.js diff --git a/packages/slate/test/commands/path/liftNodeAtPath/last-block.js b/packages/slate/test/commands/liftNode/path/last-block.js similarity index 100% rename from packages/slate/test/commands/path/liftNodeAtPath/last-block.js rename to packages/slate/test/commands/liftNode/path/last-block.js diff --git a/packages/slate/test/commands/path/liftNodeAtPath/middle-block.js b/packages/slate/test/commands/liftNode/path/middle-block.js similarity index 100% rename from packages/slate/test/commands/path/liftNodeAtPath/middle-block.js rename to packages/slate/test/commands/liftNode/path/middle-block.js diff --git a/packages/slate/test/commands/path/mergeNodeAtPath/block.js b/packages/slate/test/commands/mergeNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/mergeNodeAtPath/block.js rename to packages/slate/test/commands/mergeNode/path/block.js diff --git a/packages/slate/test/commands/selection/moveAnchor/backward.js b/packages/slate/test/commands/move/anchor/backward.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/backward.js rename to packages/slate/test/commands/move/anchor/backward.js diff --git a/packages/slate/test/commands/selection/moveAnchor/basic.js b/packages/slate/test/commands/move/anchor/basic.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/basic.js rename to packages/slate/test/commands/move/anchor/basic.js diff --git a/packages/slate/test/commands/selection/moveAnchor/collapsed.js b/packages/slate/test/commands/move/anchor/collapsed.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/collapsed.js rename to packages/slate/test/commands/move/anchor/collapsed.js diff --git a/packages/slate/test/commands/selection/moveAnchor/distance.js b/packages/slate/test/commands/move/anchor/distance.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/distance.js rename to packages/slate/test/commands/move/anchor/distance.js diff --git a/packages/slate/test/commands/selection/moveAnchor/reverse-backward.js b/packages/slate/test/commands/move/anchor/reverse-backward.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/reverse-backward.js rename to packages/slate/test/commands/move/anchor/reverse-backward.js diff --git a/packages/slate/test/commands/selection/moveAnchor/reverse-basic.js b/packages/slate/test/commands/move/anchor/reverse-basic.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/reverse-basic.js rename to packages/slate/test/commands/move/anchor/reverse-basic.js diff --git a/packages/slate/test/commands/selection/moveAnchor/reverse-collapsed.js b/packages/slate/test/commands/move/anchor/reverse-collapsed.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/reverse-collapsed.js rename to packages/slate/test/commands/move/anchor/reverse-collapsed.js diff --git a/packages/slate/test/commands/selection/moveAnchor/reverse-distance.js b/packages/slate/test/commands/move/anchor/reverse-distance.js similarity index 100% rename from packages/slate/test/commands/selection/moveAnchor/reverse-distance.js rename to packages/slate/test/commands/move/anchor/reverse-distance.js diff --git a/packages/slate/test/commands/selection/move/backward-reverse.js b/packages/slate/test/commands/move/both/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/move/backward-reverse.js rename to packages/slate/test/commands/move/both/backward-reverse.js diff --git a/packages/slate/test/commands/selection/move/backward.js b/packages/slate/test/commands/move/both/backward.js similarity index 100% rename from packages/slate/test/commands/selection/move/backward.js rename to packages/slate/test/commands/move/both/backward.js diff --git a/packages/slate/test/commands/selection/move/basic-reverse.js b/packages/slate/test/commands/move/both/basic-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/move/basic-reverse.js rename to packages/slate/test/commands/move/both/basic-reverse.js diff --git a/packages/slate/test/commands/selection/move/collapsed.js b/packages/slate/test/commands/move/both/collapsed.js similarity index 100% rename from packages/slate/test/commands/selection/move/collapsed.js rename to packages/slate/test/commands/move/both/collapsed.js diff --git a/packages/slate/test/commands/selection/move/distance-reverse.js b/packages/slate/test/commands/move/both/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/move/distance-reverse.js rename to packages/slate/test/commands/move/both/distance-reverse.js diff --git a/packages/slate/test/commands/selection/move/distance.js b/packages/slate/test/commands/move/both/distance.js similarity index 100% rename from packages/slate/test/commands/selection/move/distance.js rename to packages/slate/test/commands/move/both/distance.js diff --git a/packages/slate/test/commands/selection/move/expanded-reverse.js b/packages/slate/test/commands/move/both/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/move/expanded-reverse.js rename to packages/slate/test/commands/move/both/expanded-reverse.js diff --git a/packages/slate/test/commands/selection/move/expanded.js b/packages/slate/test/commands/move/both/expanded.js similarity index 100% rename from packages/slate/test/commands/selection/move/expanded.js rename to packages/slate/test/commands/move/both/expanded.js diff --git a/packages/slate/test/commands/selection/move/unit-word-reverse.js b/packages/slate/test/commands/move/both/unit-word-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/move/unit-word-reverse.js rename to packages/slate/test/commands/move/both/unit-word-reverse.js diff --git a/packages/slate/test/commands/selection/move/unit-word.js b/packages/slate/test/commands/move/both/unit-word.js similarity index 100% rename from packages/slate/test/commands/selection/move/unit-word.js rename to packages/slate/test/commands/move/both/unit-word.js diff --git a/packages/slate/test/commands/selection/moveEnd/backward-reverse.js b/packages/slate/test/commands/move/end/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/backward-reverse.js rename to packages/slate/test/commands/move/end/backward-reverse.js diff --git a/packages/slate/test/commands/selection/moveEnd/backward.js b/packages/slate/test/commands/move/end/backward.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/backward.js rename to packages/slate/test/commands/move/end/backward.js diff --git a/packages/slate/test/commands/selection/moveEnd/collapsed-reverse.js b/packages/slate/test/commands/move/end/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/collapsed-reverse.js rename to packages/slate/test/commands/move/end/collapsed-reverse.js diff --git a/packages/slate/test/commands/selection/moveEnd/collapsed.js b/packages/slate/test/commands/move/end/collapsed.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/collapsed.js rename to packages/slate/test/commands/move/end/collapsed.js diff --git a/packages/slate/test/commands/selection/moveEnd/distance-reverse.js b/packages/slate/test/commands/move/end/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/distance-reverse.js rename to packages/slate/test/commands/move/end/distance-reverse.js diff --git a/packages/slate/test/commands/selection/moveEnd/distance.js b/packages/slate/test/commands/move/end/distance.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/distance.js rename to packages/slate/test/commands/move/end/distance.js diff --git a/packages/slate/test/commands/selection/moveEnd/expanded-reverse.js b/packages/slate/test/commands/move/end/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/expanded-reverse.js rename to packages/slate/test/commands/move/end/expanded-reverse.js diff --git a/packages/slate/test/commands/selection/moveEnd/expanded.js b/packages/slate/test/commands/move/end/expanded.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/expanded.js rename to packages/slate/test/commands/move/end/expanded.js diff --git a/packages/slate/test/commands/selection/moveEnd/from-backward-reverse.js b/packages/slate/test/commands/move/end/from-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/from-backward-reverse.js rename to packages/slate/test/commands/move/end/from-backward-reverse.js diff --git a/packages/slate/test/commands/selection/moveEnd/to-backward-reverse.js b/packages/slate/test/commands/move/end/to-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveEnd/to-backward-reverse.js rename to packages/slate/test/commands/move/end/to-backward-reverse.js diff --git a/packages/slate/test/commands/selection/moveFocus/backward.js b/packages/slate/test/commands/move/focus/backward.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/backward.js rename to packages/slate/test/commands/move/focus/backward.js diff --git a/packages/slate/test/commands/selection/moveFocus/collapsed-reverse.js b/packages/slate/test/commands/move/focus/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/collapsed-reverse.js rename to packages/slate/test/commands/move/focus/collapsed-reverse.js diff --git a/packages/slate/test/commands/selection/moveFocus/collapsed.js b/packages/slate/test/commands/move/focus/collapsed.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/collapsed.js rename to packages/slate/test/commands/move/focus/collapsed.js diff --git a/packages/slate/test/commands/selection/moveFocus/distance-reverse.js b/packages/slate/test/commands/move/focus/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/distance-reverse.js rename to packages/slate/test/commands/move/focus/distance-reverse.js diff --git a/packages/slate/test/commands/selection/moveFocus/distance.js b/packages/slate/test/commands/move/focus/distance.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/distance.js rename to packages/slate/test/commands/move/focus/distance.js diff --git a/packages/slate/test/commands/selection/moveFocus/expanded-reverse.js b/packages/slate/test/commands/move/focus/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/expanded-reverse.js rename to packages/slate/test/commands/move/focus/expanded-reverse.js diff --git a/packages/slate/test/commands/selection/moveFocus/expanded.js b/packages/slate/test/commands/move/focus/expanded.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/expanded.js rename to packages/slate/test/commands/move/focus/expanded.js diff --git a/packages/slate/test/commands/selection/moveFocus/to-backward-reverse.js b/packages/slate/test/commands/move/focus/to-backward-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveFocus/to-backward-reverse.js rename to packages/slate/test/commands/move/focus/to-backward-reverse.js diff --git a/packages/slate/test/commands/selection/moveStart/backward-reverse.js b/packages/slate/test/commands/move/start/backward-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/backward-reverse.js rename to packages/slate/test/commands/move/start/backward-reverse.js diff --git a/packages/slate/test/commands/selection/moveStart/backward.js b/packages/slate/test/commands/move/start/backward.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/backward.js rename to packages/slate/test/commands/move/start/backward.js diff --git a/packages/slate/test/commands/selection/moveStart/collapsed-reverse.js b/packages/slate/test/commands/move/start/collapsed-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/collapsed-reverse.js rename to packages/slate/test/commands/move/start/collapsed-reverse.js diff --git a/packages/slate/test/commands/selection/moveStart/collapsed.js b/packages/slate/test/commands/move/start/collapsed.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/collapsed.js rename to packages/slate/test/commands/move/start/collapsed.js diff --git a/packages/slate/test/commands/selection/moveStart/distance-reverse.js b/packages/slate/test/commands/move/start/distance-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/distance-reverse.js rename to packages/slate/test/commands/move/start/distance-reverse.js diff --git a/packages/slate/test/commands/selection/moveStart/distance.js b/packages/slate/test/commands/move/start/distance.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/distance.js rename to packages/slate/test/commands/move/start/distance.js diff --git a/packages/slate/test/commands/selection/moveStart/expanded-reverse.js b/packages/slate/test/commands/move/start/expanded-reverse.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/expanded-reverse.js rename to packages/slate/test/commands/move/start/expanded-reverse.js diff --git a/packages/slate/test/commands/selection/moveStart/expanded.js b/packages/slate/test/commands/move/start/expanded.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/expanded.js rename to packages/slate/test/commands/move/start/expanded.js diff --git a/packages/slate/test/commands/selection/moveStart/from-backward.js b/packages/slate/test/commands/move/start/from-backward.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/from-backward.js rename to packages/slate/test/commands/move/start/from-backward.js diff --git a/packages/slate/test/commands/selection/moveStart/to-backward.js b/packages/slate/test/commands/move/start/to-backward.js similarity index 100% rename from packages/slate/test/commands/selection/moveStart/to-backward.js rename to packages/slate/test/commands/move/start/to-backward.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/block.js b/packages/slate/test/commands/moveNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/block.js rename to packages/slate/test/commands/moveNode/path/block.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/inline.js b/packages/slate/test/commands/moveNode/path/inline.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/inline.js rename to packages/slate/test/commands/moveNode/path/inline.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/inside-next.js b/packages/slate/test/commands/moveNode/path/inside-next.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/inside-next.js rename to packages/slate/test/commands/moveNode/path/inside-next.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/nested.js b/packages/slate/test/commands/moveNode/path/nested.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/nested.js rename to packages/slate/test/commands/moveNode/path/nested.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/noop-equal.js b/packages/slate/test/commands/moveNode/path/noop-equal.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/noop-equal.js rename to packages/slate/test/commands/moveNode/path/noop-equal.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/sibling-swap.js b/packages/slate/test/commands/moveNode/path/sibling-swap.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/sibling-swap.js rename to packages/slate/test/commands/moveNode/path/sibling-swap.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/text-nodes.js b/packages/slate/test/commands/moveNode/path/text-nodes.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/text-nodes.js rename to packages/slate/test/commands/moveNode/path/text-nodes.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/text.js b/packages/slate/test/commands/moveNode/path/text.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/text.js rename to packages/slate/test/commands/moveNode/path/text.js diff --git a/packages/slate/test/commands/path/moveNodeAtPath/to-sibling.js b/packages/slate/test/commands/moveNode/path/to-sibling.js similarity index 100% rename from packages/slate/test/commands/path/moveNodeAtPath/to-sibling.js rename to packages/slate/test/commands/moveNode/path/to-sibling.js diff --git a/packages/slate/test/commands/path/replaceNodeAtPath/block.js b/packages/slate/test/commands/path/replaceNodeAtPath/block.js deleted file mode 100644 index 3c948215f3..0000000000 --- a/packages/slate/test/commands/path/replaceNodeAtPath/block.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.replaceNodeAtPath([1], another) -} - -export const input = ( - - one - two - -) - -export const output = ( - - one - another - -) diff --git a/packages/slate/test/commands/path/replaceNodeAtPath/inline.js b/packages/slate/test/commands/path/replaceNodeAtPath/inline.js deleted file mode 100644 index a5544b101e..0000000000 --- a/packages/slate/test/commands/path/replaceNodeAtPath/inline.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.replaceNodeAtPath([0, 1], another) -} - -export const input = ( - - - one - two - three - - -) - -export const output = ( - - - one - another - three - - -) diff --git a/packages/slate/test/commands/path/replaceNodeAtPath/text.js b/packages/slate/test/commands/path/replaceNodeAtPath/text.js deleted file mode 100644 index fe2c4e6636..0000000000 --- a/packages/slate/test/commands/path/replaceNodeAtPath/text.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.replaceNodeAtPath([1, 0], three) -} - -export const input = ( - - one - two - -) - -export const output = ( - - one - three - -) diff --git a/packages/slate/test/commands/path/pluckNodeAtPath/block-multiple.js b/packages/slate/test/commands/pluckNode/path/block-multiple.js similarity index 100% rename from packages/slate/test/commands/path/pluckNodeAtPath/block-multiple.js rename to packages/slate/test/commands/pluckNode/path/block-multiple.js diff --git a/packages/slate/test/commands/path/pluckNodeAtPath/block.js b/packages/slate/test/commands/pluckNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/pluckNodeAtPath/block.js rename to packages/slate/test/commands/pluckNode/path/block.js diff --git a/packages/slate/test/commands/point/removeTextAtPoint/adjacent-non-void-inlines.js b/packages/slate/test/commands/point/removeTextAtPoint/adjacent-non-void-inlines.js deleted file mode 100644 index a77f2c8138..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/adjacent-non-void-inlines.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const input = ( - - - - one - a - two - - - -) - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 2], offset: 0 }, 1) -} - -export const output = ( - - - - one - - two - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/decoration-after-atomic.js b/packages/slate/test/commands/point/removeTextAtPoint/decoration-after-atomic.js deleted file mode 100644 index 14684dbd6d..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/decoration-after-atomic.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 3 }, 1) -} - -export const input = ( - - - - w - or - d - - - -) - -export const output = ( - - - w - or - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/decoration-before-atomic.js b/packages/slate/test/commands/point/removeTextAtPoint/decoration-before-atomic.js deleted file mode 100644 index 433e40f58f..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/decoration-before-atomic.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 0 }, 1) -} - -export const input = ( - - - - w - or - d - - - -) - -export const output = ( - - - - or - d - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/decoration-middle-atomic.js b/packages/slate/test/commands/point/removeTextAtPoint/decoration-middle-atomic.js deleted file mode 100644 index d351803d76..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/decoration-middle-atomic.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 2 }, 1) -} - -export const input = ( - - - - w - or - d - - - -) - -export const output = ( - - wod - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/inline-last-character.js b/packages/slate/test/commands/point/removeTextAtPoint/inline-last-character.js deleted file mode 100644 index 2c288535d7..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/inline-last-character.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 1, 0], offset: 0 }, 1) -} - -export const input = ( - - - - - a - - - - -) - -export const output = ( - - - - - - - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/inline-nested-last-character.js b/packages/slate/test/commands/point/removeTextAtPoint/inline-nested-last-character.js deleted file mode 100644 index 9f45ae58e5..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/inline-nested-last-character.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 1, 1, 0], offset: 0 }, 1) -} - -export const input = ( - - - - - - - - a - - - - - - - -) - -export const output = ( - - - - - - - - - - - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/inline-void.js b/packages/slate/test/commands/point/removeTextAtPoint/inline-void.js deleted file mode 100644 index 6e8e14afdf..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/inline-void.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 1, 0], offset: 0 }, 1) -} - -export const input = ( - - - - - - a - - - - - -) - -export const output = ( - - - - - - - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/inline.js b/packages/slate/test/commands/point/removeTextAtPoint/inline.js deleted file mode 100644 index 17a361d8bc..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/inline.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 1, 0], offset: 3 }, 1) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wor - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/next-void-inline.js b/packages/slate/test/commands/point/removeTextAtPoint/next-void-inline.js deleted file mode 100644 index c2856234c1..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/next-void-inline.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 2], offset: 0 }, 1) -} - -export const input = ( - - - - one - a - - - - - - -) - -export const output = ( - - - - one - - - - - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/previous-void-inline.js b/packages/slate/test/commands/point/removeTextAtPoint/previous-void-inline.js deleted file mode 100644 index bcfac77de8..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/previous-void-inline.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 2], offset: 0 }, 1) -} - -export const input = ( - - - - - - - a - two - - - -) - -export const output = ( - - - - - - - - two - - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/selection-after.js b/packages/slate/test/commands/point/removeTextAtPoint/selection-after.js deleted file mode 100644 index dae6b7a2d7..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/selection-after.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 3 }, 1) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - wor - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/selection-before.js b/packages/slate/test/commands/point/removeTextAtPoint/selection-before.js deleted file mode 100644 index fe23dfb411..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/selection-before.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 0 }, 1) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - ord - - -) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/selection-start.js b/packages/slate/test/commands/point/removeTextAtPoint/selection-start.js deleted file mode 100644 index 7efaebd178..0000000000 --- a/packages/slate/test/commands/point/removeTextAtPoint/selection-start.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 2 }, 1) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - wod - - -) diff --git a/packages/slate/test/commands/path/replaceTextAtPath/basic.js b/packages/slate/test/commands/removeMarks/path/basic.js similarity index 65% rename from packages/slate/test/commands/path/replaceTextAtPath/basic.js rename to packages/slate/test/commands/removeMarks/path/basic.js index 0d1c6c40e5..26099ae1a8 100644 --- a/packages/slate/test/commands/path/replaceTextAtPath/basic.js +++ b/packages/slate/test/commands/removeMarks/path/basic.js @@ -3,21 +3,19 @@ import { h } from '../../../helpers' export const run = editor => { - editor.replaceTextAtPath([0, 0], 'two') + editor.removeMarks([{ key: 'a' }], { at: [0, 0] }) } export const input = ( - one + word ) export const output = ( - - two - + word ) diff --git a/packages/slate/test/commands/removeMarks/range/basic.js b/packages/slate/test/commands/removeMarks/range/basic.js new file mode 100644 index 0000000000..9f093b1533 --- /dev/null +++ b/packages/slate/test/commands/removeMarks/range/basic.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeMarks([{ key: 'a' }], { + at: { + anchor: { path: [0, 1], offset: 0 }, + focus: { path: [0, 1], offset: 2 }, + }, + }) +} + +export const input = ( + + + w + or + d + + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/commands/removeMarks/selection/across-blocks.js b/packages/slate/test/commands/removeMarks/selection/across-blocks.js new file mode 100644 index 0000000000..83b1e7e14f --- /dev/null +++ b/packages/slate/test/commands/removeMarks/selection/across-blocks.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeMarks([{ key: 'a' }]) +} + +export const input = ( + + + wo + rd + + + an + other + + +) + +export const output = ( + + + word + + + another + + +) diff --git a/packages/slate/test/commands/value/replace-mark/across-inlines.js b/packages/slate/test/commands/removeMarks/selection/across-inlines.js similarity index 65% rename from packages/slate/test/commands/value/replace-mark/across-inlines.js rename to packages/slate/test/commands/removeMarks/selection/across-inlines.js index e3f1ea786e..cdb491c6af 100644 --- a/packages/slate/test/commands/value/replace-mark/across-inlines.js +++ b/packages/slate/test/commands/removeMarks/selection/across-inlines.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.replaceMark('italic', 'bold') + editor.removeMarks([{ key: 'a' }]) } export const input = ( @@ -11,17 +11,15 @@ export const input = ( - wo - - rd - + wo + rd - an + an other @@ -34,18 +32,14 @@ export const output = ( - wo - - rd - + word - + - + - an - other + another diff --git a/packages/slate/test/commands/value/remove-mark/collapsed-selection.js b/packages/slate/test/commands/removeMarks/selection/collapsed-selection.js similarity index 90% rename from packages/slate/test/commands/value/remove-mark/collapsed-selection.js rename to packages/slate/test/commands/removeMarks/selection/collapsed-selection.js index 216686bbf8..da510a14d4 100644 --- a/packages/slate/test/commands/value/remove-mark/collapsed-selection.js +++ b/packages/slate/test/commands/removeMarks/selection/collapsed-selection.js @@ -4,7 +4,7 @@ import { h } from '../../../helpers' export const run = editor => { editor.addMarks([{ key: 'a' }]) - editor.removeMark('bold') + editor.removeMarks([{ key: 'a' }]) editor.insertText('a') } diff --git a/packages/slate/test/commands/value/remove-mark/existing-marks.js b/packages/slate/test/commands/removeMarks/selection/existing-marks.js similarity index 92% rename from packages/slate/test/commands/value/remove-mark/existing-marks.js rename to packages/slate/test/commands/removeMarks/selection/existing-marks.js index 87f73f54fd..0cd0b023ff 100644 --- a/packages/slate/test/commands/value/remove-mark/existing-marks.js +++ b/packages/slate/test/commands/removeMarks/selection/existing-marks.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeMark('bold') + editor.removeMarks([{ key: 'a' }]) } export const input = ( diff --git a/packages/slate/test/commands/value/replace-mark/first-character.js b/packages/slate/test/commands/removeMarks/selection/first-character.js similarity index 74% rename from packages/slate/test/commands/value/replace-mark/first-character.js rename to packages/slate/test/commands/removeMarks/selection/first-character.js index 05a48f3ecf..42e78081ec 100644 --- a/packages/slate/test/commands/value/replace-mark/first-character.js +++ b/packages/slate/test/commands/removeMarks/selection/first-character.js @@ -3,14 +3,14 @@ import { h } from '../../../helpers' export const run = editor => { - editor.replaceMark('italic', 'bold') + editor.removeMarks([{ key: 'a' }]) } export const input = ( - w + w ord @@ -19,9 +19,7 @@ export const input = ( export const output = ( - - w - ord + word ) diff --git a/packages/slate/test/commands/value/replace-mark/last-character.js b/packages/slate/test/commands/removeMarks/selection/last-character.js similarity index 72% rename from packages/slate/test/commands/value/replace-mark/last-character.js rename to packages/slate/test/commands/removeMarks/selection/last-character.js index c592127b31..295dd078c9 100644 --- a/packages/slate/test/commands/value/replace-mark/last-character.js +++ b/packages/slate/test/commands/removeMarks/selection/last-character.js @@ -3,14 +3,14 @@ import { h } from '../../../helpers' export const run = editor => { - editor.replaceMark('italic', 'bold') + editor.removeMarks([{ key: 'a' }]) } export const input = ( wor - + d @@ -20,10 +20,7 @@ export const input = ( export const output = ( - wor - - d - + word ) diff --git a/packages/slate/test/commands/value/replace-mark/middle-character.js b/packages/slate/test/commands/removeMarks/selection/middle-character.js similarity index 72% rename from packages/slate/test/commands/value/replace-mark/middle-character.js rename to packages/slate/test/commands/removeMarks/selection/middle-character.js index 1fc1224975..4fa99cb057 100644 --- a/packages/slate/test/commands/value/replace-mark/middle-character.js +++ b/packages/slate/test/commands/removeMarks/selection/middle-character.js @@ -3,14 +3,14 @@ import { h } from '../../../helpers' export const run = editor => { - editor.replaceMark('italic', 'bold') + editor.removeMarks([{ key: 'a' }]) } export const input = ( w - + o rd @@ -21,11 +21,7 @@ export const input = ( export const output = ( - w - - o - - rd + word ) diff --git a/packages/slate/test/commands/removeMarks/selection/part-of-mark-backward.js b/packages/slate/test/commands/removeMarks/selection/part-of-mark-backward.js new file mode 100644 index 0000000000..d7ed4158cd --- /dev/null +++ b/packages/slate/test/commands/removeMarks/selection/part-of-mark-backward.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeMarks([{ key: 'a' }]) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wor + + d + + + +) diff --git a/packages/slate/test/commands/removeMarks/selection/part-of-mark.js b/packages/slate/test/commands/removeMarks/selection/part-of-mark.js new file mode 100644 index 0000000000..9b3df3a7dd --- /dev/null +++ b/packages/slate/test/commands/removeMarks/selection/part-of-mark.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeMarks([{ key: 'a' }]) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + wor + + d + + + +) diff --git a/packages/slate/test/commands/removeMarks/selection/whole-word.js b/packages/slate/test/commands/removeMarks/selection/whole-word.js new file mode 100644 index 0000000000..d52b6865b0 --- /dev/null +++ b/packages/slate/test/commands/removeMarks/selection/whole-word.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.removeMarks([{ key: 'a' }]) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/selection/select/basic.js b/packages/slate/test/commands/select/basic.js similarity index 100% rename from packages/slate/test/commands/selection/select/basic.js rename to packages/slate/test/commands/select/basic.js diff --git a/packages/slate/test/commands/value/set-block/across-blocks.js b/packages/slate/test/commands/setBlocks/selection/across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/set-block/across-blocks.js rename to packages/slate/test/commands/setBlocks/selection/across-blocks.js diff --git a/packages/slate/test/commands/value/set-block/across-inlines.js b/packages/slate/test/commands/setBlocks/selection/across-inlines.js similarity index 100% rename from packages/slate/test/commands/value/set-block/across-inlines.js rename to packages/slate/test/commands/setBlocks/selection/across-inlines.js diff --git a/packages/slate/test/commands/value/set-block/data-only.js b/packages/slate/test/commands/setBlocks/selection/data-only.js similarity index 100% rename from packages/slate/test/commands/value/set-block/data-only.js rename to packages/slate/test/commands/setBlocks/selection/data-only.js diff --git a/packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js b/packages/slate/test/commands/setBlocks/selection/hanging-selection-across-inlines.js similarity index 100% rename from packages/slate/test/commands/value/set-block/hanging-selection-across-inlines.js rename to packages/slate/test/commands/setBlocks/selection/hanging-selection-across-inlines.js diff --git a/packages/slate/test/commands/value/set-block/hanging-selection.js b/packages/slate/test/commands/setBlocks/selection/hanging-selection.js similarity index 100% rename from packages/slate/test/commands/value/set-block/hanging-selection.js rename to packages/slate/test/commands/setBlocks/selection/hanging-selection.js diff --git a/packages/slate/test/commands/value/set-block/nested-block.js b/packages/slate/test/commands/setBlocks/selection/nested-block.js similarity index 100% rename from packages/slate/test/commands/value/set-block/nested-block.js rename to packages/slate/test/commands/setBlocks/selection/nested-block.js diff --git a/packages/slate/test/commands/value/set-block/single-block-string-shorthand.js b/packages/slate/test/commands/setBlocks/selection/single-block-string-shorthand.js similarity index 100% rename from packages/slate/test/commands/value/set-block/single-block-string-shorthand.js rename to packages/slate/test/commands/setBlocks/selection/single-block-string-shorthand.js diff --git a/packages/slate/test/commands/value/set-block/single-block.js b/packages/slate/test/commands/setBlocks/selection/single-block.js similarity index 100% rename from packages/slate/test/commands/value/set-block/single-block.js rename to packages/slate/test/commands/setBlocks/selection/single-block.js diff --git a/packages/slate/test/commands/value/set-block/with-is-void.js b/packages/slate/test/commands/setBlocks/selection/with-is-void.js similarity index 100% rename from packages/slate/test/commands/value/set-block/with-is-void.js rename to packages/slate/test/commands/setBlocks/selection/with-is-void.js diff --git a/packages/slate/test/commands/value/set-inline/across-inlines.js b/packages/slate/test/commands/setInlines/selection/across-inlines.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/across-inlines.js rename to packages/slate/test/commands/setInlines/selection/across-inlines.js diff --git a/packages/slate/test/commands/value/set-inline/data-only.js b/packages/slate/test/commands/setInlines/selection/data-only.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/data-only.js rename to packages/slate/test/commands/setInlines/selection/data-only.js diff --git a/packages/slate/test/commands/value/set-inline/nested-inline.js b/packages/slate/test/commands/setInlines/selection/nested-inline.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/nested-inline.js rename to packages/slate/test/commands/setInlines/selection/nested-inline.js diff --git a/packages/slate/test/commands/value/set-inline/single-inline-string-shorthand.js b/packages/slate/test/commands/setInlines/selection/single-inline-string-shorthand.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/single-inline-string-shorthand.js rename to packages/slate/test/commands/setInlines/selection/single-inline-string-shorthand.js diff --git a/packages/slate/test/commands/value/set-inline/single-inline.js b/packages/slate/test/commands/setInlines/selection/single-inline.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/single-inline.js rename to packages/slate/test/commands/setInlines/selection/single-inline.js diff --git a/packages/slate/test/commands/value/set-inline/with-data-object.js b/packages/slate/test/commands/setInlines/selection/with-data-object.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/with-data-object.js rename to packages/slate/test/commands/setInlines/selection/with-data-object.js diff --git a/packages/slate/test/commands/value/set-inline/with-data.js b/packages/slate/test/commands/setInlines/selection/with-data.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/with-data.js rename to packages/slate/test/commands/setInlines/selection/with-data.js diff --git a/packages/slate/test/commands/value/set-inline/with-is-void.js b/packages/slate/test/commands/setInlines/selection/with-is-void.js similarity index 100% rename from packages/slate/test/commands/value/set-inline/with-is-void.js rename to packages/slate/test/commands/setInlines/selection/with-is-void.js diff --git a/packages/slate/test/commands/path/setMarkAtPath/basic.js b/packages/slate/test/commands/setMarks/path/basic.js similarity index 67% rename from packages/slate/test/commands/path/setMarkAtPath/basic.js rename to packages/slate/test/commands/setMarks/path/basic.js index e32a2cd7ce..fae67c79e1 100644 --- a/packages/slate/test/commands/path/setMarkAtPath/basic.js +++ b/packages/slate/test/commands/setMarks/path/basic.js @@ -3,15 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setMarkAtPath( - [0, 0], - { - key: 'a', - }, - { - key: 'b', - } - ) + editor.setMarks([{ key: 'a' }], { thing: true }, { at: [0, 0] }) } export const input = ( @@ -25,7 +17,9 @@ export const input = ( export const output = ( - word + + word + ) diff --git a/packages/slate/test/commands/setMarks/range/basic.js b/packages/slate/test/commands/setMarks/range/basic.js new file mode 100644 index 0000000000..30546d3385 --- /dev/null +++ b/packages/slate/test/commands/setMarks/range/basic.js @@ -0,0 +1,38 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setMarks( + [{ key: 'a' }], + { thing: true }, + { + at: { + anchor: { path: [0, 1], offset: 0 }, + focus: { path: [0, 1], offset: 2 }, + }, + } + ) +} + +export const input = ( + + + w + or + d + + +) + +export const output = ( + + + w + + or + + d + + +) diff --git a/packages/slate/test/commands/value/replace-mark/whole-word.js b/packages/slate/test/commands/setMarks/selection/basic.js similarity index 81% rename from packages/slate/test/commands/value/replace-mark/whole-word.js rename to packages/slate/test/commands/setMarks/selection/basic.js index 241db14bf9..675fe901fa 100644 --- a/packages/slate/test/commands/value/replace-mark/whole-word.js +++ b/packages/slate/test/commands/setMarks/selection/basic.js @@ -3,13 +3,13 @@ import { h } from '../../../helpers' export const run = editor => { - editor.replaceMark('italic', 'bold') + editor.setMarks([{ key: 'a' }], { thing: true }) } export const input = ( - + word @@ -19,7 +19,7 @@ export const input = ( export const output = ( - + word diff --git a/packages/slate/test/commands/path/setNodeAtPath/block.js b/packages/slate/test/commands/setNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/setNodeAtPath/block.js rename to packages/slate/test/commands/setNode/path/block.js diff --git a/packages/slate/test/commands/path/setNodeAtPath/inline.js b/packages/slate/test/commands/setNode/path/inline.js similarity index 100% rename from packages/slate/test/commands/path/setNodeAtPath/inline.js rename to packages/slate/test/commands/setNode/path/inline.js diff --git a/packages/slate/test/commands/path/setNodeAtPath/text.js b/packages/slate/test/commands/setNode/path/text.js similarity index 100% rename from packages/slate/test/commands/path/setNodeAtPath/text.js rename to packages/slate/test/commands/setNode/path/text.js diff --git a/packages/slate/test/commands/value/set-data/simple.js b/packages/slate/test/commands/setValue/simple.js similarity index 100% rename from packages/slate/test/commands/value/set-data/simple.js rename to packages/slate/test/commands/setValue/simple.js diff --git a/packages/slate/test/commands/point/splitBlockAtPoint/block.js b/packages/slate/test/commands/splitBlock/point/block.js similarity index 100% rename from packages/slate/test/commands/point/splitBlockAtPoint/block.js rename to packages/slate/test/commands/splitBlock/point/block.js diff --git a/packages/slate/test/commands/point/splitBlockAtPoint/selection.js b/packages/slate/test/commands/splitBlock/point/selection.js similarity index 100% rename from packages/slate/test/commands/point/splitBlockAtPoint/selection.js rename to packages/slate/test/commands/splitBlock/point/selection.js diff --git a/packages/slate/test/commands/value/split-block/after-inline-void.js b/packages/slate/test/commands/splitBlock/selection/after-inline-void.js similarity index 100% rename from packages/slate/test/commands/value/split-block/after-inline-void.js rename to packages/slate/test/commands/splitBlock/selection/after-inline-void.js diff --git a/packages/slate/test/commands/value/split-block/after-inline.js b/packages/slate/test/commands/splitBlock/selection/after-inline.js similarity index 100% rename from packages/slate/test/commands/value/split-block/after-inline.js rename to packages/slate/test/commands/splitBlock/selection/after-inline.js diff --git a/packages/slate/test/commands/value/split-block/before-inline.js b/packages/slate/test/commands/splitBlock/selection/before-inline.js similarity index 100% rename from packages/slate/test/commands/value/split-block/before-inline.js rename to packages/slate/test/commands/splitBlock/selection/before-inline.js diff --git a/packages/slate/test/commands/value/split-block/block-end.js b/packages/slate/test/commands/splitBlock/selection/block-end.js similarity index 100% rename from packages/slate/test/commands/value/split-block/block-end.js rename to packages/slate/test/commands/splitBlock/selection/block-end.js diff --git a/packages/slate/test/commands/value/split-block/block-middle.js b/packages/slate/test/commands/splitBlock/selection/block-middle.js similarity index 100% rename from packages/slate/test/commands/value/split-block/block-middle.js rename to packages/slate/test/commands/splitBlock/selection/block-middle.js diff --git a/packages/slate/test/commands/value/split-block/block-start.js b/packages/slate/test/commands/splitBlock/selection/block-start.js similarity index 100% rename from packages/slate/test/commands/value/split-block/block-start.js rename to packages/slate/test/commands/splitBlock/selection/block-start.js diff --git a/packages/slate/test/commands/value/split-block/depth.js b/packages/slate/test/commands/splitBlock/selection/depth.js similarity index 100% rename from packages/slate/test/commands/value/split-block/depth.js rename to packages/slate/test/commands/splitBlock/selection/depth.js diff --git a/packages/slate/test/commands/value/split-block/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks-and-inlines.js similarity index 100% rename from packages/slate/test/commands/value/split-block/with-delete-across-blocks-and-inlines.js rename to packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks-and-inlines.js diff --git a/packages/slate/test/commands/value/split-block/with-delete-across-blocks.js b/packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/split-block/with-delete-across-blocks.js rename to packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks.js diff --git a/packages/slate/test/commands/value/split-block/with-delete-hanging-selection.js b/packages/slate/test/commands/splitBlock/selection/with-delete-hanging-selection.js similarity index 100% rename from packages/slate/test/commands/value/split-block/with-delete-hanging-selection.js rename to packages/slate/test/commands/splitBlock/selection/with-delete-hanging-selection.js diff --git a/packages/slate/test/commands/value/split-block/with-delete.js b/packages/slate/test/commands/splitBlock/selection/with-delete.js similarity index 100% rename from packages/slate/test/commands/value/split-block/with-delete.js rename to packages/slate/test/commands/splitBlock/selection/with-delete.js diff --git a/packages/slate/test/commands/value/split-block/with-inline.js b/packages/slate/test/commands/splitBlock/selection/with-inline.js similarity index 100% rename from packages/slate/test/commands/value/split-block/with-inline.js rename to packages/slate/test/commands/splitBlock/selection/with-inline.js diff --git a/packages/slate/test/commands/value/split-block/with-marks.js b/packages/slate/test/commands/splitBlock/selection/with-marks.js similarity index 100% rename from packages/slate/test/commands/value/split-block/with-marks.js rename to packages/slate/test/commands/splitBlock/selection/with-marks.js diff --git a/packages/slate/test/commands/point/splitInlineAtPoint/inline.js b/packages/slate/test/commands/splitInline/point/inline.js similarity index 100% rename from packages/slate/test/commands/point/splitInlineAtPoint/inline.js rename to packages/slate/test/commands/splitInline/point/inline.js diff --git a/packages/slate/test/commands/value/split-inline/block-end.js b/packages/slate/test/commands/splitInline/selection/block-end.js similarity index 100% rename from packages/slate/test/commands/value/split-inline/block-end.js rename to packages/slate/test/commands/splitInline/selection/block-end.js diff --git a/packages/slate/test/commands/value/split-inline/block-middle.js b/packages/slate/test/commands/splitInline/selection/block-middle.js similarity index 100% rename from packages/slate/test/commands/value/split-inline/block-middle.js rename to packages/slate/test/commands/splitInline/selection/block-middle.js diff --git a/packages/slate/test/commands/value/split-inline/block-start.js b/packages/slate/test/commands/splitInline/selection/block-start.js similarity index 100% rename from packages/slate/test/commands/value/split-inline/block-start.js rename to packages/slate/test/commands/splitInline/selection/block-start.js diff --git a/packages/slate/test/commands/value/split-inline/height.js b/packages/slate/test/commands/splitInline/selection/height.js similarity index 100% rename from packages/slate/test/commands/value/split-inline/height.js rename to packages/slate/test/commands/splitInline/selection/height.js diff --git a/packages/slate/test/commands/value/split-inline/with-delete.js b/packages/slate/test/commands/splitInline/selection/with-delete.js similarity index 100% rename from packages/slate/test/commands/value/split-inline/with-delete.js rename to packages/slate/test/commands/splitInline/selection/with-delete.js diff --git a/packages/slate/test/commands/value/split-inline/with-marks.js b/packages/slate/test/commands/splitInline/selection/with-marks.js similarity index 100% rename from packages/slate/test/commands/value/split-inline/with-marks.js rename to packages/slate/test/commands/splitInline/selection/with-marks.js diff --git a/packages/slate/test/commands/path/splitNodeAtPath/block.js b/packages/slate/test/commands/splitNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/splitNodeAtPath/block.js rename to packages/slate/test/commands/splitNode/path/block.js diff --git a/packages/slate/test/commands/path/splitNodeAtPath/selection.js b/packages/slate/test/commands/splitNode/path/selection.js similarity index 100% rename from packages/slate/test/commands/path/splitNodeAtPath/selection.js rename to packages/slate/test/commands/splitNode/path/selection.js diff --git a/packages/slate/test/commands/point/splitNodeAtPoint/block.js b/packages/slate/test/commands/splitNode/point/block.js similarity index 100% rename from packages/slate/test/commands/point/splitNodeAtPoint/block.js rename to packages/slate/test/commands/splitNode/point/block.js diff --git a/packages/slate/test/commands/point/splitNodeAtPoint/inline.js b/packages/slate/test/commands/splitNode/point/inline.js similarity index 100% rename from packages/slate/test/commands/point/splitNodeAtPoint/inline.js rename to packages/slate/test/commands/splitNode/point/inline.js diff --git a/packages/slate/test/commands/point/splitNodeAtPoint/selection.js b/packages/slate/test/commands/splitNode/point/selection.js similarity index 100% rename from packages/slate/test/commands/point/splitNodeAtPoint/selection.js rename to packages/slate/test/commands/splitNode/point/selection.js diff --git a/packages/slate/test/commands/point/removeTextAtPoint/text.js b/packages/slate/test/commands/toggleMarks/path/add.js similarity index 63% rename from packages/slate/test/commands/point/removeTextAtPoint/text.js rename to packages/slate/test/commands/toggleMarks/path/add.js index 177b6fbca4..076fd71b29 100644 --- a/packages/slate/test/commands/point/removeTextAtPoint/text.js +++ b/packages/slate/test/commands/toggleMarks/path/add.js @@ -3,19 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 3 }, 1) + editor.toggleMarks([{ key: 'a' }], { + at: [0, 0], + }) } export const input = ( - - word - + word ) export const output = ( - wor + + word + ) diff --git a/packages/slate/test/commands/toggleMarks/path/remove.js b/packages/slate/test/commands/toggleMarks/path/remove.js new file mode 100644 index 0000000000..42e1e8186f --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/path/remove.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }], { + at: [0, 0], + }) +} + +export const input = ( + + + word + + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/commands/toggleMarks/range/add-text-middle.js b/packages/slate/test/commands/toggleMarks/range/add-text-middle.js new file mode 100644 index 0000000000..ad3e559f4a --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/range/add-text-middle.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }], { + at: { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 3 }, + }, + }) +} + +export const input = ( + + word + +) + +export const output = ( + + + w + or + d + + +) diff --git a/packages/slate/test/commands/toggleMarks/range/remove-text-middle.js b/packages/slate/test/commands/toggleMarks/range/remove-text-middle.js new file mode 100644 index 0000000000..a6c38f7ad1 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/range/remove-text-middle.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }], { + at: { + anchor: { path: [0, 1], offset: 0 }, + focus: { path: [0, 1], offset: 2 }, + }, + }) +} + +export const input = ( + + + w + or + d + + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/commands/value/replace-mark/across-blocks.js b/packages/slate/test/commands/toggleMarks/selection/add-across-blocks.js similarity index 71% rename from packages/slate/test/commands/value/replace-mark/across-blocks.js rename to packages/slate/test/commands/toggleMarks/selection/add-across-blocks.js index dd668f95e5..16fc2b50d4 100644 --- a/packages/slate/test/commands/value/replace-mark/across-blocks.js +++ b/packages/slate/test/commands/toggleMarks/selection/add-across-blocks.js @@ -3,20 +3,16 @@ import { h } from '../../../helpers' export const run = editor => { - editor.replaceMark('italic', 'bold') + editor.toggleMarks([{ key: 'a' }]) } export const input = ( - wo - - rd - + word - an - other + another ) diff --git a/packages/slate/test/commands/value/toggle-mark/add-across-inlines.js b/packages/slate/test/commands/toggleMarks/selection/add-across-inlines.js similarity index 95% rename from packages/slate/test/commands/value/toggle-mark/add-across-inlines.js rename to packages/slate/test/commands/toggleMarks/selection/add-across-inlines.js index 125e61f791..3b9c480723 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-across-inlines.js +++ b/packages/slate/test/commands/toggleMarks/selection/add-across-inlines.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.toggleMark('bold') + editor.toggleMarks([{ key: 'a' }]) } export const input = ( diff --git a/packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js b/packages/slate/test/commands/toggleMarks/selection/add-existing-marks-partially-marked.js similarity index 77% rename from packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js rename to packages/slate/test/commands/toggleMarks/selection/add-existing-marks-partially-marked.js index 9a3802c376..1d027189dc 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-existing-marks-partially-marked.js +++ b/packages/slate/test/commands/toggleMarks/selection/add-existing-marks-partially-marked.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.toggleMark('bold') + editor.toggleMarks([{ key: 'a' }]) } export const input = ( @@ -26,11 +26,11 @@ export const output = ( a - wo - - - rd + + wo + + rd ) diff --git a/packages/slate/test/commands/value/toggle-mark/add-existing-marks.js b/packages/slate/test/commands/toggleMarks/selection/add-existing-marks.js similarity index 77% rename from packages/slate/test/commands/value/toggle-mark/add-existing-marks.js rename to packages/slate/test/commands/toggleMarks/selection/add-existing-marks.js index f5fe953eb0..0634a7080c 100644 --- a/packages/slate/test/commands/value/toggle-mark/add-existing-marks.js +++ b/packages/slate/test/commands/toggleMarks/selection/add-existing-marks.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.toggleMark('bold') + editor.toggleMarks([{ key: 'a' }]) } export const input = ( @@ -21,12 +21,10 @@ export const output = ( - wo + wo - - rd - + rd ) diff --git a/packages/slate/test/commands/toggleMarks/selection/add-first-character.js b/packages/slate/test/commands/toggleMarks/selection/add-first-character.js new file mode 100644 index 0000000000..697e9da1c8 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/add-first-character.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + + w + + ord + + +) diff --git a/packages/slate/test/commands/toggleMarks/selection/add-last-character.js b/packages/slate/test/commands/toggleMarks/selection/add-last-character.js new file mode 100644 index 0000000000..0a2c829237 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/add-last-character.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + wor + + d + + + +) diff --git a/packages/slate/test/commands/toggleMarks/selection/add-middle-character.js b/packages/slate/test/commands/toggleMarks/selection/add-middle-character.js new file mode 100644 index 0000000000..927b7e007e --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/add-middle-character.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + word + + +) + +export const output = ( + + + w + + o + + rd + + +) diff --git a/packages/slate/test/commands/toggleMarks/selection/add-partially-marked.js b/packages/slate/test/commands/toggleMarks/selection/add-partially-marked.js new file mode 100644 index 0000000000..fe2c25b876 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/add-partially-marked.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + a + word + + + +) + +export const output = ( + + + + aword + + + +) diff --git a/packages/slate/test/commands/point/removeTextAtPoint/selection-middle.js b/packages/slate/test/commands/toggleMarks/selection/add-whole-word.js similarity index 69% rename from packages/slate/test/commands/point/removeTextAtPoint/selection-middle.js rename to packages/slate/test/commands/toggleMarks/selection/add-whole-word.js index 4a3bb5cca0..eb6d2e90fe 100644 --- a/packages/slate/test/commands/point/removeTextAtPoint/selection-middle.js +++ b/packages/slate/test/commands/toggleMarks/selection/add-whole-word.js @@ -3,15 +3,13 @@ import { h } from '../../../helpers' export const run = editor => { - editor.removeTextAtPoint({ path: [0, 0], offset: 2 }, 1) + editor.toggleMarks([{ key: 'a' }]) } export const input = ( - - word - + word ) @@ -19,7 +17,9 @@ export const input = ( export const output = ( - wod + + word + ) diff --git a/packages/slate/test/commands/toggleMarks/selection/remove-across-blocks.js b/packages/slate/test/commands/toggleMarks/selection/remove-across-blocks.js new file mode 100644 index 0000000000..2e3d1b50c1 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/remove-across-blocks.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + wo + + rd + + + + an + other + + +) + +export const output = ( + + + word + + + another + + +) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js b/packages/slate/test/commands/toggleMarks/selection/remove-across-inlines.js similarity index 91% rename from packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js rename to packages/slate/test/commands/toggleMarks/selection/remove-across-inlines.js index 878ca7f750..fb9dadf9d5 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-across-inlines.js +++ b/packages/slate/test/commands/toggleMarks/selection/remove-across-inlines.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.toggleMark('bold') + editor.toggleMarks([{ key: 'a' }]) } export const input = ( @@ -46,3 +46,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js b/packages/slate/test/commands/toggleMarks/selection/remove-existing-marks.js similarity index 92% rename from packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js rename to packages/slate/test/commands/toggleMarks/selection/remove-existing-marks.js index 18436241c0..71b2557055 100644 --- a/packages/slate/test/commands/value/toggle-mark/remove-existing-marks.js +++ b/packages/slate/test/commands/toggleMarks/selection/remove-existing-marks.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.toggleMark('bold') + editor.toggleMarks([{ key: 'a' }]) } export const input = ( diff --git a/packages/slate/test/commands/toggleMarks/selection/remove-first-character.js b/packages/slate/test/commands/toggleMarks/selection/remove-first-character.js new file mode 100644 index 0000000000..86893de1b7 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/remove-first-character.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + + w + + ord + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/toggleMarks/selection/remove-last-character.js b/packages/slate/test/commands/toggleMarks/selection/remove-last-character.js new file mode 100644 index 0000000000..de7882b247 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/remove-last-character.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + wor + + d + + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/toggleMarks/selection/remove-middle-character.js b/packages/slate/test/commands/toggleMarks/selection/remove-middle-character.js new file mode 100644 index 0000000000..f1725cdaa0 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/remove-middle-character.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + w + + o + + rd + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/toggleMarks/selection/remove-whole-word.js b/packages/slate/test/commands/toggleMarks/selection/remove-whole-word.js new file mode 100644 index 0000000000..8405726f18 --- /dev/null +++ b/packages/slate/test/commands/toggleMarks/selection/remove-whole-word.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/commands/value/unwrap-block/across-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/across-blocks.js rename to packages/slate/test/commands/unwrapBlock/selection/across-blocks.js diff --git a/packages/slate/test/commands/value/unwrap-block/across-inlines.js b/packages/slate/test/commands/unwrapBlock/selection/across-inlines.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/across-inlines.js rename to packages/slate/test/commands/unwrapBlock/selection/across-inlines.js diff --git a/packages/slate/test/commands/value/unwrap-block/ending-child-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/ending-child-blocks.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/ending-child-blocks.js rename to packages/slate/test/commands/unwrapBlock/selection/ending-child-blocks.js diff --git a/packages/slate/test/commands/value/unwrap-block/middle-child-blocks-with-backward-selection.js b/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks-with-backward-selection.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/middle-child-blocks-with-backward-selection.js rename to packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks-with-backward-selection.js diff --git a/packages/slate/test/commands/value/unwrap-block/middle-child-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/middle-child-blocks.js rename to packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks.js diff --git a/packages/slate/test/commands/value/unwrap-block/nested-block.js b/packages/slate/test/commands/unwrapBlock/selection/nested-block.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/nested-block.js rename to packages/slate/test/commands/unwrapBlock/selection/nested-block.js diff --git a/packages/slate/test/commands/value/unwrap-block/single-block.js b/packages/slate/test/commands/unwrapBlock/selection/single-block.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/single-block.js rename to packages/slate/test/commands/unwrapBlock/selection/single-block.js diff --git a/packages/slate/test/commands/value/unwrap-block/starting-child-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/starting-child-blocks.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/starting-child-blocks.js rename to packages/slate/test/commands/unwrapBlock/selection/starting-child-blocks.js diff --git a/packages/slate/test/commands/value/unwrap-block/with-object.js b/packages/slate/test/commands/unwrapBlock/selection/with-object.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-block/with-object.js rename to packages/slate/test/commands/unwrapBlock/selection/with-object.js diff --git a/packages/slate/test/commands/value/unwrap-inline/across-blocks.js b/packages/slate/test/commands/unwrapInline/selection/across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-inline/across-blocks.js rename to packages/slate/test/commands/unwrapInline/selection/across-blocks.js diff --git a/packages/slate/test/commands/value/unwrap-inline/across-inlines-and-text.js b/packages/slate/test/commands/unwrapInline/selection/across-inlines-and-text.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-inline/across-inlines-and-text.js rename to packages/slate/test/commands/unwrapInline/selection/across-inlines-and-text.js diff --git a/packages/slate/test/commands/value/unwrap-inline/across-inlines.js b/packages/slate/test/commands/unwrapInline/selection/across-inlines.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-inline/across-inlines.js rename to packages/slate/test/commands/unwrapInline/selection/across-inlines.js diff --git a/packages/slate/test/commands/value/unwrap-inline/nested-block.js b/packages/slate/test/commands/unwrapInline/selection/nested-block.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-inline/nested-block.js rename to packages/slate/test/commands/unwrapInline/selection/nested-block.js diff --git a/packages/slate/test/commands/value/unwrap-inline/only-one.js b/packages/slate/test/commands/unwrapInline/selection/only-one.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-inline/only-one.js rename to packages/slate/test/commands/unwrapInline/selection/only-one.js diff --git a/packages/slate/test/commands/value/unwrap-inline/single-block.js b/packages/slate/test/commands/unwrapInline/selection/single-block.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-inline/single-block.js rename to packages/slate/test/commands/unwrapInline/selection/single-block.js diff --git a/packages/slate/test/commands/value/unwrap-inline/with-object.js b/packages/slate/test/commands/unwrapInline/selection/with-object.js similarity index 100% rename from packages/slate/test/commands/value/unwrap-inline/with-object.js rename to packages/slate/test/commands/unwrapInline/selection/with-object.js diff --git a/packages/slate/test/commands/value/insert-block/block-end.js b/packages/slate/test/commands/value/insert-block/block-end.js deleted file mode 100644 index 3707919a33..0000000000 --- a/packages/slate/test/commands/value/insert-block/block-end.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertBlock('quote') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - word - - - - - -) diff --git a/packages/slate/test/commands/value/insert-block/block-middle.js b/packages/slate/test/commands/value/insert-block/block-middle.js deleted file mode 100644 index 093ee325fc..0000000000 --- a/packages/slate/test/commands/value/insert-block/block-middle.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertBlock('quote') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - wo - - - - rd - - -) diff --git a/packages/slate/test/commands/value/insert-block/block-start.js b/packages/slate/test/commands/value/insert-block/block-start.js deleted file mode 100644 index 74c6870a7a..0000000000 --- a/packages/slate/test/commands/value/insert-block/block-start.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertBlock('quote') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - - word - - -) diff --git a/packages/slate/test/commands/value/insert-block/is-void-end.js b/packages/slate/test/commands/value/insert-block/is-void-end.js deleted file mode 100644 index fb9431c122..0000000000 --- a/packages/slate/test/commands/value/insert-block/is-void-end.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertBlock('quote') -} - -export const input = ( - - - - text - - text - - -) - -export const output = ( - - - text - - - - text - - -) diff --git a/packages/slate/test/commands/value/insert-block/is-void-start.js b/packages/slate/test/commands/value/insert-block/is-void-start.js deleted file mode 100644 index c1fb127a7f..0000000000 --- a/packages/slate/test/commands/value/insert-block/is-void-start.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertBlock('quote') -} - -export const input = ( - - - - text - - text - - -) - -export const output = ( - - - - - - text - text - - -) diff --git a/packages/slate/test/commands/value/insert-block/with-block.js b/packages/slate/test/commands/value/insert-block/with-block.js deleted file mode 100644 index 8d5cbb638a..0000000000 --- a/packages/slate/test/commands/value/insert-block/with-block.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Block } from 'slate' - -export const run = editor => { - editor.insertBlock(Block.create({ type: 'quote' })) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - - word - - -) diff --git a/packages/slate/test/commands/value/insert-block/with-object.js b/packages/slate/test/commands/value/insert-block/with-object.js deleted file mode 100644 index d66f631d07..0000000000 --- a/packages/slate/test/commands/value/insert-block/with-object.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertBlock({ type: 'quote' }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - - word - - -) diff --git a/packages/slate/test/commands/value/insert-text/after-mark.js b/packages/slate/test/commands/value/insert-text/after-mark.js deleted file mode 100644 index 2a14edce7d..0000000000 --- a/packages/slate/test/commands/value/insert-text/after-mark.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertText('a') -} - -export const input = ( - - - - w - or - d - - - -) - -export const output = ( - - - - w - ora - d - - - -) diff --git a/packages/slate/test/commands/value/insert-text/expanded-with-mark.js b/packages/slate/test/commands/value/insert-text/expanded-with-mark.js deleted file mode 100644 index dedf2eca41..0000000000 --- a/packages/slate/test/commands/value/insert-text/expanded-with-mark.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertText('a') - editor.insertText('b') -} - -export const input = ( - - - - - lorem - - ipsum - - - ipsum - - - -) - -export const output = ( - - - - ab - - - -) diff --git a/packages/slate/test/commands/value/insert-text/inside-void.js b/packages/slate/test/commands/value/insert-text/inside-void.js deleted file mode 100644 index d095709541..0000000000 --- a/packages/slate/test/commands/value/insert-text/inside-void.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertText('a') -} - -export const input = ( - - - - - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/value/insert-text/with-marks.js b/packages/slate/test/commands/value/insert-text/with-marks.js deleted file mode 100644 index 48a50366c7..0000000000 --- a/packages/slate/test/commands/value/insert-text/with-marks.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Mark } from 'slate' - -export const run = editor => { - const marks = Mark.createSet([{ type: 'bold' }]) - editor.insertText('a', marks) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - worda - - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/across-blocks.js b/packages/slate/test/commands/value/remove-mark/across-blocks.js deleted file mode 100644 index 7f4d33916a..0000000000 --- a/packages/slate/test/commands/value/remove-mark/across-blocks.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - wo - rd - - - an - other - - - -) - -export const output = ( - - - - word - - - another - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/across-inlines.js b/packages/slate/test/commands/value/remove-mark/across-inlines.js deleted file mode 100644 index 3ef729d3f4..0000000000 --- a/packages/slate/test/commands/value/remove-mark/across-inlines.js +++ /dev/null @@ -1,43 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - - wo - rd - - - - - an - other - - - - -) - -export const output = ( - - - - - word - - - - - another - - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/first-character.js b/packages/slate/test/commands/value/remove-mark/first-character.js deleted file mode 100644 index e74a87b614..0000000000 --- a/packages/slate/test/commands/value/remove-mark/first-character.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - - w - ord - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/last-character.js b/packages/slate/test/commands/value/remove-mark/last-character.js deleted file mode 100644 index 5c5d0e72cf..0000000000 --- a/packages/slate/test/commands/value/remove-mark/last-character.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - wor - - d - - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/middle-character.js b/packages/slate/test/commands/value/remove-mark/middle-character.js deleted file mode 100644 index 00fbb14560..0000000000 --- a/packages/slate/test/commands/value/remove-mark/middle-character.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - w - - o - - rd - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js b/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js deleted file mode 100644 index 4afb60a4ff..0000000000 --- a/packages/slate/test/commands/value/remove-mark/part-of-mark-backward.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wor - d - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/part-of-mark.js b/packages/slate/test/commands/value/remove-mark/part-of-mark.js deleted file mode 100644 index c7a7b7daf4..0000000000 --- a/packages/slate/test/commands/value/remove-mark/part-of-mark.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - wor - d - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/whole-word.js b/packages/slate/test/commands/value/remove-mark/whole-word.js deleted file mode 100644 index b1f27efedc..0000000000 --- a/packages/slate/test/commands/value/remove-mark/whole-word.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark('bold') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/with-mark-object.js b/packages/slate/test/commands/value/remove-mark/with-mark-object.js deleted file mode 100644 index fffe165ffd..0000000000 --- a/packages/slate/test/commands/value/remove-mark/with-mark-object.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Mark } from 'slate' - -export const run = editor => { - editor.removeMark( - Mark.create({ - type: 'bold', - data: { thing: 'value' }, - }) - ) -} - -export const input = ( - - - - - w - ord - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/remove-mark/with-plain-object.js b/packages/slate/test/commands/value/remove-mark/with-plain-object.js deleted file mode 100644 index 088c99afcc..0000000000 --- a/packages/slate/test/commands/value/remove-mark/with-plain-object.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.removeMark({ - type: 'bold', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - - w - ord - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/replace-mark/existing-marks.js b/packages/slate/test/commands/value/replace-mark/existing-marks.js deleted file mode 100644 index 46de594fc6..0000000000 --- a/packages/slate/test/commands/value/replace-mark/existing-marks.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.replaceMark('italic', 'bold') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - wo - - rd - - - -) diff --git a/packages/slate/test/commands/value/replace-mark/with-mark-object.js b/packages/slate/test/commands/value/replace-mark/with-mark-object.js deleted file mode 100644 index 610f79075e..0000000000 --- a/packages/slate/test/commands/value/replace-mark/with-mark-object.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -import { Mark } from 'slate' - -export const run = editor => { - editor.replaceMark( - 'italic', - Mark.create({ - type: 'bold', - data: { thing: 'value' }, - }) - ) -} - -export const input = ( - - - - - w - - ord - - - -) - -export const output = ( - - - - - w - - ord - - - -) diff --git a/packages/slate/test/commands/value/replace-mark/with-plain-object.js b/packages/slate/test/commands/value/replace-mark/with-plain-object.js deleted file mode 100644 index 512f660443..0000000000 --- a/packages/slate/test/commands/value/replace-mark/with-plain-object.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.replaceMark('italic', { - type: 'bold', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - - w - - ord - - - -) - -export const output = ( - - - - - w - - ord - - - -) diff --git a/packages/slate/test/commands/value/set-block/with-data-as-map.js b/packages/slate/test/commands/value/set-block/with-data-as-map.js deleted file mode 100644 index c46bc4d868..0000000000 --- a/packages/slate/test/commands/value/set-block/with-data-as-map.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Data } from 'slate' - -export const run = editor => { - editor.setBlocks({ - type: 'code', - data: Data.create({ thing: 'value' }), - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/set-block/with-data-as-object.js b/packages/slate/test/commands/value/set-block/with-data-as-object.js deleted file mode 100644 index 83424a793b..0000000000 --- a/packages/slate/test/commands/value/set-block/with-data-as-object.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.setBlocks({ - type: 'code', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js b/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js deleted file mode 100644 index c811dfbc48..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-across-blocks.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - word - - - another - - - -) - -export const output = ( - - - - wo - - rd - - - - an - other - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js deleted file mode 100644 index 707caf3317..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection-start.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - a - word - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js b/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js deleted file mode 100644 index 73d1b75c5c..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-collapsed-selection.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') - editor.insertText('s') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - s - - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-first-character.js b/packages/slate/test/commands/value/toggle-mark/add-first-character.js deleted file mode 100644 index 64a5097856..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-first-character.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - w - - ord - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-last-character.js b/packages/slate/test/commands/value/toggle-mark/add-last-character.js deleted file mode 100644 index 2a39040a5e..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-last-character.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - wor - - d - - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-middle-character.js b/packages/slate/test/commands/value/toggle-mark/add-middle-character.js deleted file mode 100644 index c8493df4d7..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-middle-character.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w - - o - - rd - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js b/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js deleted file mode 100644 index 11458010c1..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-partially-marked.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - a - word - - - - -) - -export const output = ( - - - - - aword - - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-whole-word.js b/packages/slate/test/commands/value/toggle-mark/add-whole-word.js deleted file mode 100644 index 65764c4934..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-whole-word.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js b/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js deleted file mode 100644 index 34fe3acde3..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-with-mark-object.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Mark } from 'slate' - -export const run = editor => { - editor.toggleMark( - Mark.create({ - type: 'bold', - data: { thing: 'value' }, - }) - ) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - w - - ord - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js b/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js deleted file mode 100644 index b4895a0c7b..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/add-with-plain-object.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark({ - type: 'bold', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - w - - ord - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js b/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js deleted file mode 100644 index 2ec1c7fb53..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-across-blocks.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - wo - - rd - - - - an - other - - - -) - -export const output = ( - - - - word - - - another - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection-beginning.js b/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection-beginning.js deleted file mode 100644 index 5a4ca668f1..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection-beginning.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') - editor.toggleMark('bold') - editor.insertText('a') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - aword - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection.js b/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection.js deleted file mode 100644 index d679236775..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-collapsed-selection.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') - editor.toggleMark('bold') - editor.insertText('s') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - words - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-first-character.js b/packages/slate/test/commands/value/toggle-mark/remove-first-character.js deleted file mode 100644 index 10dde2f211..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-first-character.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - - w - - ord - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-last-character.js b/packages/slate/test/commands/value/toggle-mark/remove-last-character.js deleted file mode 100644 index 89ecfdcdb3..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-last-character.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - wor - - d - - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js b/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js deleted file mode 100644 index 4d2b8413f5..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-middle-character.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - w - - o - - rd - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js b/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js deleted file mode 100644 index 47b2df843c..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-whole-word.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark('bold') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js b/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js deleted file mode 100644 index 8e3fda2c97..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-with-mark-object.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Mark } from 'slate' - -export const run = editor => { - editor.toggleMark( - Mark.create({ - type: 'bold', - data: { thing: 'value' }, - }) - ) -} - -export const input = ( - - - - - w - - ord - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js b/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js deleted file mode 100644 index 1a376d06a3..0000000000 --- a/packages/slate/test/commands/value/toggle-mark/remove-with-plain-object.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.toggleMark({ - type: 'bold', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - - w - - ord - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/across-blocks.js b/packages/slate/test/commands/value/wrap-text/across-blocks.js deleted file mode 100644 index 81dd2cfd0a..0000000000 --- a/packages/slate/test/commands/value/wrap-text/across-blocks.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - word - - - another - - - -) - -export const output = ( - - - - wo[[rd - - - an]]other - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/across-inlines.js b/packages/slate/test/commands/value/wrap-text/across-inlines.js deleted file mode 100644 index ebb5612665..0000000000 --- a/packages/slate/test/commands/value/wrap-text/across-inlines.js +++ /dev/null @@ -1,37 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - - word - - - another - - - - -) - -export const output = ( - - - - - wo[[rd - - - an]]other - - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/backwards-selection.js b/packages/slate/test/commands/value/wrap-text/backwards-selection.js deleted file mode 100644 index 521fed17c7..0000000000 --- a/packages/slate/test/commands/value/wrap-text/backwards-selection.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w[[or]]d - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/empty-block.js b/packages/slate/test/commands/value/wrap-text/empty-block.js deleted file mode 100644 index 4b0d135594..0000000000 --- a/packages/slate/test/commands/value/wrap-text/empty-block.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - - - - -) - -export const output = ( - - - - [[]] - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/end-of-block.js b/packages/slate/test/commands/value/wrap-text/end-of-block.js deleted file mode 100644 index 4ad5b80847..0000000000 --- a/packages/slate/test/commands/value/wrap-text/end-of-block.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - wo[[rd]] - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/middle-of-block.js b/packages/slate/test/commands/value/wrap-text/middle-of-block.js deleted file mode 100644 index 1efad9ea35..0000000000 --- a/packages/slate/test/commands/value/wrap-text/middle-of-block.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w[[or]]d - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/start-of-block.js b/packages/slate/test/commands/value/wrap-text/start-of-block.js deleted file mode 100644 index 378253ea55..0000000000 --- a/packages/slate/test/commands/value/wrap-text/start-of-block.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - [[wo]]rd - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/whole-block.js b/packages/slate/test/commands/value/wrap-text/whole-block.js deleted file mode 100644 index 38da209cf1..0000000000 --- a/packages/slate/test/commands/value/wrap-text/whole-block.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('[[', ']]') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - [[word]] - - - -) diff --git a/packages/slate/test/commands/value/wrap-text/without-suffix.js b/packages/slate/test/commands/value/wrap-text/without-suffix.js deleted file mode 100644 index d7adc46b72..0000000000 --- a/packages/slate/test/commands/value/wrap-text/without-suffix.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapText('**') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w**or**d - - - -) diff --git a/packages/slate/test/commands/value/wrap-block/across-blocks.js b/packages/slate/test/commands/wrapBlock/selection/across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/wrap-block/across-blocks.js rename to packages/slate/test/commands/wrapBlock/selection/across-blocks.js diff --git a/packages/slate/test/commands/value/wrap-block/across-inlines.js b/packages/slate/test/commands/wrapBlock/selection/across-inlines.js similarity index 100% rename from packages/slate/test/commands/value/wrap-block/across-inlines.js rename to packages/slate/test/commands/wrapBlock/selection/across-inlines.js diff --git a/packages/slate/test/commands/value/wrap-block/nested-block-with-object.js b/packages/slate/test/commands/wrapBlock/selection/nested-block-with-object.js similarity index 100% rename from packages/slate/test/commands/value/wrap-block/nested-block-with-object.js rename to packages/slate/test/commands/wrapBlock/selection/nested-block-with-object.js diff --git a/packages/slate/test/commands/value/wrap-block/nested-block.js b/packages/slate/test/commands/wrapBlock/selection/nested-block.js similarity index 100% rename from packages/slate/test/commands/value/wrap-block/nested-block.js rename to packages/slate/test/commands/wrapBlock/selection/nested-block.js diff --git a/packages/slate/test/commands/value/wrap-block/single-block.js b/packages/slate/test/commands/wrapBlock/selection/single-block.js similarity index 100% rename from packages/slate/test/commands/value/wrap-block/single-block.js rename to packages/slate/test/commands/wrapBlock/selection/single-block.js diff --git a/packages/slate/test/commands/value/wrap-block/with-object.js b/packages/slate/test/commands/wrapBlock/selection/with-object.js similarity index 100% rename from packages/slate/test/commands/value/wrap-block/with-object.js rename to packages/slate/test/commands/wrapBlock/selection/with-object.js diff --git a/packages/slate/test/commands/value/wrap-inline/across-blocks.js b/packages/slate/test/commands/wrapInline/selection/across-blocks.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/across-blocks.js rename to packages/slate/test/commands/wrapInline/selection/across-blocks.js diff --git a/packages/slate/test/commands/value/wrap-inline/across-inlines.js b/packages/slate/test/commands/wrapInline/selection/across-inlines.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/across-inlines.js rename to packages/slate/test/commands/wrapInline/selection/across-inlines.js diff --git a/packages/slate/test/commands/value/wrap-inline/collapsed.js b/packages/slate/test/commands/wrapInline/selection/collapsed.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/collapsed.js rename to packages/slate/test/commands/wrapInline/selection/collapsed.js diff --git a/packages/slate/test/commands/value/wrap-inline/inline-end.js b/packages/slate/test/commands/wrapInline/selection/inline-end.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/inline-end.js rename to packages/slate/test/commands/wrapInline/selection/inline-end.js diff --git a/packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js b/packages/slate/test/commands/wrapInline/selection/inline-middle-with-marks.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/inline-middle-with-marks.js rename to packages/slate/test/commands/wrapInline/selection/inline-middle-with-marks.js diff --git a/packages/slate/test/commands/value/wrap-inline/inline-middle.js b/packages/slate/test/commands/wrapInline/selection/inline-middle.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/inline-middle.js rename to packages/slate/test/commands/wrapInline/selection/inline-middle.js diff --git a/packages/slate/test/commands/value/wrap-inline/inline-start.js b/packages/slate/test/commands/wrapInline/selection/inline-start.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/inline-start.js rename to packages/slate/test/commands/wrapInline/selection/inline-start.js diff --git a/packages/slate/test/commands/value/wrap-inline/inline-void.js b/packages/slate/test/commands/wrapInline/selection/inline-void.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/inline-void.js rename to packages/slate/test/commands/wrapInline/selection/inline-void.js diff --git a/packages/slate/test/commands/value/wrap-inline/nested-block.js b/packages/slate/test/commands/wrapInline/selection/nested-block.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/nested-block.js rename to packages/slate/test/commands/wrapInline/selection/nested-block.js diff --git a/packages/slate/test/commands/value/wrap-inline/single-block.js b/packages/slate/test/commands/wrapInline/selection/single-block.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/single-block.js rename to packages/slate/test/commands/wrapInline/selection/single-block.js diff --git a/packages/slate/test/commands/value/wrap-inline/twice.js b/packages/slate/test/commands/wrapInline/selection/twice.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/twice.js rename to packages/slate/test/commands/wrapInline/selection/twice.js diff --git a/packages/slate/test/commands/value/wrap-inline/whole-block.js b/packages/slate/test/commands/wrapInline/selection/whole-block.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/whole-block.js rename to packages/slate/test/commands/wrapInline/selection/whole-block.js diff --git a/packages/slate/test/commands/value/wrap-inline/with-object.js b/packages/slate/test/commands/wrapInline/selection/with-object.js similarity index 100% rename from packages/slate/test/commands/value/wrap-inline/with-object.js rename to packages/slate/test/commands/wrapInline/selection/with-object.js diff --git a/packages/slate/test/commands/path/wrapNodeAtPath/block.js b/packages/slate/test/commands/wrapNode/path/block.js similarity index 100% rename from packages/slate/test/commands/path/wrapNodeAtPath/block.js rename to packages/slate/test/commands/wrapNode/path/block.js diff --git a/packages/slate/test/commands/path/wrapNodeAtPath/text.js b/packages/slate/test/commands/wrapNode/path/text.js similarity index 100% rename from packages/slate/test/commands/path/wrapNodeAtPath/text.js rename to packages/slate/test/commands/wrapNode/path/text.js diff --git a/packages/slate/test/operations/apply/insert-text/annotation-before.js b/packages/slate/test/operations/insert-text/annotation-before.js similarity index 100% rename from packages/slate/test/operations/apply/insert-text/annotation-before.js rename to packages/slate/test/operations/insert-text/annotation-before.js diff --git a/packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js b/packages/slate/test/operations/merge-node/annotation-across-blocks.js similarity index 100% rename from packages/slate/test/operations/apply/merge-node/annotation-across-blocks.js rename to packages/slate/test/operations/merge-node/annotation-across-blocks.js diff --git a/packages/slate/test/operations/apply/move-node/path-equals-new-path.js b/packages/slate/test/operations/move-node/path-equals-new-path.js similarity index 100% rename from packages/slate/test/operations/apply/move-node/path-equals-new-path.js rename to packages/slate/test/operations/move-node/path-equals-new-path.js diff --git a/packages/slate/test/operations/apply/remove-node/annotation-across-blocks.js b/packages/slate/test/operations/remove-node/annotation-across-blocks.js similarity index 100% rename from packages/slate/test/operations/apply/remove-node/annotation-across-blocks.js rename to packages/slate/test/operations/remove-node/annotation-across-blocks.js diff --git a/packages/slate/test/operations/apply/remove-text/anchor-after.js b/packages/slate/test/operations/remove-text/anchor-after.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/anchor-after.js rename to packages/slate/test/operations/remove-text/anchor-after.js diff --git a/packages/slate/test/operations/apply/remove-text/anchor-before.js b/packages/slate/test/operations/remove-text/anchor-before.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/anchor-before.js rename to packages/slate/test/operations/remove-text/anchor-before.js diff --git a/packages/slate/test/operations/apply/remove-text/anchor-middle.js b/packages/slate/test/operations/remove-text/anchor-middle.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/anchor-middle.js rename to packages/slate/test/operations/remove-text/anchor-middle.js diff --git a/packages/slate/test/operations/apply/remove-text/annotation-after.js b/packages/slate/test/operations/remove-text/annotation-after.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/annotation-after.js rename to packages/slate/test/operations/remove-text/annotation-after.js diff --git a/packages/slate/test/operations/apply/remove-text/annotation-before.js b/packages/slate/test/operations/remove-text/annotation-before.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/annotation-before.js rename to packages/slate/test/operations/remove-text/annotation-before.js diff --git a/packages/slate/test/operations/apply/remove-text/annotation-middle.js b/packages/slate/test/operations/remove-text/annotation-middle.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/annotation-middle.js rename to packages/slate/test/operations/remove-text/annotation-middle.js diff --git a/packages/slate/test/operations/apply/remove-text/cursor-after.js b/packages/slate/test/operations/remove-text/cursor-after.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/cursor-after.js rename to packages/slate/test/operations/remove-text/cursor-after.js diff --git a/packages/slate/test/operations/apply/remove-text/cursor-before.js b/packages/slate/test/operations/remove-text/cursor-before.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/cursor-before.js rename to packages/slate/test/operations/remove-text/cursor-before.js diff --git a/packages/slate/test/operations/apply/remove-text/cursor-middle.js b/packages/slate/test/operations/remove-text/cursor-middle.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/cursor-middle.js rename to packages/slate/test/operations/remove-text/cursor-middle.js diff --git a/packages/slate/test/operations/apply/remove-text/focus-after.js b/packages/slate/test/operations/remove-text/focus-after.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/focus-after.js rename to packages/slate/test/operations/remove-text/focus-after.js diff --git a/packages/slate/test/operations/apply/remove-text/focus-before.js b/packages/slate/test/operations/remove-text/focus-before.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/focus-before.js rename to packages/slate/test/operations/remove-text/focus-before.js diff --git a/packages/slate/test/operations/apply/remove-text/focus-middle.js b/packages/slate/test/operations/remove-text/focus-middle.js similarity index 100% rename from packages/slate/test/operations/apply/remove-text/focus-middle.js rename to packages/slate/test/operations/remove-text/focus-middle.js From 1ffdf3ddef0ff7a2fc2efc198e2554b702cba99d Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 23 Oct 2019 14:40:26 -0400 Subject: [PATCH 053/165] restructure query tests --- packages/slate/test/queries/{value => }/blocks/block-multiple.js | 0 packages/slate/test/queries/{value => }/blocks/block-nested.js | 0 packages/slate/test/queries/{value => }/blocks/block-reverse.js | 0 packages/slate/test/queries/{value => }/blocks/block-void.js | 0 packages/slate/test/queries/{value => }/blocks/block.js | 0 packages/slate/test/queries/{value => }/blocks/inline.js | 0 packages/slate/test/queries/{value => }/entries/block-multiple.js | 0 packages/slate/test/queries/{value => }/entries/block-nested.js | 0 packages/slate/test/queries/{value => }/entries/block-reverse.js | 0 packages/slate/test/queries/{value => }/entries/block-void.js | 0 packages/slate/test/queries/{value => }/entries/block.js | 0 .../slate/test/queries/{value => }/entries/inline-multiple.js | 0 packages/slate/test/queries/{value => }/entries/inline-nested.js | 0 packages/slate/test/queries/{value => }/entries/inline-reverse.js | 0 packages/slate/test/queries/{value => }/entries/inline-void.js | 0 packages/slate/test/queries/{value => }/entries/inline.js | 0 .../slate/test/queries/{value => }/getActiveMarks/block-across.js | 0 .../slate/test/queries/{value => }/getActiveMarks/block-start.js | 0 .../slate/test/queries/{value => }/getActiveMarks/inline-start.js | 0 .../slate/test/queries/{value => }/getActiveMarks/intersection.js | 0 .../slate/test/queries/{value => }/getActiveMarks/multiple.js | 0 packages/slate/test/queries/{value => }/getActiveMarks/none.js | 0 packages/slate/test/queries/{value => }/getActiveMarks/one.js | 0 .../test/queries/{value => }/getActiveMarks/selection-marks.js | 0 .../test/queries/{value => }/getActiveMarks/selection-null.js | 0 .../slate/test/queries/{value => }/getActiveMarks/text-start.js | 0 packages/slate/test/queries/{value => }/getActiveMarks/union.js | 0 .../slate/test/queries/{path => }/getClosestBlock/block-nested.js | 0 packages/slate/test/queries/{path => }/getClosestBlock/block.js | 0 packages/slate/test/queries/{path => }/getClosestBlock/inline.js | 0 packages/slate/test/queries/{path => }/getText/block-across.js | 0 packages/slate/test/queries/{path => }/getText/block-void.js | 0 packages/slate/test/queries/{path => }/getText/block.js | 0 packages/slate/test/queries/{path => }/getText/inline.js | 0 packages/slate/test/queries/{path => }/getText/text.js | 0 .../slate/test/queries/{element => }/hasBlocks/block-nested.js | 0 packages/slate/test/queries/{element => }/hasBlocks/block.js | 0 .../slate/test/queries/{element => }/hasBlocks/inline-nested.js | 0 packages/slate/test/queries/{element => }/hasBlocks/inline.js | 0 .../slate/test/queries/{element => }/hasInlines/block-nested.js | 0 packages/slate/test/queries/{element => }/hasInlines/block.js | 0 .../slate/test/queries/{element => }/hasInlines/inline-nested.js | 0 packages/slate/test/queries/{element => }/hasInlines/inline.js | 0 .../slate/test/queries/{element => }/hasTexts/block-nested.js | 0 packages/slate/test/queries/{element => }/hasTexts/block.js | 0 .../slate/test/queries/{element => }/hasTexts/inline-nested.js | 0 packages/slate/test/queries/{element => }/hasTexts/inline.js | 0 packages/slate/test/queries/{value => }/inlines/block.js | 0 .../slate/test/queries/{value => }/inlines/inline-multiple.js | 0 packages/slate/test/queries/{value => }/inlines/inline-nested.js | 0 packages/slate/test/queries/{value => }/inlines/inline-reverse.js | 0 packages/slate/test/queries/{value => }/inlines/inline-void.js | 0 packages/slate/test/queries/{value => }/inlines/inline.js | 0 packages/slate/test/queries/{mark => }/isAtomic/atomic.js | 0 packages/slate/test/queries/{mark => }/isAtomic/non-atomic.js | 0 packages/slate/test/queries/{element => }/isInline/block.js | 0 packages/slate/test/queries/{element => }/isInline/inline-void.js | 0 packages/slate/test/queries/{element => }/isInline/inline.js | 0 packages/slate/test/queries/{element => }/isInline/text.js | 0 packages/slate/test/queries/{element => }/isInline/value.js | 0 packages/slate/test/queries/{element => }/isVoid/block-void.js | 0 packages/slate/test/queries/{element => }/isVoid/block.js | 0 packages/slate/test/queries/{element => }/isVoid/inline-void.js | 0 packages/slate/test/queries/{element => }/isVoid/inline.js | 0 packages/slate/test/queries/{element => }/isVoid/text.js | 0 packages/slate/test/queries/{element => }/isVoid/value.js | 0 .../slate/test/queries/{value => }/leafBlocks/block-multiple.js | 0 .../slate/test/queries/{value => }/leafBlocks/block-nested.js | 0 .../slate/test/queries/{value => }/leafBlocks/block-reverse.js | 0 packages/slate/test/queries/{value => }/leafBlocks/block-void.js | 0 packages/slate/test/queries/{value => }/leafBlocks/block.js | 0 packages/slate/test/queries/{value => }/leafBlocks/inline.js | 0 packages/slate/test/queries/{value => }/leafInlines/block.js | 0 .../slate/test/queries/{value => }/leafInlines/inline-multiple.js | 0 .../slate/test/queries/{value => }/leafInlines/inline-nested.js | 0 .../slate/test/queries/{value => }/leafInlines/inline-reverse.js | 0 .../slate/test/queries/{value => }/leafInlines/inline-void.js | 0 packages/slate/test/queries/{value => }/leafInlines/inline.js | 0 .../queries/{value => }/positions/all/block-multiple-reverse.js | 0 .../test/queries/{value => }/positions/all/block-multiple.js | 0 .../slate/test/queries/{value => }/positions/all/block-nested.js | 0 .../slate/test/queries/{value => }/positions/all/block-reverse.js | 0 packages/slate/test/queries/{value => }/positions/all/block.js | 0 .../test/queries/{value => }/positions/all/inline-multiple.js | 0 .../slate/test/queries/{value => }/positions/all/inline-nested.js | 0 .../test/queries/{value => }/positions/all/inline-reverse.js | 0 packages/slate/test/queries/{value => }/positions/all/inline.js | 0 .../test/queries/{value => }/positions/all/unit-block-reverse.js | 0 .../slate/test/queries/{value => }/positions/all/unit-block.js | 0 .../queries/{value => }/positions/all/unit-character-reverse.js | 0 .../test/queries/{value => }/positions/all/unit-character.js | 0 .../test/queries/{value => }/positions/all/unit-line-reverse.js | 0 .../slate/test/queries/{value => }/positions/all/unit-line.js | 0 .../test/queries/{value => }/positions/all/unit-word-reverse.js | 0 .../slate/test/queries/{value => }/positions/all/unit-word.js | 0 .../queries/{value => }/positions/point/block-edge-reverse.js | 0 .../slate/test/queries/{value => }/positions/point/block-edge.js | 0 .../queries/{value => }/positions/point/block-multiple-reverse.js | 0 .../test/queries/{value => }/positions/point/block-multiple.js | 0 .../test/queries/{value => }/positions/point/block-nested.js | 0 .../test/queries/{value => }/positions/point/block-reverse.js | 0 packages/slate/test/queries/{value => }/positions/point/block.js | 0 .../test/queries/{value => }/positions/point/inline-multiple.js | 0 .../test/queries/{value => }/positions/point/inline-nested.js | 0 .../test/queries/{value => }/positions/point/inline-reverse.js | 0 packages/slate/test/queries/{value => }/positions/point/inline.js | 0 .../queries/{value => }/positions/point/unit-block-reverse.js | 0 .../slate/test/queries/{value => }/positions/point/unit-block.js | 0 .../queries/{value => }/positions/point/unit-character-reverse.js | 0 .../test/queries/{value => }/positions/point/unit-character.js | 0 .../test/queries/{value => }/positions/point/unit-line-reverse.js | 0 .../slate/test/queries/{value => }/positions/point/unit-line.js | 0 .../test/queries/{value => }/positions/point/unit-word-reverse.js | 0 .../slate/test/queries/{value => }/positions/point/unit-word.js | 0 .../slate/test/queries/{value => }/rootBlocks/block-multiple.js | 0 .../slate/test/queries/{value => }/rootBlocks/block-nested.js | 0 .../slate/test/queries/{value => }/rootBlocks/block-reverse.js | 0 packages/slate/test/queries/{value => }/rootBlocks/block-void.js | 0 packages/slate/test/queries/{value => }/rootBlocks/block.js | 0 packages/slate/test/queries/{value => }/rootBlocks/inline.js | 0 packages/slate/test/queries/{value => }/rootInlines/block.js | 0 .../slate/test/queries/{value => }/rootInlines/inline-multiple.js | 0 .../slate/test/queries/{value => }/rootInlines/inline-nested.js | 0 .../slate/test/queries/{value => }/rootInlines/inline-reverse.js | 0 .../slate/test/queries/{value => }/rootInlines/inline-void.js | 0 packages/slate/test/queries/{value => }/rootInlines/inline.js | 0 packages/slate/test/queries/{value => }/texts/block-multiple.js | 0 packages/slate/test/queries/{value => }/texts/block-nested.js | 0 packages/slate/test/queries/{value => }/texts/block-reverse.js | 0 packages/slate/test/queries/{value => }/texts/block-void.js | 0 packages/slate/test/queries/{value => }/texts/block.js | 0 packages/slate/test/queries/{value => }/texts/inline-multiple.js | 0 packages/slate/test/queries/{value => }/texts/inline-nested.js | 0 packages/slate/test/queries/{value => }/texts/inline-reverse.js | 0 packages/slate/test/queries/{value => }/texts/inline-void.js | 0 packages/slate/test/queries/{value => }/texts/inline.js | 0 136 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/queries/{value => }/blocks/block-multiple.js (100%) rename packages/slate/test/queries/{value => }/blocks/block-nested.js (100%) rename packages/slate/test/queries/{value => }/blocks/block-reverse.js (100%) rename packages/slate/test/queries/{value => }/blocks/block-void.js (100%) rename packages/slate/test/queries/{value => }/blocks/block.js (100%) rename packages/slate/test/queries/{value => }/blocks/inline.js (100%) rename packages/slate/test/queries/{value => }/entries/block-multiple.js (100%) rename packages/slate/test/queries/{value => }/entries/block-nested.js (100%) rename packages/slate/test/queries/{value => }/entries/block-reverse.js (100%) rename packages/slate/test/queries/{value => }/entries/block-void.js (100%) rename packages/slate/test/queries/{value => }/entries/block.js (100%) rename packages/slate/test/queries/{value => }/entries/inline-multiple.js (100%) rename packages/slate/test/queries/{value => }/entries/inline-nested.js (100%) rename packages/slate/test/queries/{value => }/entries/inline-reverse.js (100%) rename packages/slate/test/queries/{value => }/entries/inline-void.js (100%) rename packages/slate/test/queries/{value => }/entries/inline.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/block-across.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/block-start.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/inline-start.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/intersection.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/multiple.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/none.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/one.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/selection-marks.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/selection-null.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/text-start.js (100%) rename packages/slate/test/queries/{value => }/getActiveMarks/union.js (100%) rename packages/slate/test/queries/{path => }/getClosestBlock/block-nested.js (100%) rename packages/slate/test/queries/{path => }/getClosestBlock/block.js (100%) rename packages/slate/test/queries/{path => }/getClosestBlock/inline.js (100%) rename packages/slate/test/queries/{path => }/getText/block-across.js (100%) rename packages/slate/test/queries/{path => }/getText/block-void.js (100%) rename packages/slate/test/queries/{path => }/getText/block.js (100%) rename packages/slate/test/queries/{path => }/getText/inline.js (100%) rename packages/slate/test/queries/{path => }/getText/text.js (100%) rename packages/slate/test/queries/{element => }/hasBlocks/block-nested.js (100%) rename packages/slate/test/queries/{element => }/hasBlocks/block.js (100%) rename packages/slate/test/queries/{element => }/hasBlocks/inline-nested.js (100%) rename packages/slate/test/queries/{element => }/hasBlocks/inline.js (100%) rename packages/slate/test/queries/{element => }/hasInlines/block-nested.js (100%) rename packages/slate/test/queries/{element => }/hasInlines/block.js (100%) rename packages/slate/test/queries/{element => }/hasInlines/inline-nested.js (100%) rename packages/slate/test/queries/{element => }/hasInlines/inline.js (100%) rename packages/slate/test/queries/{element => }/hasTexts/block-nested.js (100%) rename packages/slate/test/queries/{element => }/hasTexts/block.js (100%) rename packages/slate/test/queries/{element => }/hasTexts/inline-nested.js (100%) rename packages/slate/test/queries/{element => }/hasTexts/inline.js (100%) rename packages/slate/test/queries/{value => }/inlines/block.js (100%) rename packages/slate/test/queries/{value => }/inlines/inline-multiple.js (100%) rename packages/slate/test/queries/{value => }/inlines/inline-nested.js (100%) rename packages/slate/test/queries/{value => }/inlines/inline-reverse.js (100%) rename packages/slate/test/queries/{value => }/inlines/inline-void.js (100%) rename packages/slate/test/queries/{value => }/inlines/inline.js (100%) rename packages/slate/test/queries/{mark => }/isAtomic/atomic.js (100%) rename packages/slate/test/queries/{mark => }/isAtomic/non-atomic.js (100%) rename packages/slate/test/queries/{element => }/isInline/block.js (100%) rename packages/slate/test/queries/{element => }/isInline/inline-void.js (100%) rename packages/slate/test/queries/{element => }/isInline/inline.js (100%) rename packages/slate/test/queries/{element => }/isInline/text.js (100%) rename packages/slate/test/queries/{element => }/isInline/value.js (100%) rename packages/slate/test/queries/{element => }/isVoid/block-void.js (100%) rename packages/slate/test/queries/{element => }/isVoid/block.js (100%) rename packages/slate/test/queries/{element => }/isVoid/inline-void.js (100%) rename packages/slate/test/queries/{element => }/isVoid/inline.js (100%) rename packages/slate/test/queries/{element => }/isVoid/text.js (100%) rename packages/slate/test/queries/{element => }/isVoid/value.js (100%) rename packages/slate/test/queries/{value => }/leafBlocks/block-multiple.js (100%) rename packages/slate/test/queries/{value => }/leafBlocks/block-nested.js (100%) rename packages/slate/test/queries/{value => }/leafBlocks/block-reverse.js (100%) rename packages/slate/test/queries/{value => }/leafBlocks/block-void.js (100%) rename packages/slate/test/queries/{value => }/leafBlocks/block.js (100%) rename packages/slate/test/queries/{value => }/leafBlocks/inline.js (100%) rename packages/slate/test/queries/{value => }/leafInlines/block.js (100%) rename packages/slate/test/queries/{value => }/leafInlines/inline-multiple.js (100%) rename packages/slate/test/queries/{value => }/leafInlines/inline-nested.js (100%) rename packages/slate/test/queries/{value => }/leafInlines/inline-reverse.js (100%) rename packages/slate/test/queries/{value => }/leafInlines/inline-void.js (100%) rename packages/slate/test/queries/{value => }/leafInlines/inline.js (100%) rename packages/slate/test/queries/{value => }/positions/all/block-multiple-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/all/block-multiple.js (100%) rename packages/slate/test/queries/{value => }/positions/all/block-nested.js (100%) rename packages/slate/test/queries/{value => }/positions/all/block-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/all/block.js (100%) rename packages/slate/test/queries/{value => }/positions/all/inline-multiple.js (100%) rename packages/slate/test/queries/{value => }/positions/all/inline-nested.js (100%) rename packages/slate/test/queries/{value => }/positions/all/inline-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/all/inline.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-block-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-block.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-character-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-character.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-line-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-line.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-word-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/all/unit-word.js (100%) rename packages/slate/test/queries/{value => }/positions/point/block-edge-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/block-edge.js (100%) rename packages/slate/test/queries/{value => }/positions/point/block-multiple-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/block-multiple.js (100%) rename packages/slate/test/queries/{value => }/positions/point/block-nested.js (100%) rename packages/slate/test/queries/{value => }/positions/point/block-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/block.js (100%) rename packages/slate/test/queries/{value => }/positions/point/inline-multiple.js (100%) rename packages/slate/test/queries/{value => }/positions/point/inline-nested.js (100%) rename packages/slate/test/queries/{value => }/positions/point/inline-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/inline.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-block-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-block.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-character-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-character.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-line-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-line.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-word-reverse.js (100%) rename packages/slate/test/queries/{value => }/positions/point/unit-word.js (100%) rename packages/slate/test/queries/{value => }/rootBlocks/block-multiple.js (100%) rename packages/slate/test/queries/{value => }/rootBlocks/block-nested.js (100%) rename packages/slate/test/queries/{value => }/rootBlocks/block-reverse.js (100%) rename packages/slate/test/queries/{value => }/rootBlocks/block-void.js (100%) rename packages/slate/test/queries/{value => }/rootBlocks/block.js (100%) rename packages/slate/test/queries/{value => }/rootBlocks/inline.js (100%) rename packages/slate/test/queries/{value => }/rootInlines/block.js (100%) rename packages/slate/test/queries/{value => }/rootInlines/inline-multiple.js (100%) rename packages/slate/test/queries/{value => }/rootInlines/inline-nested.js (100%) rename packages/slate/test/queries/{value => }/rootInlines/inline-reverse.js (100%) rename packages/slate/test/queries/{value => }/rootInlines/inline-void.js (100%) rename packages/slate/test/queries/{value => }/rootInlines/inline.js (100%) rename packages/slate/test/queries/{value => }/texts/block-multiple.js (100%) rename packages/slate/test/queries/{value => }/texts/block-nested.js (100%) rename packages/slate/test/queries/{value => }/texts/block-reverse.js (100%) rename packages/slate/test/queries/{value => }/texts/block-void.js (100%) rename packages/slate/test/queries/{value => }/texts/block.js (100%) rename packages/slate/test/queries/{value => }/texts/inline-multiple.js (100%) rename packages/slate/test/queries/{value => }/texts/inline-nested.js (100%) rename packages/slate/test/queries/{value => }/texts/inline-reverse.js (100%) rename packages/slate/test/queries/{value => }/texts/inline-void.js (100%) rename packages/slate/test/queries/{value => }/texts/inline.js (100%) diff --git a/packages/slate/test/queries/value/blocks/block-multiple.js b/packages/slate/test/queries/blocks/block-multiple.js similarity index 100% rename from packages/slate/test/queries/value/blocks/block-multiple.js rename to packages/slate/test/queries/blocks/block-multiple.js diff --git a/packages/slate/test/queries/value/blocks/block-nested.js b/packages/slate/test/queries/blocks/block-nested.js similarity index 100% rename from packages/slate/test/queries/value/blocks/block-nested.js rename to packages/slate/test/queries/blocks/block-nested.js diff --git a/packages/slate/test/queries/value/blocks/block-reverse.js b/packages/slate/test/queries/blocks/block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/blocks/block-reverse.js rename to packages/slate/test/queries/blocks/block-reverse.js diff --git a/packages/slate/test/queries/value/blocks/block-void.js b/packages/slate/test/queries/blocks/block-void.js similarity index 100% rename from packages/slate/test/queries/value/blocks/block-void.js rename to packages/slate/test/queries/blocks/block-void.js diff --git a/packages/slate/test/queries/value/blocks/block.js b/packages/slate/test/queries/blocks/block.js similarity index 100% rename from packages/slate/test/queries/value/blocks/block.js rename to packages/slate/test/queries/blocks/block.js diff --git a/packages/slate/test/queries/value/blocks/inline.js b/packages/slate/test/queries/blocks/inline.js similarity index 100% rename from packages/slate/test/queries/value/blocks/inline.js rename to packages/slate/test/queries/blocks/inline.js diff --git a/packages/slate/test/queries/value/entries/block-multiple.js b/packages/slate/test/queries/entries/block-multiple.js similarity index 100% rename from packages/slate/test/queries/value/entries/block-multiple.js rename to packages/slate/test/queries/entries/block-multiple.js diff --git a/packages/slate/test/queries/value/entries/block-nested.js b/packages/slate/test/queries/entries/block-nested.js similarity index 100% rename from packages/slate/test/queries/value/entries/block-nested.js rename to packages/slate/test/queries/entries/block-nested.js diff --git a/packages/slate/test/queries/value/entries/block-reverse.js b/packages/slate/test/queries/entries/block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/entries/block-reverse.js rename to packages/slate/test/queries/entries/block-reverse.js diff --git a/packages/slate/test/queries/value/entries/block-void.js b/packages/slate/test/queries/entries/block-void.js similarity index 100% rename from packages/slate/test/queries/value/entries/block-void.js rename to packages/slate/test/queries/entries/block-void.js diff --git a/packages/slate/test/queries/value/entries/block.js b/packages/slate/test/queries/entries/block.js similarity index 100% rename from packages/slate/test/queries/value/entries/block.js rename to packages/slate/test/queries/entries/block.js diff --git a/packages/slate/test/queries/value/entries/inline-multiple.js b/packages/slate/test/queries/entries/inline-multiple.js similarity index 100% rename from packages/slate/test/queries/value/entries/inline-multiple.js rename to packages/slate/test/queries/entries/inline-multiple.js diff --git a/packages/slate/test/queries/value/entries/inline-nested.js b/packages/slate/test/queries/entries/inline-nested.js similarity index 100% rename from packages/slate/test/queries/value/entries/inline-nested.js rename to packages/slate/test/queries/entries/inline-nested.js diff --git a/packages/slate/test/queries/value/entries/inline-reverse.js b/packages/slate/test/queries/entries/inline-reverse.js similarity index 100% rename from packages/slate/test/queries/value/entries/inline-reverse.js rename to packages/slate/test/queries/entries/inline-reverse.js diff --git a/packages/slate/test/queries/value/entries/inline-void.js b/packages/slate/test/queries/entries/inline-void.js similarity index 100% rename from packages/slate/test/queries/value/entries/inline-void.js rename to packages/slate/test/queries/entries/inline-void.js diff --git a/packages/slate/test/queries/value/entries/inline.js b/packages/slate/test/queries/entries/inline.js similarity index 100% rename from packages/slate/test/queries/value/entries/inline.js rename to packages/slate/test/queries/entries/inline.js diff --git a/packages/slate/test/queries/value/getActiveMarks/block-across.js b/packages/slate/test/queries/getActiveMarks/block-across.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/block-across.js rename to packages/slate/test/queries/getActiveMarks/block-across.js diff --git a/packages/slate/test/queries/value/getActiveMarks/block-start.js b/packages/slate/test/queries/getActiveMarks/block-start.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/block-start.js rename to packages/slate/test/queries/getActiveMarks/block-start.js diff --git a/packages/slate/test/queries/value/getActiveMarks/inline-start.js b/packages/slate/test/queries/getActiveMarks/inline-start.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/inline-start.js rename to packages/slate/test/queries/getActiveMarks/inline-start.js diff --git a/packages/slate/test/queries/value/getActiveMarks/intersection.js b/packages/slate/test/queries/getActiveMarks/intersection.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/intersection.js rename to packages/slate/test/queries/getActiveMarks/intersection.js diff --git a/packages/slate/test/queries/value/getActiveMarks/multiple.js b/packages/slate/test/queries/getActiveMarks/multiple.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/multiple.js rename to packages/slate/test/queries/getActiveMarks/multiple.js diff --git a/packages/slate/test/queries/value/getActiveMarks/none.js b/packages/slate/test/queries/getActiveMarks/none.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/none.js rename to packages/slate/test/queries/getActiveMarks/none.js diff --git a/packages/slate/test/queries/value/getActiveMarks/one.js b/packages/slate/test/queries/getActiveMarks/one.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/one.js rename to packages/slate/test/queries/getActiveMarks/one.js diff --git a/packages/slate/test/queries/value/getActiveMarks/selection-marks.js b/packages/slate/test/queries/getActiveMarks/selection-marks.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/selection-marks.js rename to packages/slate/test/queries/getActiveMarks/selection-marks.js diff --git a/packages/slate/test/queries/value/getActiveMarks/selection-null.js b/packages/slate/test/queries/getActiveMarks/selection-null.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/selection-null.js rename to packages/slate/test/queries/getActiveMarks/selection-null.js diff --git a/packages/slate/test/queries/value/getActiveMarks/text-start.js b/packages/slate/test/queries/getActiveMarks/text-start.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/text-start.js rename to packages/slate/test/queries/getActiveMarks/text-start.js diff --git a/packages/slate/test/queries/value/getActiveMarks/union.js b/packages/slate/test/queries/getActiveMarks/union.js similarity index 100% rename from packages/slate/test/queries/value/getActiveMarks/union.js rename to packages/slate/test/queries/getActiveMarks/union.js diff --git a/packages/slate/test/queries/path/getClosestBlock/block-nested.js b/packages/slate/test/queries/getClosestBlock/block-nested.js similarity index 100% rename from packages/slate/test/queries/path/getClosestBlock/block-nested.js rename to packages/slate/test/queries/getClosestBlock/block-nested.js diff --git a/packages/slate/test/queries/path/getClosestBlock/block.js b/packages/slate/test/queries/getClosestBlock/block.js similarity index 100% rename from packages/slate/test/queries/path/getClosestBlock/block.js rename to packages/slate/test/queries/getClosestBlock/block.js diff --git a/packages/slate/test/queries/path/getClosestBlock/inline.js b/packages/slate/test/queries/getClosestBlock/inline.js similarity index 100% rename from packages/slate/test/queries/path/getClosestBlock/inline.js rename to packages/slate/test/queries/getClosestBlock/inline.js diff --git a/packages/slate/test/queries/path/getText/block-across.js b/packages/slate/test/queries/getText/block-across.js similarity index 100% rename from packages/slate/test/queries/path/getText/block-across.js rename to packages/slate/test/queries/getText/block-across.js diff --git a/packages/slate/test/queries/path/getText/block-void.js b/packages/slate/test/queries/getText/block-void.js similarity index 100% rename from packages/slate/test/queries/path/getText/block-void.js rename to packages/slate/test/queries/getText/block-void.js diff --git a/packages/slate/test/queries/path/getText/block.js b/packages/slate/test/queries/getText/block.js similarity index 100% rename from packages/slate/test/queries/path/getText/block.js rename to packages/slate/test/queries/getText/block.js diff --git a/packages/slate/test/queries/path/getText/inline.js b/packages/slate/test/queries/getText/inline.js similarity index 100% rename from packages/slate/test/queries/path/getText/inline.js rename to packages/slate/test/queries/getText/inline.js diff --git a/packages/slate/test/queries/path/getText/text.js b/packages/slate/test/queries/getText/text.js similarity index 100% rename from packages/slate/test/queries/path/getText/text.js rename to packages/slate/test/queries/getText/text.js diff --git a/packages/slate/test/queries/element/hasBlocks/block-nested.js b/packages/slate/test/queries/hasBlocks/block-nested.js similarity index 100% rename from packages/slate/test/queries/element/hasBlocks/block-nested.js rename to packages/slate/test/queries/hasBlocks/block-nested.js diff --git a/packages/slate/test/queries/element/hasBlocks/block.js b/packages/slate/test/queries/hasBlocks/block.js similarity index 100% rename from packages/slate/test/queries/element/hasBlocks/block.js rename to packages/slate/test/queries/hasBlocks/block.js diff --git a/packages/slate/test/queries/element/hasBlocks/inline-nested.js b/packages/slate/test/queries/hasBlocks/inline-nested.js similarity index 100% rename from packages/slate/test/queries/element/hasBlocks/inline-nested.js rename to packages/slate/test/queries/hasBlocks/inline-nested.js diff --git a/packages/slate/test/queries/element/hasBlocks/inline.js b/packages/slate/test/queries/hasBlocks/inline.js similarity index 100% rename from packages/slate/test/queries/element/hasBlocks/inline.js rename to packages/slate/test/queries/hasBlocks/inline.js diff --git a/packages/slate/test/queries/element/hasInlines/block-nested.js b/packages/slate/test/queries/hasInlines/block-nested.js similarity index 100% rename from packages/slate/test/queries/element/hasInlines/block-nested.js rename to packages/slate/test/queries/hasInlines/block-nested.js diff --git a/packages/slate/test/queries/element/hasInlines/block.js b/packages/slate/test/queries/hasInlines/block.js similarity index 100% rename from packages/slate/test/queries/element/hasInlines/block.js rename to packages/slate/test/queries/hasInlines/block.js diff --git a/packages/slate/test/queries/element/hasInlines/inline-nested.js b/packages/slate/test/queries/hasInlines/inline-nested.js similarity index 100% rename from packages/slate/test/queries/element/hasInlines/inline-nested.js rename to packages/slate/test/queries/hasInlines/inline-nested.js diff --git a/packages/slate/test/queries/element/hasInlines/inline.js b/packages/slate/test/queries/hasInlines/inline.js similarity index 100% rename from packages/slate/test/queries/element/hasInlines/inline.js rename to packages/slate/test/queries/hasInlines/inline.js diff --git a/packages/slate/test/queries/element/hasTexts/block-nested.js b/packages/slate/test/queries/hasTexts/block-nested.js similarity index 100% rename from packages/slate/test/queries/element/hasTexts/block-nested.js rename to packages/slate/test/queries/hasTexts/block-nested.js diff --git a/packages/slate/test/queries/element/hasTexts/block.js b/packages/slate/test/queries/hasTexts/block.js similarity index 100% rename from packages/slate/test/queries/element/hasTexts/block.js rename to packages/slate/test/queries/hasTexts/block.js diff --git a/packages/slate/test/queries/element/hasTexts/inline-nested.js b/packages/slate/test/queries/hasTexts/inline-nested.js similarity index 100% rename from packages/slate/test/queries/element/hasTexts/inline-nested.js rename to packages/slate/test/queries/hasTexts/inline-nested.js diff --git a/packages/slate/test/queries/element/hasTexts/inline.js b/packages/slate/test/queries/hasTexts/inline.js similarity index 100% rename from packages/slate/test/queries/element/hasTexts/inline.js rename to packages/slate/test/queries/hasTexts/inline.js diff --git a/packages/slate/test/queries/value/inlines/block.js b/packages/slate/test/queries/inlines/block.js similarity index 100% rename from packages/slate/test/queries/value/inlines/block.js rename to packages/slate/test/queries/inlines/block.js diff --git a/packages/slate/test/queries/value/inlines/inline-multiple.js b/packages/slate/test/queries/inlines/inline-multiple.js similarity index 100% rename from packages/slate/test/queries/value/inlines/inline-multiple.js rename to packages/slate/test/queries/inlines/inline-multiple.js diff --git a/packages/slate/test/queries/value/inlines/inline-nested.js b/packages/slate/test/queries/inlines/inline-nested.js similarity index 100% rename from packages/slate/test/queries/value/inlines/inline-nested.js rename to packages/slate/test/queries/inlines/inline-nested.js diff --git a/packages/slate/test/queries/value/inlines/inline-reverse.js b/packages/slate/test/queries/inlines/inline-reverse.js similarity index 100% rename from packages/slate/test/queries/value/inlines/inline-reverse.js rename to packages/slate/test/queries/inlines/inline-reverse.js diff --git a/packages/slate/test/queries/value/inlines/inline-void.js b/packages/slate/test/queries/inlines/inline-void.js similarity index 100% rename from packages/slate/test/queries/value/inlines/inline-void.js rename to packages/slate/test/queries/inlines/inline-void.js diff --git a/packages/slate/test/queries/value/inlines/inline.js b/packages/slate/test/queries/inlines/inline.js similarity index 100% rename from packages/slate/test/queries/value/inlines/inline.js rename to packages/slate/test/queries/inlines/inline.js diff --git a/packages/slate/test/queries/mark/isAtomic/atomic.js b/packages/slate/test/queries/isAtomic/atomic.js similarity index 100% rename from packages/slate/test/queries/mark/isAtomic/atomic.js rename to packages/slate/test/queries/isAtomic/atomic.js diff --git a/packages/slate/test/queries/mark/isAtomic/non-atomic.js b/packages/slate/test/queries/isAtomic/non-atomic.js similarity index 100% rename from packages/slate/test/queries/mark/isAtomic/non-atomic.js rename to packages/slate/test/queries/isAtomic/non-atomic.js diff --git a/packages/slate/test/queries/element/isInline/block.js b/packages/slate/test/queries/isInline/block.js similarity index 100% rename from packages/slate/test/queries/element/isInline/block.js rename to packages/slate/test/queries/isInline/block.js diff --git a/packages/slate/test/queries/element/isInline/inline-void.js b/packages/slate/test/queries/isInline/inline-void.js similarity index 100% rename from packages/slate/test/queries/element/isInline/inline-void.js rename to packages/slate/test/queries/isInline/inline-void.js diff --git a/packages/slate/test/queries/element/isInline/inline.js b/packages/slate/test/queries/isInline/inline.js similarity index 100% rename from packages/slate/test/queries/element/isInline/inline.js rename to packages/slate/test/queries/isInline/inline.js diff --git a/packages/slate/test/queries/element/isInline/text.js b/packages/slate/test/queries/isInline/text.js similarity index 100% rename from packages/slate/test/queries/element/isInline/text.js rename to packages/slate/test/queries/isInline/text.js diff --git a/packages/slate/test/queries/element/isInline/value.js b/packages/slate/test/queries/isInline/value.js similarity index 100% rename from packages/slate/test/queries/element/isInline/value.js rename to packages/slate/test/queries/isInline/value.js diff --git a/packages/slate/test/queries/element/isVoid/block-void.js b/packages/slate/test/queries/isVoid/block-void.js similarity index 100% rename from packages/slate/test/queries/element/isVoid/block-void.js rename to packages/slate/test/queries/isVoid/block-void.js diff --git a/packages/slate/test/queries/element/isVoid/block.js b/packages/slate/test/queries/isVoid/block.js similarity index 100% rename from packages/slate/test/queries/element/isVoid/block.js rename to packages/slate/test/queries/isVoid/block.js diff --git a/packages/slate/test/queries/element/isVoid/inline-void.js b/packages/slate/test/queries/isVoid/inline-void.js similarity index 100% rename from packages/slate/test/queries/element/isVoid/inline-void.js rename to packages/slate/test/queries/isVoid/inline-void.js diff --git a/packages/slate/test/queries/element/isVoid/inline.js b/packages/slate/test/queries/isVoid/inline.js similarity index 100% rename from packages/slate/test/queries/element/isVoid/inline.js rename to packages/slate/test/queries/isVoid/inline.js diff --git a/packages/slate/test/queries/element/isVoid/text.js b/packages/slate/test/queries/isVoid/text.js similarity index 100% rename from packages/slate/test/queries/element/isVoid/text.js rename to packages/slate/test/queries/isVoid/text.js diff --git a/packages/slate/test/queries/element/isVoid/value.js b/packages/slate/test/queries/isVoid/value.js similarity index 100% rename from packages/slate/test/queries/element/isVoid/value.js rename to packages/slate/test/queries/isVoid/value.js diff --git a/packages/slate/test/queries/value/leafBlocks/block-multiple.js b/packages/slate/test/queries/leafBlocks/block-multiple.js similarity index 100% rename from packages/slate/test/queries/value/leafBlocks/block-multiple.js rename to packages/slate/test/queries/leafBlocks/block-multiple.js diff --git a/packages/slate/test/queries/value/leafBlocks/block-nested.js b/packages/slate/test/queries/leafBlocks/block-nested.js similarity index 100% rename from packages/slate/test/queries/value/leafBlocks/block-nested.js rename to packages/slate/test/queries/leafBlocks/block-nested.js diff --git a/packages/slate/test/queries/value/leafBlocks/block-reverse.js b/packages/slate/test/queries/leafBlocks/block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/leafBlocks/block-reverse.js rename to packages/slate/test/queries/leafBlocks/block-reverse.js diff --git a/packages/slate/test/queries/value/leafBlocks/block-void.js b/packages/slate/test/queries/leafBlocks/block-void.js similarity index 100% rename from packages/slate/test/queries/value/leafBlocks/block-void.js rename to packages/slate/test/queries/leafBlocks/block-void.js diff --git a/packages/slate/test/queries/value/leafBlocks/block.js b/packages/slate/test/queries/leafBlocks/block.js similarity index 100% rename from packages/slate/test/queries/value/leafBlocks/block.js rename to packages/slate/test/queries/leafBlocks/block.js diff --git a/packages/slate/test/queries/value/leafBlocks/inline.js b/packages/slate/test/queries/leafBlocks/inline.js similarity index 100% rename from packages/slate/test/queries/value/leafBlocks/inline.js rename to packages/slate/test/queries/leafBlocks/inline.js diff --git a/packages/slate/test/queries/value/leafInlines/block.js b/packages/slate/test/queries/leafInlines/block.js similarity index 100% rename from packages/slate/test/queries/value/leafInlines/block.js rename to packages/slate/test/queries/leafInlines/block.js diff --git a/packages/slate/test/queries/value/leafInlines/inline-multiple.js b/packages/slate/test/queries/leafInlines/inline-multiple.js similarity index 100% rename from packages/slate/test/queries/value/leafInlines/inline-multiple.js rename to packages/slate/test/queries/leafInlines/inline-multiple.js diff --git a/packages/slate/test/queries/value/leafInlines/inline-nested.js b/packages/slate/test/queries/leafInlines/inline-nested.js similarity index 100% rename from packages/slate/test/queries/value/leafInlines/inline-nested.js rename to packages/slate/test/queries/leafInlines/inline-nested.js diff --git a/packages/slate/test/queries/value/leafInlines/inline-reverse.js b/packages/slate/test/queries/leafInlines/inline-reverse.js similarity index 100% rename from packages/slate/test/queries/value/leafInlines/inline-reverse.js rename to packages/slate/test/queries/leafInlines/inline-reverse.js diff --git a/packages/slate/test/queries/value/leafInlines/inline-void.js b/packages/slate/test/queries/leafInlines/inline-void.js similarity index 100% rename from packages/slate/test/queries/value/leafInlines/inline-void.js rename to packages/slate/test/queries/leafInlines/inline-void.js diff --git a/packages/slate/test/queries/value/leafInlines/inline.js b/packages/slate/test/queries/leafInlines/inline.js similarity index 100% rename from packages/slate/test/queries/value/leafInlines/inline.js rename to packages/slate/test/queries/leafInlines/inline.js diff --git a/packages/slate/test/queries/value/positions/all/block-multiple-reverse.js b/packages/slate/test/queries/positions/all/block-multiple-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/block-multiple-reverse.js rename to packages/slate/test/queries/positions/all/block-multiple-reverse.js diff --git a/packages/slate/test/queries/value/positions/all/block-multiple.js b/packages/slate/test/queries/positions/all/block-multiple.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/block-multiple.js rename to packages/slate/test/queries/positions/all/block-multiple.js diff --git a/packages/slate/test/queries/value/positions/all/block-nested.js b/packages/slate/test/queries/positions/all/block-nested.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/block-nested.js rename to packages/slate/test/queries/positions/all/block-nested.js diff --git a/packages/slate/test/queries/value/positions/all/block-reverse.js b/packages/slate/test/queries/positions/all/block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/block-reverse.js rename to packages/slate/test/queries/positions/all/block-reverse.js diff --git a/packages/slate/test/queries/value/positions/all/block.js b/packages/slate/test/queries/positions/all/block.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/block.js rename to packages/slate/test/queries/positions/all/block.js diff --git a/packages/slate/test/queries/value/positions/all/inline-multiple.js b/packages/slate/test/queries/positions/all/inline-multiple.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/inline-multiple.js rename to packages/slate/test/queries/positions/all/inline-multiple.js diff --git a/packages/slate/test/queries/value/positions/all/inline-nested.js b/packages/slate/test/queries/positions/all/inline-nested.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/inline-nested.js rename to packages/slate/test/queries/positions/all/inline-nested.js diff --git a/packages/slate/test/queries/value/positions/all/inline-reverse.js b/packages/slate/test/queries/positions/all/inline-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/inline-reverse.js rename to packages/slate/test/queries/positions/all/inline-reverse.js diff --git a/packages/slate/test/queries/value/positions/all/inline.js b/packages/slate/test/queries/positions/all/inline.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/inline.js rename to packages/slate/test/queries/positions/all/inline.js diff --git a/packages/slate/test/queries/value/positions/all/unit-block-reverse.js b/packages/slate/test/queries/positions/all/unit-block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-block-reverse.js rename to packages/slate/test/queries/positions/all/unit-block-reverse.js diff --git a/packages/slate/test/queries/value/positions/all/unit-block.js b/packages/slate/test/queries/positions/all/unit-block.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-block.js rename to packages/slate/test/queries/positions/all/unit-block.js diff --git a/packages/slate/test/queries/value/positions/all/unit-character-reverse.js b/packages/slate/test/queries/positions/all/unit-character-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-character-reverse.js rename to packages/slate/test/queries/positions/all/unit-character-reverse.js diff --git a/packages/slate/test/queries/value/positions/all/unit-character.js b/packages/slate/test/queries/positions/all/unit-character.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-character.js rename to packages/slate/test/queries/positions/all/unit-character.js diff --git a/packages/slate/test/queries/value/positions/all/unit-line-reverse.js b/packages/slate/test/queries/positions/all/unit-line-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-line-reverse.js rename to packages/slate/test/queries/positions/all/unit-line-reverse.js diff --git a/packages/slate/test/queries/value/positions/all/unit-line.js b/packages/slate/test/queries/positions/all/unit-line.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-line.js rename to packages/slate/test/queries/positions/all/unit-line.js diff --git a/packages/slate/test/queries/value/positions/all/unit-word-reverse.js b/packages/slate/test/queries/positions/all/unit-word-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-word-reverse.js rename to packages/slate/test/queries/positions/all/unit-word-reverse.js diff --git a/packages/slate/test/queries/value/positions/all/unit-word.js b/packages/slate/test/queries/positions/all/unit-word.js similarity index 100% rename from packages/slate/test/queries/value/positions/all/unit-word.js rename to packages/slate/test/queries/positions/all/unit-word.js diff --git a/packages/slate/test/queries/value/positions/point/block-edge-reverse.js b/packages/slate/test/queries/positions/point/block-edge-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/block-edge-reverse.js rename to packages/slate/test/queries/positions/point/block-edge-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/block-edge.js b/packages/slate/test/queries/positions/point/block-edge.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/block-edge.js rename to packages/slate/test/queries/positions/point/block-edge.js diff --git a/packages/slate/test/queries/value/positions/point/block-multiple-reverse.js b/packages/slate/test/queries/positions/point/block-multiple-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/block-multiple-reverse.js rename to packages/slate/test/queries/positions/point/block-multiple-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/block-multiple.js b/packages/slate/test/queries/positions/point/block-multiple.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/block-multiple.js rename to packages/slate/test/queries/positions/point/block-multiple.js diff --git a/packages/slate/test/queries/value/positions/point/block-nested.js b/packages/slate/test/queries/positions/point/block-nested.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/block-nested.js rename to packages/slate/test/queries/positions/point/block-nested.js diff --git a/packages/slate/test/queries/value/positions/point/block-reverse.js b/packages/slate/test/queries/positions/point/block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/block-reverse.js rename to packages/slate/test/queries/positions/point/block-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/block.js b/packages/slate/test/queries/positions/point/block.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/block.js rename to packages/slate/test/queries/positions/point/block.js diff --git a/packages/slate/test/queries/value/positions/point/inline-multiple.js b/packages/slate/test/queries/positions/point/inline-multiple.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/inline-multiple.js rename to packages/slate/test/queries/positions/point/inline-multiple.js diff --git a/packages/slate/test/queries/value/positions/point/inline-nested.js b/packages/slate/test/queries/positions/point/inline-nested.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/inline-nested.js rename to packages/slate/test/queries/positions/point/inline-nested.js diff --git a/packages/slate/test/queries/value/positions/point/inline-reverse.js b/packages/slate/test/queries/positions/point/inline-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/inline-reverse.js rename to packages/slate/test/queries/positions/point/inline-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/inline.js b/packages/slate/test/queries/positions/point/inline.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/inline.js rename to packages/slate/test/queries/positions/point/inline.js diff --git a/packages/slate/test/queries/value/positions/point/unit-block-reverse.js b/packages/slate/test/queries/positions/point/unit-block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-block-reverse.js rename to packages/slate/test/queries/positions/point/unit-block-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/unit-block.js b/packages/slate/test/queries/positions/point/unit-block.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-block.js rename to packages/slate/test/queries/positions/point/unit-block.js diff --git a/packages/slate/test/queries/value/positions/point/unit-character-reverse.js b/packages/slate/test/queries/positions/point/unit-character-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-character-reverse.js rename to packages/slate/test/queries/positions/point/unit-character-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/unit-character.js b/packages/slate/test/queries/positions/point/unit-character.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-character.js rename to packages/slate/test/queries/positions/point/unit-character.js diff --git a/packages/slate/test/queries/value/positions/point/unit-line-reverse.js b/packages/slate/test/queries/positions/point/unit-line-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-line-reverse.js rename to packages/slate/test/queries/positions/point/unit-line-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/unit-line.js b/packages/slate/test/queries/positions/point/unit-line.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-line.js rename to packages/slate/test/queries/positions/point/unit-line.js diff --git a/packages/slate/test/queries/value/positions/point/unit-word-reverse.js b/packages/slate/test/queries/positions/point/unit-word-reverse.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-word-reverse.js rename to packages/slate/test/queries/positions/point/unit-word-reverse.js diff --git a/packages/slate/test/queries/value/positions/point/unit-word.js b/packages/slate/test/queries/positions/point/unit-word.js similarity index 100% rename from packages/slate/test/queries/value/positions/point/unit-word.js rename to packages/slate/test/queries/positions/point/unit-word.js diff --git a/packages/slate/test/queries/value/rootBlocks/block-multiple.js b/packages/slate/test/queries/rootBlocks/block-multiple.js similarity index 100% rename from packages/slate/test/queries/value/rootBlocks/block-multiple.js rename to packages/slate/test/queries/rootBlocks/block-multiple.js diff --git a/packages/slate/test/queries/value/rootBlocks/block-nested.js b/packages/slate/test/queries/rootBlocks/block-nested.js similarity index 100% rename from packages/slate/test/queries/value/rootBlocks/block-nested.js rename to packages/slate/test/queries/rootBlocks/block-nested.js diff --git a/packages/slate/test/queries/value/rootBlocks/block-reverse.js b/packages/slate/test/queries/rootBlocks/block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/rootBlocks/block-reverse.js rename to packages/slate/test/queries/rootBlocks/block-reverse.js diff --git a/packages/slate/test/queries/value/rootBlocks/block-void.js b/packages/slate/test/queries/rootBlocks/block-void.js similarity index 100% rename from packages/slate/test/queries/value/rootBlocks/block-void.js rename to packages/slate/test/queries/rootBlocks/block-void.js diff --git a/packages/slate/test/queries/value/rootBlocks/block.js b/packages/slate/test/queries/rootBlocks/block.js similarity index 100% rename from packages/slate/test/queries/value/rootBlocks/block.js rename to packages/slate/test/queries/rootBlocks/block.js diff --git a/packages/slate/test/queries/value/rootBlocks/inline.js b/packages/slate/test/queries/rootBlocks/inline.js similarity index 100% rename from packages/slate/test/queries/value/rootBlocks/inline.js rename to packages/slate/test/queries/rootBlocks/inline.js diff --git a/packages/slate/test/queries/value/rootInlines/block.js b/packages/slate/test/queries/rootInlines/block.js similarity index 100% rename from packages/slate/test/queries/value/rootInlines/block.js rename to packages/slate/test/queries/rootInlines/block.js diff --git a/packages/slate/test/queries/value/rootInlines/inline-multiple.js b/packages/slate/test/queries/rootInlines/inline-multiple.js similarity index 100% rename from packages/slate/test/queries/value/rootInlines/inline-multiple.js rename to packages/slate/test/queries/rootInlines/inline-multiple.js diff --git a/packages/slate/test/queries/value/rootInlines/inline-nested.js b/packages/slate/test/queries/rootInlines/inline-nested.js similarity index 100% rename from packages/slate/test/queries/value/rootInlines/inline-nested.js rename to packages/slate/test/queries/rootInlines/inline-nested.js diff --git a/packages/slate/test/queries/value/rootInlines/inline-reverse.js b/packages/slate/test/queries/rootInlines/inline-reverse.js similarity index 100% rename from packages/slate/test/queries/value/rootInlines/inline-reverse.js rename to packages/slate/test/queries/rootInlines/inline-reverse.js diff --git a/packages/slate/test/queries/value/rootInlines/inline-void.js b/packages/slate/test/queries/rootInlines/inline-void.js similarity index 100% rename from packages/slate/test/queries/value/rootInlines/inline-void.js rename to packages/slate/test/queries/rootInlines/inline-void.js diff --git a/packages/slate/test/queries/value/rootInlines/inline.js b/packages/slate/test/queries/rootInlines/inline.js similarity index 100% rename from packages/slate/test/queries/value/rootInlines/inline.js rename to packages/slate/test/queries/rootInlines/inline.js diff --git a/packages/slate/test/queries/value/texts/block-multiple.js b/packages/slate/test/queries/texts/block-multiple.js similarity index 100% rename from packages/slate/test/queries/value/texts/block-multiple.js rename to packages/slate/test/queries/texts/block-multiple.js diff --git a/packages/slate/test/queries/value/texts/block-nested.js b/packages/slate/test/queries/texts/block-nested.js similarity index 100% rename from packages/slate/test/queries/value/texts/block-nested.js rename to packages/slate/test/queries/texts/block-nested.js diff --git a/packages/slate/test/queries/value/texts/block-reverse.js b/packages/slate/test/queries/texts/block-reverse.js similarity index 100% rename from packages/slate/test/queries/value/texts/block-reverse.js rename to packages/slate/test/queries/texts/block-reverse.js diff --git a/packages/slate/test/queries/value/texts/block-void.js b/packages/slate/test/queries/texts/block-void.js similarity index 100% rename from packages/slate/test/queries/value/texts/block-void.js rename to packages/slate/test/queries/texts/block-void.js diff --git a/packages/slate/test/queries/value/texts/block.js b/packages/slate/test/queries/texts/block.js similarity index 100% rename from packages/slate/test/queries/value/texts/block.js rename to packages/slate/test/queries/texts/block.js diff --git a/packages/slate/test/queries/value/texts/inline-multiple.js b/packages/slate/test/queries/texts/inline-multiple.js similarity index 100% rename from packages/slate/test/queries/value/texts/inline-multiple.js rename to packages/slate/test/queries/texts/inline-multiple.js diff --git a/packages/slate/test/queries/value/texts/inline-nested.js b/packages/slate/test/queries/texts/inline-nested.js similarity index 100% rename from packages/slate/test/queries/value/texts/inline-nested.js rename to packages/slate/test/queries/texts/inline-nested.js diff --git a/packages/slate/test/queries/value/texts/inline-reverse.js b/packages/slate/test/queries/texts/inline-reverse.js similarity index 100% rename from packages/slate/test/queries/value/texts/inline-reverse.js rename to packages/slate/test/queries/texts/inline-reverse.js diff --git a/packages/slate/test/queries/value/texts/inline-void.js b/packages/slate/test/queries/texts/inline-void.js similarity index 100% rename from packages/slate/test/queries/value/texts/inline-void.js rename to packages/slate/test/queries/texts/inline-void.js diff --git a/packages/slate/test/queries/value/texts/inline.js b/packages/slate/test/queries/texts/inline.js similarity index 100% rename from packages/slate/test/queries/value/texts/inline.js rename to packages/slate/test/queries/texts/inline.js From a43ffdd7b1855b372dadaa76ba6123c7cef94c14 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 23 Oct 2019 14:42:08 -0400 Subject: [PATCH 054/165] restructure operations tests --- .../operations/{insert-text => insert_text}/annotation-before.js | 0 .../{merge-node => merge_node}/annotation-across-blocks.js | 0 .../operations/{move-node => move_node}/path-equals-new-path.js | 0 .../{remove-node => remove_node}/annotation-across-blocks.js | 0 .../test/operations/{remove-text => remove_text}/anchor-after.js | 0 .../test/operations/{remove-text => remove_text}/anchor-before.js | 0 .../test/operations/{remove-text => remove_text}/anchor-middle.js | 0 .../operations/{remove-text => remove_text}/annotation-after.js | 0 .../operations/{remove-text => remove_text}/annotation-before.js | 0 .../operations/{remove-text => remove_text}/annotation-middle.js | 0 .../test/operations/{remove-text => remove_text}/cursor-after.js | 0 .../test/operations/{remove-text => remove_text}/cursor-before.js | 0 .../test/operations/{remove-text => remove_text}/cursor-middle.js | 0 .../test/operations/{remove-text => remove_text}/focus-after.js | 0 .../test/operations/{remove-text => remove_text}/focus-before.js | 0 .../test/operations/{remove-text => remove_text}/focus-middle.js | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename packages/slate/test/operations/{insert-text => insert_text}/annotation-before.js (100%) rename packages/slate/test/operations/{merge-node => merge_node}/annotation-across-blocks.js (100%) rename packages/slate/test/operations/{move-node => move_node}/path-equals-new-path.js (100%) rename packages/slate/test/operations/{remove-node => remove_node}/annotation-across-blocks.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/anchor-after.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/anchor-before.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/anchor-middle.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/annotation-after.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/annotation-before.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/annotation-middle.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/cursor-after.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/cursor-before.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/cursor-middle.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/focus-after.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/focus-before.js (100%) rename packages/slate/test/operations/{remove-text => remove_text}/focus-middle.js (100%) diff --git a/packages/slate/test/operations/insert-text/annotation-before.js b/packages/slate/test/operations/insert_text/annotation-before.js similarity index 100% rename from packages/slate/test/operations/insert-text/annotation-before.js rename to packages/slate/test/operations/insert_text/annotation-before.js diff --git a/packages/slate/test/operations/merge-node/annotation-across-blocks.js b/packages/slate/test/operations/merge_node/annotation-across-blocks.js similarity index 100% rename from packages/slate/test/operations/merge-node/annotation-across-blocks.js rename to packages/slate/test/operations/merge_node/annotation-across-blocks.js diff --git a/packages/slate/test/operations/move-node/path-equals-new-path.js b/packages/slate/test/operations/move_node/path-equals-new-path.js similarity index 100% rename from packages/slate/test/operations/move-node/path-equals-new-path.js rename to packages/slate/test/operations/move_node/path-equals-new-path.js diff --git a/packages/slate/test/operations/remove-node/annotation-across-blocks.js b/packages/slate/test/operations/remove_node/annotation-across-blocks.js similarity index 100% rename from packages/slate/test/operations/remove-node/annotation-across-blocks.js rename to packages/slate/test/operations/remove_node/annotation-across-blocks.js diff --git a/packages/slate/test/operations/remove-text/anchor-after.js b/packages/slate/test/operations/remove_text/anchor-after.js similarity index 100% rename from packages/slate/test/operations/remove-text/anchor-after.js rename to packages/slate/test/operations/remove_text/anchor-after.js diff --git a/packages/slate/test/operations/remove-text/anchor-before.js b/packages/slate/test/operations/remove_text/anchor-before.js similarity index 100% rename from packages/slate/test/operations/remove-text/anchor-before.js rename to packages/slate/test/operations/remove_text/anchor-before.js diff --git a/packages/slate/test/operations/remove-text/anchor-middle.js b/packages/slate/test/operations/remove_text/anchor-middle.js similarity index 100% rename from packages/slate/test/operations/remove-text/anchor-middle.js rename to packages/slate/test/operations/remove_text/anchor-middle.js diff --git a/packages/slate/test/operations/remove-text/annotation-after.js b/packages/slate/test/operations/remove_text/annotation-after.js similarity index 100% rename from packages/slate/test/operations/remove-text/annotation-after.js rename to packages/slate/test/operations/remove_text/annotation-after.js diff --git a/packages/slate/test/operations/remove-text/annotation-before.js b/packages/slate/test/operations/remove_text/annotation-before.js similarity index 100% rename from packages/slate/test/operations/remove-text/annotation-before.js rename to packages/slate/test/operations/remove_text/annotation-before.js diff --git a/packages/slate/test/operations/remove-text/annotation-middle.js b/packages/slate/test/operations/remove_text/annotation-middle.js similarity index 100% rename from packages/slate/test/operations/remove-text/annotation-middle.js rename to packages/slate/test/operations/remove_text/annotation-middle.js diff --git a/packages/slate/test/operations/remove-text/cursor-after.js b/packages/slate/test/operations/remove_text/cursor-after.js similarity index 100% rename from packages/slate/test/operations/remove-text/cursor-after.js rename to packages/slate/test/operations/remove_text/cursor-after.js diff --git a/packages/slate/test/operations/remove-text/cursor-before.js b/packages/slate/test/operations/remove_text/cursor-before.js similarity index 100% rename from packages/slate/test/operations/remove-text/cursor-before.js rename to packages/slate/test/operations/remove_text/cursor-before.js diff --git a/packages/slate/test/operations/remove-text/cursor-middle.js b/packages/slate/test/operations/remove_text/cursor-middle.js similarity index 100% rename from packages/slate/test/operations/remove-text/cursor-middle.js rename to packages/slate/test/operations/remove_text/cursor-middle.js diff --git a/packages/slate/test/operations/remove-text/focus-after.js b/packages/slate/test/operations/remove_text/focus-after.js similarity index 100% rename from packages/slate/test/operations/remove-text/focus-after.js rename to packages/slate/test/operations/remove_text/focus-after.js diff --git a/packages/slate/test/operations/remove-text/focus-before.js b/packages/slate/test/operations/remove_text/focus-before.js similarity index 100% rename from packages/slate/test/operations/remove-text/focus-before.js rename to packages/slate/test/operations/remove_text/focus-before.js diff --git a/packages/slate/test/operations/remove-text/focus-middle.js b/packages/slate/test/operations/remove_text/focus-middle.js similarity index 100% rename from packages/slate/test/operations/remove-text/focus-middle.js rename to packages/slate/test/operations/remove_text/focus-middle.js From d49f829dfd4c67e4549b8d34f49f37fd0577b268 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 23 Oct 2019 16:16:13 -0400 Subject: [PATCH 055/165] more work converting to multi-purpose commands --- packages/slate/src/classes/commands/point.ts | 107 --------- packages/slate/src/classes/commands/range.ts | 131 ---------- packages/slate/src/classes/commands/value.ts | 223 ++++++++++++++---- packages/slate/src/classes/queries/path.ts | 20 +- .../slate/test/commands/deselect/basic.js | 2 +- .../slate/test/commands/deselect/unfocused.js | 2 +- .../selection/{is-empty.js => block-empty.js} | 8 +- .../insertInline/selection/block-end.js | 7 +- .../insertInline/selection/block-middle.js | 6 +- .../insertInline/selection/block-start.js | 10 +- .../{with-inline.js => block-void.js} | 17 +- .../insertInline/selection/inline-middle.js | 16 +- .../insertInline/selection/is-void.js | 27 --- .../test/commands/move/anchor/backward.js | 2 +- .../slate/test/commands/move/anchor/basic.js | 2 +- .../test/commands/move/anchor/collapsed.js | 2 +- .../test/commands/move/anchor/distance.js | 2 +- .../commands/move/anchor/reverse-backward.js | 2 +- .../commands/move/anchor/reverse-basic.js | 2 +- .../commands/move/anchor/reverse-collapsed.js | 2 +- .../commands/move/anchor/reverse-distance.js | 2 +- .../commands/move/end/backward-reverse.js | 2 +- .../slate/test/commands/move/end/backward.js | 2 +- .../commands/move/end/collapsed-reverse.js | 2 +- .../slate/test/commands/move/end/collapsed.js | 2 +- .../commands/move/end/distance-reverse.js | 2 +- .../slate/test/commands/move/end/distance.js | 2 +- .../commands/move/end/expanded-reverse.js | 2 +- .../slate/test/commands/move/end/expanded.js | 2 +- .../move/end/from-backward-reverse.js | 2 +- .../commands/move/end/to-backward-reverse.js | 2 +- .../test/commands/move/focus/backward.js | 2 +- .../commands/move/focus/collapsed-reverse.js | 2 +- .../test/commands/move/focus/collapsed.js | 2 +- .../commands/move/focus/distance-reverse.js | 2 +- .../test/commands/move/focus/distance.js | 2 +- .../commands/move/focus/expanded-reverse.js | 2 +- .../test/commands/move/focus/expanded.js | 2 +- .../move/focus/to-backward-reverse.js | 2 +- .../commands/move/start/backward-reverse.js | 2 +- .../test/commands/move/start/backward.js | 2 +- .../commands/move/start/collapsed-reverse.js | 2 +- .../test/commands/move/start/collapsed.js | 2 +- .../commands/move/start/distance-reverse.js | 2 +- .../test/commands/move/start/distance.js | 2 +- .../commands/move/start/expanded-reverse.js | 2 +- .../test/commands/move/start/expanded.js | 2 +- .../test/commands/move/start/from-backward.js | 2 +- .../test/commands/move/start/to-backward.js | 2 +- packages/slate/test/commands/select/basic.js | 2 +- .../test/commands/splitBlock/point/block.js | 2 +- .../commands/splitBlock/point/selection.js | 2 +- .../splitBlock/selection/after-inline-void.js | 7 +- .../splitBlock/selection/after-inline.js | 27 +-- .../splitBlock/selection/before-inline.js | 36 +-- .../selection/{depth.js => block-depth.js} | 24 +- .../splitBlock/selection/with-inline.js | 36 +-- .../splitBlock/selection/with-marks.js | 33 --- .../splitInline/selection/block-end.js | 5 + .../splitInline/selection/block-middle.js | 5 + .../splitInline/selection/block-start.js | 5 + .../selection/{with-delete.js => expanded.js} | 5 + .../commands/splitInline/selection/height.js | 6 +- .../selection/{with-marks.js => mark.js} | 5 + 64 files changed, 377 insertions(+), 471 deletions(-) rename packages/slate/test/commands/insertInline/selection/{is-empty.js => block-empty.js} (74%) rename packages/slate/test/commands/insertInline/selection/{with-inline.js => block-void.js} (53%) delete mode 100644 packages/slate/test/commands/insertInline/selection/is-void.js rename packages/slate/test/commands/splitBlock/selection/{depth.js => block-depth.js} (58%) delete mode 100644 packages/slate/test/commands/splitBlock/selection/with-marks.js rename packages/slate/test/commands/splitInline/selection/{with-delete.js => expanded.js} (83%) rename packages/slate/test/commands/splitInline/selection/{with-marks.js => mark.js} (87%) diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts index 072a424e1f..ac421c4740 100755 --- a/packages/slate/src/classes/commands/point.ts +++ b/packages/slate/src/classes/commands/point.ts @@ -2,37 +2,6 @@ import { produce } from 'immer' import { Editor, Element, Fragment, Node, Path, Point, Range } from '../..' class PointCommands { - /** - * Delete a span of content starting from a point. - */ - - deleteAtPoint( - this: Editor, - point: Point, - options: { - distance?: number - unit?: 'character' | 'word' | 'line' | 'block' - reverse?: boolean - } = {} - ): void { - const { reverse = false, unit = 'character', ...rest } = options - const furthestVoid = this.getFurthestVoid(point.path) - - if (furthestVoid) { - const [, voidPath] = furthestVoid - this.removeNodeAtPath(voidPath) - return - } - - const target = reverse - ? this.getPreviousPoint(point, { unit, ...rest }) - : this.getNextPoint(point, { unit, ...rest }) - - if (target) { - this.deleteAtRange({ anchor: point, focus: target }) - } - } - /** * Insert a fragment of nodes at a point. */ @@ -68,22 +37,6 @@ class PointCommands { }) } - /** - * Insert an inline node at a point. - */ - - insertInlineAtPoint(this: Editor, point: Point, inline: Element): void { - this.withoutNormalizing(() => { - const pointRef = this.createPointRef(point) - this.splitInlineAtPoint(point, { always: false }) - - if (pointRef.current != null) { - this.insertNodeAtPath(pointRef.current.path, inline) - pointRef.unref() - } - }) - } - /** * Remove a string of text by length from a specific point in the document. */ @@ -124,66 +77,6 @@ class PointCommands { return point } - /** - * Split the block node at a specific point, up to a certain block height. - */ - - splitBlockAtPoint( - this: Editor, - point: Point, - options: { - always?: boolean - height?: number - } = {} - ): void { - const { height = 0, ...rest } = options - const { path } = point - const closestBlock = this.getClosestBlock(path) - let totalHeight: number - - if (closestBlock) { - const [, blockPath] = closestBlock - const relPath = Path.relative(path, blockPath) - totalHeight = relPath.length + height - } else { - totalHeight = path.length - } - - this.splitNodeAtPoint(point, { height: totalHeight, ...rest }) - } - - /** - * Split the inline node at a specific point, up to a certain inline height. - */ - - splitInlineAtPoint( - this: Editor, - point: Point, - options: { - always?: boolean - height?: number - } = {} - ): void { - const { height = 0, ...rest } = options - const { path } = point - const furthestInline = this.getFurthestInline(path) - let totalHeight: number - - if (furthestInline) { - const [, furthestPath] = furthestInline - const furthestRelPath = Path.relative(path, furthestPath) - // Ensure that the height isn't higher than the furthest inline, since - // this command should never split any block nodes. - const h = Math.max(furthestRelPath.length, height) - totalHeight = h - } else { - // If there are no inline ancestors, just split the text node. - totalHeight = 0 - } - - this.splitNodeAtPoint(point, { height: totalHeight, ...rest }) - } - /** * Split nodes in the document at a specific point, up to a certain height. * diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index f2cca3565a..02b3560187 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -10,69 +10,6 @@ import { } from '../..' class RangeCommands { - /** - * Delete the content in a range. - */ - - deleteAtRange( - this: Editor, - range: Range, - options: { - amount?: number - unit?: 'character' | 'word' | 'line' | 'block' - reverse?: boolean - hanging?: boolean - } = {} - ): void { - if (Range.isCollapsed(range)) { - this.deleteAtPoint(range.anchor, options) - return - } - - this.withoutNormalizing(() => { - const [start, end] = Range.points(range) - const beforeRef = this.createPointRef(start, { stick: 'backward' }) - const startRef = this.createPointRef(start) - const endRef = this.createPointRef(end, { stick: 'backward' }) - const afterRef = this.createPointRef(end) - let commonPath = Path.common(start.path, end.path) - let startHeight = start.path.length - commonPath.length - 1 - let endHeight = end.path.length - commonPath.length - 1 - - if (Path.equals(start.path, end.path)) { - commonPath = Path.parent(commonPath) - startHeight = 0 - endHeight = 0 - } - - this.splitNodeAtPoint(end, { height: Math.max(0, endHeight) }) - this.splitNodeAtPoint(start, { height: Math.max(0, startHeight) }) - - const startIndex = startRef.unref()!.path[commonPath.length] - const endIndex = endRef.unref()!.path[commonPath.length] - - for (let i = endIndex; i >= startIndex; i--) { - this.removeNodeAtPath(commonPath.concat(i)) - } - - const beforePoint = beforeRef.unref() - const afterPoint = afterRef.unref() - - if (beforePoint == null || afterPoint == null) { - return - } - - const ancestor = Node.get(this.value, commonPath) - - if ( - (Value.isValue(ancestor) || Element.isElement(ancestor)) && - this.hasBlocks(ancestor) - ) { - this.mergeBlockAtPath(afterPoint.path) - } - }) - } - /** * Insert a fragment of nodes at a range. */ @@ -91,24 +28,6 @@ class RangeCommands { }) } - /** - * Insert an inline node at a range. - */ - - insertInlineAtRange(this: Editor, range: Range, inline: Element): void { - this.withoutNormalizing(() => { - const [start] = Range.points(range) - const pointRef = this.createPointRef(start) - - if (Range.isExpanded(range)) { - this.deleteAtRange(range) - } - - this.insertInlineAtPoint(pointRef.current!, inline) - pointRef.unref() - }) - } - /** * Set new properties on all of the leaf blocks in a range. */ @@ -217,56 +136,6 @@ class RangeCommands { }) } - /** - * Split the block at a range, up to a height. - */ - - splitBlockAtRange( - this: Editor, - range: Range, - options: { - always?: boolean - height?: number - } = {} - ) { - this.withoutNormalizing(() => { - const [, end] = Range.points(range) - const pointRef = this.createPointRef(end) - - if (Range.isExpanded(range)) { - this.deleteAtRange(range) - } - - const point = pointRef.unref() - this.splitBlockAtPoint(point!, options) - }) - } - - /** - * Split the inline at a range, up to a height. - */ - - splitInlineAtRange( - this: Editor, - range: Range, - options: { - always?: boolean - height?: number - } = {} - ) { - this.withoutNormalizing(() => { - const [, end] = Range.points(range) - const pointRef = this.createPointRef(end) - - if (Range.isExpanded(range)) { - this.deleteAtRange(range) - } - - const point = pointRef.unref() - this.splitInlineAtPoint(point!, options) - }) - } - /** * Unwrap the block nodes in a range that match a set of properties. */ diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts index 0511945c66..bc8e409bd7 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/value.ts @@ -48,34 +48,36 @@ class ValueCommands { at = this.getRange(at) } - if (Range.isRange(at)) { - // Split the text nodes at the range's edges if necessary. - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) - this.splitNodeAtPoint(end, { always: false }) - this.splitNodeAtPoint(start, { always: false }) - at = rangeRef.unref()! + if (!Range.isRange(at)) { + return + } - // De-dupe the marks being added to ensure the set is unique. - const set: Mark[] = [] + // Split the text nodes at the range's edges if necessary. + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + this.splitNodeAtPoint(end, { always: false }) + this.splitNodeAtPoint(start, { always: false }) + at = rangeRef.unref()! - for (const mark of marks) { - if (!Mark.exists(mark, set)) { - set.push(mark) - } + // De-dupe the marks being added to ensure the set is unique. + const set: Mark[] = [] + + for (const mark of marks) { + if (!Mark.exists(mark, set)) { + set.push(mark) } + } - for (const [node, path] of this.texts({ at })) { - for (const mark of set) { - if (!Mark.exists(mark, node.marks)) { - this.apply({ type: 'add_mark', path, mark }) - } + for (const [node, path] of this.texts({ at })) { + for (const mark of set) { + if (!Mark.exists(mark, node.marks)) { + this.apply({ type: 'add_mark', path, mark }) } } + } - if (isSelection) { - this.select(at) - } + if (isSelection) { + this.select(at) } }) } @@ -297,13 +299,18 @@ class ValueCommands { at = point.path } - if (Path.isPath(at)) { - const [, blockPath] = this.getClosestBlock(at)! - const path = isAtEnd ? Path.next(blockPath) : blockPath - this.insertNodeAtPath(path, block) + if (!Path.isPath(at)) { + return + } - if (isSelection) { - const point = this.getStart(path)! + const [, blockPath] = this.getClosestBlock(at)! + const path = isAtEnd ? Path.next(blockPath) : blockPath + this.insertNodeAtPath(path, block) + + if (isSelection) { + const point = this.getEnd(path) + + if (point) { this.select(point) } } @@ -332,18 +339,64 @@ class ValueCommands { * Insert an inline node at the cursor. */ - insertInline(this: Editor, inline: Element) { - const { selection } = this.value + insertInline( + this: Editor, + inline: Element, + options: { + at?: Path | Point | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false + let isAtEnd = false - if (selection == null) { - return - } + if (!at && selection) { + at = selection + isSelection = true + } - const [start] = Range.points(selection) - const pointRef = this.createPointRef(start) - this.insertInlineAtRange(selection, inline) - this.select(pointRef.current!) - pointRef.unref() + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (Point.isPoint(at)) { + isAtEnd = this.isAtEnd(at, at.path) + const pointRef = this.createPointRef(at) + this.splitNodeAtPoint(at, { always: false }) + const point = pointRef.unref()! + at = point.path + } + + if (!Path.isPath(at)) { + return + } + + const [, blockPath] = this.getClosestBlock(at)! + + if (this.getFurthestVoid(blockPath)) { + return + } + + const path = isAtEnd ? Path.next(at) : at + this.insertNodeAtPath(path, inline) + + if (isSelection) { + const point = this.getEnd(path) + + if (point) { + this.select(point) + } + } + }) } /** @@ -641,21 +694,57 @@ class ValueCommands { splitBlock( this: Editor, options: { + at?: Point | Range always?: boolean height?: number } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value + const { height = 0, always = true } = options + let { at } = options + let isSelection = false + + if (!at && selection) { + at = selection + isSelection = true + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } - if (selection == null) { + if (!Point.isPoint(at)) { return } - const [, end] = Range.points(selection) - const pointRef = this.createPointRef(end) - this.splitBlockAtRange(selection, options) - this.select(pointRef.current!) + const { path } = at + const closestBlock = this.getClosestBlock(path) + let totalHeight: number + + if (closestBlock) { + const [, blockPath] = closestBlock + const relPath = Path.relative(path, blockPath) + totalHeight = relPath.length + height + } else { + totalHeight = path.length + } + + const pointRef = this.createPointRef(at) + this.splitNodeAtPoint(at, { height: totalHeight, always }) + + if (isSelection) { + const point = pointRef.current! + this.select(point) + } + pointRef.unref() }) } @@ -667,21 +756,61 @@ class ValueCommands { splitInline( this: Editor, options: { + at?: Point | Range always?: boolean height?: number } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value + const { height = 0, always = true } = options + let { at } = options + let isSelection = false - if (selection == null) { + if (!at && selection) { + at = selection + isSelection = true + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (!Point.isPoint(at)) { return } - const [, end] = Range.points(selection) - const pointRef = this.createPointRef(end) - this.splitInlineAtRange(selection, options) - this.select(pointRef.current!) + const { path } = at + const furthestInline = this.getFurthestInline(path) + let totalHeight: number + + if (furthestInline) { + const [, furthestPath] = furthestInline + const furthestRelPath = Path.relative(path, furthestPath) + // Ensure that the height isn't higher than the furthest inline, since + // this command should never split any block nodes. + const h = Math.max(furthestRelPath.length, height) + totalHeight = h + } else { + // If there are no inline ancestors, just split the text node. + totalHeight = 0 + } + + const pointRef = this.createPointRef(at) + this.splitNodeAtPoint(at, { height: totalHeight, always }) + + if (isSelection) { + const point = pointRef.current! + this.select(point) + } + pointRef.unref() }) } diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 77b03f4910..b7a05d0440 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -103,8 +103,14 @@ class PathQueries { */ getFirstText(this: Editor, path: Path): TextEntry | undefined { - const [first] = this.texts({ at: path }) - return first + const first = Node.first(this.value, path) + + if (!first) { + return + } + + const [n, p] = first + return Text.isText(n) ? [n, p] : undefined } /** @@ -148,8 +154,14 @@ class PathQueries { */ getLastText(this: Editor, path: Path): TextEntry | undefined { - const [last] = this.texts({ at: path, reverse: true }) - return last + const last = Node.last(this.value, path) + + if (!last) { + return + } + + const [n, p] = last + return Text.isText(n) ? [n, p] : undefined } /** diff --git a/packages/slate/test/commands/deselect/basic.js b/packages/slate/test/commands/deselect/basic.js index 93ac7f5654..b95028c9b2 100644 --- a/packages/slate/test/commands/deselect/basic.js +++ b/packages/slate/test/commands/deselect/basic.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const run = editor => { editor.deselect() diff --git a/packages/slate/test/commands/deselect/unfocused.js b/packages/slate/test/commands/deselect/unfocused.js index 26f357a0ee..4cd8e73c8d 100644 --- a/packages/slate/test/commands/deselect/unfocused.js +++ b/packages/slate/test/commands/deselect/unfocused.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const run = editor => { editor.deselect() diff --git a/packages/slate/test/commands/insertInline/selection/is-empty.js b/packages/slate/test/commands/insertInline/selection/block-empty.js similarity index 74% rename from packages/slate/test/commands/insertInline/selection/is-empty.js rename to packages/slate/test/commands/insertInline/selection/block-empty.js index 6557d0d59f..853c17fe5f 100644 --- a/packages/slate/test/commands/insertInline/selection/is-empty.js +++ b/packages/slate/test/commands/insertInline/selection/block-empty.js @@ -3,7 +3,11 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline('emoji') + editor.insertInline( + + + + ) } export const input = ( @@ -17,9 +21,11 @@ export const input = ( export const output = ( + + ) diff --git a/packages/slate/test/commands/insertInline/selection/block-end.js b/packages/slate/test/commands/insertInline/selection/block-end.js index df63771b9f..747dd78629 100644 --- a/packages/slate/test/commands/insertInline/selection/block-end.js +++ b/packages/slate/test/commands/insertInline/selection/block-end.js @@ -3,7 +3,11 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline('emoji') + editor.insertInline( + + + + ) } export const input = ( @@ -20,6 +24,7 @@ export const output = ( word + ) diff --git a/packages/slate/test/commands/insertInline/selection/block-middle.js b/packages/slate/test/commands/insertInline/selection/block-middle.js index 93e15b10bd..dd2df8901c 100644 --- a/packages/slate/test/commands/insertInline/selection/block-middle.js +++ b/packages/slate/test/commands/insertInline/selection/block-middle.js @@ -3,7 +3,11 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline('emoji') + editor.insertInline( + + + + ) } export const input = ( diff --git a/packages/slate/test/commands/insertInline/selection/block-start.js b/packages/slate/test/commands/insertInline/selection/block-start.js index 353ad3ed0c..ec5da366b0 100644 --- a/packages/slate/test/commands/insertInline/selection/block-start.js +++ b/packages/slate/test/commands/insertInline/selection/block-start.js @@ -3,7 +3,11 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline('emoji') + editor.insertInline( + + + + ) } export const input = ( @@ -17,9 +21,11 @@ export const input = ( export const output = ( + - word + + word ) diff --git a/packages/slate/test/commands/insertInline/selection/with-inline.js b/packages/slate/test/commands/insertInline/selection/block-void.js similarity index 53% rename from packages/slate/test/commands/insertInline/selection/with-inline.js rename to packages/slate/test/commands/insertInline/selection/block-void.js index 5323d1cf19..aa8f8adbf6 100644 --- a/packages/slate/test/commands/insertInline/selection/with-inline.js +++ b/packages/slate/test/commands/insertInline/selection/block-void.js @@ -1,26 +1,27 @@ /** @jsx h */ import { h } from '../../../helpers' -import { Inline } from 'slate' export const run = editor => { - editor.insertInline(Inline.create('emoji')) + editor.insertInline( + + + + ) } export const input = ( - - word + + ) export const output = ( - - wo - - rd + + ) diff --git a/packages/slate/test/commands/insertInline/selection/inline-middle.js b/packages/slate/test/commands/insertInline/selection/inline-middle.js index 1cc9708703..6dd2ada8dc 100644 --- a/packages/slate/test/commands/insertInline/selection/inline-middle.js +++ b/packages/slate/test/commands/insertInline/selection/inline-middle.js @@ -3,15 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline('emoji') + editor.insertInline( + + + + ) } export const input = ( + word + ) @@ -19,11 +25,15 @@ export const input = ( export const output = ( + - wo + wo + - rd + + rd + ) diff --git a/packages/slate/test/commands/insertInline/selection/is-void.js b/packages/slate/test/commands/insertInline/selection/is-void.js deleted file mode 100644 index 6ef3f1406f..0000000000 --- a/packages/slate/test/commands/insertInline/selection/is-void.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.insertInline('emoji') -} - -export const input = ( - - - - - - - -) - -export const output = ( - - - - - - - -) diff --git a/packages/slate/test/commands/move/anchor/backward.js b/packages/slate/test/commands/move/anchor/backward.js index be6fef861b..9a321dd9ab 100644 --- a/packages/slate/test/commands/move/anchor/backward.js +++ b/packages/slate/test/commands/move/anchor/backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor() + editor.move({ edge: 'anchor' }) } export const input = ( diff --git a/packages/slate/test/commands/move/anchor/basic.js b/packages/slate/test/commands/move/anchor/basic.js index ce86cad1ca..edce0a08e2 100644 --- a/packages/slate/test/commands/move/anchor/basic.js +++ b/packages/slate/test/commands/move/anchor/basic.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor() + editor.move({ edge: 'anchor' }) } export const input = ( diff --git a/packages/slate/test/commands/move/anchor/collapsed.js b/packages/slate/test/commands/move/anchor/collapsed.js index 93d28c53e8..70d10e0e20 100644 --- a/packages/slate/test/commands/move/anchor/collapsed.js +++ b/packages/slate/test/commands/move/anchor/collapsed.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor() + editor.move({ edge: 'anchor' }) } export const input = ( diff --git a/packages/slate/test/commands/move/anchor/distance.js b/packages/slate/test/commands/move/anchor/distance.js index 59f364d705..fdd1684d96 100644 --- a/packages/slate/test/commands/move/anchor/distance.js +++ b/packages/slate/test/commands/move/anchor/distance.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor({ distance: 3 }) + editor.move({ edge: 'anchor', distance: 3 }) } export const input = ( diff --git a/packages/slate/test/commands/move/anchor/reverse-backward.js b/packages/slate/test/commands/move/anchor/reverse-backward.js index 78b2f55c70..17451f6100 100644 --- a/packages/slate/test/commands/move/anchor/reverse-backward.js +++ b/packages/slate/test/commands/move/anchor/reverse-backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor({ reverse: true }) + editor.move({ edge: 'anchor', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/anchor/reverse-basic.js b/packages/slate/test/commands/move/anchor/reverse-basic.js index ab1c5e9af9..2bfe61f963 100644 --- a/packages/slate/test/commands/move/anchor/reverse-basic.js +++ b/packages/slate/test/commands/move/anchor/reverse-basic.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor({ reverse: true }) + editor.move({ edge: 'anchor', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/anchor/reverse-collapsed.js b/packages/slate/test/commands/move/anchor/reverse-collapsed.js index f3700afb10..7ed4bf1e12 100644 --- a/packages/slate/test/commands/move/anchor/reverse-collapsed.js +++ b/packages/slate/test/commands/move/anchor/reverse-collapsed.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor({ reverse: true }) + editor.move({ edge: 'anchor', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/anchor/reverse-distance.js b/packages/slate/test/commands/move/anchor/reverse-distance.js index 616fe2b42d..24be3d6497 100644 --- a/packages/slate/test/commands/move/anchor/reverse-distance.js +++ b/packages/slate/test/commands/move/anchor/reverse-distance.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveAnchor({ reverse: true, distance: 3 }) + editor.move({ edge: 'anchor', reverse: true, distance: 3 }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/backward-reverse.js b/packages/slate/test/commands/move/end/backward-reverse.js index 591eae22d4..77c8d8fe50 100644 --- a/packages/slate/test/commands/move/end/backward-reverse.js +++ b/packages/slate/test/commands/move/end/backward-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd({ reverse: true }) + editor.move({ edge: 'end', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/backward.js b/packages/slate/test/commands/move/end/backward.js index 320756252b..20b34df4a5 100644 --- a/packages/slate/test/commands/move/end/backward.js +++ b/packages/slate/test/commands/move/end/backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd() + editor.move({ edge: 'end' }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/collapsed-reverse.js b/packages/slate/test/commands/move/end/collapsed-reverse.js index c25027dc1e..3c9d21dec7 100644 --- a/packages/slate/test/commands/move/end/collapsed-reverse.js +++ b/packages/slate/test/commands/move/end/collapsed-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd({ reverse: true }) + editor.move({ edge: 'end', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/collapsed.js b/packages/slate/test/commands/move/end/collapsed.js index 48b2edc7a0..feb5287e4c 100644 --- a/packages/slate/test/commands/move/end/collapsed.js +++ b/packages/slate/test/commands/move/end/collapsed.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd() + editor.move({ edge: 'end' }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/distance-reverse.js b/packages/slate/test/commands/move/end/distance-reverse.js index 9b7740df8f..f8a56c1fd5 100644 --- a/packages/slate/test/commands/move/end/distance-reverse.js +++ b/packages/slate/test/commands/move/end/distance-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd({ reverse: true, distance: 3 }) + editor.move({ edge: 'end', reverse: true, distance: 3 }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/distance.js b/packages/slate/test/commands/move/end/distance.js index ed5c163ef9..d984daa026 100644 --- a/packages/slate/test/commands/move/end/distance.js +++ b/packages/slate/test/commands/move/end/distance.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd({ distance: 3 }) + editor.move({ edge: 'end', distance: 3 }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/expanded-reverse.js b/packages/slate/test/commands/move/end/expanded-reverse.js index 38e51b8841..38cd1f005c 100644 --- a/packages/slate/test/commands/move/end/expanded-reverse.js +++ b/packages/slate/test/commands/move/end/expanded-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd({ reverse: true }) + editor.move({ edge: 'end', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/expanded.js b/packages/slate/test/commands/move/end/expanded.js index b4f3ebec58..3af95482e0 100644 --- a/packages/slate/test/commands/move/end/expanded.js +++ b/packages/slate/test/commands/move/end/expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd() + editor.move({ edge: 'end' }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/from-backward-reverse.js b/packages/slate/test/commands/move/end/from-backward-reverse.js index 98f35e5076..40075700a6 100644 --- a/packages/slate/test/commands/move/end/from-backward-reverse.js +++ b/packages/slate/test/commands/move/end/from-backward-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd({ reverse: true, distance: 7 }) + editor.move({ edge: 'end', reverse: true, distance: 7 }) } export const input = ( diff --git a/packages/slate/test/commands/move/end/to-backward-reverse.js b/packages/slate/test/commands/move/end/to-backward-reverse.js index 467f85106d..286de67fe3 100644 --- a/packages/slate/test/commands/move/end/to-backward-reverse.js +++ b/packages/slate/test/commands/move/end/to-backward-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveEnd({ reverse: true, distance: 6 }) + editor.move({ edge: 'end', reverse: true, distance: 6 }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/backward.js b/packages/slate/test/commands/move/focus/backward.js index ab6ce6dccc..49d696a9fe 100644 --- a/packages/slate/test/commands/move/focus/backward.js +++ b/packages/slate/test/commands/move/focus/backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus({ distance: 7 }) + editor.move({ edge: 'focus', distance: 7 }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/collapsed-reverse.js b/packages/slate/test/commands/move/focus/collapsed-reverse.js index a36cd87d36..b25af66619 100644 --- a/packages/slate/test/commands/move/focus/collapsed-reverse.js +++ b/packages/slate/test/commands/move/focus/collapsed-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus({ reverse: true }) + editor.move({ edge: 'focus', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/collapsed.js b/packages/slate/test/commands/move/focus/collapsed.js index b7a3279248..b8c8715fd3 100644 --- a/packages/slate/test/commands/move/focus/collapsed.js +++ b/packages/slate/test/commands/move/focus/collapsed.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus() + editor.move({ edge: 'focus' }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/distance-reverse.js b/packages/slate/test/commands/move/focus/distance-reverse.js index 418889933b..3c63c30641 100644 --- a/packages/slate/test/commands/move/focus/distance-reverse.js +++ b/packages/slate/test/commands/move/focus/distance-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus({ reverse: true, distance: 6 }) + editor.move({ edge: 'focus', reverse: true, distance: 6 }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/distance.js b/packages/slate/test/commands/move/focus/distance.js index 72d38c3ec4..b753b49eba 100644 --- a/packages/slate/test/commands/move/focus/distance.js +++ b/packages/slate/test/commands/move/focus/distance.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus({ distance: 4 }) + editor.move({ edge: 'focus', distance: 4 }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/expanded-reverse.js b/packages/slate/test/commands/move/focus/expanded-reverse.js index dcf63da818..ef22836369 100644 --- a/packages/slate/test/commands/move/focus/expanded-reverse.js +++ b/packages/slate/test/commands/move/focus/expanded-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus({ reverse: true }) + editor.move({ edge: 'focus', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/expanded.js b/packages/slate/test/commands/move/focus/expanded.js index 8ec46256d6..ba35f3a583 100644 --- a/packages/slate/test/commands/move/focus/expanded.js +++ b/packages/slate/test/commands/move/focus/expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus() + editor.move({ edge: 'focus' }) } export const input = ( diff --git a/packages/slate/test/commands/move/focus/to-backward-reverse.js b/packages/slate/test/commands/move/focus/to-backward-reverse.js index 5e043cf8d4..befd435af9 100644 --- a/packages/slate/test/commands/move/focus/to-backward-reverse.js +++ b/packages/slate/test/commands/move/focus/to-backward-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveFocus({ reverse: true, distance: 10 }) + editor.move({ edge: 'focus', reverse: true, distance: 10 }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/backward-reverse.js b/packages/slate/test/commands/move/start/backward-reverse.js index 3b26dec3b4..f1b7e6c3c2 100644 --- a/packages/slate/test/commands/move/start/backward-reverse.js +++ b/packages/slate/test/commands/move/start/backward-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart({ reverse: true }) + editor.move({ edge: 'start', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/backward.js b/packages/slate/test/commands/move/start/backward.js index f499c23335..9122722ca1 100644 --- a/packages/slate/test/commands/move/start/backward.js +++ b/packages/slate/test/commands/move/start/backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart() + editor.move({ edge: 'start' }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/collapsed-reverse.js b/packages/slate/test/commands/move/start/collapsed-reverse.js index a89b62e067..3bf2981ed9 100644 --- a/packages/slate/test/commands/move/start/collapsed-reverse.js +++ b/packages/slate/test/commands/move/start/collapsed-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart({ reverse: true }) + editor.move({ edge: 'start', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/collapsed.js b/packages/slate/test/commands/move/start/collapsed.js index 503f5f4096..a4e4f6bd88 100644 --- a/packages/slate/test/commands/move/start/collapsed.js +++ b/packages/slate/test/commands/move/start/collapsed.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart() + editor.move({ edge: 'start' }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/distance-reverse.js b/packages/slate/test/commands/move/start/distance-reverse.js index 0750e36676..59abffd7b0 100644 --- a/packages/slate/test/commands/move/start/distance-reverse.js +++ b/packages/slate/test/commands/move/start/distance-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart({ reverse: true, distance: 3 }) + editor.move({ edge: 'start', reverse: true, distance: 3 }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/distance.js b/packages/slate/test/commands/move/start/distance.js index bc1c3808b2..c9fea21219 100644 --- a/packages/slate/test/commands/move/start/distance.js +++ b/packages/slate/test/commands/move/start/distance.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart({ distance: 3 }) + editor.move({ edge: 'start', distance: 3 }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/expanded-reverse.js b/packages/slate/test/commands/move/start/expanded-reverse.js index 5acbf1b2a2..4f55bdcbf2 100644 --- a/packages/slate/test/commands/move/start/expanded-reverse.js +++ b/packages/slate/test/commands/move/start/expanded-reverse.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart({ reverse: true }) + editor.move({ edge: 'start', reverse: true }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/expanded.js b/packages/slate/test/commands/move/start/expanded.js index d7d074c3aa..6071937169 100644 --- a/packages/slate/test/commands/move/start/expanded.js +++ b/packages/slate/test/commands/move/start/expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart() + editor.move({ edge: 'start' }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/from-backward.js b/packages/slate/test/commands/move/start/from-backward.js index d1f7de4c4f..d62a061890 100644 --- a/packages/slate/test/commands/move/start/from-backward.js +++ b/packages/slate/test/commands/move/start/from-backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart({ distance: 7 }) + editor.move({ edge: 'start', distance: 7 }) } export const input = ( diff --git a/packages/slate/test/commands/move/start/to-backward.js b/packages/slate/test/commands/move/start/to-backward.js index ddc0f0d4fe..0da754a455 100644 --- a/packages/slate/test/commands/move/start/to-backward.js +++ b/packages/slate/test/commands/move/start/to-backward.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveStart({ distance: 8 }) + editor.move({ edge: 'start', distance: 8 }) } export const input = ( diff --git a/packages/slate/test/commands/select/basic.js b/packages/slate/test/commands/select/basic.js index 1a39b532f3..8e7d0f0d97 100644 --- a/packages/slate/test/commands/select/basic.js +++ b/packages/slate/test/commands/select/basic.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const run = editor => { editor.select({ diff --git a/packages/slate/test/commands/splitBlock/point/block.js b/packages/slate/test/commands/splitBlock/point/block.js index 8c4718cc1e..3596cc03d9 100644 --- a/packages/slate/test/commands/splitBlock/point/block.js +++ b/packages/slate/test/commands/splitBlock/point/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlockAtPoint({ path: [0, 0], offset: 2 }) + editor.splitBlock({ at: { path: [0, 0], offset: 2 } }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/point/selection.js b/packages/slate/test/commands/splitBlock/point/selection.js index 02430ebc96..c407ffa85d 100644 --- a/packages/slate/test/commands/splitBlock/point/selection.js +++ b/packages/slate/test/commands/splitBlock/point/selection.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlockAtPoint({ path: [0, 0], offset: 2 }) + editor.splitBlock({ at: { path: [0, 0], offset: 2 } }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/selection/after-inline-void.js b/packages/slate/test/commands/splitBlock/selection/after-inline-void.js index 339d1bbe3a..fbb471a4a3 100644 --- a/packages/slate/test/commands/splitBlock/selection/after-inline-void.js +++ b/packages/slate/test/commands/splitBlock/selection/after-inline-void.js @@ -9,7 +9,8 @@ export const run = editor => { export const input = ( - one + one + two @@ -20,9 +21,11 @@ export const input = ( export const output = ( - one + one + + two diff --git a/packages/slate/test/commands/splitBlock/selection/after-inline.js b/packages/slate/test/commands/splitBlock/selection/after-inline.js index 8b1b7b160a..c882df2cdd 100644 --- a/packages/slate/test/commands/splitBlock/selection/after-inline.js +++ b/packages/slate/test/commands/splitBlock/selection/after-inline.js @@ -8,24 +8,23 @@ export const run = editor => { export const input = ( - - - wordhyperlink - word - - + + word + hyperlink + word + ) export const output = ( - - - wordhyperlink - - - word - - + + word + hyperlink + + + + word + ) diff --git a/packages/slate/test/commands/splitBlock/selection/before-inline.js b/packages/slate/test/commands/splitBlock/selection/before-inline.js index 83791880b9..e324c26ff0 100644 --- a/packages/slate/test/commands/splitBlock/selection/before-inline.js +++ b/packages/slate/test/commands/splitBlock/selection/before-inline.js @@ -8,27 +8,29 @@ export const run = editor => { export const input = ( - - - word - hyperlink - word - - + + word + hyperlink + word + ) export const output = ( - - - word - - - - hyperlink - word - - + + word + + + + + + + + + hyperlink + + word + ) diff --git a/packages/slate/test/commands/splitBlock/selection/depth.js b/packages/slate/test/commands/splitBlock/selection/block-depth.js similarity index 58% rename from packages/slate/test/commands/splitBlock/selection/depth.js rename to packages/slate/test/commands/splitBlock/selection/block-depth.js index 4fbfc73425..56d12603e1 100644 --- a/packages/slate/test/commands/splitBlock/selection/depth.js +++ b/packages/slate/test/commands/splitBlock/selection/block-depth.js @@ -3,38 +3,34 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock(Infinity) + editor.splitBlock({ height: Infinity }) } export const input = ( - + - - word - + word - + ) export const output = ( - + - - wo - + wo + + - - rd - + rd - + ) diff --git a/packages/slate/test/commands/splitBlock/selection/with-inline.js b/packages/slate/test/commands/splitBlock/selection/with-inline.js index d97661dcbc..cb3016dd04 100644 --- a/packages/slate/test/commands/splitBlock/selection/with-inline.js +++ b/packages/slate/test/commands/splitBlock/selection/with-inline.js @@ -8,27 +8,29 @@ export const run = editor => { export const input = ( - - - - word - - - + + + + word + + + ) export const output = ( - - - wo - - - - rd - - - + + + wo + + + + + + rd + + + ) diff --git a/packages/slate/test/commands/splitBlock/selection/with-marks.js b/packages/slate/test/commands/splitBlock/selection/with-marks.js deleted file mode 100644 index 873ebdf1dc..0000000000 --- a/packages/slate/test/commands/splitBlock/selection/with-marks.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.addMarks([{ key: 'b' }]) - editor.splitBlock() - editor.insertText('cat is cute') -} - -export const input = ( - - - word - - - -) - -export const output = ( - - - word - - - - - cat is cute - - - - -) diff --git a/packages/slate/test/commands/splitInline/selection/block-end.js b/packages/slate/test/commands/splitInline/selection/block-end.js index f21148c0ab..32c1b67e24 100644 --- a/packages/slate/test/commands/splitInline/selection/block-end.js +++ b/packages/slate/test/commands/splitInline/selection/block-end.js @@ -9,9 +9,11 @@ export const run = editor => { export const input = ( + word + ) @@ -19,10 +21,13 @@ export const input = ( export const output = ( + word + + ) diff --git a/packages/slate/test/commands/splitInline/selection/block-middle.js b/packages/slate/test/commands/splitInline/selection/block-middle.js index de98c88ecd..586af6f5a8 100644 --- a/packages/slate/test/commands/splitInline/selection/block-middle.js +++ b/packages/slate/test/commands/splitInline/selection/block-middle.js @@ -9,9 +9,11 @@ export const run = editor => { export const input = ( + word + ) @@ -19,10 +21,13 @@ export const input = ( export const output = ( + wo + rd + ) diff --git a/packages/slate/test/commands/splitInline/selection/block-start.js b/packages/slate/test/commands/splitInline/selection/block-start.js index 0f486a29e8..110e9f7ab6 100644 --- a/packages/slate/test/commands/splitInline/selection/block-start.js +++ b/packages/slate/test/commands/splitInline/selection/block-start.js @@ -9,9 +9,11 @@ export const run = editor => { export const input = ( + word + ) @@ -19,12 +21,15 @@ export const input = ( export const output = ( + + word + ) diff --git a/packages/slate/test/commands/splitInline/selection/with-delete.js b/packages/slate/test/commands/splitInline/selection/expanded.js similarity index 83% rename from packages/slate/test/commands/splitInline/selection/with-delete.js rename to packages/slate/test/commands/splitInline/selection/expanded.js index 31af7485a5..3cef877e48 100644 --- a/packages/slate/test/commands/splitInline/selection/with-delete.js +++ b/packages/slate/test/commands/splitInline/selection/expanded.js @@ -9,9 +9,11 @@ export const run = editor => { export const input = ( + word + ) @@ -19,10 +21,13 @@ export const input = ( export const output = ( + w + d + ) diff --git a/packages/slate/test/commands/splitInline/selection/height.js b/packages/slate/test/commands/splitInline/selection/height.js index a83687633a..2de3042a51 100644 --- a/packages/slate/test/commands/splitInline/selection/height.js +++ b/packages/slate/test/commands/splitInline/selection/height.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInline(1) + editor.splitInline({ height: 1 }) } export const input = ( @@ -30,6 +30,10 @@ export const output = ( wo + + + + rd diff --git a/packages/slate/test/commands/splitInline/selection/with-marks.js b/packages/slate/test/commands/splitInline/selection/mark.js similarity index 87% rename from packages/slate/test/commands/splitInline/selection/with-marks.js rename to packages/slate/test/commands/splitInline/selection/mark.js index 4032e24ea5..466dcdb215 100644 --- a/packages/slate/test/commands/splitInline/selection/with-marks.js +++ b/packages/slate/test/commands/splitInline/selection/mark.js @@ -9,11 +9,13 @@ export const run = editor => { export const input = ( + word + ) @@ -21,14 +23,17 @@ export const input = ( export const output = ( + wo + rd + ) From 2c1492421391844f751f590c773f173a9348e1f3 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 24 Oct 2019 16:50:36 -0400 Subject: [PATCH 056/165] lots of progress on converting to at-based commands --- packages/slate/src/classes/commands/mark.ts | 188 +++++ packages/slate/src/classes/commands/node.ts | 687 ++++++++++++++++ packages/slate/src/classes/commands/path.ts | 362 +-------- packages/slate/src/classes/commands/point.ts | 154 ---- packages/slate/src/classes/commands/range.ts | 126 --- packages/slate/src/classes/commands/text.ts | 226 ++++++ packages/slate/src/classes/commands/value.ts | 761 +----------------- packages/slate/src/classes/editor.ts | 12 +- packages/slate/src/classes/queries/path.ts | 40 + packages/slate/src/classes/queries/value.ts | 20 + packages/slate/src/interfaces/range.ts | 16 + packages/slate/src/plugins/schema/plugin.ts | 14 +- .../insertFragment/path/end-of-target.js | 27 - .../insertFragment/path/middle-of-target.js | 29 - .../block}/block-empty.js | 16 +- .../block}/block-end.js | 2 +- .../block}/block-middle.js | 2 +- .../block}/block-start.js | 2 +- .../block}/block-void.js | 2 +- .../block}/inline-void.js | 2 +- .../inline}/block-empty.js | 16 +- .../inline}/block-end.js | 2 +- .../inline}/block-middle.js | 2 +- .../inline}/block-start.js | 2 +- .../inline}/block-void.js | 2 +- .../inline}/inline-middle.js | 14 +- .../{insertNode => insertNodes}/path/block.js | 6 +- .../path/inline.js | 6 +- .../commands/insertNodes/path/multiple.js | 25 + .../{insertNode => insertNodes}/path/text.js | 2 +- .../insertText/range/expanded-with-mark.js | 3 - .../{pluckNode => liftNodes}/path/block.js | 2 +- .../path/first-block.js | 2 +- .../path/last-block.js | 2 +- .../path/middle-block.js | 2 +- .../{mergeNode => mergeNodes}/path/block.js | 0 .../{moveNode => moveNodes}/path/block.js | 2 +- .../{moveNode => moveNodes}/path/inline.js | 2 +- .../path/inside-next.js | 2 +- .../{moveNode => moveNodes}/path/nested.js | 2 +- .../path/noop-equal.js | 2 +- .../path/sibling-swap.js | 2 +- .../path/text-nodes.js | 2 +- .../{moveNode => moveNodes}/path/text.js | 2 +- .../path/to-sibling.js | 2 +- .../commands/moveNodes/selection/block.js | 25 + .../match-block/block-across.js} | 18 +- .../pluckNodes/match-block/block-end.js | 39 + .../match-block/block-inline.js} | 32 +- .../pluckNodes/match-block/block-middle.js | 39 + .../match-block/block-nested.js} | 10 +- .../pluckNodes/match-block/block-start.js | 39 + .../match-block/block.js} | 14 +- .../match-inline/block-nested.js} | 15 +- .../pluckNodes/match-inline/inline-across.js | 31 + .../match-inline/inline-over.js} | 10 +- .../match-inline/inline.js} | 10 +- .../path/block-multiple.js | 2 +- .../{liftNode => pluckNodes}/path/block.js | 2 +- .../commands/setBlocks/selection/data-only.js | 29 - .../setInlines/selection/across-inlines.js | 41 - .../setInlines/selection/data-only.js | 32 - .../single-inline-string-shorthand.js | 31 - .../setInlines/selection/single-inline.js | 31 - .../setInlines/selection/with-data-object.js | 34 - .../setInlines/selection/with-data.js | 31 - .../block/block-across.js} | 18 +- .../block/block-hanging.js} | 16 +- .../block/block-nested.js} | 14 +- .../block/block-void.js} | 14 +- .../block/block.js} | 12 +- .../inline/inline-across.js} | 14 +- .../inline/inline-hanging.js} | 12 +- .../inline/inline-nested.js} | 22 +- .../commands/setNodes/inline/inline-void.js | 31 + .../inline/inline.js} | 8 +- .../{setNode => setNodes}/path/block.js | 8 +- .../{setNode => setNodes}/path/inline.js | 2 +- .../{setNode => setNodes}/path/text.js | 2 +- .../splitBlock/selection/block-end.js | 30 - .../splitBlock/selection/block-middle.js | 28 - .../with-delete-across-blocks-and-inlines.js | 51 -- .../splitBlock/selection/with-delete.js | 28 - .../commands/splitNode/point/selection.js | 28 - .../height-block}/after-inline-void.js | 2 +- .../height-block}/after-inline.js | 2 +- .../height-block}/before-inline.js | 2 +- .../splitNodes/height-block/block-end.js | 26 + .../splitNodes/height-block/block-middle.js | 24 + .../height-block}/block-start.js | 2 +- .../height-block/point.js} | 2 +- .../with-delete-across-blocks-and-inlines.js | 47 ++ .../height-block/with-delete-across-blocks.js | 27 + .../with-delete-hanging-selection.js | 2 +- .../splitNodes/height-block/with-delete.js | 24 + .../height-block}/with-inline.js | 2 +- .../height-inline}/block-end.js | 2 +- .../splitNodes/height-inline/block-middle.js | 33 + .../height-inline}/block-start.js | 2 +- .../height-inline}/expanded.js | 2 +- .../height-inline}/mark.js | 2 +- .../height-inline/point.js} | 2 +- .../height/infinity.js} | 2 +- .../height/one.js} | 2 +- .../path/block-inline.js} | 2 +- .../path/block-nested.js} | 26 +- .../path/selection.js | 2 +- .../{splitBlock => splitNodes}/point/block.js | 2 +- .../point/inline.js | 2 +- .../point/selection.js | 2 +- .../unwrapBlock/selection/across-blocks.js | 35 - .../unwrapBlock/selection/across-inlines.js | 43 - .../selection/ending-child-blocks.js | 45 -- ...le-child-blocks-with-backward-selection.js | 47 -- .../selection/middle-child-blocks.js | 47 -- .../unwrapBlock/selection/nested-block.js | 33 - .../selection/starting-child-blocks.js | 45 -- .../unwrapBlock/selection/with-object.js | 28 - .../selection/across-inlines-and-text.js | 31 - .../unwrapInline/selection/across-inlines.js | 41 - .../unwrapInline/selection/nested-block.js | 34 - .../unwrapInline/selection/with-object.js | 36 - .../unwrapNodes/match-block/block-partial.js | 41 + .../selection/nested-block-with-object.js | 36 - .../wrapBlock/selection/nested-block.js | 16 +- .../wrapBlock/selection/with-object.js | 32 - .../{wrapNode => wrapNodes}/path/block.js | 0 .../{wrapNode => wrapNodes}/path/text.js | 0 128 files changed, 1906 insertions(+), 2576 deletions(-) create mode 100644 packages/slate/src/classes/commands/mark.ts create mode 100644 packages/slate/src/classes/commands/node.ts delete mode 100755 packages/slate/src/classes/commands/point.ts create mode 100644 packages/slate/src/classes/commands/text.ts delete mode 100644 packages/slate/test/commands/insertFragment/path/end-of-target.js delete mode 100644 packages/slate/test/commands/insertFragment/path/middle-of-target.js rename packages/slate/test/commands/{insertBlock/selection => insertNodes/block}/block-empty.js (94%) rename packages/slate/test/commands/{insertBlock/selection => insertNodes/block}/block-end.js (93%) rename packages/slate/test/commands/{insertBlock/selection => insertNodes/block}/block-middle.js (94%) rename packages/slate/test/commands/{insertBlock/selection => insertNodes/block}/block-start.js (93%) rename packages/slate/test/commands/{insertBlock/selection => insertNodes/block}/block-void.js (95%) rename packages/slate/test/commands/{insertBlock/selection => insertNodes/block}/inline-void.js (96%) rename packages/slate/test/commands/{insertInline/selection => insertNodes/inline}/block-empty.js (94%) rename packages/slate/test/commands/{insertInline/selection => insertNodes/inline}/block-end.js (94%) rename packages/slate/test/commands/{insertInline/selection => insertNodes/inline}/block-middle.js (94%) rename packages/slate/test/commands/{insertInline/selection => insertNodes/inline}/block-start.js (94%) rename packages/slate/test/commands/{insertInline/selection => insertNodes/inline}/block-void.js (93%) rename packages/slate/test/commands/{insertInline/selection => insertNodes/inline}/inline-middle.js (74%) rename packages/slate/test/commands/{insertNode => insertNodes}/path/block.js (86%) rename packages/slate/test/commands/{insertNode => insertNodes}/path/inline.js (86%) create mode 100644 packages/slate/test/commands/insertNodes/path/multiple.js rename packages/slate/test/commands/{insertNode => insertNodes}/path/text.js (82%) rename packages/slate/test/commands/{pluckNode => liftNodes}/path/block.js (87%) rename packages/slate/test/commands/{liftNode => liftNodes}/path/first-block.js (90%) rename packages/slate/test/commands/{liftNode => liftNodes}/path/last-block.js (90%) rename packages/slate/test/commands/{liftNode => liftNodes}/path/middle-block.js (92%) rename packages/slate/test/commands/{mergeNode => mergeNodes}/path/block.js (100%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/block.js (88%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/inline.js (91%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/inside-next.js (89%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/nested.js (89%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/noop-equal.js (86%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/sibling-swap.js (88%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/text-nodes.js (87%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/text.js (86%) rename packages/slate/test/commands/{moveNode => moveNodes}/path/to-sibling.js (89%) create mode 100644 packages/slate/test/commands/moveNodes/selection/block.js rename packages/slate/test/commands/{splitBlock/selection/with-delete-across-blocks.js => pluckNodes/match-block/block-across.js} (62%) create mode 100644 packages/slate/test/commands/pluckNodes/match-block/block-end.js rename packages/slate/test/commands/{splitInline/selection/height.js => pluckNodes/match-block/block-inline.js} (67%) create mode 100644 packages/slate/test/commands/pluckNodes/match-block/block-middle.js rename packages/slate/test/commands/{unwrapBlock/selection/single-block.js => pluckNodes/match-block/block-nested.js} (75%) create mode 100644 packages/slate/test/commands/pluckNodes/match-block/block-start.js rename packages/slate/test/commands/{setBlocks/selection/with-is-void.js => pluckNodes/match-block/block.js} (65%) rename packages/slate/test/commands/{unwrapInline/selection/single-block.js => pluckNodes/match-inline/block-nested.js} (67%) create mode 100644 packages/slate/test/commands/pluckNodes/match-inline/inline-across.js rename packages/slate/test/commands/{unwrapInline/selection/across-blocks.js => pluckNodes/match-inline/inline-over.js} (63%) rename packages/slate/test/commands/{unwrapInline/selection/only-one.js => pluckNodes/match-inline/inline.js} (62%) rename packages/slate/test/commands/{pluckNode => pluckNodes}/path/block-multiple.js (90%) rename packages/slate/test/commands/{liftNode => pluckNodes}/path/block.js (88%) delete mode 100644 packages/slate/test/commands/setBlocks/selection/data-only.js delete mode 100644 packages/slate/test/commands/setInlines/selection/across-inlines.js delete mode 100644 packages/slate/test/commands/setInlines/selection/data-only.js delete mode 100644 packages/slate/test/commands/setInlines/selection/single-inline-string-shorthand.js delete mode 100644 packages/slate/test/commands/setInlines/selection/single-inline.js delete mode 100644 packages/slate/test/commands/setInlines/selection/with-data-object.js delete mode 100644 packages/slate/test/commands/setInlines/selection/with-data.js rename packages/slate/test/commands/{setBlocks/selection/across-blocks.js => setNodes/block/block-across.js} (67%) rename packages/slate/test/commands/{setBlocks/selection/hanging-selection.js => setNodes/block/block-hanging.js} (70%) rename packages/slate/test/commands/{setBlocks/selection/nested-block.js => setNodes/block/block-nested.js} (69%) rename packages/slate/test/commands/{setBlocks/selection/single-block-string-shorthand.js => setNodes/block/block-void.js} (64%) rename packages/slate/test/commands/{setBlocks/selection/single-block.js => setNodes/block/block.js} (70%) rename packages/slate/test/commands/{setBlocks/selection/across-inlines.js => setNodes/inline/inline-across.js} (68%) rename packages/slate/test/commands/{setBlocks/selection/hanging-selection-across-inlines.js => setNodes/inline/inline-hanging.js} (71%) rename packages/slate/test/commands/{setInlines/selection/nested-inline.js => setNodes/inline/inline-nested.js} (56%) create mode 100644 packages/slate/test/commands/setNodes/inline/inline-void.js rename packages/slate/test/commands/{setInlines/selection/with-is-void.js => setNodes/inline/inline.js} (70%) rename packages/slate/test/commands/{setNode => setNodes}/path/block.js (84%) rename packages/slate/test/commands/{setNode => setNodes}/path/inline.js (88%) rename packages/slate/test/commands/{setNode => setNodes}/path/text.js (84%) delete mode 100644 packages/slate/test/commands/splitBlock/selection/block-end.js delete mode 100644 packages/slate/test/commands/splitBlock/selection/block-middle.js delete mode 100644 packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks-and-inlines.js delete mode 100644 packages/slate/test/commands/splitBlock/selection/with-delete.js delete mode 100644 packages/slate/test/commands/splitNode/point/selection.js rename packages/slate/test/commands/{splitBlock/selection => splitNodes/height-block}/after-inline-void.js (91%) rename packages/slate/test/commands/{splitBlock/selection => splitNodes/height-block}/after-inline.js (90%) rename packages/slate/test/commands/{splitBlock/selection => splitNodes/height-block}/before-inline.js (92%) create mode 100644 packages/slate/test/commands/splitNodes/height-block/block-end.js create mode 100644 packages/slate/test/commands/splitNodes/height-block/block-middle.js rename packages/slate/test/commands/{splitBlock/selection => splitNodes/height-block}/block-start.js (89%) rename packages/slate/test/commands/{splitNode/point/block.js => splitNodes/height-block/point.js} (78%) create mode 100644 packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks-and-inlines.js create mode 100644 packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks.js rename packages/slate/test/commands/{splitBlock/selection => splitNodes/height-block}/with-delete-hanging-selection.js (91%) create mode 100644 packages/slate/test/commands/splitNodes/height-block/with-delete.js rename packages/slate/test/commands/{splitBlock/selection => splitNodes/height-block}/with-inline.js (92%) rename packages/slate/test/commands/{splitInline/selection => splitNodes/height-inline}/block-end.js (91%) create mode 100644 packages/slate/test/commands/splitNodes/height-inline/block-middle.js rename packages/slate/test/commands/{splitInline/selection => splitNodes/height-inline}/block-start.js (91%) rename packages/slate/test/commands/{splitInline/selection => splitNodes/height-inline}/expanded.js (91%) rename packages/slate/test/commands/{splitInline/selection => splitNodes/height-inline}/mark.js (92%) rename packages/slate/test/commands/{splitNode/point/inline.js => splitNodes/height-inline/point.js} (85%) rename packages/slate/test/commands/{splitBlock/selection/block-depth.js => splitNodes/height/infinity.js} (92%) rename packages/slate/test/commands/{splitInline/selection/block-middle.js => splitNodes/height/one.js} (92%) rename packages/slate/test/commands/{splitNode/path/block.js => splitNodes/path/block-inline.js} (92%) rename packages/slate/test/commands/{insertFragment/path/start-of-target.js => splitNodes/path/block-nested.js} (63%) rename packages/slate/test/commands/{splitNode => splitNodes}/path/selection.js (94%) rename packages/slate/test/commands/{splitBlock => splitNodes}/point/block.js (80%) rename packages/slate/test/commands/{splitInline => splitNodes}/point/inline.js (86%) rename packages/slate/test/commands/{splitBlock => splitNodes}/point/selection.js (83%) delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/across-blocks.js delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/across-inlines.js delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/ending-child-blocks.js delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks-with-backward-selection.js delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks.js delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/nested-block.js delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/starting-child-blocks.js delete mode 100644 packages/slate/test/commands/unwrapBlock/selection/with-object.js delete mode 100644 packages/slate/test/commands/unwrapInline/selection/across-inlines-and-text.js delete mode 100644 packages/slate/test/commands/unwrapInline/selection/across-inlines.js delete mode 100644 packages/slate/test/commands/unwrapInline/selection/nested-block.js delete mode 100644 packages/slate/test/commands/unwrapInline/selection/with-object.js create mode 100644 packages/slate/test/commands/unwrapNodes/match-block/block-partial.js delete mode 100644 packages/slate/test/commands/wrapBlock/selection/nested-block-with-object.js delete mode 100644 packages/slate/test/commands/wrapBlock/selection/with-object.js rename packages/slate/test/commands/{wrapNode => wrapNodes}/path/block.js (100%) rename packages/slate/test/commands/{wrapNode => wrapNodes}/path/text.js (100%) diff --git a/packages/slate/src/classes/commands/mark.ts b/packages/slate/src/classes/commands/mark.ts new file mode 100644 index 0000000000..b08893c3ea --- /dev/null +++ b/packages/slate/src/classes/commands/mark.ts @@ -0,0 +1,188 @@ +import { Editor, Mark, Path, Range } from '../..' + +class MarkingCommands { + addMarks( + this: Editor, + marks: Mark[], + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false + + if (!at && selection) { + at = selection + isSelection = true + } + + if (Path.isPath(at)) { + at = this.getRange(at) + } + + if (!Range.isRange(at)) { + return + } + + // Split the text nodes at the range's edges if necessary. + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + this.splitNodes({ at: end, always: false }) + this.splitNodes({ at: start, always: false }) + at = rangeRef.unref()! + + // De-dupe the marks being added to ensure the set is unique. + const set: Mark[] = [] + + for (const mark of marks) { + if (!Mark.exists(mark, set)) { + set.push(mark) + } + } + + for (const [node, path] of this.texts({ at })) { + for (const mark of set) { + if (!Mark.exists(mark, node.marks)) { + this.apply({ type: 'add_mark', path, mark }) + } + } + } + + if (isSelection) { + this.select(at) + } + }) + } + + removeMarks( + this: Editor, + marks: Mark[], + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false + + if (!at && selection) { + at = selection + isSelection = true + } + + if (Path.isPath(at)) { + at = this.getRange(at) + } + + if (Range.isRange(at)) { + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + this.splitNodes({ at: end, always: false }) + this.splitNodes({ at: start, always: false }) + at = rangeRef.unref()! + + for (const [mark, i, node, path] of this.marks({ at })) { + if (Mark.exists(mark, marks)) { + this.apply({ type: 'remove_mark', path, mark }) + } + } + + if (isSelection) { + this.select(at) + } + } + }) + } + + setMarks( + this: Editor, + marks: Mark[], + props: Partial, + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false + + if (!at && selection) { + at = selection + isSelection = true + } + + // PERF: Do this before the path coercion logic since we're guaranteed not + // to need to split in that case. + if (Range.isRange(at)) { + // Split the text nodes at the range's edges if necessary. + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + this.splitNodes({ at: end, always: false }) + this.splitNodes({ at: start, always: false }) + at = rangeRef.unref()! + } + + if (Path.isPath(at)) { + at = this.getRange(at) + } + + if (Range.isRange(at)) { + for (const [mark, i, node, path] of this.marks({ at })) { + if (!Mark.exists(mark, marks)) { + continue + } + + const newProps = {} + + for (const k in props) { + if (props[k] !== mark[k]) { + newProps[k] = props[k] + } + } + + // If no properties have changed don't apply an operation at all. + if (Object.keys(newProps).length === 0) { + continue + } + + this.apply({ + type: 'set_mark', + path, + properties: mark, + newProperties: newProps, + }) + } + + if (isSelection) { + this.select(at) + } + } + }) + } + + toggleMarks( + this: Editor, + marks: Mark[], + options: { + at?: Path | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { at } = options + const existing = this.getActiveMarks({ at }) + const exists = marks.every(m => Mark.exists(m, existing)) + + if (exists) { + this.removeMarks(marks, { at }) + } else { + this.addMarks(marks, { at }) + } + }) + } +} + +export default MarkingCommands diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts new file mode 100644 index 0000000000..de8bee3e66 --- /dev/null +++ b/packages/slate/src/classes/commands/node.ts @@ -0,0 +1,687 @@ +import { produce } from 'immer' +import { + Descendant, + ElementEntry, + PathRef, + Editor, + Fragment, + Node, + NodeEntry, + RangeRef, + Element, + Path, + Text, + Range, + Value, + Point, +} from '../..' + +class NodeCommands { + /** + * Insert a node (or nodes) at a specific location in the editor. + * + * The `at` option can be: + * + * - Omitted and the editor's current selection will be used as a range. + * + * - A `Range` and the range's content will be deleted, and then the collapsed + * range will be used as a point. + * + * - A `Point` and the nodes up to a certain height will be split, and then + * the node will be inserted at the correct path. The height is determined + * by what kind of node you insert. Blocks are inserted at as leaf blocks. + * Inlines are inserted as root inlines. And texts are inserted at leaf + * nodes. You can override the default by passing the `height` option. + * + * - A `Path` and the node will be inserted at the specific path. + */ + + insertNodes( + this: Editor, + nodes: Node | Node[], + options: { + at?: Range | Point | Path + height?: number | 'block' | 'inline' + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, height } = options + let isSelection = false + + if (Node.isNode(nodes)) { + nodes = [nodes] + } + + if (nodes.length === 0) { + return + } + + const [node] = nodes + + if (height == null) { + if (Text.isText(node)) { + height = 0 + } else if (this.isInline(node)) { + height = 'inline' + } else { + height = 'block' + } + } + + if (at == null && selection != null) { + at = selection + isSelection = true + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (Point.isPoint(at)) { + height = this.getHeight(at.path, height) + const topPath = at.path.slice(0, at.path.length - height) + const isAtEnd = this.isAtEnd(at, topPath) + const pointRef = this.createPointRef(at) + this.splitNodes({ at, height, always: false }) + const point = pointRef.unref()! + const path = point.path.slice(0, point.path.length - height) + at = isAtEnd ? Path.next(path) : path + } + + if (!Path.isPath(at)) { + return + } + + const path = at + const parentPath = Path.parent(at) + let index = path[path.length - 1] + + if (this.getFurthestVoid(parentPath)) { + return + } + + for (const node of nodes) { + const p = parentPath.concat(index) + index++ + + this.apply({ + type: 'insert_node', + path: p, + node, + }) + } + + if (isSelection) { + const point = this.getEnd(path) + + if (point) { + this.select(point) + } + } + }) + } + + /** + * Unwrap a single node from its parent. + * + * If the node is surrounded with siblings, its parent will be split. If the + * node is the only child, the parent is removed, and simply replaced by the + * node itself. + */ + + liftNodes( + this: Editor, + options: { + at?: Range | Point | Path + depth?: number + } + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, depth = 2 } = options + + if (depth < 2) { + throw new Error( + `Cannot lift nodes at a depth of less than \`2\`, but you passed depth: \`${depth}\`` + ) + } + + if (!at && selection) { + at = selection + } + + if (Path.isPath(at)) { + depth = at.length + at = this.getRange(at) + } + + if (Point.isPoint(at)) { + at = { anchor: at, focus: at } + } + + if (!Range.isRange(at)) { + return + } + + const [start, end] = Range.points(at) + const [, commonPath] = this.getCommon(start.path, end.path) + const parentPath = commonPath.slice(0, depth - 1) + const parent = this.getNode(parentPath) + const startIndex = start.path[parentPath.length] + const endIndex = end.path[parentPath.length] + const { length } = parent.nodes + + if (length === 1) { + this.pluckNodes({ at: parentPath }) + } else if (startIndex === 0) { + this.moveNodes({ at, depth, to: parentPath }) + } else if (endIndex === length - 1) { + this.moveNodes({ at, depth, to: Path.next(parentPath) }) + } else { + const newPath = Path.next(parentPath) + this.splitNodes({ at: parentPath.concat(endIndex + 1) }) + this.moveNodes({ at, depth: parentPath.length + 1, to: newPath }) + } + }) + } + + /** + * Move the nodes at a location to a new location. + */ + + moveNodes( + this: Editor, + options: { + at?: Range | Point | Path + depth?: number + to: Path + } + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + const { to } = options + const newIndex = to[to.length - 1] + let { at, depth = 1 } = options + let isSelection = false + + if (newIndex > 0 && !this.hasNode(Path.previous(to))) { + throw new Error( + `Cannot move the node at path [${at}] to new path [${to}] because the index is out of range.` + ) + } + + if (depth < 1) { + throw new Error( + `Cannot move nodes at a depth less than \`1\`, but you passed depth: \`${depth}\`` + ) + } + + if (!at && selection) { + at = selection + isSelection = true + } + + if (Path.isPath(at)) { + depth = at.length + at = this.getRange(at) + } + + if (Point.isPoint(at)) { + at = { anchor: at, focus: at } + } + + if (!Range.isRange(at)) { + return + } + + const [start, end] = Range.points(at) + const rangeRef = this.createRangeRef(at) + const [, commonPath] = this.getCommon(start.path, end.path) + const parentPath = commonPath.slice(0, depth - 1) + const startIndex = start.path[parentPath.length] + const endIndex = end.path[parentPath.length] + + for (let i = endIndex; i >= startIndex; i--) { + this.apply({ + type: 'move_node', + path: parentPath.concat(i), + newPath: to, + }) + } + + if (isSelection && rangeRef.current) { + this.select(rangeRef.current) + } + + rangeRef.unref() + }) + } + + /** + * Normalize a node at a path, returning it to a valid state if it is + * currently invalid. + */ + + normalizeNodes(this: Editor, options: { at: Path }): void { + const { at } = options + const node = this.getNode(at) + + // There are no core normalizations for text nodes. + if (Text.isText(node)) { + return + } + + // Ensure that block and inline nodes have at least one text child. + if (Element.isElement(node) && node.nodes.length === 0) { + const child = { text: '', marks: [] } + this.insertNodes(child, { at: at.concat(0) }) + return + } + + // Determine whether the node should have block or inline children. + const shouldHaveInlines = + Element.isElement(node) && + (this.isInline(node) || + node.nodes.length === 0 || + Text.isText(node.nodes[0]) || + this.isInline(node.nodes[0])) + + // Since we'll be applying operations while iterating, keep track of an + // index that accounts for any added/removed nodes. + let n = 0 + + for (let i = 0; i < node.nodes.length; i++, n++) { + const child = node.nodes[i] as Descendant + const prev = node.nodes[i - 1] + const isLast = i === node.nodes.length - 1 + + if (Element.isElement(child)) { + const isInline = this.isInline(child) + + // Only allow block nodes in the top-level value and parent blocks that + // only contain block nodes. Similarly, only allow inline nodes in other + // inline nodes, or parent blocks that only contain inlines and text. + if (isInline !== shouldHaveInlines) { + this.removeNodes({ at: at.concat(n) }) + n-- + continue + } + + // Ensure that inline nodes are surrounded by text nodes. + if (isInline) { + if (prev == null || !Text.isText(prev)) { + const child = { text: '', marks: [] } + this.insertNodes(child, { at: at.concat(n) }) + n++ + continue + } + + if (isLast) { + const child = { text: '', marks: [] } + this.insertNodes(child, { at: at.concat(n + 1) }) + n++ + continue + } + } + } else { + // Merge adjacent text nodes that are empty or have matching marks. + if (prev != null && Text.isText(prev)) { + if (Text.matches(child, prev)) { + this.mergeNodeAtPath(at.concat(n)) + n-- + continue + } else if (prev.text === '') { + this.removeNodes({ at: at.concat(n - 1) }) + n-- + continue + } else if (isLast && child.text === '') { + this.removeNodes({ at: at.concat(n) }) + n-- + continue + } + } + } + } + } + + /** + * Removing a node at a path, replacing it with its children. + */ + + pluckNodes( + this: Editor, + options: { + at?: Path | Range + match?: Partial | ((entry: ElementEntry) => boolean) + } + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, match = () => true } = options + + if (!at && selection) { + at = selection + } + + if (Path.isPath(at)) { + const path = at + match = ([n, p]: NodeEntry) => Path.equals(p, path) + at = this.getRange(at) + } + + if (typeof match === 'object') { + const props = match + match = ([n]: NodeEntry) => + Element.isElement(n) && Element.matches(n, props) + } + + if (typeof match !== 'function') { + throw new Error( + `The \`match\` option to \`editor.pluckNodes()\` should be a function or a properties object to match.` + ) + } + + for (const [node, path] of this.elements({ at })) { + if (!match([node, path])) { + continue + } + + this.moveNodes({ + at: this.getRange(path), + depth: path.length + 1, + to: Path.next(path), + }) + + this.removeNodes({ at: path }) + } + }) + } + + /** + * Remove the node at a path. + */ + + removeNodes(this: Editor, options: { at: Path }) { + const { at } = options + const node = this.getNode(at) + this.apply({ type: 'remove_node', path: at, node }) + } + + /** + * Set new properties on nodes in the editor. + */ + + setNodes( + this: Editor, + props: Partial, + options: { + at?: Path | Point | Range + match?: 'block' | 'inline' | 'text' | ((entry: NodeEntry) => boolean) + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, match = () => true } = options + + if (match === 'block') { + match = ([n]: NodeEntry) => Element.isElement(n) && !this.isInline(n) + } else if (match === 'inline') { + match = ([n]: NodeEntry) => Element.isElement(n) && this.isInline(n) + } else if (match === 'text') { + match = ([n]: NodeEntry) => Text.isText(n) + } + + if (!at && selection) { + at = selection + } + + if (Path.isPath(at)) { + const path = at + match = ([n, p]: NodeEntry) => Path.equals(p, path) + at = this.getRange(path) + } + + if (Point.isPoint(at)) { + const point = at + match = ([n, p]: NodeEntry) => Path.equals(p, point.path) + at = { anchor: point, focus: point } + } + + if (!Range.isRange(at)) { + return + } + + at = this.getNonHangingRange(at) + + for (const [node, path] of this.entries({ at })) { + if (!match([node, path])) { + continue + } + + const properties: Partial = {} + const newProperties: Partial = {} + + for (const k in props) { + if ( + k === 'annotations' || + k === 'marks' || + k === 'nodes' || + k === 'selection' || + k === 'text' + ) { + continue + } + + if (props[k] !== node[k]) { + properties[k] = node[k] + newProperties[k] = props[k] + } + } + + // If no properties have changed don't apply an operation at all. + if (Object.keys(newProperties).length === 0) { + continue + } + + this.apply({ + type: 'set_node', + path, + properties, + newProperties, + }) + } + }) + } + + /** + * Split the nodes at a specific location. + */ + + splitNodes( + this: Editor, + options: { + at?: Path | Point | Range + always?: boolean + height?: number | 'block' | 'inline' + skip?: number + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + const { always = true } = options + let { at, height = 0, skip = 0 } = options + let isSelection = false + let minHeight = 0 + let position: number | null = null + + if (!at && selection) { + at = selection + isSelection = true + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (Path.isPath(at)) { + const first = this.getFirstText(at) + + if (!first) { + return + } + + const [, firstPath] = first + skip = firstPath.length - at.length + 1 + position = at[at.length - 1] + minHeight = skip + at = { path: firstPath, offset: 0 } + } + + if (!Point.isPoint(at)) { + return + } + + const { path, offset } = at + const outsideRef = this.createPointRef(at) + const insideRef = this.createPointRef(at, { stick: 'backward' }) + const furthestVoid = this.getFurthestVoid(path) + let pos = position == null ? offset : position + let target: number | null = null + let h = skip + height = this.getHeight(path, height) + height = Math.max(height, minHeight) + + // If the point it inside a void node, we still want to split up to a + // `height`, but we need to start after the void node in the tree. + if (furthestVoid) { + const [, voidPath] = furthestVoid + const relPath = Path.relative(path, voidPath) + h = Math.max(relPath.length + 1, skip) + pos = voidPath[voidPath.length - 1] + } + + while (h <= height) { + const depth = path.length - h + const p = path.slice(0, depth) + h++ + + if (p.length === 0) { + break + } + + // With the `always: false` option, we will instead split the nodes only + // when the point isn't already at it's edge. + if ( + !always && + insideRef.current != null && + this.isAtEdge(insideRef.current, p) + ) { + continue + } + + const node = this.getNode(path) + let properties + + if (Text.isText(node)) { + const { text, marks, ...rest } = node + properties = rest + } else { + const { nodes, ...rest } = node + properties = rest + } + + this.apply({ + type: 'split_node', + path: p, + position: pos, + target, + properties, + }) + + target = pos + pos = path[depth - 1] + 1 + } + + if (isSelection) { + const point = outsideRef.current! + this.select(point) + } + + outsideRef.unref() + }) + } + + /** + * Unwrap the leaf nodes from the closest matching parent. + */ + + unwrapNodes( + this: Editor, + options: { + at?: Path | Range + match?: Partial | ((entry: ElementEntry) => boolean) + } + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, match = () => true } = options + + if (!at && selection) { + at = selection + } + + if (Path.isPath(at)) { + const path = at + match = ([n, p]: ElementEntry) => Path.equals(p, path) + at = this.getRange(at) + } + + if (typeof match === 'object') { + const props = match + match = ([n]: ElementEntry) => Element.matches(n, props) + } + + if (typeof match !== 'function') { + throw new Error( + `The \`match\` option to \`editor.pluckNodes()\` should be a function or a properties object to match.` + ) + } + + const rangeRefs: RangeRef[] = [] + + for (const [node, path] of this.elements({ at })) { + if (match([node, path])) { + const range = this.getRange(path) + const intersection = Range.intersection(at, range) + const rangeRef = this.createRangeRef(intersection) + rangeRefs.push(rangeRef) + } + } + + for (const rangeRef of rangeRefs) { + if (rangeRef.current) { + this.liftNodes({ at: rangeRef.current }) + } + + rangeRef.unref() + } + }) + } +} + +export default NodeCommands diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 19c677b43d..0e44eab1c2 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -13,79 +13,6 @@ import { } from '../..' class PathCommands { - /** - * Insert a fragment starting at a path. - */ - - insertFragmentAtPath(this: Editor, path: Path, fragment: Fragment): void { - const parentPath = path.slice(0, -1) - let i = path[path.length - 1] - - this.withoutNormalizing(() => { - for (const node of fragment.nodes) { - const childPath = parentPath.concat(i) - i++ - this.insertNodeAtPath(childPath, node) - } - }) - } - - /** - * Insert a node at a path. - */ - - insertNodeAtPath(this: Editor, path: Path, node: Node): void { - this.apply({ type: 'insert_node', path, node }) - } - - /** - * Unwrap a single node from its parent. - * - * If the node is surrounded with siblings, its parent will be split. If the - * node is the only child, the parent is removed, and simply replaced by the - * node itself. - */ - - liftNodeAtPath(this: Editor, path: Path): void { - const { value } = this - const parent = Node.parent(value, path) - const parentPath = Path.parent(path) - const index = path[path.length - 1] - const parentIndex = parentPath[parentPath.length - 1] - const grandPath = Path.parent(parentPath) - const isFirst = index === 0 - const isLast = index === parent.nodes.length - 1 - - this.withoutNormalizing(() => { - let targetPath = path - let newPath = grandPath.concat(parentIndex + 1) - - // If the parent has multiple nodes and we're unwrapping the first one, we - // will just move it before the parent instead. - if (parent.nodes.length > 1 && isFirst) { - newPath = grandPath.concat(parentIndex) - } - - // If there are multiple children, and we're unwrapping one of the middle - // children, we need to split the parent in half first. - if (parent.nodes.length > 1 && !isFirst && !isLast) { - targetPath = produce(path, p => { - p[parentPath.length - 1] += 1 - p[targetPath.length - 1] = 0 - }) - - this.splitNodeAtPath(parentPath, index) - } - - this.moveNodeAtPath(targetPath, newPath) - - // If there was only one child, the parent gets removed. - if (parent.nodes.length === 1) { - this.removeNodeAtPath(parentPath) - } - }) - } - /** * Merge the leaf block at a path with the previous leaf block. */ @@ -123,17 +50,17 @@ class PathCommands { const furthestRef = furthest ? this.createPathRef(furthest[1]) : null - this.moveNodeAtPath(blockPath, newPath) + this.moveNodes({ at: blockPath, to: newPath }) if (furthestRef) { - this.removeNodeAtPath(furthestRef.unref()!) + this.removeNodes({ at: furthestRef.unref()! }) } // If the target block is empty, remove it instead of merging. This is a // rich text editor common behavior to prevent losing block formatting // when deleting the entire previous block (with a hanging selection). if (this.isEmpty(prev)) { - this.removeNodeAtPath(prevPath) + this.removeNodes({ at: prevPath }) } else { this.mergeNodeAtPath(newPath) } @@ -189,295 +116,16 @@ class PathCommands { } } - /** - * Move a node at a path to a new path. - */ - - moveNodeAtPath(this: Editor, path: Path, newPath: Path): void { - const { value } = this - const parentPath = Path.parent(path) - const newIndex = newPath[newPath.length - 1] - - if (!Node.has(value, path)) { - throw new Error( - `Cannot move the node at path [${path}] because it does not exist.` - ) - } - - if (!Node.has(value, parentPath)) { - throw new Error( - `Cannot move the node at path [${path}] to the new parent at path [${parentPath}] because the parent does not exist.` - ) - } - - if (newIndex !== 0 && !Node.has(value, Path.previous(newPath))) { - throw new Error( - `Cannot move the node at path [${path}] to new path [${newPath}] because the index is out of range.` - ) - } - - this.apply({ - type: 'move_node', - path, - newPath, - }) - } - - /** - * Normalize a node at a path, returning it to a valid state if it is - * currently invalid. - */ - - normalizeNodeAtPath(this: Editor, path: Path): void { - const { value } = this - const node = Node.get(value, path) - - // There are no core normalizations for text nodes. - if (Text.isText(node)) { - return - } - - // Ensure that block and inline nodes have at least one text child. - if (Element.isElement(node) && node.nodes.length === 0) { - this.insertNodeAtPath(path.concat(0), { text: '', marks: [] }) - return - } - - // Determine whether the node should have block or inline children. - const shouldHaveInlines = - Element.isElement(node) && - (this.isInline(node) || - node.nodes.length === 0 || - Text.isText(node.nodes[0]) || - this.isInline(node.nodes[0])) - - // Since we'll be applying operations while iterating, keep track of an - // index that accounts for any added/removed nodes. - let n = 0 - - for (let i = 0; i < node.nodes.length; i++, n++) { - const child = node.nodes[i] as Descendant - const prev = node.nodes[i - 1] - const isLast = i === node.nodes.length - 1 - - if (Element.isElement(child)) { - const isInline = this.isInline(child) - - // Only allow block nodes in the top-level value and parent blocks that - // only contain block nodes. Similarly, only allow inline nodes in other - // inline nodes, or parent blocks that only contain inlines and text. - if (isInline !== shouldHaveInlines) { - this.removeNodeAtPath(path.concat(n)) - n-- - continue - } - - // Ensure that inline nodes are surrounded by text nodes. - if (isInline) { - if (prev == null || !Text.isText(prev)) { - this.insertNodeAtPath(path.concat(n), { text: '', marks: [] }) - n++ - continue - } - - if (isLast) { - this.insertNodeAtPath(path.concat(n + 1), { text: '', marks: [] }) - n++ - continue - } - } - } else { - // Merge adjacent text nodes that are empty or have matching marks. - if (prev != null && Text.isText(prev)) { - if (Text.matches(child, prev)) { - this.mergeNodeAtPath(path.concat(n)) - n-- - continue - } else if (prev.text === '') { - this.removeNodeAtPath(path.concat(n - 1)) - n-- - continue - } else if (isLast && child.text === '') { - this.removeNodeAtPath(path.concat(n)) - n-- - continue - } - } - } - } - } - - /** - * Removing a node at a path, replacing it with its children. - */ - - pluckNodeAtPath(this: Editor, path: Path): void { - const { value } = this - const node = Node.get(value, path) - - if (Text.isText(node)) { - throw new Error( - `Cannot pluck a node at [${path}] because it is a text node and has no children.` - ) - } - - this.withoutNormalizing(() => { - const parentPath = Path.parent(path) - const index = path[path.length - 1] - - for (let i = 0; i < node.nodes.length; i++) { - const targetPath = path.concat(0) - const newPath = parentPath.concat(index + i + 1) - this.moveNodeAtPath(targetPath, newPath) - } - - this.removeNodeAtPath(path) - }) - } - - /** - * Remove all of the children from the node at a path. - */ - - removeChildrenAtPath(this: Editor, path: Path): void { - const { value } = this - const parent = Node.ancestor(value, path) - - this.withoutNormalizing(() => { - const childPath = path.concat([0]) - - for (let i = 0; i < parent.nodes.length; i++) { - this.removeNodeAtPath(childPath) - } - }) - } - - /** - * Remove the node at a path. - */ - - removeNodeAtPath(this: Editor, path: Path): void { - const { value } = this - const node = Node.get(value, path) - this.apply({ type: 'remove_node', path, node }) - } - - /** - * Remove the parent node of a path. - */ - - removeParentAtPath(this: Editor, path: Path): void { - const { value } = this - const parent = Node.parent(value, path) - const parentPath = Path.parent(path) - this.apply({ type: 'remove_node', path: parentPath, node: parent }) - } - - /** - * Replace the node at a path with a new node. - */ - - replaceNodeAtPath(this: Editor, path: Path, node: Node): void { - this.withoutNormalizing(() => { - this.removeNodeAtPath(path) - this.insertNodeAtPath(path, node) - }) - } - - /** - * Set new properties on the node at a path. - */ - - setNodeAtPath(this: Editor, path: Path, props: {}): void { - if (path.length === 0) { - this.setValue(props) - return - } - - const { value } = this - const node = Node.get(value, path) - const newProps = {} - const oldProps = {} - - for (const k in props) { - if (k === 'nodes' || k === 'text' || k === 'marks') { - continue - } - - if (props[k] !== node[k]) { - oldProps[k] = node[k] - newProps[k] = props[k] - } - } - - // If no properties have changed don't apply an operation at all. - if (Object.keys(newProps).length !== 0) { - return - } - - this.apply({ - type: 'set_node', - path, - properties: oldProps, - newProperties: newProps, - }) - } - - /** - * Split the node at a path at a specific position in the node. If the node is - * a text node, `position` refers to a string offset. If the node is an - * element node, `position` refers to the index of its children. - * - * If you're looking to split from an ancestor all the way down to a leaf text - * node, you likely want `splitNodeAtPoint` instead. - */ - - splitNodeAtPath( - this: Editor, - path: Path, - position: number, - options: { target?: number } = {} - ): void { - if (path.length === 0) { - throw new Error(`Cannot split the root node.`) - } - - if (this.getFurthestVoid(path)) { - return - } - - const { target = null } = options - const { value } = this - const node = Node.get(value, path) - let properties - - if (Text.isText(node)) { - const { text, marks, ...rest } = node - properties = rest - } else { - const { nodes, ...rest } = node - properties = rest - } - - this.apply({ - type: 'split_node', - path, - position, - target, - properties, - }) - } - /** * Wrap the node at a path in a new parent node. */ wrapNodeAtPath(this: Editor, path: Path, element: Element): void { this.withoutNormalizing(() => { - this.insertNodeAtPath(path, element) + this.insertNodes(element, { at: path }) const nextPath = Path.next(path) const childPath = path.concat(0) - this.moveNodeAtPath(nextPath, childPath) + this.moveNodes({ at: nextPath, to: childPath }) }) } } diff --git a/packages/slate/src/classes/commands/point.ts b/packages/slate/src/classes/commands/point.ts deleted file mode 100755 index ac421c4740..0000000000 --- a/packages/slate/src/classes/commands/point.ts +++ /dev/null @@ -1,154 +0,0 @@ -import { produce } from 'immer' -import { Editor, Element, Fragment, Node, Path, Point, Range } from '../..' - -class PointCommands { - /** - * Insert a fragment of nodes at a point. - */ - - insertFragmentAtPoint(this: Editor, point: Point, fragment: Fragment): void { - if (fragment.nodes.length === 0) { - return - } - - this.withoutNormalizing(() => { - const pointRef = this.createPointRef(point) - this.splitBlockAtPoint(point) - - if (pointRef.current != null) { - const insertClosest = this.getClosestBlock(pointRef.current.path) - - if (insertClosest != null) { - const [, insertPath] = insertClosest - this.insertFragmentAtPath(insertPath, fragment) - - const afterClosest = this.getClosestBlock(pointRef.current.path) - const beforeClosest = this.getClosestBlock(point.path) - - if (afterClosest != null && beforeClosest != null) { - const [, afterPath] = afterClosest - const [, beforePath] = beforeClosest - const startPath = Path.next(beforePath) - this.mergeBlockAtPath(afterPath) - this.mergeBlockAtPath(startPath) - } - } - } - }) - } - - /** - * Remove a string of text by length from a specific point in the document. - */ - - removeTextAtPoint(this: Editor, point: Point, length: number): Point { - const { value } = this - const { annotations } = value - const { path, offset } = point - const node = Node.leaf(value, path) - const text = node.text.slice(offset, offset + length) - - this.withoutNormalizing(() => { - for (const key in annotations) { - const annotation = annotations[key] - - if (this.isAtomic(annotation)) { - const [start] = Range.points(annotation) - const [, end] = Range.points(annotation) - - if ( - start.offset < offset && - Path.equals(start.path, path) && - (!Path.equals(end.path, path) || offset < end.offset) - ) { - this.removeAnnotation(key) - } - } - } - - this.apply({ - type: 'remove_text', - path, - offset, - text, - }) - }) - - return point - } - - /** - * Split nodes in the document at a specific point, up to a certain height. - * - * If the `always: false` option is passed, nodes will only be split if the - * point is not already at one of their edges. - */ - - splitNodeAtPoint( - this: Editor, - point: Point, - options: { - always?: boolean - height?: number - } = {} - ): void { - const { path, offset } = point - const { height = 0, always = true } = options - - if (height < 0) { - throw new Error( - `Cannot split the node at path [${path}] to a negative height of \`${height}\`.` - ) - } - - this.withoutNormalizing(() => { - const furthestVoid = this.getFurthestVoid(point.path) - let position = offset - let target: number | undefined - let h = 0 - - // If the point it inside a void node, we still want to split up to a - // `height`, but we need to start after the void node in the tree. - if (furthestVoid) { - const [, voidPath] = furthestVoid - const relPath = Path.relative(point.path, voidPath) - h = relPath.length + 1 - position = voidPath[voidPath.length - 1] - } - - // Create a ref that tracks the split point as we move up the ancestors. - // Stick backwards because we're splitting and we want to remain inside - // the ancestor branch. - const pointRef = this.createPointRef(point, { stick: 'backward' }) - - // Iterate up the ancestors, splitting each until the right depth. - while (h <= height) { - const depth = path.length - h - const p = path.slice(0, depth) - h++ - - if (p.length === 0) { - break - } - - // With the `always: false` option, we will instead split the nodes only - // when the point isn't already at it's edge. - if ( - !always && - pointRef.current != null && - this.isAtEdge(pointRef.current, p) - ) { - continue - } - - this.splitNodeAtPath(p, position, { target }) - target = position - position = path[depth - 1] + 1 - } - - pointRef.unref() - }) - } -} - -export default PointCommands diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index 02b3560187..8b4d8dbd86 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -10,132 +10,6 @@ import { } from '../..' class RangeCommands { - /** - * Insert a fragment of nodes at a range. - */ - - insertFragmentAtRange(this: Editor, range: Range, fragment: Fragment): void { - this.withoutNormalizing(() => { - const [start] = Range.points(range) - const pointRef = this.createPointRef(start) - - if (Range.isExpanded(range)) { - this.deleteAtRange(range) - } - - this.insertFragmentAtPoint(pointRef.current!, fragment) - pointRef.unref() - }) - } - - /** - * Set new properties on all of the leaf blocks in a range. - */ - - setLeafBlocksAtRange( - this: Editor, - range: Range, - props: {}, - options: { - hanging?: boolean - } = {} - ): void { - const { hanging = false } = options - - this.withoutNormalizing(() => { - if (hanging === false) { - // To obey common rich text editor behavior, if the range is "hanging" - // into the end block, we move it backwards so that it's not. - range = this.getNonHangingRange(range) - } - - for (const [, path] of this.leafBlocks({ at: range })) { - this.setNodeAtPath(path, props) - } - }) - } - - /** - * Set new properties on all of the leaf inlines in a range. - */ - - setLeafInlinesAtRange( - this: Editor, - range: Range, - props: {}, - options: { - hanging?: boolean - } = {} - ): void { - const { hanging = false } = options - - this.withoutNormalizing(() => { - if (hanging === false) { - // To obey common rich text editor behavior, if the range is "hanging" - // into the end block, we move it backwards so that it's not. - range = this.getNonHangingRange(range) - } - - for (const [, path] of this.leafInlines({ at: range })) { - this.setNodeAtPath(path, props) - } - }) - } - - /** - * Set new properties on all of the root blocks in a range. - */ - - setRootBlocksAtRange( - this: Editor, - range: Range, - props: {}, - options: { - hanging?: boolean - } = {} - ): void { - const { hanging = false } = options - - this.withoutNormalizing(() => { - if (hanging === false) { - // To obey common rich text editor behavior, if the range is "hanging" - // into the end block, we move it backwards so that it's not. - range = this.getNonHangingRange(range) - } - - for (const [, path] of this.rootBlocks({ at: range })) { - this.setNodeAtPath(path, props) - } - }) - } - - /** - * Set new properties on all of the root inlines in a range. - */ - - setRootInlinesAtRange( - this: Editor, - range: Range, - props: {}, - options: { - hanging?: boolean - } = {} - ): void { - const { hanging = false } = options - - this.withoutNormalizing(() => { - if (hanging === false) { - // To obey common rich text editor behavior, if the range is "hanging" - // into the end block, we move it backwards so that it's not. - range = this.getNonHangingRange(range) - } - - for (const [, path] of this.rootInlines({ at: range })) { - this.setNodeAtPath(path, props) - } - }) - } - /** * Unwrap the block nodes in a range that match a set of properties. */ diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts new file mode 100644 index 0000000000..2c639563b6 --- /dev/null +++ b/packages/slate/src/classes/commands/text.ts @@ -0,0 +1,226 @@ +import { + Editor, + Element, + Node, + Fragment, + Path, + Range, + Point, + Value, +} from '../..' + +class DeletingCommands { + /** + * Delete content in the editor. + */ + + delete( + this: Editor, + options: { + at?: Path | Point | Range + distance?: number + unit?: 'character' | 'word' | 'line' | 'block' + reverse?: boolean + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + const { reverse = false, unit = 'character', distance = 1 } = options + let { at } = options + let isSelection = false + let ancestorPath: Path = [] + let ancestor: Node = this.value + + if (!at && selection) { + at = selection + isSelection = true + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Point.isPoint(at)) { + const furthestVoid = this.getFurthestVoid(at.path) + + if (furthestVoid) { + const [, voidPath] = furthestVoid + at = voidPath + } else { + const opts = { unit, distance } + const target = reverse + ? this.getPreviousPoint(at, opts) + : this.getNextPoint(at, opts) + + if (target) { + at = { anchor: at, focus: target } + } + } + } + + if (Range.isRange(at)) { + const [start, end] = Range.points(at) + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [common, commonPath] = this.getCommon(start.path, end.path) + let startHeight = start.path.length - commonPath.length - 1 + let endHeight = end.path.length - commonPath.length - 1 + + if (Path.equals(start.path, end.path)) { + ancestorPath = Path.parent(commonPath) + ancestor = Node.get(this.value, ancestorPath) + startHeight = 0 + endHeight = 0 + } else { + ancestorPath = commonPath + ancestor = common + } + + this.splitNodes({ at: end, height: Math.max(0, endHeight) }) + this.splitNodes({ at: start, height: Math.max(0, startHeight) }) + at = rangeRef.unref()! + } + + if (Path.isPath(at)) { + const node = Node.get(this.value, at) + this.apply({ type: 'remove_node', path: at, node }) + } + + if (Range.isRange(at)) { + const [start, end] = Range.points(at) + const after = this.getNextPoint(end)! + const afterRef = this.createPointRef(after) + const l = ancestorPath.length + const startIndex = start.path[l] + const endIndex = end.path[l] + const hasBlocks = + Value.isValue(ancestor) || + (Element.isElement(ancestor) && this.hasBlocks(ancestor)) + + // Iterate backwards so the paths are unaffected. + for (let i = endIndex; i >= startIndex; i--) { + const path = ancestorPath.concat(i) + const node = Node.get(this.value, path) + this.apply({ type: 'remove_node', path, node }) + } + + if (hasBlocks) { + this.mergeBlockAtPath(afterRef.current!.path) + } + + if (isSelection) { + this.select(afterRef.current!) + } + + afterRef.unref() + } + }) + } + + /** + * Insert a fragment at a specific location in the editor. + */ + + insertFragment( + this: Editor, + fragment: Fragment, + options: { + at?: Range | Point + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + let isSelection = false + + if (!at && selection) { + at = selection + isSelection = true + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (!Point.isPoint(at) || this.getFurthestVoid(at.path)) { + return + } + + const pointRef = this.createPointRef(at) + this.splitNodes({ at, height: 'block' }) + + if (pointRef.current) { + const [, insertPath] = this.getClosestBlock(pointRef.current.path)! + this.insertNodes(fragment.nodes, { at: insertPath }) + + const afterClosest = this.getClosestBlock(pointRef.current.path) + const beforeClosest = this.getClosestBlock(at.path) + + if (afterClosest && beforeClosest) { + const [, afterPath] = afterClosest + const [, beforePath] = beforeClosest + const startPath = Path.next(beforePath) + this.mergeBlockAtPath(afterPath) + this.mergeBlockAtPath(startPath) + } + } + + if (isSelection) { + this.select(pointRef.current!) + } + + pointRef.unref() + }) + } + + /** + * Insert a string of text in the editor. + */ + + insertText( + this: Editor, + text: string, + options: { + at?: Point | Range + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at } = options + + if (!at && selection) { + at = selection + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } + + if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } + + if (Point.isPoint(at) && !this.getFurthestVoid(at.path)) { + for (const [annotation, key] of this.annotations({ at })) { + if (this.isAtomic(annotation)) { + this.removeAnnotation(key) + } + } + + const { path, offset } = at + this.apply({ type: 'insert_text', path, offset, text }) + } + }) + } +} + +export default DeletingCommands diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts index bc8e409bd7..64bf82a8fa 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/value.ts @@ -1,15 +1,11 @@ import { Change, + Operation, Editor, Element, - Fragment, - Mark, Node, - Operation, Path, Text, - Range, - Point, Value, } from '../..' import { @@ -22,70 +18,6 @@ import { } from '../../symbols' class ValueCommands { - /** - * Add a set of marks at a location. You can add them to the content of - * specific node at a path, or to all of the text content in a range. - */ - - addMarks( - this: Editor, - marks: Mark[], - options: { - at?: Path | Range - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false - - if (!at && selection) { - at = selection - isSelection = true - } - - if (Path.isPath(at)) { - at = this.getRange(at) - } - - if (!Range.isRange(at)) { - return - } - - // Split the text nodes at the range's edges if necessary. - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) - this.splitNodeAtPoint(end, { always: false }) - this.splitNodeAtPoint(start, { always: false }) - at = rangeRef.unref()! - - // De-dupe the marks being added to ensure the set is unique. - const set: Mark[] = [] - - for (const mark of marks) { - if (!Mark.exists(mark, set)) { - set.push(mark) - } - } - - for (const [node, path] of this.texts({ at })) { - for (const mark of set) { - if (!Mark.exists(mark, node.marks)) { - this.apply({ type: 'add_mark', path, mark }) - } - } - } - - if (isSelection) { - this.select(at) - } - }) - } - - /** - * Apply an operation to the editor, updating its current value. - */ - apply(this: Editor, op: Operation): void { this.value = Value.transform(this.value, op) this.operations.push(op) @@ -136,116 +68,6 @@ class ValueCommands { } } - /** - * Delete the content in the selection, or starting from the cursor. - */ - - delete( - this: Editor, - options: { - at?: Path | Point | Range - distance?: number - unit?: 'character' | 'word' | 'line' | 'block' - reverse?: boolean - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - const { reverse = false, unit = 'character', distance = 1 } = options - let { at } = options - let isSelection = false - let ancestorPath: Path = [] - let ancestor: Node = this.value - - if (!at && selection) { - at = selection - isSelection = true - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - - if (Point.isPoint(at)) { - const furthestVoid = this.getFurthestVoid(at.path) - - if (furthestVoid) { - const [, voidPath] = furthestVoid - at = voidPath - } else { - const opts = { unit, distance } - const target = reverse - ? this.getPreviousPoint(at, opts) - : this.getNextPoint(at, opts) - - if (target) { - at = { anchor: at, focus: target } - } - } - } - - if (Range.isRange(at)) { - const [start, end] = Range.points(at) - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [common, commonPath] = this.getCommon(start.path, end.path) - let startHeight = start.path.length - commonPath.length - 1 - let endHeight = end.path.length - commonPath.length - 1 - - if (Path.equals(start.path, end.path)) { - ancestorPath = Path.parent(commonPath) - ancestor = Node.get(this.value, ancestorPath) - startHeight = 0 - endHeight = 0 - } else { - ancestorPath = commonPath - ancestor = common - } - - this.splitNodeAtPoint(end, { height: Math.max(0, endHeight) }) - this.splitNodeAtPoint(start, { height: Math.max(0, startHeight) }) - at = rangeRef.unref()! - } - - if (Path.isPath(at)) { - const node = Node.get(this.value, at) - this.apply({ type: 'remove_node', path: at, node }) - } - - if (Range.isRange(at)) { - const [start, end] = Range.points(at) - const after = this.getNextPoint(end)! - const afterRef = this.createPointRef(after) - const l = ancestorPath.length - const startIndex = start.path[l] - const endIndex = end.path[l] - const hasBlocks = - Value.isValue(ancestor) || - (Element.isElement(ancestor) && this.hasBlocks(ancestor)) - - // Iterate backwards so the paths are unaffected. - for (let i = endIndex; i >= startIndex; i--) { - const path = ancestorPath.concat(i) - const node = Node.get(this.value, path) - this.apply({ type: 'remove_node', path, node }) - } - - if (hasBlocks) { - this.mergeBlockAtPath(afterRef.current!.path) - } - - if (isSelection) { - this.select(afterRef.current!) - } - - afterRef.unref() - } - }) - } - - /** - * Flush the editor's current changes. - */ - flush(this: Editor): void { this[FLUSHING] = false const { value, operations } = this @@ -257,196 +79,6 @@ class ValueCommands { } } - /** - * Insert a block node at the cursor. - */ - - insertBlock( - this: Editor, - block: Element, - options: { - at?: Path | Point | Range - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false - let isAtEnd = false - - if (!at && selection) { - at = selection - isSelection = true - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - - if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! - } - - if (Point.isPoint(at)) { - const [, blockPath] = this.getClosestBlock(at.path)! - isAtEnd = this.isAtEnd(at, blockPath) - const pointRef = this.createPointRef(at) - this.splitBlockAtPoint(at, { always: false }) - const point = pointRef.unref()! - at = point.path - } - - if (!Path.isPath(at)) { - return - } - - const [, blockPath] = this.getClosestBlock(at)! - const path = isAtEnd ? Path.next(blockPath) : blockPath - this.insertNodeAtPath(path, block) - - if (isSelection) { - const point = this.getEnd(path) - - if (point) { - this.select(point) - } - } - }) - } - - /** - * Insert a fragment of nodes at the cursor. - */ - - insertFragment(this: Editor, fragment: Fragment) { - const { selection } = this.value - - if (selection == null) { - return - } - - const [start] = Range.points(selection) - const pointRef = this.createPointRef(start) - this.insertFragmentAtRange(selection, fragment) - this.select(pointRef.current!) - pointRef.unref() - } - - /** - * Insert an inline node at the cursor. - */ - - insertInline( - this: Editor, - inline: Element, - options: { - at?: Path | Point | Range - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false - let isAtEnd = false - - if (!at && selection) { - at = selection - isSelection = true - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - - if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! - } - - if (Point.isPoint(at)) { - isAtEnd = this.isAtEnd(at, at.path) - const pointRef = this.createPointRef(at) - this.splitNodeAtPoint(at, { always: false }) - const point = pointRef.unref()! - at = point.path - } - - if (!Path.isPath(at)) { - return - } - - const [, blockPath] = this.getClosestBlock(at)! - - if (this.getFurthestVoid(blockPath)) { - return - } - - const path = isAtEnd ? Path.next(at) : at - this.insertNodeAtPath(path, inline) - - if (isSelection) { - const point = this.getEnd(path) - - if (point) { - this.select(point) - } - } - }) - } - - /** - * Insert a string of text at the current selection. - */ - - insertText( - this: Editor, - text: string, - options: { - at?: Point | Range - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - - if (!at && selection) { - at = selection - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - - if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! - } - - if (Point.isPoint(at) && !this.getFurthestVoid(at.path)) { - for (const [annotation, key] of this.annotations({ at })) { - if (this.isAtomic(annotation)) { - this.removeAnnotation(key) - } - } - - const { path, offset } = at - this.apply({ type: 'insert_text', path, offset, text }) - } - }) - } - - /** - * Normalize any paths that are considered "dirty", meaning they have recently - * been changed by an operation. - */ - normalize( this: Editor, options: { @@ -480,113 +112,88 @@ class ValueCommands { } const path = this[DIRTY_PATHS].pop() - this.normalizeNodeAtPath(path!) + this.normalizeNodes({ at: path! }) m++ } }) } - removeMarks( - this: Editor, - marks: Mark[], - options: { - at?: Path | Range - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false - - if (!at && selection) { - at = selection - isSelection = true - } - - if (Path.isPath(at)) { - at = this.getRange(at) - } - - if (Range.isRange(at)) { - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) - this.splitNodeAtPoint(end, { always: false }) - this.splitNodeAtPoint(start, { always: false }) - at = rangeRef.unref()! - - for (const [mark, i, node, path] of this.marks({ at })) { - if (Mark.exists(mark, marks)) { - this.apply({ type: 'remove_mark', path, mark }) - } - } - - if (isSelection) { - this.select(at) - } - } - }) + withoutNormalizing(this: Editor, fn: () => void): void { + const value = this[NORMALIZING] + this[NORMALIZING] = false + fn() + this[NORMALIZING] = value + this.normalize() } /** - * Set new properties on the leaf block nodes in the current selection. + * Unwrap the block nodes in the selection that match a set of properties. */ - setLeafBlocks(this: Editor, props: {}) { + unwrapBlock(this: Editor, props: {}): void { const { selection } = this.value if (selection == null) { return } - this.setLeafBlocksAtRange(selection, props) + const rangeRef = this.createRangeRef(selection) + this.unwrapBlockAtRange(selection, props) + const range = rangeRef.unref()! + this.select(range) } /** - * Set new properties on the leaf inline nodes in the current selection. + * Unwrap the inline nodes in the selection that match a set of properties. */ - setLeafInlines(this: Editor, props: {}) { + unwrapInline(this: Editor, props: {}): void { const { selection } = this.value if (selection == null) { return } - this.setLeafInlinesAtRange(selection, props) + const rangeRef = this.createRangeRef(selection) + this.unwrapInlineAtRange(selection, props) + const range = rangeRef.unref()! + this.select(range) } /** - * Set new properties on the root block nodes in the current selection. + * Wrap the block nodes in the selection in a new block. */ - setRootBlocks(this: Editor, props: {}) { + wrapBlock(this: Editor, block: Element): void { const { selection } = this.value if (selection == null) { return } - this.setRootBlocksAtRange(selection, props) + const rangeRef = this.createRangeRef(selection) + this.wrapBlockAtRange(selection, block) + const range = rangeRef.unref()! + this.select(range) } /** - * Set new properties on the root inline nodes in the current selection. + * Wrap the inline nodes in the selection in a new inline. */ - setRootInlines(this: Editor, props: {}) { + wrapInline(this: Editor, inline: Element): void { const { selection } = this.value if (selection == null) { return } - this.setRootInlinesAtRange(selection, props) + const rangeRef = this.createRangeRef(selection) + this.wrapInlineAtRange(selection, inline) + const range = rangeRef.unref()! + this.select(range) } - /** - * Set new properties on the top-level `Value` object. - */ - setValue(this: Editor, props: Partial) { const { value } = this const newProps = {} @@ -615,310 +222,6 @@ class ValueCommands { newProperties: newProps, }) } - - /** - * Set new properties on a set of marks. - */ - - setMarks( - this: Editor, - marks: Mark[], - props: Partial, - options: { - at?: Path | Range - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false - - if (!at && selection) { - at = selection - isSelection = true - } - - // PERF: Do this before the path coercion logic since we're guaranteed not - // to need to split in that case. - if (Range.isRange(at)) { - // Split the text nodes at the range's edges if necessary. - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) - this.splitNodeAtPoint(end, { always: false }) - this.splitNodeAtPoint(start, { always: false }) - at = rangeRef.unref()! - } - - if (Path.isPath(at)) { - at = this.getRange(at) - } - - if (Range.isRange(at)) { - for (const [mark, i, node, path] of this.marks({ at })) { - if (!Mark.exists(mark, marks)) { - continue - } - - const newProps = {} - - for (const k in props) { - if (props[k] !== mark[k]) { - newProps[k] = props[k] - } - } - - // If no properties have changed don't apply an operation at all. - if (Object.keys(newProps).length === 0) { - continue - } - - this.apply({ - type: 'set_mark', - path, - properties: mark, - newProperties: newProps, - }) - } - - if (isSelection) { - this.select(at) - } - } - }) - } - - /** - * Split the block at the cursor, up to a height. - */ - - splitBlock( - this: Editor, - options: { - at?: Point | Range - always?: boolean - height?: number - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - const { height = 0, always = true } = options - let { at } = options - let isSelection = false - - if (!at && selection) { - at = selection - isSelection = true - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - - if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! - } - - if (!Point.isPoint(at)) { - return - } - - const { path } = at - const closestBlock = this.getClosestBlock(path) - let totalHeight: number - - if (closestBlock) { - const [, blockPath] = closestBlock - const relPath = Path.relative(path, blockPath) - totalHeight = relPath.length + height - } else { - totalHeight = path.length - } - - const pointRef = this.createPointRef(at) - this.splitNodeAtPoint(at, { height: totalHeight, always }) - - if (isSelection) { - const point = pointRef.current! - this.select(point) - } - - pointRef.unref() - }) - } - - /** - * Split the inline at the cursor, up to a height. - */ - - splitInline( - this: Editor, - options: { - at?: Point | Range - always?: boolean - height?: number - } = {} - ) { - this.withoutNormalizing(() => { - const { selection } = this.value - const { height = 0, always = true } = options - let { at } = options - let isSelection = false - - if (!at && selection) { - at = selection - isSelection = true - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - - if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! - } - - if (!Point.isPoint(at)) { - return - } - - const { path } = at - const furthestInline = this.getFurthestInline(path) - let totalHeight: number - - if (furthestInline) { - const [, furthestPath] = furthestInline - const furthestRelPath = Path.relative(path, furthestPath) - // Ensure that the height isn't higher than the furthest inline, since - // this command should never split any block nodes. - const h = Math.max(furthestRelPath.length, height) - totalHeight = h - } else { - // If there are no inline ancestors, just split the text node. - totalHeight = 0 - } - - const pointRef = this.createPointRef(at) - this.splitNodeAtPoint(at, { height: totalHeight, always }) - - if (isSelection) { - const point = pointRef.current! - this.select(point) - } - - pointRef.unref() - }) - } - - /** - * Toggle a mark on or off for all the spans of text in the selection. - */ - - toggleMarks( - this: Editor, - marks: Mark[], - options: { - at?: Path | Range - } = {} - ) { - this.withoutNormalizing(() => { - const { at } = options - const existing = this.getActiveMarks({ at }) - const exists = marks.every(m => Mark.exists(m, existing)) - - if (exists) { - this.removeMarks(marks, { at }) - } else { - this.addMarks(marks, { at }) - } - }) - } - - /** - * Unwrap the block nodes in the selection that match a set of properties. - */ - - unwrapBlock(this: Editor, props: {}): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.unwrapBlockAtRange(selection, props) - const range = rangeRef.unref()! - this.select(range) - } - - /** - * Unwrap the inline nodes in the selection that match a set of properties. - */ - - unwrapInline(this: Editor, props: {}): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.unwrapInlineAtRange(selection, props) - const range = rangeRef.unref()! - this.select(range) - } - - /** - * Apply a series of changes inside a synchronous callback, deferring - * normalization until after the callback has finished executing. - */ - - withoutNormalizing(this: Editor, fn: () => void): void { - const value = this[NORMALIZING] - this[NORMALIZING] = false - fn() - this[NORMALIZING] = value - this.normalize() - } - - /** - * Wrap the block nodes in the selection in a new block. - */ - - wrapBlock(this: Editor, block: Element): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.wrapBlockAtRange(selection, block) - const range = rangeRef.unref()! - this.select(range) - } - - /** - * Wrap the inline nodes in the selection in a new inline. - */ - - wrapInline(this: Editor, inline: Element): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.wrapInlineAtRange(selection, inline) - const range = rangeRef.unref()! - this.select(range) - } } /** diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index e8d60c0f99..162456a28d 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -9,8 +9,10 @@ import { RANGE_REFS, } from '../symbols' import AnnotationCommands from './commands/annotation' +import TextCommands from './commands/text' +import NodeCommands from './commands/node' +import MarkCommands from './commands/mark' import PathCommands from './commands/path' -import PointCommands from './commands/point' import RangeCommands from './commands/range' import SelectionCommands from './commands/selection' import ValueCommands from './commands/value' @@ -76,8 +78,10 @@ class Editor { interface Editor extends AnnotationCommands, + TextCommands, + NodeCommands, + MarkCommands, PathCommands, - PointCommands, RangeCommands, SelectionCommands, ValueCommands, @@ -100,8 +104,10 @@ const mixin = (Mixins: Array any>) => { mixin([ AnnotationCommands, + TextCommands, + NodeCommands, + MarkCommands, PathCommands, - PointCommands, RangeCommands, SelectionCommands, ValueCommands, diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index b7a05d0440..58b3e771bf 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -19,14 +19,54 @@ class PathQueries { return Node.common(this.value, path, another) } + getParent(this: Editor, path: Path): Ancestor { + return Node.parent(this.value, path) + } + getLeaf(this: Editor, path: Path): Text { return Node.leaf(this.value, path) } + hasNode(this: Editor, path: Path): Node { + return Node.has(this.value, path) + } + getNode(this: Editor, path: Path): Node { return Node.get(this.value, path) } + getHeight(this: Editor, path: Path, height: number | 'inline' | 'block') { + if (height === 'block') { + const closestBlock = this.getClosestBlock(path) + + if (closestBlock) { + const [, blockPath] = closestBlock + const relPath = Path.relative(path, blockPath) + return relPath.length + } else { + return 0 + } + } + + if (height === 'inline') { + const furthestInline = this.getFurthestInline(path) + + if (furthestInline) { + const [, inlinePath] = furthestInline + const relPath = Path.relative(path, inlinePath) + return relPath.length + } else { + return 0 + } + } + + if (height > path.length) { + height = path.length + } + + return height + } + /** * Create a mutable ref for a `Path` object, which will stay in sync as new * operations are applied to the this. diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index b9458b1ca7..04eb09110e 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -67,6 +67,26 @@ class ValueQueries { }) } + /** + * Iterate through all of the elements in the editor. + */ + + *elements( + this: Editor, + options: { + at?: Path | Range + reverse?: boolean + pass?: (entry: ElementEntry) => boolean + } = {} + ): Iterable { + const { pass = () => false } = options + yield* Node.elements(this.value, { + ...options, + pass: ([n, p]) => + Element.isElement(n) && (this.isVoid(n) || pass([n, p])), + }) + } + /** * Iterate through all of the nodes in the editor. */ diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index 2ae88a3bb0..8a0ded5fe3 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -15,6 +15,22 @@ interface Range { } namespace Range { + export const intersection = (range: Range, another: Range): Range => { + if (!Range.includes(range, another)) { + throw new Error( + `Cannot get the intersection of ranges ${JSON.stringify( + range + )} and ${JSON.stringify(another)} because they do not overlap.` + ) + } + + const [s1, e1] = Range.points(range) + const [s2, e2] = Range.points(another) + const start = Point.isBefore(s1, s2) ? s2 : s1 + const end = Point.isBefore(e1, e2) ? e1 : e2 + return { anchor: start, focus: end } + } + /** * Check if a range is exactly equal to another. */ diff --git a/packages/slate/src/plugins/schema/plugin.ts b/packages/slate/src/plugins/schema/plugin.ts index 3d86a9046d..379da23ad9 100644 --- a/packages/slate/src/plugins/schema/plugin.ts +++ b/packages/slate/src/plugins/schema/plugin.ts @@ -131,14 +131,20 @@ const SchemaPlugin = ( * valid state if it is currently invalid. */ - normalizeNodeAtPath(this: Editor, path: Path): void { - const node = Node.get(this.value, path) + normalizeNodeAtPath(this: Editor, options: { at?: Path } = {}): void { + const { at } = options + + if (!Path.isPath(at)) { + return super.normalizeNodes(options) + } + + const node = this.getNode(at) let error: SchemaError | undefined let rule: SchemaRule | undefined for (const r of rules) { if ('validate' in r) { - const e = checkNode(node, path, r.match, rules) + const e = checkNode(node, at, r.match, rules) if (e) { error = e @@ -149,7 +155,7 @@ const SchemaPlugin = ( } if (error == null) { - return super.normalizeNodeAtPath(path) + return super.normalizeNodes(options) } const prevLength = this.operations.length diff --git a/packages/slate/test/commands/insertFragment/path/end-of-target.js b/packages/slate/test/commands/insertFragment/path/end-of-target.js deleted file mode 100644 index e9e26f2b3f..0000000000 --- a/packages/slate/test/commands/insertFragment/path/end-of-target.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const input = ( - - word - -) - -export const run = editor => { - editor.insertFragmentAtPath( - [1], - - one - two - - ) -} - -export const output = ( - - word - one - two - -) diff --git a/packages/slate/test/commands/insertFragment/path/middle-of-target.js b/packages/slate/test/commands/insertFragment/path/middle-of-target.js deleted file mode 100644 index 8b583390b1..0000000000 --- a/packages/slate/test/commands/insertFragment/path/middle-of-target.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const input = ( - - word - another - -) - -export const run = editor => { - editor.insertFragmentAtPath( - [1], - - one - two - - ) -} - -export const output = ( - - word - one - two - another - -) diff --git a/packages/slate/test/commands/insertBlock/selection/block-empty.js b/packages/slate/test/commands/insertNodes/block/block-empty.js similarity index 94% rename from packages/slate/test/commands/insertBlock/selection/block-empty.js rename to packages/slate/test/commands/insertNodes/block/block-empty.js index bb6f78b091..063290895d 100644 --- a/packages/slate/test/commands/insertBlock/selection/block-empty.js +++ b/packages/slate/test/commands/insertNodes/block/block-empty.js @@ -2,14 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertBlock( - - - - ) -} - export const input = ( @@ -19,6 +11,14 @@ export const input = ( ) +export const run = editor => { + editor.insertNodes( + + + + ) +} + export const output = ( diff --git a/packages/slate/test/commands/insertBlock/selection/block-end.js b/packages/slate/test/commands/insertNodes/block/block-end.js similarity index 93% rename from packages/slate/test/commands/insertBlock/selection/block-end.js rename to packages/slate/test/commands/insertNodes/block/block-end.js index 8c229a4444..1ddb93b9db 100644 --- a/packages/slate/test/commands/insertBlock/selection/block-end.js +++ b/packages/slate/test/commands/insertNodes/block/block-end.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - editor.insertBlock( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertBlock/selection/block-middle.js b/packages/slate/test/commands/insertNodes/block/block-middle.js similarity index 94% rename from packages/slate/test/commands/insertBlock/selection/block-middle.js rename to packages/slate/test/commands/insertNodes/block/block-middle.js index 1a9ae5b49b..9a808a287d 100644 --- a/packages/slate/test/commands/insertBlock/selection/block-middle.js +++ b/packages/slate/test/commands/insertNodes/block/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertBlock( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertBlock/selection/block-start.js b/packages/slate/test/commands/insertNodes/block/block-start.js similarity index 93% rename from packages/slate/test/commands/insertBlock/selection/block-start.js rename to packages/slate/test/commands/insertNodes/block/block-start.js index 84e47f5137..c33d1588a7 100644 --- a/packages/slate/test/commands/insertBlock/selection/block-start.js +++ b/packages/slate/test/commands/insertNodes/block/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertBlock( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertBlock/selection/block-void.js b/packages/slate/test/commands/insertNodes/block/block-void.js similarity index 95% rename from packages/slate/test/commands/insertBlock/selection/block-void.js rename to packages/slate/test/commands/insertNodes/block/block-void.js index 2f9d45c709..f5136ebf34 100644 --- a/packages/slate/test/commands/insertBlock/selection/block-void.js +++ b/packages/slate/test/commands/insertNodes/block/block-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertBlock( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertBlock/selection/inline-void.js b/packages/slate/test/commands/insertNodes/block/inline-void.js similarity index 96% rename from packages/slate/test/commands/insertBlock/selection/inline-void.js rename to packages/slate/test/commands/insertNodes/block/inline-void.js index 0d58c40165..e22a2ea8bd 100644 --- a/packages/slate/test/commands/insertBlock/selection/inline-void.js +++ b/packages/slate/test/commands/insertNodes/block/inline-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertBlock( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertInline/selection/block-empty.js b/packages/slate/test/commands/insertNodes/inline/block-empty.js similarity index 94% rename from packages/slate/test/commands/insertInline/selection/block-empty.js rename to packages/slate/test/commands/insertNodes/inline/block-empty.js index 853c17fe5f..860efbaad7 100644 --- a/packages/slate/test/commands/insertInline/selection/block-empty.js +++ b/packages/slate/test/commands/insertNodes/inline/block-empty.js @@ -2,14 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.insertInline( - - - - ) -} - export const input = ( @@ -18,6 +10,14 @@ export const input = ( ) +export const run = editor => { + editor.insertNodes( + + + + ) +} + export const output = ( diff --git a/packages/slate/test/commands/insertInline/selection/block-end.js b/packages/slate/test/commands/insertNodes/inline/block-end.js similarity index 94% rename from packages/slate/test/commands/insertInline/selection/block-end.js rename to packages/slate/test/commands/insertNodes/inline/block-end.js index 747dd78629..2d459a88d5 100644 --- a/packages/slate/test/commands/insertInline/selection/block-end.js +++ b/packages/slate/test/commands/insertNodes/inline/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertInline/selection/block-middle.js b/packages/slate/test/commands/insertNodes/inline/block-middle.js similarity index 94% rename from packages/slate/test/commands/insertInline/selection/block-middle.js rename to packages/slate/test/commands/insertNodes/inline/block-middle.js index dd2df8901c..d05bb87b03 100644 --- a/packages/slate/test/commands/insertInline/selection/block-middle.js +++ b/packages/slate/test/commands/insertNodes/inline/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertInline/selection/block-start.js b/packages/slate/test/commands/insertNodes/inline/block-start.js similarity index 94% rename from packages/slate/test/commands/insertInline/selection/block-start.js rename to packages/slate/test/commands/insertNodes/inline/block-start.js index ec5da366b0..95e01302fe 100644 --- a/packages/slate/test/commands/insertInline/selection/block-start.js +++ b/packages/slate/test/commands/insertNodes/inline/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertInline/selection/block-void.js b/packages/slate/test/commands/insertNodes/inline/block-void.js similarity index 93% rename from packages/slate/test/commands/insertInline/selection/block-void.js rename to packages/slate/test/commands/insertNodes/inline/block-void.js index aa8f8adbf6..21138b1c30 100644 --- a/packages/slate/test/commands/insertInline/selection/block-void.js +++ b/packages/slate/test/commands/insertNodes/inline/block-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline( + editor.insertNodes( diff --git a/packages/slate/test/commands/insertInline/selection/inline-middle.js b/packages/slate/test/commands/insertNodes/inline/inline-middle.js similarity index 74% rename from packages/slate/test/commands/insertInline/selection/inline-middle.js rename to packages/slate/test/commands/insertNodes/inline/inline-middle.js index 6dd2ada8dc..b263a73692 100644 --- a/packages/slate/test/commands/insertInline/selection/inline-middle.js +++ b/packages/slate/test/commands/insertNodes/inline/inline-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertInline( + editor.insertNodes( @@ -26,14 +26,14 @@ export const output = ( - - wo - - - - rd + wo + + + + rd + ) diff --git a/packages/slate/test/commands/insertNode/path/block.js b/packages/slate/test/commands/insertNodes/path/block.js similarity index 86% rename from packages/slate/test/commands/insertNode/path/block.js rename to packages/slate/test/commands/insertNodes/path/block.js index d11e6b73b9..970e750a8f 100644 --- a/packages/slate/test/commands/insertNode/path/block.js +++ b/packages/slate/test/commands/insertNodes/path/block.js @@ -11,11 +11,11 @@ export const input = ( ) export const run = editor => { - editor.insertNodeAtPath( - [0], + editor.insertNodes( - + , + { at: [0] } ) } diff --git a/packages/slate/test/commands/insertNode/path/inline.js b/packages/slate/test/commands/insertNodes/path/inline.js similarity index 86% rename from packages/slate/test/commands/insertNode/path/inline.js rename to packages/slate/test/commands/insertNodes/path/inline.js index 2da3af6f30..8318e7040f 100644 --- a/packages/slate/test/commands/insertNode/path/inline.js +++ b/packages/slate/test/commands/insertNodes/path/inline.js @@ -11,11 +11,11 @@ export const input = ( ) export const run = editor => { - editor.insertNodeAtPath( - [0, 0], + editor.insertNodes( - + , + { at: [0, 0] } ) } diff --git a/packages/slate/test/commands/insertNodes/path/multiple.js b/packages/slate/test/commands/insertNodes/path/multiple.js new file mode 100644 index 0000000000..1fc55ce6ef --- /dev/null +++ b/packages/slate/test/commands/insertNodes/path/multiple.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + editor.insertNodes([two, three], { at: [0] }) +} + +export const output = ( + + two + three + + one + + +) diff --git a/packages/slate/test/commands/insertNode/path/text.js b/packages/slate/test/commands/insertNodes/path/text.js similarity index 82% rename from packages/slate/test/commands/insertNode/path/text.js rename to packages/slate/test/commands/insertNodes/path/text.js index f04bc06e6a..898df4be23 100644 --- a/packages/slate/test/commands/insertNode/path/text.js +++ b/packages/slate/test/commands/insertNodes/path/text.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - editor.insertNodeAtPath([0, 0], another) + editor.insertNodes(another, { at: [0, 0] }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/range/expanded-with-mark.js b/packages/slate/test/commands/insertText/range/expanded-with-mark.js index c019573790..f9ad312899 100644 --- a/packages/slate/test/commands/insertText/range/expanded-with-mark.js +++ b/packages/slate/test/commands/insertText/range/expanded-with-mark.js @@ -3,11 +3,8 @@ import { h } from '../../../helpers' export const run = editor => { - debugger editor.insertText('a') - debugger editor.insertText('b') - debugger } export const input = ( diff --git a/packages/slate/test/commands/pluckNode/path/block.js b/packages/slate/test/commands/liftNodes/path/block.js similarity index 87% rename from packages/slate/test/commands/pluckNode/path/block.js rename to packages/slate/test/commands/liftNodes/path/block.js index d5e20a3f40..0079731c4f 100644 --- a/packages/slate/test/commands/pluckNode/path/block.js +++ b/packages/slate/test/commands/liftNodes/path/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodeAtPath([0]) + editor.liftNodes({ at: [0, 0] }) } export const input = ( diff --git a/packages/slate/test/commands/liftNode/path/first-block.js b/packages/slate/test/commands/liftNodes/path/first-block.js similarity index 90% rename from packages/slate/test/commands/liftNode/path/first-block.js rename to packages/slate/test/commands/liftNodes/path/first-block.js index 14ce4347e7..3384075cfd 100644 --- a/packages/slate/test/commands/liftNode/path/first-block.js +++ b/packages/slate/test/commands/liftNodes/path/first-block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.liftNodeAtPath([0, 0]) + editor.liftNodes({ at: [0, 0] }) } export const input = ( diff --git a/packages/slate/test/commands/liftNode/path/last-block.js b/packages/slate/test/commands/liftNodes/path/last-block.js similarity index 90% rename from packages/slate/test/commands/liftNode/path/last-block.js rename to packages/slate/test/commands/liftNodes/path/last-block.js index e7de9be845..e7738e9a60 100644 --- a/packages/slate/test/commands/liftNode/path/last-block.js +++ b/packages/slate/test/commands/liftNodes/path/last-block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.liftNodeAtPath([0, 1]) + editor.liftNodes({ at: [0, 1] }) } export const input = ( diff --git a/packages/slate/test/commands/liftNode/path/middle-block.js b/packages/slate/test/commands/liftNodes/path/middle-block.js similarity index 92% rename from packages/slate/test/commands/liftNode/path/middle-block.js rename to packages/slate/test/commands/liftNodes/path/middle-block.js index 9b8291c5fd..c8aa35377a 100644 --- a/packages/slate/test/commands/liftNode/path/middle-block.js +++ b/packages/slate/test/commands/liftNodes/path/middle-block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.liftNodeAtPath([0, 1]) + editor.liftNodes({ at: [0, 1] }) } export const input = ( diff --git a/packages/slate/test/commands/mergeNode/path/block.js b/packages/slate/test/commands/mergeNodes/path/block.js similarity index 100% rename from packages/slate/test/commands/mergeNode/path/block.js rename to packages/slate/test/commands/mergeNodes/path/block.js diff --git a/packages/slate/test/commands/moveNode/path/block.js b/packages/slate/test/commands/moveNodes/path/block.js similarity index 88% rename from packages/slate/test/commands/moveNode/path/block.js rename to packages/slate/test/commands/moveNodes/path/block.js index fd81dcac9f..91d7de806b 100644 --- a/packages/slate/test/commands/moveNode/path/block.js +++ b/packages/slate/test/commands/moveNodes/path/block.js @@ -12,7 +12,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([0], [1]) + editor.moveNodes({ at: [0], to: [1] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/inline.js b/packages/slate/test/commands/moveNodes/path/inline.js similarity index 91% rename from packages/slate/test/commands/moveNode/path/inline.js rename to packages/slate/test/commands/moveNodes/path/inline.js index 8ffc2a7592..1f059b1224 100644 --- a/packages/slate/test/commands/moveNode/path/inline.js +++ b/packages/slate/test/commands/moveNodes/path/inline.js @@ -17,7 +17,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([0, 1], [0, 3]) + editor.moveNodes({ at: [0, 1], to: [0, 3] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/inside-next.js b/packages/slate/test/commands/moveNodes/path/inside-next.js similarity index 89% rename from packages/slate/test/commands/moveNode/path/inside-next.js rename to packages/slate/test/commands/moveNodes/path/inside-next.js index 27f7038001..1106a850cd 100644 --- a/packages/slate/test/commands/moveNode/path/inside-next.js +++ b/packages/slate/test/commands/moveNodes/path/inside-next.js @@ -14,7 +14,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([0], [1, 1]) + editor.moveNodes({ at: [0], to: [1, 1] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/nested.js b/packages/slate/test/commands/moveNodes/path/nested.js similarity index 89% rename from packages/slate/test/commands/moveNode/path/nested.js rename to packages/slate/test/commands/moveNodes/path/nested.js index 17c7e814f6..786a17f1e0 100644 --- a/packages/slate/test/commands/moveNode/path/nested.js +++ b/packages/slate/test/commands/moveNodes/path/nested.js @@ -14,7 +14,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([0, 0], [1, 0]) + editor.moveNodes({ at: [0, 0], to: [1, 0] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/noop-equal.js b/packages/slate/test/commands/moveNodes/path/noop-equal.js similarity index 86% rename from packages/slate/test/commands/moveNode/path/noop-equal.js rename to packages/slate/test/commands/moveNodes/path/noop-equal.js index 406cc269e7..fc86e7e7c4 100644 --- a/packages/slate/test/commands/moveNode/path/noop-equal.js +++ b/packages/slate/test/commands/moveNodes/path/noop-equal.js @@ -10,7 +10,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([1], [1]) + editor.moveNodes({ at: [1], to: [1] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/sibling-swap.js b/packages/slate/test/commands/moveNodes/path/sibling-swap.js similarity index 88% rename from packages/slate/test/commands/moveNode/path/sibling-swap.js rename to packages/slate/test/commands/moveNodes/path/sibling-swap.js index fd81dcac9f..91d7de806b 100644 --- a/packages/slate/test/commands/moveNode/path/sibling-swap.js +++ b/packages/slate/test/commands/moveNodes/path/sibling-swap.js @@ -12,7 +12,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([0], [1]) + editor.moveNodes({ at: [0], to: [1] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/text-nodes.js b/packages/slate/test/commands/moveNodes/path/text-nodes.js similarity index 87% rename from packages/slate/test/commands/moveNode/path/text-nodes.js rename to packages/slate/test/commands/moveNodes/path/text-nodes.js index 1f4e009ba0..34c757620b 100644 --- a/packages/slate/test/commands/moveNode/path/text-nodes.js +++ b/packages/slate/test/commands/moveNodes/path/text-nodes.js @@ -12,7 +12,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([0, 0], [1, 0]) + editor.moveNodes({ at: [0, 0], to: [1, 0] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/text.js b/packages/slate/test/commands/moveNodes/path/text.js similarity index 86% rename from packages/slate/test/commands/moveNode/path/text.js rename to packages/slate/test/commands/moveNodes/path/text.js index 257d0268ba..b00aca1812 100644 --- a/packages/slate/test/commands/moveNode/path/text.js +++ b/packages/slate/test/commands/moveNodes/path/text.js @@ -10,7 +10,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([1, 0], [0, 1]) + editor.moveNodes({ at: [1, 0], to: [0, 1] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNode/path/to-sibling.js b/packages/slate/test/commands/moveNodes/path/to-sibling.js similarity index 89% rename from packages/slate/test/commands/moveNode/path/to-sibling.js rename to packages/slate/test/commands/moveNodes/path/to-sibling.js index 27f7038001..1106a850cd 100644 --- a/packages/slate/test/commands/moveNode/path/to-sibling.js +++ b/packages/slate/test/commands/moveNodes/path/to-sibling.js @@ -14,7 +14,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodeAtPath([0], [1, 1]) + editor.moveNodes({ at: [0], to: [1, 1] }) } export const output = ( diff --git a/packages/slate/test/commands/moveNodes/selection/block.js b/packages/slate/test/commands/moveNodes/selection/block.js new file mode 100644 index 0000000000..ce4046c7c7 --- /dev/null +++ b/packages/slate/test/commands/moveNodes/selection/block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + two + +) + +export const run = editor => { + editor.moveNodes({ depth: 1, to: [1] }) +} + +export const output = ( + + two + + one + + +) diff --git a/packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks.js b/packages/slate/test/commands/pluckNodes/match-block/block-across.js similarity index 62% rename from packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks.js rename to packages/slate/test/commands/pluckNodes/match-block/block-across.js index ff47735161..f52892385a 100644 --- a/packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks.js +++ b/packages/slate/test/commands/pluckNodes/match-block/block-across.js @@ -3,29 +3,29 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock() + editor.pluckNodes({ match: { key: 'a' } }) } export const input = ( - + word another - + ) export const output = ( - - wo - - other - - + + word + + + another + ) diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-end.js b/packages/slate/test/commands/pluckNodes/match-block/block-end.js new file mode 100644 index 0000000000..3ab2401097 --- /dev/null +++ b/packages/slate/test/commands/pluckNodes/match-block/block-end.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.pluckNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + one + two + three + four + + five + + + six + + + +) + +export const output = ( + + one + two + three + four + + five + + + six + + +) diff --git a/packages/slate/test/commands/splitInline/selection/height.js b/packages/slate/test/commands/pluckNodes/match-block/block-inline.js similarity index 67% rename from packages/slate/test/commands/splitInline/selection/height.js rename to packages/slate/test/commands/pluckNodes/match-block/block-inline.js index 2de3042a51..b3d99ffff1 100644 --- a/packages/slate/test/commands/splitInline/selection/height.js +++ b/packages/slate/test/commands/pluckNodes/match-block/block-inline.js @@ -3,21 +3,26 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInline({ height: 1 }) + editor.pluckNodes({ match: { key: 'a' } }) } export const input = ( - - - + + - word + word - - + + + + + another + + + ) @@ -27,17 +32,14 @@ export const output = ( - - wo - + word + + + - - - rd - - + another diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-middle.js b/packages/slate/test/commands/pluckNodes/match-block/block-middle.js new file mode 100644 index 0000000000..aa73590f5a --- /dev/null +++ b/packages/slate/test/commands/pluckNodes/match-block/block-middle.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.pluckNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + one + two + + three + + + four + + five + six + + +) + +export const output = ( + + one + two + + three + + + four + + five + six + +) diff --git a/packages/slate/test/commands/unwrapBlock/selection/single-block.js b/packages/slate/test/commands/pluckNodes/match-block/block-nested.js similarity index 75% rename from packages/slate/test/commands/unwrapBlock/selection/single-block.js rename to packages/slate/test/commands/pluckNodes/match-block/block-nested.js index e8d1a3bcdc..fb3a605d5b 100644 --- a/packages/slate/test/commands/unwrapBlock/selection/single-block.js +++ b/packages/slate/test/commands/pluckNodes/match-block/block-nested.js @@ -3,27 +3,27 @@ import { h } from '../../../helpers' export const run = editor => { - editor.unwrapBlock('quote') + editor.pluckNodes({ match: { key: 'a' } }) } export const input = ( - + word - + ) export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-start.js b/packages/slate/test/commands/pluckNodes/match-block/block-start.js new file mode 100644 index 0000000000..48445e6f84 --- /dev/null +++ b/packages/slate/test/commands/pluckNodes/match-block/block-start.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.pluckNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + + one + + + two + + three + four + five + six + + +) + +export const output = ( + + + one + + + two + + three + four + five + six + +) diff --git a/packages/slate/test/commands/setBlocks/selection/with-is-void.js b/packages/slate/test/commands/pluckNodes/match-block/block.js similarity index 65% rename from packages/slate/test/commands/setBlocks/selection/with-is-void.js rename to packages/slate/test/commands/pluckNodes/match-block/block.js index 58cccfabaf..f97887fdb5 100644 --- a/packages/slate/test/commands/setBlocks/selection/with-is-void.js +++ b/packages/slate/test/commands/pluckNodes/match-block/block.js @@ -3,25 +3,23 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks('image') + editor.pluckNodes({ match: { key: 'a' } }) } export const input = ( - + word - + ) export const output = ( - - - word - - + + word + ) diff --git a/packages/slate/test/commands/unwrapInline/selection/single-block.js b/packages/slate/test/commands/pluckNodes/match-inline/block-nested.js similarity index 67% rename from packages/slate/test/commands/unwrapInline/selection/single-block.js rename to packages/slate/test/commands/pluckNodes/match-inline/block-nested.js index 83e48cdaa6..85ae37fa8b 100644 --- a/packages/slate/test/commands/unwrapInline/selection/single-block.js +++ b/packages/slate/test/commands/pluckNodes/match-inline/block-nested.js @@ -3,28 +3,29 @@ import { h } from '../../../helpers' export const run = editor => { - editor.unwrapInline('hashtag') + editor.pluckNodes({ match: { key: 'a' } }) } export const input = ( - + w - + or - d + + d - + ) export const output = ( - + word - + ) diff --git a/packages/slate/test/commands/pluckNodes/match-inline/inline-across.js b/packages/slate/test/commands/pluckNodes/match-inline/inline-across.js new file mode 100644 index 0000000000..c297e0af15 --- /dev/null +++ b/packages/slate/test/commands/pluckNodes/match-inline/inline-across.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.pluckNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + + + one + + two + + three + + + + +) + +export const output = ( + + + onetwothree + + +) diff --git a/packages/slate/test/commands/unwrapInline/selection/across-blocks.js b/packages/slate/test/commands/pluckNodes/match-inline/inline-over.js similarity index 63% rename from packages/slate/test/commands/unwrapInline/selection/across-blocks.js rename to packages/slate/test/commands/pluckNodes/match-inline/inline-over.js index 874dc7eb0e..89439be89e 100644 --- a/packages/slate/test/commands/unwrapInline/selection/across-blocks.js +++ b/packages/slate/test/commands/pluckNodes/match-inline/inline-over.js @@ -3,16 +3,20 @@ import { h } from '../../../helpers' export const run = editor => { - editor.unwrapInline('hashtag') + editor.pluckNodes({ match: { key: 'a' } }) } export const input = ( - word + wo + rd + - another + + an + other ) diff --git a/packages/slate/test/commands/unwrapInline/selection/only-one.js b/packages/slate/test/commands/pluckNodes/match-inline/inline.js similarity index 62% rename from packages/slate/test/commands/unwrapInline/selection/only-one.js rename to packages/slate/test/commands/pluckNodes/match-inline/inline.js index 18cec822c5..789497999b 100644 --- a/packages/slate/test/commands/unwrapInline/selection/only-one.js +++ b/packages/slate/test/commands/pluckNodes/match-inline/inline.js @@ -3,15 +3,17 @@ import { h } from '../../../helpers' export const run = editor => { - editor.unwrapInline('hashtag') + editor.pluckNodes({ match: { key: 'a' } }) } export const input = ( - hello w + w + or - d + + d ) @@ -19,7 +21,7 @@ export const input = ( export const output = ( - hello word + word ) diff --git a/packages/slate/test/commands/pluckNode/path/block-multiple.js b/packages/slate/test/commands/pluckNodes/path/block-multiple.js similarity index 90% rename from packages/slate/test/commands/pluckNode/path/block-multiple.js rename to packages/slate/test/commands/pluckNodes/path/block-multiple.js index 223d8f6445..1d966873ee 100644 --- a/packages/slate/test/commands/pluckNode/path/block-multiple.js +++ b/packages/slate/test/commands/pluckNodes/path/block-multiple.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodeAtPath([0]) + editor.pluckNodes({ at: [0] }) } export const input = ( diff --git a/packages/slate/test/commands/liftNode/path/block.js b/packages/slate/test/commands/pluckNodes/path/block.js similarity index 88% rename from packages/slate/test/commands/liftNode/path/block.js rename to packages/slate/test/commands/pluckNodes/path/block.js index 83a42d6fe2..1f39f29e59 100644 --- a/packages/slate/test/commands/liftNode/path/block.js +++ b/packages/slate/test/commands/pluckNodes/path/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.liftNodeAtPath([0, 0]) + editor.pluckNodes({ at: [0] }) } export const input = ( diff --git a/packages/slate/test/commands/setBlocks/selection/data-only.js b/packages/slate/test/commands/setBlocks/selection/data-only.js deleted file mode 100644 index a7b7ce5ae5..0000000000 --- a/packages/slate/test/commands/setBlocks/selection/data-only.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -import { Data } from 'slate' - -export const run = editor => { - editor.setBlocks({ data: Data.create({ thing: 'value' }) }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/setInlines/selection/across-inlines.js b/packages/slate/test/commands/setInlines/selection/across-inlines.js deleted file mode 100644 index d12f645410..0000000000 --- a/packages/slate/test/commands/setInlines/selection/across-inlines.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.setInlines({ type: 'hashtag' }) -} - -export const input = ( - - - - - word - - - - - another - - - - -) - -export const output = ( - - - - - word - - - - - another - - - - -) diff --git a/packages/slate/test/commands/setInlines/selection/data-only.js b/packages/slate/test/commands/setInlines/selection/data-only.js deleted file mode 100644 index d25a5e44cf..0000000000 --- a/packages/slate/test/commands/setInlines/selection/data-only.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Data } from 'slate' - -export const run = editor => { - editor.setInlines({ data: Data.create({ thing: 'value' }) }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/setInlines/selection/single-inline-string-shorthand.js b/packages/slate/test/commands/setInlines/selection/single-inline-string-shorthand.js deleted file mode 100644 index afb841d6eb..0000000000 --- a/packages/slate/test/commands/setInlines/selection/single-inline-string-shorthand.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.setInlines('hashtag') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/setInlines/selection/single-inline.js b/packages/slate/test/commands/setInlines/selection/single-inline.js deleted file mode 100644 index b7b590f9d4..0000000000 --- a/packages/slate/test/commands/setInlines/selection/single-inline.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.setInlines({ type: 'hashtag' }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/setInlines/selection/with-data-object.js b/packages/slate/test/commands/setInlines/selection/with-data-object.js deleted file mode 100644 index fd94671152..0000000000 --- a/packages/slate/test/commands/setInlines/selection/with-data-object.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.setInlines({ - type: 'hashtag', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/setInlines/selection/with-data.js b/packages/slate/test/commands/setInlines/selection/with-data.js deleted file mode 100644 index 5f2c08cedb..0000000000 --- a/packages/slate/test/commands/setInlines/selection/with-data.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' -import { Data } from 'slate' - -export const run = editor => { - editor.setInlines({ - type: 'hashtag', - data: Data.create({ thing: 'value' }), - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/setBlocks/selection/across-blocks.js b/packages/slate/test/commands/setNodes/block/block-across.js similarity index 67% rename from packages/slate/test/commands/setBlocks/selection/across-blocks.js rename to packages/slate/test/commands/setNodes/block/block-across.js index 019ed31030..9244df2cf8 100644 --- a/packages/slate/test/commands/setBlocks/selection/across-blocks.js +++ b/packages/slate/test/commands/setNodes/block/block-across.js @@ -3,31 +3,27 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks({ type: 'code' }) + editor.setNodes({ thing: true }, { match: 'block' }) } export const input = ( - word - + another - - + ) export const output = ( - - + word - - + + another - - + ) diff --git a/packages/slate/test/commands/setBlocks/selection/hanging-selection.js b/packages/slate/test/commands/setNodes/block/block-hanging.js similarity index 70% rename from packages/slate/test/commands/setBlocks/selection/hanging-selection.js rename to packages/slate/test/commands/setNodes/block/block-hanging.js index cbb890927f..1a262fb624 100644 --- a/packages/slate/test/commands/setBlocks/selection/hanging-selection.js +++ b/packages/slate/test/commands/setNodes/block/block-hanging.js @@ -3,31 +3,27 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks({ type: 'code' }) + editor.setNodes({ thing: true }, { match: 'block' }) } export const input = ( - word - + another - - + ) export const output = ( - - + word - + another - - + ) diff --git a/packages/slate/test/commands/setBlocks/selection/nested-block.js b/packages/slate/test/commands/setNodes/block/block-nested.js similarity index 69% rename from packages/slate/test/commands/setBlocks/selection/nested-block.js rename to packages/slate/test/commands/setNodes/block/block-nested.js index 91a10275bc..9511a1390d 100644 --- a/packages/slate/test/commands/setBlocks/selection/nested-block.js +++ b/packages/slate/test/commands/setNodes/block/block-nested.js @@ -3,29 +3,25 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks({ type: 'code' }) + editor.setNodes({ thing: true }, { match: 'block' }) } export const input = ( - word - + - ) export const output = ( - - - + + word - + - ) diff --git a/packages/slate/test/commands/setBlocks/selection/single-block-string-shorthand.js b/packages/slate/test/commands/setNodes/block/block-void.js similarity index 64% rename from packages/slate/test/commands/setBlocks/selection/single-block-string-shorthand.js rename to packages/slate/test/commands/setNodes/block/block-void.js index bff9cf2aba..acfaf40969 100644 --- a/packages/slate/test/commands/setBlocks/selection/single-block-string-shorthand.js +++ b/packages/slate/test/commands/setNodes/block/block-void.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks('code') + editor.setNodes({ thing: true }, { match: 'block' }) } export const input = ( - - + word - - + ) export const output = ( - - + word - - + ) diff --git a/packages/slate/test/commands/setBlocks/selection/single-block.js b/packages/slate/test/commands/setNodes/block/block.js similarity index 70% rename from packages/slate/test/commands/setBlocks/selection/single-block.js rename to packages/slate/test/commands/setNodes/block/block.js index 85f2af1857..3a017b9725 100644 --- a/packages/slate/test/commands/setBlocks/selection/single-block.js +++ b/packages/slate/test/commands/setNodes/block/block.js @@ -3,25 +3,21 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks({ type: 'code' }) + editor.setNodes({ thing: true }, { match: 'block' }) } export const input = ( - word - - + ) export const output = ( - - + word - - + ) diff --git a/packages/slate/test/commands/setBlocks/selection/across-inlines.js b/packages/slate/test/commands/setNodes/inline/inline-across.js similarity index 68% rename from packages/slate/test/commands/setBlocks/selection/across-inlines.js rename to packages/slate/test/commands/setNodes/inline/inline-across.js index d0e177aae9..af94c0aef7 100644 --- a/packages/slate/test/commands/setBlocks/selection/across-inlines.js +++ b/packages/slate/test/commands/setNodes/inline/inline-across.js @@ -3,20 +3,24 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks({ type: 'code' }) + editor.setNodes({ thing: true }, { match: 'inline' }) } export const input = ( + word + + another + ) @@ -24,14 +28,18 @@ export const input = ( export const output = ( - + + word + - + + another + ) diff --git a/packages/slate/test/commands/setBlocks/selection/hanging-selection-across-inlines.js b/packages/slate/test/commands/setNodes/inline/inline-hanging.js similarity index 71% rename from packages/slate/test/commands/setBlocks/selection/hanging-selection-across-inlines.js rename to packages/slate/test/commands/setNodes/inline/inline-hanging.js index 95b5609fbb..c4e6eb658b 100644 --- a/packages/slate/test/commands/setBlocks/selection/hanging-selection-across-inlines.js +++ b/packages/slate/test/commands/setNodes/inline/inline-hanging.js @@ -3,20 +3,24 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setBlocks({ type: 'code' }) + editor.setNodes({ thing: true }, { match: 'inline' }) } export const input = ( + word + + another + ) @@ -24,14 +28,18 @@ export const input = ( export const output = ( - + + word + + another + ) diff --git a/packages/slate/test/commands/setInlines/selection/nested-inline.js b/packages/slate/test/commands/setNodes/inline/inline-nested.js similarity index 56% rename from packages/slate/test/commands/setInlines/selection/nested-inline.js rename to packages/slate/test/commands/setNodes/inline/inline-nested.js index 70bc04eb39..2bff8839e5 100644 --- a/packages/slate/test/commands/setInlines/selection/nested-inline.js +++ b/packages/slate/test/commands/setNodes/inline/inline-nested.js @@ -3,33 +3,37 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setInlines({ type: 'comment' }) + editor.setNodes({ thing: true }, { match: 'inline' }) } export const input = ( - + + word - + + + - ) export const output = ( - - - + + + + word - + + + - ) diff --git a/packages/slate/test/commands/setNodes/inline/inline-void.js b/packages/slate/test/commands/setNodes/inline/inline-void.js new file mode 100644 index 0000000000..4d910c231d --- /dev/null +++ b/packages/slate/test/commands/setNodes/inline/inline-void.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setNodes({ thing: true }, { match: 'inline' }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/setInlines/selection/with-is-void.js b/packages/slate/test/commands/setNodes/inline/inline.js similarity index 70% rename from packages/slate/test/commands/setInlines/selection/with-is-void.js rename to packages/slate/test/commands/setNodes/inline/inline.js index 5e1f205e33..8c9aacd166 100644 --- a/packages/slate/test/commands/setInlines/selection/with-is-void.js +++ b/packages/slate/test/commands/setNodes/inline/inline.js @@ -3,15 +3,17 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setInlines('emoji') + editor.setNodes({ thing: true }, { match: 'inline' }) } export const input = ( + word + ) @@ -19,9 +21,11 @@ export const input = ( export const output = ( - + + word + ) diff --git a/packages/slate/test/commands/setNode/path/block.js b/packages/slate/test/commands/setNodes/path/block.js similarity index 84% rename from packages/slate/test/commands/setNode/path/block.js rename to packages/slate/test/commands/setNodes/path/block.js index 41172492c2..601588e7a8 100644 --- a/packages/slate/test/commands/setNode/path/block.js +++ b/packages/slate/test/commands/setNodes/path/block.js @@ -2,16 +2,16 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.setNodeAtPath([0], { key: 'a' }) -} - export const input = ( word ) +export const run = editor => { + editor.setNodes({ key: 'a' }, { at: [0] }) +} + export const output = ( word diff --git a/packages/slate/test/commands/setNode/path/inline.js b/packages/slate/test/commands/setNodes/path/inline.js similarity index 88% rename from packages/slate/test/commands/setNode/path/inline.js rename to packages/slate/test/commands/setNodes/path/inline.js index 75584eca64..df95b7da05 100644 --- a/packages/slate/test/commands/setNode/path/inline.js +++ b/packages/slate/test/commands/setNodes/path/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodeAtPath([0, 1], { key: 'a' }) + editor.setNodes({ key: 'a' }, { at: [0, 1] }) } export const input = ( diff --git a/packages/slate/test/commands/setNode/path/text.js b/packages/slate/test/commands/setNodes/path/text.js similarity index 84% rename from packages/slate/test/commands/setNode/path/text.js rename to packages/slate/test/commands/setNodes/path/text.js index 9c68fec96d..a9489c30a9 100644 --- a/packages/slate/test/commands/setNode/path/text.js +++ b/packages/slate/test/commands/setNodes/path/text.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodeAtPath([0, 0], { key: 'a' }) + editor.setNodes({ key: 'a' }, { at: [0, 0] }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/selection/block-end.js b/packages/slate/test/commands/splitBlock/selection/block-end.js deleted file mode 100644 index df246e0abf..0000000000 --- a/packages/slate/test/commands/splitBlock/selection/block-end.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitBlock() -} - -export const input = ( - - - - word - - another - - -) - -export const output = ( - - - word - - - - another - - -) diff --git a/packages/slate/test/commands/splitBlock/selection/block-middle.js b/packages/slate/test/commands/splitBlock/selection/block-middle.js deleted file mode 100644 index 8806453cfe..0000000000 --- a/packages/slate/test/commands/splitBlock/selection/block-middle.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitBlock() -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - wo - - rd - - - -) diff --git a/packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks-and-inlines.js deleted file mode 100644 index 0032e9fa6b..0000000000 --- a/packages/slate/test/commands/splitBlock/selection/with-delete-across-blocks-and-inlines.js +++ /dev/null @@ -1,51 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitBlock() -} - -export const input = ( - - - - - - word - - - - - - - another - - - - - -) - -export const output = ( - - - - - wo - - - - - - - - - - other - - - - - -) diff --git a/packages/slate/test/commands/splitBlock/selection/with-delete.js b/packages/slate/test/commands/splitBlock/selection/with-delete.js deleted file mode 100644 index 38e280d8a1..0000000000 --- a/packages/slate/test/commands/splitBlock/selection/with-delete.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitBlock() -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - w - - d - - - -) diff --git a/packages/slate/test/commands/splitNode/point/selection.js b/packages/slate/test/commands/splitNode/point/selection.js deleted file mode 100644 index 79d4226bab..0000000000 --- a/packages/slate/test/commands/splitNode/point/selection.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitNodeAtPoint({ path: [0, 0], offset: 2 }, { height: 1 }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - wo - - - rd - - -) diff --git a/packages/slate/test/commands/splitBlock/selection/after-inline-void.js b/packages/slate/test/commands/splitNodes/height-block/after-inline-void.js similarity index 91% rename from packages/slate/test/commands/splitBlock/selection/after-inline-void.js rename to packages/slate/test/commands/splitNodes/height-block/after-inline-void.js index fbb471a4a3..16804ae59b 100644 --- a/packages/slate/test/commands/splitBlock/selection/after-inline-void.js +++ b/packages/slate/test/commands/splitNodes/height-block/after-inline-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock() + editor.splitNodes({ height: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/selection/after-inline.js b/packages/slate/test/commands/splitNodes/height-block/after-inline.js similarity index 90% rename from packages/slate/test/commands/splitBlock/selection/after-inline.js rename to packages/slate/test/commands/splitNodes/height-block/after-inline.js index c882df2cdd..3bbfd99081 100644 --- a/packages/slate/test/commands/splitBlock/selection/after-inline.js +++ b/packages/slate/test/commands/splitNodes/height-block/after-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock() + editor.splitNodes({ height: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/selection/before-inline.js b/packages/slate/test/commands/splitNodes/height-block/before-inline.js similarity index 92% rename from packages/slate/test/commands/splitBlock/selection/before-inline.js rename to packages/slate/test/commands/splitNodes/height-block/before-inline.js index e324c26ff0..29b9cb3a12 100644 --- a/packages/slate/test/commands/splitBlock/selection/before-inline.js +++ b/packages/slate/test/commands/splitNodes/height-block/before-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock() + editor.splitNodes({ height: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/block-end.js b/packages/slate/test/commands/splitNodes/height-block/block-end.js new file mode 100644 index 0000000000..9032811b9a --- /dev/null +++ b/packages/slate/test/commands/splitNodes/height-block/block-end.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ height: 'block' }) +} + +export const input = ( + + + word + + another + +) + +export const output = ( + + word + + + + another + +) diff --git a/packages/slate/test/commands/splitNodes/height-block/block-middle.js b/packages/slate/test/commands/splitNodes/height-block/block-middle.js new file mode 100644 index 0000000000..0d12abbf51 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/height-block/block-middle.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ height: 'block' }) +} + +export const input = ( + + + word + + +) + +export const output = ( + + wo + + rd + + +) diff --git a/packages/slate/test/commands/splitBlock/selection/block-start.js b/packages/slate/test/commands/splitNodes/height-block/block-start.js similarity index 89% rename from packages/slate/test/commands/splitBlock/selection/block-start.js rename to packages/slate/test/commands/splitNodes/height-block/block-start.js index 581126e9e0..b693aaba9e 100644 --- a/packages/slate/test/commands/splitBlock/selection/block-start.js +++ b/packages/slate/test/commands/splitNodes/height-block/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock() + editor.splitNodes({ height: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNode/point/block.js b/packages/slate/test/commands/splitNodes/height-block/point.js similarity index 78% rename from packages/slate/test/commands/splitNode/point/block.js rename to packages/slate/test/commands/splitNodes/height-block/point.js index 505ec92fdf..3a1e2bd1e2 100644 --- a/packages/slate/test/commands/splitNode/point/block.js +++ b/packages/slate/test/commands/splitNodes/height-block/point.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodeAtPoint({ path: [0, 0], offset: 2 }, { height: 1 }) + editor.splitNodes({ height: 'block', at: { path: [0, 0], offset: 2 } }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks-and-inlines.js new file mode 100644 index 0000000000..1aa697a204 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks-and-inlines.js @@ -0,0 +1,47 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ height: 'block' }) +} + +export const input = ( + + + + + word + + + + + + + another + + + + +) + +export const output = ( + + + + wo + + + + + + + + + + other + + + + +) diff --git a/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks.js b/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks.js new file mode 100644 index 0000000000..88d0336a1b --- /dev/null +++ b/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ height: 'block' }) +} + +export const input = ( + + + word + + + another + + +) + +export const output = ( + + wo + + other + + +) diff --git a/packages/slate/test/commands/splitBlock/selection/with-delete-hanging-selection.js b/packages/slate/test/commands/splitNodes/height-block/with-delete-hanging-selection.js similarity index 91% rename from packages/slate/test/commands/splitBlock/selection/with-delete-hanging-selection.js rename to packages/slate/test/commands/splitNodes/height-block/with-delete-hanging-selection.js index 4c030ddbd9..815a6e7ebc 100644 --- a/packages/slate/test/commands/splitBlock/selection/with-delete-hanging-selection.js +++ b/packages/slate/test/commands/splitNodes/height-block/with-delete-hanging-selection.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock() + editor.splitNodes({ height: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/with-delete.js b/packages/slate/test/commands/splitNodes/height-block/with-delete.js new file mode 100644 index 0000000000..49865053ec --- /dev/null +++ b/packages/slate/test/commands/splitNodes/height-block/with-delete.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ height: 'block' }) +} + +export const input = ( + + + word + + +) + +export const output = ( + + w + + d + + +) diff --git a/packages/slate/test/commands/splitBlock/selection/with-inline.js b/packages/slate/test/commands/splitNodes/height-block/with-inline.js similarity index 92% rename from packages/slate/test/commands/splitBlock/selection/with-inline.js rename to packages/slate/test/commands/splitNodes/height-block/with-inline.js index cb3016dd04..8fe6fb352b 100644 --- a/packages/slate/test/commands/splitBlock/selection/with-inline.js +++ b/packages/slate/test/commands/splitNodes/height-block/with-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock() + editor.splitNodes({ height: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitInline/selection/block-end.js b/packages/slate/test/commands/splitNodes/height-inline/block-end.js similarity index 91% rename from packages/slate/test/commands/splitInline/selection/block-end.js rename to packages/slate/test/commands/splitNodes/height-inline/block-end.js index 32c1b67e24..c9aebf5a5f 100644 --- a/packages/slate/test/commands/splitInline/selection/block-end.js +++ b/packages/slate/test/commands/splitNodes/height-inline/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInline() + editor.splitNodes({ height: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-inline/block-middle.js b/packages/slate/test/commands/splitNodes/height-inline/block-middle.js new file mode 100644 index 0000000000..5f4914f638 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/height-inline/block-middle.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ height: 'inline' }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + wo + + + rd + + + + +) diff --git a/packages/slate/test/commands/splitInline/selection/block-start.js b/packages/slate/test/commands/splitNodes/height-inline/block-start.js similarity index 91% rename from packages/slate/test/commands/splitInline/selection/block-start.js rename to packages/slate/test/commands/splitNodes/height-inline/block-start.js index 110e9f7ab6..6cfc4b37aa 100644 --- a/packages/slate/test/commands/splitInline/selection/block-start.js +++ b/packages/slate/test/commands/splitNodes/height-inline/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInline() + editor.splitNodes({ height: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitInline/selection/expanded.js b/packages/slate/test/commands/splitNodes/height-inline/expanded.js similarity index 91% rename from packages/slate/test/commands/splitInline/selection/expanded.js rename to packages/slate/test/commands/splitNodes/height-inline/expanded.js index 3cef877e48..114ff02972 100644 --- a/packages/slate/test/commands/splitInline/selection/expanded.js +++ b/packages/slate/test/commands/splitNodes/height-inline/expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInline() + editor.splitNodes({ height: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitInline/selection/mark.js b/packages/slate/test/commands/splitNodes/height-inline/mark.js similarity index 92% rename from packages/slate/test/commands/splitInline/selection/mark.js rename to packages/slate/test/commands/splitNodes/height-inline/mark.js index 466dcdb215..3e6d3ea9eb 100644 --- a/packages/slate/test/commands/splitInline/selection/mark.js +++ b/packages/slate/test/commands/splitNodes/height-inline/mark.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInline() + editor.splitNodes({ height: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNode/point/inline.js b/packages/slate/test/commands/splitNodes/height-inline/point.js similarity index 85% rename from packages/slate/test/commands/splitNode/point/inline.js rename to packages/slate/test/commands/splitNodes/height-inline/point.js index 085efc1380..12afb4ad90 100644 --- a/packages/slate/test/commands/splitNode/point/inline.js +++ b/packages/slate/test/commands/splitNodes/height-inline/point.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodeAtPoint({ path: [0, 1, 0], offset: 2 }, { height: 1 }) + editor.splitNodes({ height: 'inline', at: { path: [0, 1, 0], offset: 2 } }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/selection/block-depth.js b/packages/slate/test/commands/splitNodes/height/infinity.js similarity index 92% rename from packages/slate/test/commands/splitBlock/selection/block-depth.js rename to packages/slate/test/commands/splitNodes/height/infinity.js index 56d12603e1..ba1c16073e 100644 --- a/packages/slate/test/commands/splitBlock/selection/block-depth.js +++ b/packages/slate/test/commands/splitNodes/height/infinity.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock({ height: Infinity }) + editor.splitNodes({ height: Infinity }) } export const input = ( diff --git a/packages/slate/test/commands/splitInline/selection/block-middle.js b/packages/slate/test/commands/splitNodes/height/one.js similarity index 92% rename from packages/slate/test/commands/splitInline/selection/block-middle.js rename to packages/slate/test/commands/splitNodes/height/one.js index 586af6f5a8..c250928541 100644 --- a/packages/slate/test/commands/splitInline/selection/block-middle.js +++ b/packages/slate/test/commands/splitNodes/height/one.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInline() + editor.splitNodes({ height: 1 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNode/path/block.js b/packages/slate/test/commands/splitNodes/path/block-inline.js similarity index 92% rename from packages/slate/test/commands/splitNode/path/block.js rename to packages/slate/test/commands/splitNodes/path/block-inline.js index 1b2468bce1..c9e03bc125 100644 --- a/packages/slate/test/commands/splitNode/path/block.js +++ b/packages/slate/test/commands/splitNodes/path/block-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodeAtPath([0], 2) + editor.splitNodes({ at: [0, 2] }) } export const input = ( diff --git a/packages/slate/test/commands/insertFragment/path/start-of-target.js b/packages/slate/test/commands/splitNodes/path/block-nested.js similarity index 63% rename from packages/slate/test/commands/insertFragment/path/start-of-target.js rename to packages/slate/test/commands/splitNodes/path/block-nested.js index 986e29af86..ade480ad89 100644 --- a/packages/slate/test/commands/insertFragment/path/start-of-target.js +++ b/packages/slate/test/commands/splitNodes/path/block-nested.js @@ -2,30 +2,28 @@ import { h } from '../../../helpers' +export const run = editor => { + editor.splitNodes({ at: [0, 1] }) +} + export const input = ( - word + one + two + three ) -export const run = editor => { - editor.insertFragmentAtPath( - [0], - - one - two - - ) -} - export const output = ( - one - two - word + one + + + two + three ) diff --git a/packages/slate/test/commands/splitNode/path/selection.js b/packages/slate/test/commands/splitNodes/path/selection.js similarity index 94% rename from packages/slate/test/commands/splitNode/path/selection.js rename to packages/slate/test/commands/splitNodes/path/selection.js index 987624cf5b..7751c7e650 100644 --- a/packages/slate/test/commands/splitNode/path/selection.js +++ b/packages/slate/test/commands/splitNodes/path/selection.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodeAtPath([0], 2) + editor.splitNodes({ at: [0, 2] }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/point/block.js b/packages/slate/test/commands/splitNodes/point/block.js similarity index 80% rename from packages/slate/test/commands/splitBlock/point/block.js rename to packages/slate/test/commands/splitNodes/point/block.js index 3596cc03d9..f261578ed0 100644 --- a/packages/slate/test/commands/splitBlock/point/block.js +++ b/packages/slate/test/commands/splitNodes/point/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock({ at: { path: [0, 0], offset: 2 } }) + editor.splitNodes({ at: { path: [0, 0], offset: 2 }, height: 1 }) } export const input = ( diff --git a/packages/slate/test/commands/splitInline/point/inline.js b/packages/slate/test/commands/splitNodes/point/inline.js similarity index 86% rename from packages/slate/test/commands/splitInline/point/inline.js rename to packages/slate/test/commands/splitNodes/point/inline.js index 087ed791d7..d2d6ae4e74 100644 --- a/packages/slate/test/commands/splitInline/point/inline.js +++ b/packages/slate/test/commands/splitNodes/point/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitInlineAtPoint({ path: [0, 1, 0], offset: 2 }) + editor.splitNodes({ at: { path: [0, 1, 0], offset: 2 }, height: 1 }) } export const input = ( diff --git a/packages/slate/test/commands/splitBlock/point/selection.js b/packages/slate/test/commands/splitNodes/point/selection.js similarity index 83% rename from packages/slate/test/commands/splitBlock/point/selection.js rename to packages/slate/test/commands/splitNodes/point/selection.js index c407ffa85d..c53018a301 100644 --- a/packages/slate/test/commands/splitBlock/point/selection.js +++ b/packages/slate/test/commands/splitNodes/point/selection.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitBlock({ at: { path: [0, 0], offset: 2 } }) + editor.splitNodes({ at: { path: [0, 0], offset: 2 }, height: 1 }) } export const input = ( diff --git a/packages/slate/test/commands/unwrapBlock/selection/across-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/across-blocks.js deleted file mode 100644 index cfe1cad951..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/across-blocks.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock('quote') -} - -export const input = ( - - - - - word - - - another - - - - -) - -export const output = ( - - - - word - - - another - - - -) diff --git a/packages/slate/test/commands/unwrapBlock/selection/across-inlines.js b/packages/slate/test/commands/unwrapBlock/selection/across-inlines.js deleted file mode 100644 index e049993bd8..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/across-inlines.js +++ /dev/null @@ -1,43 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock('quote') -} - -export const input = ( - - - - - - word - - - - - another - - - - - -) - -export const output = ( - - - - - word - - - - - another - - - - -) diff --git a/packages/slate/test/commands/unwrapBlock/selection/ending-child-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/ending-child-blocks.js deleted file mode 100644 index c54b685263..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/ending-child-blocks.js +++ /dev/null @@ -1,45 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock('quote') -} - -export const input = ( - - - - one - two - three - four - - five - - - six - - - - -) - -export const output = ( - - - - one - two - three - four - - - five - - - six - - - -) diff --git a/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks-with-backward-selection.js b/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks-with-backward-selection.js deleted file mode 100644 index 41f1b9cf41..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks-with-backward-selection.js +++ /dev/null @@ -1,47 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock('quote') -} - -export const input = ( - - - - one - two - - three - - - four - - five - six - - - -) - -export const output = ( - - - - one - two - - - three - - - four - - - five - six - - - -) diff --git a/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks.js deleted file mode 100644 index a80cb189fb..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/middle-child-blocks.js +++ /dev/null @@ -1,47 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock('quote') -} - -export const input = ( - - - - one - two - - three - - - four - - five - six - - - -) - -export const output = ( - - - - one - two - - - three - - - four - - - five - six - - - -) diff --git a/packages/slate/test/commands/unwrapBlock/selection/nested-block.js b/packages/slate/test/commands/unwrapBlock/selection/nested-block.js deleted file mode 100644 index a89870db73..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/nested-block.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock('quote') -} - -export const input = ( - - - - - - word - - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/unwrapBlock/selection/starting-child-blocks.js b/packages/slate/test/commands/unwrapBlock/selection/starting-child-blocks.js deleted file mode 100644 index ee3c7e954c..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/starting-child-blocks.js +++ /dev/null @@ -1,45 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock('quote') -} - -export const input = ( - - - - - one - - - two - - three - four - five - six - - - -) - -export const output = ( - - - - one - - - two - - - three - four - five - six - - - -) diff --git a/packages/slate/test/commands/unwrapBlock/selection/with-object.js b/packages/slate/test/commands/unwrapBlock/selection/with-object.js deleted file mode 100644 index 3e5a2077e3..0000000000 --- a/packages/slate/test/commands/unwrapBlock/selection/with-object.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapBlock({ - type: 'quote', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - word - - -) diff --git a/packages/slate/test/commands/unwrapInline/selection/across-inlines-and-text.js b/packages/slate/test/commands/unwrapInline/selection/across-inlines-and-text.js deleted file mode 100644 index 340a8519d8..0000000000 --- a/packages/slate/test/commands/unwrapInline/selection/across-inlines-and-text.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapInline('link') -} - -export const input = ( - - - - - one - two - three - - - - -) - -export const output = ( - - - - onetwothree - - - -) diff --git a/packages/slate/test/commands/unwrapInline/selection/across-inlines.js b/packages/slate/test/commands/unwrapInline/selection/across-inlines.js deleted file mode 100644 index 900037568e..0000000000 --- a/packages/slate/test/commands/unwrapInline/selection/across-inlines.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapInline('hashtag') -} - -export const input = ( - - - - wo - - - rd - - - an - - - other - - - -) - -export const output = ( - - - - wo - - rd - an - - other - - - -) diff --git a/packages/slate/test/commands/unwrapInline/selection/nested-block.js b/packages/slate/test/commands/unwrapInline/selection/nested-block.js deleted file mode 100644 index d13258acb8..0000000000 --- a/packages/slate/test/commands/unwrapInline/selection/nested-block.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapInline('hashtag') -} - -export const input = ( - - - - - w - - or - d - - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/unwrapInline/selection/with-object.js b/packages/slate/test/commands/unwrapInline/selection/with-object.js deleted file mode 100644 index c58322dddd..0000000000 --- a/packages/slate/test/commands/unwrapInline/selection/with-object.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.unwrapInline({ - type: 'hashtag', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - w - - or - - d - - - -) - -export const output = ( - - - - w - or - d - - - -) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-partial.js b/packages/slate/test/commands/unwrapNodes/match-block/block-partial.js new file mode 100644 index 0000000000..385f24649c --- /dev/null +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-partial.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.pluckNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + one + two + three + four + + five + + + six + + + +) + +export const output = ( + + + one + two + three + four + + + five + + + six + + +) diff --git a/packages/slate/test/commands/wrapBlock/selection/nested-block-with-object.js b/packages/slate/test/commands/wrapBlock/selection/nested-block-with-object.js deleted file mode 100644 index 07b3fc781c..0000000000 --- a/packages/slate/test/commands/wrapBlock/selection/nested-block-with-object.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapBlock({ - type: 'quote', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - - word - - - - - -) diff --git a/packages/slate/test/commands/wrapBlock/selection/nested-block.js b/packages/slate/test/commands/wrapBlock/selection/nested-block.js index 46765a1cbb..5f76201052 100644 --- a/packages/slate/test/commands/wrapBlock/selection/nested-block.js +++ b/packages/slate/test/commands/wrapBlock/selection/nested-block.js @@ -8,26 +8,22 @@ export const run = editor => { export const input = ( - + - - word - + word - + ) export const output = ( - + - - word - + word - + ) diff --git a/packages/slate/test/commands/wrapBlock/selection/with-object.js b/packages/slate/test/commands/wrapBlock/selection/with-object.js deleted file mode 100644 index 19420653b9..0000000000 --- a/packages/slate/test/commands/wrapBlock/selection/with-object.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapBlock({ - type: 'quote', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/wrapNode/path/block.js b/packages/slate/test/commands/wrapNodes/path/block.js similarity index 100% rename from packages/slate/test/commands/wrapNode/path/block.js rename to packages/slate/test/commands/wrapNodes/path/block.js diff --git a/packages/slate/test/commands/wrapNode/path/text.js b/packages/slate/test/commands/wrapNodes/path/text.js similarity index 100% rename from packages/slate/test/commands/wrapNode/path/text.js rename to packages/slate/test/commands/wrapNodes/path/text.js From bfb020161adcd8bf64aad26857f4ae9858a77b92 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 24 Oct 2019 18:17:43 -0400 Subject: [PATCH 057/165] add unwrapNodes --- packages/slate/src/classes/commands/node.ts | 27 ++++++----- packages/slate/src/classes/queries/path.ts | 2 +- packages/slate/src/interfaces/range.ts | 4 +- .../liftNodes/selection/block-full.js | 39 +++++++++++++++ .../liftNodes/selection/block-nested.js | 29 ++++++++++++ .../moveNodes/selection/block-nested-after.js | 35 ++++++++++++++ .../selection/block-nested-before.js | 34 ++++++++++++++ .../unwrapNodes/match-block/block-all.js | 39 +++++++++++++++ .../{block-partial.js => block-end.js} | 4 +- .../unwrapNodes/match-block/block-middle.js | 43 +++++++++++++++++ .../unwrapNodes/match-block/block-nested.js | 47 +++++++++++++++++++ .../unwrapNodes/match-block/block-start.js | 41 ++++++++++++++++ .../commands/unwrapNodes/match-block/block.js | 25 ++++++++++ 13 files changed, 353 insertions(+), 16 deletions(-) create mode 100644 packages/slate/test/commands/liftNodes/selection/block-full.js create mode 100644 packages/slate/test/commands/liftNodes/selection/block-nested.js create mode 100644 packages/slate/test/commands/moveNodes/selection/block-nested-after.js create mode 100644 packages/slate/test/commands/moveNodes/selection/block-nested-before.js create mode 100644 packages/slate/test/commands/unwrapNodes/match-block/block-all.js rename packages/slate/test/commands/unwrapNodes/match-block/{block-partial.js => block-end.js} (90%) create mode 100644 packages/slate/test/commands/unwrapNodes/match-block/block-middle.js create mode 100644 packages/slate/test/commands/unwrapNodes/match-block/block-nested.js create mode 100644 packages/slate/test/commands/unwrapNodes/match-block/block-start.js create mode 100644 packages/slate/test/commands/unwrapNodes/match-block/block.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index de8bee3e66..529c2f4c14 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -179,7 +179,7 @@ class NodeCommands { const endIndex = end.path[parentPath.length] const { length } = parent.nodes - if (length === 1) { + if (endIndex - startIndex + 1 === length) { this.pluckNodes({ at: parentPath }) } else if (startIndex === 0) { this.moveNodes({ at, depth, to: parentPath }) @@ -248,12 +248,14 @@ class NodeCommands { const parentPath = commonPath.slice(0, depth - 1) const startIndex = start.path[parentPath.length] const endIndex = end.path[parentPath.length] + const toRef = this.createPathRef(to) + const parentRef = this.createPathRef(parentPath) for (let i = endIndex; i >= startIndex; i--) { this.apply({ type: 'move_node', - path: parentPath.concat(i), - newPath: to, + path: parentRef.current!.concat(startIndex), + newPath: toRef.current!, }) } @@ -639,11 +641,7 @@ class NodeCommands { ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, match = () => true } = options - - if (!at && selection) { - at = selection - } + let { at = selection, match = () => true } = options if (Path.isPath(at)) { const path = at @@ -662,20 +660,25 @@ class NodeCommands { ) } - const rangeRefs: RangeRef[] = [] + if (!Range.isRange(at)) { + return + } + + const matches: [RangeRef, number][] = [] for (const [node, path] of this.elements({ at })) { if (match([node, path])) { const range = this.getRange(path) const intersection = Range.intersection(at, range) const rangeRef = this.createRangeRef(intersection) - rangeRefs.push(rangeRef) + const depth = path.length + 1 + matches.push([rangeRef, depth]) } } - for (const rangeRef of rangeRefs) { + for (const [rangeRef, depth] of matches) { if (rangeRef.current) { - this.liftNodes({ at: rangeRef.current }) + this.liftNodes({ at: rangeRef.current, depth }) } rangeRef.unref() diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 58b3e771bf..69c7ab216a 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -27,7 +27,7 @@ class PathQueries { return Node.leaf(this.value, path) } - hasNode(this: Editor, path: Path): Node { + hasNode(this: Editor, path: Path): boolean { return Node.has(this.value, path) } diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index 8a0ded5fe3..3bec1846fe 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -16,6 +16,7 @@ interface Range { namespace Range { export const intersection = (range: Range, another: Range): Range => { + debugger if (!Range.includes(range, another)) { throw new Error( `Cannot get the intersection of ranges ${JSON.stringify( @@ -53,7 +54,8 @@ namespace Range { if (Range.isRange(target)) { return ( Range.includes(range, target.anchor) || - Range.includes(range, target.focus) + Range.includes(range, target.focus) || + Range.includes(target, range) ) } diff --git a/packages/slate/test/commands/liftNodes/selection/block-full.js b/packages/slate/test/commands/liftNodes/selection/block-full.js new file mode 100644 index 0000000000..88ee2a3693 --- /dev/null +++ b/packages/slate/test/commands/liftNodes/selection/block-full.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.liftNodes({ depth: 2 }) +} + +export const input = ( + + + + one + + two + three + four + five + + six + + + +) + +export const output = ( + + + one + + two + three + four + five + + six + + +) diff --git a/packages/slate/test/commands/liftNodes/selection/block-nested.js b/packages/slate/test/commands/liftNodes/selection/block-nested.js new file mode 100644 index 0000000000..8d63b3c56f --- /dev/null +++ b/packages/slate/test/commands/liftNodes/selection/block-nested.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.liftNodes({ depth: 3 }) +} + +export const input = ( + + + + + one + + + + +) + +export const output = ( + + + + one + + + +) diff --git a/packages/slate/test/commands/moveNodes/selection/block-nested-after.js b/packages/slate/test/commands/moveNodes/selection/block-nested-after.js new file mode 100644 index 0000000000..2e2a23acbf --- /dev/null +++ b/packages/slate/test/commands/moveNodes/selection/block-nested-after.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.moveNodes({ depth: 2, to: [1] }) +} + +export const input = ( + + + one + + two + + + three + + + +) + +export const output = ( + + + one + + + two + + + three + + +) diff --git a/packages/slate/test/commands/moveNodes/selection/block-nested-before.js b/packages/slate/test/commands/moveNodes/selection/block-nested-before.js new file mode 100644 index 0000000000..683cbf01ba --- /dev/null +++ b/packages/slate/test/commands/moveNodes/selection/block-nested-before.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.moveNodes({ depth: 2, to: [0] }) +} + +export const input = ( + + + + one + + + two + + + +) + +export const output = ( + + + one + + + two + + + + + +) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-all.js b/packages/slate/test/commands/unwrapNodes/match-block/block-all.js new file mode 100644 index 0000000000..1b5f2512d2 --- /dev/null +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-all.js @@ -0,0 +1,39 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.unwrapNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + + one + + two + three + four + five + + six + + + +) + +export const output = ( + + + one + + two + three + four + five + + six + + +) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-partial.js b/packages/slate/test/commands/unwrapNodes/match-block/block-end.js similarity index 90% rename from packages/slate/test/commands/unwrapNodes/match-block/block-partial.js rename to packages/slate/test/commands/unwrapNodes/match-block/block-end.js index 385f24649c..d2288f03f0 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-partial.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' } }) } export const input = ( @@ -25,7 +25,7 @@ export const input = ( export const output = ( - + one two three diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js b/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js new file mode 100644 index 0000000000..fc7b551229 --- /dev/null +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js @@ -0,0 +1,43 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.unwrapNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + one + two + + three + + + four + + five + six + + +) + +export const output = ( + + + one + two + + + three + + + four + + + five + six + + +) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js b/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js new file mode 100644 index 0000000000..51375b9efe --- /dev/null +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js @@ -0,0 +1,47 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.unwrapNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + + one + two + + three + + + four + + five + six + + + +) + +export const output = ( + + + + one + two + + + three + + + four + + + five + six + + + +) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-start.js b/packages/slate/test/commands/unwrapNodes/match-block/block-start.js new file mode 100644 index 0000000000..4f7aaec439 --- /dev/null +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-start.js @@ -0,0 +1,41 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.unwrapNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + + one + + + two + + three + four + five + six + + +) + +export const output = ( + + + one + + + two + + + three + four + five + six + + +) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block.js b/packages/slate/test/commands/unwrapNodes/match-block/block.js new file mode 100644 index 0000000000..35761f6afc --- /dev/null +++ b/packages/slate/test/commands/unwrapNodes/match-block/block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.unwrapNodes({ match: { key: 'a' } }) +} + +export const input = ( + + + + one + + + +) + +export const output = ( + + + one + + +) From 11ad4ad3ac82c14884b921c858ea508dc98399ad Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 24 Oct 2019 18:24:38 -0400 Subject: [PATCH 058/165] remove setValue --- packages/slate/src/classes/commands/range.ts | 33 ---------- packages/slate/src/classes/commands/value.ts | 63 ------------------- .../test/commands/setNodes/path/value.js | 21 +++++++ .../slate/test/commands/setValue/simple.js | 25 -------- 4 files changed, 21 insertions(+), 121 deletions(-) create mode 100644 packages/slate/test/commands/setNodes/path/value.js delete mode 100644 packages/slate/test/commands/setValue/simple.js diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index 8b4d8dbd86..9621a37c73 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -10,39 +10,6 @@ import { } from '../..' class RangeCommands { - /** - * Unwrap the block nodes in a range that match a set of properties. - */ - - unwrapBlockAtRange(this: Editor, range: Range, props: {}) { - this.withoutNormalizing(() => { - // Iterate in reverse to ensure unwrapping doesn't affect path lookups. - for (const [element, path] of this.blocks({ at: range, reverse: true })) { - if (Element.matches(element, props)) { - this.pluckNodeAtPath(path) - } - } - }) - } - - /** - * Unwrap the inline nodes in a range that match a set of properties. - */ - - unwrapInlineAtRange(this: Editor, range: Range, props: {}) { - this.withoutNormalizing(() => { - // Iterate in reverse to ensure unwrapping doesn't affect path lookups. - for (const [element, path] of this.inlines({ - at: range, - reverse: true, - })) { - if (Element.matches(element, props)) { - this.pluckNodeAtPath(path) - } - } - }) - } - /** * Wrap the blocks in a range in a new block parent. */ diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts index 64bf82a8fa..53e8ac4d97 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/value.ts @@ -126,40 +126,6 @@ class ValueCommands { this.normalize() } - /** - * Unwrap the block nodes in the selection that match a set of properties. - */ - - unwrapBlock(this: Editor, props: {}): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.unwrapBlockAtRange(selection, props) - const range = rangeRef.unref()! - this.select(range) - } - - /** - * Unwrap the inline nodes in the selection that match a set of properties. - */ - - unwrapInline(this: Editor, props: {}): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.unwrapInlineAtRange(selection, props) - const range = rangeRef.unref()! - this.select(range) - } - /** * Wrap the block nodes in the selection in a new block. */ @@ -193,35 +159,6 @@ class ValueCommands { const range = rangeRef.unref()! this.select(range) } - - setValue(this: Editor, props: Partial) { - const { value } = this - const newProps = {} - const oldProps = {} - - // Dedupe new and old properties to avoid unnecessary sets. - for (const k in props) { - if (k === 'annotations' || k === 'nodes' || k === 'selection') { - continue - } - - if (props[k] !== value[k]) { - newProps[k] = props[k] - oldProps[k] = value[k] - } - } - - // PERF: If no properties have changed don't apply an operation at all. - if (Object.keys(newProps).length === 0) { - return - } - - this.apply({ - type: 'set_value', - properties: oldProps, - newProperties: newProps, - }) - } } /** diff --git a/packages/slate/test/commands/setNodes/path/value.js b/packages/slate/test/commands/setNodes/path/value.js new file mode 100644 index 0000000000..7f37887899 --- /dev/null +++ b/packages/slate/test/commands/setNodes/path/value.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setNodes({ key: true }, { at: [] }) +} + +export const input = ( + + word + another + +) + +export const output = ( + + word + another + +) diff --git a/packages/slate/test/commands/setValue/simple.js b/packages/slate/test/commands/setValue/simple.js deleted file mode 100644 index fb520e28f7..0000000000 --- a/packages/slate/test/commands/setValue/simple.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.setData({ thing: 'value' }) -} - -export const input = ( - - - word - another - - -) - -export const output = ( - - - word - another - - -) From 489db29e3d242d60ea0bc9a8f9f23b8843593474 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 25 Oct 2019 12:58:03 -0400 Subject: [PATCH 059/165] more progress --- packages/slate/src/classes/commands/node.ts | 362 ++++++++++++++---- packages/slate/src/classes/commands/path.ts | 121 +----- packages/slate/src/classes/commands/range.ts | 19 +- packages/slate/src/classes/commands/text.ts | 8 +- packages/slate/src/classes/queries/path.ts | 20 +- packages/slate/src/interfaces/range.ts | 1 - .../insertNodes/selection/none-empty.js | 17 + .../selection/none-end.js} | 13 +- .../commands/mergeNodes/depth-block/block.js | 20 + .../test/commands/mergeNodes/path/block.js | 2 +- .../commands/mergeNodes/path/text-across.js | 20 + .../after-inline-void.js | 2 +- .../after-inline.js | 2 +- .../before-inline.js | 2 +- .../block-end.js | 2 +- .../block-middle.js | 2 +- .../block-start.js | 2 +- .../{height-block => depth-block}/point.js | 2 +- .../with-inline.js | 2 +- .../block-end.js | 2 +- .../block-middle.js | 2 +- .../block-start.js | 2 +- .../{height/one.js => depth/two.js} | 2 +- .../{height/infinity.js => depth/zero.js} | 2 +- .../splitNodes/height-inline/point.js | 35 -- .../test/commands/splitNodes/point/block.js | 2 +- .../test/commands/splitNodes/point/inline.js | 2 +- .../{height-inline => selection}/expanded.js | 2 +- .../{height-inline => selection}/mark.js | 2 +- .../with-delete-across-blocks-and-inlines.js | 4 +- .../with-delete-across-blocks.js | 4 +- .../with-delete-hanging-selection.js | 4 +- .../with-delete.js | 4 +- .../block/block-across-nested.js | 35 ++ .../surroundNodes/block/block-across.js | 31 ++ .../surroundNodes/block/block-nested.js | 29 ++ .../commands/surroundNodes/block/block.js | 25 ++ .../surroundNodes/block/inline-across.js | 47 +++ .../surroundNodes/block/omit-nodes.js | 37 ++ .../inline/inline-across.js} | 25 +- .../commands/surroundNodes/inline/inline.js | 35 ++ .../commands/surroundNodes/inline/text.js | 27 ++ .../commands/wrapNodes/block/block-across.js | 31 ++ .../commands/wrapNodes/block/block-end.js | 33 ++ .../commands/wrapNodes/block/block-middle.js | 29 ++ .../block/block-start.js} | 25 +- .../test/commands/wrapNodes/block/block.js | 25 ++ .../{path/text.js => selection/depth-text.js} | 4 +- 48 files changed, 824 insertions(+), 302 deletions(-) create mode 100644 packages/slate/test/commands/insertNodes/selection/none-empty.js rename packages/slate/test/commands/{wrapNodes/path/block.js => insertNodes/selection/none-end.js} (65%) create mode 100644 packages/slate/test/commands/mergeNodes/depth-block/block.js create mode 100644 packages/slate/test/commands/mergeNodes/path/text-across.js rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/after-inline-void.js (91%) rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/after-inline.js (90%) rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/before-inline.js (92%) rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/block-end.js (89%) rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/block-middle.js (87%) rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/block-start.js (89%) rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/point.js (78%) rename packages/slate/test/commands/splitNodes/{height-block => depth-block}/with-inline.js (92%) rename packages/slate/test/commands/splitNodes/{height-inline => depth-inline}/block-end.js (91%) rename packages/slate/test/commands/splitNodes/{height-inline => depth-inline}/block-middle.js (91%) rename packages/slate/test/commands/splitNodes/{height-inline => depth-inline}/block-start.js (91%) rename packages/slate/test/commands/splitNodes/{height/one.js => depth/two.js} (92%) rename packages/slate/test/commands/splitNodes/{height/infinity.js => depth/zero.js} (92%) delete mode 100644 packages/slate/test/commands/splitNodes/height-inline/point.js rename packages/slate/test/commands/splitNodes/{height-inline => selection}/expanded.js (91%) rename packages/slate/test/commands/splitNodes/{height-inline => selection}/mark.js (92%) rename packages/slate/test/commands/splitNodes/{height-block => selection}/with-delete-across-blocks-and-inlines.js (90%) rename packages/slate/test/commands/splitNodes/{height-block => selection}/with-delete-across-blocks.js (83%) rename packages/slate/test/commands/splitNodes/{height-block => selection}/with-delete-hanging-selection.js (86%) rename packages/slate/test/commands/splitNodes/{height-block => selection}/with-delete.js (81%) create mode 100644 packages/slate/test/commands/surroundNodes/block/block-across-nested.js create mode 100644 packages/slate/test/commands/surroundNodes/block/block-across.js create mode 100644 packages/slate/test/commands/surroundNodes/block/block-nested.js create mode 100644 packages/slate/test/commands/surroundNodes/block/block.js create mode 100644 packages/slate/test/commands/surroundNodes/block/inline-across.js create mode 100644 packages/slate/test/commands/surroundNodes/block/omit-nodes.js rename packages/slate/test/commands/{splitNodes/path/selection.js => surroundNodes/inline/inline-across.js} (56%) create mode 100644 packages/slate/test/commands/surroundNodes/inline/inline.js create mode 100644 packages/slate/test/commands/surroundNodes/inline/text.js create mode 100644 packages/slate/test/commands/wrapNodes/block/block-across.js create mode 100644 packages/slate/test/commands/wrapNodes/block/block-end.js create mode 100644 packages/slate/test/commands/wrapNodes/block/block-middle.js rename packages/slate/test/commands/{splitNodes/point/selection.js => wrapNodes/block/block-start.js} (58%) create mode 100644 packages/slate/test/commands/wrapNodes/block/block.js rename packages/slate/test/commands/wrapNodes/{path/text.js => selection/depth-text.js} (77%) diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index 529c2f4c14..cc64ca8771 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -41,13 +41,13 @@ class NodeCommands { nodes: Node | Node[], options: { at?: Range | Point | Path - height?: number | 'block' | 'inline' + depth?: number | 'block' | 'inline' } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, height } = options - let isSelection = false + let { at, depth } = options + let select = false if (Node.isNode(nodes)) { nodes = [nodes] @@ -59,68 +59,62 @@ class NodeCommands { const [node] = nodes - if (height == null) { + // If the depth isn't explicitly set, infer it from the node. + if (depth == null) { if (Text.isText(node)) { - height = 0 + depth = -1 } else if (this.isInline(node)) { - height = 'inline' + depth = 'inline' } else { - height = 'block' + depth = 'block' } } - if (at == null && selection != null) { - at = selection - isSelection = true - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor + // By default, use the selection as the target location. But if there is + // no selection, insert at the end of the document since that is such a + // common use case when inserting from a non-focused state. + if (!at) { + at = selection || this.getEnd() || [this.value.nodes.length] + select = true } if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! + if (Range.isCollapsed(at)) { + at = at.anchor + } else { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } } if (Point.isPoint(at)) { - height = this.getHeight(at.path, height) - const topPath = at.path.slice(0, at.path.length - height) + depth = this.getDepth(at.path, depth) + const topPath = at.path.slice(0, depth) const isAtEnd = this.isAtEnd(at, topPath) const pointRef = this.createPointRef(at) - this.splitNodes({ at, height, always: false }) + this.splitNodes({ at, depth, always: false }) const point = pointRef.unref()! - const path = point.path.slice(0, point.path.length - height) + const path = point.path.slice(0, depth) at = isAtEnd ? Path.next(path) : path } - if (!Path.isPath(at)) { - return - } - - const path = at const parentPath = Path.parent(at) - let index = path[path.length - 1] + let index = at[at.length - 1] if (this.getFurthestVoid(parentPath)) { return } for (const node of nodes) { - const p = parentPath.concat(index) + const path = parentPath.concat(index) index++ - - this.apply({ - type: 'insert_node', - path: p, - node, - }) + this.apply({ type: 'insert_node', path, node }) } - if (isSelection) { - const point = this.getEnd(path) + if (select) { + const point = this.getEnd(at) if (point) { this.select(point) @@ -193,6 +187,128 @@ class NodeCommands { }) } + /** + * Merge the nodes at a specific location. + */ + + mergeNodes( + this: Editor, + options: { + at?: Path | Point | Range + depth?: number | 'block' | 'inline' + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, depth } = options + + if (!at && selection) { + at = selection + } + + if (Range.isRange(at) && Range.isCollapsed(at)) { + at = at.anchor + } else if (Range.isRange(at)) { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } else if (Path.isPath(at)) { + depth = at.length + at = this.getStart(at) + } + + if (!Point.isPoint(at)) { + return + } + + const fromDepth = this.getDepth(at.path, depth) + const path = at.path.slice(0, fromDepth) + const node = this.getNode(path) + const prevText = this.getPreviousText(path) + + if (!prevText) { + return + } + + const [, prevTextPath] = prevText + const prevDepth = this.getDepth(prevTextPath, depth) + const prevPath = prevTextPath.slice(0, prevDepth) + const prevNode = this.getNode(prevPath) + const newPath = Path.next(prevPath) + const commonPath = Path.common(path, prevPath) + const isPreviousSibling = Path.isSibling(path, prevPath) + + // Determine if the merge will leave an ancestor of the path empty as a + // result, in which case we'll want to remove it after merging. + const emptyAncestor = Node.furthest(this.value, path, ([n, p]) => { + return ( + Path.isDescendant(p, commonPath) && + Path.isAncestor(p, path) && + Element.isElement(n) && + n.nodes.length === 1 + ) + }) + + const emptyRef = emptyAncestor && this.createPathRef(emptyAncestor[1]) + let properties + let position + + // Ensure that the nodes are equivalent, and figure out what the position + // and extra properties of the merge will be. + if (Text.isText(node) && Text.isText(prevNode)) { + const { text, marks, ...rest } = node + position = prevNode.text.length + properties = rest as Partial + } else if (Element.isElement(node) && Element.isElement(prevNode)) { + const { nodes, ...rest } = node + position = prevNode.nodes.length + properties = rest as Partial + } else { + throw new Error( + `Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify( + node + )} ${JSON.stringify(prevNode)}` + ) + } + + // If the node isn't already the next sibling of the previous node, move + // it so that it is before merging. + if (!isPreviousSibling) { + this.moveNodes({ at: path, to: newPath }) + } + + // If there was going to be an empty ancestor of the node that was merged, + // we remove it from the tree. + if (emptyRef) { + this.removeNodes({ at: emptyRef.current! }) + } + + // If the target node that we're merging with is empty, remove it instead + // of merging the two. This is a common rich text editor behavior to + // prevent losing formatting when deleting entire nodes when you have a + // hanging selection. + if ( + (Element.isElement(prevNode) && this.isEmpty(prevNode)) || + (Text.isText(prevNode) && prevNode.text === '') + ) { + this.removeNodes({ at: prevPath }) + } else { + this.apply({ + type: 'merge_node', + path: newPath, + position, + target: null, + properties, + }) + } + + if (emptyRef) { + emptyRef.unref() + } + }) + } + /** * Move the nodes at a location to a new location. */ @@ -209,16 +325,14 @@ class NodeCommands { const { selection } = this.value const { to } = options const newIndex = to[to.length - 1] - let { at, depth = 1 } = options + let { at, depth } = options let isSelection = false if (newIndex > 0 && !this.hasNode(Path.previous(to))) { throw new Error( `Cannot move the node at path [${at}] to new path [${to}] because the index is out of range.` ) - } - - if (depth < 1) { + } else if (depth != null && depth < 1) { throw new Error( `Cannot move nodes at a depth less than \`1\`, but you passed depth: \`${depth}\`` ) @@ -227,24 +341,23 @@ class NodeCommands { if (!at && selection) { at = selection isSelection = true - } - - if (Path.isPath(at)) { + } else if (Path.isPath(at)) { depth = at.length at = this.getRange(at) - } - - if (Point.isPoint(at)) { + } else if (Point.isPoint(at)) { at = { anchor: at, focus: at } - } - - if (!Range.isRange(at)) { + } else if (!Range.isRange(at)) { return } const [start, end] = Range.points(at) const rangeRef = this.createRangeRef(at) - const [, commonPath] = this.getCommon(start.path, end.path) + const commonPath = Path.common(start.path, end.path) + + if (depth == null) { + depth = commonPath.length + 1 + } + const parentPath = commonPath.slice(0, depth - 1) const startIndex = start.path[parentPath.length] const endIndex = end.path[parentPath.length] @@ -337,7 +450,7 @@ class NodeCommands { // Merge adjacent text nodes that are empty or have matching marks. if (prev != null && Text.isText(prev)) { if (Text.matches(child, prev)) { - this.mergeNodeAtPath(at.concat(n)) + this.mergeNodes({ at: at.concat(n) }) n-- continue } else if (prev.text === '') { @@ -426,7 +539,7 @@ class NodeCommands { props: Partial, options: { at?: Path | Point | Range - match?: 'block' | 'inline' | 'text' | ((entry: NodeEntry) => boolean) + match?: 'block' | 'inline' | ((entry: NodeEntry) => boolean) } = {} ) { this.withoutNormalizing(() => { @@ -437,8 +550,6 @@ class NodeCommands { match = ([n]: NodeEntry) => Element.isElement(n) && !this.isInline(n) } else if (match === 'inline') { match = ([n]: NodeEntry) => Element.isElement(n) && this.isInline(n) - } else if (match === 'text') { - match = ([n]: NodeEntry) => Text.isText(n) } if (!at && selection) { @@ -512,16 +623,16 @@ class NodeCommands { options: { at?: Path | Point | Range always?: boolean - height?: number | 'block' | 'inline' - skip?: number + depth?: 'block' | 'inline' | number + height?: number } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value const { always = true } = options - let { at, height = 0, skip = 0 } = options + let { at, depth = -1, height = 0 } = options let isSelection = false - let minHeight = 0 + let maxDepth = Infinity let position: number | null = null if (!at && selection) { @@ -548,10 +659,12 @@ class NodeCommands { } const [, firstPath] = first - skip = firstPath.length - at.length + 1 + debugger + height = firstPath.length - at.length + 1 position = at[at.length - 1] - minHeight = skip + maxDepth = at.length - 1 at = { path: firstPath, offset: 0 } + debugger } if (!Point.isPoint(at)) { @@ -559,28 +672,29 @@ class NodeCommands { } const { path, offset } = at - const outsideRef = this.createPointRef(at) - const insideRef = this.createPointRef(at, { stick: 'backward' }) const furthestVoid = this.getFurthestVoid(path) let pos = position == null ? offset : position let target: number | null = null - let h = skip - height = this.getHeight(path, height) - height = Math.max(height, minHeight) // If the point it inside a void node, we still want to split up to a // `height`, but we need to start after the void node in the tree. if (furthestVoid) { const [, voidPath] = furthestVoid const relPath = Path.relative(path, voidPath) - h = Math.max(relPath.length + 1, skip) + height = Math.max(relPath.length + 1, height) pos = voidPath[voidPath.length - 1] } - while (h <= height) { - const depth = path.length - h - const p = path.slice(0, depth) - h++ + const outsideRef = this.createPointRef(at) + const insideRef = this.createPointRef(at, { stick: 'backward' }) + let d = path.length - height + depth = this.getDepth(path, depth) + depth = Math.min(depth, maxDepth) + + while (d >= depth) { + debugger + const p = path.slice(0, d) + d-- if (p.length === 0) { break @@ -596,7 +710,7 @@ class NodeCommands { continue } - const node = this.getNode(path) + const node = this.getNode(p) let properties if (Text.isText(node)) { @@ -616,7 +730,7 @@ class NodeCommands { }) target = pos - pos = path[depth - 1] + 1 + pos = path[d] + 1 } if (isSelection) { @@ -628,6 +742,77 @@ class NodeCommands { }) } + surroundNodes( + this: Editor, + element: Element, + options: { + at?: Path | Point | Range + depth?: 'block' | 'inline' | number + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, depth } = options + + // Convert the possibilities for `at` into a range. + if (!at && selection) { + at = selection + } else if (Path.isPath(at)) { + depth = at.length + at = this.getRange(at) + } else if (Point.isPoint(at)) { + at = { anchor: at, focus: at } + } else if (!Range.isRange(at)) { + return + } + + const isInline = this.isInline(element) + let range = at + let minDepth = 0 + + if (depth == null) { + depth = isInline ? 'inline' : 'block' + } + + const surround = () => { + const [start, end] = Range.points(range) + const startDepth = this.getDepth(start.path, depth) + const endDepth = this.getDepth(start.path, depth) + const commonPath = Path.common(start.path, end.path) + let d = Math.min(startDepth - 1, endDepth - 1, commonPath.length) + d = Math.max(minDepth, d) + const path = commonPath.slice(0, d) + const firstPath = path.concat(0) + const target = this.getRange(path) + const targetRef = this.createRangeRef(target) + const container = { ...element, nodes: [] } + + this.insertNodes(container, { at: firstPath }) + + this.moveNodes({ + at: targetRef.current!, + depth: path.length + 1, + to: firstPath.concat(0), + }) + + targetRef.unref() + } + + if (!isInline) { + surround() + } else { + for (const [, blockPath] of this.leafBlocks({ at })) { + range = Range.intersection(at, this.getRange(blockPath)) + const [start, end] = Range.points(range) + const startDepth = this.getDepth(start.path, 'inline') - 1 + const endDepth = this.getDepth(end.path, 'inline') - 1 + minDepth = Math.min(startDepth, endDepth) + surround() + } + } + }) + } + /** * Unwrap the leaf nodes from the closest matching parent. */ @@ -685,6 +870,37 @@ class NodeCommands { } }) } + + wrapNodes( + this: Editor, + element: Element, + options: { + at?: Path | Point | Range + depth?: 'block' | 'inline' | number + } = {} + ) { + this.withoutNormalizing(() => { + const { selection } = this.value + let { at, depth } = options + + // Convert the possibilities for `at` into a range. + if (!at && selection) { + at = selection + } else if (Path.isPath(at)) { + depth = at.length + at = this.getRange(at) + } else if (Point.isPoint(at)) { + at = { anchor: at, focus: at } + } else if (!Range.isRange(at)) { + return + } + + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + this.splitNodes({ at, always: false, depth }) + const range = rangeRef.unref()! + this.surroundNodes(element, { at: range, depth }) + }) + } } export default NodeCommands diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts index 0e44eab1c2..aadfd729bb 100755 --- a/packages/slate/src/classes/commands/path.ts +++ b/packages/slate/src/classes/commands/path.ts @@ -1,125 +1,6 @@ -import { produce } from 'immer' -import { - Editor, - Fragment, - Mark, - Element, - Text, - Node, - NodeEntry, - Path, - Descendant, - Value, -} from '../..' +import { Editor, Element, Path } from '../..' class PathCommands { - /** - * Merge the leaf block at a path with the previous leaf block. - */ - - mergeBlockAtPath(this: Editor, path: Path): void { - this.withoutNormalizing(() => { - const { value } = this - const closestBlock = this.getClosestBlock(path) - const prevBlock = this.getPreviousLeafBlock(path) - - if (!closestBlock) { - throw new Error( - `Cannot merge the leaf block above path [${path}] because there isn't one.` - ) - } - - if (!prevBlock) { - throw new Error( - `Cannot merge the block above path [${path}] with the previous leaf block because there isn't one.` - ) - } - - const [, blockPath] = closestBlock - const [prev, prevPath] = prevBlock - const newPath = Path.next(prevPath) - const commonPath = Path.common(blockPath, prevPath) - const furthest = Node.furthest(value, blockPath, ([n, p]) => { - return ( - Path.isDescendant(p, commonPath) && - Path.isAncestor(p, blockPath) && - Element.isElement(n) && - n.nodes.length === 1 - ) - }) - - const furthestRef = furthest ? this.createPathRef(furthest[1]) : null - - this.moveNodes({ at: blockPath, to: newPath }) - - if (furthestRef) { - this.removeNodes({ at: furthestRef.unref()! }) - } - - // If the target block is empty, remove it instead of merging. This is a - // rich text editor common behavior to prevent losing block formatting - // when deleting the entire previous block (with a hanging selection). - if (this.isEmpty(prev)) { - this.removeNodes({ at: prevPath }) - } else { - this.mergeNodeAtPath(newPath) - } - }) - } - - /** - * Merge the node at a path with the previous node. - */ - - mergeNodeAtPath(this: Editor, path: Path): void { - if (path.length === 0) { - throw new Error(`Cannot perform a merge on the top-level node.`) - } - - if (path[path.length - 1] === 0) { - throw new Error( - `Cannot merge the node at path [${path}] with the previous sibling because there isn't one.` - ) - } - - const { value } = this - const prevPath = Path.previous(path) - const node = Node.get(value, path) - const prevNode = Node.get(value, prevPath) - - if (Text.isText(node) && Text.isText(prevNode)) { - const { text, marks, ...properties } = node - const position = prevNode.text.length - this.apply({ - type: 'merge_node', - path, - position, - target: null, - properties, - }) - } else if (Element.isElement(node) && Element.isElement(prevNode)) { - const { nodes, ...properties } = node - const position = prevNode.nodes.length - this.apply({ - type: 'merge_node', - path, - position, - target: null, - properties, - }) - } else { - throw new Error( - `Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify( - node - )} ${JSON.stringify(prevNode)}` - ) - } - } - - /** - * Wrap the node at a path in a new parent node. - */ - wrapNodeAtPath(this: Editor, path: Path, element: Element): void { this.withoutNormalizing(() => { this.insertNodes(element, { at: path }) diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts index 9621a37c73..a4ebdbd243 100755 --- a/packages/slate/src/classes/commands/range.ts +++ b/packages/slate/src/classes/commands/range.ts @@ -1,19 +1,6 @@ -import { - Value, - Editor, - Fragment, - Mark, - Node, - Element, - Path, - Range, -} from '../..' +import { Editor, Element, Path, Range } from '../..' class RangeCommands { - /** - * Wrap the blocks in a range in a new block parent. - */ - wrapBlockAtRange(this: Editor, range: Range, block: Element) { this.withoutNormalizing(() => { const [start] = Range.points(range) @@ -40,10 +27,6 @@ class RangeCommands { }) } - /** - * Wrap the text and inline nodes in a range in a new inline parent. - */ - wrapInlineAtRange(this: Editor, range: Range, inline: Element) { this.withoutNormalizing(() => { const rangeRef = this.createRangeRef(range, { stick: 'inward' }) diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 2c639563b6..b773658a88 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -104,7 +104,7 @@ class DeletingCommands { } if (hasBlocks) { - this.mergeBlockAtPath(afterRef.current!.path) + this.mergeNodes({ at: afterRef.current!.path }) } if (isSelection) { @@ -153,7 +153,7 @@ class DeletingCommands { } const pointRef = this.createPointRef(at) - this.splitNodes({ at, height: 'block' }) + this.splitNodes({ at, depth: 'block' }) if (pointRef.current) { const [, insertPath] = this.getClosestBlock(pointRef.current.path)! @@ -166,8 +166,8 @@ class DeletingCommands { const [, afterPath] = afterClosest const [, beforePath] = beforeClosest const startPath = Path.next(beforePath) - this.mergeBlockAtPath(afterPath) - this.mergeBlockAtPath(startPath) + this.mergeNodes({ at: afterPath }) + this.mergeNodes({ at: startPath }) } } diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 69c7ab216a..d48b562684 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -35,6 +35,22 @@ class PathQueries { return Node.get(this.value, path) } + getDepth( + this: Editor, + path: Path, + depth: 'block' | 'inline' | number | undefined + ): number { + if (depth === 'block') { + const closestBlock = this.getClosestBlock(path) + depth = closestBlock && closestBlock[1].length + } else if (depth === 'inline') { + const closestInline = this.getClosestInline(path) + depth = closestInline && closestInline[1].length + } + + return depth == null || depth === -1 ? path.length : depth + } + getHeight(this: Editor, path: Path, height: number | 'inline' | 'block') { if (height === 'block') { const closestBlock = this.getClosestBlock(path) @@ -128,7 +144,7 @@ class PathQueries { * Get the end point of the node at path. */ - getEnd(this: Editor, path: Path): Point | undefined { + getEnd(this: Editor, path: Path = []): Point | undefined { const last = this.getLastText(path) if (last) { @@ -387,7 +403,7 @@ class PathQueries { * Get the start point of the node at path. */ - getStart(this: Editor, path: Path): Point | undefined { + getStart(this: Editor, path: Path = []): Point | undefined { const first = this.getFirstText(path) if (first) { diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index 3bec1846fe..7cdb363027 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -16,7 +16,6 @@ interface Range { namespace Range { export const intersection = (range: Range, another: Range): Range => { - debugger if (!Range.includes(range, another)) { throw new Error( `Cannot get the intersection of ranges ${JSON.stringify( diff --git a/packages/slate/test/commands/insertNodes/selection/none-empty.js b/packages/slate/test/commands/insertNodes/selection/none-empty.js new file mode 100644 index 0000000000..aa2eedc9ce --- /dev/null +++ b/packages/slate/test/commands/insertNodes/selection/none-empty.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = + +export const run = editor => { + editor.insertNodes(one) +} + +export const output = ( + + + one + + +) diff --git a/packages/slate/test/commands/wrapNodes/path/block.js b/packages/slate/test/commands/insertNodes/selection/none-end.js similarity index 65% rename from packages/slate/test/commands/wrapNodes/path/block.js rename to packages/slate/test/commands/insertNodes/selection/none-end.js index 930b5b4323..e61865808b 100644 --- a/packages/slate/test/commands/wrapNodes/path/block.js +++ b/packages/slate/test/commands/insertNodes/selection/none-end.js @@ -2,20 +2,21 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.wrapNodeAtPath([0], ) -} - export const input = ( - word + one ) +export const run = editor => { + editor.insertNodes(two) +} + export const output = ( + one - word + two ) diff --git a/packages/slate/test/commands/mergeNodes/depth-block/block.js b/packages/slate/test/commands/mergeNodes/depth-block/block.js new file mode 100644 index 0000000000..3b6668a904 --- /dev/null +++ b/packages/slate/test/commands/mergeNodes/depth-block/block.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + editor.mergeNodes({ at: { path: [1, 0], offset: 0 }, depth: 'block' }) +} + +export const output = ( + + onetwo + +) diff --git a/packages/slate/test/commands/mergeNodes/path/block.js b/packages/slate/test/commands/mergeNodes/path/block.js index b88e7ffb1e..5ca17cc314 100644 --- a/packages/slate/test/commands/mergeNodes/path/block.js +++ b/packages/slate/test/commands/mergeNodes/path/block.js @@ -10,7 +10,7 @@ export const input = ( ) export const run = editor => { - editor.mergeNodeAtPath([1]) + editor.mergeNodes({ at: [1] }) } export const output = ( diff --git a/packages/slate/test/commands/mergeNodes/path/text-across.js b/packages/slate/test/commands/mergeNodes/path/text-across.js new file mode 100644 index 0000000000..fb705142dc --- /dev/null +++ b/packages/slate/test/commands/mergeNodes/path/text-across.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + editor.mergeNodes({ at: [1, 0] }) +} + +export const output = ( + + onetwo + +) diff --git a/packages/slate/test/commands/splitNodes/height-block/after-inline-void.js b/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js similarity index 91% rename from packages/slate/test/commands/splitNodes/height-block/after-inline-void.js rename to packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js index 16804ae59b..8e0e532c17 100644 --- a/packages/slate/test/commands/splitNodes/height-block/after-inline-void.js +++ b/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/after-inline.js b/packages/slate/test/commands/splitNodes/depth-block/after-inline.js similarity index 90% rename from packages/slate/test/commands/splitNodes/height-block/after-inline.js rename to packages/slate/test/commands/splitNodes/depth-block/after-inline.js index 3bbfd99081..ddf7b252ca 100644 --- a/packages/slate/test/commands/splitNodes/height-block/after-inline.js +++ b/packages/slate/test/commands/splitNodes/depth-block/after-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/before-inline.js b/packages/slate/test/commands/splitNodes/depth-block/before-inline.js similarity index 92% rename from packages/slate/test/commands/splitNodes/height-block/before-inline.js rename to packages/slate/test/commands/splitNodes/depth-block/before-inline.js index 29b9cb3a12..3cfa2bb884 100644 --- a/packages/slate/test/commands/splitNodes/height-block/before-inline.js +++ b/packages/slate/test/commands/splitNodes/depth-block/before-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/block-end.js b/packages/slate/test/commands/splitNodes/depth-block/block-end.js similarity index 89% rename from packages/slate/test/commands/splitNodes/height-block/block-end.js rename to packages/slate/test/commands/splitNodes/depth-block/block-end.js index 9032811b9a..e959373c82 100644 --- a/packages/slate/test/commands/splitNodes/height-block/block-end.js +++ b/packages/slate/test/commands/splitNodes/depth-block/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/block-middle.js b/packages/slate/test/commands/splitNodes/depth-block/block-middle.js similarity index 87% rename from packages/slate/test/commands/splitNodes/height-block/block-middle.js rename to packages/slate/test/commands/splitNodes/depth-block/block-middle.js index 0d12abbf51..d506669e60 100644 --- a/packages/slate/test/commands/splitNodes/height-block/block-middle.js +++ b/packages/slate/test/commands/splitNodes/depth-block/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/block-start.js b/packages/slate/test/commands/splitNodes/depth-block/block-start.js similarity index 89% rename from packages/slate/test/commands/splitNodes/height-block/block-start.js rename to packages/slate/test/commands/splitNodes/depth-block/block-start.js index b693aaba9e..751b57d1a1 100644 --- a/packages/slate/test/commands/splitNodes/height-block/block-start.js +++ b/packages/slate/test/commands/splitNodes/depth-block/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/point.js b/packages/slate/test/commands/splitNodes/depth-block/point.js similarity index 78% rename from packages/slate/test/commands/splitNodes/height-block/point.js rename to packages/slate/test/commands/splitNodes/depth-block/point.js index 3a1e2bd1e2..661c2aa61a 100644 --- a/packages/slate/test/commands/splitNodes/height-block/point.js +++ b/packages/slate/test/commands/splitNodes/depth-block/point.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block', at: { path: [0, 0], offset: 2 } }) + editor.splitNodes({ depth: 'block', at: { path: [0, 0], offset: 2 } }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/with-inline.js b/packages/slate/test/commands/splitNodes/depth-block/with-inline.js similarity index 92% rename from packages/slate/test/commands/splitNodes/height-block/with-inline.js rename to packages/slate/test/commands/splitNodes/depth-block/with-inline.js index 8fe6fb352b..7b3b7fd4a3 100644 --- a/packages/slate/test/commands/splitNodes/height-block/with-inline.js +++ b/packages/slate/test/commands/splitNodes/depth-block/with-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-inline/block-end.js b/packages/slate/test/commands/splitNodes/depth-inline/block-end.js similarity index 91% rename from packages/slate/test/commands/splitNodes/height-inline/block-end.js rename to packages/slate/test/commands/splitNodes/depth-inline/block-end.js index c9aebf5a5f..f04c685ef4 100644 --- a/packages/slate/test/commands/splitNodes/height-inline/block-end.js +++ b/packages/slate/test/commands/splitNodes/depth-inline/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'inline' }) + editor.splitNodes({ depth: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-inline/block-middle.js b/packages/slate/test/commands/splitNodes/depth-inline/block-middle.js similarity index 91% rename from packages/slate/test/commands/splitNodes/height-inline/block-middle.js rename to packages/slate/test/commands/splitNodes/depth-inline/block-middle.js index 5f4914f638..13cf3810bb 100644 --- a/packages/slate/test/commands/splitNodes/height-inline/block-middle.js +++ b/packages/slate/test/commands/splitNodes/depth-inline/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'inline' }) + editor.splitNodes({ depth: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-inline/block-start.js b/packages/slate/test/commands/splitNodes/depth-inline/block-start.js similarity index 91% rename from packages/slate/test/commands/splitNodes/height-inline/block-start.js rename to packages/slate/test/commands/splitNodes/depth-inline/block-start.js index 6cfc4b37aa..f8360da9b0 100644 --- a/packages/slate/test/commands/splitNodes/height-inline/block-start.js +++ b/packages/slate/test/commands/splitNodes/depth-inline/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'inline' }) + editor.splitNodes({ depth: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height/one.js b/packages/slate/test/commands/splitNodes/depth/two.js similarity index 92% rename from packages/slate/test/commands/splitNodes/height/one.js rename to packages/slate/test/commands/splitNodes/depth/two.js index c250928541..d0a63c3e09 100644 --- a/packages/slate/test/commands/splitNodes/height/one.js +++ b/packages/slate/test/commands/splitNodes/depth/two.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 1 }) + editor.splitNodes({ depth: 2 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height/infinity.js b/packages/slate/test/commands/splitNodes/depth/zero.js similarity index 92% rename from packages/slate/test/commands/splitNodes/height/infinity.js rename to packages/slate/test/commands/splitNodes/depth/zero.js index ba1c16073e..6999cd0eac 100644 --- a/packages/slate/test/commands/splitNodes/height/infinity.js +++ b/packages/slate/test/commands/splitNodes/depth/zero.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: Infinity }) + editor.splitNodes({ depth: 0 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-inline/point.js b/packages/slate/test/commands/splitNodes/height-inline/point.js deleted file mode 100644 index 12afb4ad90..0000000000 --- a/packages/slate/test/commands/splitNodes/height-inline/point.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitNodes({ height: 'inline', at: { path: [0, 1, 0], offset: 2 } }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - wo - - - - rd - - - - -) diff --git a/packages/slate/test/commands/splitNodes/point/block.js b/packages/slate/test/commands/splitNodes/point/block.js index f261578ed0..45c3b77f76 100644 --- a/packages/slate/test/commands/splitNodes/point/block.js +++ b/packages/slate/test/commands/splitNodes/point/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ at: { path: [0, 0], offset: 2 }, height: 1 }) + editor.splitNodes({ at: { path: [0, 0], offset: 2 }, depth: 1 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/point/inline.js b/packages/slate/test/commands/splitNodes/point/inline.js index d2d6ae4e74..74daf5ad4a 100644 --- a/packages/slate/test/commands/splitNodes/point/inline.js +++ b/packages/slate/test/commands/splitNodes/point/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ at: { path: [0, 1, 0], offset: 2 }, height: 1 }) + editor.splitNodes({ at: { path: [0, 1, 0], offset: 2 }, depth: 2 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-inline/expanded.js b/packages/slate/test/commands/splitNodes/selection/expanded.js similarity index 91% rename from packages/slate/test/commands/splitNodes/height-inline/expanded.js rename to packages/slate/test/commands/splitNodes/selection/expanded.js index 114ff02972..579d616897 100644 --- a/packages/slate/test/commands/splitNodes/height-inline/expanded.js +++ b/packages/slate/test/commands/splitNodes/selection/expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'inline' }) + editor.splitNodes({ depth: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-inline/mark.js b/packages/slate/test/commands/splitNodes/selection/mark.js similarity index 92% rename from packages/slate/test/commands/splitNodes/height-inline/mark.js rename to packages/slate/test/commands/splitNodes/selection/mark.js index 3e6d3ea9eb..7310079217 100644 --- a/packages/slate/test/commands/splitNodes/height-inline/mark.js +++ b/packages/slate/test/commands/splitNodes/selection/mark.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'inline' }) + editor.splitNodes({ depth: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js similarity index 90% rename from packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks-and-inlines.js rename to packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js index 1aa697a204..1652c09f36 100644 --- a/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks-and-inlines.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( @@ -45,3 +45,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks.js b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js similarity index 83% rename from packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks.js rename to packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js index 88d0336a1b..5f291184f4 100644 --- a/packages/slate/test/commands/splitNodes/height-block/with-delete-across-blocks.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( @@ -25,3 +25,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/splitNodes/height-block/with-delete-hanging-selection.js b/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js similarity index 86% rename from packages/slate/test/commands/splitNodes/height-block/with-delete-hanging-selection.js rename to packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js index 815a6e7ebc..b28926f03b 100644 --- a/packages/slate/test/commands/splitNodes/height-block/with-delete-hanging-selection.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( @@ -29,3 +29,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/splitNodes/height-block/with-delete.js b/packages/slate/test/commands/splitNodes/selection/with-delete.js similarity index 81% rename from packages/slate/test/commands/splitNodes/height-block/with-delete.js rename to packages/slate/test/commands/splitNodes/selection/with-delete.js index 49865053ec..361355461d 100644 --- a/packages/slate/test/commands/splitNodes/height-block/with-delete.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ height: 'block' }) + editor.splitNodes({ depth: 'block' }) } export const input = ( @@ -22,3 +22,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/surroundNodes/block/block-across-nested.js b/packages/slate/test/commands/surroundNodes/block/block-across-nested.js new file mode 100644 index 0000000000..cf649a04f2 --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/block/block-across-nested.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes() +} + +export const input = ( + + + + word + + + another + + + +) + +export const output = ( + + + + + word + + + another + + + + +) diff --git a/packages/slate/test/commands/surroundNodes/block/block-across.js b/packages/slate/test/commands/surroundNodes/block/block-across.js new file mode 100644 index 0000000000..6008000cc2 --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/block/block-across.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes() +} + +export const input = ( + + + word + + + another + + +) + +export const output = ( + + + + word + + + another + + + +) diff --git a/packages/slate/test/commands/surroundNodes/block/block-nested.js b/packages/slate/test/commands/surroundNodes/block/block-nested.js new file mode 100644 index 0000000000..5b89d6f30a --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/block/block-nested.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes() +} + +export const input = ( + + + + word + + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/surroundNodes/block/block.js b/packages/slate/test/commands/surroundNodes/block/block.js new file mode 100644 index 0000000000..28e339213c --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/block/block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes() +} + +export const input = ( + + + word + + +) + +export const output = ( + + + + word + + + +) diff --git a/packages/slate/test/commands/surroundNodes/block/inline-across.js b/packages/slate/test/commands/surroundNodes/block/inline-across.js new file mode 100644 index 0000000000..8f4adbb24e --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/block/inline-across.js @@ -0,0 +1,47 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes() +} + +export const input = ( + + + + + word + + + + + + + another + + + + +) + +export const output = ( + + + + + + word + + + + + + + another + + + + + +) diff --git a/packages/slate/test/commands/surroundNodes/block/omit-nodes.js b/packages/slate/test/commands/surroundNodes/block/omit-nodes.js new file mode 100644 index 0000000000..90ceb88217 --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/block/omit-nodes.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes( + + + + + + ) +} + +export const input = ( + + + word + + + another + + +) + +export const output = ( + + + + word + + + another + + + +) diff --git a/packages/slate/test/commands/splitNodes/path/selection.js b/packages/slate/test/commands/surroundNodes/inline/inline-across.js similarity index 56% rename from packages/slate/test/commands/splitNodes/path/selection.js rename to packages/slate/test/commands/surroundNodes/inline/inline-across.js index 7751c7e650..018f125c37 100644 --- a/packages/slate/test/commands/splitNodes/path/selection.js +++ b/packages/slate/test/commands/surroundNodes/inline/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ at: [0, 2] }) + editor.surroundNodes() } export const input = ( @@ -11,11 +11,14 @@ export const input = ( - one + word + + + - two + another @@ -26,15 +29,23 @@ export const output = ( - - one + + + + word + + - - two + + + + another + + diff --git a/packages/slate/test/commands/surroundNodes/inline/inline.js b/packages/slate/test/commands/surroundNodes/inline/inline.js new file mode 100644 index 0000000000..5f22d30b54 --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/inline/inline.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes() +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + + + word + + + + + + +) diff --git a/packages/slate/test/commands/surroundNodes/inline/text.js b/packages/slate/test/commands/surroundNodes/inline/text.js new file mode 100644 index 0000000000..fe7e677f82 --- /dev/null +++ b/packages/slate/test/commands/surroundNodes/inline/text.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.surroundNodes() +} + +export const input = ( + + + word + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/wrapNodes/block/block-across.js b/packages/slate/test/commands/wrapNodes/block/block-across.js new file mode 100644 index 0000000000..d45c01dd62 --- /dev/null +++ b/packages/slate/test/commands/wrapNodes/block/block-across.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + editor.wrapNodes() +} + +export const output = ( + + + + one + + + two + + + +) diff --git a/packages/slate/test/commands/wrapNodes/block/block-end.js b/packages/slate/test/commands/wrapNodes/block/block-end.js new file mode 100644 index 0000000000..71fa38bb9d --- /dev/null +++ b/packages/slate/test/commands/wrapNodes/block/block-end.js @@ -0,0 +1,33 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + + two + + + three + + +) + +export const run = editor => { + editor.wrapNodes() +} + +export const output = ( + + one + + + two + + + three + + + +) diff --git a/packages/slate/test/commands/wrapNodes/block/block-middle.js b/packages/slate/test/commands/wrapNodes/block/block-middle.js new file mode 100644 index 0000000000..270b113a74 --- /dev/null +++ b/packages/slate/test/commands/wrapNodes/block/block-middle.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + + two + + three + +) + +export const run = editor => { + editor.wrapNodes() +} + +export const output = ( + + one + + + two + + + three + +) diff --git a/packages/slate/test/commands/splitNodes/point/selection.js b/packages/slate/test/commands/wrapNodes/block/block-start.js similarity index 58% rename from packages/slate/test/commands/splitNodes/point/selection.js rename to packages/slate/test/commands/wrapNodes/block/block-start.js index c53018a301..3a3539be2d 100644 --- a/packages/slate/test/commands/splitNodes/point/selection.js +++ b/packages/slate/test/commands/wrapNodes/block/block-start.js @@ -2,27 +2,28 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.splitNodes({ at: { path: [0, 0], offset: 2 }, height: 1 }) -} - export const input = ( - - word - + one + + two + + three ) +export const run = editor => { + editor.wrapNodes() +} + export const output = ( - - wo - - - rd + + + word + ) diff --git a/packages/slate/test/commands/wrapNodes/block/block.js b/packages/slate/test/commands/wrapNodes/block/block.js new file mode 100644 index 0000000000..41ce57f628 --- /dev/null +++ b/packages/slate/test/commands/wrapNodes/block/block.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + word + + +) + +export const run = editor => { + editor.wrapNodes() +} + +export const output = ( + + + + word + + + +) diff --git a/packages/slate/test/commands/wrapNodes/path/text.js b/packages/slate/test/commands/wrapNodes/selection/depth-text.js similarity index 77% rename from packages/slate/test/commands/wrapNodes/path/text.js rename to packages/slate/test/commands/wrapNodes/selection/depth-text.js index 8e2b8b5413..2e4ea72cb4 100644 --- a/packages/slate/test/commands/wrapNodes/path/text.js +++ b/packages/slate/test/commands/wrapNodes/selection/depth-text.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.wrapNodeAtPath([0, 0], ) + editor.wrapNodes(, { depth: -1 }) } export const input = ( @@ -17,7 +17,7 @@ export const input = ( export const output = ( - word + word ) From 9059fb3e4045ef364291ece5946d75673a747760 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 09:27:27 -0400 Subject: [PATCH 060/165] refactor node commands to use consistent matching logic --- packages/slate/src/classes/commands/node.ts | 905 ++++++++---------- packages/slate/src/classes/commands/path.ts | 14 - packages/slate/src/classes/commands/range.ts | 61 -- packages/slate/src/classes/commands/text.ts | 17 +- packages/slate/src/classes/commands/value.ts | 34 - packages/slate/src/classes/editor.ts | 6 - packages/slate/src/classes/queries/path.ts | 119 +-- packages/slate/src/classes/queries/point.ts | 22 +- packages/slate/src/classes/queries/value.ts | 213 +++-- packages/slate/src/interfaces/node.ts | 18 +- packages/slate/src/interfaces/path.ts | 17 +- packages/slate/src/interfaces/range.ts | 8 +- packages/slate/src/interfaces/value.ts | 27 +- .../liftNodes/selection/block-full.js | 2 +- .../liftNodes/selection/block-nested.js | 2 +- .../commands/mergeNodes/depth-block/block.js | 2 +- .../moveNodes/selection/block-nested-after.js | 6 +- .../selection/block-nested-before.js | 6 +- .../commands/moveNodes/selection/block.js | 2 +- .../commands/removeNodes/path/block-nested.js | 29 + .../test/commands/removeNodes/path/block.js | 20 + .../test/commands/removeNodes/path/inline.js | 29 + .../test/commands/removeNodes/path/text.js | 23 + .../removeNodes/selection/block-across.js | 27 + .../removeNodes/selection/block-all.js | 20 + .../commands/setNodes/block/block-across.js | 6 +- .../commands/setNodes/block/block-hanging.js | 4 +- .../commands/setNodes/block/block-nested.js | 6 +- .../commands/setNodes/block/block-void.js | 4 +- .../test/commands/setNodes/block/block.js | 4 +- .../commands/setNodes/inline/inline-across.js | 10 +- .../setNodes/inline/inline-hanging.js | 8 +- .../commands/setNodes/inline/inline-nested.js | 6 +- .../commands/setNodes/inline/inline-void.js | 4 +- .../test/commands/setNodes/inline/inline.js | 4 +- .../depth-block/after-inline-void.js | 2 +- .../splitNodes/depth-block/after-inline.js | 2 +- .../splitNodes/depth-block/before-inline.js | 2 +- .../splitNodes/depth-block/block-end.js | 2 +- .../splitNodes/depth-block/block-middle.js | 2 +- .../splitNodes/depth-block/block-start.js | 2 +- .../commands/splitNodes/depth-block/point.js | 2 +- .../splitNodes/depth-block/with-inline.js | 2 +- .../splitNodes/depth-inline/block-end.js | 2 +- .../splitNodes/depth-inline/block-middle.js | 2 +- .../splitNodes/depth-inline/block-start.js | 2 +- .../test/commands/splitNodes/depth/two.js | 2 +- .../test/commands/splitNodes/depth/zero.js | 2 +- .../test/commands/splitNodes/point/block.js | 2 +- .../test/commands/splitNodes/point/inline.js | 2 +- .../commands/splitNodes/selection/expanded.js | 4 +- .../commands/splitNodes/selection/mark.js | 2 +- .../with-delete-across-blocks-and-inlines.js | 2 +- .../selection/with-delete-across-blocks.js | 2 +- .../with-delete-hanging-selection.js | 2 +- .../splitNodes/selection/with-delete.js | 2 +- .../block/block-end.js} | 28 +- .../unwrapNodes/match-block/block-end.js | 4 +- .../unwrapNodes/match-block/block-middle.js | 4 +- .../unwrapNodes/match-block/block-nested.js | 4 +- .../unwrapNodes/match-block/block-start.js | 4 +- .../wrapBlock/selection/across-blocks.js | 35 - .../wrapBlock/selection/single-block.js | 29 - .../wrapInline/selection/across-blocks.js | 38 - .../wrapInline/selection/across-inlines.js | 41 - .../wrapInline/selection/collapsed.js | 30 - .../wrapInline/selection/inline-end.js | 41 - .../selection/inline-middle-with-marks.js | 52 - .../wrapInline/selection/inline-middle.js | 44 - .../wrapInline/selection/inline-start.js | 43 - .../wrapInline/selection/nested-block.js | 34 - .../wrapInline/selection/single-block.js | 30 - .../commands/wrapInline/selection/twice.js | 36 - .../wrapInline/selection/whole-block.js | 29 - .../wrapInline/selection/with-object.js | 33 - .../commands/wrapNodes/block/block-across.js | 14 +- .../commands/wrapNodes/block/block-end.js | 17 +- .../commands/wrapNodes/block/block-middle.js | 14 +- .../block/block-nested.js} | 20 +- .../commands/wrapNodes/block/block-start.js | 13 +- .../test/commands/wrapNodes/block/block.js | 4 +- .../inline/inline.js} | 22 +- .../wrapNodes/selection/depth-text.js | 16 +- .../test/interfaces/Node/descendants/path.js | 2 +- .../test/interfaces/Node/descendants/range.js | 2 +- .../Node/entries/path-multiple-elements.js | 2 +- .../Node/entries/path-of-element.js | 2 +- .../test/interfaces/Node/entries/path.js | 2 +- .../test/interfaces/Node/entries/range.js | 2 +- .../slate/test/interfaces/Node/marks/path.js | 2 +- .../slate/test/interfaces/Node/marks/range.js | 2 +- .../Node/texts/path-multiple-elements.js | 2 +- .../interfaces/Node/texts/path-of-element.js | 2 +- .../slate/test/interfaces/Node/texts/path.js | 2 +- .../slate/test/interfaces/Node/texts/range.js | 2 +- packages/slate/test/queries/blocks/at-path.js | 17 + .../slate/test/queries/blocks/at-range.js | 21 + .../test/queries/blocks/block-multiple.js | 2 +- .../slate/test/queries/blocks/block-nested.js | 2 +- .../test/queries/blocks/block-reverse.js | 2 +- .../slate/test/queries/blocks/block-void.js | 2 +- packages/slate/test/queries/blocks/block.js | 2 +- packages/slate/test/queries/blocks/inline.js | 2 +- .../test/queries/entries/block-multiple.js | 2 +- .../test/queries/entries/block-nested.js | 2 +- .../test/queries/entries/block-reverse.js | 2 +- .../slate/test/queries/entries/block-void.js | 2 +- packages/slate/test/queries/entries/block.js | 2 +- .../test/queries/entries/inline-multiple.js | 2 +- .../test/queries/entries/inline-nested.js | 2 +- .../test/queries/entries/inline-reverse.js | 2 +- .../slate/test/queries/entries/inline-void.js | 2 +- packages/slate/test/queries/entries/inline.js | 2 +- .../queries/getActiveMarks/block-across.js | 2 +- .../queries/getActiveMarks/block-start.js | 2 +- .../queries/getActiveMarks/inline-start.js | 2 +- .../queries/getActiveMarks/intersection.js | 2 +- .../test/queries/getActiveMarks/multiple.js | 2 +- .../slate/test/queries/getActiveMarks/none.js | 2 +- .../slate/test/queries/getActiveMarks/one.js | 2 +- .../queries/getActiveMarks/selection-marks.js | 2 +- .../queries/getActiveMarks/selection-null.js | 2 +- .../test/queries/getActiveMarks/text-start.js | 2 +- .../test/queries/getActiveMarks/union.js | 2 +- .../queries/getClosestBlock/block-nested.js | 2 +- .../test/queries/getClosestBlock/block.js | 2 +- .../test/queries/getClosestBlock/inline.js | 2 +- .../test/queries/getText/block-across.js | 2 +- .../slate/test/queries/getText/block-void.js | 2 +- packages/slate/test/queries/getText/block.js | 2 +- packages/slate/test/queries/getText/inline.js | 2 +- packages/slate/test/queries/getText/text.js | 2 +- .../test/queries/hasBlocks/block-nested.js | 2 +- .../slate/test/queries/hasBlocks/block.js | 2 +- .../test/queries/hasBlocks/inline-nested.js | 2 +- .../slate/test/queries/hasBlocks/inline.js | 2 +- .../test/queries/hasInlines/block-nested.js | 2 +- .../slate/test/queries/hasInlines/block.js | 2 +- .../test/queries/hasInlines/inline-nested.js | 2 +- .../slate/test/queries/hasInlines/inline.js | 2 +- .../test/queries/hasTexts/block-nested.js | 2 +- packages/slate/test/queries/hasTexts/block.js | 2 +- .../test/queries/hasTexts/inline-nested.js | 2 +- .../slate/test/queries/hasTexts/inline.js | 2 +- packages/slate/test/queries/inlines/block.js | 2 +- .../test/queries/inlines/inline-multiple.js | 2 +- .../test/queries/inlines/inline-nested.js | 2 +- .../test/queries/inlines/inline-reverse.js | 2 +- .../slate/test/queries/inlines/inline-void.js | 2 +- packages/slate/test/queries/inlines/inline.js | 2 +- .../slate/test/queries/isAtomic/atomic.js | 2 +- .../slate/test/queries/isAtomic/non-atomic.js | 2 +- packages/slate/test/queries/isInline/block.js | 2 +- .../test/queries/isInline/inline-void.js | 2 +- .../slate/test/queries/isInline/inline.js | 2 +- packages/slate/test/queries/isInline/text.js | 2 +- packages/slate/test/queries/isInline/value.js | 2 +- .../slate/test/queries/isVoid/block-void.js | 2 +- packages/slate/test/queries/isVoid/block.js | 2 +- .../slate/test/queries/isVoid/inline-void.js | 2 +- packages/slate/test/queries/isVoid/inline.js | 2 +- packages/slate/test/queries/isVoid/text.js | 2 +- packages/slate/test/queries/isVoid/value.js | 2 +- .../test/queries/leafBlocks/block-multiple.js | 2 +- .../test/queries/leafBlocks/block-nested.js | 2 +- .../test/queries/leafBlocks/block-reverse.js | 2 +- .../test/queries/leafBlocks/block-void.js | 2 +- .../slate/test/queries/leafBlocks/block.js | 2 +- .../slate/test/queries/leafBlocks/inline.js | 2 +- .../slate/test/queries/leafInlines/block.js | 2 +- .../queries/leafInlines/inline-multiple.js | 2 +- .../test/queries/leafInlines/inline-nested.js | 2 +- .../queries/leafInlines/inline-reverse.js | 2 +- .../test/queries/leafInlines/inline-void.js | 2 +- .../slate/test/queries/leafInlines/inline.js | 2 +- .../test/queries/rootBlocks/block-multiple.js | 2 +- .../test/queries/rootBlocks/block-nested.js | 2 +- .../test/queries/rootBlocks/block-reverse.js | 2 +- .../test/queries/rootBlocks/block-void.js | 2 +- .../slate/test/queries/rootBlocks/block.js | 2 +- .../slate/test/queries/rootBlocks/inline.js | 2 +- .../slate/test/queries/rootInlines/block.js | 2 +- .../queries/rootInlines/inline-multiple.js | 2 +- .../test/queries/rootInlines/inline-nested.js | 2 +- .../queries/rootInlines/inline-reverse.js | 2 +- .../test/queries/rootInlines/inline-void.js | 2 +- .../slate/test/queries/rootInlines/inline.js | 2 +- .../test/queries/texts/block-multiple.js | 2 +- .../slate/test/queries/texts/block-nested.js | 2 +- .../slate/test/queries/texts/block-reverse.js | 2 +- .../slate/test/queries/texts/block-void.js | 2 +- packages/slate/test/queries/texts/block.js | 2 +- .../test/queries/texts/inline-multiple.js | 2 +- .../slate/test/queries/texts/inline-nested.js | 2 +- .../test/queries/texts/inline-reverse.js | 2 +- .../slate/test/queries/texts/inline-void.js | 2 +- packages/slate/test/queries/texts/inline.js | 2 +- 197 files changed, 1066 insertions(+), 1604 deletions(-) delete mode 100755 packages/slate/src/classes/commands/path.ts delete mode 100755 packages/slate/src/classes/commands/range.ts create mode 100644 packages/slate/test/commands/removeNodes/path/block-nested.js create mode 100644 packages/slate/test/commands/removeNodes/path/block.js create mode 100644 packages/slate/test/commands/removeNodes/path/inline.js create mode 100644 packages/slate/test/commands/removeNodes/path/text.js create mode 100644 packages/slate/test/commands/removeNodes/selection/block-across.js create mode 100644 packages/slate/test/commands/removeNodes/selection/block-all.js rename packages/slate/test/commands/{wrapBlock/selection/across-inlines.js => surroundNodes/block/block-end.js} (52%) delete mode 100644 packages/slate/test/commands/wrapBlock/selection/across-blocks.js delete mode 100644 packages/slate/test/commands/wrapBlock/selection/single-block.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/across-blocks.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/across-inlines.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/collapsed.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/inline-end.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/inline-middle-with-marks.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/inline-middle.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/inline-start.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/nested-block.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/single-block.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/twice.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/whole-block.js delete mode 100644 packages/slate/test/commands/wrapInline/selection/with-object.js rename packages/slate/test/commands/{wrapBlock/selection/nested-block.js => wrapNodes/block/block-nested.js} (59%) rename packages/slate/test/commands/{wrapInline/selection/inline-void.js => wrapNodes/inline/inline.js} (60%) create mode 100644 packages/slate/test/queries/blocks/at-path.js create mode 100644 packages/slate/test/queries/blocks/at-range.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index cc64ca8771..6dea61fbc2 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -1,52 +1,42 @@ -import { produce } from 'immer' import { Descendant, - ElementEntry, - PathRef, Editor, - Fragment, Node, NodeEntry, - RangeRef, Element, Path, Text, Range, - Value, Point, } from '../..' +type AtOption = Range | Point | Path + +type MatchOption = + | number + | 'value' + | 'block' + | 'inline' + | 'text' + | Partial + | ((entry: NodeEntry) => boolean) + class NodeCommands { /** - * Insert a node (or nodes) at a specific location in the editor. - * - * The `at` option can be: - * - * - Omitted and the editor's current selection will be used as a range. - * - * - A `Range` and the range's content will be deleted, and then the collapsed - * range will be used as a point. - * - * - A `Point` and the nodes up to a certain height will be split, and then - * the node will be inserted at the correct path. The height is determined - * by what kind of node you insert. Blocks are inserted at as leaf blocks. - * Inlines are inserted as root inlines. And texts are inserted at leaf - * nodes. You can override the default by passing the `height` option. - * - * - A `Path` and the node will be inserted at the specific path. + * Insert nodes at a specific location in the editor. */ insertNodes( this: Editor, nodes: Node | Node[], options: { - at?: Range | Point | Path - depth?: number | 'block' | 'inline' + at?: AtOption + match?: MatchOption } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, depth } = options + let { at, match } = options let select = false if (Node.isNode(nodes)) { @@ -59,14 +49,14 @@ class NodeCommands { const [node] = nodes - // If the depth isn't explicitly set, infer it from the node. - if (depth == null) { + // If the match isn't explicitly set, infer it from the node. + if (match == null) { if (Text.isText(node)) { - depth = -1 + match = 'text' } else if (this.isInline(node)) { - depth = 'inline' + match = 'inline' } else { - depth = 'block' + match = 'block' } } @@ -90,14 +80,18 @@ class NodeCommands { } if (Point.isPoint(at)) { - depth = this.getDepth(at.path, depth) - const topPath = at.path.slice(0, depth) - const isAtEnd = this.isAtEnd(at, topPath) - const pointRef = this.createPointRef(at) - this.splitNodes({ at, depth, always: false }) - const point = pointRef.unref()! - const path = point.path.slice(0, depth) - at = isAtEnd ? Path.next(path) : path + const atMatch = this.getMatch(at.path, match) + + if (atMatch) { + const [, matchPath] = atMatch + const pathRef = this.createPathRef(matchPath) + const isAtEnd = this.isAtEnd(at, matchPath) + this.splitNodes({ at, match, always: false }) + const path = pathRef.unref()! + at = isAtEnd ? Path.next(path) : path + } else { + return + } } const parentPath = Path.parent(at) @@ -124,187 +118,183 @@ class NodeCommands { } /** - * Unwrap a single node from its parent. - * - * If the node is surrounded with siblings, its parent will be split. If the - * node is the only child, the parent is removed, and simply replaced by the - * node itself. + * Lift nodes at a specific location upwards in the document tree, splitting + * their parent in two if necessary. */ liftNodes( this: Editor, options: { - at?: Range | Point | Path - depth?: number + at?: AtOption + match?: MatchOption } ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, depth = 2 } = options + const { at = selection, match = 'block' } = options - if (depth < 2) { - throw new Error( - `Cannot lift nodes at a depth of less than \`2\`, but you passed depth: \`${depth}\`` - ) - } - - if (!at && selection) { - at = selection + if (!at) { + return } - if (Path.isPath(at)) { - depth = at.length - at = this.getRange(at) - } + const matches = this.matches({ at, match }) + const pathRefs = Array.from(matches, ([, p]) => this.createPathRef(p)) - if (Point.isPoint(at)) { - at = { anchor: at, focus: at } - } + for (const pathRef of pathRefs) { + const path = pathRef.unref()! - if (!Range.isRange(at)) { - return - } + if (path.length < 2) { + throw new Error( + `Cannot lift node at a path [${path}] because it has a depth of less than \`2\`.` + ) + } - const [start, end] = Range.points(at) - const [, commonPath] = this.getCommon(start.path, end.path) - const parentPath = commonPath.slice(0, depth - 1) - const parent = this.getNode(parentPath) - const startIndex = start.path[parentPath.length] - const endIndex = end.path[parentPath.length] - const { length } = parent.nodes - - if (endIndex - startIndex + 1 === length) { - this.pluckNodes({ at: parentPath }) - } else if (startIndex === 0) { - this.moveNodes({ at, depth, to: parentPath }) - } else if (endIndex === length - 1) { - this.moveNodes({ at, depth, to: Path.next(parentPath) }) - } else { - const newPath = Path.next(parentPath) - this.splitNodes({ at: parentPath.concat(endIndex + 1) }) - this.moveNodes({ at, depth: parentPath.length + 1, to: newPath }) + const parentPath = Path.parent(path) + const parent = this.getParent(path) + const index = path[path.length - 1] + const { length } = parent.nodes + + if (length === 1) { + this.pluckNodes({ at: parentPath }) + } else if (index === 0) { + this.moveNodes({ at: path, to: parentPath }) + } else if (index === length - 1) { + this.moveNodes({ at: path, to: Path.next(parentPath) }) + } else { + this.splitNodes({ at: Path.next(path) }) + this.moveNodes({ at: path, to: Path.next(parentPath) }) + } } }) } /** - * Merge the nodes at a specific location. + * Merge a node at a location with the previous node of the same depth, + * removing any empty containing nodes after the merge if necessary. */ mergeNodes( this: Editor, options: { - at?: Path | Point | Range - depth?: number | 'block' | 'inline' + at?: AtOption + match?: MatchOption } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, depth } = options + const { match = 'block' } = options + let { at } = options - if (!at && selection) { - at = selection + if (!at) { + if (selection) { + at = selection + } else { + return + } } - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } else if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! - } else if (Path.isPath(at)) { - depth = at.length - at = this.getStart(at) - } + if (Range.isRange(at)) { + if (Range.isCollapsed(at)) { + at = at.anchor + } else { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! - if (!Point.isPoint(at)) { - return + if (options.at == null) { + this.select(at) + } + } } - const fromDepth = this.getDepth(at.path, depth) - const path = at.path.slice(0, fromDepth) - const node = this.getNode(path) - const prevText = this.getPreviousText(path) + for (const [node, path] of this.matches({ at, match })) { + const prevText = this.getPreviousText(path) - if (!prevText) { - return - } + if (!prevText) { + continue + } - const [, prevTextPath] = prevText - const prevDepth = this.getDepth(prevTextPath, depth) - const prevPath = prevTextPath.slice(0, prevDepth) - const prevNode = this.getNode(prevPath) - const newPath = Path.next(prevPath) - const commonPath = Path.common(path, prevPath) - const isPreviousSibling = Path.isSibling(path, prevPath) - - // Determine if the merge will leave an ancestor of the path empty as a - // result, in which case we'll want to remove it after merging. - const emptyAncestor = Node.furthest(this.value, path, ([n, p]) => { - return ( - Path.isDescendant(p, commonPath) && - Path.isAncestor(p, path) && - Element.isElement(n) && - n.nodes.length === 1 - ) - }) + const [, prevTextPath] = prevText + const prevMatcher = Path.isPath(at) ? at.length : match + const prevMatch = this.getMatch(prevTextPath, prevMatcher) - const emptyRef = emptyAncestor && this.createPathRef(emptyAncestor[1]) - let properties - let position + if (!prevMatch) { + return + } - // Ensure that the nodes are equivalent, and figure out what the position - // and extra properties of the merge will be. - if (Text.isText(node) && Text.isText(prevNode)) { - const { text, marks, ...rest } = node - position = prevNode.text.length - properties = rest as Partial - } else if (Element.isElement(node) && Element.isElement(prevNode)) { - const { nodes, ...rest } = node - position = prevNode.nodes.length - properties = rest as Partial - } else { - throw new Error( - `Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify( - node - )} ${JSON.stringify(prevNode)}` - ) - } + const [prevNode, prevPath] = prevMatch + const newPath = Path.next(prevPath) + const commonPath = Path.common(path, prevPath) + const isPreviousSibling = Path.isSibling(path, prevPath) + + // Determine if the merge will leave an ancestor of the path empty as a + // result, in which case we'll want to remove it after merging. + const emptyAncestor = Node.furthest(this.value, path, ([n, p]) => { + return ( + Path.isDescendant(p, commonPath) && + Path.isAncestor(p, path) && + Element.isElement(n) && + n.nodes.length === 1 + ) + }) - // If the node isn't already the next sibling of the previous node, move - // it so that it is before merging. - if (!isPreviousSibling) { - this.moveNodes({ at: path, to: newPath }) - } + const emptyRef = emptyAncestor && this.createPathRef(emptyAncestor[1]) + let properties + let position - // If there was going to be an empty ancestor of the node that was merged, - // we remove it from the tree. - if (emptyRef) { - this.removeNodes({ at: emptyRef.current! }) - } + // Ensure that the nodes are equivalent, and figure out what the position + // and extra properties of the merge will be. + if (Text.isText(node) && Text.isText(prevNode)) { + const { text, marks, ...rest } = node + position = prevNode.text.length + properties = rest as Partial + } else if (Element.isElement(node) && Element.isElement(prevNode)) { + const { nodes, ...rest } = node + position = prevNode.nodes.length + properties = rest as Partial + } else { + throw new Error( + `Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify( + node + )} ${JSON.stringify(prevNode)}` + ) + } - // If the target node that we're merging with is empty, remove it instead - // of merging the two. This is a common rich text editor behavior to - // prevent losing formatting when deleting entire nodes when you have a - // hanging selection. - if ( - (Element.isElement(prevNode) && this.isEmpty(prevNode)) || - (Text.isText(prevNode) && prevNode.text === '') - ) { - this.removeNodes({ at: prevPath }) - } else { - this.apply({ - type: 'merge_node', - path: newPath, - position, - target: null, - properties, - }) - } + // If the node isn't already the next sibling of the previous node, move + // it so that it is before merging. + if (!isPreviousSibling) { + this.moveNodes({ at: path, to: newPath }) + } + + // If there was going to be an empty ancestor of the node that was merged, + // we remove it from the tree. + if (emptyRef) { + this.removeNodes({ at: emptyRef.current! }) + } - if (emptyRef) { - emptyRef.unref() + // If the target node that we're merging with is empty, remove it instead + // of merging the two. This is a common rich text editor behavior to + // prevent losing formatting when deleting entire nodes when you have a + // hanging selection. + if ( + (Element.isElement(prevNode) && this.isEmpty(prevNode)) || + (Text.isText(prevNode) && prevNode.text === '') + ) { + this.removeNodes({ at: prevPath }) + } else { + this.apply({ + type: 'merge_node', + path: newPath, + position, + target: null, + properties, + }) + } + + if (emptyRef) { + emptyRef.unref() + } } }) } @@ -316,67 +306,51 @@ class NodeCommands { moveNodes( this: Editor, options: { - at?: Range | Point | Path - depth?: number + at?: AtOption + match?: MatchOption to: Path } ) { this.withoutNormalizing(() => { const { selection } = this.value - const { to } = options + const { to, match = 'block' } = options const newIndex = to[to.length - 1] - let { at, depth } = options - let isSelection = false + let { at } = options + let selectRef if (newIndex > 0 && !this.hasNode(Path.previous(to))) { throw new Error( - `Cannot move the node at path [${at}] to new path [${to}] because the index is out of range.` - ) - } else if (depth != null && depth < 1) { - throw new Error( - `Cannot move nodes at a depth less than \`1\`, but you passed depth: \`${depth}\`` + `Cannot move nodes to new path [${to}] because the index is out of range.` ) } - if (!at && selection) { - at = selection - isSelection = true - } else if (Path.isPath(at)) { - depth = at.length - at = this.getRange(at) - } else if (Point.isPoint(at)) { - at = { anchor: at, focus: at } - } else if (!Range.isRange(at)) { - return - } - - const [start, end] = Range.points(at) - const rangeRef = this.createRangeRef(at) - const commonPath = Path.common(start.path, end.path) - - if (depth == null) { - depth = commonPath.length + 1 + if (!at) { + if (selection) { + at = selection + selectRef = this.createRangeRef(at) + } else { + return + } } - const parentPath = commonPath.slice(0, depth - 1) - const startIndex = start.path[parentPath.length] - const endIndex = end.path[parentPath.length] const toRef = this.createPathRef(to) - const parentRef = this.createPathRef(parentPath) + const targets = this.matches({ at, match }) + const pathRefs = Array.from(targets, ([, p]) => this.createPathRef(p)) - for (let i = endIndex; i >= startIndex; i--) { - this.apply({ - type: 'move_node', - path: parentRef.current!.concat(startIndex), - newPath: toRef.current!, - }) + for (const pathRef of pathRefs) { + const path = pathRef.unref()! + const newPath = toRef.current! + + if (path.length !== 0) { + this.apply({ type: 'move_node', path, newPath }) + } } - if (isSelection && rangeRef.current) { - this.select(rangeRef.current) + if (selectRef) { + this.select(selectRef.current!) } - rangeRef.unref() + toRef.unref() }) } @@ -468,117 +442,99 @@ class NodeCommands { } /** - * Removing a node at a path, replacing it with its children. + * Remove a node at a specific location, replacing it with its children. */ pluckNodes( this: Editor, options: { - at?: Path | Range - match?: Partial | ((entry: ElementEntry) => boolean) + at?: AtOption + match?: MatchOption } ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, match = () => true } = options - - if (!at && selection) { - at = selection - } - - if (Path.isPath(at)) { - const path = at - match = ([n, p]: NodeEntry) => Path.equals(p, path) - at = this.getRange(at) - } + const { match = 'block' } = options + let { at } = options - if (typeof match === 'object') { - const props = match - match = ([n]: NodeEntry) => - Element.isElement(n) && Element.matches(n, props) - } - - if (typeof match !== 'function') { - throw new Error( - `The \`match\` option to \`editor.pluckNodes()\` should be a function or a properties object to match.` - ) - } - - for (const [node, path] of this.elements({ at })) { - if (!match([node, path])) { - continue + if (!at) { + if (selection) { + at = selection + } else { + return } + } - this.moveNodes({ - at: this.getRange(path), - depth: path.length + 1, - to: Path.next(path), - }) + const matches = this.matches({ at, match }) + const pathRefs = Array.from(matches, ([, p]) => this.createPathRef(p)) + for (const pathRef of pathRefs) { + const path = pathRef.unref()! + const range = this.getRange(path) + const depth = path.length + 1 + const to = Path.next(path) + this.moveNodes({ at: range, match: depth, to }) this.removeNodes({ at: path }) } }) } /** - * Remove the node at a path. + * Remove the nodes at a specific location in the document. */ - removeNodes(this: Editor, options: { at: Path }) { - const { at } = options - const node = this.getNode(at) - this.apply({ type: 'remove_node', path: at, node }) - } - - /** - * Set new properties on nodes in the editor. - */ - - setNodes( + removeNodes( this: Editor, - props: Partial, options: { - at?: Path | Point | Range - match?: 'block' | 'inline' | ((entry: NodeEntry) => boolean) + at?: AtOption + match?: MatchOption } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, match = () => true } = options + const { match = 'block' } = options + let { at } = options - if (match === 'block') { - match = ([n]: NodeEntry) => Element.isElement(n) && !this.isInline(n) - } else if (match === 'inline') { - match = ([n]: NodeEntry) => Element.isElement(n) && this.isInline(n) + if (!at) { + if (selection) { + at = selection + } else { + return + } } - if (!at && selection) { - at = selection - } + const depths = this.matches({ at, match }) + const pathRefs = Array.from(depths, ([, p]) => this.createPathRef(p)) - if (Path.isPath(at)) { - const path = at - match = ([n, p]: NodeEntry) => Path.equals(p, path) - at = this.getRange(path) + for (const pathRef of pathRefs) { + const path = pathRef.unref()! + const node = this.getNode(path) + this.apply({ type: 'remove_node', path, node }) } + }) + } - if (Point.isPoint(at)) { - const point = at - match = ([n, p]: NodeEntry) => Path.equals(p, point.path) - at = { anchor: point, focus: point } - } + /** + * Set new properties on the nodes ... + */ - if (!Range.isRange(at)) { + setNodes( + this: Editor, + props: Partial, + options: { + at?: AtOption + match?: MatchOption + hanging?: boolean + } = {} + ) { + this.withoutNormalizing(() => { + const { at = this.value.selection, match = 'block' } = options + + if (!at) { return } - at = this.getNonHangingRange(at) - - for (const [node, path] of this.entries({ at })) { - if (!match([node, path])) { - continue - } - + for (const [node, path] of this.matches({ at, match })) { const properties: Partial = {} const newProperties: Partial = {} @@ -599,17 +555,14 @@ class NodeCommands { } } - // If no properties have changed don't apply an operation at all. - if (Object.keys(newProperties).length === 0) { - continue + if (Object.keys(newProperties).length !== 0) { + this.apply({ + type: 'set_node', + path, + properties, + newProperties, + }) } - - this.apply({ - type: 'set_node', - path, - properties, - newProperties, - }) } }) } @@ -621,284 +574,228 @@ class NodeCommands { splitNodes( this: Editor, options: { - at?: Path | Point | Range + at?: AtOption + match?: MatchOption always?: boolean - depth?: 'block' | 'inline' | number height?: number } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value - const { always = true } = options - let { at, depth = -1, height = 0 } = options - let isSelection = false - let maxDepth = Infinity - let position: number | null = null - - if (!at && selection) { - at = selection - isSelection = true - } + const { always = true, match = 'block' } = options + let { at, height = 0 } = options + let target: number | null = null + let position + let selectRef + let edgeRef + let firstPath - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor + if (!at) { + if (selection) { + const [, end] = Range.points(selection) + selectRef = this.createPointRef(end) + at = selection + } else { + return + } } if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! + if (Range.isCollapsed(at)) { + at = at.anchor + } else { + const [, end] = Range.points(at) + const pointRef = this.createPointRef(end) + this.delete({ at }) + at = pointRef.unref()! + } } + // If the target is a path, the default height-skipping and position + // counters need to account for us potentially splitting at a non-leaf. if (Path.isPath(at)) { - const first = this.getFirstText(at) - - if (!first) { - return - } - - const [, firstPath] = first - debugger - height = firstPath.length - at.length + 1 + const [, p] = Node.first(this.value, at) + firstPath = p + height = p.length - at.length + 1 position = at[at.length - 1] - maxDepth = at.length - 1 - at = { path: firstPath, offset: 0 } - debugger - } - - if (!Point.isPoint(at)) { - return - } - - const { path, offset } = at - const furthestVoid = this.getFurthestVoid(path) - let pos = position == null ? offset : position - let target: number | null = null - - // If the point it inside a void node, we still want to split up to a - // `height`, but we need to start after the void node in the tree. - if (furthestVoid) { - const [, voidPath] = furthestVoid - const relPath = Path.relative(path, voidPath) - height = Math.max(relPath.length + 1, height) - pos = voidPath[voidPath.length - 1] + at = at.slice(0, -1) + } else { + firstPath = at.path + position = at.offset + edgeRef = this.createPointRef(at, { stick: 'backward' }) } - const outsideRef = this.createPointRef(at) - const insideRef = this.createPointRef(at, { stick: 'backward' }) - let d = path.length - height - depth = this.getDepth(path, depth) - depth = Math.min(depth, maxDepth) + let d = firstPath.length - height - while (d >= depth) { - debugger - const p = path.slice(0, d) - d-- + for (const [, path] of this.matches({ at, match })) { + while (d >= path.length && d > 0) { + const p = firstPath.slice(0, d) + d-- - if (p.length === 0) { - break - } + // With the `always: false` option, we will instead split the nodes only + // when the point isn't already at it's edge. + if ( + !always && + edgeRef && + edgeRef.current && + this.isAtEdge(edgeRef.current, p) + ) { + continue + } - // With the `always: false` option, we will instead split the nodes only - // when the point isn't already at it's edge. - if ( - !always && - insideRef.current != null && - this.isAtEdge(insideRef.current, p) - ) { - continue - } + const node = this.getNode(p) + const { text, marks, nodes, ...properties } = node - const node = this.getNode(p) - let properties + this.apply({ + type: 'split_node', + path: p, + position, + target, + properties, + }) - if (Text.isText(node)) { - const { text, marks, ...rest } = node - properties = rest - } else { - const { nodes, ...rest } = node - properties = rest + target = position + position = firstPath[d] + 1 } - - this.apply({ - type: 'split_node', - path: p, - position: pos, - target, - properties, - }) - - target = pos - pos = path[d] + 1 } - if (isSelection) { - const point = outsideRef.current! - this.select(point) + if (selectRef) { + this.select(selectRef.current!) + selectRef.unref() } - outsideRef.unref() + if (edgeRef) { + edgeRef.unref() + } }) } + /** + * Surround the nodes at a location with a new parent node. + */ + surroundNodes( this: Editor, element: Element, options: { - at?: Path | Point | Range - depth?: 'block' | 'inline' | number + at?: AtOption + match?: MatchOption } = {} ) { this.withoutNormalizing(() => { const { selection } = this.value - let { at, depth } = options - - // Convert the possibilities for `at` into a range. - if (!at && selection) { - at = selection - } else if (Path.isPath(at)) { - depth = at.length - at = this.getRange(at) - } else if (Point.isPoint(at)) { - at = { anchor: at, focus: at } - } else if (!Range.isRange(at)) { - return - } + const { match = this.isInline(element) ? 'inline' : 'block' } = options + let { at } = options - const isInline = this.isInline(element) - let range = at - let minDepth = 0 - - if (depth == null) { - depth = isInline ? 'inline' : 'block' + if (!at) { + if (selection) { + at = selection + } else { + return + } } - const surround = () => { - const [start, end] = Range.points(range) - const startDepth = this.getDepth(start.path, depth) - const endDepth = this.getDepth(start.path, depth) - const commonPath = Path.common(start.path, end.path) - let d = Math.min(startDepth - 1, endDepth - 1, commonPath.length) - d = Math.max(minDepth, d) - const path = commonPath.slice(0, d) - const firstPath = path.concat(0) - const target = this.getRange(path) - const targetRef = this.createRangeRef(target) - const container = { ...element, nodes: [] } - - this.insertNodes(container, { at: firstPath }) - + for (const [, , matches] of this.batches({ + element, + at, + match, + })) { + const [first] = matches + const last = matches[matches.length - 1] + const [, firstPath] = first + const [, lastPath] = last + const commonPath = Path.equals(firstPath, lastPath) + ? Path.parent(firstPath) + : Path.common(firstPath, lastPath) + + const range = this.getRange(firstPath, lastPath) + const depth = commonPath.length + 1 + const wrapperPath = Path.next(lastPath).slice(0, depth) + const wrapper = { ...element, nodes: [] } + this.insertNodes(wrapper, { at: wrapperPath }) this.moveNodes({ - at: targetRef.current!, - depth: path.length + 1, - to: firstPath.concat(0), + at: range, + match: depth, + to: wrapperPath.concat(0), }) - - targetRef.unref() - } - - if (!isInline) { - surround() - } else { - for (const [, blockPath] of this.leafBlocks({ at })) { - range = Range.intersection(at, this.getRange(blockPath)) - const [start, end] = Range.points(range) - const startDepth = this.getDepth(start.path, 'inline') - 1 - const endDepth = this.getDepth(end.path, 'inline') - 1 - minDepth = Math.min(startDepth, endDepth) - surround() - } } }) } /** - * Unwrap the leaf nodes from the closest matching parent. + * Unwrap the nodes at a location from a parent node, splitting the parent if + * necessary to ensure that only the content in the range is unwrapped. */ unwrapNodes( this: Editor, options: { - at?: Path | Range - match?: Partial | ((entry: ElementEntry) => boolean) + at?: AtOption + match?: MatchOption } ) { this.withoutNormalizing(() => { - const { selection } = this.value - let { at = selection, match = () => true } = options + const { at = this.value.selection, match = 'block' } = options - if (Path.isPath(at)) { - const path = at - match = ([n, p]: ElementEntry) => Path.equals(p, path) - at = this.getRange(at) - } - - if (typeof match === 'object') { - const props = match - match = ([n]: ElementEntry) => Element.matches(n, props) - } - - if (typeof match !== 'function') { - throw new Error( - `The \`match\` option to \`editor.pluckNodes()\` should be a function or a properties object to match.` - ) - } - - if (!Range.isRange(at)) { + if (!at) { return } - const matches: [RangeRef, number][] = [] + const matches = this.matches({ at, match }) + const pathRefs = Array.from(matches, ([, p]) => this.createPathRef(p)) - for (const [node, path] of this.elements({ at })) { - if (match([node, path])) { - const range = this.getRange(path) - const intersection = Range.intersection(at, range) - const rangeRef = this.createRangeRef(intersection) - const depth = path.length + 1 - matches.push([rangeRef, depth]) - } - } + for (const pathRef of pathRefs) { + const path = pathRef.unref()! + const depth = path.length + 1 + const a = Range.isRange(at) + ? Range.intersection(at, this.getRange(path))! + : at - for (const [rangeRef, depth] of matches) { - if (rangeRef.current) { - this.liftNodes({ at: rangeRef.current, depth }) - } - - rangeRef.unref() + this.liftNodes({ at: a, match: depth }) } }) } + /** + * Wrap the nodes at a location in a new container node, splitting the edges + * of the range first to ensure that only the content in the range is wrapped. + */ + wrapNodes( this: Editor, element: Element, options: { - at?: Path | Point | Range - depth?: 'block' | 'inline' | number + at?: AtOption + match?: MatchOption } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - let { at, depth } = options - - // Convert the possibilities for `at` into a range. - if (!at && selection) { - at = selection - } else if (Path.isPath(at)) { - depth = at.length - at = this.getRange(at) - } else if (Point.isPoint(at)) { - at = { anchor: at, focus: at } - } else if (!Range.isRange(at)) { + const { match = this.isInline(element) ? 'inline' : 'block' } = options + let { at = this.value.selection } = options + + if (!at) { return } - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - this.splitNodes({ at, always: false, depth }) - const range = rangeRef.unref()! - this.surroundNodes(element, { at: range, depth }) + let rangeRef + + if (Range.isRange(at)) { + const [start, end] = Range.points(at) + rangeRef = this.createRangeRef(at, { stick: 'inward' }) + this.splitNodes({ at: end, always: false, match }) + this.splitNodes({ at: start, always: false, match }) + at = rangeRef.current! + + if (options.at == null) { + this.select(at) + } + } + + this.surroundNodes(element, { at, match }) + + if (rangeRef) { + rangeRef.unref() + } }) } } diff --git a/packages/slate/src/classes/commands/path.ts b/packages/slate/src/classes/commands/path.ts deleted file mode 100755 index aadfd729bb..0000000000 --- a/packages/slate/src/classes/commands/path.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Editor, Element, Path } from '../..' - -class PathCommands { - wrapNodeAtPath(this: Editor, path: Path, element: Element): void { - this.withoutNormalizing(() => { - this.insertNodes(element, { at: path }) - const nextPath = Path.next(path) - const childPath = path.concat(0) - this.moveNodes({ at: nextPath, to: childPath }) - }) - } -} - -export default PathCommands diff --git a/packages/slate/src/classes/commands/range.ts b/packages/slate/src/classes/commands/range.ts deleted file mode 100755 index a4ebdbd243..0000000000 --- a/packages/slate/src/classes/commands/range.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Editor, Element, Path, Range } from '../..' - -class RangeCommands { - wrapBlockAtRange(this: Editor, range: Range, block: Element) { - this.withoutNormalizing(() => { - const [start] = Range.points(range) - const [, end] = Range.points(range) - - const startClosest = this.getClosestBlock(start.path) - const endClosest = this.getClosestBlock(end.path) - - if (startClosest && endClosest) { - const [, startPath] = startClosest - const [, endPath] = endClosest - const ancestorPath = Path.common(startPath, endPath) - const startIndex = startPath[ancestorPath.length] - const endIndex = endPath[ancestorPath.length] - const targetPath = ancestorPath.concat([startIndex]) - this.insertNodeAtPath(targetPath, block) - - for (let i = 0; i <= endIndex - startIndex; i++) { - const path = ancestorPath.concat(startIndex + 1) - const newPath = ancestorPath.concat([startIndex, i]) - this.moveNodeAtPath(path, newPath) - } - } - }) - } - - wrapInlineAtRange(this: Editor, range: Range, inline: Element) { - this.withoutNormalizing(() => { - const rangeRef = this.createRangeRef(range, { stick: 'inward' }) - const [splitStart, splitEnd] = Range.points(range) - this.splitInlineAtPoint(splitStart, { always: false }) - this.splitInlineAtPoint(splitEnd, { always: false }) - - range = rangeRef.current! - const [start, end] = Range.points(range) - - for (const [block, blockPath] of this.leafBlocks({ at: range })) { - const isStart = Path.isAncestor(blockPath, start.path) - const isEnd = Path.isAncestor(blockPath, end.path) - const startIndex = isStart ? start.path[blockPath.length] : 0 - const endIndex = isEnd - ? end.path[blockPath.length] - : block.nodes.length - 1 - - const targetPath = blockPath.concat([startIndex]) - this.insertNodeAtPath(targetPath, inline) - - for (let i = 0; i <= endIndex - startIndex; i++) { - const path = blockPath.concat(startIndex + 1) - const newPath = blockPath.concat([startIndex, i]) - this.moveNodeAtPath(path, newPath) - } - } - }) - } -} - -export default RangeCommands diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index b773658a88..1d6eb89184 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -60,23 +60,20 @@ class DeletingCommands { if (Range.isRange(at)) { const [start, end] = Range.points(at) - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) const [common, commonPath] = this.getCommon(start.path, end.path) - let startHeight = start.path.length - commonPath.length - 1 - let endHeight = end.path.length - commonPath.length - 1 + let ancestorPath = commonPath + let ancestor = common + let d: number | 'text' = commonPath.length if (Path.equals(start.path, end.path)) { ancestorPath = Path.parent(commonPath) ancestor = Node.get(this.value, ancestorPath) - startHeight = 0 - endHeight = 0 - } else { - ancestorPath = commonPath - ancestor = common + d = 'text' } - this.splitNodes({ at: end, height: Math.max(0, endHeight) }) - this.splitNodes({ at: start, height: Math.max(0, startHeight) }) + const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + this.splitNodes({ at: end, depth: d }) + this.splitNodes({ at: start, depth: d }) at = rangeRef.unref()! } diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/value.ts index 53e8ac4d97..11399dfdf5 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/value.ts @@ -125,40 +125,6 @@ class ValueCommands { this[NORMALIZING] = value this.normalize() } - - /** - * Wrap the block nodes in the selection in a new block. - */ - - wrapBlock(this: Editor, block: Element): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.wrapBlockAtRange(selection, block) - const range = rangeRef.unref()! - this.select(range) - } - - /** - * Wrap the inline nodes in the selection in a new inline. - */ - - wrapInline(this: Editor, inline: Element): void { - const { selection } = this.value - - if (selection == null) { - return - } - - const rangeRef = this.createRangeRef(selection) - this.wrapInlineAtRange(selection, inline) - const range = rangeRef.unref()! - this.select(range) - } } /** diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index 162456a28d..8c37428e20 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -12,8 +12,6 @@ import AnnotationCommands from './commands/annotation' import TextCommands from './commands/text' import NodeCommands from './commands/node' import MarkCommands from './commands/mark' -import PathCommands from './commands/path' -import RangeCommands from './commands/range' import SelectionCommands from './commands/selection' import ValueCommands from './commands/value' import ElementQueries from './queries/element' @@ -81,8 +79,6 @@ interface Editor TextCommands, NodeCommands, MarkCommands, - PathCommands, - RangeCommands, SelectionCommands, ValueCommands, ElementQueries, @@ -107,8 +103,6 @@ mixin([ TextCommands, NodeCommands, MarkCommands, - PathCommands, - RangeCommands, SelectionCommands, ValueCommands, ElementQueries, diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index d48b562684..0113588884 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -38,7 +38,7 @@ class PathQueries { getDepth( this: Editor, path: Path, - depth: 'block' | 'inline' | number | undefined + depth: 'block' | 'inline' | 'text' | number | undefined ): number { if (depth === 'block') { const closestBlock = this.getClosestBlock(path) @@ -46,9 +46,12 @@ class PathQueries { } else if (depth === 'inline') { const closestInline = this.getClosestInline(path) depth = closestInline && closestInline[1].length + } else if (depth === 'text') { + const start = this.getStart(path) + depth = start && start.path.length } - return depth == null || depth === -1 ? path.length : depth + return depth == null ? path.length : depth } getHeight(this: Editor, path: Path, height: number | 'inline' | 'block') { @@ -220,54 +223,6 @@ class PathQueries { return Text.isText(n) ? [n, p] : undefined } - /** - * Get the next leaf block node entry starting from a path. - */ - - getNextLeafBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafBlocks({ at: path })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - - /** - * Get the next leaf inline node entry starting from a path. - */ - - getNextLeafInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafInlines({ at: path })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - - /** - * Get the next root block node entry starting from a path. - */ - - getNextRootBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootBlocks({ at: path })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - - /** - * Get the next root inline node entry starting from a path. - */ - - getNextRootInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootInlines({ at: path })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - /** * Get the next text node entry starting from a path. */ @@ -321,54 +276,6 @@ class PathQueries { return o } - /** - * Get the previous leaf block node entry starting from a path. - */ - - getPreviousLeafBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafBlocks({ at: path, reverse: true })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - - /** - * Get the previous leaf inline node entry starting from a path. - */ - - getPreviousLeafInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.leafInlines({ at: path, reverse: true })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - - /** - * Get the previous root block node entry starting from a path. - */ - - getPreviousRootBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootBlocks({ at: path, reverse: true })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - - /** - * Get the previous root inline node entry starting from a path. - */ - - getPreviousRootInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of this.rootInlines({ at: path, reverse: true })) { - if (!Path.isAncestor(p, path) && !Path.equals(p, path)) { - return [n, p] - } - } - } - /** * Get the previous text node entry starting from a path. */ @@ -382,13 +289,19 @@ class PathQueries { * Get the full range of a node at path. */ - getRange(this: Editor, path: Path): Range { - const first = this.getFirstText(path) - const last = this.getLastText(path) + getRange(this: Editor, startPath: Path, endPath: Path = startPath): Range { + const first = this.getFirstText(startPath) + const last = this.getLastText(endPath) - if (!first || !last) { + if (!first) { + throw new Error( + `Unable to get a range for the node at path [${startPath}] because it has no text nodes.` + ) + } + + if (!last) { throw new Error( - `Unable to get a range for the node at path ${path} because it has no text nodes.` + `Unable to get a range for the node at path [${endPath}] because it has no text nodes.` ) } diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index 2de6a94e5d..e2f1c6a153 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -1,7 +1,27 @@ -import { Editor, Node, Operation, Path, Point, PointRef } from '../..' +import { + Editor, + Node, + NodeEntry, + Operation, + Path, + Point, + PointRef, +} from '../..' import { POINT_REFS } from '../../symbols' class PointQueries { + getTarget( + this: Editor, + point: Point, + depth: number | 'block' | 'inline' | 'text' + ): NodeEntry | undefined { + const range = { anchor: point, focus: point } + + for (const entry of this.depths(depth, { at: range })) { + return entry + } + } + /** * Create a mutable ref for a `Point` object, which will stay in sync as new * operations are applied to the this. diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 04eb09110e..7ebed49c80 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -14,8 +14,18 @@ import { String, Text, TextEntry, + Value, } from '../..' +type NodeMatch = + | number + | 'value' + | 'block' + | 'inline' + | 'text' + | Partial + | ((entry: NodeEntry) => boolean) + class ValueQueries { /** * Iterate through all of the annotations in the editor. @@ -67,6 +77,130 @@ class ValueQueries { }) } + *batches( + this: Editor, + options: { + element: Element + match: NodeMatch + at: Range | Point | Path + hanging?: boolean + reverse?: boolean + } + ): Iterable<[Node, Path, NodeEntry[]]> { + const { element, at, ...rest } = options + let roots: NodeEntry[] = [] + + if (this.isInline(element)) { + for (const [node, path] of this.blocks()) { + if (this.hasInlines(node)) { + roots.push([node, path]) + } + } + } else { + roots.push([this.value, []]) + } + + for (const [node, path] of roots) { + const a = Range.isRange(at) + ? Range.intersection(at, this.getRange(path))! + : at + + const matches = Array.from(this.matches({ at: a, ...rest })) + + if (matches.length !== 0) { + yield [node, path, matches] + } + } + } + + isMatch(this: Editor, entry: NodeEntry, match: NodeMatch) { + const [node, path] = entry + + if (typeof match === 'function') { + return match(entry) + } else if (typeof match === 'number') { + return path.length === match + } else if (match === 'text') { + return Text.isText(node) + } else if (match === 'value') { + return Value.isValue(node) + } else if (match === 'inline') { + return ( + (Element.isElement(node) && this.isInline(node)) || Text.isText(node) + ) + } else if (match === 'block') { + return ( + Element.isElement(node) && !this.isInline(node) && this.hasInlines(node) + ) + } else { + return Node.matches(node, match) + } + } + + *levels( + this: Editor, + path: Path, + options: { + reverse?: boolean + } + ): Iterable { + const furthestVoid = this.getFurthestVoid(path) + + if (furthestVoid) { + const [, voidPath] = furthestVoid + path = voidPath + } + + yield* Node.levels(this.value, path, options) + } + + getMatch(this: Editor, path: Path, match: NodeMatch): NodeEntry | undefined { + for (const entry of this.levels(path, { reverse: true })) { + if (this.isMatch(entry, match)) { + return entry + } + } + } + + *matches( + this: Editor, + options: { + match: NodeMatch + at: Range | Point | Path + hanging?: boolean + reverse?: boolean + } + ): Iterable { + const { reverse, match, hanging = false } = options + let { at } = options + let prevPath: Path | undefined + let test = (entry: NodeEntry) => true + + // PERF: If the target is a path, we don't need to traverse at all. + if (Path.isPath(at)) { + const node = this.getNode(at) + yield [node, at] + return + } + + if (Point.isPoint(at)) { + at = { anchor: at, focus: at } + } else if (!hanging) { + at = this.getNonHangingRange(at) + } + + for (const [n, p] of this.entries({ at, reverse })) { + if (prevPath && Path.compare(p, prevPath) === 0) { + continue + } + + if (this.isMatch([n, p], match)) { + prevPath = p + yield [n, p] + } + } + } + /** * Iterate through all of the elements in the editor. */ @@ -76,14 +210,11 @@ class ValueQueries { options: { at?: Path | Range reverse?: boolean - pass?: (entry: ElementEntry) => boolean } = {} ): Iterable { - const { pass = () => false } = options yield* Node.elements(this.value, { ...options, - pass: ([n, p]) => - Element.isElement(n) && (this.isVoid(n) || pass([n, p])), + pass: ([n]) => Element.isElement(n) && this.isVoid(n), }) } @@ -241,42 +372,6 @@ class ValueQueries { }) } - /** - * Iterate through all of the leaf block nodes in the editor. - */ - - *leafBlocks( - this: Editor, - options: { - at?: Path | Range - reverse?: boolean - } = {} - ): Iterable { - for (const [n, p] of this.blocks(options)) { - if (this.hasInlines(n) || this.isVoid(n)) { - yield [n, p] - } - } - } - - /** - * Iterate through all of the leaf inline nodes in the editor. - */ - - *leafInlines( - this: Editor, - options: { - at?: Path | Range - reverse?: boolean - } = {} - ): Iterable { - for (const [n, p] of this.inlines(options)) { - if (this.hasTexts(n) || this.isVoid(n)) { - yield [n, p] - } - } - } - /** * Iterate through all of the positions in the document where a `Point` can be * placed. @@ -405,44 +500,6 @@ class ValueQueries { } } - /** - * Iterate through all of the root block nodes in the editor. - */ - - *rootBlocks( - this: Editor, - options: { - at?: Path | Range - reverse?: boolean - } = {} - ): Iterable { - for (const [n, p] of this.blocks(options)) { - if (p.length === 1) { - yield [n, p] - } - } - } - - /** - * Iterate through all of the root inline nodes in the editor. - */ - - *rootInlines( - this: Editor, - options: { - at?: Path | Range - reverse?: boolean - } = {} - ): Iterable { - for (const [n, p] of this.inlines(options)) { - const parent = Node.parent(this.value, p) - - if (!this.isInline(parent)) { - yield [n, p] - } - } - } - /** * Iterate through all of the text nodes in the editor. */ diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 79a14790a3..57c4455862 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -57,6 +57,14 @@ type DescendantEntry = [Descendant, Path] type AncestorEntry = [Ancestor, Path] namespace Node { + export const matches = (node: Node, props: Partial): boolean => { + return ( + (Value.isValue(node) && Value.matches(node, props)) || + (Element.isElement(node) && Element.matches(node, props)) || + (Text.isText(node) && Text.matches(node, props)) + ) + } + /** * Get the node at a specific path, asserting that it's an ancestor node. */ @@ -233,13 +241,16 @@ namespace Node { const visited = new Set() let p: Path = [] let n = root - yield [n, p] while (true) { - if (toPath != null && Path.equals(p, toPath)) { + if (toPath != null && Path.isAfter(p, toPath)) { break } + if (!visited.has(n)) { + yield [n, p] + } + // If we're allowed to go downward and we haven't decsended yet, do. if ( !visited.has(n) && @@ -256,7 +267,6 @@ namespace Node { p = p.concat(nextIndex) n = Node.get(root, p) - yield [n, p] continue } @@ -272,7 +282,6 @@ namespace Node { if (Node.has(root, newPath)) { p = newPath n = Node.get(root, p) - yield [n, p] continue } } @@ -282,7 +291,6 @@ namespace Node { const newPath = Path.previous(p) p = newPath n = Node.get(root, p) - yield [n, p] continue } diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index 3d1132a011..6c85bbd734 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -393,24 +393,25 @@ namespace Path { } if (Path.isAncestor(op, p) || Path.equals(op, p)) { + let copy = onp.slice() + if (Path.endsBefore(op, onp) && op.length < onp.length) { const i = Math.min(onp.length, op.length) - 1 - onp[i] -= 1 + copy[i] -= 1 } - onp.concat(p.slice(op.length)) - - // Retain any indices past the move point in the original path. - p.splice(0, op.length, ...onp) + return copy.concat(p.slice(op.length)) } else { + const copy = p.slice() + if (Path.endsBefore(op, p)) { p[op.length - 1] -= 1 } if ( - Path.endsBefore(onp, p) || - Path.equals(onp, p) || - Path.isAncestor(onp, p) + Path.endsBefore(onp, copy) || + Path.equals(onp, copy) || + Path.isAncestor(onp, copy) ) { p[onp.length - 1] += 1 } diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index 7cdb363027..ea7e5e6b09 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -15,13 +15,9 @@ interface Range { } namespace Range { - export const intersection = (range: Range, another: Range): Range => { + export const intersection = (range: Range, another: Range): Range | null => { if (!Range.includes(range, another)) { - throw new Error( - `Cannot get the intersection of ranges ${JSON.stringify( - range - )} and ${JSON.stringify(another)} because they do not overlap.` - ) + return null } const [s1, e1] = Range.points(range) diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 3593cd1645..61f66e203d 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -54,6 +54,27 @@ namespace Value { ) } + /** + * Check if a value matches a set of properties. + * + * Note: the is for checking custom properties, and it does not ensure that + * any children in the `nodes` property are equal. + */ + + export const matches = (value: Value, props: Partial): boolean => { + for (const key in props) { + if (key === 'annotations' || key === 'nodes' || key === 'selection') { + continue + } + + if (value[key] !== props[key]) { + return false + } + } + + return true + } + /** * Iterate through all of the point objects in a value. */ @@ -80,6 +101,7 @@ namespace Value { */ export const transform = (value: Value, op: Operation): Value => { + debugger return produce(value, v => { switch (op.type) { case 'add_annotation': { @@ -165,7 +187,6 @@ namespace Value { const node = Node.get(v, path) const parent = Node.parent(v, path) const index = path[path.length - 1] - parent.nodes.splice(index, 1) // This is tricky, but since the `path` and `newPath` both refer to // the same snapshot in time, there's a mismatch. After either @@ -173,9 +194,11 @@ namespace Value { // of date. So instead of using the `op.newPath` directly, we // transform `op.path` to ascertain what the `newPath` would be after // the operation was applied. + parent.nodes.splice(index, 1) const truePath = Path.transform(path, op)! - const newParent = Node.parent(v, truePath) + const newParent = Node.get(v, Path.parent(truePath)) const newIndex = truePath[truePath.length - 1] + newParent.nodes.splice(newIndex, 0, node) for (const [point, key, range] of Value.points(v)) { diff --git a/packages/slate/test/commands/liftNodes/selection/block-full.js b/packages/slate/test/commands/liftNodes/selection/block-full.js index 88ee2a3693..8736dcec78 100644 --- a/packages/slate/test/commands/liftNodes/selection/block-full.js +++ b/packages/slate/test/commands/liftNodes/selection/block-full.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.liftNodes({ depth: 2 }) + editor.liftNodes({ match: 2 }) } export const input = ( diff --git a/packages/slate/test/commands/liftNodes/selection/block-nested.js b/packages/slate/test/commands/liftNodes/selection/block-nested.js index 8d63b3c56f..b5e6603567 100644 --- a/packages/slate/test/commands/liftNodes/selection/block-nested.js +++ b/packages/slate/test/commands/liftNodes/selection/block-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.liftNodes({ depth: 3 }) + editor.liftNodes({ match: 3 }) } export const input = ( diff --git a/packages/slate/test/commands/mergeNodes/depth-block/block.js b/packages/slate/test/commands/mergeNodes/depth-block/block.js index 3b6668a904..9e9bbe508f 100644 --- a/packages/slate/test/commands/mergeNodes/depth-block/block.js +++ b/packages/slate/test/commands/mergeNodes/depth-block/block.js @@ -10,7 +10,7 @@ export const input = ( ) export const run = editor => { - editor.mergeNodes({ at: { path: [1, 0], offset: 0 }, depth: 'block' }) + editor.mergeNodes({ at: { path: [1, 0], offset: 0 }, match: 'block' }) } export const output = ( diff --git a/packages/slate/test/commands/moveNodes/selection/block-nested-after.js b/packages/slate/test/commands/moveNodes/selection/block-nested-after.js index 2e2a23acbf..2976b11c26 100644 --- a/packages/slate/test/commands/moveNodes/selection/block-nested-after.js +++ b/packages/slate/test/commands/moveNodes/selection/block-nested-after.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveNodes({ depth: 2, to: [1] }) + editor.moveNodes({ match: 2, to: [1] }) } export const input = ( @@ -14,7 +14,7 @@ export const input = ( two - three + three @@ -29,7 +29,7 @@ export const output = ( two - three + three ) diff --git a/packages/slate/test/commands/moveNodes/selection/block-nested-before.js b/packages/slate/test/commands/moveNodes/selection/block-nested-before.js index 683cbf01ba..579551a24e 100644 --- a/packages/slate/test/commands/moveNodes/selection/block-nested-before.js +++ b/packages/slate/test/commands/moveNodes/selection/block-nested-before.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.moveNodes({ depth: 2, to: [0] }) + editor.moveNodes({ match: 2, to: [0] }) } export const input = ( @@ -13,7 +13,7 @@ export const input = ( one - two + two @@ -25,7 +25,7 @@ export const output = ( one - two + two diff --git a/packages/slate/test/commands/moveNodes/selection/block.js b/packages/slate/test/commands/moveNodes/selection/block.js index ce4046c7c7..5df8054c95 100644 --- a/packages/slate/test/commands/moveNodes/selection/block.js +++ b/packages/slate/test/commands/moveNodes/selection/block.js @@ -12,7 +12,7 @@ export const input = ( ) export const run = editor => { - editor.moveNodes({ depth: 1, to: [1] }) + editor.moveNodes({ match: 1, to: [1] }) } export const output = ( diff --git a/packages/slate/test/commands/removeNodes/path/block-nested.js b/packages/slate/test/commands/removeNodes/path/block-nested.js new file mode 100644 index 0000000000..9ad0ccfbe9 --- /dev/null +++ b/packages/slate/test/commands/removeNodes/path/block-nested.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + editor.removeNodes({ at: [0, 0] }) +} + +export const output = ( + + + + + + two + + +) diff --git a/packages/slate/test/commands/removeNodes/path/block.js b/packages/slate/test/commands/removeNodes/path/block.js new file mode 100644 index 0000000000..19b541e64f --- /dev/null +++ b/packages/slate/test/commands/removeNodes/path/block.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + editor.removeNodes({ at: [0] }) +} + +export const output = ( + + two + +) diff --git a/packages/slate/test/commands/removeNodes/path/inline.js b/packages/slate/test/commands/removeNodes/path/inline.js new file mode 100644 index 0000000000..7d47575c71 --- /dev/null +++ b/packages/slate/test/commands/removeNodes/path/inline.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + + one + + two + + + +) + +export const run = editor => { + editor.removeNodes({ at: [0, 1] }) +} + +export const output = ( + + + + two + + + +) diff --git a/packages/slate/test/commands/removeNodes/path/text.js b/packages/slate/test/commands/removeNodes/path/text.js new file mode 100644 index 0000000000..f89dac2be9 --- /dev/null +++ b/packages/slate/test/commands/removeNodes/path/text.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + editor.removeNodes({ at: [1, 0] }) +} + +export const output = ( + + one + + + + +) diff --git a/packages/slate/test/commands/removeNodes/selection/block-across.js b/packages/slate/test/commands/removeNodes/selection/block-across.js new file mode 100644 index 0000000000..a412d1571b --- /dev/null +++ b/packages/slate/test/commands/removeNodes/selection/block-across.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + three + +) + +export const run = editor => { + editor.removeNodes() +} + +export const output = ( + + + three + + +) diff --git a/packages/slate/test/commands/removeNodes/selection/block-all.js b/packages/slate/test/commands/removeNodes/selection/block-all.js new file mode 100644 index 0000000000..45353bf01f --- /dev/null +++ b/packages/slate/test/commands/removeNodes/selection/block-all.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + + two + + +) + +export const run = editor => { + editor.removeNodes() +} + +export const output = diff --git a/packages/slate/test/commands/setNodes/block/block-across.js b/packages/slate/test/commands/setNodes/block/block-across.js index 9244df2cf8..7bfc4ec993 100644 --- a/packages/slate/test/commands/setNodes/block/block-across.js +++ b/packages/slate/test/commands/setNodes/block/block-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'block' }) + editor.setNodes({ key: true }, { match: 'block' }) } export const input = ( @@ -19,10 +19,10 @@ export const input = ( export const output = ( - + word - + another diff --git a/packages/slate/test/commands/setNodes/block/block-hanging.js b/packages/slate/test/commands/setNodes/block/block-hanging.js index 1a262fb624..7669d12f40 100644 --- a/packages/slate/test/commands/setNodes/block/block-hanging.js +++ b/packages/slate/test/commands/setNodes/block/block-hanging.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'block' }) + editor.setNodes({ key: true }, { match: 'block' }) } export const input = ( @@ -19,7 +19,7 @@ export const input = ( export const output = ( - + word diff --git a/packages/slate/test/commands/setNodes/block/block-nested.js b/packages/slate/test/commands/setNodes/block/block-nested.js index 9511a1390d..dcb1ad1d46 100644 --- a/packages/slate/test/commands/setNodes/block/block-nested.js +++ b/packages/slate/test/commands/setNodes/block/block-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'block' }) + editor.setNodes({ key: true }, { match: 'block' }) } export const input = ( @@ -18,8 +18,8 @@ export const input = ( export const output = ( - - + + word diff --git a/packages/slate/test/commands/setNodes/block/block-void.js b/packages/slate/test/commands/setNodes/block/block-void.js index acfaf40969..6b2ebfcf51 100644 --- a/packages/slate/test/commands/setNodes/block/block-void.js +++ b/packages/slate/test/commands/setNodes/block/block-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'block' }) + editor.setNodes({ key: true }, { match: 'block' }) } export const input = ( @@ -16,7 +16,7 @@ export const input = ( export const output = ( - + word diff --git a/packages/slate/test/commands/setNodes/block/block.js b/packages/slate/test/commands/setNodes/block/block.js index 3a017b9725..0f0d7898a5 100644 --- a/packages/slate/test/commands/setNodes/block/block.js +++ b/packages/slate/test/commands/setNodes/block/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'block' }) + editor.setNodes({ key: true }, { match: 'block' }) } export const input = ( @@ -16,7 +16,7 @@ export const input = ( export const output = ( - + word diff --git a/packages/slate/test/commands/setNodes/inline/inline-across.js b/packages/slate/test/commands/setNodes/inline/inline-across.js index af94c0aef7..e56e76215e 100644 --- a/packages/slate/test/commands/setNodes/inline/inline-across.js +++ b/packages/slate/test/commands/setNodes/inline/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'inline' }) + editor.setNodes({ key: true }, { match: 'inline' }) } export const input = ( @@ -29,14 +29,14 @@ export const output = ( - + word - + - - + + another diff --git a/packages/slate/test/commands/setNodes/inline/inline-hanging.js b/packages/slate/test/commands/setNodes/inline/inline-hanging.js index c4e6eb658b..bd02b3ccd4 100644 --- a/packages/slate/test/commands/setNodes/inline/inline-hanging.js +++ b/packages/slate/test/commands/setNodes/inline/inline-hanging.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'inline' }) + editor.setNodes({ key: true }, { match: 'inline' }) } export const input = ( @@ -29,10 +29,10 @@ export const output = ( - + word - + @@ -43,3 +43,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/setNodes/inline/inline-nested.js b/packages/slate/test/commands/setNodes/inline/inline-nested.js index 2bff8839e5..b8b8d4c100 100644 --- a/packages/slate/test/commands/setNodes/inline/inline-nested.js +++ b/packages/slate/test/commands/setNodes/inline/inline-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'inline' }) + editor.setNodes({ key: true }, { match: 'inline' }) } export const input = ( @@ -26,9 +26,9 @@ export const output = ( - + - + word diff --git a/packages/slate/test/commands/setNodes/inline/inline-void.js b/packages/slate/test/commands/setNodes/inline/inline-void.js index 4d910c231d..044e69f81e 100644 --- a/packages/slate/test/commands/setNodes/inline/inline-void.js +++ b/packages/slate/test/commands/setNodes/inline/inline-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'inline' }) + editor.setNodes({ key: true }, { match: 'inline' }) } export const input = ( @@ -22,7 +22,7 @@ export const output = ( - + word diff --git a/packages/slate/test/commands/setNodes/inline/inline.js b/packages/slate/test/commands/setNodes/inline/inline.js index 8c9aacd166..c18a512b6a 100644 --- a/packages/slate/test/commands/setNodes/inline/inline.js +++ b/packages/slate/test/commands/setNodes/inline/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setNodes({ thing: true }, { match: 'inline' }) + editor.setNodes({ key: true }, { match: 'inline' }) } export const input = ( @@ -22,7 +22,7 @@ export const output = ( - + word diff --git a/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js b/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js index 8e0e532c17..a78a9f3b54 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js +++ b/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/after-inline.js b/packages/slate/test/commands/splitNodes/depth-block/after-inline.js index ddf7b252ca..46093c903f 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/after-inline.js +++ b/packages/slate/test/commands/splitNodes/depth-block/after-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/before-inline.js b/packages/slate/test/commands/splitNodes/depth-block/before-inline.js index 3cfa2bb884..55f608a6cf 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/before-inline.js +++ b/packages/slate/test/commands/splitNodes/depth-block/before-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/block-end.js b/packages/slate/test/commands/splitNodes/depth-block/block-end.js index e959373c82..1c4c1cdec0 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/block-end.js +++ b/packages/slate/test/commands/splitNodes/depth-block/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/block-middle.js b/packages/slate/test/commands/splitNodes/depth-block/block-middle.js index d506669e60..4fcd84b237 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/block-middle.js +++ b/packages/slate/test/commands/splitNodes/depth-block/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/block-start.js b/packages/slate/test/commands/splitNodes/depth-block/block-start.js index 751b57d1a1..9c55c31841 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/block-start.js +++ b/packages/slate/test/commands/splitNodes/depth-block/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/point.js b/packages/slate/test/commands/splitNodes/depth-block/point.js index 661c2aa61a..717cbb9151 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/point.js +++ b/packages/slate/test/commands/splitNodes/depth-block/point.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block', at: { path: [0, 0], offset: 2 } }) + editor.splitNodes({ match: 'block', at: { path: [0, 0], offset: 2 } }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/with-inline.js b/packages/slate/test/commands/splitNodes/depth-block/with-inline.js index 7b3b7fd4a3..2d3b83c7a2 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/with-inline.js +++ b/packages/slate/test/commands/splitNodes/depth-block/with-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-inline/block-end.js b/packages/slate/test/commands/splitNodes/depth-inline/block-end.js index f04c685ef4..0a5eb0309d 100644 --- a/packages/slate/test/commands/splitNodes/depth-inline/block-end.js +++ b/packages/slate/test/commands/splitNodes/depth-inline/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'inline' }) + editor.splitNodes({ match: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-inline/block-middle.js b/packages/slate/test/commands/splitNodes/depth-inline/block-middle.js index 13cf3810bb..05b964c5b8 100644 --- a/packages/slate/test/commands/splitNodes/depth-inline/block-middle.js +++ b/packages/slate/test/commands/splitNodes/depth-inline/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'inline' }) + editor.splitNodes({ match: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-inline/block-start.js b/packages/slate/test/commands/splitNodes/depth-inline/block-start.js index f8360da9b0..ce980f43eb 100644 --- a/packages/slate/test/commands/splitNodes/depth-inline/block-start.js +++ b/packages/slate/test/commands/splitNodes/depth-inline/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'inline' }) + editor.splitNodes({ match: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth/two.js b/packages/slate/test/commands/splitNodes/depth/two.js index d0a63c3e09..ef9ea70432 100644 --- a/packages/slate/test/commands/splitNodes/depth/two.js +++ b/packages/slate/test/commands/splitNodes/depth/two.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 2 }) + editor.splitNodes({ match: 2 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth/zero.js b/packages/slate/test/commands/splitNodes/depth/zero.js index 6999cd0eac..32112b2fd5 100644 --- a/packages/slate/test/commands/splitNodes/depth/zero.js +++ b/packages/slate/test/commands/splitNodes/depth/zero.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 0 }) + editor.splitNodes({ match: 0 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/point/block.js b/packages/slate/test/commands/splitNodes/point/block.js index 45c3b77f76..e847bd3617 100644 --- a/packages/slate/test/commands/splitNodes/point/block.js +++ b/packages/slate/test/commands/splitNodes/point/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ at: { path: [0, 0], offset: 2 }, depth: 1 }) + editor.splitNodes({ at: { path: [0, 0], offset: 2 }, match: 1 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/point/inline.js b/packages/slate/test/commands/splitNodes/point/inline.js index 74daf5ad4a..8dea4c275b 100644 --- a/packages/slate/test/commands/splitNodes/point/inline.js +++ b/packages/slate/test/commands/splitNodes/point/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ at: { path: [0, 1, 0], offset: 2 }, depth: 2 }) + editor.splitNodes({ at: { path: [0, 1, 0], offset: 2 }, match: 2 }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/selection/expanded.js b/packages/slate/test/commands/splitNodes/selection/expanded.js index 579d616897..2df7a93576 100644 --- a/packages/slate/test/commands/splitNodes/selection/expanded.js +++ b/packages/slate/test/commands/splitNodes/selection/expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'inline' }) + editor.splitNodes({ match: 'inline' }) } export const input = ( @@ -31,3 +31,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/mark.js b/packages/slate/test/commands/splitNodes/selection/mark.js index 7310079217..320f43dbee 100644 --- a/packages/slate/test/commands/splitNodes/selection/mark.js +++ b/packages/slate/test/commands/splitNodes/selection/mark.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'inline' }) + editor.splitNodes({ match: 'inline' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js index 1652c09f36..fa2d01509b 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js index 5f291184f4..4a586e465e 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js b/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js index b28926f03b..f346e95b40 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete.js b/packages/slate/test/commands/splitNodes/selection/with-delete.js index 361355461d..a660b37290 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete.js +++ b/packages/slate/test/commands/splitNodes/selection/with-delete.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ depth: 'block' }) + editor.splitNodes({ match: 'block' }) } export const input = ( diff --git a/packages/slate/test/commands/wrapBlock/selection/across-inlines.js b/packages/slate/test/commands/surroundNodes/block/block-end.js similarity index 52% rename from packages/slate/test/commands/wrapBlock/selection/across-inlines.js rename to packages/slate/test/commands/surroundNodes/block/block-end.js index a1137afd1d..d4ee6d150f 100644 --- a/packages/slate/test/commands/wrapBlock/selection/across-inlines.js +++ b/packages/slate/test/commands/surroundNodes/block/block-end.js @@ -2,37 +2,31 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.wrapBlock('quote') -} - export const input = ( + one - - word - + two - - another - + three ) +export const run = editor => { + editor.surroundNodes() +} + export const output = ( - + one + - - word - + two - - another - + three diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-end.js b/packages/slate/test/commands/unwrapNodes/match-block/block-end.js index d2288f03f0..dc4f5b1ef5 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-end.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-end.js @@ -17,7 +17,7 @@ export const input = ( five - six + six @@ -35,7 +35,7 @@ export const output = ( five - six + six ) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js b/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js index fc7b551229..0560a6a72f 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js @@ -15,7 +15,7 @@ export const input = ( three - four + four five six @@ -33,7 +33,7 @@ export const output = ( three - four + four five diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js b/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js index 51375b9efe..86ca6067f2 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js @@ -16,7 +16,7 @@ export const input = ( three - four + four five six @@ -36,7 +36,7 @@ export const output = ( three - four + four five diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-start.js b/packages/slate/test/commands/unwrapNodes/match-block/block-start.js index 4f7aaec439..de8bfdd62a 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-start.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-start.js @@ -13,7 +13,7 @@ export const input = ( one - two + two three four @@ -29,7 +29,7 @@ export const output = ( one - two + two three diff --git a/packages/slate/test/commands/wrapBlock/selection/across-blocks.js b/packages/slate/test/commands/wrapBlock/selection/across-blocks.js deleted file mode 100644 index 95d5411f32..0000000000 --- a/packages/slate/test/commands/wrapBlock/selection/across-blocks.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapBlock('quote') -} - -export const input = ( - - - - word - - - another - - - -) - -export const output = ( - - - - - word - - - another - - - - -) diff --git a/packages/slate/test/commands/wrapBlock/selection/single-block.js b/packages/slate/test/commands/wrapBlock/selection/single-block.js deleted file mode 100644 index 6808a9fab3..0000000000 --- a/packages/slate/test/commands/wrapBlock/selection/single-block.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapBlock('quote') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/across-blocks.js b/packages/slate/test/commands/wrapInline/selection/across-blocks.js deleted file mode 100644 index dbbce905d7..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/across-blocks.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - word - - - another - - - -) - -export const output = ( - - - - wo - rd - - - - - - an - other - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/across-inlines.js b/packages/slate/test/commands/wrapInline/selection/across-inlines.js deleted file mode 100644 index 374c98edad..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/across-inlines.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - - word - - - another - - - - -) - -export const output = ( - - - - wo - - - rd - - an - - - other - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/collapsed.js b/packages/slate/test/commands/wrapInline/selection/collapsed.js deleted file mode 100644 index 421b29bd7d..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/collapsed.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - wd - - - -) - -export const output = ( - - - - w - - - d - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/inline-end.js b/packages/slate/test/commands/wrapInline/selection/inline-end.js deleted file mode 100644 index f5555e1d1e..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/inline-end.js +++ /dev/null @@ -1,41 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - - - hello - - - - - -) - -export const output = ( - - - - - hel - - - - - lo - - - - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/inline-middle-with-marks.js b/packages/slate/test/commands/wrapInline/selection/inline-middle-with-marks.js deleted file mode 100644 index c883a42173..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/inline-middle-with-marks.js +++ /dev/null @@ -1,52 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - - - - hello - - - - - - -) - -// TODO: this selection logic isn't right -export const output = ( - - - - - - he - - - - - - ll - - - - - - - o - - - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/inline-middle.js b/packages/slate/test/commands/wrapInline/selection/inline-middle.js deleted file mode 100644 index 5a8e838d11..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/inline-middle.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - - - hello - - - - - -) - -// TODO: this selection logic isn't right -export const output = ( - - - - - he - - - - ll - - - - - o - - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/inline-start.js b/packages/slate/test/commands/wrapInline/selection/inline-start.js deleted file mode 100644 index dc94658489..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/inline-start.js +++ /dev/null @@ -1,43 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - - - hello - - - - - -) - -export const output = ( - - - - - - - - hel - - - - - - lo - - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/nested-block.js b/packages/slate/test/commands/wrapInline/selection/nested-block.js deleted file mode 100644 index ea0077023f..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/nested-block.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - w - or - - d - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/single-block.js b/packages/slate/test/commands/wrapInline/selection/single-block.js deleted file mode 100644 index c31bd8b7dd..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/single-block.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w - or - - d - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/twice.js b/packages/slate/test/commands/wrapInline/selection/twice.js deleted file mode 100644 index 3f131bcae9..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/twice.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('link') - editor.wrapInline('hashtag') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w - - - - or - - - - d - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/whole-block.js b/packages/slate/test/commands/wrapInline/selection/whole-block.js deleted file mode 100644 index 6495044ee1..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/whole-block.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline('hashtag') -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - - word - - - - -) diff --git a/packages/slate/test/commands/wrapInline/selection/with-object.js b/packages/slate/test/commands/wrapInline/selection/with-object.js deleted file mode 100644 index 561d63d2f1..0000000000 --- a/packages/slate/test/commands/wrapInline/selection/with-object.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.wrapInline({ - type: 'hashtag', - data: { thing: 'value' }, - }) -} - -export const input = ( - - - - word - - - -) - -export const output = ( - - - - w - or - - d - - - -) diff --git a/packages/slate/test/commands/wrapNodes/block/block-across.js b/packages/slate/test/commands/wrapNodes/block/block-across.js index d45c01dd62..2f0154a3f1 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-across.js +++ b/packages/slate/test/commands/wrapNodes/block/block-across.js @@ -5,27 +5,29 @@ import { h } from '../../../helpers' export const input = ( - one + one - two + two ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes() } export const output = ( - + on + - one + e - two + t + wo ) diff --git a/packages/slate/test/commands/wrapNodes/block/block-end.js b/packages/slate/test/commands/wrapNodes/block/block-end.js index 71fa38bb9d..97353c9a31 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-end.js +++ b/packages/slate/test/commands/wrapNodes/block/block-end.js @@ -4,29 +4,22 @@ import { h } from '../../../helpers' export const input = ( - one - two - - - three + word ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes() } export const output = ( - one - - - two - + wo + - three + rd diff --git a/packages/slate/test/commands/wrapNodes/block/block-middle.js b/packages/slate/test/commands/wrapNodes/block/block-middle.js index 270b113a74..b49765ff29 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-middle.js +++ b/packages/slate/test/commands/wrapNodes/block/block-middle.js @@ -4,26 +4,24 @@ import { h } from '../../../helpers' export const input = ( - one - two + word - three ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes() } export const output = ( - one - + w + - two + or - three + d ) diff --git a/packages/slate/test/commands/wrapBlock/selection/nested-block.js b/packages/slate/test/commands/wrapNodes/block/block-nested.js similarity index 59% rename from packages/slate/test/commands/wrapBlock/selection/nested-block.js rename to packages/slate/test/commands/wrapNodes/block/block-nested.js index 5f76201052..205256a319 100644 --- a/packages/slate/test/commands/wrapBlock/selection/nested-block.js +++ b/packages/slate/test/commands/wrapNodes/block/block-nested.js @@ -2,28 +2,30 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.wrapBlock('quote') -} - export const input = ( - + - word + word ) +export const run = editor => { + editor.wrapNodes() +} + export const output = ( - - + + w + - word + or + d ) diff --git a/packages/slate/test/commands/wrapNodes/block/block-start.js b/packages/slate/test/commands/wrapNodes/block/block-start.js index 3a3539be2d..b8cdb83c1c 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-start.js +++ b/packages/slate/test/commands/wrapNodes/block/block-start.js @@ -5,25 +5,22 @@ import { h } from '../../../helpers' export const input = ( - one + word - - two - - three ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes() } export const output = ( - + - word + wo + rd ) diff --git a/packages/slate/test/commands/wrapNodes/block/block.js b/packages/slate/test/commands/wrapNodes/block/block.js index 41ce57f628..2eed2428ca 100644 --- a/packages/slate/test/commands/wrapNodes/block/block.js +++ b/packages/slate/test/commands/wrapNodes/block/block.js @@ -11,12 +11,12 @@ export const input = ( ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes() } export const output = ( - + word diff --git a/packages/slate/test/commands/wrapInline/selection/inline-void.js b/packages/slate/test/commands/wrapNodes/inline/inline.js similarity index 60% rename from packages/slate/test/commands/wrapInline/selection/inline-void.js rename to packages/slate/test/commands/wrapNodes/inline/inline.js index c2adddda77..9f77d8e3c0 100644 --- a/packages/slate/test/commands/wrapInline/selection/inline-void.js +++ b/packages/slate/test/commands/wrapNodes/inline/inline.js @@ -2,28 +2,28 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.wrapInline('link') -} - export const input = ( - - - + one + two + three ) +export const run = editor => { + editor.wrapNodes() +} + export const output = ( - - - - + one + + two + three ) diff --git a/packages/slate/test/commands/wrapNodes/selection/depth-text.js b/packages/slate/test/commands/wrapNodes/selection/depth-text.js index 2e4ea72cb4..79ceebf814 100644 --- a/packages/slate/test/commands/wrapNodes/selection/depth-text.js +++ b/packages/slate/test/commands/wrapNodes/selection/depth-text.js @@ -2,22 +2,26 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.wrapNodes(, { depth: -1 }) -} - export const input = ( - word + + word + ) +export const run = editor => { + editor.wrapNodes(, { match: 'text' }) +} + export const output = ( - word + + word + ) diff --git a/packages/slate/test/interfaces/Node/descendants/path.js b/packages/slate/test/interfaces/Node/descendants/path.js index 5068e54385..1f052a774d 100644 --- a/packages/slate/test/interfaces/Node/descendants/path.js +++ b/packages/slate/test/interfaces/Node/descendants/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.descendants(value, { path: [0, 1] })) + return Array.from(Node.descendants(value, { at: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/descendants/range.js b/packages/slate/test/interfaces/Node/descendants/range.js index af4c27c6c4..eb7568dd6f 100644 --- a/packages/slate/test/interfaces/Node/descendants/range.js +++ b/packages/slate/test/interfaces/Node/descendants/range.js @@ -17,7 +17,7 @@ export const input = ( export const test = value => { return Array.from( Node.descendants(value, { - range: { + at: { anchor: { path: [0, 1], offset: 0, diff --git a/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js b/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js index d820291f59..1bbf9cdb45 100644 --- a/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js +++ b/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.entries(value, { path: [0, 1] })) + return Array.from(Node.entries(value, { at: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/entries/path-of-element.js b/packages/slate/test/interfaces/Node/entries/path-of-element.js index 0d66b934ee..164a19b713 100644 --- a/packages/slate/test/interfaces/Node/entries/path-of-element.js +++ b/packages/slate/test/interfaces/Node/entries/path-of-element.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.entries(value, { path: [0] })) + return Array.from(Node.entries(value, { at: [0] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/entries/path.js b/packages/slate/test/interfaces/Node/entries/path.js index 4a882b1065..742162e8f9 100644 --- a/packages/slate/test/interfaces/Node/entries/path.js +++ b/packages/slate/test/interfaces/Node/entries/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.entries(value, { path: [0, 1] })) + return Array.from(Node.entries(value, { at: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/entries/range.js b/packages/slate/test/interfaces/Node/entries/range.js index e23077d5a3..eff10a7ee0 100644 --- a/packages/slate/test/interfaces/Node/entries/range.js +++ b/packages/slate/test/interfaces/Node/entries/range.js @@ -17,7 +17,7 @@ export const input = ( export const test = value => { return Array.from( Node.entries(value, { - range: { + at: { anchor: { path: [0, 1], offset: 0, diff --git a/packages/slate/test/interfaces/Node/marks/path.js b/packages/slate/test/interfaces/Node/marks/path.js index 280238eef3..2f8181f33c 100644 --- a/packages/slate/test/interfaces/Node/marks/path.js +++ b/packages/slate/test/interfaces/Node/marks/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.marks(value, { path: [0, 1] })) + return Array.from(Node.marks(value, { at: [0, 1] })) } export const output = [[{ key: 'b' }, 0, two, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/marks/range.js b/packages/slate/test/interfaces/Node/marks/range.js index c997683363..9c61bd2978 100644 --- a/packages/slate/test/interfaces/Node/marks/range.js +++ b/packages/slate/test/interfaces/Node/marks/range.js @@ -16,7 +16,7 @@ export const input = ( export const test = value => { return Array.from( Node.marks(value, { - range: { + at: { anchor: { path: [0, 0], offset: 0, diff --git a/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js b/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js index d8bc87d7d8..86b5d1088d 100644 --- a/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js +++ b/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { path: [0, 1] })) + return Array.from(Node.texts(value, { at: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/texts/path-of-element.js b/packages/slate/test/interfaces/Node/texts/path-of-element.js index 7292b7f421..c0bac4346f 100644 --- a/packages/slate/test/interfaces/Node/texts/path-of-element.js +++ b/packages/slate/test/interfaces/Node/texts/path-of-element.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { path: [0] })) + return Array.from(Node.texts(value, { at: [0] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/texts/path.js b/packages/slate/test/interfaces/Node/texts/path.js index 7f4dd4d4ca..af835df35b 100644 --- a/packages/slate/test/interfaces/Node/texts/path.js +++ b/packages/slate/test/interfaces/Node/texts/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { path: [0, 1] })) + return Array.from(Node.texts(value, { at: [0, 1] })) } export const output = [[, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/texts/range.js b/packages/slate/test/interfaces/Node/texts/range.js index 699d6affee..9db4722845 100644 --- a/packages/slate/test/interfaces/Node/texts/range.js +++ b/packages/slate/test/interfaces/Node/texts/range.js @@ -17,7 +17,7 @@ export const input = ( export const test = value => { return Array.from( Node.texts(value, { - range: { + at: { anchor: { path: [0, 1], offset: 0, diff --git a/packages/slate/test/queries/blocks/at-path.js b/packages/slate/test/queries/blocks/at-path.js new file mode 100644 index 0000000000..20ce12c5eb --- /dev/null +++ b/packages/slate/test/queries/blocks/at-path.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from(editor.blocks({ at: [1] })) +} + +export const output = [[two, [1]], [three, [2]]] diff --git a/packages/slate/test/queries/blocks/at-range.js b/packages/slate/test/queries/blocks/at-range.js new file mode 100644 index 0000000000..32276bcc11 --- /dev/null +++ b/packages/slate/test/queries/blocks/at-range.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + three + +) + +export const run = editor => { + return Array.from( + editor.blocks({ + at: { anchor: { path: [1], offset: 0 }, focus: { path: [1], offset: 3 } }, + }) + ) +} + +export const output = [[two, [1]]] diff --git a/packages/slate/test/queries/blocks/block-multiple.js b/packages/slate/test/queries/blocks/block-multiple.js index e894ada442..5c7bd9f003 100644 --- a/packages/slate/test/queries/blocks/block-multiple.js +++ b/packages/slate/test/queries/blocks/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/blocks/block-nested.js b/packages/slate/test/queries/blocks/block-nested.js index 0d942b8166..5f6f4233cb 100644 --- a/packages/slate/test/queries/blocks/block-nested.js +++ b/packages/slate/test/queries/blocks/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/blocks/block-reverse.js b/packages/slate/test/queries/blocks/block-reverse.js index 1900aa9148..64511896df 100644 --- a/packages/slate/test/queries/blocks/block-reverse.js +++ b/packages/slate/test/queries/blocks/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/blocks/block-void.js b/packages/slate/test/queries/blocks/block-void.js index 6e1608f077..fe20f3c614 100644 --- a/packages/slate/test/queries/blocks/block-void.js +++ b/packages/slate/test/queries/blocks/block-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/blocks/block.js b/packages/slate/test/queries/blocks/block.js index 9215e63fa0..8d6e4c8c5b 100644 --- a/packages/slate/test/queries/blocks/block.js +++ b/packages/slate/test/queries/blocks/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/blocks/inline.js b/packages/slate/test/queries/blocks/inline.js index 3d5934ec94..d46c4d1fcd 100644 --- a/packages/slate/test/queries/blocks/inline.js +++ b/packages/slate/test/queries/blocks/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/block-multiple.js b/packages/slate/test/queries/entries/block-multiple.js index 333a755fdc..c9dbdb9734 100644 --- a/packages/slate/test/queries/entries/block-multiple.js +++ b/packages/slate/test/queries/entries/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/block-nested.js b/packages/slate/test/queries/entries/block-nested.js index a4d8e4ceb5..3a889fdbb4 100644 --- a/packages/slate/test/queries/entries/block-nested.js +++ b/packages/slate/test/queries/entries/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/block-reverse.js b/packages/slate/test/queries/entries/block-reverse.js index f19c4b15ce..8ab3a7311f 100644 --- a/packages/slate/test/queries/entries/block-reverse.js +++ b/packages/slate/test/queries/entries/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/block-void.js b/packages/slate/test/queries/entries/block-void.js index 14f23c0610..f1677cf753 100644 --- a/packages/slate/test/queries/entries/block-void.js +++ b/packages/slate/test/queries/entries/block-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/block.js b/packages/slate/test/queries/entries/block.js index 8b4ec5fa89..62e862153c 100644 --- a/packages/slate/test/queries/entries/block.js +++ b/packages/slate/test/queries/entries/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/inline-multiple.js b/packages/slate/test/queries/entries/inline-multiple.js index db2c4132c9..9499cc3a9d 100644 --- a/packages/slate/test/queries/entries/inline-multiple.js +++ b/packages/slate/test/queries/entries/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/inline-nested.js b/packages/slate/test/queries/entries/inline-nested.js index e754fd5f95..6b412d9842 100644 --- a/packages/slate/test/queries/entries/inline-nested.js +++ b/packages/slate/test/queries/entries/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/inline-reverse.js b/packages/slate/test/queries/entries/inline-reverse.js index aaac86a1ad..656d9e2a86 100644 --- a/packages/slate/test/queries/entries/inline-reverse.js +++ b/packages/slate/test/queries/entries/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/inline-void.js b/packages/slate/test/queries/entries/inline-void.js index cf7ca3f30f..558600ee44 100644 --- a/packages/slate/test/queries/entries/inline-void.js +++ b/packages/slate/test/queries/entries/inline-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/entries/inline.js b/packages/slate/test/queries/entries/inline.js index dc80e76902..5b0fdc9e57 100644 --- a/packages/slate/test/queries/entries/inline.js +++ b/packages/slate/test/queries/entries/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/block-across.js b/packages/slate/test/queries/getActiveMarks/block-across.js index 5b385647c7..9a8a2c32d1 100644 --- a/packages/slate/test/queries/getActiveMarks/block-across.js +++ b/packages/slate/test/queries/getActiveMarks/block-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/block-start.js b/packages/slate/test/queries/getActiveMarks/block-start.js index f778f68783..39a12e88a5 100644 --- a/packages/slate/test/queries/getActiveMarks/block-start.js +++ b/packages/slate/test/queries/getActiveMarks/block-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/inline-start.js b/packages/slate/test/queries/getActiveMarks/inline-start.js index e5bb69b06e..67164d1db6 100644 --- a/packages/slate/test/queries/getActiveMarks/inline-start.js +++ b/packages/slate/test/queries/getActiveMarks/inline-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/intersection.js b/packages/slate/test/queries/getActiveMarks/intersection.js index fd69719632..68b6d87b20 100644 --- a/packages/slate/test/queries/getActiveMarks/intersection.js +++ b/packages/slate/test/queries/getActiveMarks/intersection.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/multiple.js b/packages/slate/test/queries/getActiveMarks/multiple.js index b3aa4bb67c..2fd390a9f8 100644 --- a/packages/slate/test/queries/getActiveMarks/multiple.js +++ b/packages/slate/test/queries/getActiveMarks/multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/none.js b/packages/slate/test/queries/getActiveMarks/none.js index fd06db2291..dca135c13b 100644 --- a/packages/slate/test/queries/getActiveMarks/none.js +++ b/packages/slate/test/queries/getActiveMarks/none.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/one.js b/packages/slate/test/queries/getActiveMarks/one.js index 5e8d89911b..b0251227c4 100644 --- a/packages/slate/test/queries/getActiveMarks/one.js +++ b/packages/slate/test/queries/getActiveMarks/one.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/selection-marks.js b/packages/slate/test/queries/getActiveMarks/selection-marks.js index 0dc2d973fb..a32c0d86ea 100644 --- a/packages/slate/test/queries/getActiveMarks/selection-marks.js +++ b/packages/slate/test/queries/getActiveMarks/selection-marks.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/selection-null.js b/packages/slate/test/queries/getActiveMarks/selection-null.js index 28b1803655..4e86bf33a6 100644 --- a/packages/slate/test/queries/getActiveMarks/selection-null.js +++ b/packages/slate/test/queries/getActiveMarks/selection-null.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/text-start.js b/packages/slate/test/queries/getActiveMarks/text-start.js index 9e3ccf9e69..c5b84e80dc 100644 --- a/packages/slate/test/queries/getActiveMarks/text-start.js +++ b/packages/slate/test/queries/getActiveMarks/text-start.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getActiveMarks/union.js b/packages/slate/test/queries/getActiveMarks/union.js index d523710f79..7356a7731f 100644 --- a/packages/slate/test/queries/getActiveMarks/union.js +++ b/packages/slate/test/queries/getActiveMarks/union.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getClosestBlock/block-nested.js b/packages/slate/test/queries/getClosestBlock/block-nested.js index 2947d14266..f8cba59122 100644 --- a/packages/slate/test/queries/getClosestBlock/block-nested.js +++ b/packages/slate/test/queries/getClosestBlock/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getClosestBlock/block.js b/packages/slate/test/queries/getClosestBlock/block.js index 88e8a747df..50e9649439 100644 --- a/packages/slate/test/queries/getClosestBlock/block.js +++ b/packages/slate/test/queries/getClosestBlock/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getClosestBlock/inline.js b/packages/slate/test/queries/getClosestBlock/inline.js index d81d7eca82..264ee599ae 100644 --- a/packages/slate/test/queries/getClosestBlock/inline.js +++ b/packages/slate/test/queries/getClosestBlock/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getText/block-across.js b/packages/slate/test/queries/getText/block-across.js index 8e2ba1214d..924683eaed 100644 --- a/packages/slate/test/queries/getText/block-across.js +++ b/packages/slate/test/queries/getText/block-across.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getText/block-void.js b/packages/slate/test/queries/getText/block-void.js index 0488bc8b9d..8f3967c5db 100644 --- a/packages/slate/test/queries/getText/block-void.js +++ b/packages/slate/test/queries/getText/block-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getText/block.js b/packages/slate/test/queries/getText/block.js index c1bbe832a2..07efa6d33e 100644 --- a/packages/slate/test/queries/getText/block.js +++ b/packages/slate/test/queries/getText/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getText/inline.js b/packages/slate/test/queries/getText/inline.js index fb0fc3a1f1..ca8e98fbc2 100644 --- a/packages/slate/test/queries/getText/inline.js +++ b/packages/slate/test/queries/getText/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getText/text.js b/packages/slate/test/queries/getText/text.js index c9a64792ed..bdc004c83d 100644 --- a/packages/slate/test/queries/getText/text.js +++ b/packages/slate/test/queries/getText/text.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasBlocks/block-nested.js b/packages/slate/test/queries/hasBlocks/block-nested.js index fa5ea1a4e6..1969d45c26 100644 --- a/packages/slate/test/queries/hasBlocks/block-nested.js +++ b/packages/slate/test/queries/hasBlocks/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasBlocks/block.js b/packages/slate/test/queries/hasBlocks/block.js index 57ca875732..caa3775177 100644 --- a/packages/slate/test/queries/hasBlocks/block.js +++ b/packages/slate/test/queries/hasBlocks/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasBlocks/inline-nested.js b/packages/slate/test/queries/hasBlocks/inline-nested.js index 6d2dce1dc3..644fd9916f 100644 --- a/packages/slate/test/queries/hasBlocks/inline-nested.js +++ b/packages/slate/test/queries/hasBlocks/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasBlocks/inline.js b/packages/slate/test/queries/hasBlocks/inline.js index f8ec307bc2..61e0bdae9c 100644 --- a/packages/slate/test/queries/hasBlocks/inline.js +++ b/packages/slate/test/queries/hasBlocks/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasInlines/block-nested.js b/packages/slate/test/queries/hasInlines/block-nested.js index 0c22a20186..48fdbb8e57 100644 --- a/packages/slate/test/queries/hasInlines/block-nested.js +++ b/packages/slate/test/queries/hasInlines/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasInlines/block.js b/packages/slate/test/queries/hasInlines/block.js index 787b2c9514..55e8b73e97 100644 --- a/packages/slate/test/queries/hasInlines/block.js +++ b/packages/slate/test/queries/hasInlines/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasInlines/inline-nested.js b/packages/slate/test/queries/hasInlines/inline-nested.js index f5d3a517bb..97280d6b30 100644 --- a/packages/slate/test/queries/hasInlines/inline-nested.js +++ b/packages/slate/test/queries/hasInlines/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasInlines/inline.js b/packages/slate/test/queries/hasInlines/inline.js index 8e85af55b9..80e3aea70c 100644 --- a/packages/slate/test/queries/hasInlines/inline.js +++ b/packages/slate/test/queries/hasInlines/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasTexts/block-nested.js b/packages/slate/test/queries/hasTexts/block-nested.js index 089264b1b9..9c8afbe5fd 100644 --- a/packages/slate/test/queries/hasTexts/block-nested.js +++ b/packages/slate/test/queries/hasTexts/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasTexts/block.js b/packages/slate/test/queries/hasTexts/block.js index 58f8a67e84..db8f383722 100644 --- a/packages/slate/test/queries/hasTexts/block.js +++ b/packages/slate/test/queries/hasTexts/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasTexts/inline-nested.js b/packages/slate/test/queries/hasTexts/inline-nested.js index 10d5d1c7af..8a88cd1fd3 100644 --- a/packages/slate/test/queries/hasTexts/inline-nested.js +++ b/packages/slate/test/queries/hasTexts/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/hasTexts/inline.js b/packages/slate/test/queries/hasTexts/inline.js index f47f65e60f..b8882094ac 100644 --- a/packages/slate/test/queries/hasTexts/inline.js +++ b/packages/slate/test/queries/hasTexts/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/inlines/block.js b/packages/slate/test/queries/inlines/block.js index b7a6348635..5877ad11d0 100644 --- a/packages/slate/test/queries/inlines/block.js +++ b/packages/slate/test/queries/inlines/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/inlines/inline-multiple.js b/packages/slate/test/queries/inlines/inline-multiple.js index 92eb234e4f..fb3567f963 100644 --- a/packages/slate/test/queries/inlines/inline-multiple.js +++ b/packages/slate/test/queries/inlines/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/inlines/inline-nested.js b/packages/slate/test/queries/inlines/inline-nested.js index d878d533af..91955e09ff 100644 --- a/packages/slate/test/queries/inlines/inline-nested.js +++ b/packages/slate/test/queries/inlines/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/inlines/inline-reverse.js b/packages/slate/test/queries/inlines/inline-reverse.js index 6f6af63231..6b68cdbbad 100644 --- a/packages/slate/test/queries/inlines/inline-reverse.js +++ b/packages/slate/test/queries/inlines/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/inlines/inline-void.js b/packages/slate/test/queries/inlines/inline-void.js index 1e2083ad9b..b6c7cfb33b 100644 --- a/packages/slate/test/queries/inlines/inline-void.js +++ b/packages/slate/test/queries/inlines/inline-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/inlines/inline.js b/packages/slate/test/queries/inlines/inline.js index 92b455cd79..35e21d26c5 100644 --- a/packages/slate/test/queries/inlines/inline.js +++ b/packages/slate/test/queries/inlines/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isAtomic/atomic.js b/packages/slate/test/queries/isAtomic/atomic.js index 666d8d523c..92950eba95 100644 --- a/packages/slate/test/queries/isAtomic/atomic.js +++ b/packages/slate/test/queries/isAtomic/atomic.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isAtomic/non-atomic.js b/packages/slate/test/queries/isAtomic/non-atomic.js index 6bffa13ac8..703eb34ea5 100644 --- a/packages/slate/test/queries/isAtomic/non-atomic.js +++ b/packages/slate/test/queries/isAtomic/non-atomic.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isInline/block.js b/packages/slate/test/queries/isInline/block.js index 255b4a4581..d38e31c906 100644 --- a/packages/slate/test/queries/isInline/block.js +++ b/packages/slate/test/queries/isInline/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isInline/inline-void.js b/packages/slate/test/queries/isInline/inline-void.js index 885f414476..1f4f1ffb05 100644 --- a/packages/slate/test/queries/isInline/inline-void.js +++ b/packages/slate/test/queries/isInline/inline-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isInline/inline.js b/packages/slate/test/queries/isInline/inline.js index 9f7ccf3046..a05f1ca740 100644 --- a/packages/slate/test/queries/isInline/inline.js +++ b/packages/slate/test/queries/isInline/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isInline/text.js b/packages/slate/test/queries/isInline/text.js index 8ff1a9b17d..0d6e4baf1c 100644 --- a/packages/slate/test/queries/isInline/text.js +++ b/packages/slate/test/queries/isInline/text.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isInline/value.js b/packages/slate/test/queries/isInline/value.js index 9015edf444..9c02030887 100644 --- a/packages/slate/test/queries/isInline/value.js +++ b/packages/slate/test/queries/isInline/value.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isVoid/block-void.js b/packages/slate/test/queries/isVoid/block-void.js index d3ec4368de..de2fe9912f 100644 --- a/packages/slate/test/queries/isVoid/block-void.js +++ b/packages/slate/test/queries/isVoid/block-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isVoid/block.js b/packages/slate/test/queries/isVoid/block.js index 06261160ae..f401314ad2 100644 --- a/packages/slate/test/queries/isVoid/block.js +++ b/packages/slate/test/queries/isVoid/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isVoid/inline-void.js b/packages/slate/test/queries/isVoid/inline-void.js index 9398494ed1..3a87de53fd 100644 --- a/packages/slate/test/queries/isVoid/inline-void.js +++ b/packages/slate/test/queries/isVoid/inline-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isVoid/inline.js b/packages/slate/test/queries/isVoid/inline.js index 21eff3669b..d76d2cfad4 100644 --- a/packages/slate/test/queries/isVoid/inline.js +++ b/packages/slate/test/queries/isVoid/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isVoid/text.js b/packages/slate/test/queries/isVoid/text.js index c4efa18d0a..b81b768444 100644 --- a/packages/slate/test/queries/isVoid/text.js +++ b/packages/slate/test/queries/isVoid/text.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/isVoid/value.js b/packages/slate/test/queries/isVoid/value.js index d19f550bba..0b8738c51b 100644 --- a/packages/slate/test/queries/isVoid/value.js +++ b/packages/slate/test/queries/isVoid/value.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafBlocks/block-multiple.js b/packages/slate/test/queries/leafBlocks/block-multiple.js index 9c91c8e8f6..a183c1c87a 100644 --- a/packages/slate/test/queries/leafBlocks/block-multiple.js +++ b/packages/slate/test/queries/leafBlocks/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafBlocks/block-nested.js b/packages/slate/test/queries/leafBlocks/block-nested.js index 6cccc38e9c..5892bd56ef 100644 --- a/packages/slate/test/queries/leafBlocks/block-nested.js +++ b/packages/slate/test/queries/leafBlocks/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafBlocks/block-reverse.js b/packages/slate/test/queries/leafBlocks/block-reverse.js index c759987dc9..3fa0989227 100644 --- a/packages/slate/test/queries/leafBlocks/block-reverse.js +++ b/packages/slate/test/queries/leafBlocks/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafBlocks/block-void.js b/packages/slate/test/queries/leafBlocks/block-void.js index 2550f933d3..33dbcdbbc0 100644 --- a/packages/slate/test/queries/leafBlocks/block-void.js +++ b/packages/slate/test/queries/leafBlocks/block-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafBlocks/block.js b/packages/slate/test/queries/leafBlocks/block.js index cb19ac37f4..e6dc53c211 100644 --- a/packages/slate/test/queries/leafBlocks/block.js +++ b/packages/slate/test/queries/leafBlocks/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafBlocks/inline.js b/packages/slate/test/queries/leafBlocks/inline.js index d16cf8a366..f1685c62ac 100644 --- a/packages/slate/test/queries/leafBlocks/inline.js +++ b/packages/slate/test/queries/leafBlocks/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafInlines/block.js b/packages/slate/test/queries/leafInlines/block.js index 42ae6aab77..2570d899ef 100644 --- a/packages/slate/test/queries/leafInlines/block.js +++ b/packages/slate/test/queries/leafInlines/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafInlines/inline-multiple.js b/packages/slate/test/queries/leafInlines/inline-multiple.js index b0971ee01a..3c20e1277d 100644 --- a/packages/slate/test/queries/leafInlines/inline-multiple.js +++ b/packages/slate/test/queries/leafInlines/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafInlines/inline-nested.js b/packages/slate/test/queries/leafInlines/inline-nested.js index d77eaf9cb6..4454e30427 100644 --- a/packages/slate/test/queries/leafInlines/inline-nested.js +++ b/packages/slate/test/queries/leafInlines/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafInlines/inline-reverse.js b/packages/slate/test/queries/leafInlines/inline-reverse.js index 19071ccd6c..c98273f378 100644 --- a/packages/slate/test/queries/leafInlines/inline-reverse.js +++ b/packages/slate/test/queries/leafInlines/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafInlines/inline-void.js b/packages/slate/test/queries/leafInlines/inline-void.js index 545bd4b026..74f2b92efc 100644 --- a/packages/slate/test/queries/leafInlines/inline-void.js +++ b/packages/slate/test/queries/leafInlines/inline-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/leafInlines/inline.js b/packages/slate/test/queries/leafInlines/inline.js index 0d6421d81f..6ef8643444 100644 --- a/packages/slate/test/queries/leafInlines/inline.js +++ b/packages/slate/test/queries/leafInlines/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootBlocks/block-multiple.js b/packages/slate/test/queries/rootBlocks/block-multiple.js index 4c62835797..5a731b0cbc 100644 --- a/packages/slate/test/queries/rootBlocks/block-multiple.js +++ b/packages/slate/test/queries/rootBlocks/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootBlocks/block-nested.js b/packages/slate/test/queries/rootBlocks/block-nested.js index ebd9996144..c9973946e1 100644 --- a/packages/slate/test/queries/rootBlocks/block-nested.js +++ b/packages/slate/test/queries/rootBlocks/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootBlocks/block-reverse.js b/packages/slate/test/queries/rootBlocks/block-reverse.js index 4a6fb99b2a..e7d963f318 100644 --- a/packages/slate/test/queries/rootBlocks/block-reverse.js +++ b/packages/slate/test/queries/rootBlocks/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootBlocks/block-void.js b/packages/slate/test/queries/rootBlocks/block-void.js index 16cbcd9bff..659720e1cf 100644 --- a/packages/slate/test/queries/rootBlocks/block-void.js +++ b/packages/slate/test/queries/rootBlocks/block-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootBlocks/block.js b/packages/slate/test/queries/rootBlocks/block.js index 0fa7903637..aef754d0ba 100644 --- a/packages/slate/test/queries/rootBlocks/block.js +++ b/packages/slate/test/queries/rootBlocks/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootBlocks/inline.js b/packages/slate/test/queries/rootBlocks/inline.js index 359c506804..7cddd4b285 100644 --- a/packages/slate/test/queries/rootBlocks/inline.js +++ b/packages/slate/test/queries/rootBlocks/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootInlines/block.js b/packages/slate/test/queries/rootInlines/block.js index 41a5b8b2d5..357717d71a 100644 --- a/packages/slate/test/queries/rootInlines/block.js +++ b/packages/slate/test/queries/rootInlines/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootInlines/inline-multiple.js b/packages/slate/test/queries/rootInlines/inline-multiple.js index fca59f22bc..a3c64ea6f0 100644 --- a/packages/slate/test/queries/rootInlines/inline-multiple.js +++ b/packages/slate/test/queries/rootInlines/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootInlines/inline-nested.js b/packages/slate/test/queries/rootInlines/inline-nested.js index cf98b8d4d5..f53d1a819f 100644 --- a/packages/slate/test/queries/rootInlines/inline-nested.js +++ b/packages/slate/test/queries/rootInlines/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootInlines/inline-reverse.js b/packages/slate/test/queries/rootInlines/inline-reverse.js index a1e4af7d46..1f8ce7d4c7 100644 --- a/packages/slate/test/queries/rootInlines/inline-reverse.js +++ b/packages/slate/test/queries/rootInlines/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootInlines/inline-void.js b/packages/slate/test/queries/rootInlines/inline-void.js index 5a91539bc2..9ddbb9a2cc 100644 --- a/packages/slate/test/queries/rootInlines/inline-void.js +++ b/packages/slate/test/queries/rootInlines/inline-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/rootInlines/inline.js b/packages/slate/test/queries/rootInlines/inline.js index edb9f350ee..e34c6d580b 100644 --- a/packages/slate/test/queries/rootInlines/inline.js +++ b/packages/slate/test/queries/rootInlines/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/block-multiple.js b/packages/slate/test/queries/texts/block-multiple.js index 5d3ecb98bb..ea1907ddf1 100644 --- a/packages/slate/test/queries/texts/block-multiple.js +++ b/packages/slate/test/queries/texts/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/block-nested.js b/packages/slate/test/queries/texts/block-nested.js index 5287539bfd..476c14f650 100644 --- a/packages/slate/test/queries/texts/block-nested.js +++ b/packages/slate/test/queries/texts/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/block-reverse.js b/packages/slate/test/queries/texts/block-reverse.js index 57a9b9c456..711d471627 100644 --- a/packages/slate/test/queries/texts/block-reverse.js +++ b/packages/slate/test/queries/texts/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/block-void.js b/packages/slate/test/queries/texts/block-void.js index c1b3b75493..cc2d966386 100644 --- a/packages/slate/test/queries/texts/block-void.js +++ b/packages/slate/test/queries/texts/block-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/block.js b/packages/slate/test/queries/texts/block.js index bc7f4e0348..270a4fbaf8 100644 --- a/packages/slate/test/queries/texts/block.js +++ b/packages/slate/test/queries/texts/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/inline-multiple.js b/packages/slate/test/queries/texts/inline-multiple.js index 823531a7cf..491f83a993 100644 --- a/packages/slate/test/queries/texts/inline-multiple.js +++ b/packages/slate/test/queries/texts/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/inline-nested.js b/packages/slate/test/queries/texts/inline-nested.js index 62b00986dd..8f1ea6eae4 100644 --- a/packages/slate/test/queries/texts/inline-nested.js +++ b/packages/slate/test/queries/texts/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/inline-reverse.js b/packages/slate/test/queries/texts/inline-reverse.js index c47fc23bca..7f79851cc2 100644 --- a/packages/slate/test/queries/texts/inline-reverse.js +++ b/packages/slate/test/queries/texts/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/inline-void.js b/packages/slate/test/queries/texts/inline-void.js index febeec7c26..6549dd1135 100644 --- a/packages/slate/test/queries/texts/inline-void.js +++ b/packages/slate/test/queries/texts/inline-void.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( diff --git a/packages/slate/test/queries/texts/inline.js b/packages/slate/test/queries/texts/inline.js index 86cf7d24bd..5ac0b53e1e 100644 --- a/packages/slate/test/queries/texts/inline.js +++ b/packages/slate/test/queries/texts/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../helpers' +import { h } from '../../helpers' export const input = ( From 3d9e221d498257fb21a13611a1c9d0f97520980d Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 10:07:45 -0400 Subject: [PATCH 061/165] cleanup, get non-fragment commands passing --- .../slate/src/classes/commands/annotation.ts | 20 +-- packages/slate/src/classes/commands/mark.ts | 147 +++++++----------- .../slate/src/classes/commands/selection.ts | 27 ++-- packages/slate/src/classes/commands/text.ts | 21 ++- packages/slate/src/interfaces/range.ts | 10 ++ .../point/decoration-after-atomic.js | 27 ---- .../point/decoration-before-atomic.js | 29 ---- .../point/decoration-middle-atomic.js | 25 --- .../insertText/point/selection-after.js | 2 +- .../insertText/point/selection-before.js | 2 +- .../insertText/point/selection-end.js | 2 +- .../insertText/point/selection-middle.js | 2 +- .../insertText/point/selection-start.js | 2 +- .../commands/insertText/point/text-end.js | 2 +- .../commands/insertText/point/text-middle.js | 2 +- .../commands/insertText/point/text-start.js | 4 +- packages/slate/test/commands/select/path.js | 23 +++ packages/slate/test/commands/select/point.js | 26 ++++ .../commands/select/{basic.js => range.js} | 0 .../test/commands/setMarks/path/basic.js | 6 +- 20 files changed, 155 insertions(+), 224 deletions(-) delete mode 100644 packages/slate/test/commands/insertText/point/decoration-after-atomic.js delete mode 100644 packages/slate/test/commands/insertText/point/decoration-before-atomic.js delete mode 100644 packages/slate/test/commands/insertText/point/decoration-middle-atomic.js create mode 100644 packages/slate/test/commands/select/path.js create mode 100644 packages/slate/test/commands/select/point.js rename packages/slate/test/commands/select/{basic.js => range.js} (100%) diff --git a/packages/slate/src/classes/commands/annotation.ts b/packages/slate/src/classes/commands/annotation.ts index 94963b4333..ad8143d530 100755 --- a/packages/slate/src/classes/commands/annotation.ts +++ b/packages/slate/src/classes/commands/annotation.ts @@ -51,9 +51,7 @@ class AnnotationCommands { const annotation = annotations[key] const newProps = {} const prevProps = {} - let isChange = false - // Dedupe new and old properties to avoid unnecessary sets. for (const k in props) { const isPoint = k === 'anchor' || k === 'focus' @@ -61,23 +59,19 @@ class AnnotationCommands { (isPoint && !Point.equals(props[k], annotation[k])) || (!isPoint && props[k] !== annotation[k]) ) { - isChange = true newProps[k] = props[k] prevProps[k] = annotation[k] } } - // If no properties have actually changed, don't apply an operation at all. - if (!isChange) { - return + if (Object.keys(newProps).length > 0) { + this.apply({ + type: 'set_annotation', + key, + properties: prevProps, + newProperties: newProps, + }) } - - this.apply({ - type: 'set_annotation', - key, - properties: prevProps, - newProperties: newProps, - }) } } diff --git a/packages/slate/src/classes/commands/mark.ts b/packages/slate/src/classes/commands/mark.ts index b08893c3ea..c109303d0d 100644 --- a/packages/slate/src/classes/commands/mark.ts +++ b/packages/slate/src/classes/commands/mark.ts @@ -1,6 +1,6 @@ import { Editor, Mark, Path, Range } from '../..' -class MarkingCommands { +class MarkCommands { addMarks( this: Editor, marks: Mark[], @@ -9,30 +9,20 @@ class MarkingCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false + let { at = this.value.selection } = options - if (!at && selection) { - at = selection - isSelection = true - } + if (!at) { + return + } else if (Range.isRange(at)) { + at = splitRange(this, at) - if (Path.isPath(at)) { + if (options.at == null) { + this.select(at) + } + } else if (Path.isPath(at)) { at = this.getRange(at) } - if (!Range.isRange(at)) { - return - } - - // Split the text nodes at the range's edges if necessary. - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) - this.splitNodes({ at: end, always: false }) - this.splitNodes({ at: start, always: false }) - at = rangeRef.unref()! - // De-dupe the marks being added to ensure the set is unique. const set: Mark[] = [] @@ -49,10 +39,6 @@ class MarkingCommands { } } } - - if (isSelection) { - this.select(at) - } }) } @@ -64,34 +50,23 @@ class MarkingCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false + let { at = this.value.selection } = options - if (!at && selection) { - at = selection - isSelection = true - } + if (!at) { + return + } else if (Range.isRange(at)) { + at = splitRange(this, at) - if (Path.isPath(at)) { + if (options.at == null) { + this.select(at) + } + } else if (Path.isPath(at)) { at = this.getRange(at) } - if (Range.isRange(at)) { - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) - this.splitNodes({ at: end, always: false }) - this.splitNodes({ at: start, always: false }) - at = rangeRef.unref()! - - for (const [mark, i, node, path] of this.marks({ at })) { - if (Mark.exists(mark, marks)) { - this.apply({ type: 'remove_mark', path, mark }) - } - } - - if (isSelection) { - this.select(at) + for (const [mark, i, node, path] of this.marks({ at })) { + if (Mark.exists(mark, marks)) { + this.apply({ type: 'remove_mark', path, mark }) } } }) @@ -106,36 +81,22 @@ class MarkingCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - let { at } = options - let isSelection = false + let { at = this.value.selection } = options - if (!at && selection) { - at = selection - isSelection = true - } - - // PERF: Do this before the path coercion logic since we're guaranteed not - // to need to split in that case. - if (Range.isRange(at)) { - // Split the text nodes at the range's edges if necessary. - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) - this.splitNodes({ at: end, always: false }) - this.splitNodes({ at: start, always: false }) - at = rangeRef.unref()! - } + if (!at) { + return + } else if (Range.isRange(at)) { + at = splitRange(this, at) - if (Path.isPath(at)) { + if (options.at == null) { + this.select(at) + } + } else if (Path.isPath(at)) { at = this.getRange(at) } - if (Range.isRange(at)) { - for (const [mark, i, node, path] of this.marks({ at })) { - if (!Mark.exists(mark, marks)) { - continue - } - + for (const [mark, i, node, path] of this.marks({ at })) { + if (Mark.exists(mark, marks)) { const newProps = {} for (const k in props) { @@ -144,21 +105,14 @@ class MarkingCommands { } } - // If no properties have changed don't apply an operation at all. - if (Object.keys(newProps).length === 0) { - continue + if (Object.keys(newProps).length > 0) { + this.apply({ + type: 'set_mark', + path, + properties: mark, + newProperties: newProps, + }) } - - this.apply({ - type: 'set_mark', - path, - properties: mark, - newProperties: newProps, - }) - } - - if (isSelection) { - this.select(at) } } }) @@ -172,17 +126,28 @@ class MarkingCommands { } = {} ) { this.withoutNormalizing(() => { - const { at } = options - const existing = this.getActiveMarks({ at }) + const existing = this.getActiveMarks(options) const exists = marks.every(m => Mark.exists(m, existing)) if (exists) { - this.removeMarks(marks, { at }) + this.removeMarks(marks, options) } else { - this.addMarks(marks, { at }) + this.addMarks(marks, options) } }) } } -export default MarkingCommands +/** + * Split the text nodes at a range's edges to prepare for adding/removing marks. + */ + +const splitRange = (editor: Editor, range: Range): Range => { + const rangeRef = editor.createRangeRef(range, { stick: 'inward' }) + const [start, end] = Range.points(range) + editor.splitNodes({ at: end, match: 'text', always: false }) + editor.splitNodes({ at: start, match: 'text', always: false }) + return rangeRef.unref()! +} + +export default MarkCommands diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index ae161f80c8..7165b28866 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -1,4 +1,4 @@ -import { Editor, Point, Range } from '../..' +import { Editor, Point, Range, Path } from '../..' class SelectionCommands { /** @@ -105,14 +105,13 @@ class SelectionCommands { * Set the selection to a new value. */ - select(this: Editor, target: Point | Range | Partial) { + select(this: Editor, target: Range | Point | Path) { const { selection } = this.value if (Point.isPoint(target)) { - target = { - anchor: target, - focus: target, - } + target = { anchor: target, focus: target } + } else if (Path.isPath(target)) { + target = this.getRange(target) } if (selection) { @@ -185,7 +184,6 @@ class SelectionCommands { return } - // Remove any props that aren't different from the existing selection. for (const k in props) { if ( (k === 'anchor' && @@ -201,16 +199,13 @@ class SelectionCommands { } } - // If nothing has changed, don't apply any operations. - if (Object.keys(oldProps).length === 0) { - return + if (Object.keys(oldProps).length > 0) { + this.apply({ + type: 'set_selection', + properties: oldProps, + newProperties: newProps, + }) } - - this.apply({ - type: 'set_selection', - properties: oldProps, - newProperties: newProps, - }) } } diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 1d6eb89184..48d72ad515 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -72,8 +72,8 @@ class DeletingCommands { } const rangeRef = this.createRangeRef(at, { stick: 'inward' }) - this.splitNodes({ at: end, depth: d }) - this.splitNodes({ at: start, depth: d }) + this.splitNodes({ at: end, match: d }) + this.splitNodes({ at: start, match: d }) at = rangeRef.unref()! } @@ -150,7 +150,7 @@ class DeletingCommands { } const pointRef = this.createPointRef(at) - this.splitNodes({ at, depth: 'block' }) + this.splitNodes({ at }) if (pointRef.current) { const [, insertPath] = this.getClosestBlock(pointRef.current.path)! @@ -195,15 +195,14 @@ class DeletingCommands { at = selection } - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - if (Range.isRange(at)) { - const [, end] = Range.points(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! + if (Range.isCollapsed(at)) { + at = at.anchor + } else { + const pointRef = this.createPointRef(Range.end(at)) + this.delete({ at }) + at = pointRef.unref()! + } } if (Point.isPoint(at) && !this.getFurthestVoid(at.path)) { diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index ea7e5e6b09..887ed1614c 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -15,6 +15,16 @@ interface Range { } namespace Range { + export const start = (range: Range): Point => { + const [start] = Range.points(range) + return start + } + + export const end = (range: Range): Point => { + const [, end] = Range.points(range) + return end + } + export const intersection = (range: Range, another: Range): Range | null => { if (!Range.includes(range, another)) { return null diff --git a/packages/slate/test/commands/insertText/point/decoration-after-atomic.js b/packages/slate/test/commands/insertText/point/decoration-after-atomic.js deleted file mode 100644 index eb86e11309..0000000000 --- a/packages/slate/test/commands/insertText/point/decoration-after-atomic.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const input = ( - - - w - or - d - - -) - -export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 4 }, 'x') -} - -export const output = ( - - - w - or - dx - - -) diff --git a/packages/slate/test/commands/insertText/point/decoration-before-atomic.js b/packages/slate/test/commands/insertText/point/decoration-before-atomic.js deleted file mode 100644 index 2413f7073a..0000000000 --- a/packages/slate/test/commands/insertText/point/decoration-before-atomic.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const input = ( - - - - w - or - d - - - -) - -export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 1 }, 'x') -} - -export const output = ( - - - wx - or - d - - -) diff --git a/packages/slate/test/commands/insertText/point/decoration-middle-atomic.js b/packages/slate/test/commands/insertText/point/decoration-middle-atomic.js deleted file mode 100644 index b2e76f2580..0000000000 --- a/packages/slate/test/commands/insertText/point/decoration-middle-atomic.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const input = ( - - - - w - or - d - - - -) - -export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 2 }, 'x') -} - -export const output = ( - - woxrd - -) diff --git a/packages/slate/test/commands/insertText/point/selection-after.js b/packages/slate/test/commands/insertText/point/selection-after.js index c2e62331cd..77203f8210 100644 --- a/packages/slate/test/commands/insertText/point/selection-after.js +++ b/packages/slate/test/commands/insertText/point/selection-after.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 4 }, 'x') + editor.insertText('x', { at: { path: [0, 0], offset: 4 } }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/point/selection-before.js b/packages/slate/test/commands/insertText/point/selection-before.js index 735ae85e8b..de6f007c6d 100644 --- a/packages/slate/test/commands/insertText/point/selection-before.js +++ b/packages/slate/test/commands/insertText/point/selection-before.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 0 }, 'x') + editor.insertText('x', { at: { path: [0, 0], offset: 0 } }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/point/selection-end.js b/packages/slate/test/commands/insertText/point/selection-end.js index b59d68867e..c8ad2d6b00 100644 --- a/packages/slate/test/commands/insertText/point/selection-end.js +++ b/packages/slate/test/commands/insertText/point/selection-end.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 3 }, 'x') + editor.insertText('x', { at: { path: [0, 0], offset: 3 } }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/point/selection-middle.js b/packages/slate/test/commands/insertText/point/selection-middle.js index 16c3160966..11a0dbd48e 100644 --- a/packages/slate/test/commands/insertText/point/selection-middle.js +++ b/packages/slate/test/commands/insertText/point/selection-middle.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 2 }, 'x') + editor.insertText('x', { at: { path: [0, 0], offset: 2 } }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/point/selection-start.js b/packages/slate/test/commands/insertText/point/selection-start.js index 7607577bd5..06518e8103 100644 --- a/packages/slate/test/commands/insertText/point/selection-start.js +++ b/packages/slate/test/commands/insertText/point/selection-start.js @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 1 }, 'x') + editor.insertText('x', { at: { path: [0, 0], offset: 1 } }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/point/text-end.js b/packages/slate/test/commands/insertText/point/text-end.js index 8d7557bc6e..89bf87b96f 100644 --- a/packages/slate/test/commands/insertText/point/text-end.js +++ b/packages/slate/test/commands/insertText/point/text-end.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 4 }, 'x') + editor.insertText('x', { at: { path: [0, 0], offset: 4 } }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/point/text-middle.js b/packages/slate/test/commands/insertText/point/text-middle.js index ddbc6c95a8..6094ebeb16 100644 --- a/packages/slate/test/commands/insertText/point/text-middle.js +++ b/packages/slate/test/commands/insertText/point/text-middle.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 2 }, 'x') + editor.insertText('x', { at: { path: [0, 0], offset: 2 } }) } export const output = ( diff --git a/packages/slate/test/commands/insertText/point/text-start.js b/packages/slate/test/commands/insertText/point/text-start.js index 859ca1dfa0..c35f9ef260 100644 --- a/packages/slate/test/commands/insertText/point/text-start.js +++ b/packages/slate/test/commands/insertText/point/text-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.insertTextAtPoint({ path: [0, 0], offset: 0 }, 'a') + editor.insertText('x', { at: { path: [0, 0], offset: 0 } }) } export const input = ( @@ -19,7 +19,7 @@ export const input = ( export const output = ( - aword + xword ) diff --git a/packages/slate/test/commands/select/path.js b/packages/slate/test/commands/select/path.js new file mode 100644 index 0000000000..8567b91d62 --- /dev/null +++ b/packages/slate/test/commands/select/path.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.select([0, 0]) +} + +export const input = ( + + + one + + +) + +export const output = ( + + + one + + +) diff --git a/packages/slate/test/commands/select/point.js b/packages/slate/test/commands/select/point.js new file mode 100644 index 0000000000..a9811b62fd --- /dev/null +++ b/packages/slate/test/commands/select/point.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.select({ + path: [0, 0], + offset: 1, + }) +} + +export const input = ( + + + one + + +) + +export const output = ( + + + one + + +) diff --git a/packages/slate/test/commands/select/basic.js b/packages/slate/test/commands/select/range.js similarity index 100% rename from packages/slate/test/commands/select/basic.js rename to packages/slate/test/commands/select/range.js diff --git a/packages/slate/test/commands/setMarks/path/basic.js b/packages/slate/test/commands/setMarks/path/basic.js index fae67c79e1..86eed69fcb 100644 --- a/packages/slate/test/commands/setMarks/path/basic.js +++ b/packages/slate/test/commands/setMarks/path/basic.js @@ -3,13 +3,13 @@ import { h } from '../../../helpers' export const run = editor => { - editor.setMarks([{ key: 'a' }], { thing: true }, { at: [0, 0] }) + editor.setMarks([{ existing: true }], { key: true }, { at: [0, 0] }) } export const input = ( - word + word ) @@ -17,7 +17,7 @@ export const input = ( export const output = ( - + word From 28bc6e8b6516152b14d1ba9403f01efdbf51f46b Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 10:20:02 -0400 Subject: [PATCH 062/165] remove annotations and isAtomic --- .../slate/src/classes/commands/annotation.ts | 6 +- packages/slate/src/classes/commands/text.ts | 6 -- packages/slate/src/classes/editor.ts | 3 - packages/slate/src/classes/queries/mark.ts | 14 ----- packages/slate/src/index.ts | 5 -- packages/slate/src/interfaces/annotation.ts | 55 ------------------- packages/slate/src/interfaces/operation.ts | 21 +++---- packages/slate/src/interfaces/value.ts | 50 ++++++++++++++--- packages/slate/src/plugins/schema/checkers.ts | 15 +---- packages/slate/src/plugins/schema/error.ts | 17 ++---- packages/slate/src/plugins/schema/plugin.ts | 28 +--------- packages/slate/src/plugins/schema/rule.ts | 1 - 12 files changed, 61 insertions(+), 160 deletions(-) delete mode 100644 packages/slate/src/classes/queries/mark.ts delete mode 100755 packages/slate/src/interfaces/annotation.ts diff --git a/packages/slate/src/classes/commands/annotation.ts b/packages/slate/src/classes/commands/annotation.ts index ad8143d530..f0760d4425 100755 --- a/packages/slate/src/classes/commands/annotation.ts +++ b/packages/slate/src/classes/commands/annotation.ts @@ -1,11 +1,11 @@ -import { Editor, Point, Annotation } from '../..' +import { Editor, Point, Range } from '../..' class AnnotationCommands { /** * Add a new `annotation` object with a `key`. */ - addAnnotation(this: Editor, key: string, annotation: Annotation) { + addAnnotation(this: Editor, key: string, annotation: Range) { this.apply({ type: 'add_annotation', key, @@ -39,7 +39,7 @@ class AnnotationCommands { * Set new properties on an annotation object with `key`. */ - setAnnotation(this: Editor, key: string, props: Partial) { + setAnnotation(this: Editor, key: string, props: Partial) { const { annotations } = this.value if (!(key in annotations)) { diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 48d72ad515..98737d79fb 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -206,12 +206,6 @@ class DeletingCommands { } if (Point.isPoint(at) && !this.getFurthestVoid(at.path)) { - for (const [annotation, key] of this.annotations({ at })) { - if (this.isAtomic(annotation)) { - this.removeAnnotation(key) - } - } - const { path, offset } = at this.apply({ type: 'insert_text', path, offset, text }) } diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index 8c37428e20..d47f5b1dae 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -15,7 +15,6 @@ import MarkCommands from './commands/mark' import SelectionCommands from './commands/selection' import ValueCommands from './commands/value' import ElementQueries from './queries/element' -import MarkQueries from './queries/mark' import PathQueries from './queries/path' import PointQueries from './queries/point' import RangeQueries from './queries/range' @@ -82,7 +81,6 @@ interface Editor SelectionCommands, ValueCommands, ElementQueries, - MarkQueries, PathQueries, PointQueries, RangeQueries, @@ -106,7 +104,6 @@ mixin([ SelectionCommands, ValueCommands, ElementQueries, - MarkQueries, PathQueries, PointQueries, RangeQueries, diff --git a/packages/slate/src/classes/queries/mark.ts b/packages/slate/src/classes/queries/mark.ts deleted file mode 100644 index a5e7ab1ecb..0000000000 --- a/packages/slate/src/classes/queries/mark.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Editor, Mark } from '../..' - -class MarkQueries { - /** - * Determine is a mark is atomic, meaning that removing any text inside the - * mark should remove the mark entirely. - */ - - isAtomic(this: Editor, mark: Mark): boolean { - return false - } -} - -export default MarkQueries diff --git a/packages/slate/src/index.ts b/packages/slate/src/index.ts index ea389cbd99..ee19cc5e7f 100755 --- a/packages/slate/src/index.ts +++ b/packages/slate/src/index.ts @@ -3,11 +3,6 @@ export { PathRef } from './classes/path-ref' export { PointRef } from './classes/point-ref' export { RangeRef } from './classes/range-ref' -export { - Annotation, - AnnotationEntry, - AnnotationPointEntry, -} from './interfaces/annotation' export * from './interfaces/change' export * from './interfaces/element' export * from './interfaces/fragment' diff --git a/packages/slate/src/interfaces/annotation.ts b/packages/slate/src/interfaces/annotation.ts deleted file mode 100755 index 59ec2f1ae2..0000000000 --- a/packages/slate/src/interfaces/annotation.ts +++ /dev/null @@ -1,55 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Mark, Point, PointKey, Range } from '..' - -/** - * `Annotation` objects are a type of formatting that are applied at the - * top-level of a Slate value. They implement both the `Mark` and `Range` - * interfaces, such that a single annotation can describe formatting that spans - * across multiple nodes in the document. - */ - -interface Annotation extends Mark, Range {} - -/** - * `AnnotationEntry` objects are returned when iterating over `Annotation` - * objects in the top-level value. - */ - -type AnnotationEntry = [Annotation, string] - -/** - * `AnnotationPointEntry` objects are returned when iterating over `Point` - * objects that belong to an `Annotation`. - */ - -type AnnotationPointEntry = [Point, PointKey, Annotation, string] - -namespace Annotation { - /** - * Check if a value implements the `Annotation` interface. - */ - - export const isAnnotation = (value: any): value is Annotation => { - return Range.isRange(value) && Mark.isMark(value) - } - - /** - * Check if a value is a map of `Annotation` objects. - */ - - export const isAnnotationMap = ( - value: any - ): value is Record => { - if (!isPlainObject(value)) { - return false - } - - for (const key in value) { - return Annotation.isAnnotation(value[key]) - } - - return true - } -} - -export { Annotation, AnnotationEntry, AnnotationPointEntry } diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index b4a814dcf9..f6008307ca 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -1,10 +1,10 @@ -import { Annotation, Mark, Node, Path, Range, Value } from '..' +import { Mark, Node, Path, Range, Value } from '..' import isPlainObject from 'is-plain-object' type AddAnnotationOperation = { type: 'add_annotation' key: string - annotation: Annotation + annotation: Range [key: string]: any } @@ -49,7 +49,7 @@ type MoveNodeOperation = { type RemoveAnnotationOperation = { type: 'remove_annotation' key: string - annotation: Annotation + annotation: Range [key: string]: any } @@ -78,8 +78,8 @@ type RemoveTextOperation = { type SetAnnotationOperation = { type: 'set_annotation' key: string - properties: Partial - newProperties: Partial + properties: Partial + newProperties: Partial [key: string]: any } @@ -213,11 +213,9 @@ namespace Operation { } case 'add_annotation': { - return ( - typeof value.key === 'string' && - Annotation.isAnnotation(value.annotation) - ) + return typeof value.key === 'string' && Range.isRange(value.annotation) } + case 'insert_node': { return Path.isPath(value.path) && Node.isNode(value.node) } @@ -244,10 +242,7 @@ namespace Operation { } case 'remove_annotation': { - return ( - typeof value.key === 'string' && - Annotation.isAnnotation(value.annotation) - ) + return typeof value.key === 'string' && Range.isRange(value.annotation) } case 'remove_mark': { diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 61f66e203d..933eda3b3d 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -1,8 +1,6 @@ import isPlainObject from 'is-plain-object' import { produce } from 'immer' import { - Annotation, - AnnotationPointEntry, Element, Mark, Node, @@ -22,7 +20,7 @@ import { interface Value extends Element { selection: Range | null - annotations: Record + annotations: Record [key: string]: any } @@ -33,6 +31,20 @@ interface Value extends Element { type ValueEntry = [Value, Path] +/** + * `AnnotationEntry` objects are returned when iterating over annotations + * in the top-level value. + */ + +type AnnotationEntry = [Range, string] + +/** + * `AnnotationPointEntry` objects are returned when iterating over `Point` + * objects that belong to an annotation. + */ + +type AnnotationPointEntry = [Point, PointKey, Range, string] + /** * `SelectionPointEntry` objects are returned when iterating over `Point` * objects that belong to a selection. @@ -50,7 +62,7 @@ namespace Value { isPlainObject(value) && (value.selection === null || Range.isRange(value.selection)) && Node.isNodeList(value.nodes) && - Annotation.isAnnotationMap(value.annotations) + isAnnotationMap(value.annotations) ) } @@ -253,10 +265,10 @@ namespace Value { const newNextPath = Path.transform(nextPath, op)! point.path = newNextPath point.offset = 0 - } else if (Range.isRange(range)) { - v.selection = null - } else if (Annotation.isAnnotation(range)) { + } else if (key != null) { delete v.annotations[key!] + } else { + v.selection = null } } else { range[k] = result @@ -379,4 +391,26 @@ namespace Value { } } -export { Value, ValueEntry } +/** + * Check if a value is a map of `Annotation` objects. + */ + +export const isAnnotationMap = (value: any): value is Record => { + if (!isPlainObject(value)) { + return false + } + + for (const key in value) { + return Range.isRange(value[key]) + } + + return true +} + +export { + Value, + ValueEntry, + AnnotationEntry, + AnnotationPointEntry, + SelectionPointEntry, +} diff --git a/packages/slate/src/plugins/schema/checkers.ts b/packages/slate/src/plugins/schema/checkers.ts index bdfa151f9b..02da002cb6 100644 --- a/packages/slate/src/plugins/schema/checkers.ts +++ b/packages/slate/src/plugins/schema/checkers.ts @@ -1,13 +1,4 @@ -import { - Ancestor, - Annotation, - Element, - Mark, - Node, - Path, - Text, - Value, -} from '../..' +import { Ancestor, Range, Element, Mark, Node, Path, Text, Value } from '../..' import { SchemaError } from './error' import { SchemaRule, SchemaCheck } from './rule' @@ -16,7 +7,7 @@ import { SchemaRule, SchemaCheck } from './rule' */ export const checkAnnotation = ( - annotation: Annotation, + annotation: Range, key: string, check: SchemaCheck ): SchemaError | undefined => { @@ -31,7 +22,7 @@ export const checkAnnotation = ( if ( 'object' in check && check.object === 'annotation' && - !Annotation.isAnnotation(annotation) + !Range.isRange(annotation) ) { return { code: 'annotation_object_invalid', annotation, key } } diff --git a/packages/slate/src/plugins/schema/error.ts b/packages/slate/src/plugins/schema/error.ts index 476dd65d27..da6b943f40 100644 --- a/packages/slate/src/plugins/schema/error.ts +++ b/packages/slate/src/plugins/schema/error.ts @@ -1,29 +1,20 @@ -import { - Ancestor, - Annotation, - Descendant, - Element, - Mark, - Node, - Path, - Text, -} from '../..' +import { Ancestor, Descendant, Range, Mark, Node, Path, Text } from '../..' interface AnnotationInvalidError { code: 'annotation_invalid' - annotation: Annotation + annotation: Range key: string } interface AnnotationObjectInvalidError { code: 'annotation_object_invalid' - annotation: Annotation + annotation: Range key: string } interface AnnotationPropertyInvalidError { code: 'annotation_property_invalid' - annotation: Annotation + annotation: Range key: string property: string } diff --git a/packages/slate/src/plugins/schema/plugin.ts b/packages/slate/src/plugins/schema/plugin.ts index 379da23ad9..6975b09e7f 100644 --- a/packages/slate/src/plugins/schema/plugin.ts +++ b/packages/slate/src/plugins/schema/plugin.ts @@ -1,7 +1,7 @@ import { Editor, Mark, - Annotation, + Range, EditorConstructor, Element, Node, @@ -56,32 +56,6 @@ const SchemaPlugin = ( return (Base: EditorConstructor) => { return class extends Base { - /** - * Check if a mark is atomic based on the schema rules. - */ - - isAtomic(this: Editor, mark: Mark): boolean { - // HACK: The mark-checking logic needs a node and a path for creating an - // error with details. But we don't care about the error itself, so we - // use fake details here. - const index = 0 - const [node, path] = this.getFirstText([]) - - for (const rule of rules) { - if ( - rule.define != null && - rule.define.isAtomic != null && - ((Annotation.isAnnotation(mark) && - checkAnnotation(mark, '', rule.match) == null) || - checkMark(mark, index, node, path, rule.match) == null) - ) { - return rule.define.isAtomic - } - } - - return super.isAtomic(mark) - } - /** * Check if a node is inline based on the schema rules. */ diff --git a/packages/slate/src/plugins/schema/rule.ts b/packages/slate/src/plugins/schema/rule.ts index eaf69a6f2c..822f1f9c03 100644 --- a/packages/slate/src/plugins/schema/rule.ts +++ b/packages/slate/src/plugins/schema/rule.ts @@ -65,7 +65,6 @@ interface SchemaFunctionCheck { } interface SchemaDefine { - isAtomic?: boolean isInline?: boolean isVoid?: boolean } From ef1da7cee952a91e394c8756c168df11e1402a6d Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 10:56:11 -0400 Subject: [PATCH 063/165] rename surround/pluck to cover/uncover --- packages/slate/src/classes/commands/node.ts | 8 ++++---- .../block/block-across-nested.js | 2 +- .../{surroundNodes => coverNodes}/block/block-across.js | 2 +- .../{surroundNodes => coverNodes}/block/block-end.js | 2 +- .../{surroundNodes => coverNodes}/block/block-nested.js | 2 +- .../commands/{surroundNodes => coverNodes}/block/block.js | 2 +- .../{surroundNodes => coverNodes}/block/inline-across.js | 2 +- .../{surroundNodes => coverNodes}/block/omit-nodes.js | 2 +- .../{surroundNodes => coverNodes}/inline/inline-across.js | 2 +- .../{surroundNodes => coverNodes}/inline/inline.js | 2 +- .../commands/{surroundNodes => coverNodes}/inline/text.js | 2 +- .../match-block/block-across.js | 2 +- .../{pluckNodes => uncoverNodes}/match-block/block-end.js | 2 +- .../match-block/block-inline.js | 2 +- .../match-block/block-middle.js | 2 +- .../match-block/block-nested.js | 2 +- .../match-block/block-start.js | 2 +- .../{pluckNodes => uncoverNodes}/match-block/block.js | 2 +- .../match-inline/block-nested.js | 2 +- .../match-inline/inline-across.js | 2 +- .../match-inline/inline-over.js | 2 +- .../{pluckNodes => uncoverNodes}/match-inline/inline.js | 2 +- .../{pluckNodes => uncoverNodes}/path/block-multiple.js | 2 +- .../commands/{pluckNodes => uncoverNodes}/path/block.js | 2 +- 24 files changed, 27 insertions(+), 27 deletions(-) rename packages/slate/test/commands/{surroundNodes => coverNodes}/block/block-across-nested.js (93%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/block/block-across.js (91%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/block/block-end.js (92%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/block/block-nested.js (90%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/block/block.js (89%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/block/inline-across.js (94%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/block/omit-nodes.js (95%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/inline/inline-across.js (95%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/inline/inline.js (92%) rename packages/slate/test/commands/{surroundNodes => coverNodes}/inline/text.js (90%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-block/block-across.js (89%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-block/block-end.js (92%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-block/block-inline.js (93%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-block/block-middle.js (92%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-block/block-nested.js (88%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-block/block-start.js (92%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-block/block.js (86%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-inline/block-nested.js (89%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-inline/inline-across.js (90%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-inline/inline-over.js (90%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/match-inline/inline.js (88%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/path/block-multiple.js (89%) rename packages/slate/test/commands/{pluckNodes => uncoverNodes}/path/block.js (87%) diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index 6dea61fbc2..5202bbb824 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -155,7 +155,7 @@ class NodeCommands { const { length } = parent.nodes if (length === 1) { - this.pluckNodes({ at: parentPath }) + this.uncoverNodes({ at: parentPath }) } else if (index === 0) { this.moveNodes({ at: path, to: parentPath }) } else if (index === length - 1) { @@ -445,7 +445,7 @@ class NodeCommands { * Remove a node at a specific location, replacing it with its children. */ - pluckNodes( + uncoverNodes( this: Editor, options: { at?: AtOption @@ -674,7 +674,7 @@ class NodeCommands { * Surround the nodes at a location with a new parent node. */ - surroundNodes( + coverNodes( this: Editor, element: Element, options: { @@ -791,7 +791,7 @@ class NodeCommands { } } - this.surroundNodes(element, { at, match }) + this.coverNodes(element, { at, match }) if (rangeRef) { rangeRef.unref() diff --git a/packages/slate/test/commands/surroundNodes/block/block-across-nested.js b/packages/slate/test/commands/coverNodes/block/block-across-nested.js similarity index 93% rename from packages/slate/test/commands/surroundNodes/block/block-across-nested.js rename to packages/slate/test/commands/coverNodes/block/block-across-nested.js index cf649a04f2..c5d046b2ba 100644 --- a/packages/slate/test/commands/surroundNodes/block/block-across-nested.js +++ b/packages/slate/test/commands/coverNodes/block/block-across-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/surroundNodes/block/block-across.js b/packages/slate/test/commands/coverNodes/block/block-across.js similarity index 91% rename from packages/slate/test/commands/surroundNodes/block/block-across.js rename to packages/slate/test/commands/coverNodes/block/block-across.js index 6008000cc2..088e061d8a 100644 --- a/packages/slate/test/commands/surroundNodes/block/block-across.js +++ b/packages/slate/test/commands/coverNodes/block/block-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/surroundNodes/block/block-end.js b/packages/slate/test/commands/coverNodes/block/block-end.js similarity index 92% rename from packages/slate/test/commands/surroundNodes/block/block-end.js rename to packages/slate/test/commands/coverNodes/block/block-end.js index d4ee6d150f..f16fe447e1 100644 --- a/packages/slate/test/commands/surroundNodes/block/block-end.js +++ b/packages/slate/test/commands/coverNodes/block/block-end.js @@ -15,7 +15,7 @@ export const input = ( ) export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const output = ( diff --git a/packages/slate/test/commands/surroundNodes/block/block-nested.js b/packages/slate/test/commands/coverNodes/block/block-nested.js similarity index 90% rename from packages/slate/test/commands/surroundNodes/block/block-nested.js rename to packages/slate/test/commands/coverNodes/block/block-nested.js index 5b89d6f30a..1b22254211 100644 --- a/packages/slate/test/commands/surroundNodes/block/block-nested.js +++ b/packages/slate/test/commands/coverNodes/block/block-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/surroundNodes/block/block.js b/packages/slate/test/commands/coverNodes/block/block.js similarity index 89% rename from packages/slate/test/commands/surroundNodes/block/block.js rename to packages/slate/test/commands/coverNodes/block/block.js index 28e339213c..2d67883253 100644 --- a/packages/slate/test/commands/surroundNodes/block/block.js +++ b/packages/slate/test/commands/coverNodes/block/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/surroundNodes/block/inline-across.js b/packages/slate/test/commands/coverNodes/block/inline-across.js similarity index 94% rename from packages/slate/test/commands/surroundNodes/block/inline-across.js rename to packages/slate/test/commands/coverNodes/block/inline-across.js index 8f4adbb24e..017c7304b8 100644 --- a/packages/slate/test/commands/surroundNodes/block/inline-across.js +++ b/packages/slate/test/commands/coverNodes/block/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/surroundNodes/block/omit-nodes.js b/packages/slate/test/commands/coverNodes/block/omit-nodes.js similarity index 95% rename from packages/slate/test/commands/surroundNodes/block/omit-nodes.js rename to packages/slate/test/commands/coverNodes/block/omit-nodes.js index 90ceb88217..93d1294021 100644 --- a/packages/slate/test/commands/surroundNodes/block/omit-nodes.js +++ b/packages/slate/test/commands/coverNodes/block/omit-nodes.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes( + editor.coverNodes( diff --git a/packages/slate/test/commands/surroundNodes/inline/inline-across.js b/packages/slate/test/commands/coverNodes/inline/inline-across.js similarity index 95% rename from packages/slate/test/commands/surroundNodes/inline/inline-across.js rename to packages/slate/test/commands/coverNodes/inline/inline-across.js index 018f125c37..f9b2961f4d 100644 --- a/packages/slate/test/commands/surroundNodes/inline/inline-across.js +++ b/packages/slate/test/commands/coverNodes/inline/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/surroundNodes/inline/inline.js b/packages/slate/test/commands/coverNodes/inline/inline.js similarity index 92% rename from packages/slate/test/commands/surroundNodes/inline/inline.js rename to packages/slate/test/commands/coverNodes/inline/inline.js index 5f22d30b54..fe0fb24ace 100644 --- a/packages/slate/test/commands/surroundNodes/inline/inline.js +++ b/packages/slate/test/commands/coverNodes/inline/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/surroundNodes/inline/text.js b/packages/slate/test/commands/coverNodes/inline/text.js similarity index 90% rename from packages/slate/test/commands/surroundNodes/inline/text.js rename to packages/slate/test/commands/coverNodes/inline/text.js index fe7e677f82..7831d38e0b 100644 --- a/packages/slate/test/commands/surroundNodes/inline/text.js +++ b/packages/slate/test/commands/coverNodes/inline/text.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.surroundNodes() + editor.coverNodes() } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-across.js b/packages/slate/test/commands/uncoverNodes/match-block/block-across.js similarity index 89% rename from packages/slate/test/commands/pluckNodes/match-block/block-across.js rename to packages/slate/test/commands/uncoverNodes/match-block/block-across.js index f52892385a..6515530490 100644 --- a/packages/slate/test/commands/pluckNodes/match-block/block-across.js +++ b/packages/slate/test/commands/uncoverNodes/match-block/block-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-end.js b/packages/slate/test/commands/uncoverNodes/match-block/block-end.js similarity index 92% rename from packages/slate/test/commands/pluckNodes/match-block/block-end.js rename to packages/slate/test/commands/uncoverNodes/match-block/block-end.js index 3ab2401097..a9fea34861 100644 --- a/packages/slate/test/commands/pluckNodes/match-block/block-end.js +++ b/packages/slate/test/commands/uncoverNodes/match-block/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-inline.js b/packages/slate/test/commands/uncoverNodes/match-block/block-inline.js similarity index 93% rename from packages/slate/test/commands/pluckNodes/match-block/block-inline.js rename to packages/slate/test/commands/uncoverNodes/match-block/block-inline.js index b3d99ffff1..057503ec1d 100644 --- a/packages/slate/test/commands/pluckNodes/match-block/block-inline.js +++ b/packages/slate/test/commands/uncoverNodes/match-block/block-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-middle.js b/packages/slate/test/commands/uncoverNodes/match-block/block-middle.js similarity index 92% rename from packages/slate/test/commands/pluckNodes/match-block/block-middle.js rename to packages/slate/test/commands/uncoverNodes/match-block/block-middle.js index aa73590f5a..8d63ff594b 100644 --- a/packages/slate/test/commands/pluckNodes/match-block/block-middle.js +++ b/packages/slate/test/commands/uncoverNodes/match-block/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-nested.js b/packages/slate/test/commands/uncoverNodes/match-block/block-nested.js similarity index 88% rename from packages/slate/test/commands/pluckNodes/match-block/block-nested.js rename to packages/slate/test/commands/uncoverNodes/match-block/block-nested.js index fb3a605d5b..2919779bff 100644 --- a/packages/slate/test/commands/pluckNodes/match-block/block-nested.js +++ b/packages/slate/test/commands/uncoverNodes/match-block/block-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-block/block-start.js b/packages/slate/test/commands/uncoverNodes/match-block/block-start.js similarity index 92% rename from packages/slate/test/commands/pluckNodes/match-block/block-start.js rename to packages/slate/test/commands/uncoverNodes/match-block/block-start.js index 48445e6f84..800611429c 100644 --- a/packages/slate/test/commands/pluckNodes/match-block/block-start.js +++ b/packages/slate/test/commands/uncoverNodes/match-block/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-block/block.js b/packages/slate/test/commands/uncoverNodes/match-block/block.js similarity index 86% rename from packages/slate/test/commands/pluckNodes/match-block/block.js rename to packages/slate/test/commands/uncoverNodes/match-block/block.js index f97887fdb5..de0cc5f321 100644 --- a/packages/slate/test/commands/pluckNodes/match-block/block.js +++ b/packages/slate/test/commands/uncoverNodes/match-block/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-inline/block-nested.js b/packages/slate/test/commands/uncoverNodes/match-inline/block-nested.js similarity index 89% rename from packages/slate/test/commands/pluckNodes/match-inline/block-nested.js rename to packages/slate/test/commands/uncoverNodes/match-inline/block-nested.js index 85ae37fa8b..3396232c8d 100644 --- a/packages/slate/test/commands/pluckNodes/match-inline/block-nested.js +++ b/packages/slate/test/commands/uncoverNodes/match-inline/block-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-inline/inline-across.js b/packages/slate/test/commands/uncoverNodes/match-inline/inline-across.js similarity index 90% rename from packages/slate/test/commands/pluckNodes/match-inline/inline-across.js rename to packages/slate/test/commands/uncoverNodes/match-inline/inline-across.js index c297e0af15..1115456350 100644 --- a/packages/slate/test/commands/pluckNodes/match-inline/inline-across.js +++ b/packages/slate/test/commands/uncoverNodes/match-inline/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-inline/inline-over.js b/packages/slate/test/commands/uncoverNodes/match-inline/inline-over.js similarity index 90% rename from packages/slate/test/commands/pluckNodes/match-inline/inline-over.js rename to packages/slate/test/commands/uncoverNodes/match-inline/inline-over.js index 89439be89e..2984140649 100644 --- a/packages/slate/test/commands/pluckNodes/match-inline/inline-over.js +++ b/packages/slate/test/commands/uncoverNodes/match-inline/inline-over.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/match-inline/inline.js b/packages/slate/test/commands/uncoverNodes/match-inline/inline.js similarity index 88% rename from packages/slate/test/commands/pluckNodes/match-inline/inline.js rename to packages/slate/test/commands/uncoverNodes/match-inline/inline.js index 789497999b..5386f28211 100644 --- a/packages/slate/test/commands/pluckNodes/match-inline/inline.js +++ b/packages/slate/test/commands/uncoverNodes/match-inline/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ match: { key: 'a' } }) + editor.uncoverNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/path/block-multiple.js b/packages/slate/test/commands/uncoverNodes/path/block-multiple.js similarity index 89% rename from packages/slate/test/commands/pluckNodes/path/block-multiple.js rename to packages/slate/test/commands/uncoverNodes/path/block-multiple.js index 1d966873ee..5d165a3912 100644 --- a/packages/slate/test/commands/pluckNodes/path/block-multiple.js +++ b/packages/slate/test/commands/uncoverNodes/path/block-multiple.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ at: [0] }) + editor.uncoverNodes({ at: [0] }) } export const input = ( diff --git a/packages/slate/test/commands/pluckNodes/path/block.js b/packages/slate/test/commands/uncoverNodes/path/block.js similarity index 87% rename from packages/slate/test/commands/pluckNodes/path/block.js rename to packages/slate/test/commands/uncoverNodes/path/block.js index 1f39f29e59..4e41465deb 100644 --- a/packages/slate/test/commands/pluckNodes/path/block.js +++ b/packages/slate/test/commands/uncoverNodes/path/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.pluckNodes({ at: [0] }) + editor.uncoverNodes({ at: [0] }) } export const input = ( From 3cdea29bda87caa7b8096459c620561edaf5d1ad Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 12:38:49 -0400 Subject: [PATCH 064/165] add location concept, change at-path to from-path for iterables --- .../classes/commands/{value.ts => general.ts} | 15 +-- packages/slate/src/classes/commands/mark.ts | 121 +++++++++--------- packages/slate/src/classes/commands/node.ts | 25 ++-- .../slate/src/classes/commands/selection.ts | 4 +- packages/slate/src/classes/commands/text.ts | 3 +- packages/slate/src/classes/editor.ts | 6 +- packages/slate/src/classes/queries/path.ts | 55 +------- packages/slate/src/classes/queries/point.ts | 12 -- packages/slate/src/classes/queries/value.ts | 98 +++++++------- packages/slate/src/index.ts | 1 + packages/slate/src/interfaces/location.ts | 25 ++++ packages/slate/src/interfaces/node.ts | 36 ++++-- packages/slate/src/interfaces/value.ts | 4 +- .../insertText/range/expanded-with-mark.js | 2 + .../hanging-selection-multiple-blocks.js | 26 ++-- .../range/hanging-selection-single-block.js | 24 ++-- .../test/interfaces/Node/descendants/path.js | 2 +- .../Node/entries/path-multiple-elements.js | 2 +- .../Node/entries/path-of-element.js | 2 +- .../test/interfaces/Node/entries/path.js | 2 +- .../slate/test/interfaces/Node/marks/path.js | 2 +- .../Node/texts/path-multiple-elements.js | 2 +- .../interfaces/Node/texts/path-of-element.js | 2 +- .../slate/test/interfaces/Node/texts/path.js | 2 +- packages/slate/test/queries/blocks/at-path.js | 2 +- 25 files changed, 215 insertions(+), 260 deletions(-) rename packages/slate/src/classes/commands/{value.ts => general.ts} (96%) create mode 100755 packages/slate/src/interfaces/location.ts diff --git a/packages/slate/src/classes/commands/value.ts b/packages/slate/src/classes/commands/general.ts similarity index 96% rename from packages/slate/src/classes/commands/value.ts rename to packages/slate/src/classes/commands/general.ts index 11399dfdf5..ef8c7e1a97 100755 --- a/packages/slate/src/classes/commands/value.ts +++ b/packages/slate/src/classes/commands/general.ts @@ -1,13 +1,4 @@ -import { - Change, - Operation, - Editor, - Element, - Node, - Path, - Text, - Value, -} from '../..' +import { Change, Operation, Editor, Node, Path, Text, Value } from '../..' import { DIRTY_PATHS, PATH_REFS, @@ -17,7 +8,7 @@ import { NORMALIZING, } from '../../symbols' -class ValueCommands { +class GeneralCommands { apply(this: Editor, op: Operation): void { this.value = Value.transform(this.value, op) this.operations.push(op) @@ -202,4 +193,4 @@ const getDirtyPaths = (op: Operation) => { } } -export default ValueCommands +export default GeneralCommands diff --git a/packages/slate/src/classes/commands/mark.ts b/packages/slate/src/classes/commands/mark.ts index c109303d0d..f2ca779f52 100644 --- a/packages/slate/src/classes/commands/mark.ts +++ b/packages/slate/src/classes/commands/mark.ts @@ -1,26 +1,22 @@ -import { Editor, Mark, Path, Range } from '../..' +import { Editor, Mark, Location, Range } from '../..' class MarkCommands { + /** + * Add a set of marks to the text nodes at a location. + */ + addMarks( this: Editor, marks: Mark[], options: { - at?: Path | Range + at?: Location } = {} ) { this.withoutNormalizing(() => { - let { at = this.value.selection } = options + const at = splitLocation(this, options) if (!at) { return - } else if (Range.isRange(at)) { - at = splitRange(this, at) - - if (options.at == null) { - this.select(at) - } - } else if (Path.isPath(at)) { - at = this.getRange(at) } // De-dupe the marks being added to ensure the set is unique. @@ -46,27 +42,17 @@ class MarkCommands { this: Editor, marks: Mark[], options: { - at?: Path | Range + at?: Location } = {} ) { this.withoutNormalizing(() => { - let { at = this.value.selection } = options + const at = splitLocation(this, options) - if (!at) { - return - } else if (Range.isRange(at)) { - at = splitRange(this, at) - - if (options.at == null) { - this.select(at) - } - } else if (Path.isPath(at)) { - at = this.getRange(at) - } - - for (const [mark, i, node, path] of this.marks({ at })) { - if (Mark.exists(mark, marks)) { - this.apply({ type: 'remove_mark', path, mark }) + if (at) { + for (const [mark, i, node, path] of this.marks({ at })) { + if (Mark.exists(mark, marks)) { + this.apply({ type: 'remove_mark', path, mark }) + } } } }) @@ -77,41 +63,31 @@ class MarkCommands { marks: Mark[], props: Partial, options: { - at?: Path | Range + at?: Location } = {} ) { this.withoutNormalizing(() => { - let { at = this.value.selection } = options + const at = splitLocation(this, options) - if (!at) { - return - } else if (Range.isRange(at)) { - at = splitRange(this, at) + if (at) { + for (const [mark, i, node, path] of this.marks({ at })) { + if (Mark.exists(mark, marks)) { + const newProps = {} - if (options.at == null) { - this.select(at) - } - } else if (Path.isPath(at)) { - at = this.getRange(at) - } - - for (const [mark, i, node, path] of this.marks({ at })) { - if (Mark.exists(mark, marks)) { - const newProps = {} - - for (const k in props) { - if (props[k] !== mark[k]) { - newProps[k] = props[k] + for (const k in props) { + if (props[k] !== mark[k]) { + newProps[k] = props[k] + } } - } - if (Object.keys(newProps).length > 0) { - this.apply({ - type: 'set_mark', - path, - properties: mark, - newProperties: newProps, - }) + if (Object.keys(newProps).length > 0) { + this.apply({ + type: 'set_mark', + path, + properties: mark, + newProperties: newProps, + }) + } } } } @@ -122,7 +98,7 @@ class MarkCommands { this: Editor, marks: Mark[], options: { - at?: Path | Range + at?: Location } = {} ) { this.withoutNormalizing(() => { @@ -142,12 +118,31 @@ class MarkCommands { * Split the text nodes at a range's edges to prepare for adding/removing marks. */ -const splitRange = (editor: Editor, range: Range): Range => { - const rangeRef = editor.createRangeRef(range, { stick: 'inward' }) - const [start, end] = Range.points(range) - editor.splitNodes({ at: end, match: 'text', always: false }) - editor.splitNodes({ at: start, match: 'text', always: false }) - return rangeRef.unref()! +const splitLocation = ( + editor: Editor, + options: { at?: Location } = {} +): Location | undefined => { + const { at = editor.value.selection } = options + + if (!at) { + return + } + + if (Range.isRange(at)) { + const rangeRef = editor.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.points(at) + editor.splitNodes({ at: end, match: 'text', always: false }) + editor.splitNodes({ at: start, match: 'text', always: false }) + const range = rangeRef.unref()! + + if (options.at == null) { + editor.select(range) + } + + return range + } + + return at } export default MarkCommands diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index 5202bbb824..b7f272e2c1 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -4,14 +4,13 @@ import { Node, NodeEntry, Element, + Location, Path, Text, Range, Point, } from '../..' -type AtOption = Range | Point | Path - type MatchOption = | number | 'value' @@ -30,7 +29,7 @@ class NodeCommands { this: Editor, nodes: Node | Node[], options: { - at?: AtOption + at?: Location match?: MatchOption } = {} ) { @@ -125,7 +124,7 @@ class NodeCommands { liftNodes( this: Editor, options: { - at?: AtOption + at?: Location match?: MatchOption } ) { @@ -176,7 +175,7 @@ class NodeCommands { mergeNodes( this: Editor, options: { - at?: AtOption + at?: Location match?: MatchOption } = {} ) { @@ -306,7 +305,7 @@ class NodeCommands { moveNodes( this: Editor, options: { - at?: AtOption + at?: Location match?: MatchOption to: Path } @@ -448,7 +447,7 @@ class NodeCommands { uncoverNodes( this: Editor, options: { - at?: AtOption + at?: Location match?: MatchOption } ) { @@ -486,7 +485,7 @@ class NodeCommands { removeNodes( this: Editor, options: { - at?: AtOption + at?: Location match?: MatchOption } = {} ) { @@ -522,7 +521,7 @@ class NodeCommands { this: Editor, props: Partial, options: { - at?: AtOption + at?: Location match?: MatchOption hanging?: boolean } = {} @@ -574,7 +573,7 @@ class NodeCommands { splitNodes( this: Editor, options: { - at?: AtOption + at?: Location match?: MatchOption always?: boolean height?: number @@ -678,7 +677,7 @@ class NodeCommands { this: Editor, element: Element, options: { - at?: AtOption + at?: Location match?: MatchOption } = {} ) { @@ -730,7 +729,7 @@ class NodeCommands { unwrapNodes( this: Editor, options: { - at?: AtOption + at?: Location match?: MatchOption } ) { @@ -765,7 +764,7 @@ class NodeCommands { this: Editor, element: Element, options: { - at?: AtOption + at?: Location match?: MatchOption } = {} ) { diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index 7165b28866..122f252711 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -1,4 +1,4 @@ -import { Editor, Point, Range, Path } from '../..' +import { Editor, Location, Point, Range, Path } from '../..' class SelectionCommands { /** @@ -105,7 +105,7 @@ class SelectionCommands { * Set the selection to a new value. */ - select(this: Editor, target: Range | Point | Path) { + select(this: Editor, target: Location) { const { selection } = this.value if (Point.isPoint(target)) { diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 98737d79fb..d0fdc0cdb3 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -4,6 +4,7 @@ import { Node, Fragment, Path, + Location, Range, Point, Value, @@ -17,7 +18,7 @@ class DeletingCommands { delete( this: Editor, options: { - at?: Path | Point | Range + at?: Location distance?: number unit?: 'character' | 'word' | 'line' | 'block' reverse?: boolean diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index d47f5b1dae..2fad1903e6 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -13,7 +13,7 @@ import TextCommands from './commands/text' import NodeCommands from './commands/node' import MarkCommands from './commands/mark' import SelectionCommands from './commands/selection' -import ValueCommands from './commands/value' +import GeneralCommands from './commands/general' import ElementQueries from './queries/element' import PathQueries from './queries/path' import PointQueries from './queries/point' @@ -79,7 +79,7 @@ interface Editor NodeCommands, MarkCommands, SelectionCommands, - ValueCommands, + GeneralCommands, ElementQueries, PathQueries, PointQueries, @@ -102,7 +102,7 @@ mixin([ NodeCommands, MarkCommands, SelectionCommands, - ValueCommands, + GeneralCommands, ElementQueries, PathQueries, PointQueries, diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 0113588884..53ff37e0a7 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -35,57 +35,6 @@ class PathQueries { return Node.get(this.value, path) } - getDepth( - this: Editor, - path: Path, - depth: 'block' | 'inline' | 'text' | number | undefined - ): number { - if (depth === 'block') { - const closestBlock = this.getClosestBlock(path) - depth = closestBlock && closestBlock[1].length - } else if (depth === 'inline') { - const closestInline = this.getClosestInline(path) - depth = closestInline && closestInline[1].length - } else if (depth === 'text') { - const start = this.getStart(path) - depth = start && start.path.length - } - - return depth == null ? path.length : depth - } - - getHeight(this: Editor, path: Path, height: number | 'inline' | 'block') { - if (height === 'block') { - const closestBlock = this.getClosestBlock(path) - - if (closestBlock) { - const [, blockPath] = closestBlock - const relPath = Path.relative(path, blockPath) - return relPath.length - } else { - return 0 - } - } - - if (height === 'inline') { - const furthestInline = this.getFurthestInline(path) - - if (furthestInline) { - const [, inlinePath] = furthestInline - const relPath = Path.relative(path, inlinePath) - return relPath.length - } else { - return 0 - } - } - - if (height > path.length) { - height = path.length - } - - return height - } - /** * Create a mutable ref for a `Path` object, which will stay in sync as new * operations are applied to the this. @@ -228,7 +177,7 @@ class PathQueries { */ getNextText(this: Editor, path: Path): TextEntry | undefined { - const [, next] = this.texts({ at: path }) + const [, next] = this.texts({ from: path }) return next } @@ -281,7 +230,7 @@ class PathQueries { */ getPreviousText(this: Editor, path: Path): TextEntry | undefined { - const [, prev] = this.texts({ at: path, reverse: true }) + const [, prev] = this.texts({ from: path, reverse: true }) return prev } diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index e2f1c6a153..2ca2a7ece5 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -10,18 +10,6 @@ import { import { POINT_REFS } from '../../symbols' class PointQueries { - getTarget( - this: Editor, - point: Point, - depth: number | 'block' | 'inline' | 'text' - ): NodeEntry | undefined { - const range = { anchor: point, focus: point } - - for (const entry of this.depths(depth, { at: range })) { - return entry - } - } - /** * Create a mutable ref for a `Point` object, which will stay in sync as new * operations are applied to the this. diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 7ebed49c80..ec1728d07b 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -34,7 +34,7 @@ class ValueQueries { *annotations( this: Editor, options: { - at?: Path | Point | Range + at?: Range | Point | Path } = {} ): Iterable { const { annotations } = this.value @@ -42,9 +42,7 @@ class ValueQueries { if (Path.isPath(at)) { at = this.getRange(at) - } - - if (Point.isPoint(at)) { + } else if (Point.isPoint(at)) { at = { anchor: at, focus: at } } @@ -66,7 +64,8 @@ class ValueQueries { *blocks( this: Editor, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean } = {} ): Iterable { @@ -174,7 +173,6 @@ class ValueQueries { const { reverse, match, hanging = false } = options let { at } = options let prevPath: Path | undefined - let test = (entry: NodeEntry) => true // PERF: If the target is a path, we don't need to traverse at all. if (Path.isPath(at)) { @@ -185,7 +183,9 @@ class ValueQueries { if (Point.isPoint(at)) { at = { anchor: at, focus: at } - } else if (!hanging) { + } + + if (!hanging) { at = this.getNonHangingRange(at) } @@ -208,7 +208,8 @@ class ValueQueries { *elements( this: Editor, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean } = {} ): Iterable { @@ -225,7 +226,8 @@ class ValueQueries { *entries( this: Editor, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean } = {} ): Iterable { @@ -252,18 +254,15 @@ class ValueQueries { getActiveMarks( this: Editor, options: { - at?: Path | Point | Range + at?: Range | Point | Path union?: boolean } = {} ): Mark[] { const { value } = this - const { selection } = this.value - let { at, union = false } = options - let isSelection = false + let { at = this.value.selection, union = false } = options - if (!at && selection) { - at = selection - isSelection = true + if (!at) { + return [] } if (Path.isPath(at)) { @@ -293,37 +292,34 @@ class ValueQueries { const marks: Mark[] = [] let first = true + at = this.getNonHangingRange(at) - if (Range.isRange(at)) { - at = this.getNonHangingRange(at) - - for (const [node] of this.texts({ at })) { - if (first) { - marks.push(...node.marks) - first = false - continue - } + for (const [node] of this.texts({ at })) { + if (first) { + marks.push(...node.marks) + first = false + continue + } - if (union) { - for (const mark of node.marks) { - if (!Mark.exists(mark, marks)) { - marks.push(mark) - } - } - } else { - // PERF: If we're doing an intersection and the result hits zero it can - // never increase again, so we can exit early. - if (marks.length === 0) { - break + if (union) { + for (const mark of node.marks) { + if (!Mark.exists(mark, marks)) { + marks.push(mark) } + } + } else { + // PERF: If we're doing an intersection and the result hits zero it can + // never increase again, so we can exit early. + if (marks.length === 0) { + break + } - // Iterate backwards so that removing marks doesn't impact indexing. - for (let i = marks.length - 1; i >= 0; i--) { - const existing = marks[i] + // Iterate backwards so that removing marks doesn't impact indexing. + for (let i = marks.length - 1; i >= 0; i--) { + const existing = marks[i] - if (!Mark.exists(existing, node.marks)) { - marks.splice(i, 1) - } + if (!Mark.exists(existing, node.marks)) { + marks.splice(i, 1) } } } @@ -339,16 +335,12 @@ class ValueQueries { *inlines( this: Editor, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean } = {} ): Iterable { - const iterable = Node.elements(this.value, { - ...options, - pass: ([n]) => Element.isElement(n) && this.isVoid(n), - }) - - for (const [n, p] of iterable) { + for (const [n, p] of this.elements(options)) { if (this.isInline(n)) { yield [n, p] } @@ -362,7 +354,8 @@ class ValueQueries { *marks( this: Editor, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean } = {} ): Iterable { @@ -395,7 +388,7 @@ class ValueQueries { const { unit = 'offset', reverse = false, - at = reverse ? this.getEnd([]) : this.getStart([]), + at = reverse ? this.getEnd() : this.getStart(), } = options if (at == null) { @@ -507,7 +500,8 @@ class ValueQueries { *texts( this: Editor, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean } = {} ): Iterable { diff --git a/packages/slate/src/index.ts b/packages/slate/src/index.ts index ee19cc5e7f..342712642f 100755 --- a/packages/slate/src/index.ts +++ b/packages/slate/src/index.ts @@ -6,6 +6,7 @@ export { RangeRef } from './classes/range-ref' export * from './interfaces/change' export * from './interfaces/element' export * from './interfaces/fragment' +export * from './interfaces/location' export * from './interfaces/mark' export * from './interfaces/node' export * from './interfaces/operation' diff --git a/packages/slate/src/interfaces/location.ts b/packages/slate/src/interfaces/location.ts new file mode 100755 index 0000000000..bd31754838 --- /dev/null +++ b/packages/slate/src/interfaces/location.ts @@ -0,0 +1,25 @@ +import isPlainObject from 'is-plain-object' +import { Path, Point, Range } from '..' + +/** + * The `Location` interface is a union of the ways to refer to a specific + * location in a Slate document: paths, points or ranges. + * + * Methods will often accept a `Location` instead of requiring only a `Path`, + * `Point` or `Range`. This eliminates the need for developers to manage + * converting between the different interfaces in their own code base. + */ + +type Location = Path | Point | Range + +namespace Location { + /** + * Check if a value implements the `Location` interface. + */ + + export const isLocation = (value: any): value is Location => { + return Path.isPath(value) || Point.isPoint(value) || Range.isRange(value) + } +} + +export { Location } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 57c4455862..f7d2ff6f07 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -8,6 +8,7 @@ import { Range, Text, TextEntry, + Point, Value, } from '..' @@ -175,7 +176,8 @@ namespace Node { export function* descendants( root: Node, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -198,7 +200,8 @@ namespace Node { export function* elements( root: Node, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -219,23 +222,32 @@ namespace Node { export function* entries( root: Node, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean pass?: (entry: NodeEntry) => boolean } = {} ): Iterable { - const { at = [], reverse = false, pass = () => false } = options - let fromPath + const { at, from, pass, reverse = false } = options + let [, fromPath] = Node.first(root, []) let toPath if (Range.isRange(at)) { const [s, e] = Range.points(at) fromPath = reverse ? e.path : s.path toPath = reverse ? s.path : e.path - } else { - const [, f] = reverse ? Node.last(root, at) : Node.first(root, at) + } else if (Point.isPoint(at)) { + fromPath = toPath = at.path + } else if (Path.isPath(at)) { + const [, f] = Node.first(root, at) + const [, l] = Node.last(root, at) + fromPath = reverse ? l : f + toPath = reverse ? f : l + } + + if (Path.isPath(from)) { + const [, f] = reverse ? Node.last(root, from) : Node.first(root, from) fromPath = f - toPath = null } const visited = new Set() @@ -256,7 +268,7 @@ namespace Node { !visited.has(n) && !Text.isText(n) && n.nodes.length !== 0 && - !pass([n, p]) + (pass == null || pass([n, p]) === false) ) { visited.add(n) let nextIndex = reverse ? n.nodes.length - 1 : 0 @@ -500,7 +512,8 @@ namespace Node { export function* marks( root: Node, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -583,7 +596,8 @@ namespace Node { export function* texts( root: Node, options: { - at?: Path | Range + at?: Range | Point | Path + from?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 933eda3b3d..98b064b900 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -246,8 +246,8 @@ namespace Value { const parent = Node.parent(v, path) const [, first] = Node.first(v, path) const [, last] = Node.last(v, path) - const [, prev] = Node.texts(v, { at: first, reverse: true }) - const [, next] = Node.texts(v, { at: last }) + const [, prev] = Node.texts(v, { from: first, reverse: true }) + const [, next] = Node.texts(v, { from: last }) parent.nodes.splice(index, 1) // Transform all of the points in the value, but if the point was in the diff --git a/packages/slate/test/commands/insertText/range/expanded-with-mark.js b/packages/slate/test/commands/insertText/range/expanded-with-mark.js index f9ad312899..c5c3b3a367 100644 --- a/packages/slate/test/commands/insertText/range/expanded-with-mark.js +++ b/packages/slate/test/commands/insertText/range/expanded-with-mark.js @@ -27,3 +27,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/insertText/range/hanging-selection-multiple-blocks.js b/packages/slate/test/commands/insertText/range/hanging-selection-multiple-blocks.js index cc98f434f9..a8dde44a42 100644 --- a/packages/slate/test/commands/insertText/range/hanging-selection-multiple-blocks.js +++ b/packages/slate/test/commands/insertText/range/hanging-selection-multiple-blocks.js @@ -8,24 +8,22 @@ export const run = editor => { export const input = ( - - - one - - two - - three - - + + one + + two + + three + ) export const output = ( - - - athree - - + + athree + ) + +export const skip = true diff --git a/packages/slate/test/commands/insertText/range/hanging-selection-single-block.js b/packages/slate/test/commands/insertText/range/hanging-selection-single-block.js index ac2626465e..a84d35ee4a 100644 --- a/packages/slate/test/commands/insertText/range/hanging-selection-single-block.js +++ b/packages/slate/test/commands/insertText/range/hanging-selection-single-block.js @@ -8,23 +8,21 @@ export const run = editor => { export const input = ( - - - one - - - two - - + + one + + + two + ) export const output = ( - - - atwo - - + + atwo + ) + +export const skip = true diff --git a/packages/slate/test/interfaces/Node/descendants/path.js b/packages/slate/test/interfaces/Node/descendants/path.js index 1f052a774d..49d4cac85a 100644 --- a/packages/slate/test/interfaces/Node/descendants/path.js +++ b/packages/slate/test/interfaces/Node/descendants/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.descendants(value, { at: [0, 1] })) + return Array.from(Node.descendants(value, { from: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js b/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js index 1bbf9cdb45..df5af942ff 100644 --- a/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js +++ b/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.entries(value, { at: [0, 1] })) + return Array.from(Node.entries(value, { from: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/entries/path-of-element.js b/packages/slate/test/interfaces/Node/entries/path-of-element.js index 164a19b713..4389a2d65e 100644 --- a/packages/slate/test/interfaces/Node/entries/path-of-element.js +++ b/packages/slate/test/interfaces/Node/entries/path-of-element.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.entries(value, { at: [0] })) + return Array.from(Node.entries(value, { from: [0] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/entries/path.js b/packages/slate/test/interfaces/Node/entries/path.js index 742162e8f9..1a9b3a5229 100644 --- a/packages/slate/test/interfaces/Node/entries/path.js +++ b/packages/slate/test/interfaces/Node/entries/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.entries(value, { at: [0, 1] })) + return Array.from(Node.entries(value, { from: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/marks/path.js b/packages/slate/test/interfaces/Node/marks/path.js index 2f8181f33c..b982533e1d 100644 --- a/packages/slate/test/interfaces/Node/marks/path.js +++ b/packages/slate/test/interfaces/Node/marks/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.marks(value, { at: [0, 1] })) + return Array.from(Node.marks(value, { from: [0, 1] })) } export const output = [[{ key: 'b' }, 0, two, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js b/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js index 86b5d1088d..59d80af6db 100644 --- a/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js +++ b/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { at: [0, 1] })) + return Array.from(Node.texts(value, { from: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/texts/path-of-element.js b/packages/slate/test/interfaces/Node/texts/path-of-element.js index c0bac4346f..bb0e7326f2 100644 --- a/packages/slate/test/interfaces/Node/texts/path-of-element.js +++ b/packages/slate/test/interfaces/Node/texts/path-of-element.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { at: [0] })) + return Array.from(Node.texts(value, { from: [0] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/texts/path.js b/packages/slate/test/interfaces/Node/texts/path.js index af835df35b..30b8963c4d 100644 --- a/packages/slate/test/interfaces/Node/texts/path.js +++ b/packages/slate/test/interfaces/Node/texts/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { at: [0, 1] })) + return Array.from(Node.texts(value, { from: [0, 1] })) } export const output = [[, [0, 1]]] diff --git a/packages/slate/test/queries/blocks/at-path.js b/packages/slate/test/queries/blocks/at-path.js index 20ce12c5eb..dde098baf5 100644 --- a/packages/slate/test/queries/blocks/at-path.js +++ b/packages/slate/test/queries/blocks/at-path.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.blocks({ at: [1] })) + return Array.from(editor.blocks({ from: [1] })) } export const output = [[two, [1]], [three, [2]]] From ecbcfa13bd976f49139b6c3fa9f7ee8e87e4d5b6 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 13:13:39 -0400 Subject: [PATCH 065/165] refactor batches --- packages/slate/src/classes/commands/node.ts | 54 ++++++++++++--------- packages/slate/src/classes/queries/path.ts | 1 + packages/slate/src/classes/queries/point.ts | 10 +--- packages/slate/src/classes/queries/range.ts | 4 +- packages/slate/src/classes/queries/value.ts | 53 ++++---------------- 5 files changed, 43 insertions(+), 79 deletions(-) diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index b7f272e2c1..af8cc9ee01 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -694,29 +694,37 @@ class NodeCommands { } } - for (const [, , matches] of this.batches({ - element, - at, - match, - })) { - const [first] = matches - const last = matches[matches.length - 1] - const [, firstPath] = first - const [, lastPath] = last - const commonPath = Path.equals(firstPath, lastPath) - ? Path.parent(firstPath) - : Path.common(firstPath, lastPath) - - const range = this.getRange(firstPath, lastPath) - const depth = commonPath.length + 1 - const wrapperPath = Path.next(lastPath).slice(0, depth) - const wrapper = { ...element, nodes: [] } - this.insertNodes(wrapper, { at: wrapperPath }) - this.moveNodes({ - at: range, - match: depth, - to: wrapperPath.concat(0), - }) + const roots: NodeEntry[] = this.isInline(element) + ? Array.from(this.matches({ ...options, at, match: 'block' })) + : [[this.value, []]] + + for (const [, rootPath] of roots) { + const a = Range.isRange(at) + ? Range.intersection(at, this.getRange(rootPath))! + : at + + const matches = Array.from(this.matches({ ...options, at: a, match })) + + if (matches.length > 0) { + const [first] = matches + const last = matches[matches.length - 1] + const [, firstPath] = first + const [, lastPath] = last + const commonPath = Path.equals(firstPath, lastPath) + ? Path.parent(firstPath) + : Path.common(firstPath, lastPath) + + const range = this.getRange(firstPath, lastPath) + const depth = commonPath.length + 1 + const wrapperPath = Path.next(lastPath).slice(0, depth) + const wrapper = { ...element, nodes: [] } + this.insertNodes(wrapper, { at: wrapperPath }) + this.moveNodes({ + at: range, + match: depth, + to: wrapperPath.concat(0), + }) + } } }) } diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 53ff37e0a7..4fbbeb9d45 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -274,6 +274,7 @@ class PathQueries { return point } } + /** * Get the text content of a node at path. * diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index 2ca2a7ece5..d8dca8e08a 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -1,12 +1,4 @@ -import { - Editor, - Node, - NodeEntry, - Operation, - Path, - Point, - PointRef, -} from '../..' +import { Editor, Path, Point, PointRef } from '../..' import { POINT_REFS } from '../../symbols' class PointQueries { diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts index aaa24ba8e0..820c6f3e1e 100644 --- a/packages/slate/src/classes/queries/range.ts +++ b/packages/slate/src/classes/queries/range.ts @@ -1,9 +1,7 @@ import { produce } from 'immer' -import { Editor, Path, Operation, Range, RangeRef } from '../..' +import { Editor, Range, RangeRef } from '../..' import { RANGE_REFS } from '../../symbols' -let rangeRefIds = 0 - class RangeQueries { /** * Create a mutable ref for a `Range` object, which will stay in sync as new diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index ec1728d07b..c5bacf6bae 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -6,6 +6,7 @@ import { ElementEntry, Mark, Node, + Location, NodeEntry, MarkEntry, Path, @@ -34,7 +35,7 @@ class ValueQueries { *annotations( this: Editor, options: { - at?: Range | Point | Path + at?: Location } = {} ): Iterable { const { annotations } = this.value @@ -64,7 +65,7 @@ class ValueQueries { *blocks( this: Editor, options: { - at?: Range | Point | Path + at?: Location from?: Path reverse?: boolean } = {} @@ -76,42 +77,6 @@ class ValueQueries { }) } - *batches( - this: Editor, - options: { - element: Element - match: NodeMatch - at: Range | Point | Path - hanging?: boolean - reverse?: boolean - } - ): Iterable<[Node, Path, NodeEntry[]]> { - const { element, at, ...rest } = options - let roots: NodeEntry[] = [] - - if (this.isInline(element)) { - for (const [node, path] of this.blocks()) { - if (this.hasInlines(node)) { - roots.push([node, path]) - } - } - } else { - roots.push([this.value, []]) - } - - for (const [node, path] of roots) { - const a = Range.isRange(at) - ? Range.intersection(at, this.getRange(path))! - : at - - const matches = Array.from(this.matches({ at: a, ...rest })) - - if (matches.length !== 0) { - yield [node, path, matches] - } - } - } - isMatch(this: Editor, entry: NodeEntry, match: NodeMatch) { const [node, path] = entry @@ -208,7 +173,7 @@ class ValueQueries { *elements( this: Editor, options: { - at?: Range | Point | Path + at?: Location from?: Path reverse?: boolean } = {} @@ -226,7 +191,7 @@ class ValueQueries { *entries( this: Editor, options: { - at?: Range | Point | Path + at?: Location from?: Path reverse?: boolean } = {} @@ -254,7 +219,7 @@ class ValueQueries { getActiveMarks( this: Editor, options: { - at?: Range | Point | Path + at?: Location union?: boolean } = {} ): Mark[] { @@ -335,7 +300,7 @@ class ValueQueries { *inlines( this: Editor, options: { - at?: Range | Point | Path + at?: Location from?: Path reverse?: boolean } = {} @@ -354,7 +319,7 @@ class ValueQueries { *marks( this: Editor, options: { - at?: Range | Point | Path + at?: Location from?: Path reverse?: boolean } = {} @@ -500,7 +465,7 @@ class ValueQueries { *texts( this: Editor, options: { - at?: Range | Point | Path + at?: Location from?: Path reverse?: boolean } = {} From 9dfc2b6fabda50ac3cb2b64ee4a6b8e4a97e4cfb Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 14:30:32 -0400 Subject: [PATCH 066/165] add location-based queries --- packages/slate/src/classes/commands/node.ts | 27 +- packages/slate/src/classes/commands/text.ts | 13 +- packages/slate/src/classes/editor.ts | 3 + .../slate/src/classes/queries/location.ts | 258 ++++++++++++++++++ packages/slate/src/classes/queries/path.ts | 142 ---------- packages/slate/src/classes/queries/point.ts | 40 --- packages/slate/src/classes/queries/range.ts | 4 +- packages/slate/src/classes/queries/value.ts | 17 +- 8 files changed, 284 insertions(+), 220 deletions(-) create mode 100644 packages/slate/src/classes/queries/location.ts diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index af8cc9ee01..a3978006bc 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -84,7 +84,7 @@ class NodeCommands { if (atMatch) { const [, matchPath] = atMatch const pathRef = this.createPathRef(matchPath) - const isAtEnd = this.isAtEnd(at, matchPath) + const isAtEnd = this.isEnd(at, matchPath) this.splitNodes({ at, match, always: false }) const path = pathRef.unref()! at = isAtEnd ? Path.next(path) : path @@ -148,8 +148,7 @@ class NodeCommands { ) } - const parentPath = Path.parent(path) - const parent = this.getParent(path) + const [parent, parentPath] = this.getParent(path) const index = path[path.length - 1] const { length } = parent.nodes @@ -360,7 +359,7 @@ class NodeCommands { normalizeNodes(this: Editor, options: { at: Path }): void { const { at } = options - const node = this.getNode(at) + const [node] = this.getNode(at) // There are no core normalizations for text nodes. if (Text.isText(node)) { @@ -507,7 +506,7 @@ class NodeCommands { for (const pathRef of pathRefs) { const path = pathRef.unref()! - const node = this.getNode(path) + const [node] = this.getNode(path) this.apply({ type: 'remove_node', path, node }) } }) @@ -637,12 +636,12 @@ class NodeCommands { !always && edgeRef && edgeRef.current && - this.isAtEdge(edgeRef.current, p) + this.isEdge(edgeRef.current, p) ) { continue } - const node = this.getNode(p) + const [node] = this.getNode(p) const { text, marks, nodes, ...properties } = node this.apply({ @@ -682,16 +681,13 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - const { match = this.isInline(element) ? 'inline' : 'block' } = options - let { at } = options + const { + at = this.value.selection, + match = this.isInline(element) ? 'inline' : 'block', + } = options if (!at) { - if (selection) { - at = selection - } else { - return - } + return } const roots: NodeEntry[] = this.isInline(element) @@ -699,6 +695,7 @@ class NodeCommands { : [[this.value, []]] for (const [, rootPath] of roots) { + debugger const a = Range.isRange(at) ? Range.intersection(at, this.getRange(rootPath))! : at diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index d0fdc0cdb3..0df3867ac1 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -61,17 +61,8 @@ class DeletingCommands { if (Range.isRange(at)) { const [start, end] = Range.points(at) - const [common, commonPath] = this.getCommon(start.path, end.path) - let ancestorPath = commonPath - let ancestor = common - let d: number | 'text' = commonPath.length - - if (Path.equals(start.path, end.path)) { - ancestorPath = Path.parent(commonPath) - ancestor = Node.get(this.value, ancestorPath) - d = 'text' - } - + const [, ancestorPath] = this.getAncestor(at) + const d = Range.isCollapsed(at) ? 'text' : ancestorPath.length const rangeRef = this.createRangeRef(at, { stick: 'inward' }) this.splitNodes({ at: end, match: d }) this.splitNodes({ at: start, match: d }) diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index 2fad1903e6..d00a474ad0 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -15,6 +15,7 @@ import MarkCommands from './commands/mark' import SelectionCommands from './commands/selection' import GeneralCommands from './commands/general' import ElementQueries from './queries/element' +import LocationQueries from './queries/location' import PathQueries from './queries/path' import PointQueries from './queries/point' import RangeQueries from './queries/range' @@ -81,6 +82,7 @@ interface Editor SelectionCommands, GeneralCommands, ElementQueries, + LocationQueries, PathQueries, PointQueries, RangeQueries, @@ -104,6 +106,7 @@ mixin([ SelectionCommands, GeneralCommands, ElementQueries, + LocationQueries, PathQueries, PointQueries, RangeQueries, diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts new file mode 100644 index 0000000000..870fcf6cb3 --- /dev/null +++ b/packages/slate/src/classes/queries/location.ts @@ -0,0 +1,258 @@ +import { + Ancestor, + AncestorEntry, + Editor, + Location, + Node, + Path, + NodeEntry, + Point, + Range, + Text, +} from '../..' + +class LocationQueries { + /** + * Get the common ancestor node of a location. + */ + + getAncestor( + this: Editor, + at: Location = [], + options: { + depth?: number + edge?: 'start' | 'end' + } = {} + ): AncestorEntry { + if (Path.isPath(at) || Point.isPoint(at)) { + return this.getParent(at, options) + } + + const path = this.getPath(at, options) + const ancestorPath = Range.isCollapsed(at) ? Path.parent(path) : path + const ancestor = Node.get(this.value, ancestorPath) as Ancestor + return [ancestor, ancestorPath] + } + + /** + * Get the node at a location. + */ + + getNode( + this: Editor, + at: Location = [], + options: { + depth?: number + edge?: 'start' | 'end' + } = {} + ): NodeEntry { + const path = this.getPath(at, options) + const node = Node.get(this.value, path) + return [node, path] + } + + /** + * Get the parent node of a location. + */ + + getParent( + this: Editor, + at: Location = [], + options: { + depth?: number + edge?: 'start' | 'end' + } = {} + ): AncestorEntry { + const path = this.getPath(at, options) + const parentPath = Path.parent(path) + const parent = Node.get(this.value, path) as Ancestor + return [parent, parentPath] + } + + /** + * Get the path from a location, at a specific depth. + */ + + getPath( + this: Editor, + at: Location = [], + options: { + depth?: number + edge?: 'start' | 'end' + } = {} + ): Path { + const { edge, depth } = options + + if (Range.isRange(at)) { + if (edge != null) { + const point = this.getPoint(at, options) + at = point.path + } else { + const { anchor, focus } = at + const common = Path.common(anchor.path, focus.path) + return common + } + } + + if (Point.isPoint(at)) { + at = at.path + + if (depth != null) { + if (depth > at.length) { + throw new Error( + `Cannot get a path for point ${JSON.stringify( + at + )} at depth \`${depth}\` because it is not that deep.` + ) + } + + at = at.slice(0, depth) + } + } + + return at + } + + /** + * Get the start or end point of a location. + */ + + getPoint( + this: Editor, + at: Location = [], + options: { + edge?: 'start' | 'end' + } = {} + ): Point { + const { edge } = options + + if (Path.isPath(at)) { + if (edge === 'end') { + const [lastNode, lastPath] = Node.last(this.value, at) + + if (!Text.isText(lastNode)) { + throw new Error( + `Cannot get the end point of the node at path [${at}] because it has no ending text node.` + ) + } + + return { path: lastPath, offset: lastNode.text.length } + } else { + const [firstNode, firstPath] = Node.first(this.value, at) + + if (!Text.isText(firstNode)) { + throw new Error( + `Cannot get the start point of the node at path [${at}] because it has no starting text node.` + ) + } + + return { path: firstPath, offset: 0 } + } + } + + if (Range.isRange(at)) { + switch (edge) { + default: + case 'start': + return Range.start(at) + case 'end': + return Range.end(at) + } + } + + return at + } + + /** + * Get a range of a location. + */ + + getRange(this: Editor, at: Location = [], to: Location = at): Range { + if (Point.isPoint(at)) { + const end = this.getEnd(to) + return { anchor: at, focus: end } + } + + if (Path.isPath(at)) { + const start = this.getStart(at) + const end = this.getEnd(to) + return { anchor: start, focus: end } + } + + return at + } + + /** + * Get the start and end points of a location. + */ + + getEdges(this: Editor, at: Location = []): [Point, Point] { + return [this.getStart(at), this.getEnd(at)] + } + + /** + * Get the end point of a location. + */ + + getEnd(this: Editor, at: Location = []): Point { + return this.getPoint(at, { edge: 'end' }) + } + + /** + * Get the start point of a location. + */ + + getStart(this: Editor, at: Location = []): Point { + return this.getPoint(at, { edge: 'start' }) + } + + /** + * Check if there is a node at a location. + */ + + hasNode( + this: Editor, + at: Location = [], + options: { + depth?: number + edge?: 'start' | 'end' + } = {} + ): boolean { + const path = this.getPath(at, options) + const exists = Node.has(this.value, path) + return exists + } + + /** + * Check if a point the start point of a location. + */ + + isStart(this: Editor, point: Point, at: Location): boolean { + // PERF: If the offset isn't `0` we know it's not the start. + if (point.offset !== 0) { + return false + } + + const start = this.getStart(at) + return Point.equals(point, start) + } + + /** + * Check if a point is the end point of a location. + */ + + isEnd(this: Editor, point: Point, at: Location): boolean { + const end = this.getEnd(at) + return Point.equals(point, end) + } + + /** + * Check if a point is an edge of a location. + */ + + isEdge(this: Editor, point: Point, at: Location): boolean { + return this.isStart(point, at) || this.isEnd(point, at) + } +} + +export default LocationQueries diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 4fbbeb9d45..db9a712cd1 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -1,40 +1,16 @@ import { - Ancestor, Editor, Element, ElementEntry, Node, - NodeEntry, - Point, Path, PathRef, - Range, Text, TextEntry, } from '../..' import { PATH_REFS } from '../../symbols' class PathQueries { - getCommon(this: Editor, path: Path, another: Path): NodeEntry { - return Node.common(this.value, path, another) - } - - getParent(this: Editor, path: Path): Ancestor { - return Node.parent(this.value, path) - } - - getLeaf(this: Editor, path: Path): Text { - return Node.leaf(this.value, path) - } - - hasNode(this: Editor, path: Path): boolean { - return Node.has(this.value, path) - } - - getNode(this: Editor, path: Path): Node { - return Node.get(this.value, path) - } - /** * Create a mutable ref for a `Path` object, which will stay in sync as new * operations are applied to the this. @@ -80,59 +56,6 @@ class PathQueries { } } - /** - * Get the closest void node entry at a path. - */ - - getClosestVoid(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.levels(this.value, path)) { - if (Element.isElement(n) && this.isVoid(n)) { - return [n, p] - } - } - } - - /** - * Get the end point of the node at path. - */ - - getEnd(this: Editor, path: Path = []): Point | undefined { - const last = this.getLastText(path) - - if (last) { - const [node, path] = last - const point = { path, offset: node.text.length } - return point - } - } - - /** - * Get the first text node from a node at path. - */ - - getFirstText(this: Editor, path: Path): TextEntry | undefined { - const first = Node.first(this.value, path) - - if (!first) { - return - } - - const [n, p] = first - return Text.isText(n) ? [n, p] : undefined - } - - /** - * Get the furthest block node at a path. - */ - - getFurthestBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { - if (Element.isElement(n) && !this.isInline(n)) { - return [n, p] - } - } - } - /** * Get the furthest inline node entry at a path. */ @@ -157,30 +80,6 @@ class PathQueries { } } - /** - * Get the last text node from a node at path. - */ - - getLastText(this: Editor, path: Path): TextEntry | undefined { - const last = Node.last(this.value, path) - - if (!last) { - return - } - - const [n, p] = last - return Text.isText(n) ? [n, p] : undefined - } - - /** - * Get the next text node entry starting from a path. - */ - - getNextText(this: Editor, path: Path): TextEntry | undefined { - const [, next] = this.texts({ from: path }) - return next - } - /** * Get the relative offset to a node at a path in the document. * @@ -234,47 +133,6 @@ class PathQueries { return prev } - /** - * Get the full range of a node at path. - */ - - getRange(this: Editor, startPath: Path, endPath: Path = startPath): Range { - const first = this.getFirstText(startPath) - const last = this.getLastText(endPath) - - if (!first) { - throw new Error( - `Unable to get a range for the node at path [${startPath}] because it has no text nodes.` - ) - } - - if (!last) { - throw new Error( - `Unable to get a range for the node at path [${endPath}] because it has no text nodes.` - ) - } - - const [, firstPath] = first - const [lastNode, lastPath] = last - const anchor = { path: firstPath, offset: 0 } - const focus = { path: lastPath, offset: lastNode.text.length } - return { anchor, focus } - } - - /** - * Get the start point of the node at path. - */ - - getStart(this: Editor, path: Path = []): Point | undefined { - const first = this.getFirstText(path) - - if (first) { - const [, path] = first - const point = { path, offset: 0 } - return point - } - } - /** * Get the text content of a node at path. * diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index d8dca8e08a..f6ac3c64c0 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -84,46 +84,6 @@ class PointQueries { return target } - - /** - * Check if a point is at the start of a path. - */ - - isAtStart(this: Editor, point: Point, path: Path): boolean { - const first = this.getFirstText(path) - - if (!first) { - return false - } - - const [, firstPath] = first - return point.offset === 0 && Path.equals(point.path, firstPath) - } - - /** - * Check if a point is at the end of a path. - */ - - isAtEnd(this: Editor, point: Point, path: Path): boolean { - const last = this.getLastText(path) - - if (!last) { - return false - } - - const [lastNode, lastPath] = last - return ( - point.offset === lastNode.text.length && Path.equals(point.path, lastPath) - ) - } - - /** - * Check if a point is at either edge of a path. - */ - - isAtEdge(this: Editor, point: Point, path: Path): boolean { - return this.isAtStart(point, path) || this.isAtEnd(point, path) - } } export default PointQueries diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts index 820c6f3e1e..1b0c8dd6c5 100644 --- a/packages/slate/src/classes/queries/range.ts +++ b/packages/slate/src/classes/queries/range.ts @@ -107,7 +107,7 @@ class RangeQueries { const [, startPath] = startClosest const [, endPath] = endClosest - return this.isAtStart(start, startPath) && this.isAtStart(end, endPath) + return this.isStart(start, startPath) && this.isStart(end, endPath) } /** @@ -124,7 +124,7 @@ class RangeQueries { if (closestInline) { const [, endInlinePath] = closestInline - return this.isAtStart(end, endInlinePath) + return this.isStart(end, endInlinePath) } else { return end.offset === 0 } diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index c5bacf6bae..7c7cece8fd 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -118,6 +118,10 @@ class ValueQueries { yield* Node.levels(this.value, path, options) } + /** + * Get the matching node in a single branch of the document at a path. + */ + getMatch(this: Editor, path: Path, match: NodeMatch): NodeEntry | undefined { for (const entry of this.levels(path, { reverse: true })) { if (this.isMatch(entry, match)) { @@ -130,7 +134,7 @@ class ValueQueries { this: Editor, options: { match: NodeMatch - at: Range | Point | Path + at: Location hanging?: boolean reverse?: boolean } @@ -141,8 +145,7 @@ class ValueQueries { // PERF: If the target is a path, we don't need to traverse at all. if (Path.isPath(at)) { - const node = this.getNode(at) - yield [node, at] + yield this.getNode(at) return } @@ -398,13 +401,7 @@ class ValueQueries { // Void nodes are a special case, since we don't want to iterate over // their content. We instead always just yield their first point. if (this.isVoid(node)) { - const first = this.getFirstText(path) - - if (first) { - const [, firstPath] = first - yield { path: firstPath, offset: 0 } - } - + yield this.getStart(path) continue } From 91d695a65738ca6cc23cfa523041461f3f86bf36 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 16:02:22 -0400 Subject: [PATCH 067/165] refactor hanging logic --- packages/slate/src/classes/commands/node.ts | 1 - .../slate/src/classes/queries/location.ts | 48 +++++++- packages/slate/src/classes/queries/range.ts | 113 ------------------ packages/slate/src/classes/queries/value.ts | 43 ++----- packages/slate/src/interfaces/value.ts | 1 - .../setNodes/inline/inline-block-hanging.js | 45 +++++++ .../setNodes/inline/inline-hanging.js | 20 +--- 7 files changed, 102 insertions(+), 169 deletions(-) create mode 100644 packages/slate/test/commands/setNodes/inline/inline-block-hanging.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index a3978006bc..e290d4c63d 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -695,7 +695,6 @@ class NodeCommands { : [[this.value, []]] for (const [, rootPath] of roots) { - debugger const a = Range.isRange(at) ? Range.intersection(at, this.getRange(rootPath))! : at diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 870fcf6cb3..bccb9b630b 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -167,16 +167,54 @@ class LocationQueries { * Get a range of a location. */ - getRange(this: Editor, at: Location = [], to: Location = at): Range { + getRange( + this: Editor, + at: Location = [], + options: { + to?: Location + hanging?: boolean + } = {} + ): Range { + const { to, hanging = false } = options + if (Point.isPoint(at)) { - const end = this.getEnd(to) - return { anchor: at, focus: end } + const end = to ? this.getEnd(to) : at + at = { anchor: at, focus: end } } if (Path.isPath(at)) { const start = this.getStart(at) - const end = this.getEnd(to) - return { anchor: start, focus: end } + const end = this.getEnd(at || to) + at = { anchor: start, focus: end } + } + + // PERF: exit early if we can guarantee that the range isn't hanging, or + // that they don't mind receiving hanging ranges. + if ( + hanging || + at.anchor.offset !== 0 || + at.focus.offset !== 0 || + Range.isCollapsed(at) + ) { + return at + } + + let [start, end] = Range.points(at) + const closestBlock = this.getClosestBlock(end.path) + const blockPath = closestBlock ? closestBlock[1] : [] + let skip = true + + for (const [node, path] of this.texts({ from: end.path, reverse: true })) { + if (skip) { + skip = false + continue + } + + if (node.text !== '' || Path.isBefore(path, blockPath)) { + const point = { path, offset: node.text.length } + at = { anchor: start, focus: point } + break + } } return at diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts index 1b0c8dd6c5..99fc0dc040 100644 --- a/packages/slate/src/classes/queries/range.ts +++ b/packages/slate/src/classes/queries/range.ts @@ -1,4 +1,3 @@ -import { produce } from 'immer' import { Editor, Range, RangeRef } from '../..' import { RANGE_REFS } from '../../symbols' @@ -25,118 +24,6 @@ class RangeQueries { this[RANGE_REFS][ref.id] = ref return ref } - - /** - * Get a range, ensuring that it is not hanging into a block node. - * - * @param {Range} range - * @return {Range} - */ - - getNonBlockHangingRange(this: Editor, range: Range): Range { - if (this.isBlockHanging(range)) { - range = produce(range, r => { - const [, end] = Range.points(r) - const prev = this.getPreviousText(end.path) - - if (prev) { - const [prevText, prevPath] = prev - end.path = prevPath - end.offset = prevText.text.length - } - }) - } - - return range - } - - /** - * Get a range, ensuring that it is not hanging into an inline or text node. - * - * @param {Range} range - * @return {Range} - */ - - getNonInlineHangingRange(this: Editor, range: Range): Range { - if (this.isInlineHanging(range)) { - range = produce(range, r => { - const [, end] = Range.points(r) - const prev = this.getPreviousText(end.path) - - if (prev) { - const [prevText, prevPath] = prev - end.path = prevPath - end.offset = prevText.text.length - } - }) - } - - return range - } - - /** - * Get a range, ensuring that it is not hanging into the next leaf inline or - * block node. - * - * @param {Range} range - * @return {Range} - */ - - getNonHangingRange(this: Editor, range: Range): Range { - range = this.getNonInlineHangingRange(range) - range = this.getNonBlockHangingRange(range) - return range - } - - /** - * Check whether a range is hanging in a block. - */ - - isBlockHanging(this: Editor, range: Range): boolean { - if (!Range.isExpanded(range)) { - return false - } - - const [start, end] = Range.points(range) - const startClosest = this.getClosestBlock(start.path) - const endClosest = this.getClosestBlock(end.path) - - if (!startClosest || !endClosest) { - return false - } - - const [, startPath] = startClosest - const [, endPath] = endClosest - return this.isStart(start, startPath) && this.isStart(end, endPath) - } - - /** - * Check whether a range is hanging in an inline or text node. - */ - - isInlineHanging(this: Editor, range: Range): boolean { - if (!Range.isExpanded(range)) { - return false - } - - const [, end] = Range.points(range) - const closestInline = this.getClosestInline(end.path) - - if (closestInline) { - const [, endInlinePath] = closestInline - return this.isStart(end, endInlinePath) - } else { - return end.offset === 0 - } - } - - /** - * Check whether a range is hanging into the next leaf inline or block node. - */ - - isHanging(this: Editor, range: Range): boolean { - return this.isInlineHanging(range) || this.isBlockHanging(range) - } } export default RangeQueries diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 7c7cece8fd..b9e31220a5 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -139,7 +139,7 @@ class ValueQueries { reverse?: boolean } ): Iterable { - const { reverse, match, hanging = false } = options + const { reverse, match, hanging } = options let { at } = options let prevPath: Path | undefined @@ -149,13 +149,7 @@ class ValueQueries { return } - if (Point.isPoint(at)) { - at = { anchor: at, focus: at } - } - - if (!hanging) { - at = this.getNonHangingRange(at) - } + at = this.getRange(at, { hanging }) for (const [n, p] of this.entries({ at, reverse })) { if (prevPath && Path.compare(p, prevPath) === 0) { @@ -226,41 +220,28 @@ class ValueQueries { union?: boolean } = {} ): Mark[] { - const { value } = this - let { at = this.value.selection, union = false } = options + const { union = false } = options + let { at = this.value.selection } = options if (!at) { return [] } - if (Path.isPath(at)) { - at = this.getRange(at) - } - - if (Range.isRange(at) && Range.isCollapsed(at)) { - at = at.anchor - } - - if (Point.isPoint(at)) { - let { path, offset } = at + at = this.getRange(at) - // If the range is collapsed at the start of a text node, it should carry - // over the marks from the previous text node in the same block. - if (offset === 0 && path[path.length - 1] !== 0) { - const prevPath = Path.previous(path) - const prevNode = Node.get(value, prevPath) + // If the range is collapsed at the start of a text node, it should carry + // over the marks from the previous text node in the same block. + if (Range.isCollapsed(at) && this.isStart(at.anchor, at.anchor.path)) { + const prevPath = Path.previous(at.anchor.path) + const [prevNode] = this.getNode(prevPath) - if (Text.isText(prevNode)) { - path = prevPath - } + if (Text.isText(prevNode)) { + at = this.getRange(prevPath) } - - at = this.getRange(path) } const marks: Mark[] = [] let first = true - at = this.getNonHangingRange(at) for (const [node] of this.texts({ at })) { if (first) { diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 98b064b900..ed16a847e5 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -113,7 +113,6 @@ namespace Value { */ export const transform = (value: Value, op: Operation): Value => { - debugger return produce(value, v => { switch (op.type) { case 'add_annotation': { diff --git a/packages/slate/test/commands/setNodes/inline/inline-block-hanging.js b/packages/slate/test/commands/setNodes/inline/inline-block-hanging.js new file mode 100644 index 0000000000..ee61f3dc8c --- /dev/null +++ b/packages/slate/test/commands/setNodes/inline/inline-block-hanging.js @@ -0,0 +1,45 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.setNodes({ key: true }, { match: 'inline' }) +} + +export const input = ( + + + + + word + + + + + + + another + + + + +) + +export const output = ( + + + + + word + + + + + + + another + + + + +) diff --git a/packages/slate/test/commands/setNodes/inline/inline-hanging.js b/packages/slate/test/commands/setNodes/inline/inline-hanging.js index bd02b3ccd4..394a56c516 100644 --- a/packages/slate/test/commands/setNodes/inline/inline-hanging.js +++ b/packages/slate/test/commands/setNodes/inline/inline-hanging.js @@ -13,14 +13,7 @@ export const input = ( word - - - - - - another - - + ) @@ -32,16 +25,7 @@ export const output = ( word - - - - - - another - - + ) - -export const skip = true From cbc709ca7e1369390e07925e011f2813652481d7 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 18:19:33 -0400 Subject: [PATCH 068/165] more location query work --- packages/slate/src/classes/commands/node.ts | 8 +- .../slate/src/classes/queries/location.ts | 146 ++++++++++++++++-- packages/slate/src/classes/queries/path.ts | 44 +----- packages/slate/src/classes/queries/point.ts | 62 -------- packages/slate/src/classes/queries/value.ts | 8 +- 5 files changed, 142 insertions(+), 126 deletions(-) diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index e290d4c63d..bebbb48af5 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -207,15 +207,14 @@ class NodeCommands { } for (const [node, path] of this.matches({ at, match })) { - const prevText = this.getPreviousText(path) + const prev = this.getPreviousPoint(path) - if (!prevText) { + if (!prev) { continue } - const [, prevTextPath] = prevText const prevMatcher = Path.isPath(at) ? at.length : match - const prevMatch = this.getMatch(prevTextPath, prevMatcher) + const prevMatch = this.getMatch(prev, prevMatcher) if (!prevMatch) { return @@ -522,7 +521,6 @@ class NodeCommands { options: { at?: Location match?: MatchOption - hanging?: boolean } = {} ) { this.withoutNormalizing(() => { diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index bccb9b630b..713e494191 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -34,6 +34,55 @@ class LocationQueries { return [ancestor, ancestorPath] } + /** + * Get the start and end points of a location. + */ + + getEdges(this: Editor, at: Location = []): [Point, Point] { + return [this.getStart(at), this.getEnd(at)] + } + + /** + * Get the end point of a location. + */ + + getEnd(this: Editor, at: Location = []): Point { + return this.getPoint(at, { edge: 'end' }) + } + + /** + * Calculate the next point forward in the document from a starting point. + */ + + getNextPoint( + this: Editor, + at: Location, + options: { + distance?: number + edge?: 'start' | 'end' + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' + } = {} + ): Point | undefined { + at = this.getPoint(at, options) + const { distance = 1 } = options + let d = 0 + let target + + for (const p of this.positions({ ...options, at })) { + if (d > distance) { + break + } + + if (d !== 0) { + target = p + } + + d++ + } + + return target + } + /** * Get the node at a location. */ @@ -51,6 +100,32 @@ class LocationQueries { return [node, path] } + /** + * Get the relative offset to a node at a path in the document. + * + * Note: this ignores void nodes in calculating the offset, as their text + * content is presumed to be an empty string. + */ + + getOffset(this: Editor, at: Location = []): number { + const point = this.getPoint(at, { edge: 'start' }) + + if (this.isStart(point)) { + return 0 + } + + const start = this.getStart() + const end = this.getPreviousPoint(point)! + const range = { anchor: start, focus: end } + let offset = 0 + + for (const [node] of this.texts({ at: range })) { + offset += node.text.length + } + + return offset + } + /** * Get the parent node of a location. */ @@ -163,6 +238,39 @@ class LocationQueries { return at } + /** + * Calculate the previous point backward from a starting point. + */ + + getPreviousPoint( + this: Editor, + at: Location, + options: { + distance?: number + edge?: 'start' | 'end' + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' + } = {} + ): Point | undefined { + at = this.getPoint(at, options) + const { distance = 1 } = options + let d = 0 + let target + + for (const p of this.positions({ ...options, at, reverse: true })) { + if (d > distance) { + break + } + + if (d !== 0) { + target = p + } + + d++ + } + + return target + } + /** * Get a range of a location. */ @@ -221,27 +329,35 @@ class LocationQueries { } /** - * Get the start and end points of a location. + * Get the start point of a location. */ - getEdges(this: Editor, at: Location = []): [Point, Point] { - return [this.getStart(at), this.getEnd(at)] + getStart(this: Editor, at: Location = []): Point { + return this.getPoint(at, { edge: 'start' }) } /** - * Get the end point of a location. + * Get the text content of a location. + * + * Note: the text of void nodes is presumed to be an empty string, regardless + * of what their actual content is. */ - getEnd(this: Editor, at: Location = []): Point { - return this.getPoint(at, { edge: 'end' }) - } + getText( + this: Editor, + at: Location = [], + options: { + hanging?: boolean + } = {} + ): string { + const range = this.getRange(at, options) + let text = '' - /** - * Get the start point of a location. - */ + for (const [node, path] of this.texts({ at: range })) { + text += node.text.length + } - getStart(this: Editor, at: Location = []): Point { - return this.getPoint(at, { edge: 'start' }) + return text } /** @@ -265,7 +381,7 @@ class LocationQueries { * Check if a point the start point of a location. */ - isStart(this: Editor, point: Point, at: Location): boolean { + isStart(this: Editor, point: Point, at: Location = []): boolean { // PERF: If the offset isn't `0` we know it's not the start. if (point.offset !== 0) { return false @@ -279,7 +395,7 @@ class LocationQueries { * Check if a point is the end point of a location. */ - isEnd(this: Editor, point: Point, at: Location): boolean { + isEnd(this: Editor, point: Point, at: Location = []): boolean { const end = this.getEnd(at) return Point.equals(point, end) } @@ -288,7 +404,7 @@ class LocationQueries { * Check if a point is an edge of a location. */ - isEdge(this: Editor, point: Point, at: Location): boolean { + isEdge(this: Editor, point: Point, at: Location = []): boolean { return this.isStart(point, at) || this.isEnd(point, at) } } diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index db9a712cd1..6a40b7fe66 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -1,13 +1,4 @@ -import { - Editor, - Element, - ElementEntry, - Node, - Path, - PathRef, - Text, - TextEntry, -} from '../..' +import { Editor, Element, ElementEntry, Node, Path, PathRef, Text } from '../..' import { PATH_REFS } from '../../symbols' class PathQueries { @@ -44,30 +35,6 @@ class PathQueries { } } - /** - * Get the closest inline node entry at a path. - */ - - getClosestInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.levels(this.value, path)) { - if (Element.isElement(n) && this.isInline(n)) { - return [n, p] - } - } - } - - /** - * Get the furthest inline node entry at a path. - */ - - getFurthestInline(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { - if (Element.isElement(n) && this.isInline(n)) { - return [n, p] - } - } - } - /** * Get the furthest void node entry at a path. */ @@ -124,15 +91,6 @@ class PathQueries { return o } - /** - * Get the previous text node entry starting from a path. - */ - - getPreviousText(this: Editor, path: Path): TextEntry | undefined { - const [, prev] = this.texts({ from: path, reverse: true }) - return prev - } - /** * Get the text content of a node at path. * diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index f6ac3c64c0..e1711cfb5d 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -22,68 +22,6 @@ class PointQueries { this[POINT_REFS][ref.id] = ref return ref } - - /** - * Calculate the next point forward in the document from a starting point. - */ - - getNextPoint( - this: Editor, - point: Point, - options: { - distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' | 'block' - } = {} - ): Point | undefined { - const { distance = 1 } = options - let d = 0 - let target - - for (const p of this.positions({ ...options, at: point })) { - if (d > distance) { - break - } - - if (d !== 0) { - target = p - } - - d++ - } - - return target - } - - /** - * Calculate the previous point backward from a starting point. - */ - - getPreviousPoint( - this: Editor, - point: Point, - options: { - distance?: number - unit?: 'offset' | 'character' | 'word' | 'line' | 'block' - } = {} - ): Point | undefined { - const { distance = 1 } = options - let d = 0 - let target - - for (const p of this.positions({ ...options, at: point, reverse: true })) { - if (d > distance) { - break - } - - if (d !== 0) { - target = p - } - - d++ - } - - return target - } } export default PointQueries diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index b9e31220a5..6797b95979 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -122,7 +122,13 @@ class ValueQueries { * Get the matching node in a single branch of the document at a path. */ - getMatch(this: Editor, path: Path, match: NodeMatch): NodeEntry | undefined { + getMatch( + this: Editor, + at: Location, + match: NodeMatch + ): NodeEntry | undefined { + const path = this.getPath(at) + for (const entry of this.levels(path, { reverse: true })) { if (this.isMatch(entry, match)) { return entry From a174ab8dc09fec1cde6782bff33d7fca52539153 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 18:21:25 -0400 Subject: [PATCH 069/165] renaming --- packages/slate/src/classes/commands/mark.ts | 4 +- packages/slate/src/classes/commands/node.ts | 14 +++--- .../slate/src/classes/commands/selection.ts | 4 +- packages/slate/src/classes/commands/text.ts | 8 ++-- packages/slate/src/classes/path-ref.ts | 12 ++--- packages/slate/src/classes/point-ref.ts | 12 ++--- .../slate/src/classes/queries/location.ts | 2 +- packages/slate/src/classes/queries/path.ts | 6 +-- packages/slate/src/classes/queries/point.ts | 6 +-- packages/slate/src/classes/queries/range.ts | 6 +-- packages/slate/src/classes/range-ref.ts | 12 ++--- packages/slate/src/interfaces/node.ts | 4 +- packages/slate/src/interfaces/path.ts | 8 ++-- packages/slate/src/interfaces/point.ts | 10 ++-- packages/slate/src/interfaces/range.ts | 48 +++++++++---------- .../test/interfaces/Range/points/backward.js | 2 +- .../test/interfaces/Range/points/collapsed.js | 2 +- .../test/interfaces/Range/points/forward.js | 2 +- 18 files changed, 81 insertions(+), 81 deletions(-) diff --git a/packages/slate/src/classes/commands/mark.ts b/packages/slate/src/classes/commands/mark.ts index f2ca779f52..163a8f6518 100644 --- a/packages/slate/src/classes/commands/mark.ts +++ b/packages/slate/src/classes/commands/mark.ts @@ -129,8 +129,8 @@ const splitLocation = ( } if (Range.isRange(at)) { - const rangeRef = editor.createRangeRef(at, { stick: 'inward' }) - const [start, end] = Range.points(at) + const rangeRef = editor.createRangeRef(at, { affinity: 'inward' }) + const [start, end] = Range.edges(at) editor.splitNodes({ at: end, match: 'text', always: false }) editor.splitNodes({ at: start, match: 'text', always: false }) const range = rangeRef.unref()! diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index bebbb48af5..c866f64d3e 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -71,7 +71,7 @@ class NodeCommands { if (Range.isCollapsed(at)) { at = at.anchor } else { - const [, end] = Range.points(at) + const [, end] = Range.edges(at) const pointRef = this.createPointRef(end) this.delete({ at }) at = pointRef.unref()! @@ -195,7 +195,7 @@ class NodeCommands { if (Range.isCollapsed(at)) { at = at.anchor } else { - const [, end] = Range.points(at) + const [, end] = Range.edges(at) const pointRef = this.createPointRef(end) this.delete({ at }) at = pointRef.unref()! @@ -588,7 +588,7 @@ class NodeCommands { if (!at) { if (selection) { - const [, end] = Range.points(selection) + const [, end] = Range.edges(selection) selectRef = this.createPointRef(end) at = selection } else { @@ -600,7 +600,7 @@ class NodeCommands { if (Range.isCollapsed(at)) { at = at.anchor } else { - const [, end] = Range.points(at) + const [, end] = Range.edges(at) const pointRef = this.createPointRef(end) this.delete({ at }) at = pointRef.unref()! @@ -618,7 +618,7 @@ class NodeCommands { } else { firstPath = at.path position = at.offset - edgeRef = this.createPointRef(at, { stick: 'backward' }) + edgeRef = this.createPointRef(at, { affinity: 'backward' }) } let d = firstPath.length - height @@ -781,8 +781,8 @@ class NodeCommands { let rangeRef if (Range.isRange(at)) { - const [start, end] = Range.points(at) - rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const [start, end] = Range.edges(at) + rangeRef = this.createRangeRef(at, { affinity: 'inward' }) this.splitNodes({ at: end, always: false, match }) this.splitNodes({ at: start, always: false, match }) at = rangeRef.current! diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index 122f252711..f4543b4ae9 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -21,10 +21,10 @@ class SelectionCommands { } else if (edge === 'focus') { this.select(selection.focus) } else if (edge === 'start') { - const [start] = Range.points(selection) + const [start] = Range.edges(selection) this.select(start) } else if (edge === 'end') { - const [, end] = Range.points(selection) + const [, end] = Range.edges(selection) this.select(end) } } diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 0df3867ac1..16cbb1af69 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -60,10 +60,10 @@ class DeletingCommands { } if (Range.isRange(at)) { - const [start, end] = Range.points(at) + const [start, end] = Range.edges(at) const [, ancestorPath] = this.getAncestor(at) const d = Range.isCollapsed(at) ? 'text' : ancestorPath.length - const rangeRef = this.createRangeRef(at, { stick: 'inward' }) + const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) this.splitNodes({ at: end, match: d }) this.splitNodes({ at: start, match: d }) at = rangeRef.unref()! @@ -75,7 +75,7 @@ class DeletingCommands { } if (Range.isRange(at)) { - const [start, end] = Range.points(at) + const [start, end] = Range.edges(at) const after = this.getNextPoint(end)! const afterRef = this.createPointRef(after) const l = ancestorPath.length @@ -131,7 +131,7 @@ class DeletingCommands { } if (Range.isRange(at)) { - const [, end] = Range.points(at) + const [, end] = Range.edges(at) const pointRef = this.createPointRef(end) this.delete({ at }) at = pointRef.unref()! diff --git a/packages/slate/src/classes/path-ref.ts b/packages/slate/src/classes/path-ref.ts index 4a47fda712..dd4e7de6f0 100644 --- a/packages/slate/src/classes/path-ref.ts +++ b/packages/slate/src/classes/path-ref.ts @@ -15,18 +15,18 @@ let id = 0 class PathRef { id: number current: Path | null - private stick: 'forward' | 'backward' | null + private affinity: 'forward' | 'backward' | null private onUnref: () => void constructor(props: { path: Path | null - stick: 'forward' | 'backward' | null + affinity: 'forward' | 'backward' | null onUnref: () => void }) { - const { path, stick, onUnref } = props + const { path, affinity, onUnref } = props this.id = id++ this.current = path - this.stick = stick + this.affinity = affinity this.onUnref = onUnref } @@ -35,13 +35,13 @@ class PathRef { */ transform(op: Operation): void { - const { current, stick } = this + const { current, affinity } = this if (current == null) { return } - const path = Path.transform(current, op, { stick }) + const path = Path.transform(current, op, { affinity }) this.current = path if (path == null) { diff --git a/packages/slate/src/classes/point-ref.ts b/packages/slate/src/classes/point-ref.ts index 466c8ea67f..9cde7b4d5a 100644 --- a/packages/slate/src/classes/point-ref.ts +++ b/packages/slate/src/classes/point-ref.ts @@ -15,18 +15,18 @@ let id = 0 class PointRef { id: number current: Point | null - private stick: 'forward' | 'backward' | null + private affinity: 'forward' | 'backward' | null private onUnref: () => void constructor(props: { point: Point | null - stick: 'forward' | 'backward' | null + affinity: 'forward' | 'backward' | null onUnref: () => void }) { - const { point, stick, onUnref } = props + const { point, affinity, onUnref } = props this.id = id++ this.current = point - this.stick = stick + this.affinity = affinity this.onUnref = onUnref } @@ -35,13 +35,13 @@ class PointRef { */ transform(op: Operation): void { - const { current, stick } = this + const { current, affinity } = this if (current == null) { return } - const point = Point.transform(current, op, { stick }) + const point = Point.transform(current, op, { affinity }) this.current = point if (point == null) { diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 713e494191..7305e9aaa3 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -307,7 +307,7 @@ class LocationQueries { return at } - let [start, end] = Range.points(at) + let [start, end] = Range.edges(at) const closestBlock = this.getClosestBlock(end.path) const blockPath = closestBlock ? closestBlock[1] : [] let skip = true diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts index 6a40b7fe66..cbe0eb3825 100644 --- a/packages/slate/src/classes/queries/path.ts +++ b/packages/slate/src/classes/queries/path.ts @@ -10,12 +10,12 @@ class PathQueries { createPathRef( this: Editor, path: Path, - options: { stick?: 'backward' | 'forward' | null } = {} + options: { affinity?: 'backward' | 'forward' | null } = {} ): PathRef { - const { stick = 'forward' } = options + const { affinity = 'forward' } = options const ref: PathRef = new PathRef({ path, - stick, + affinity, onUnref: () => delete this[PATH_REFS][ref.id], }) diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts index e1711cfb5d..194524515a 100644 --- a/packages/slate/src/classes/queries/point.ts +++ b/packages/slate/src/classes/queries/point.ts @@ -10,12 +10,12 @@ class PointQueries { createPointRef( this: Editor, point: Point, - options: { stick?: 'backward' | 'forward' | null } = {} + options: { affinity?: 'backward' | 'forward' | null } = {} ): PointRef { - const { stick = 'forward' } = options + const { affinity = 'forward' } = options const ref: PointRef = new PointRef({ point, - stick, + affinity, onUnref: () => delete this[POINT_REFS][ref.id], }) diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts index 99fc0dc040..568e9305ae 100644 --- a/packages/slate/src/classes/queries/range.ts +++ b/packages/slate/src/classes/queries/range.ts @@ -11,13 +11,13 @@ class RangeQueries { this: Editor, range: Range, options: { - stick?: 'backward' | 'forward' | 'outward' | 'inward' | null + affinity?: 'backward' | 'forward' | 'outward' | 'inward' | null } = {} ): RangeRef { - const { stick = 'forward' } = options + const { affinity = 'forward' } = options const ref: RangeRef = new RangeRef({ range, - stick, + affinity, onUnref: () => delete this[RANGE_REFS][ref.id], }) diff --git a/packages/slate/src/classes/range-ref.ts b/packages/slate/src/classes/range-ref.ts index a9a2983269..a0eb648bcb 100644 --- a/packages/slate/src/classes/range-ref.ts +++ b/packages/slate/src/classes/range-ref.ts @@ -15,18 +15,18 @@ let id = 0 class RangeRef { id: number current: Range | null - private stick: 'forward' | 'backward' | 'outward' | 'inward' | null + private affinity: 'forward' | 'backward' | 'outward' | 'inward' | null private onUnref: () => void constructor(props: { range: Range | null - stick: 'forward' | 'backward' | 'outward' | 'inward' | null + affinity: 'forward' | 'backward' | 'outward' | 'inward' | null onUnref: () => void }) { - const { range, stick, onUnref } = props + const { range, affinity, onUnref } = props this.id = id++ this.current = range - this.stick = stick + this.affinity = affinity this.onUnref = onUnref } @@ -35,13 +35,13 @@ class RangeRef { */ transform(op: Operation): void { - const { current, stick } = this + const { current, affinity } = this if (current == null) { return } - const range = Range.transform(current, op, { stick }) + const range = Range.transform(current, op, { affinity }) this.current = range if (range == null) { diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index f7d2ff6f07..906ea918c0 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -233,7 +233,7 @@ namespace Node { let toPath if (Range.isRange(at)) { - const [s, e] = Range.points(at) + const [s, e] = Range.edges(at) fromPath = reverse ? e.path : s.path toPath = reverse ? s.path : e.path } else if (Point.isPoint(at)) { @@ -347,7 +347,7 @@ namespace Node { } return produce(root, r => { - const [start, end] = Range.points(range) + const [start, end] = Range.edges(range) for (const [, path] of Node.entries(r, { reverse: true })) { if (!Range.includes(range, path)) { diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index 6c85bbd734..a27e1d5eb1 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -298,10 +298,10 @@ namespace Path { export const transform = ( path: Path, operation: Operation, - options: { stick?: 'forward' | 'backward' | null } = {} + options: { affinity?: 'forward' | 'backward' | null } = {} ): Path | null => { return produce(path, p => { - const { stick = 'forward' } = options + const { affinity = 'forward' } = options // PERF: Exit early if the operation is guaranteed not to have an effect. if (path.length === 0) { @@ -367,9 +367,9 @@ namespace Path { const { path: op, position } = operation if (Path.equals(op, p)) { - if (stick === 'forward') { + if (affinity === 'forward') { p[p.length - 1] += 1 - } else if (stick === 'backward') { + } else if (affinity === 'backward') { // Nothing, because it still refers to the right path. } else { return null diff --git a/packages/slate/src/interfaces/point.ts b/packages/slate/src/interfaces/point.ts index 42f2cc4aa5..22820be056 100755 --- a/packages/slate/src/interfaces/point.ts +++ b/packages/slate/src/interfaces/point.ts @@ -86,10 +86,10 @@ namespace Point { export const transform = ( point: Point, op: Operation, - options: { stick?: 'forward' | 'backward' | null } = {} + options: { affinity?: 'forward' | 'backward' | null } = {} ): Point | null => { return produce(point, p => { - const { stick = 'forward' } = options + const { affinity = 'forward' } = options const { path, offset } = p switch (op.type) { @@ -135,16 +135,16 @@ namespace Point { case 'split_node': { if (Path.equals(op.path, path)) { - if (op.position === offset && stick == null) { + if (op.position === offset && affinity == null) { return null } else if ( op.position < offset || - (op.position === offset && stick === 'forward') + (op.position === offset && affinity === 'forward') ) { p.offset -= op.position p.path = Path.transform(path, op, { ...options, - stick: 'forward', + affinity: 'forward', })! } } else { diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index 887ed1614c..d553639878 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -16,12 +16,12 @@ interface Range { namespace Range { export const start = (range: Range): Point => { - const [start] = Range.points(range) + const [start] = Range.edges(range) return start } export const end = (range: Range): Point => { - const [, end] = Range.points(range) + const [, end] = Range.edges(range) return end } @@ -30,8 +30,8 @@ namespace Range { return null } - const [s1, e1] = Range.points(range) - const [s2, e2] = Range.points(another) + const [s1, e1] = Range.edges(range) + const [s2, e2] = Range.edges(another) const start = Point.isBefore(s1, s2) ? s2 : s1 const end = Point.isBefore(e1, e2) ? e1 : e2 return { anchor: start, focus: end } @@ -64,7 +64,7 @@ namespace Range { ) } - const [start, end] = Range.points(range) + const [start, end] = Range.edges(range) let isAfterStart = false let isBeforeEnd = false @@ -136,7 +136,7 @@ namespace Range { * in the document. */ - export const points = (range: Range): [Point, Point] => { + export const edges = (range: Range): [Point, Point] => { const { anchor, focus } = range return Range.isBackward(range) ? [focus, anchor] : [anchor, focus] } @@ -148,36 +148,36 @@ namespace Range { export const transform = ( range: Range, op: Operation, - options: { stick: 'forward' | 'backward' | 'outward' | 'inward' | null } + options: { affinity: 'forward' | 'backward' | 'outward' | 'inward' | null } ): Range | null => { - const { stick = 'inward' } = options - let stickAnchor: 'forward' | 'backward' | null - let stickFocus: 'forward' | 'backward' | null + const { affinity = 'inward' } = options + let affinityAnchor: 'forward' | 'backward' | null + let affinityFocus: 'forward' | 'backward' | null - if (stick === 'inward') { + if (affinity === 'inward') { if (Range.isForward(range)) { - stickAnchor = 'forward' - stickFocus = 'backward' + affinityAnchor = 'forward' + affinityFocus = 'backward' } else { - stickAnchor = 'backward' - stickFocus = 'forward' + affinityAnchor = 'backward' + affinityFocus = 'forward' } - } else if (stick === 'outward') { + } else if (affinity === 'outward') { if (Range.isForward(range)) { - stickAnchor = 'backward' - stickFocus = 'forward' + affinityAnchor = 'backward' + affinityFocus = 'forward' } else { - stickAnchor = 'forward' - stickFocus = 'backward' + affinityAnchor = 'forward' + affinityFocus = 'backward' } } else { - stickAnchor = stick - stickFocus = stick + affinityAnchor = affinity + affinityFocus = affinity } return produce(range, r => { - const anchor = Point.transform(r.anchor, op, { stick: stickAnchor }) - const focus = Point.transform(r.focus, op, { stick: stickFocus }) + const anchor = Point.transform(r.anchor, op, { affinity: affinityAnchor }) + const focus = Point.transform(r.focus, op, { affinity: affinityFocus }) if (!anchor || !focus) { return null diff --git a/packages/slate/test/interfaces/Range/points/backward.js b/packages/slate/test/interfaces/Range/points/backward.js index 815a1db8d2..4f3cb386bf 100644 --- a/packages/slate/test/interfaces/Range/points/backward.js +++ b/packages/slate/test/interfaces/Range/points/backward.js @@ -12,7 +12,7 @@ export const input = { } export const test = range => { - return Range.points(range) + return Range.edges(range) } export const output = [ diff --git a/packages/slate/test/interfaces/Range/points/collapsed.js b/packages/slate/test/interfaces/Range/points/collapsed.js index 1e3f3ca264..66e6f24c89 100644 --- a/packages/slate/test/interfaces/Range/points/collapsed.js +++ b/packages/slate/test/interfaces/Range/points/collapsed.js @@ -12,7 +12,7 @@ export const input = { } export const test = range => { - return Range.points(range) + return Range.edges(range) } export const output = [ diff --git a/packages/slate/test/interfaces/Range/points/forward.js b/packages/slate/test/interfaces/Range/points/forward.js index dce7078186..7cf362edf9 100644 --- a/packages/slate/test/interfaces/Range/points/forward.js +++ b/packages/slate/test/interfaces/Range/points/forward.js @@ -12,7 +12,7 @@ export const input = { } export const test = range => { - return Range.points(range) + return Range.edges(range) } export const output = [ From 847dcb8cd20aa9383c1e7250c3fb19544a804802 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 19:39:28 -0400 Subject: [PATCH 070/165] use getMatch more --- packages/slate/src/classes/commands/node.ts | 35 ++---- packages/slate/src/classes/commands/text.ts | 12 +- packages/slate/src/classes/editor.ts | 12 +- packages/slate/src/classes/queries/general.ts | 70 +++++++++++ .../slate/src/classes/queries/location.ts | 40 +----- packages/slate/src/classes/queries/path.ts | 116 ------------------ packages/slate/src/classes/queries/point.ts | 27 ---- packages/slate/src/classes/queries/range.ts | 29 ----- packages/slate/src/classes/queries/value.ts | 39 ++++-- packages/slate/src/interfaces/node.ts | 32 +---- .../Annotation/isAnnotation/annotation.js | 18 --- .../Annotation/isAnnotation/boolean.js | 9 -- .../isAnnotation/custom-property.js | 19 --- .../Annotation/isAnnotation/object.js | 9 -- .../Annotation/isAnnotation/without-anchor.js | 14 --- .../Annotation/isAnnotation/without-focus.js | 14 --- .../Annotation/isAnnotationMap/annotation.js | 18 --- .../Annotation/isAnnotationMap/boolean.js | 9 -- .../Annotation/isAnnotationMap/empty.js | 9 -- .../Annotation/isAnnotationMap/full.js | 20 --- .../queries/getClosestBlock/block-nested.js | 2 +- .../test/queries/getClosestBlock/block.js | 2 +- .../test/queries/getClosestBlock/inline.js | 2 +- 23 files changed, 123 insertions(+), 434 deletions(-) create mode 100644 packages/slate/src/classes/queries/general.ts delete mode 100644 packages/slate/src/classes/queries/path.ts delete mode 100644 packages/slate/src/classes/queries/point.ts delete mode 100644 packages/slate/src/classes/queries/range.ts delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/object.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationMap/annotation.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationMap/boolean.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationMap/empty.js delete mode 100644 packages/slate/test/interfaces/Annotation/isAnnotationMap/full.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index c866f64d3e..1ab3cdba7c 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -17,6 +17,7 @@ type MatchOption = | 'block' | 'inline' | 'text' + | 'void' | Partial | ((entry: NodeEntry) => boolean) @@ -61,7 +62,7 @@ class NodeCommands { // By default, use the selection as the target location. But if there is // no selection, insert at the end of the document since that is such a - // common use case when inserting from a non-focused state. + // common use case when inserting from a non-selected state. if (!at) { at = selection || this.getEnd() || [this.value.nodes.length] select = true @@ -96,7 +97,7 @@ class NodeCommands { const parentPath = Path.parent(at) let index = at[at.length - 1] - if (this.getFurthestVoid(parentPath)) { + if (this.getMatch(parentPath, 'void')) { return } @@ -129,8 +130,7 @@ class NodeCommands { } ) { this.withoutNormalizing(() => { - const { selection } = this.value - const { at = selection, match = 'block' } = options + const { at = this.value.selection, match = 'block' } = options if (!at) { return @@ -311,16 +311,9 @@ class NodeCommands { this.withoutNormalizing(() => { const { selection } = this.value const { to, match = 'block' } = options - const newIndex = to[to.length - 1] let { at } = options let selectRef - if (newIndex > 0 && !this.hasNode(Path.previous(to))) { - throw new Error( - `Cannot move nodes to new path [${to}] because the index is out of range.` - ) - } - if (!at) { if (selection) { at = selection @@ -450,16 +443,10 @@ class NodeCommands { } ) { this.withoutNormalizing(() => { - const { selection } = this.value - const { match = 'block' } = options - let { at } = options + const { at = this.value.selection, match = 'block' } = options if (!at) { - if (selection) { - at = selection - } else { - return - } + return } const matches = this.matches({ at, match }) @@ -488,16 +475,10 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - const { match = 'block' } = options - let { at } = options + const { at = this.value.selection, match = 'block' } = options if (!at) { - if (selection) { - at = selection - } else { - return - } + return } const depths = this.matches({ at, match }) diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 16cbb1af69..e61926c281 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -42,7 +42,7 @@ class DeletingCommands { } if (Point.isPoint(at)) { - const furthestVoid = this.getFurthestVoid(at.path) + const furthestVoid = this.getMatch(at.path, 'void') if (furthestVoid) { const [, voidPath] = furthestVoid @@ -137,7 +137,7 @@ class DeletingCommands { at = pointRef.unref()! } - if (!Point.isPoint(at) || this.getFurthestVoid(at.path)) { + if (!Point.isPoint(at) || this.getMatch(at.path, 'void')) { return } @@ -145,11 +145,11 @@ class DeletingCommands { this.splitNodes({ at }) if (pointRef.current) { - const [, insertPath] = this.getClosestBlock(pointRef.current.path)! + const [, insertPath] = this.getMatch(pointRef.current.path, 'block')! this.insertNodes(fragment.nodes, { at: insertPath }) - const afterClosest = this.getClosestBlock(pointRef.current.path) - const beforeClosest = this.getClosestBlock(at.path) + const afterClosest = this.getMatch(pointRef.current.path, 'block') + const beforeClosest = this.getMatch(at.path, 'block') if (afterClosest && beforeClosest) { const [, afterPath] = afterClosest @@ -197,7 +197,7 @@ class DeletingCommands { } } - if (Point.isPoint(at) && !this.getFurthestVoid(at.path)) { + if (Point.isPoint(at) && !this.getMatch(at.path, 'void')) { const { path, offset } = at this.apply({ type: 'insert_text', path, offset, text }) } diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index d00a474ad0..aeb94ece27 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -15,10 +15,8 @@ import MarkCommands from './commands/mark' import SelectionCommands from './commands/selection' import GeneralCommands from './commands/general' import ElementQueries from './queries/element' +import GeneralQueries from './queries/general' import LocationQueries from './queries/location' -import PathQueries from './queries/path' -import PointQueries from './queries/point' -import RangeQueries from './queries/range' import ValueQueries from './queries/value' /** @@ -82,10 +80,8 @@ interface Editor SelectionCommands, GeneralCommands, ElementQueries, + GeneralQueries, LocationQueries, - PathQueries, - PointQueries, - RangeQueries, ValueQueries {} const mixin = (Mixins: Array any>) => { @@ -106,10 +102,8 @@ mixin([ SelectionCommands, GeneralCommands, ElementQueries, + GeneralQueries, LocationQueries, - PathQueries, - PointQueries, - RangeQueries, ValueQueries, ]) diff --git a/packages/slate/src/classes/queries/general.ts b/packages/slate/src/classes/queries/general.ts new file mode 100644 index 0000000000..86f5c6c648 --- /dev/null +++ b/packages/slate/src/classes/queries/general.ts @@ -0,0 +1,70 @@ +import { Editor, Path, Point, PathRef, PointRef, Range, RangeRef } from '../..' +import { PATH_REFS, POINT_REFS, RANGE_REFS } from '../../symbols' + +class GeneralQueries { + /** + * Create a mutable ref for a `Path` object, which will stay in sync as new + * operations are applied to the this. + */ + + createPathRef( + this: Editor, + path: Path, + options: { affinity?: 'backward' | 'forward' | null } = {} + ): PathRef { + const { affinity = 'forward' } = options + const ref: PathRef = new PathRef({ + path, + affinity, + onUnref: () => delete this[PATH_REFS][ref.id], + }) + + this[PATH_REFS][ref.id] = ref + return ref + } + + /** + * Create a mutable ref for a `Point` object, which will stay in sync as new + * operations are applied to the this. + */ + + createPointRef( + this: Editor, + point: Point, + options: { affinity?: 'backward' | 'forward' | null } = {} + ): PointRef { + const { affinity = 'forward' } = options + const ref: PointRef = new PointRef({ + point, + affinity, + onUnref: () => delete this[POINT_REFS][ref.id], + }) + + this[POINT_REFS][ref.id] = ref + return ref + } + /** + * Create a mutable ref for a `Range` object, which will stay in sync as new + * operations are applied to the this. + */ + + createRangeRef( + this: Editor, + range: Range, + options: { + affinity?: 'backward' | 'forward' | 'outward' | 'inward' | null + } = {} + ): RangeRef { + const { affinity = 'forward' } = options + const ref: RangeRef = new RangeRef({ + range, + affinity, + onUnref: () => delete this[RANGE_REFS][ref.id], + }) + + this[RANGE_REFS][ref.id] = ref + return ref + } +} + +export default GeneralQueries diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 7305e9aaa3..e40505cdec 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -100,32 +100,6 @@ class LocationQueries { return [node, path] } - /** - * Get the relative offset to a node at a path in the document. - * - * Note: this ignores void nodes in calculating the offset, as their text - * content is presumed to be an empty string. - */ - - getOffset(this: Editor, at: Location = []): number { - const point = this.getPoint(at, { edge: 'start' }) - - if (this.isStart(point)) { - return 0 - } - - const start = this.getStart() - const end = this.getPreviousPoint(point)! - const range = { anchor: start, focus: end } - let offset = 0 - - for (const [node] of this.texts({ at: range })) { - offset += node.text.length - } - - return offset - } - /** * Get the parent node of a location. */ @@ -308,7 +282,7 @@ class LocationQueries { } let [start, end] = Range.edges(at) - const closestBlock = this.getClosestBlock(end.path) + const closestBlock = this.getMatch(end.path, 'block') const blockPath = closestBlock ? closestBlock[1] : [] let skip = true @@ -343,17 +317,11 @@ class LocationQueries { * of what their actual content is. */ - getText( - this: Editor, - at: Location = [], - options: { - hanging?: boolean - } = {} - ): string { - const range = this.getRange(at, options) + getText(this: Editor, at: Location = []): string { + const range = this.getRange(at) let text = '' - for (const [node, path] of this.texts({ at: range })) { + for (const [node] of this.texts({ at: range })) { text += node.text.length } diff --git a/packages/slate/src/classes/queries/path.ts b/packages/slate/src/classes/queries/path.ts deleted file mode 100644 index cbe0eb3825..0000000000 --- a/packages/slate/src/classes/queries/path.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { Editor, Element, ElementEntry, Node, Path, PathRef, Text } from '../..' -import { PATH_REFS } from '../../symbols' - -class PathQueries { - /** - * Create a mutable ref for a `Path` object, which will stay in sync as new - * operations are applied to the this. - */ - - createPathRef( - this: Editor, - path: Path, - options: { affinity?: 'backward' | 'forward' | null } = {} - ): PathRef { - const { affinity = 'forward' } = options - const ref: PathRef = new PathRef({ - path, - affinity, - onUnref: () => delete this[PATH_REFS][ref.id], - }) - - this[PATH_REFS][ref.id] = ref - return ref - } - - /** - * Get the closest block node at a path. - */ - - getClosestBlock(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.levels(this.value, path)) { - if (Element.isElement(n) && !this.isInline(n)) { - return [n, p] - } - } - } - - /** - * Get the furthest void node entry at a path. - */ - - getFurthestVoid(this: Editor, path: Path): ElementEntry | undefined { - for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { - if (Element.isElement(n) && this.isVoid(n)) { - return [n, p] - } - } - } - - /** - * Get the relative offset to a node at a path in the document. - * - * Note: this ignores void nodes in calculating the offset, as their text - * content is presumed to be an empty string. - */ - - getOffset( - this: Editor, - path: Path, - options: { - depth?: number - } = {} - ): number { - const { value } = this - const { depth = 0 } = options - - if (path.length === depth) { - return 0 - } - - const rootPath = path.slice(0, depth) - const root = Node.get(value, rootPath) - const relPath = Path.relative(path, rootPath) - - if (Text.isText(root)) { - throw new Error( - `Cannot get the offset into a root text node: ${JSON.stringify(root)}` - ) - } - - const [index] = relPath - let o = 0 - - for (let i = 0; i < index; i++) { - const text = this.getText(rootPath.concat(i)) - o += text.length - } - - const relOffset = this.getOffset(path, { depth: depth + 1 }) - o += relOffset - return o - } - - /** - * Get the text content of a node at path. - * - * Note: the text of void nodes is presumed to be an empty string, regardless - * of what their actual content is. - */ - - getText(this: Editor, path: Path): string { - const { value } = this - const node = Node.get(value, path) - const furthestVoid = this.getFurthestVoid(path) - - if (furthestVoid) { - return '' - } else if (Text.isText(node)) { - return node.text - } else { - return node.nodes.map((n, i) => this.getText(path.concat(i))).join('') - } - } -} - -export default PathQueries diff --git a/packages/slate/src/classes/queries/point.ts b/packages/slate/src/classes/queries/point.ts deleted file mode 100644 index 194524515a..0000000000 --- a/packages/slate/src/classes/queries/point.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Editor, Path, Point, PointRef } from '../..' -import { POINT_REFS } from '../../symbols' - -class PointQueries { - /** - * Create a mutable ref for a `Point` object, which will stay in sync as new - * operations are applied to the this. - */ - - createPointRef( - this: Editor, - point: Point, - options: { affinity?: 'backward' | 'forward' | null } = {} - ): PointRef { - const { affinity = 'forward' } = options - const ref: PointRef = new PointRef({ - point, - affinity, - onUnref: () => delete this[POINT_REFS][ref.id], - }) - - this[POINT_REFS][ref.id] = ref - return ref - } -} - -export default PointQueries diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts deleted file mode 100644 index 568e9305ae..0000000000 --- a/packages/slate/src/classes/queries/range.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Editor, Range, RangeRef } from '../..' -import { RANGE_REFS } from '../../symbols' - -class RangeQueries { - /** - * Create a mutable ref for a `Range` object, which will stay in sync as new - * operations are applied to the this. - */ - - createRangeRef( - this: Editor, - range: Range, - options: { - affinity?: 'backward' | 'forward' | 'outward' | 'inward' | null - } = {} - ): RangeRef { - const { affinity = 'forward' } = options - const ref: RangeRef = new RangeRef({ - range, - affinity, - onUnref: () => delete this[RANGE_REFS][ref.id], - }) - - this[RANGE_REFS][ref.id] = ref - return ref - } -} - -export default RangeQueries diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 6797b95979..f1043cae03 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -24,6 +24,7 @@ type NodeMatch = | 'block' | 'inline' | 'text' + | 'void' | Partial | ((entry: NodeEntry) => boolean) @@ -96,6 +97,8 @@ class ValueQueries { return ( Element.isElement(node) && !this.isInline(node) && this.hasInlines(node) ) + } else if (match === 'void') { + return Element.isElement(node) && this.isVoid(node) } else { return Node.matches(node, match) } @@ -108,14 +111,22 @@ class ValueQueries { reverse?: boolean } ): Iterable { - const furthestVoid = this.getFurthestVoid(path) + const { reverse = false } = options + const levels: NodeEntry[] = [] - if (furthestVoid) { - const [, voidPath] = furthestVoid - path = voidPath + for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { + levels.push([n, p]) + + if (Element.isElement(n) && this.isVoid(n)) { + break + } + } + + if (reverse === false) { + levels.reverse() } - yield* Node.levels(this.value, path, options) + yield* levels } /** @@ -346,7 +357,7 @@ class ValueQueries { at = reverse ? this.getEnd() : this.getStart(), } = options - if (at == null) { + if (!at) { return } @@ -380,10 +391,7 @@ class ValueQueries { distance = available >= 0 ? null : 0 - available } - for (const [node, path] of this.entries({ - at: at.path, - reverse, - })) { + for (const [node, path] of this.entries({ at, reverse })) { if (Element.isElement(node)) { // Void nodes are a special case, since we don't want to iterate over // their content. We instead always just yield their first point. @@ -396,7 +404,16 @@ class ValueQueries { let text = this.getText(path) if (Path.isAncestor(path, at.path)) { - const before = this.getOffset(at.path, { depth: path.length }) + let before = 0 + + for (const [n, p] of this.texts({ from: path })) { + if (Path.equals(p, at.path)) { + break + } + + before += n.text.length + } + const o = before + at.offset text = reverse ? text.slice(0, o) : text.slice(o) } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 906ea918c0..72f5438d6d 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -229,7 +229,7 @@ namespace Node { } = {} ): Iterable { const { at, from, pass, reverse = false } = options - let [, fromPath] = Node.first(root, []) + let [, fromPath] = reverse ? Node.last(root, []) : Node.first(root, []) let toPath if (Range.isRange(at)) { @@ -526,36 +526,6 @@ namespace Node { } } - /** - * Calculate the string offset of all the nodes before a node at a given path. - */ - - export const offset = (root: Node, path: Path): number => { - // PERF: We can exit early if the path is empty. - if (path.length === 0) { - return 0 - } - - if (Text.isText(root)) { - throw new Error( - `Cannot get the offset into a root text node: ${JSON.stringify(root)}` - ) - } - - const [index] = path - const befores = root.nodes.slice(0, index) - let o = 0 - - for (const node of befores) { - o += Node.text(node).length - } - - const child = Node.child(root, index) - const relPath = Path.relative(path, [index]) - o += Node.offset(child, relPath) - return o - } - /** * Get the parent of a node at a specific path. */ diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js b/packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js deleted file mode 100644 index 13c137e371..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotation/annotation.js +++ /dev/null @@ -1,18 +0,0 @@ -import { Annotation } from 'slate' - -export const input = { - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Annotation.isAnnotation(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js b/packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js deleted file mode 100644 index 737bf20d83..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotation/boolean.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Annotation } from 'slate' - -export const input = true - -export const test = value => { - return Annotation.isAnnotation(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js b/packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js deleted file mode 100644 index afceeadc6b..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotation/custom-property.js +++ /dev/null @@ -1,19 +0,0 @@ -import { Annotation } from 'slate' - -export const input = { - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, - custom: 'value', -} - -export const test = value => { - return Annotation.isAnnotation(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/object.js b/packages/slate/test/interfaces/Annotation/isAnnotation/object.js deleted file mode 100644 index 387aeb5bdd..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotation/object.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Annotation } from 'slate' - -export const input = {} - -export const test = value => { - return Annotation.isAnnotation(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js b/packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js deleted file mode 100644 index 05ad30e351..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotation/without-anchor.js +++ /dev/null @@ -1,14 +0,0 @@ -import { Annotation } from 'slate' - -export const input = { - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Annotation.isAnnotation(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js b/packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js deleted file mode 100644 index 39285cf5aa..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotation/without-focus.js +++ /dev/null @@ -1,14 +0,0 @@ -import { Annotation } from 'slate' - -export const input = { - anchor: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Annotation.isAnnotation(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationMap/annotation.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/annotation.js deleted file mode 100644 index 5de86e02b8..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotationMap/annotation.js +++ /dev/null @@ -1,18 +0,0 @@ -import { Annotation } from 'slate' - -export const input = { - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, -} - -export const test = value => { - return Annotation.isAnnotationMap(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationMap/boolean.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/boolean.js deleted file mode 100644 index 0292dd0306..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotationMap/boolean.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Annotation } from 'slate' - -export const input = true - -export const test = value => { - return Annotation.isAnnotationMap(value) -} - -export const output = false diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationMap/empty.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/empty.js deleted file mode 100644 index 7394641d10..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotationMap/empty.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Annotation } from 'slate' - -export const input = {} - -export const test = value => { - return Annotation.isAnnotationMap(value) -} - -export const output = true diff --git a/packages/slate/test/interfaces/Annotation/isAnnotationMap/full.js b/packages/slate/test/interfaces/Annotation/isAnnotationMap/full.js deleted file mode 100644 index 3b69d732ac..0000000000 --- a/packages/slate/test/interfaces/Annotation/isAnnotationMap/full.js +++ /dev/null @@ -1,20 +0,0 @@ -import { Annotation } from 'slate' - -export const input = { - a: { - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, - }, -} - -export const test = value => { - return Annotation.isAnnotationMap(value) -} - -export const output = true diff --git a/packages/slate/test/queries/getClosestBlock/block-nested.js b/packages/slate/test/queries/getClosestBlock/block-nested.js index f8cba59122..fb7ce428e8 100644 --- a/packages/slate/test/queries/getClosestBlock/block-nested.js +++ b/packages/slate/test/queries/getClosestBlock/block-nested.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return editor.getClosestBlock([0, 0, 0]) + return editor.getMatch([0, 0, 0], 'block') } export const output = [one, [0, 0]] diff --git a/packages/slate/test/queries/getClosestBlock/block.js b/packages/slate/test/queries/getClosestBlock/block.js index 50e9649439..e2c45d4cd9 100644 --- a/packages/slate/test/queries/getClosestBlock/block.js +++ b/packages/slate/test/queries/getClosestBlock/block.js @@ -9,7 +9,7 @@ export const input = ( ) export const run = editor => { - return editor.getClosestBlock([0, 0]) + return editor.getMatch([0, 0], 'block') } export const output = [one, [0]] diff --git a/packages/slate/test/queries/getClosestBlock/inline.js b/packages/slate/test/queries/getClosestBlock/inline.js index 264ee599ae..7483d81cca 100644 --- a/packages/slate/test/queries/getClosestBlock/inline.js +++ b/packages/slate/test/queries/getClosestBlock/inline.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return editor.getClosestBlock([0, 1, 0]) + return editor.getMatch([0, 1, 0], 'block') } export const output = [ From bf305a2a751bb14729e318a84f0c204b1c5a58e9 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Sun, 27 Oct 2019 21:17:14 -0400 Subject: [PATCH 071/165] add split to wrap/unwrap --- packages/slate/src/classes/commands/node.ts | 187 ++++++------------ .../slate/src/classes/queries/location.ts | 21 +- packages/slate/src/classes/queries/value.ts | 33 +--- packages/slate/src/classes/utils.ts | 16 ++ .../commands/coverNodes/block/block-end.js | 33 ---- .../test/commands/coverNodes/inline/inline.js | 35 ---- .../insertNodes/selection/none-empty.js | 2 + .../uncoverNodes/match-block/block-nested.js | 29 --- .../match-block/block-across.js | 2 +- .../unwrapNodes/match-block/block-end.js | 14 +- .../match-block/block-inline.js | 2 +- .../unwrapNodes/match-block/block-middle.js | 16 +- .../unwrapNodes/match-block/block-nested.js | 26 +-- .../unwrapNodes/match-block/block-start.js | 14 +- .../commands/unwrapNodes/match-block/block.js | 4 +- .../match-inline/block-nested.js | 2 +- .../match-inline/inline-across.js | 2 +- .../match-inline/inline-over.js | 2 +- .../match-inline/inline.js | 2 +- .../path/block-multiple.js | 2 +- .../path/block.js | 2 +- .../{match-block => split-block}/block-all.js | 2 +- .../split-block}/block-end.js | 16 +- .../split-block}/block-middle.js | 18 +- .../unwrapNodes/split-block/block-nested.js | 47 +++++ .../split-block}/block-start.js | 16 +- .../split-block}/block.js | 14 +- .../block/block-across-nested.js | 2 +- .../commands/wrapNodes/block/block-across.js | 20 +- .../commands/wrapNodes/block/block-end.js | 17 +- .../commands/wrapNodes/block/block-nested.js | 18 +- .../test/commands/wrapNodes/block/block.js | 10 +- .../block/inline-across.js | 2 +- .../block/omit-nodes.js | 2 +- .../inline/inline-across.js | 2 +- .../test/commands/wrapNodes/inline/inline.js | 28 +-- .../{coverNodes => wrapNodes}/inline/text.js | 2 +- .../split-block}/block-across.js | 20 +- .../wrapNodes/split-block/block-end.js | 26 +++ .../{block => split-block}/block-middle.js | 2 +- .../split-block}/block-nested.js | 18 +- .../{block => split-block}/block-start.js | 2 +- .../split-block}/block.js | 20 +- .../commands/wrapNodes/split-inline/inline.js | 29 +++ 44 files changed, 362 insertions(+), 417 deletions(-) create mode 100644 packages/slate/src/classes/utils.ts delete mode 100644 packages/slate/test/commands/coverNodes/block/block-end.js delete mode 100644 packages/slate/test/commands/coverNodes/inline/inline.js delete mode 100644 packages/slate/test/commands/uncoverNodes/match-block/block-nested.js rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/match-block/block-across.js (89%) rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/match-block/block-inline.js (93%) rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/match-inline/block-nested.js (89%) rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/match-inline/inline-across.js (90%) rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/match-inline/inline-over.js (90%) rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/match-inline/inline.js (88%) rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/path/block-multiple.js (89%) rename packages/slate/test/commands/{uncoverNodes => unwrapNodes}/path/block.js (87%) rename packages/slate/test/commands/unwrapNodes/{match-block => split-block}/block-all.js (91%) rename packages/slate/test/commands/{uncoverNodes/match-block => unwrapNodes/split-block}/block-end.js (66%) rename packages/slate/test/commands/{uncoverNodes/match-block => unwrapNodes/split-block}/block-middle.js (63%) create mode 100644 packages/slate/test/commands/unwrapNodes/split-block/block-nested.js rename packages/slate/test/commands/{uncoverNodes/match-block => unwrapNodes/split-block}/block-start.js (66%) rename packages/slate/test/commands/{coverNodes/block => unwrapNodes/split-block}/block.js (67%) rename packages/slate/test/commands/{coverNodes => wrapNodes}/block/block-across-nested.js (93%) rename packages/slate/test/commands/{coverNodes => wrapNodes}/block/inline-across.js (95%) rename packages/slate/test/commands/{coverNodes => wrapNodes}/block/omit-nodes.js (95%) rename packages/slate/test/commands/{coverNodes => wrapNodes}/inline/inline-across.js (95%) rename packages/slate/test/commands/{coverNodes => wrapNodes}/inline/text.js (90%) rename packages/slate/test/commands/{coverNodes/block => wrapNodes/split-block}/block-across.js (61%) create mode 100644 packages/slate/test/commands/wrapNodes/split-block/block-end.js rename packages/slate/test/commands/wrapNodes/{block => split-block}/block-middle.js (87%) rename packages/slate/test/commands/{coverNodes/block => wrapNodes/split-block}/block-nested.js (61%) rename packages/slate/test/commands/wrapNodes/{block => split-block}/block-start.js (87%) rename packages/slate/test/commands/{uncoverNodes/match-block => wrapNodes/split-block}/block.js (81%) create mode 100644 packages/slate/test/commands/wrapNodes/split-inline/inline.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index 1ab3cdba7c..bc2b62610e 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -10,16 +10,7 @@ import { Range, Point, } from '../..' - -type MatchOption = - | number - | 'value' - | 'block' - | 'inline' - | 'text' - | 'void' - | Partial - | ((entry: NodeEntry) => boolean) +import { Match } from '../utils' class NodeCommands { /** @@ -31,7 +22,7 @@ class NodeCommands { nodes: Node | Node[], options: { at?: Location - match?: MatchOption + match?: Match } = {} ) { this.withoutNormalizing(() => { @@ -126,7 +117,7 @@ class NodeCommands { this: Editor, options: { at?: Location - match?: MatchOption + match?: Match } ) { this.withoutNormalizing(() => { @@ -148,12 +139,13 @@ class NodeCommands { ) } - const [parent, parentPath] = this.getParent(path) + const [parent, parentPath] = this.getNode(Path.parent(path)) const index = path[path.length - 1] const { length } = parent.nodes if (length === 1) { - this.uncoverNodes({ at: parentPath }) + this.moveNodes({ at: path, to: Path.next(parentPath) }) + this.removeNodes({ at: parentPath }) } else if (index === 0) { this.moveNodes({ at: path, to: parentPath }) } else if (index === length - 1) { @@ -175,7 +167,7 @@ class NodeCommands { this: Editor, options: { at?: Location - match?: MatchOption + match?: Match } = {} ) { this.withoutNormalizing(() => { @@ -304,7 +296,7 @@ class NodeCommands { this: Editor, options: { at?: Location - match?: MatchOption + match?: Match to: Path } ) { @@ -431,38 +423,6 @@ class NodeCommands { } } - /** - * Remove a node at a specific location, replacing it with its children. - */ - - uncoverNodes( - this: Editor, - options: { - at?: Location - match?: MatchOption - } - ) { - this.withoutNormalizing(() => { - const { at = this.value.selection, match = 'block' } = options - - if (!at) { - return - } - - const matches = this.matches({ at, match }) - const pathRefs = Array.from(matches, ([, p]) => this.createPathRef(p)) - - for (const pathRef of pathRefs) { - const path = pathRef.unref()! - const range = this.getRange(path) - const depth = path.length + 1 - const to = Path.next(path) - this.moveNodes({ at: range, match: depth, to }) - this.removeNodes({ at: path }) - } - }) - } - /** * Remove the nodes at a specific location in the document. */ @@ -471,7 +431,7 @@ class NodeCommands { this: Editor, options: { at?: Location - match?: MatchOption + match?: Match } = {} ) { this.withoutNormalizing(() => { @@ -501,7 +461,7 @@ class NodeCommands { props: Partial, options: { at?: Location - match?: MatchOption + match?: Match } = {} ) { this.withoutNormalizing(() => { @@ -552,7 +512,7 @@ class NodeCommands { this: Editor, options: { at?: Location - match?: MatchOption + match?: Match always?: boolean height?: number } = {} @@ -647,63 +607,6 @@ class NodeCommands { }) } - /** - * Surround the nodes at a location with a new parent node. - */ - - coverNodes( - this: Editor, - element: Element, - options: { - at?: Location - match?: MatchOption - } = {} - ) { - this.withoutNormalizing(() => { - const { - at = this.value.selection, - match = this.isInline(element) ? 'inline' : 'block', - } = options - - if (!at) { - return - } - - const roots: NodeEntry[] = this.isInline(element) - ? Array.from(this.matches({ ...options, at, match: 'block' })) - : [[this.value, []]] - - for (const [, rootPath] of roots) { - const a = Range.isRange(at) - ? Range.intersection(at, this.getRange(rootPath))! - : at - - const matches = Array.from(this.matches({ ...options, at: a, match })) - - if (matches.length > 0) { - const [first] = matches - const last = matches[matches.length - 1] - const [, firstPath] = first - const [, lastPath] = last - const commonPath = Path.equals(firstPath, lastPath) - ? Path.parent(firstPath) - : Path.common(firstPath, lastPath) - - const range = this.getRange(firstPath, lastPath) - const depth = commonPath.length + 1 - const wrapperPath = Path.next(lastPath).slice(0, depth) - const wrapper = { ...element, nodes: [] } - this.insertNodes(wrapper, { at: wrapperPath }) - this.moveNodes({ - at: range, - match: depth, - to: wrapperPath.concat(0), - }) - } - } - }) - } - /** * Unwrap the nodes at a location from a parent node, splitting the parent if * necessary to ensure that only the content in the range is unwrapped. @@ -713,11 +616,16 @@ class NodeCommands { this: Editor, options: { at?: Location - match?: MatchOption + match?: Match + split?: boolean } ) { this.withoutNormalizing(() => { - const { at = this.value.selection, match = 'block' } = options + const { + at = this.value.selection, + match = 'block', + split = false, + } = options if (!at) { return @@ -729,11 +637,13 @@ class NodeCommands { for (const pathRef of pathRefs) { const path = pathRef.unref()! const depth = path.length + 1 - const a = Range.isRange(at) - ? Range.intersection(at, this.getRange(path))! - : at + let range = this.getRange(path) + + if (split && Range.isRange(at)) { + range = Range.intersection(at, range)! + } - this.liftNodes({ at: a, match: depth }) + this.liftNodes({ at: range, match: depth }) } }) } @@ -748,35 +658,64 @@ class NodeCommands { element: Element, options: { at?: Location - match?: MatchOption + match?: Match + split?: boolean } = {} ) { this.withoutNormalizing(() => { - const { match = this.isInline(element) ? 'inline' : 'block' } = options + const { + match = this.isInline(element) ? 'inline' : 'block', + split = false, + } = options let { at = this.value.selection } = options if (!at) { return } - let rangeRef - - if (Range.isRange(at)) { + if (split && Range.isRange(at)) { const [start, end] = Range.edges(at) - rangeRef = this.createRangeRef(at, { affinity: 'inward' }) + const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) this.splitNodes({ at: end, always: false, match }) this.splitNodes({ at: start, always: false, match }) - at = rangeRef.current! + at = rangeRef.unref()! if (options.at == null) { this.select(at) } } - this.coverNodes(element, { at, match }) + const roots: NodeEntry[] = this.isInline(element) + ? Array.from(this.matches({ ...options, at, match: 'block' })) + : [[this.value, []]] + + for (const [, rootPath] of roots) { + const a = Range.isRange(at) + ? Range.intersection(at, this.getRange(rootPath))! + : at + + const matches = Array.from(this.matches({ ...options, at: a, match })) + + if (matches.length > 0) { + const [first] = matches + const last = matches[matches.length - 1] + const [, firstPath] = first + const [, lastPath] = last + const commonPath = Path.equals(firstPath, lastPath) + ? Path.parent(firstPath) + : Path.common(firstPath, lastPath) - if (rangeRef) { - rangeRef.unref() + const range = this.getRange(firstPath, { to: lastPath }) + const depth = commonPath.length + 1 + const wrapperPath = Path.next(lastPath).slice(0, depth) + const wrapper = { ...element, nodes: [] } + this.insertNodes(wrapper, { at: wrapperPath }) + this.moveNodes({ + at: range, + match: depth, + to: wrapperPath.concat(0), + }) + } } }) } diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index e40505cdec..9318bba1cc 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -10,6 +10,7 @@ import { Range, Text, } from '../..' +import { Match } from '../utils' class LocationQueries { /** @@ -50,6 +51,20 @@ class LocationQueries { return this.getPoint(at, { edge: 'end' }) } + /** + * Get the first matching node in a single branch of the document. + */ + + getMatch(this: Editor, at: Location, match: Match): NodeEntry | undefined { + const path = this.getPath(at) + + for (const entry of this.levels(path, { reverse: true })) { + if (this.isMatch(entry, match)) { + return entry + } + } + } + /** * Calculate the next point forward in the document from a starting point. */ @@ -114,8 +129,8 @@ class LocationQueries { ): AncestorEntry { const path = this.getPath(at, options) const parentPath = Path.parent(path) - const parent = Node.get(this.value, path) as Ancestor - return [parent, parentPath] + const entry = this.getNode(parentPath) + return entry as AncestorEntry } /** @@ -266,7 +281,7 @@ class LocationQueries { if (Path.isPath(at)) { const start = this.getStart(at) - const end = this.getEnd(at || to) + const end = this.getEnd(to || at) at = { anchor: start, focus: end } } diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index f1043cae03..34c680b877 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -17,16 +17,7 @@ import { TextEntry, Value, } from '../..' - -type NodeMatch = - | number - | 'value' - | 'block' - | 'inline' - | 'text' - | 'void' - | Partial - | ((entry: NodeEntry) => boolean) +import { Match } from '../utils' class ValueQueries { /** @@ -78,7 +69,7 @@ class ValueQueries { }) } - isMatch(this: Editor, entry: NodeEntry, match: NodeMatch) { + isMatch(this: Editor, entry: NodeEntry, match: Match) { const [node, path] = entry if (typeof match === 'function') { @@ -129,28 +120,10 @@ class ValueQueries { yield* levels } - /** - * Get the matching node in a single branch of the document at a path. - */ - - getMatch( - this: Editor, - at: Location, - match: NodeMatch - ): NodeEntry | undefined { - const path = this.getPath(at) - - for (const entry of this.levels(path, { reverse: true })) { - if (this.isMatch(entry, match)) { - return entry - } - } - } - *matches( this: Editor, options: { - match: NodeMatch + match: Match at: Location hanging?: boolean reverse?: boolean diff --git a/packages/slate/src/classes/utils.ts b/packages/slate/src/classes/utils.ts new file mode 100644 index 0000000000..e19736e96d --- /dev/null +++ b/packages/slate/src/classes/utils.ts @@ -0,0 +1,16 @@ +import { NodeEntry } from '..' + +/** + * `Match` is a shorthand for a `NodeEntry` predicate for handling the most + * common needs for rich text editing. + */ + +export type Match = + | number + | 'value' + | 'block' + | 'inline' + | 'text' + | 'void' + | Partial + | ((entry: NodeEntry) => boolean) diff --git a/packages/slate/test/commands/coverNodes/block/block-end.js b/packages/slate/test/commands/coverNodes/block/block-end.js deleted file mode 100644 index f16fe447e1..0000000000 --- a/packages/slate/test/commands/coverNodes/block/block-end.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const input = ( - - one - - two - - - three - - -) - -export const run = editor => { - editor.coverNodes() -} - -export const output = ( - - one - - - two - - - three - - - -) diff --git a/packages/slate/test/commands/coverNodes/inline/inline.js b/packages/slate/test/commands/coverNodes/inline/inline.js deleted file mode 100644 index fe0fb24ace..0000000000 --- a/packages/slate/test/commands/coverNodes/inline/inline.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.coverNodes() -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - - - word - - - - - - -) diff --git a/packages/slate/test/commands/insertNodes/selection/none-empty.js b/packages/slate/test/commands/insertNodes/selection/none-empty.js index aa2eedc9ce..debe23bd6c 100644 --- a/packages/slate/test/commands/insertNodes/selection/none-empty.js +++ b/packages/slate/test/commands/insertNodes/selection/none-empty.js @@ -15,3 +15,5 @@ export const output = ( ) + +export const skip = true diff --git a/packages/slate/test/commands/uncoverNodes/match-block/block-nested.js b/packages/slate/test/commands/uncoverNodes/match-block/block-nested.js deleted file mode 100644 index 2919779bff..0000000000 --- a/packages/slate/test/commands/uncoverNodes/match-block/block-nested.js +++ /dev/null @@ -1,29 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - word - - - -) diff --git a/packages/slate/test/commands/uncoverNodes/match-block/block-across.js b/packages/slate/test/commands/unwrapNodes/match-block/block-across.js similarity index 89% rename from packages/slate/test/commands/uncoverNodes/match-block/block-across.js rename to packages/slate/test/commands/unwrapNodes/match-block/block-across.js index 6515530490..8a25f56b9e 100644 --- a/packages/slate/test/commands/uncoverNodes/match-block/block-across.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-end.js b/packages/slate/test/commands/unwrapNodes/match-block/block-end.js index dc4f5b1ef5..3d22470766 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-end.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-end.js @@ -17,7 +17,7 @@ export const input = ( five - six + six @@ -25,17 +25,15 @@ export const input = ( export const output = ( - - one - two - three - four - + one + two + three + four five - six + six ) diff --git a/packages/slate/test/commands/uncoverNodes/match-block/block-inline.js b/packages/slate/test/commands/unwrapNodes/match-block/block-inline.js similarity index 93% rename from packages/slate/test/commands/uncoverNodes/match-block/block-inline.js rename to packages/slate/test/commands/unwrapNodes/match-block/block-inline.js index 057503ec1d..5ba77f2023 100644 --- a/packages/slate/test/commands/uncoverNodes/match-block/block-inline.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js b/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js index 0560a6a72f..2941afe806 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-middle.js @@ -15,7 +15,7 @@ export const input = ( three - four + four five six @@ -25,19 +25,15 @@ export const input = ( export const output = ( - - one - two - + one + two three - four - - - five - six + four + five + six ) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js b/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js index 86ca6067f2..5df4580ced 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-nested.js @@ -8,18 +8,11 @@ export const run = editor => { export const input = ( - - - one - two - - three - + + - four + word - five - six @@ -28,19 +21,8 @@ export const input = ( export const output = ( - - one - two - - - three - - four - - - five - six + word diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-start.js b/packages/slate/test/commands/unwrapNodes/match-block/block-start.js index de8bfdd62a..24f499e355 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-start.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block-start.js @@ -13,7 +13,7 @@ export const input = ( one - two + two three four @@ -29,13 +29,11 @@ export const output = ( one - two - - - three - four - five - six + two + three + four + five + six ) diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block.js b/packages/slate/test/commands/unwrapNodes/match-block/block.js index 35761f6afc..a1f55b3ed0 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block.js +++ b/packages/slate/test/commands/unwrapNodes/match-block/block.js @@ -10,7 +10,7 @@ export const input = ( - one + word @@ -19,7 +19,7 @@ export const input = ( export const output = ( - one + word ) diff --git a/packages/slate/test/commands/uncoverNodes/match-inline/block-nested.js b/packages/slate/test/commands/unwrapNodes/match-inline/block-nested.js similarity index 89% rename from packages/slate/test/commands/uncoverNodes/match-inline/block-nested.js rename to packages/slate/test/commands/unwrapNodes/match-inline/block-nested.js index 3396232c8d..ea62fae8db 100644 --- a/packages/slate/test/commands/uncoverNodes/match-inline/block-nested.js +++ b/packages/slate/test/commands/unwrapNodes/match-inline/block-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/uncoverNodes/match-inline/inline-across.js b/packages/slate/test/commands/unwrapNodes/match-inline/inline-across.js similarity index 90% rename from packages/slate/test/commands/uncoverNodes/match-inline/inline-across.js rename to packages/slate/test/commands/unwrapNodes/match-inline/inline-across.js index 1115456350..16205c331e 100644 --- a/packages/slate/test/commands/uncoverNodes/match-inline/inline-across.js +++ b/packages/slate/test/commands/unwrapNodes/match-inline/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/uncoverNodes/match-inline/inline-over.js b/packages/slate/test/commands/unwrapNodes/match-inline/inline-over.js similarity index 90% rename from packages/slate/test/commands/uncoverNodes/match-inline/inline-over.js rename to packages/slate/test/commands/unwrapNodes/match-inline/inline-over.js index 2984140649..b2f34a495c 100644 --- a/packages/slate/test/commands/uncoverNodes/match-inline/inline-over.js +++ b/packages/slate/test/commands/unwrapNodes/match-inline/inline-over.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/uncoverNodes/match-inline/inline.js b/packages/slate/test/commands/unwrapNodes/match-inline/inline.js similarity index 88% rename from packages/slate/test/commands/uncoverNodes/match-inline/inline.js rename to packages/slate/test/commands/unwrapNodes/match-inline/inline.js index 5386f28211..4034756b13 100644 --- a/packages/slate/test/commands/uncoverNodes/match-inline/inline.js +++ b/packages/slate/test/commands/unwrapNodes/match-inline/inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' } }) } export const input = ( diff --git a/packages/slate/test/commands/uncoverNodes/path/block-multiple.js b/packages/slate/test/commands/unwrapNodes/path/block-multiple.js similarity index 89% rename from packages/slate/test/commands/uncoverNodes/path/block-multiple.js rename to packages/slate/test/commands/unwrapNodes/path/block-multiple.js index 5d165a3912..b585c4fe57 100644 --- a/packages/slate/test/commands/uncoverNodes/path/block-multiple.js +++ b/packages/slate/test/commands/unwrapNodes/path/block-multiple.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ at: [0] }) + editor.unwrapNodes({ at: [0] }) } export const input = ( diff --git a/packages/slate/test/commands/uncoverNodes/path/block.js b/packages/slate/test/commands/unwrapNodes/path/block.js similarity index 87% rename from packages/slate/test/commands/uncoverNodes/path/block.js rename to packages/slate/test/commands/unwrapNodes/path/block.js index 4e41465deb..14183ce075 100644 --- a/packages/slate/test/commands/uncoverNodes/path/block.js +++ b/packages/slate/test/commands/unwrapNodes/path/block.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ at: [0] }) + editor.unwrapNodes({ at: [0] }) } export const input = ( diff --git a/packages/slate/test/commands/unwrapNodes/match-block/block-all.js b/packages/slate/test/commands/unwrapNodes/split-block/block-all.js similarity index 91% rename from packages/slate/test/commands/unwrapNodes/match-block/block-all.js rename to packages/slate/test/commands/unwrapNodes/split-block/block-all.js index 1b5f2512d2..be136bb47a 100644 --- a/packages/slate/test/commands/unwrapNodes/match-block/block-all.js +++ b/packages/slate/test/commands/unwrapNodes/split-block/block-all.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.unwrapNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' }, split: true }) } export const input = ( diff --git a/packages/slate/test/commands/uncoverNodes/match-block/block-end.js b/packages/slate/test/commands/unwrapNodes/split-block/block-end.js similarity index 66% rename from packages/slate/test/commands/uncoverNodes/match-block/block-end.js rename to packages/slate/test/commands/unwrapNodes/split-block/block-end.js index a9fea34861..693a3f9a12 100644 --- a/packages/slate/test/commands/uncoverNodes/match-block/block-end.js +++ b/packages/slate/test/commands/unwrapNodes/split-block/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' }, split: true }) } export const input = ( @@ -17,7 +17,7 @@ export const input = ( five - six + six @@ -25,15 +25,17 @@ export const input = ( export const output = ( - one - two - three - four + + one + two + three + four + five - six + six ) diff --git a/packages/slate/test/commands/uncoverNodes/match-block/block-middle.js b/packages/slate/test/commands/unwrapNodes/split-block/block-middle.js similarity index 63% rename from packages/slate/test/commands/uncoverNodes/match-block/block-middle.js rename to packages/slate/test/commands/unwrapNodes/split-block/block-middle.js index 8d63ff594b..a46a44978b 100644 --- a/packages/slate/test/commands/uncoverNodes/match-block/block-middle.js +++ b/packages/slate/test/commands/unwrapNodes/split-block/block-middle.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' }, split: true }) } export const input = ( @@ -15,7 +15,7 @@ export const input = ( three - four + four five six @@ -25,15 +25,19 @@ export const input = ( export const output = ( - one - two + + one + two + three - four + four + + + five + six - five - six ) diff --git a/packages/slate/test/commands/unwrapNodes/split-block/block-nested.js b/packages/slate/test/commands/unwrapNodes/split-block/block-nested.js new file mode 100644 index 0000000000..5960eff81f --- /dev/null +++ b/packages/slate/test/commands/unwrapNodes/split-block/block-nested.js @@ -0,0 +1,47 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.unwrapNodes({ match: { key: 'a' }, split: true }) +} + +export const input = ( + + + + one + two + + three + + + four + + five + six + + + +) + +export const output = ( + + + + one + two + + + three + + + four + + + five + six + + + +) diff --git a/packages/slate/test/commands/uncoverNodes/match-block/block-start.js b/packages/slate/test/commands/unwrapNodes/split-block/block-start.js similarity index 66% rename from packages/slate/test/commands/uncoverNodes/match-block/block-start.js rename to packages/slate/test/commands/unwrapNodes/split-block/block-start.js index 800611429c..e6e413d685 100644 --- a/packages/slate/test/commands/uncoverNodes/match-block/block-start.js +++ b/packages/slate/test/commands/unwrapNodes/split-block/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) + editor.unwrapNodes({ match: { key: 'a' }, split: true }) } export const input = ( @@ -13,7 +13,7 @@ export const input = ( one - two + two three four @@ -29,11 +29,13 @@ export const output = ( one - two + two + + + three + four + five + six - three - four - five - six ) diff --git a/packages/slate/test/commands/coverNodes/block/block.js b/packages/slate/test/commands/unwrapNodes/split-block/block.js similarity index 67% rename from packages/slate/test/commands/coverNodes/block/block.js rename to packages/slate/test/commands/unwrapNodes/split-block/block.js index 2d67883253..026c39e3e1 100644 --- a/packages/slate/test/commands/coverNodes/block/block.js +++ b/packages/slate/test/commands/unwrapNodes/split-block/block.js @@ -3,23 +3,23 @@ import { h } from '../../../helpers' export const run = editor => { - editor.coverNodes() + editor.unwrapNodes({ match: { key: 'a' }, split: true }) } export const input = ( - - word + + + one + ) export const output = ( - - - word - + + one ) diff --git a/packages/slate/test/commands/coverNodes/block/block-across-nested.js b/packages/slate/test/commands/wrapNodes/block/block-across-nested.js similarity index 93% rename from packages/slate/test/commands/coverNodes/block/block-across-nested.js rename to packages/slate/test/commands/wrapNodes/block/block-across-nested.js index c5d046b2ba..d557c068e3 100644 --- a/packages/slate/test/commands/coverNodes/block/block-across-nested.js +++ b/packages/slate/test/commands/wrapNodes/block/block-across-nested.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.coverNodes() + editor.wrapNodes() } export const input = ( diff --git a/packages/slate/test/commands/wrapNodes/block/block-across.js b/packages/slate/test/commands/wrapNodes/block/block-across.js index 2f0154a3f1..dd4447b728 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-across.js +++ b/packages/slate/test/commands/wrapNodes/block/block-across.js @@ -2,32 +2,30 @@ import { h } from '../../../helpers' +export const run = editor => { + editor.wrapNodes() +} + export const input = ( - one + word - two + another ) -export const run = editor => { - editor.wrapNodes() -} - export const output = ( - on - + - e + word - t + another - wo ) diff --git a/packages/slate/test/commands/wrapNodes/block/block-end.js b/packages/slate/test/commands/wrapNodes/block/block-end.js index 97353c9a31..71fa38bb9d 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-end.js +++ b/packages/slate/test/commands/wrapNodes/block/block-end.js @@ -4,22 +4,29 @@ import { h } from '../../../helpers' export const input = ( + one - word + two + + + three ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes() } export const output = ( - wo - + one + + + two + - rd + three diff --git a/packages/slate/test/commands/wrapNodes/block/block-nested.js b/packages/slate/test/commands/wrapNodes/block/block-nested.js index 205256a319..15adb967cd 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-nested.js +++ b/packages/slate/test/commands/wrapNodes/block/block-nested.js @@ -2,30 +2,28 @@ import { h } from '../../../helpers' +export const run = editor => { + editor.wrapNodes() +} + export const input = ( - - word + + word ) -export const run = editor => { - editor.wrapNodes() -} - export const output = ( - w - - or + + word - d ) diff --git a/packages/slate/test/commands/wrapNodes/block/block.js b/packages/slate/test/commands/wrapNodes/block/block.js index 2eed2428ca..4a83d90ab1 100644 --- a/packages/slate/test/commands/wrapNodes/block/block.js +++ b/packages/slate/test/commands/wrapNodes/block/block.js @@ -2,6 +2,10 @@ import { h } from '../../../helpers' +export const run = editor => { + editor.wrapNodes() +} + export const input = ( @@ -10,13 +14,9 @@ export const input = ( ) -export const run = editor => { - editor.wrapNodes() -} - export const output = ( - + word diff --git a/packages/slate/test/commands/coverNodes/block/inline-across.js b/packages/slate/test/commands/wrapNodes/block/inline-across.js similarity index 95% rename from packages/slate/test/commands/coverNodes/block/inline-across.js rename to packages/slate/test/commands/wrapNodes/block/inline-across.js index 017c7304b8..072c54a580 100644 --- a/packages/slate/test/commands/coverNodes/block/inline-across.js +++ b/packages/slate/test/commands/wrapNodes/block/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.coverNodes() + editor.wrapNodes() } export const input = ( diff --git a/packages/slate/test/commands/coverNodes/block/omit-nodes.js b/packages/slate/test/commands/wrapNodes/block/omit-nodes.js similarity index 95% rename from packages/slate/test/commands/coverNodes/block/omit-nodes.js rename to packages/slate/test/commands/wrapNodes/block/omit-nodes.js index 93d1294021..eb5eb85fab 100644 --- a/packages/slate/test/commands/coverNodes/block/omit-nodes.js +++ b/packages/slate/test/commands/wrapNodes/block/omit-nodes.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.coverNodes( + editor.wrapNodes( diff --git a/packages/slate/test/commands/coverNodes/inline/inline-across.js b/packages/slate/test/commands/wrapNodes/inline/inline-across.js similarity index 95% rename from packages/slate/test/commands/coverNodes/inline/inline-across.js rename to packages/slate/test/commands/wrapNodes/inline/inline-across.js index f9b2961f4d..c52fcae263 100644 --- a/packages/slate/test/commands/coverNodes/inline/inline-across.js +++ b/packages/slate/test/commands/wrapNodes/inline/inline-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.coverNodes() + editor.wrapNodes() } export const input = ( diff --git a/packages/slate/test/commands/wrapNodes/inline/inline.js b/packages/slate/test/commands/wrapNodes/inline/inline.js index 9f77d8e3c0..12c87a590f 100644 --- a/packages/slate/test/commands/wrapNodes/inline/inline.js +++ b/packages/slate/test/commands/wrapNodes/inline/inline.js @@ -2,28 +2,34 @@ import { h } from '../../../helpers' +export const run = editor => { + editor.wrapNodes() +} + export const input = ( - one - two - three + + + word + + ) -export const run = editor => { - editor.wrapNodes() -} - export const output = ( - one - - two + + + + + word + + - three + ) diff --git a/packages/slate/test/commands/coverNodes/inline/text.js b/packages/slate/test/commands/wrapNodes/inline/text.js similarity index 90% rename from packages/slate/test/commands/coverNodes/inline/text.js rename to packages/slate/test/commands/wrapNodes/inline/text.js index 7831d38e0b..aeb779f774 100644 --- a/packages/slate/test/commands/coverNodes/inline/text.js +++ b/packages/slate/test/commands/wrapNodes/inline/text.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.coverNodes() + editor.wrapNodes() } export const input = ( diff --git a/packages/slate/test/commands/coverNodes/block/block-across.js b/packages/slate/test/commands/wrapNodes/split-block/block-across.js similarity index 61% rename from packages/slate/test/commands/coverNodes/block/block-across.js rename to packages/slate/test/commands/wrapNodes/split-block/block-across.js index 088e061d8a..7421be3869 100644 --- a/packages/slate/test/commands/coverNodes/block/block-across.js +++ b/packages/slate/test/commands/wrapNodes/split-block/block-across.js @@ -2,30 +2,32 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.coverNodes() -} - export const input = ( - word + one - another + two ) +export const run = editor => { + editor.wrapNodes(, { split: true }) +} + export const output = ( - + on + - word + e - another + t + wo ) diff --git a/packages/slate/test/commands/wrapNodes/split-block/block-end.js b/packages/slate/test/commands/wrapNodes/split-block/block-end.js new file mode 100644 index 0000000000..74c6ac4c88 --- /dev/null +++ b/packages/slate/test/commands/wrapNodes/split-block/block-end.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + word + + +) + +export const run = editor => { + editor.wrapNodes(, { split: true }) +} + +export const output = ( + + wo + + + rd + + + +) diff --git a/packages/slate/test/commands/wrapNodes/block/block-middle.js b/packages/slate/test/commands/wrapNodes/split-block/block-middle.js similarity index 87% rename from packages/slate/test/commands/wrapNodes/block/block-middle.js rename to packages/slate/test/commands/wrapNodes/split-block/block-middle.js index b49765ff29..ddd00b2ce7 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-middle.js +++ b/packages/slate/test/commands/wrapNodes/split-block/block-middle.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes(, { split: true }) } export const output = ( diff --git a/packages/slate/test/commands/coverNodes/block/block-nested.js b/packages/slate/test/commands/wrapNodes/split-block/block-nested.js similarity index 61% rename from packages/slate/test/commands/coverNodes/block/block-nested.js rename to packages/slate/test/commands/wrapNodes/split-block/block-nested.js index 1b22254211..288b640e0f 100644 --- a/packages/slate/test/commands/coverNodes/block/block-nested.js +++ b/packages/slate/test/commands/wrapNodes/split-block/block-nested.js @@ -2,28 +2,30 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.coverNodes() -} - export const input = ( - - word + + word ) +export const run = editor => { + editor.wrapNodes(, { split: true }) +} + export const output = ( + w - - word + + or + d ) diff --git a/packages/slate/test/commands/wrapNodes/block/block-start.js b/packages/slate/test/commands/wrapNodes/split-block/block-start.js similarity index 87% rename from packages/slate/test/commands/wrapNodes/block/block-start.js rename to packages/slate/test/commands/wrapNodes/split-block/block-start.js index b8cdb83c1c..fd5a94d959 100644 --- a/packages/slate/test/commands/wrapNodes/block/block-start.js +++ b/packages/slate/test/commands/wrapNodes/split-block/block-start.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - editor.wrapNodes() + editor.wrapNodes(, { split: true }) } export const output = ( diff --git a/packages/slate/test/commands/uncoverNodes/match-block/block.js b/packages/slate/test/commands/wrapNodes/split-block/block.js similarity index 81% rename from packages/slate/test/commands/uncoverNodes/match-block/block.js rename to packages/slate/test/commands/wrapNodes/split-block/block.js index de0cc5f321..0ea0d6c2f3 100644 --- a/packages/slate/test/commands/uncoverNodes/match-block/block.js +++ b/packages/slate/test/commands/wrapNodes/split-block/block.js @@ -2,24 +2,24 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.uncoverNodes({ match: { key: 'a' } }) -} - export const input = ( - - - word - + + word ) +export const run = editor => { + editor.wrapNodes(, { split: true }) +} + export const output = ( - - word + + + word + ) diff --git a/packages/slate/test/commands/wrapNodes/split-inline/inline.js b/packages/slate/test/commands/wrapNodes/split-inline/inline.js new file mode 100644 index 0000000000..baf3730fbc --- /dev/null +++ b/packages/slate/test/commands/wrapNodes/split-inline/inline.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + two + three + + +) + +export const run = editor => { + editor.wrapNodes(, { split: true }) +} + +export const output = ( + + + one + + two + + three + + +) From 22a40353931e7662e3e8c134fb9c7c0ebc16a237 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 28 Oct 2019 10:02:19 -0400 Subject: [PATCH 072/165] flip levels/ancestors ordering --- packages/slate/src/classes/queries/location.ts | 2 +- packages/slate/src/classes/queries/value.ts | 6 +++--- packages/slate/src/interfaces/node.ts | 4 ++-- packages/slate/src/interfaces/path.ts | 6 +++--- packages/slate/test/interfaces/Node/ancestors/reverse.js | 2 +- packages/slate/test/interfaces/Node/ancestors/success.js | 2 +- packages/slate/test/interfaces/Node/levels/reverse.js | 4 ++-- packages/slate/test/interfaces/Node/levels/success.js | 4 ++-- packages/slate/test/interfaces/Path/ancestors/reverse.js | 2 +- packages/slate/test/interfaces/Path/ancestors/success.js | 2 +- packages/slate/test/interfaces/Path/levels/reverse.js | 2 +- packages/slate/test/interfaces/Path/levels/success.js | 2 +- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 9318bba1cc..c0aa314353 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -58,7 +58,7 @@ class LocationQueries { getMatch(this: Editor, at: Location, match: Match): NodeEntry | undefined { const path = this.getPath(at) - for (const entry of this.levels(path, { reverse: true })) { + for (const entry of this.levels(path)) { if (this.isMatch(entry, match)) { return entry } diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 34c680b877..adfa5e5815 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -100,12 +100,12 @@ class ValueQueries { path: Path, options: { reverse?: boolean - } + } = {} ): Iterable { const { reverse = false } = options const levels: NodeEntry[] = [] - for (const [n, p] of Node.levels(this.value, path, { reverse: true })) { + for (const [n, p] of Node.levels(this.value, path)) { levels.push([n, p]) if (Element.isElement(n) && this.isVoid(n)) { @@ -113,7 +113,7 @@ class ValueQueries { } } - if (reverse === false) { + if (reverse) { levels.reverse() } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 72f5438d6d..ae25011409 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -136,7 +136,7 @@ namespace Node { path: Path, predicate: (entry: NodeEntry) => boolean ): NodeEntry | undefined => { - for (const entry of Node.levels(root, path)) { + for (const entry of Node.levels(root, path, { reverse: true })) { if (predicate(entry)) { return entry } @@ -378,7 +378,7 @@ namespace Node { path: Path, predicate: (entry: NodeEntry) => boolean ): NodeEntry | undefined => { - for (const entry of Node.levels(root, path, { reverse: true })) { + for (const entry of Node.levels(root, path)) { if (predicate(entry)) { return entry } diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index a27e1d5eb1..eacf986767 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -25,9 +25,9 @@ namespace Path { let paths = Path.levels(path, options) if (reverse) { - paths = paths.slice(0, -1) - } else { paths = paths.slice(1) + } else { + paths = paths.slice(0, -1) } return paths @@ -217,7 +217,7 @@ namespace Path { const { reverse = false } = options const list: Path[] = [] - for (let i = path.length; i >= 0; i--) { + for (let i = 0; i <= path.length; i++) { list.push(path.slice(0, i)) } diff --git a/packages/slate/test/interfaces/Node/ancestors/reverse.js b/packages/slate/test/interfaces/Node/ancestors/reverse.js index 74131b89ed..c0574c784d 100644 --- a/packages/slate/test/interfaces/Node/ancestors/reverse.js +++ b/packages/slate/test/interfaces/Node/ancestors/reverse.js @@ -15,4 +15,4 @@ export const test = value => { return Array.from(Node.ancestors(value, [0, 0], { reverse: true })) } -export const output = [[input, []], [input.nodes[0], [0]]] +export const output = [[input.nodes[0], [0]], [input, []]] diff --git a/packages/slate/test/interfaces/Node/ancestors/success.js b/packages/slate/test/interfaces/Node/ancestors/success.js index ae2b61303b..3078a93fee 100644 --- a/packages/slate/test/interfaces/Node/ancestors/success.js +++ b/packages/slate/test/interfaces/Node/ancestors/success.js @@ -15,4 +15,4 @@ export const test = value => { return Array.from(Node.ancestors(value, [0, 0])) } -export const output = [[input.nodes[0], [0]], [input, []]] +export const output = [[input, []], [input.nodes[0], [0]]] diff --git a/packages/slate/test/interfaces/Node/levels/reverse.js b/packages/slate/test/interfaces/Node/levels/reverse.js index 7edc3c23ff..99b9497545 100644 --- a/packages/slate/test/interfaces/Node/levels/reverse.js +++ b/packages/slate/test/interfaces/Node/levels/reverse.js @@ -16,7 +16,7 @@ export const test = value => { } export const output = [ - [input, []], - [input.nodes[0], [0]], [input.nodes[0].nodes[0], [0, 0]], + [input.nodes[0], [0]], + [input, []], ] diff --git a/packages/slate/test/interfaces/Node/levels/success.js b/packages/slate/test/interfaces/Node/levels/success.js index b6fc86b14c..8c404c295f 100644 --- a/packages/slate/test/interfaces/Node/levels/success.js +++ b/packages/slate/test/interfaces/Node/levels/success.js @@ -16,7 +16,7 @@ export const test = value => { } export const output = [ - [input.nodes[0].nodes[0], [0, 0]], - [input.nodes[0], [0]], [input, []], + [input.nodes[0], [0]], + [input.nodes[0].nodes[0], [0, 0]], ] diff --git a/packages/slate/test/interfaces/Path/ancestors/reverse.js b/packages/slate/test/interfaces/Path/ancestors/reverse.js index 3f5e1205b3..a4463ed7ae 100644 --- a/packages/slate/test/interfaces/Path/ancestors/reverse.js +++ b/packages/slate/test/interfaces/Path/ancestors/reverse.js @@ -6,4 +6,4 @@ export const test = path => { return Path.ancestors(path, { reverse: true }) } -export const output = [[], [0], [0, 1]] +export const output = [[0, 1], [0], []] diff --git a/packages/slate/test/interfaces/Path/ancestors/success.js b/packages/slate/test/interfaces/Path/ancestors/success.js index 992d2331f4..284549496f 100644 --- a/packages/slate/test/interfaces/Path/ancestors/success.js +++ b/packages/slate/test/interfaces/Path/ancestors/success.js @@ -6,4 +6,4 @@ export const test = path => { return Path.ancestors(path) } -export const output = [[0, 1], [0], []] +export const output = [[], [0], [0, 1]] diff --git a/packages/slate/test/interfaces/Path/levels/reverse.js b/packages/slate/test/interfaces/Path/levels/reverse.js index 4f1b8978e1..f4ebbbddf5 100644 --- a/packages/slate/test/interfaces/Path/levels/reverse.js +++ b/packages/slate/test/interfaces/Path/levels/reverse.js @@ -6,4 +6,4 @@ export const test = path => { return Path.levels(path, { reverse: true }) } -export const output = [[], [0], [0, 1], [0, 1, 2]] +export const output = [[0, 1, 2], [0, 1], [0], []] diff --git a/packages/slate/test/interfaces/Path/levels/success.js b/packages/slate/test/interfaces/Path/levels/success.js index 6546dc06ff..70b3084363 100644 --- a/packages/slate/test/interfaces/Path/levels/success.js +++ b/packages/slate/test/interfaces/Path/levels/success.js @@ -6,4 +6,4 @@ export const test = path => { return Path.levels(path) } -export const output = [[0, 1, 2], [0, 1], [0], []] +export const output = [[][0], [0, 1], [0, 1, 2]] From b91bd63f6324f79c9a338fcb7ab1ec16434c951b Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 28 Oct 2019 10:44:13 -0400 Subject: [PATCH 073/165] switch splitNodes to use levels --- packages/slate/src/classes/commands/node.ts | 152 +++++++++--------- .../slate/src/classes/queries/location.ts | 6 + packages/slate/src/classes/queries/value.ts | 5 +- 3 files changed, 80 insertions(+), 83 deletions(-) diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index bc2b62610e..bc591cccf9 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -40,14 +40,15 @@ class NodeCommands { const [node] = nodes - // If the match isn't explicitly set, infer it from the node. if (match == null) { - if (Text.isText(node)) { + if (Path.isPath(at)) { + match = at.length + } else if (Text.isText(node)) { match = 'text' } else if (this.isInline(node)) { match = 'inline' } else { - match = 'block' + match = Path.isPath(at) ? at.length : 'block' } } @@ -121,7 +122,10 @@ class NodeCommands { } ) { this.withoutNormalizing(() => { - const { at = this.value.selection, match = 'block' } = options + const { + at = this.value.selection, + match = Path.isPath(at) ? at.length : 'block', + } = options if (!at) { return @@ -171,16 +175,11 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - const { match = 'block' } = options - let { at } = options + let { at = this.value.selection } = options + const { match = Path.isPath(at) ? at.length : 'block' } = options if (!at) { - if (selection) { - at = selection - } else { - return - } + return } if (Range.isRange(at)) { @@ -301,18 +300,14 @@ class NodeCommands { } ) { this.withoutNormalizing(() => { - const { selection } = this.value - const { to, match = 'block' } = options - let { at } = options - let selectRef + const { + to, + at = this.value.selection, + match = Path.isPath(at) ? at.length : 'block', + } = options if (!at) { - if (selection) { - at = selection - selectRef = this.createRangeRef(at) - } else { - return - } + return } const toRef = this.createPathRef(to) @@ -328,10 +323,6 @@ class NodeCommands { } } - if (selectRef) { - this.select(selectRef.current!) - } - toRef.unref() }) } @@ -435,7 +426,10 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { at = this.value.selection, match = 'block' } = options + const { + at = this.value.selection, + match = Path.isPath(at) ? at.length : 'block', + } = options if (!at) { return @@ -465,7 +459,10 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { at = this.value.selection, match = 'block' } = options + const { + at = this.value.selection, + match = Path.isPath(at) ? at.length : 'block', + } = options if (!at) { return @@ -518,22 +515,21 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value - const { always = true, match = 'block' } = options - let { at, height = 0 } = options + const { always = true } = options + let { at = this.value.selection, match, height = 0 } = options let target: number | null = null let position - let selectRef let edgeRef - let firstPath if (!at) { - if (selection) { - const [, end] = Range.edges(selection) - selectRef = this.createPointRef(end) - at = selection + return + } + + if (match == null) { + if (Path.isPath(at)) { + match = at.length } else { - return + match = 'block' } } @@ -545,60 +541,49 @@ class NodeCommands { const pointRef = this.createPointRef(end) this.delete({ at }) at = pointRef.unref()! + + if (options.at == null) { + this.select(at) + } } } // If the target is a path, the default height-skipping and position // counters need to account for us potentially splitting at a non-leaf. if (Path.isPath(at)) { - const [, p] = Node.first(this.value, at) - firstPath = p - height = p.length - at.length + 1 + const point = this.getPoint(at) + match = at.length - 1 position = at[at.length - 1] - at = at.slice(0, -1) + height = point.path.length - at.length + 1 + at = point } else { - firstPath = at.path position = at.offset edgeRef = this.createPointRef(at, { affinity: 'backward' }) } - let d = firstPath.length - height + const highest = this.getMatch(at, match) - for (const [, path] of this.matches({ at, match })) { - while (d >= path.length && d > 0) { - const p = firstPath.slice(0, d) - d-- - - // With the `always: false` option, we will instead split the nodes only - // when the point isn't already at it's edge. - if ( - !always && - edgeRef && - edgeRef.current && - this.isEdge(edgeRef.current, p) - ) { - continue - } + if (!highest) { + return + } - const [node] = this.getNode(p) - const { text, marks, nodes, ...properties } = node + const [, highestPath] = highest + const lowestPath = at.path.slice(0, at.path.length - height) - this.apply({ - type: 'split_node', - path: p, - position, - target, - properties, - }) + for (const [n, path] of this.levels(lowestPath, { reverse: true })) { + if (path.length < highestPath.length || path.length === 0) { + break + } - target = position - position = firstPath[d] + 1 + // With `always: false`, split only when not at the edge already. + if (!always && edgeRef && this.isEdge(edgeRef.current!, path)) { + continue } - } - if (selectRef) { - this.select(selectRef.current!) - selectRef.unref() + const { text, marks, nodes, ...properties } = n + this.apply({ type: 'split_node', path, position, target, properties }) + target = position + position = path[path.length - 1] + 1 } if (edgeRef) { @@ -623,7 +608,7 @@ class NodeCommands { this.withoutNormalizing(() => { const { at = this.value.selection, - match = 'block', + match = Path.isPath(at) ? at.length : 'block', split = false, } = options @@ -663,16 +648,23 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { - match = this.isInline(element) ? 'inline' : 'block', - split = false, - } = options - let { at = this.value.selection } = options + const { split = false } = options + let { match, at = this.value.selection } = options if (!at) { return } + if (match == null) { + if (Path.isPath(at)) { + match = at.length + } else if (this.isInline(element)) { + match = 'inline' + } else { + match = 'block' + } + } + if (split && Range.isRange(at)) { const [start, end] = Range.edges(at) const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index c0aa314353..8cba793ecc 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -56,6 +56,12 @@ class LocationQueries { */ getMatch(this: Editor, at: Location, match: Match): NodeEntry | undefined { + // PERF: If the target is a path and the match is a depth, don't traverse. + if (Path.isPath(at) && typeof match === 'number' && match <= at.length) { + const p = at.slice(0, match) + return this.getNode(p) + } + const path = this.getPath(at) for (const entry of this.levels(path)) { diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index adfa5e5815..02b6317702 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -133,10 +133,9 @@ class ValueQueries { let { at } = options let prevPath: Path | undefined - // PERF: If the target is a path, we don't need to traverse at all. + // PERF: If the target is a path, don't traverse. if (Path.isPath(at)) { - yield this.getNode(at) - return + return this.getMatch(at, match) } at = this.getRange(at, { hanging }) From e51bdc18db82165d45932bc2e6b5ff87c346c811 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 28 Oct 2019 10:52:29 -0400 Subject: [PATCH 074/165] change split to always:false by default --- packages/slate/src/classes/commands/mark.ts | 4 +-- packages/slate/src/classes/commands/node.ts | 21 +++++------ packages/slate/src/classes/commands/text.ts | 6 ++-- .../after-inline-void.js | 2 +- .../{depth-block => always}/after-inline.js | 2 +- .../splitNodes/always/before-inline.js | 28 +++++++++++++++ .../{depth-block => always}/block-end.js | 2 +- .../{depth-block => always}/block-start.js | 2 +- .../splitNodes/depth-block/before-inline.js | 36 ------------------- .../{with-inline.js => inline-middle.js} | 0 .../splitNodes/depth-inline/block-end.js | 33 ----------------- .../splitNodes/depth-inline/block-start.js | 35 ------------------ .../{block-middle.js => inline-middle.js} | 0 .../point.js => point/with-match.js} | 0 14 files changed, 48 insertions(+), 123 deletions(-) rename packages/slate/test/commands/splitNodes/{depth-block => always}/after-inline-void.js (89%) rename packages/slate/test/commands/splitNodes/{depth-block => always}/after-inline.js (88%) create mode 100644 packages/slate/test/commands/splitNodes/always/before-inline.js rename packages/slate/test/commands/splitNodes/{depth-block => always}/block-end.js (86%) rename packages/slate/test/commands/splitNodes/{depth-block => always}/block-start.js (87%) delete mode 100644 packages/slate/test/commands/splitNodes/depth-block/before-inline.js rename packages/slate/test/commands/splitNodes/depth-block/{with-inline.js => inline-middle.js} (100%) delete mode 100644 packages/slate/test/commands/splitNodes/depth-inline/block-end.js delete mode 100644 packages/slate/test/commands/splitNodes/depth-inline/block-start.js rename packages/slate/test/commands/splitNodes/depth-inline/{block-middle.js => inline-middle.js} (100%) rename packages/slate/test/commands/splitNodes/{depth-block/point.js => point/with-match.js} (100%) diff --git a/packages/slate/src/classes/commands/mark.ts b/packages/slate/src/classes/commands/mark.ts index 163a8f6518..f842f178f4 100644 --- a/packages/slate/src/classes/commands/mark.ts +++ b/packages/slate/src/classes/commands/mark.ts @@ -131,8 +131,8 @@ const splitLocation = ( if (Range.isRange(at)) { const rangeRef = editor.createRangeRef(at, { affinity: 'inward' }) const [start, end] = Range.edges(at) - editor.splitNodes({ at: end, match: 'text', always: false }) - editor.splitNodes({ at: start, match: 'text', always: false }) + editor.splitNodes({ at: end, match: 'text' }) + editor.splitNodes({ at: start, match: 'text' }) const range = rangeRef.unref()! if (options.at == null) { diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index bc591cccf9..08b8aedb56 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -78,7 +78,7 @@ class NodeCommands { const [, matchPath] = atMatch const pathRef = this.createPathRef(matchPath) const isAtEnd = this.isEnd(at, matchPath) - this.splitNodes({ at, match, always: false }) + this.splitNodes({ at, match }) const path = pathRef.unref()! at = isAtEnd ? Path.next(path) : path } else { @@ -515,7 +515,7 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { always = true } = options + const { always = false } = options let { at = this.value.selection, match, height = 0 } = options let target: number | null = null let position @@ -571,19 +571,20 @@ class NodeCommands { const lowestPath = at.path.slice(0, at.path.length - height) for (const [n, path] of this.levels(lowestPath, { reverse: true })) { + let split = false + if (path.length < highestPath.length || path.length === 0) { break } - // With `always: false`, split only when not at the edge already. - if (!always && edgeRef && this.isEdge(edgeRef.current!, path)) { - continue + if (always || !edgeRef || !this.isEdge(edgeRef.current!, path)) { + const { text, marks, nodes, ...properties } = n + this.apply({ type: 'split_node', path, position, target, properties }) + split = true } - const { text, marks, nodes, ...properties } = n - this.apply({ type: 'split_node', path, position, target, properties }) target = position - position = path[path.length - 1] + 1 + position = path[path.length - 1] + (split ? 1 : 0) } if (edgeRef) { @@ -668,8 +669,8 @@ class NodeCommands { if (split && Range.isRange(at)) { const [start, end] = Range.edges(at) const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) - this.splitNodes({ at: end, always: false, match }) - this.splitNodes({ at: start, always: false, match }) + this.splitNodes({ at: end, match }) + this.splitNodes({ at: start, match }) at = rangeRef.unref()! if (options.at == null) { diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index e61926c281..9abb20f303 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -64,8 +64,8 @@ class DeletingCommands { const [, ancestorPath] = this.getAncestor(at) const d = Range.isCollapsed(at) ? 'text' : ancestorPath.length const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) - this.splitNodes({ at: end, match: d }) - this.splitNodes({ at: start, match: d }) + this.splitNodes({ at: end, match: d, always: true }) + this.splitNodes({ at: start, match: d, always: true }) at = rangeRef.unref()! } @@ -142,7 +142,7 @@ class DeletingCommands { } const pointRef = this.createPointRef(at) - this.splitNodes({ at }) + this.splitNodes({ at, always: true }) if (pointRef.current) { const [, insertPath] = this.getMatch(pointRef.current.path, 'block')! diff --git a/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js b/packages/slate/test/commands/splitNodes/always/after-inline-void.js similarity index 89% rename from packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js rename to packages/slate/test/commands/splitNodes/always/after-inline-void.js index a78a9f3b54..7e3a74bf27 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/after-inline-void.js +++ b/packages/slate/test/commands/splitNodes/always/after-inline-void.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'block' }) + editor.splitNodes({ match: 'block', always: true }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/after-inline.js b/packages/slate/test/commands/splitNodes/always/after-inline.js similarity index 88% rename from packages/slate/test/commands/splitNodes/depth-block/after-inline.js rename to packages/slate/test/commands/splitNodes/always/after-inline.js index 46093c903f..59328b0104 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/after-inline.js +++ b/packages/slate/test/commands/splitNodes/always/after-inline.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'block' }) + editor.splitNodes({ match: 'block', always: true }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/always/before-inline.js b/packages/slate/test/commands/splitNodes/always/before-inline.js new file mode 100644 index 0000000000..3b37f29968 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/always/before-inline.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ match: 'block', always: true }) +} + +export const input = ( + + + word + hyperlink + word + + +) + +export const output = ( + + word + + + hyperlink + word + + +) diff --git a/packages/slate/test/commands/splitNodes/depth-block/block-end.js b/packages/slate/test/commands/splitNodes/always/block-end.js similarity index 86% rename from packages/slate/test/commands/splitNodes/depth-block/block-end.js rename to packages/slate/test/commands/splitNodes/always/block-end.js index 1c4c1cdec0..8504797506 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/block-end.js +++ b/packages/slate/test/commands/splitNodes/always/block-end.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'block' }) + editor.splitNodes({ match: 'block', always: true }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/block-start.js b/packages/slate/test/commands/splitNodes/always/block-start.js similarity index 87% rename from packages/slate/test/commands/splitNodes/depth-block/block-start.js rename to packages/slate/test/commands/splitNodes/always/block-start.js index 9c55c31841..61e14e8b58 100644 --- a/packages/slate/test/commands/splitNodes/depth-block/block-start.js +++ b/packages/slate/test/commands/splitNodes/always/block-start.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'block' }) + editor.splitNodes({ match: 'block', always: true }) } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/depth-block/before-inline.js b/packages/slate/test/commands/splitNodes/depth-block/before-inline.js deleted file mode 100644 index 55f608a6cf..0000000000 --- a/packages/slate/test/commands/splitNodes/depth-block/before-inline.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitNodes({ match: 'block' }) -} - -export const input = ( - - - word - hyperlink - word - - -) - -export const output = ( - - - word - - - - - - - - - hyperlink - - word - - -) diff --git a/packages/slate/test/commands/splitNodes/depth-block/with-inline.js b/packages/slate/test/commands/splitNodes/depth-block/inline-middle.js similarity index 100% rename from packages/slate/test/commands/splitNodes/depth-block/with-inline.js rename to packages/slate/test/commands/splitNodes/depth-block/inline-middle.js diff --git a/packages/slate/test/commands/splitNodes/depth-inline/block-end.js b/packages/slate/test/commands/splitNodes/depth-inline/block-end.js deleted file mode 100644 index 0a5eb0309d..0000000000 --- a/packages/slate/test/commands/splitNodes/depth-inline/block-end.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitNodes({ match: 'inline' }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - word - - - - - - - -) diff --git a/packages/slate/test/commands/splitNodes/depth-inline/block-start.js b/packages/slate/test/commands/splitNodes/depth-inline/block-start.js deleted file mode 100644 index ce980f43eb..0000000000 --- a/packages/slate/test/commands/splitNodes/depth-inline/block-start.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../helpers' - -export const run = editor => { - editor.splitNodes({ match: 'inline' }) -} - -export const input = ( - - - - - word - - - - -) - -export const output = ( - - - - - - - - - word - - - - -) diff --git a/packages/slate/test/commands/splitNodes/depth-inline/block-middle.js b/packages/slate/test/commands/splitNodes/depth-inline/inline-middle.js similarity index 100% rename from packages/slate/test/commands/splitNodes/depth-inline/block-middle.js rename to packages/slate/test/commands/splitNodes/depth-inline/inline-middle.js diff --git a/packages/slate/test/commands/splitNodes/depth-block/point.js b/packages/slate/test/commands/splitNodes/point/with-match.js similarity index 100% rename from packages/slate/test/commands/splitNodes/depth-block/point.js rename to packages/slate/test/commands/splitNodes/point/with-match.js From 741064a3bba82f56d23e2048019eef4ede23755a Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 28 Oct 2019 11:27:35 -0400 Subject: [PATCH 075/165] fix tests --- packages/slate/src/classes/commands/node.ts | 13 +- .../slate/src/classes/commands/selection.ts | 8 +- packages/slate/src/classes/commands/text.ts | 6 +- .../slate/src/classes/queries/location.ts | 130 +++++++++++------- packages/slate/src/classes/queries/value.ts | 8 +- 5 files changed, 97 insertions(+), 68 deletions(-) diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index 08b8aedb56..f004dabf94 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -198,20 +198,13 @@ class NodeCommands { } for (const [node, path] of this.matches({ at, match })) { - const prev = this.getPreviousPoint(path) + const prev = this.getPrevious(at, match) if (!prev) { - continue - } - - const prevMatcher = Path.isPath(at) ? at.length : match - const prevMatch = this.getMatch(prev, prevMatcher) - - if (!prevMatch) { return } - const [prevNode, prevPath] = prevMatch + const [prevNode, prevPath] = prev const newPath = Path.next(prevPath) const commonPath = Path.common(path, prevPath) const isPreviousSibling = Path.isSibling(path, prevPath) @@ -397,7 +390,9 @@ class NodeCommands { // Merge adjacent text nodes that are empty or have matching marks. if (prev != null && Text.isText(prev)) { if (Text.matches(child, prev)) { + debugger this.mergeNodes({ at: at.concat(n) }) + debugger n-- continue } else if (prev.text === '') { diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index f4543b4ae9..bc55c7a2e1 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -80,8 +80,8 @@ class SelectionCommands { if (edge == null || edge === 'anchor') { const point = reverse - ? this.getPreviousPoint(anchor, opts) - : this.getNextPoint(anchor, opts) + ? this.getBefore(anchor, opts) + : this.getAfter(anchor, opts) if (point) { props.anchor = point @@ -90,8 +90,8 @@ class SelectionCommands { if (edge == null || edge === 'focus') { const point = reverse - ? this.getPreviousPoint(focus, opts) - : this.getNextPoint(focus, opts) + ? this.getBefore(focus, opts) + : this.getAfter(focus, opts) if (point) { props.focus = point diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 9abb20f303..77939c6913 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -50,8 +50,8 @@ class DeletingCommands { } else { const opts = { unit, distance } const target = reverse - ? this.getPreviousPoint(at, opts) - : this.getNextPoint(at, opts) + ? this.getBefore(at, opts) + : this.getAfter(at, opts) if (target) { at = { anchor: at, focus: target } @@ -76,7 +76,7 @@ class DeletingCommands { if (Range.isRange(at)) { const [start, end] = Range.edges(at) - const after = this.getNextPoint(end)! + const after = this.getAfter(end)! const afterRef = this.createPointRef(after) const l = ancestorPath.length const startIndex = start.path[l] diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 8cba793ecc..6bef9ded85 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -13,6 +13,38 @@ import { import { Match } from '../utils' class LocationQueries { + /** + * Get the point after a location. + */ + + getAfter( + this: Editor, + at: Location, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' + } = {} + ): Point | undefined { + at = this.getPoint(at, { edge: 'end' }) + const { distance = 1 } = options + let d = 0 + let target + + for (const p of this.positions({ ...options, at })) { + if (d > distance) { + break + } + + if (d !== 0) { + target = p + } + + d++ + } + + return target + } + /** * Get the common ancestor node of a location. */ @@ -35,6 +67,40 @@ class LocationQueries { return [ancestor, ancestorPath] } + /** + * Get the point before a location. + */ + + getBefore( + this: Editor, + at: Location, + options: { + distance?: number + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' + } = {} + ): Point | undefined { + debugger + at = this.getPoint(at, { edge: 'start' }) + debugger + const { distance = 1 } = options + let d = 0 + let target + + for (const p of this.positions({ ...options, at, reverse: true })) { + if (d > distance) { + break + } + + if (d !== 0) { + target = p + } + + d++ + } + + return target + } + /** * Get the start and end points of a location. */ @@ -72,36 +138,17 @@ class LocationQueries { } /** - * Calculate the next point forward in the document from a starting point. + * Get the matching node in the branch of the document after a location. */ - getNextPoint( - this: Editor, - at: Location, - options: { - distance?: number - edge?: 'start' | 'end' - unit?: 'offset' | 'character' | 'word' | 'line' | 'block' - } = {} - ): Point | undefined { - at = this.getPoint(at, options) - const { distance = 1 } = options - let d = 0 - let target - - for (const p of this.positions({ ...options, at })) { - if (d > distance) { - break - } + getNext(this: Editor, at: Location, match: Match): NodeEntry | undefined { + const point = this.getAfter(at) - if (d !== 0) { - target = p - } - - d++ + if (!point) { + return } - return target + return this.getMatch(point, match) } /** @@ -234,36 +281,17 @@ class LocationQueries { } /** - * Calculate the previous point backward from a starting point. + * Get the matching node in the branch of the document before a location. */ - getPreviousPoint( - this: Editor, - at: Location, - options: { - distance?: number - edge?: 'start' | 'end' - unit?: 'offset' | 'character' | 'word' | 'line' | 'block' - } = {} - ): Point | undefined { - at = this.getPoint(at, options) - const { distance = 1 } = options - let d = 0 - let target - - for (const p of this.positions({ ...options, at, reverse: true })) { - if (d > distance) { - break - } + getPrevious(this: Editor, at: Location, match: Match): NodeEntry | undefined { + const point = this.getBefore(at) - if (d !== 0) { - target = p - } - - d++ + if (!point) { + return } - return target + return this.getMatch(point, match) } /** @@ -343,7 +371,7 @@ class LocationQueries { let text = '' for (const [node] of this.texts({ at: range })) { - text += node.text.length + text += node.text } return text diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 02b6317702..907725c0a8 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -135,7 +135,13 @@ class ValueQueries { // PERF: If the target is a path, don't traverse. if (Path.isPath(at)) { - return this.getMatch(at, match) + const m = this.getMatch(at, match) + + if (m) { + yield m + } + + return } at = this.getRange(at, { hanging }) From 644be4a0c366f99f84fa3af0d58bdfd973825a1e Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 28 Oct 2019 15:20:31 -0400 Subject: [PATCH 076/165] add more queries tests --- packages/slate/src/classes/commands/node.ts | 2 - packages/slate/src/classes/queries/element.ts | 13 +- .../slate/src/classes/queries/location.ts | 138 +++++---------- packages/slate/src/classes/queries/value.ts | 77 ++++----- packages/slate/src/interfaces/location.ts | 1 - packages/slate/src/interfaces/node.ts | 161 ++++++++++++++---- packages/slate/src/interfaces/value.ts | 12 +- .../test/interfaces/Node/descendants/path.js | 2 +- .../point.js} | 17 +- .../test/interfaces/Node/descendants/range.js | 3 +- .../Node/entries/path-multiple-elements.js | 54 ------ .../Node/entries/path-of-element.js | 55 ------ .../test/interfaces/Node/entries/path.js | 11 +- .../slate/test/interfaces/Node/marks/path.js | 2 +- .../interfaces/Node/offset/across-elements.js | 23 --- .../test/interfaces/Node/offset/element.js | 23 --- .../slate/test/interfaces/Node/offset/end.js | 20 --- .../test/interfaces/Node/offset/middle.js | 20 --- .../test/interfaces/Node/offset/start.js | 20 --- .../interfaces/Node/texts/path-of-element.js | 28 --- .../slate/test/interfaces/Node/texts/path.js | 2 +- .../test/interfaces/Path/levels/success.js | 2 +- packages/slate/test/queries/blocks/at-path.js | 4 +- .../queries/getActiveMarks/inline-start.js | 1 - .../queries/getActiveMarks/selection-marks.js | 19 --- packages/slate/test/queries/getAfter/end.js | 16 ++ packages/slate/test/queries/getAfter/path.js | 16 ++ packages/slate/test/queries/getAfter/point.js | 15 ++ packages/slate/test/queries/getAfter/range.js | 19 +++ .../block.js => getAncestor/path.js} | 4 +- .../slate/test/queries/getAncestor/point.js | 15 ++ .../test/queries/getAncestor/range-text.js | 19 +++ .../slate/test/queries/getAncestor/range.js | 25 +++ packages/slate/test/queries/getBefore/path.js | 16 ++ .../slate/test/queries/getBefore/point.js | 15 ++ .../slate/test/queries/getBefore/range.js | 19 +++ .../slate/test/queries/getBefore/start.js | 16 ++ packages/slate/test/queries/getEdges/path.js | 15 ++ packages/slate/test/queries/getEdges/point.js | 15 ++ packages/slate/test/queries/getEdges/range.js | 18 ++ packages/slate/test/queries/getEnd/path.js | 15 ++ packages/slate/test/queries/getEnd/point.js | 15 ++ packages/slate/test/queries/getEnd/range.js | 18 ++ .../block}/block-nested.js | 2 +- .../block}/block.js | 2 +- .../block}/inline.js | 2 +- packages/slate/test/queries/getNext/block.js | 16 ++ packages/slate/test/queries/getNext/text.js | 16 ++ .../{rootInlines/block.js => getNode/path.js} | 4 +- packages/slate/test/queries/getNode/point.js | 15 ++ .../slate/test/queries/getNode/range-end.js | 22 +++ .../slate/test/queries/getNode/range-start.js | 22 +++ .../block-reverse.js => getNode/range.js} | 14 +- packages/slate/test/queries/getParent/path.js | 15 ++ .../slate/test/queries/getParent/point.js | 15 ++ .../slate/test/queries/getParent/range-end.js | 22 +++ .../test/queries/getParent/range-start.js | 22 +++ .../slate/test/queries/getParent/range.js | 19 +++ .../{leafInlines/block.js => getPath/path.js} | 4 +- packages/slate/test/queries/getPath/point.js | 15 ++ .../slate/test/queries/getPath/range-end.js | 22 +++ .../slate/test/queries/getPath/range-start.js | 22 +++ packages/slate/test/queries/getPath/range.js | 19 +++ .../slate/test/queries/getPoint/path-end.js | 15 ++ .../slate/test/queries/getPoint/path-start.js | 15 ++ packages/slate/test/queries/getPoint/path.js | 15 ++ packages/slate/test/queries/getPoint/point.js | 15 ++ .../slate/test/queries/getPoint/range-end.js | 22 +++ .../test/queries/getPoint/range-start.js | 22 +++ packages/slate/test/queries/getPoint/range.js | 19 +++ .../slate/test/queries/getPrevious/block.js | 16 ++ .../slate/test/queries/getPrevious/text.js | 16 ++ packages/slate/test/queries/getRange/path.js | 18 ++ packages/slate/test/queries/getRange/point.js | 18 ++ packages/slate/test/queries/getRange/range.js | 21 +++ packages/slate/test/queries/getStart/path.js | 15 ++ packages/slate/test/queries/getStart/point.js | 15 ++ packages/slate/test/queries/getStart/range.js | 18 ++ .../inline.js => isEdge/path-end.js} | 7 +- .../slate/test/queries/isEdge/path-middle.js | 18 ++ .../slate/test/queries/isEdge/path-start.js | 18 ++ .../atomic.js => isEmpty/block-blank.js} | 6 +- .../slate/test/queries/isEmpty/block-empty.js | 16 ++ .../slate/test/queries/isEmpty/block-full.js | 16 ++ .../slate/test/queries/isEmpty/block-void.js | 18 ++ .../test/queries/isEmpty/inline-blank.js | 22 +++ .../inline-empty.js} | 9 +- .../inline.js => isEmpty/inline-full.js} | 5 +- .../slate/test/queries/isEmpty/inline-void.js | 22 +++ packages/slate/test/queries/isEnd/path-end.js | 18 ++ .../non-atomic.js => isEnd/path-middle.js} | 6 +- .../slate/test/queries/isEnd/path-start.js | 18 ++ .../slate/test/queries/isStart/path-end.js | 18 ++ .../slate/test/queries/isStart/path-middle.js | 18 ++ .../slate/test/queries/isStart/path-start.js | 18 ++ .../test/queries/leafBlocks/block-void.js | 24 --- .../slate/test/queries/leafBlocks/inline.js | 24 --- .../test/queries/leafInlines/inline-nested.js | 19 --- .../block}/block-multiple.js | 4 +- .../block}/block-nested.js | 4 +- .../block}/block-reverse.js | 4 +- .../test/queries/matches/block/block-void.js | 17 ++ .../{leafBlocks => matches/block}/block.js | 4 +- .../{rootBlocks => matches/block}/inline.js | 4 +- .../depth/one.js} | 4 +- .../test/queries/matches/inline/block.js | 15 ++ .../inline}/inline-multiple.js | 7 +- .../inline}/inline-nested.js | 6 +- .../inline}/inline-reverse.js | 7 +- .../queries/matches/inline/inline-void.js | 21 +++ .../test/queries/matches/inline/inline.js | 21 +++ .../positions/all/block-multiple-reverse.js | 2 +- .../queries/positions/all/block-multiple.js | 2 +- .../queries/positions/all/block-nested.js | 2 +- .../queries/positions/all/block-reverse.js | 2 +- .../slate/test/queries/positions/all/block.js | 2 +- .../queries/positions/all/inline-multiple.js | 2 +- .../queries/positions/all/inline-nested.js | 2 +- .../queries/positions/all/inline-reverse.js | 2 +- .../test/queries/positions/all/inline.js | 2 +- .../positions/all/unit-block-reverse.js | 2 +- .../test/queries/positions/all/unit-block.js | 2 +- .../positions/all/unit-character-reverse.js | 2 +- .../queries/positions/all/unit-character.js | 2 +- .../positions/all/unit-line-reverse.js | 2 +- .../test/queries/positions/all/unit-line.js | 2 +- .../positions/all/unit-word-reverse.js | 2 +- .../test/queries/positions/all/unit-word.js | 2 +- .../queries/positions/path/block-nested.js | 27 +++ .../block-reverse.js} | 7 +- .../{point/block-edge.js => path/block.js} | 5 +- .../{point => path}/inline-nested.js | 11 +- .../queries/positions/path/inline-reverse.js | 22 +++ .../test/queries/positions/path/inline.js | 22 +++ .../queries/positions/point/block-nested.js | 27 --- .../queries/positions/point/block-reverse.js | 21 --- .../test/queries/positions/point/block.js | 19 --- .../queries/positions/point/inline-reverse.js | 31 ---- .../test/queries/positions/point/inline.js | 32 ---- .../positions/point/unit-block-reverse.js | 27 --- .../queries/positions/point/unit-block.js | 23 --- .../positions/point/unit-character-reverse.js | 34 ---- .../queries/positions/point/unit-character.js | 30 ---- .../positions/point/unit-line-reverse.js | 27 --- .../test/queries/positions/point/unit-line.js | 23 --- .../positions/point/unit-word-reverse.js | 31 ---- .../test/queries/positions/point/unit-word.js | 27 --- .../block-reverse.js} | 32 ++-- .../block.js} | 28 +-- .../inline-multiple.js => range/inline.js} | 13 +- .../test/queries/rootBlocks/block-nested.js | 33 ---- .../test/queries/rootBlocks/block-void.js | 24 --- .../queries/rootInlines/inline-multiple.js | 20 --- .../queries/rootInlines/inline-reverse.js | 20 --- .../test/queries/rootInlines/inline-void.js | 17 -- 155 files changed, 1546 insertions(+), 1110 deletions(-) rename packages/slate/test/interfaces/Node/{texts/path-multiple-elements.js => descendants/point.js} (63%) delete mode 100644 packages/slate/test/interfaces/Node/entries/path-multiple-elements.js delete mode 100644 packages/slate/test/interfaces/Node/entries/path-of-element.js delete mode 100644 packages/slate/test/interfaces/Node/offset/across-elements.js delete mode 100644 packages/slate/test/interfaces/Node/offset/element.js delete mode 100644 packages/slate/test/interfaces/Node/offset/end.js delete mode 100644 packages/slate/test/interfaces/Node/offset/middle.js delete mode 100644 packages/slate/test/interfaces/Node/offset/start.js delete mode 100644 packages/slate/test/interfaces/Node/texts/path-of-element.js delete mode 100644 packages/slate/test/queries/getActiveMarks/selection-marks.js create mode 100644 packages/slate/test/queries/getAfter/end.js create mode 100644 packages/slate/test/queries/getAfter/path.js create mode 100644 packages/slate/test/queries/getAfter/point.js create mode 100644 packages/slate/test/queries/getAfter/range.js rename packages/slate/test/queries/{rootBlocks/block.js => getAncestor/path.js} (62%) create mode 100644 packages/slate/test/queries/getAncestor/point.js create mode 100644 packages/slate/test/queries/getAncestor/range-text.js create mode 100644 packages/slate/test/queries/getAncestor/range.js create mode 100644 packages/slate/test/queries/getBefore/path.js create mode 100644 packages/slate/test/queries/getBefore/point.js create mode 100644 packages/slate/test/queries/getBefore/range.js create mode 100644 packages/slate/test/queries/getBefore/start.js create mode 100644 packages/slate/test/queries/getEdges/path.js create mode 100644 packages/slate/test/queries/getEdges/point.js create mode 100644 packages/slate/test/queries/getEdges/range.js create mode 100644 packages/slate/test/queries/getEnd/path.js create mode 100644 packages/slate/test/queries/getEnd/point.js create mode 100644 packages/slate/test/queries/getEnd/range.js rename packages/slate/test/queries/{getClosestBlock => getMatch/block}/block-nested.js (86%) rename packages/slate/test/queries/{getClosestBlock => getMatch/block}/block.js (85%) rename packages/slate/test/queries/{getClosestBlock => getMatch/block}/inline.js (88%) create mode 100644 packages/slate/test/queries/getNext/block.js create mode 100644 packages/slate/test/queries/getNext/text.js rename packages/slate/test/queries/{rootInlines/block.js => getNode/path.js} (66%) create mode 100644 packages/slate/test/queries/getNode/point.js create mode 100644 packages/slate/test/queries/getNode/range-end.js create mode 100644 packages/slate/test/queries/getNode/range-start.js rename packages/slate/test/queries/{rootBlocks/block-reverse.js => getNode/range.js} (52%) create mode 100644 packages/slate/test/queries/getParent/path.js create mode 100644 packages/slate/test/queries/getParent/point.js create mode 100644 packages/slate/test/queries/getParent/range-end.js create mode 100644 packages/slate/test/queries/getParent/range-start.js create mode 100644 packages/slate/test/queries/getParent/range.js rename packages/slate/test/queries/{leafInlines/block.js => getPath/path.js} (69%) create mode 100644 packages/slate/test/queries/getPath/point.js create mode 100644 packages/slate/test/queries/getPath/range-end.js create mode 100644 packages/slate/test/queries/getPath/range-start.js create mode 100644 packages/slate/test/queries/getPath/range.js create mode 100644 packages/slate/test/queries/getPoint/path-end.js create mode 100644 packages/slate/test/queries/getPoint/path-start.js create mode 100644 packages/slate/test/queries/getPoint/path.js create mode 100644 packages/slate/test/queries/getPoint/point.js create mode 100644 packages/slate/test/queries/getPoint/range-end.js create mode 100644 packages/slate/test/queries/getPoint/range-start.js create mode 100644 packages/slate/test/queries/getPoint/range.js create mode 100644 packages/slate/test/queries/getPrevious/block.js create mode 100644 packages/slate/test/queries/getPrevious/text.js create mode 100644 packages/slate/test/queries/getRange/path.js create mode 100644 packages/slate/test/queries/getRange/point.js create mode 100644 packages/slate/test/queries/getRange/range.js create mode 100644 packages/slate/test/queries/getStart/path.js create mode 100644 packages/slate/test/queries/getStart/point.js create mode 100644 packages/slate/test/queries/getStart/range.js rename packages/slate/test/queries/{leafInlines/inline.js => isEdge/path-end.js} (54%) create mode 100644 packages/slate/test/queries/isEdge/path-middle.js create mode 100644 packages/slate/test/queries/isEdge/path-start.js rename packages/slate/test/queries/{isAtomic/atomic.js => isEmpty/block-blank.js} (65%) create mode 100644 packages/slate/test/queries/isEmpty/block-empty.js create mode 100644 packages/slate/test/queries/isEmpty/block-full.js create mode 100644 packages/slate/test/queries/isEmpty/block-void.js create mode 100644 packages/slate/test/queries/isEmpty/inline-blank.js rename packages/slate/test/queries/{leafInlines/inline-void.js => isEmpty/inline-empty.js} (51%) rename packages/slate/test/queries/{rootInlines/inline.js => isEmpty/inline-full.js} (63%) create mode 100644 packages/slate/test/queries/isEmpty/inline-void.js create mode 100644 packages/slate/test/queries/isEnd/path-end.js rename packages/slate/test/queries/{isAtomic/non-atomic.js => isEnd/path-middle.js} (65%) create mode 100644 packages/slate/test/queries/isEnd/path-start.js create mode 100644 packages/slate/test/queries/isStart/path-end.js create mode 100644 packages/slate/test/queries/isStart/path-middle.js create mode 100644 packages/slate/test/queries/isStart/path-start.js delete mode 100644 packages/slate/test/queries/leafBlocks/block-void.js delete mode 100644 packages/slate/test/queries/leafBlocks/inline.js delete mode 100644 packages/slate/test/queries/leafInlines/inline-nested.js rename packages/slate/test/queries/{rootBlocks => matches/block}/block-multiple.js (75%) rename packages/slate/test/queries/{leafBlocks => matches/block}/block-nested.js (75%) rename packages/slate/test/queries/{leafBlocks => matches/block}/block-reverse.js (72%) create mode 100644 packages/slate/test/queries/matches/block/block-void.js rename packages/slate/test/queries/{leafBlocks => matches/block}/block.js (64%) rename packages/slate/test/queries/{rootBlocks => matches/block}/inline.js (73%) rename packages/slate/test/queries/{leafBlocks/block-multiple.js => matches/depth/one.js} (76%) create mode 100644 packages/slate/test/queries/matches/inline/block.js rename packages/slate/test/queries/{leafInlines => matches/inline}/inline-multiple.js (59%) rename packages/slate/test/queries/{rootInlines => matches/inline}/inline-nested.js (66%) rename packages/slate/test/queries/{leafInlines => matches/inline}/inline-reverse.js (57%) create mode 100644 packages/slate/test/queries/matches/inline/inline-void.js create mode 100644 packages/slate/test/queries/matches/inline/inline.js create mode 100644 packages/slate/test/queries/positions/path/block-nested.js rename packages/slate/test/queries/positions/{point/block-edge-reverse.js => path/block-reverse.js} (63%) rename packages/slate/test/queries/positions/{point/block-edge.js => path/block.js} (66%) rename packages/slate/test/queries/positions/{point => path}/inline-nested.js (69%) create mode 100644 packages/slate/test/queries/positions/path/inline-reverse.js create mode 100644 packages/slate/test/queries/positions/path/inline.js delete mode 100644 packages/slate/test/queries/positions/point/block-nested.js delete mode 100644 packages/slate/test/queries/positions/point/block-reverse.js delete mode 100644 packages/slate/test/queries/positions/point/block.js delete mode 100644 packages/slate/test/queries/positions/point/inline-reverse.js delete mode 100644 packages/slate/test/queries/positions/point/inline.js delete mode 100644 packages/slate/test/queries/positions/point/unit-block-reverse.js delete mode 100644 packages/slate/test/queries/positions/point/unit-block.js delete mode 100644 packages/slate/test/queries/positions/point/unit-character-reverse.js delete mode 100644 packages/slate/test/queries/positions/point/unit-character.js delete mode 100644 packages/slate/test/queries/positions/point/unit-line-reverse.js delete mode 100644 packages/slate/test/queries/positions/point/unit-line.js delete mode 100644 packages/slate/test/queries/positions/point/unit-word-reverse.js delete mode 100644 packages/slate/test/queries/positions/point/unit-word.js rename packages/slate/test/queries/positions/{point/block-multiple.js => range/block-reverse.js} (65%) rename packages/slate/test/queries/positions/{point/block-multiple-reverse.js => range/block.js} (74%) rename packages/slate/test/queries/positions/{point/inline-multiple.js => range/inline.js} (80%) delete mode 100644 packages/slate/test/queries/rootBlocks/block-nested.js delete mode 100644 packages/slate/test/queries/rootBlocks/block-void.js delete mode 100644 packages/slate/test/queries/rootInlines/inline-multiple.js delete mode 100644 packages/slate/test/queries/rootInlines/inline-reverse.js delete mode 100644 packages/slate/test/queries/rootInlines/inline-void.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index f004dabf94..2ed744aec4 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -390,9 +390,7 @@ class NodeCommands { // Merge adjacent text nodes that are empty or have matching marks. if (prev != null && Text.isText(prev)) { if (Text.matches(child, prev)) { - debugger this.mergeNodes({ at: at.concat(n) }) - debugger n-- continue } else if (prev.text === '') { diff --git a/packages/slate/src/classes/queries/element.ts b/packages/slate/src/classes/queries/element.ts index 2c08a3efe2..0b77336e37 100644 --- a/packages/slate/src/classes/queries/element.ts +++ b/packages/slate/src/classes/queries/element.ts @@ -6,7 +6,7 @@ class ElementQueries { */ hasBlocks(this: Editor, element: Element): boolean { - return element.nodes.every(n => Element.isElement(n) && !this.isInline(n)) + return element.nodes.some(n => Element.isElement(n) && !this.isInline(n)) } /** @@ -14,7 +14,7 @@ class ElementQueries { */ hasInlines(this: Editor, element: Element): boolean { - return element.nodes.every( + return element.nodes.some( n => Text.isText(n) || (Element.isElement(n) && this.isInline(n)) ) } @@ -35,10 +35,11 @@ class ElementQueries { const { nodes } = element const [first] = nodes return ( - nodes.length === 1 && - Text.isText(first) && - first.text === '' && - !this.isVoid(element) + nodes.length === 0 || + (nodes.length === 1 && + Text.isText(first) && + first.text === '' && + !this.isVoid(element)) ) } diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 6bef9ded85..2f71ee9ad3 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -25,12 +25,14 @@ class LocationQueries { unit?: 'offset' | 'character' | 'word' | 'line' | 'block' } = {} ): Point | undefined { - at = this.getPoint(at, { edge: 'end' }) + const anchor = this.getPoint(at, { edge: 'end' }) + const focus = this.getEnd() + const range = { anchor, focus } const { distance = 1 } = options let d = 0 let target - for (const p of this.positions({ ...options, at })) { + for (const p of this.positions({ ...options, at: range })) { if (d > distance) { break } @@ -62,7 +64,10 @@ class LocationQueries { } const path = this.getPath(at, options) - const ancestorPath = Range.isCollapsed(at) ? Path.parent(path) : path + const ancestorPath = Path.equals(at.anchor.path, at.focus.path) + ? Path.parent(path) + : path + const ancestor = Node.get(this.value, ancestorPath) as Ancestor return [ancestor, ancestorPath] } @@ -79,14 +84,14 @@ class LocationQueries { unit?: 'offset' | 'character' | 'word' | 'line' | 'block' } = {} ): Point | undefined { - debugger - at = this.getPoint(at, { edge: 'start' }) - debugger + const focus = this.getPoint(at, { edge: 'start' }) + const anchor = this.getStart() + const range = { anchor, focus } const { distance = 1 } = options let d = 0 let target - for (const p of this.positions({ ...options, at, reverse: true })) { + for (const p of this.positions({ ...options, at: range, reverse: true })) { if (d > distance) { break } @@ -187,7 +192,7 @@ class LocationQueries { } /** - * Get the path from a location, at a specific depth. + * Get the path of a location. */ getPath( @@ -198,36 +203,8 @@ class LocationQueries { edge?: 'start' | 'end' } = {} ): Path { - const { edge, depth } = options - - if (Range.isRange(at)) { - if (edge != null) { - const point = this.getPoint(at, options) - at = point.path - } else { - const { anchor, focus } = at - const common = Path.common(anchor.path, focus.path) - return common - } - } - - if (Point.isPoint(at)) { - at = at.path - - if (depth != null) { - if (depth > at.length) { - throw new Error( - `Cannot get a path for point ${JSON.stringify( - at - )} at depth \`${depth}\` because it is not that deep.` - ) - } - - at = at.slice(0, depth) - } - } - - return at + const path = Node.path(this.value, at, options) + return path } /** @@ -241,43 +218,8 @@ class LocationQueries { edge?: 'start' | 'end' } = {} ): Point { - const { edge } = options - - if (Path.isPath(at)) { - if (edge === 'end') { - const [lastNode, lastPath] = Node.last(this.value, at) - - if (!Text.isText(lastNode)) { - throw new Error( - `Cannot get the end point of the node at path [${at}] because it has no ending text node.` - ) - } - - return { path: lastPath, offset: lastNode.text.length } - } else { - const [firstNode, firstPath] = Node.first(this.value, at) - - if (!Text.isText(firstNode)) { - throw new Error( - `Cannot get the start point of the node at path [${at}] because it has no starting text node.` - ) - } - - return { path: firstPath, offset: 0 } - } - } - - if (Range.isRange(at)) { - switch (edge) { - default: - case 'start': - return Range.start(at) - case 'end': - return Range.end(at) - } - } - - return at + const point = Node.point(this.value, at, options) + return point } /** @@ -307,35 +249,27 @@ class LocationQueries { } = {} ): Range { const { to, hanging = false } = options - - if (Point.isPoint(at)) { - const end = to ? this.getEnd(to) : at - at = { anchor: at, focus: end } - } - - if (Path.isPath(at)) { - const start = this.getStart(at) - const end = this.getEnd(to || at) - at = { anchor: start, focus: end } - } + const range = Node.range(this.value, at, to) // PERF: exit early if we can guarantee that the range isn't hanging, or // that they don't mind receiving hanging ranges. if ( hanging || - at.anchor.offset !== 0 || - at.focus.offset !== 0 || - Range.isCollapsed(at) + range.anchor.offset !== 0 || + range.focus.offset !== 0 || + Range.isCollapsed(range) ) { - return at + return range } - let [start, end] = Range.edges(at) + let [start, end] = Range.edges(range) const closestBlock = this.getMatch(end.path, 'block') const blockPath = closestBlock ? closestBlock[1] : [] + const last = this.getEnd() + const rest = { anchor: end, focus: last } let skip = true - for (const [node, path] of this.texts({ from: end.path, reverse: true })) { + for (const [node, path] of this.texts({ at: rest, reverse: true })) { if (skip) { skip = false continue @@ -343,12 +277,11 @@ class LocationQueries { if (node.text !== '' || Path.isBefore(path, blockPath)) { const point = { path, offset: node.text.length } - at = { anchor: start, focus: point } - break + return { anchor: start, focus: point } } } - return at + return range } /** @@ -368,10 +301,21 @@ class LocationQueries { getText(this: Editor, at: Location = []): string { const range = this.getRange(at) + const [start, end] = Range.edges(range) let text = '' - for (const [node] of this.texts({ at: range })) { - text += node.text + for (const [node, path] of this.texts({ at: range })) { + let t = node.text + + if (Path.equals(path, end.path)) { + t = t.slice(0, end.offset) + } + + if (Path.equals(path, start.path)) { + t = t.slice(start.offset) + } + + text += t } return text diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index 907725c0a8..f43ac7c456 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -58,7 +58,6 @@ class ValueQueries { this: Editor, options: { at?: Location - from?: Path reverse?: boolean } = {} ): Iterable { @@ -166,7 +165,6 @@ class ValueQueries { this: Editor, options: { at?: Location - from?: Path reverse?: boolean } = {} ): Iterable { @@ -184,7 +182,6 @@ class ValueQueries { this: Editor, options: { at?: Location - from?: Path reverse?: boolean } = {} ): Iterable { @@ -226,12 +223,16 @@ class ValueQueries { // If the range is collapsed at the start of a text node, it should carry // over the marks from the previous text node in the same block. - if (Range.isCollapsed(at) && this.isStart(at.anchor, at.anchor.path)) { - const prevPath = Path.previous(at.anchor.path) - const [prevNode] = this.getNode(prevPath) + if (Range.isCollapsed(at) && at.anchor.offset === 0) { + const { anchor } = at + const prev = this.getPrevious(anchor, 'text') - if (Text.isText(prevNode)) { - at = this.getRange(prevPath) + if (prev && Path.isSibling(anchor.path, prev[1])) { + const [prevNode, prevPath] = prev + + if (Text.isText(prevNode)) { + at = this.getRange(prevPath) + } } } @@ -280,7 +281,6 @@ class ValueQueries { this: Editor, options: { at?: Location - from?: Path reverse?: boolean } = {} ): Iterable { @@ -299,7 +299,6 @@ class ValueQueries { this: Editor, options: { at?: Location - from?: Path reverse?: boolean } = {} ): Iterable { @@ -324,26 +323,20 @@ class ValueQueries { *positions( this: Editor, options: { - at?: Point + at?: Location unit?: 'offset' | 'character' | 'word' | 'line' | 'block' reverse?: boolean } = {} ): Iterable { - const { - unit = 'offset', - reverse = false, - at = reverse ? this.getEnd() : this.getStart(), - } = options - - if (!at) { - return - } - + const { at = [], unit = 'offset', reverse = false } = options + const range = this.getRange(at) + const [start, end] = Range.edges(range) + const first = reverse ? end : start let string = '' let available = 0 let offset = 0 let distance: number | null = null - let isBlockStart = true + let isNewBlock = false const advance = () => { if (distance == null) { @@ -378,40 +371,33 @@ class ValueQueries { continue } - if (!this.isInline(node) && this.hasInlines(node)) { - let text = this.getText(path) - - if (Path.isAncestor(path, at.path)) { - let before = 0 - - for (const [n, p] of this.texts({ from: path })) { - if (Path.equals(p, at.path)) { - break - } - - before += n.text.length - } + if (this.isInline(node)) { + continue + } - const o = before + at.offset - text = reverse ? text.slice(0, o) : text.slice(o) - } + if (this.hasInlines(node)) { + let e = Path.isAncestor(path, end.path) ? end : this.getEnd(path) + let s = Path.isAncestor(path, start.path) + ? start + : this.getStart(path) + const text = this.getText({ anchor: s, focus: e }) string = reverse ? reverseText(text) : text - isBlockStart = true + isNewBlock = true } } if (Text.isText(node)) { - const isStart = Path.equals(path, at.path) + const isFirst = Path.equals(path, first.path) available = node.text.length offset = reverse ? available : 0 - if (isStart) { - available = reverse ? at.offset : available - at.offset - offset = at.offset + if (isFirst) { + available = reverse ? first.offset : available - first.offset + offset = first.offset } - if (isStart || isBlockStart || unit === 'offset') { + if (isFirst || isNewBlock || unit === 'offset') { yield { path, offset } } @@ -432,7 +418,7 @@ class ValueQueries { } } - isBlockStart = false + isNewBlock = false } } } @@ -445,7 +431,6 @@ class ValueQueries { this: Editor, options: { at?: Location - from?: Path reverse?: boolean } = {} ): Iterable { diff --git a/packages/slate/src/interfaces/location.ts b/packages/slate/src/interfaces/location.ts index bd31754838..45fd2eba44 100755 --- a/packages/slate/src/interfaces/location.ts +++ b/packages/slate/src/interfaces/location.ts @@ -1,4 +1,3 @@ -import isPlainObject from 'is-plain-object' import { Path, Point, Range } from '..' /** diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index ae25011409..ca90611c84 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -3,6 +3,7 @@ import { Element, ElementEntry, Fragment, + Location, MarkEntry, Path, Range, @@ -176,8 +177,7 @@ namespace Node { export function* descendants( root: Node, options: { - at?: Range | Point | Path - from?: Path + at?: Location reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -200,8 +200,7 @@ namespace Node { export function* elements( root: Node, options: { - at?: Range | Point | Path - from?: Path + at?: Location reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -213,6 +212,15 @@ namespace Node { } } + /** + * Get the end point of a location inside the root node. + */ + + export const end = (root: Node, at: Location): Point => { + const end = Node.point(root, at, { edge: 'end' }) + return end + } + /** * Return an iterable of all the node entries of a root node. Each entry is * returned as a `[Node, Path]` tuple, with the path referring to the node's @@ -222,40 +230,25 @@ namespace Node { export function* entries( root: Node, options: { - at?: Range | Point | Path - from?: Path + at?: Location reverse?: boolean pass?: (entry: NodeEntry) => boolean } = {} ): Iterable { - const { at, from, pass, reverse = false } = options - let [, fromPath] = reverse ? Node.last(root, []) : Node.first(root, []) - let toPath - - if (Range.isRange(at)) { - const [s, e] = Range.edges(at) - fromPath = reverse ? e.path : s.path - toPath = reverse ? s.path : e.path - } else if (Point.isPoint(at)) { - fromPath = toPath = at.path - } else if (Path.isPath(at)) { - const [, f] = Node.first(root, at) - const [, l] = Node.last(root, at) - fromPath = reverse ? l : f - toPath = reverse ? f : l - } - - if (Path.isPath(from)) { - const [, f] = reverse ? Node.last(root, from) : Node.first(root, from) - fromPath = f - } - + const { at = [], pass, reverse = false } = options + const startPath = Node.path(root, at, { edge: 'start' }) + const endPath = Node.path(root, at, { edge: 'end' }) + const fromPath = reverse ? endPath : startPath + const toPath = reverse ? startPath : endPath const visited = new Set() let p: Path = [] let n = root while (true) { - if (toPath != null && Path.isAfter(p, toPath)) { + if ( + (!reverse && Path.isAfter(p, toPath)) || + (reverse && Path.isBefore(p, toPath)) + ) { break } @@ -512,8 +505,7 @@ namespace Node { export function* marks( root: Node, options: { - at?: Range | Point | Path - from?: Path + at?: Location reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -543,6 +535,110 @@ namespace Node { return parent } + /** + * Get the path of a location inside the root node. + */ + + export const path = ( + root: Node, + at: Location, + options: { + depth?: number + edge?: 'start' | 'end' + } + ): Path => { + const { depth, edge } = options + + if (Path.isPath(at)) { + if (edge === 'start') { + const [, firstPath] = Node.first(root, at) + at = firstPath + } else if (edge === 'end') { + const [, lastPath] = Node.last(root, at) + at = lastPath + } + } + + if (Range.isRange(at)) { + if (edge === 'start') { + at = Range.start(at) + } else if (edge === 'end') { + at = Range.end(at) + } else { + at = Path.common(at.anchor.path, at.focus.path) + } + } + + if (Point.isPoint(at)) { + at = at.path + } + + if (depth != null) { + at = at.slice(0, depth) + } + + return at + } + + /** + * Get the start of end point of a location inside the root node. + */ + + export const point = ( + root: Node, + at: Location, + options: { + edge?: 'start' | 'end' + } + ): Point => { + const { edge = 'start' } = options + + if (Path.isPath(at)) { + debugger + const path = Node.path(root, at, { edge }) + const node = Node.get(root, path) + + if (!Text.isText(node)) { + debugger + throw new Error( + `Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.` + ) + } + + return { path, offset: edge === 'start' ? 0 : node.text.length } + } + + if (Range.isRange(at)) { + const [start, end] = Range.edges(at) + return edge === 'start' ? start : end + } + + return at + } + + /** + * Get the range from one location to another inside the root node. + */ + + export const range = ( + root: Node, + from: Location, + to: Location = from + ): Range => { + const anchor = Node.start(root, from) + const focus = Node.end(root, to) + return { anchor, focus } + } + + /** + * Get the start point of a location inside the root node. + */ + + export const start = (root: Node, at: Location): Point => { + const start = Node.point(root, at, { edge: 'start' }) + return start + } + /** * Get the concatenated text string of a node's content. * @@ -566,8 +662,7 @@ namespace Node { export function* texts( root: Node, options: { - at?: Range | Point | Path - from?: Path + at?: Location reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index ed16a847e5..d2ebe75398 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -243,10 +243,14 @@ namespace Value { const { path } = op const index = path[path.length - 1] const parent = Node.parent(v, path) - const [, first] = Node.first(v, path) - const [, last] = Node.last(v, path) - const [, prev] = Node.texts(v, { from: first, reverse: true }) - const [, next] = Node.texts(v, { from: last }) + const rootStart = Node.start(v, []) + const rootEnd = Node.end(v, []) + const nodeStart = Node.start(v, path) + const nodeEnd = Node.end(v, path) + const before = { anchor: rootStart, focus: nodeStart } + const after = { anchor: nodeEnd, focus: rootEnd } + const [, prev] = Node.texts(v, { at: before, reverse: true }) + const [, next] = Node.texts(v, { at: after }) parent.nodes.splice(index, 1) // Transform all of the points in the value, but if the point was in the diff --git a/packages/slate/test/interfaces/Node/descendants/path.js b/packages/slate/test/interfaces/Node/descendants/path.js index 49d4cac85a..1f052a774d 100644 --- a/packages/slate/test/interfaces/Node/descendants/path.js +++ b/packages/slate/test/interfaces/Node/descendants/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.descendants(value, { from: [0, 1] })) + return Array.from(Node.descendants(value, { at: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js b/packages/slate/test/interfaces/Node/descendants/point.js similarity index 63% rename from packages/slate/test/interfaces/Node/texts/path-multiple-elements.js rename to packages/slate/test/interfaces/Node/descendants/point.js index 59d80af6db..829561c765 100644 --- a/packages/slate/test/interfaces/Node/texts/path-multiple-elements.js +++ b/packages/slate/test/interfaces/Node/descendants/point.js @@ -9,19 +9,22 @@ export const input = ( - - - - ) export const test = value => { - return Array.from(Node.texts(value, { from: [0, 1] })) + return Array.from( + Node.descendants(value, { at: { path: [0, 1], offset: 0 } }) + ) } export const output = [ + [ + + + + , + [0], + ], [, [0, 1]], - [, [1, 0]], - [, [1, 1]], ] diff --git a/packages/slate/test/interfaces/Node/descendants/range.js b/packages/slate/test/interfaces/Node/descendants/range.js index eb7568dd6f..9e18bd5469 100644 --- a/packages/slate/test/interfaces/Node/descendants/range.js +++ b/packages/slate/test/interfaces/Node/descendants/range.js @@ -23,7 +23,7 @@ export const test = value => { offset: 0, }, focus: { - path: [0, 2], + path: [0, 1], offset: 0, }, }, @@ -42,5 +42,4 @@ export const output = [ [0], ], [, [0, 1]], - [, [0, 2]], ] diff --git a/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js b/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js deleted file mode 100644 index df5af942ff..0000000000 --- a/packages/slate/test/interfaces/Node/entries/path-multiple-elements.js +++ /dev/null @@ -1,54 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - - - - - - - - -) - -export const test = value => { - return Array.from(Node.entries(value, { from: [0, 1] })) -} - -export const output = [ - [ - - - - - - - - - - , - [], - ], - [ - - - - , - [0], - ], - [, [0, 1]], - [ - - - - , - [1], - ], - [, [1, 0]], - [, [1, 1]], -] diff --git a/packages/slate/test/interfaces/Node/entries/path-of-element.js b/packages/slate/test/interfaces/Node/entries/path-of-element.js deleted file mode 100644 index 4389a2d65e..0000000000 --- a/packages/slate/test/interfaces/Node/entries/path-of-element.js +++ /dev/null @@ -1,55 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - - - - - - - - -) - -export const test = value => { - return Array.from(Node.entries(value, { from: [0] })) -} - -export const output = [ - [ - - - - - - - - - - , - [], - ], - [ - - - - , - [0], - ], - [, [0, 0]], - [, [0, 1]], - [ - - - - , - [1], - ], - [, [1, 0]], - [, [1, 1]], -] diff --git a/packages/slate/test/interfaces/Node/entries/path.js b/packages/slate/test/interfaces/Node/entries/path.js index 1a9b3a5229..860b099143 100644 --- a/packages/slate/test/interfaces/Node/entries/path.js +++ b/packages/slate/test/interfaces/Node/entries/path.js @@ -9,11 +9,15 @@ export const input = ( + + + + ) export const test = value => { - return Array.from(Node.entries(value, { from: [0, 1] })) + return Array.from(Node.entries(value, { at: [0] })) } export const output = [ @@ -23,6 +27,10 @@ export const output = [ + + + + , [], ], @@ -33,5 +41,6 @@ export const output = [ , [0], ], + [, [0, 0]], [, [0, 1]], ] diff --git a/packages/slate/test/interfaces/Node/marks/path.js b/packages/slate/test/interfaces/Node/marks/path.js index b982533e1d..2f8181f33c 100644 --- a/packages/slate/test/interfaces/Node/marks/path.js +++ b/packages/slate/test/interfaces/Node/marks/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.marks(value, { from: [0, 1] })) + return Array.from(Node.marks(value, { at: [0, 1] })) } export const output = [[{ key: 'b' }, 0, two, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/offset/across-elements.js b/packages/slate/test/interfaces/Node/offset/across-elements.js deleted file mode 100644 index 0973bbe212..0000000000 --- a/packages/slate/test/interfaces/Node/offset/across-elements.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - one - two - - - three - four - - -) - -export const test = value => { - return Node.offset(value, [1, 1]) -} - -export const output = 11 diff --git a/packages/slate/test/interfaces/Node/offset/element.js b/packages/slate/test/interfaces/Node/offset/element.js deleted file mode 100644 index 206405afed..0000000000 --- a/packages/slate/test/interfaces/Node/offset/element.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - one - two - - - three - four - - -) - -export const test = value => { - return Node.offset(value, [1]) -} - -export const output = 6 diff --git a/packages/slate/test/interfaces/Node/offset/end.js b/packages/slate/test/interfaces/Node/offset/end.js deleted file mode 100644 index 53e58374a9..0000000000 --- a/packages/slate/test/interfaces/Node/offset/end.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - one - two - three - - -) - -export const test = value => { - return Node.offset(value, [0, 2]) -} - -export const output = 6 diff --git a/packages/slate/test/interfaces/Node/offset/middle.js b/packages/slate/test/interfaces/Node/offset/middle.js deleted file mode 100644 index 7d5a3170cb..0000000000 --- a/packages/slate/test/interfaces/Node/offset/middle.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - one - two - three - - -) - -export const test = value => { - return Node.offset(value, [0, 1]) -} - -export const output = 3 diff --git a/packages/slate/test/interfaces/Node/offset/start.js b/packages/slate/test/interfaces/Node/offset/start.js deleted file mode 100644 index 55b7b0c885..0000000000 --- a/packages/slate/test/interfaces/Node/offset/start.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - one - two - three - - -) - -export const test = value => { - return Node.offset(value, [0, 0]) -} - -export const output = 0 diff --git a/packages/slate/test/interfaces/Node/texts/path-of-element.js b/packages/slate/test/interfaces/Node/texts/path-of-element.js deleted file mode 100644 index bb0e7326f2..0000000000 --- a/packages/slate/test/interfaces/Node/texts/path-of-element.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - - - - - - - - -) - -export const test = value => { - return Array.from(Node.texts(value, { from: [0] })) -} - -export const output = [ - [, [0, 0]], - [, [0, 1]], - [, [1, 0]], - [, [1, 1]], -] diff --git a/packages/slate/test/interfaces/Node/texts/path.js b/packages/slate/test/interfaces/Node/texts/path.js index 30b8963c4d..af835df35b 100644 --- a/packages/slate/test/interfaces/Node/texts/path.js +++ b/packages/slate/test/interfaces/Node/texts/path.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { from: [0, 1] })) + return Array.from(Node.texts(value, { at: [0, 1] })) } export const output = [[, [0, 1]]] diff --git a/packages/slate/test/interfaces/Path/levels/success.js b/packages/slate/test/interfaces/Path/levels/success.js index 70b3084363..561ed6a1c2 100644 --- a/packages/slate/test/interfaces/Path/levels/success.js +++ b/packages/slate/test/interfaces/Path/levels/success.js @@ -6,4 +6,4 @@ export const test = path => { return Path.levels(path) } -export const output = [[][0], [0, 1], [0, 1, 2]] +export const output = [[], [0], [0, 1], [0, 1, 2]] diff --git a/packages/slate/test/queries/blocks/at-path.js b/packages/slate/test/queries/blocks/at-path.js index dde098baf5..7a87a5ba43 100644 --- a/packages/slate/test/queries/blocks/at-path.js +++ b/packages/slate/test/queries/blocks/at-path.js @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.blocks({ from: [1] })) + return Array.from(editor.blocks({ at: [1] })) } -export const output = [[two, [1]], [three, [2]]] +export const output = [[two, [1]]] diff --git a/packages/slate/test/queries/getActiveMarks/inline-start.js b/packages/slate/test/queries/getActiveMarks/inline-start.js index 67164d1db6..9b29c7d409 100644 --- a/packages/slate/test/queries/getActiveMarks/inline-start.js +++ b/packages/slate/test/queries/getActiveMarks/inline-start.js @@ -11,7 +11,6 @@ export const input = ( three - ) diff --git a/packages/slate/test/queries/getActiveMarks/selection-marks.js b/packages/slate/test/queries/getActiveMarks/selection-marks.js deleted file mode 100644 index a32c0d86ea..0000000000 --- a/packages/slate/test/queries/getActiveMarks/selection-marks.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - - one - - - -) - -export const run = editor => { - return Array.from(editor.getActiveMarks()) -} - -export const output = [{ key: 'b' }] diff --git a/packages/slate/test/queries/getAfter/end.js b/packages/slate/test/queries/getAfter/end.js new file mode 100644 index 0000000000..8d9f5f34e9 --- /dev/null +++ b/packages/slate/test/queries/getAfter/end.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getAfter([1, 0]) +} + +export const output = undefined diff --git a/packages/slate/test/queries/getAfter/path.js b/packages/slate/test/queries/getAfter/path.js new file mode 100644 index 0000000000..e33397588a --- /dev/null +++ b/packages/slate/test/queries/getAfter/path.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getAfter([0, 0]) +} + +export const output = { path: [1, 0], offset: 0 } diff --git a/packages/slate/test/queries/getAfter/point.js b/packages/slate/test/queries/getAfter/point.js new file mode 100644 index 0000000000..6fa91e2d73 --- /dev/null +++ b/packages/slate/test/queries/getAfter/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getAfter({ path: [0, 0], offset: 1 }) +} + +export const output = { path: [0, 0], offset: 2 } diff --git a/packages/slate/test/queries/getAfter/range.js b/packages/slate/test/queries/getAfter/range.js new file mode 100644 index 0000000000..6e3c4d85fe --- /dev/null +++ b/packages/slate/test/queries/getAfter/range.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getAfter({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }) +} + +export const output = { path: [1, 0], offset: 3 } diff --git a/packages/slate/test/queries/rootBlocks/block.js b/packages/slate/test/queries/getAncestor/path.js similarity index 62% rename from packages/slate/test/queries/rootBlocks/block.js rename to packages/slate/test/queries/getAncestor/path.js index aef754d0ba..99782eccc1 100644 --- a/packages/slate/test/queries/rootBlocks/block.js +++ b/packages/slate/test/queries/getAncestor/path.js @@ -9,7 +9,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.rootBlocks()) + return editor.getAncestor([0, 0]) } -export const output = [[one, [0]]] +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getAncestor/point.js b/packages/slate/test/queries/getAncestor/point.js new file mode 100644 index 0000000000..4a04120a8f --- /dev/null +++ b/packages/slate/test/queries/getAncestor/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getAncestor({ path: [0, 0], offset: 1 }) +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getAncestor/range-text.js b/packages/slate/test/queries/getAncestor/range-text.js new file mode 100644 index 0000000000..85982b908f --- /dev/null +++ b/packages/slate/test/queries/getAncestor/range-text.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getAncestor({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 2 }, + }) +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getAncestor/range.js b/packages/slate/test/queries/getAncestor/range.js new file mode 100644 index 0000000000..c71593413a --- /dev/null +++ b/packages/slate/test/queries/getAncestor/range.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getAncestor({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }) +} + +export const output = [ + + one + two + , + [], +] diff --git a/packages/slate/test/queries/getBefore/path.js b/packages/slate/test/queries/getBefore/path.js new file mode 100644 index 0000000000..5df8d79cfb --- /dev/null +++ b/packages/slate/test/queries/getBefore/path.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getBefore([1, 0]) +} + +export const output = { path: [0, 0], offset: 3 } diff --git a/packages/slate/test/queries/getBefore/point.js b/packages/slate/test/queries/getBefore/point.js new file mode 100644 index 0000000000..456ae8212d --- /dev/null +++ b/packages/slate/test/queries/getBefore/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getBefore({ path: [0, 0], offset: 1 }) +} + +export const output = { path: [0, 0], offset: 0 } diff --git a/packages/slate/test/queries/getBefore/range.js b/packages/slate/test/queries/getBefore/range.js new file mode 100644 index 0000000000..ea72b7c8cb --- /dev/null +++ b/packages/slate/test/queries/getBefore/range.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getBefore({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 1], offset: 2 }, + }) +} + +export const output = { path: [0, 0], offset: 0 } diff --git a/packages/slate/test/queries/getBefore/start.js b/packages/slate/test/queries/getBefore/start.js new file mode 100644 index 0000000000..1a99a5d63f --- /dev/null +++ b/packages/slate/test/queries/getBefore/start.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getBefore([0, 0]) +} + +export const output = undefined diff --git a/packages/slate/test/queries/getEdges/path.js b/packages/slate/test/queries/getEdges/path.js new file mode 100644 index 0000000000..418d46fd0d --- /dev/null +++ b/packages/slate/test/queries/getEdges/path.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getEdges([0]) +} + +export const output = [{ path: [0, 0], offset: 0 }, { path: [0, 0], offset: 3 }] diff --git a/packages/slate/test/queries/getEdges/point.js b/packages/slate/test/queries/getEdges/point.js new file mode 100644 index 0000000000..12ef7c18cb --- /dev/null +++ b/packages/slate/test/queries/getEdges/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getEdges({ path: [0, 0], offset: 1 }) +} + +export const output = [{ path: [0, 0], offset: 1 }, { path: [0, 0], offset: 1 }] diff --git a/packages/slate/test/queries/getEdges/range.js b/packages/slate/test/queries/getEdges/range.js new file mode 100644 index 0000000000..0f688baf5b --- /dev/null +++ b/packages/slate/test/queries/getEdges/range.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getEdges({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 3 }, + }) +} + +export const output = [{ path: [0, 0], offset: 1 }, { path: [0, 0], offset: 3 }] diff --git a/packages/slate/test/queries/getEnd/path.js b/packages/slate/test/queries/getEnd/path.js new file mode 100644 index 0000000000..14b30a4136 --- /dev/null +++ b/packages/slate/test/queries/getEnd/path.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getEnd([0]) +} + +export const output = { path: [0, 0], offset: 3 } diff --git a/packages/slate/test/queries/getEnd/point.js b/packages/slate/test/queries/getEnd/point.js new file mode 100644 index 0000000000..f18ed37145 --- /dev/null +++ b/packages/slate/test/queries/getEnd/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getEnd({ path: [0, 0], offset: 1 }) +} + +export const output = { path: [0, 0], offset: 1 } diff --git a/packages/slate/test/queries/getEnd/range.js b/packages/slate/test/queries/getEnd/range.js new file mode 100644 index 0000000000..cb5b3c2b40 --- /dev/null +++ b/packages/slate/test/queries/getEnd/range.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getEnd({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 2 }, + }) +} + +export const output = { path: [0, 0], offset: 2 } diff --git a/packages/slate/test/queries/getClosestBlock/block-nested.js b/packages/slate/test/queries/getMatch/block/block-nested.js similarity index 86% rename from packages/slate/test/queries/getClosestBlock/block-nested.js rename to packages/slate/test/queries/getMatch/block/block-nested.js index fb7ce428e8..7f44ed6c71 100644 --- a/packages/slate/test/queries/getClosestBlock/block-nested.js +++ b/packages/slate/test/queries/getMatch/block/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getClosestBlock/block.js b/packages/slate/test/queries/getMatch/block/block.js similarity index 85% rename from packages/slate/test/queries/getClosestBlock/block.js rename to packages/slate/test/queries/getMatch/block/block.js index e2c45d4cd9..a09e636cbe 100644 --- a/packages/slate/test/queries/getClosestBlock/block.js +++ b/packages/slate/test/queries/getMatch/block/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getClosestBlock/inline.js b/packages/slate/test/queries/getMatch/block/inline.js similarity index 88% rename from packages/slate/test/queries/getClosestBlock/inline.js rename to packages/slate/test/queries/getMatch/block/inline.js index 7483d81cca..4a6c539e66 100644 --- a/packages/slate/test/queries/getClosestBlock/inline.js +++ b/packages/slate/test/queries/getMatch/block/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/getNext/block.js b/packages/slate/test/queries/getNext/block.js new file mode 100644 index 0000000000..24df0942e8 --- /dev/null +++ b/packages/slate/test/queries/getNext/block.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getNext([0], 'block') +} + +export const output = [two, [1]] diff --git a/packages/slate/test/queries/getNext/text.js b/packages/slate/test/queries/getNext/text.js new file mode 100644 index 0000000000..09565b096d --- /dev/null +++ b/packages/slate/test/queries/getNext/text.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getNext([0], 'text') +} + +export const output = [two, [1, 0]] diff --git a/packages/slate/test/queries/rootInlines/block.js b/packages/slate/test/queries/getNode/path.js similarity index 66% rename from packages/slate/test/queries/rootInlines/block.js rename to packages/slate/test/queries/getNode/path.js index 357717d71a..95f5dd3c21 100644 --- a/packages/slate/test/queries/rootInlines/block.js +++ b/packages/slate/test/queries/getNode/path.js @@ -9,7 +9,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.rootInlines()) + return editor.getNode([0]) } -export const output = [] +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getNode/point.js b/packages/slate/test/queries/getNode/point.js new file mode 100644 index 0000000000..5bff8a985f --- /dev/null +++ b/packages/slate/test/queries/getNode/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getNode({ path: [0, 0], offset: 1 }) +} + +export const output = [one, [0, 0]] diff --git a/packages/slate/test/queries/getNode/range-end.js b/packages/slate/test/queries/getNode/range-end.js new file mode 100644 index 0000000000..5fad3dc859 --- /dev/null +++ b/packages/slate/test/queries/getNode/range-end.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getNode( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }, + { edge: 'end' } + ) +} + +export const output = [two, [1, 0]] diff --git a/packages/slate/test/queries/getNode/range-start.js b/packages/slate/test/queries/getNode/range-start.js new file mode 100644 index 0000000000..72b38b1244 --- /dev/null +++ b/packages/slate/test/queries/getNode/range-start.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getNode( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }, + { edge: 'start' } + ) +} + +export const output = [one, [0, 0]] diff --git a/packages/slate/test/queries/rootBlocks/block-reverse.js b/packages/slate/test/queries/getNode/range.js similarity index 52% rename from packages/slate/test/queries/rootBlocks/block-reverse.js rename to packages/slate/test/queries/getNode/range.js index e7d963f318..5b43c82e3f 100644 --- a/packages/slate/test/queries/rootBlocks/block-reverse.js +++ b/packages/slate/test/queries/getNode/range.js @@ -6,16 +6,20 @@ export const input = ( one two - three ) export const run = editor => { - return Array.from(editor.rootBlocks({ reverse: true })) + return editor.getNode({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }) } export const output = [ - [three, [2]], - [two, [1]], - [one, [0]], + + one + two + , + [], ] diff --git a/packages/slate/test/queries/getParent/path.js b/packages/slate/test/queries/getParent/path.js new file mode 100644 index 0000000000..ab930a887b --- /dev/null +++ b/packages/slate/test/queries/getParent/path.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getParent([0, 0]) +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getParent/point.js b/packages/slate/test/queries/getParent/point.js new file mode 100644 index 0000000000..c491d9b4c8 --- /dev/null +++ b/packages/slate/test/queries/getParent/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getParent({ path: [0, 0], offset: 1 }) +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getParent/range-end.js b/packages/slate/test/queries/getParent/range-end.js new file mode 100644 index 0000000000..c5e16b17b4 --- /dev/null +++ b/packages/slate/test/queries/getParent/range-end.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getParent( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }, + { edge: 'end' } + ) +} + +export const output = [two, [1]] diff --git a/packages/slate/test/queries/getParent/range-start.js b/packages/slate/test/queries/getParent/range-start.js new file mode 100644 index 0000000000..d20cc6f1ae --- /dev/null +++ b/packages/slate/test/queries/getParent/range-start.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getParent( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }, + { edge: 'start' } + ) +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getParent/range.js b/packages/slate/test/queries/getParent/range.js new file mode 100644 index 0000000000..90b1bb3419 --- /dev/null +++ b/packages/slate/test/queries/getParent/range.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getParent({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 2 }, + }) +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/leafInlines/block.js b/packages/slate/test/queries/getPath/path.js similarity index 69% rename from packages/slate/test/queries/leafInlines/block.js rename to packages/slate/test/queries/getPath/path.js index 2570d899ef..e133148758 100644 --- a/packages/slate/test/queries/leafInlines/block.js +++ b/packages/slate/test/queries/getPath/path.js @@ -9,7 +9,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.leafInlines()) + return editor.getPath([0]) } -export const output = [] +export const output = [0] diff --git a/packages/slate/test/queries/getPath/point.js b/packages/slate/test/queries/getPath/point.js new file mode 100644 index 0000000000..0c47b98fef --- /dev/null +++ b/packages/slate/test/queries/getPath/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getPath({ path: [0, 0], offset: 1 }) +} + +export const output = [0, 0] diff --git a/packages/slate/test/queries/getPath/range-end.js b/packages/slate/test/queries/getPath/range-end.js new file mode 100644 index 0000000000..d7107471a1 --- /dev/null +++ b/packages/slate/test/queries/getPath/range-end.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPath( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }, + { edge: 'end' } + ) +} + +export const output = [0, 1] diff --git a/packages/slate/test/queries/getPath/range-start.js b/packages/slate/test/queries/getPath/range-start.js new file mode 100644 index 0000000000..3099e749d9 --- /dev/null +++ b/packages/slate/test/queries/getPath/range-start.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPath( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }, + { edge: 'start' } + ) +} + +export const output = [0, 0] diff --git a/packages/slate/test/queries/getPath/range.js b/packages/slate/test/queries/getPath/range.js new file mode 100644 index 0000000000..3f1f06c159 --- /dev/null +++ b/packages/slate/test/queries/getPath/range.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPath({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [1, 0], offset: 2 }, + }) +} + +export const output = [0] diff --git a/packages/slate/test/queries/getPoint/path-end.js b/packages/slate/test/queries/getPoint/path-end.js new file mode 100644 index 0000000000..9f2a576af4 --- /dev/null +++ b/packages/slate/test/queries/getPoint/path-end.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getPoint([0], { edge: 'end' }) +} + +export const output = { path: [0, 0], offset: 3 } diff --git a/packages/slate/test/queries/getPoint/path-start.js b/packages/slate/test/queries/getPoint/path-start.js new file mode 100644 index 0000000000..309863d2a3 --- /dev/null +++ b/packages/slate/test/queries/getPoint/path-start.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getPoint([0], { edge: 'start' }) +} + +export const output = { path: [0, 0], offset: 0 } diff --git a/packages/slate/test/queries/getPoint/path.js b/packages/slate/test/queries/getPoint/path.js new file mode 100644 index 0000000000..ce349dc04d --- /dev/null +++ b/packages/slate/test/queries/getPoint/path.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getPoint([0]) +} + +export const output = { path: [0, 0], offset: 0 } diff --git a/packages/slate/test/queries/getPoint/point.js b/packages/slate/test/queries/getPoint/point.js new file mode 100644 index 0000000000..31c8c7a84b --- /dev/null +++ b/packages/slate/test/queries/getPoint/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getPoint({ path: [0, 0], offset: 1 }) +} + +export const output = { path: [0, 0], offset: 1 } diff --git a/packages/slate/test/queries/getPoint/range-end.js b/packages/slate/test/queries/getPoint/range-end.js new file mode 100644 index 0000000000..269c7ff120 --- /dev/null +++ b/packages/slate/test/queries/getPoint/range-end.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPoint( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 1], offset: 2 }, + }, + { edge: 'end' } + ) +} + +export const output = { path: [0, 1], offset: 2 } diff --git a/packages/slate/test/queries/getPoint/range-start.js b/packages/slate/test/queries/getPoint/range-start.js new file mode 100644 index 0000000000..ddef300a50 --- /dev/null +++ b/packages/slate/test/queries/getPoint/range-start.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPoint( + { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 1], offset: 2 }, + }, + { edge: 'start' } + ) +} + +export const output = { path: [0, 0], offset: 1 } diff --git a/packages/slate/test/queries/getPoint/range.js b/packages/slate/test/queries/getPoint/range.js new file mode 100644 index 0000000000..024f5f749f --- /dev/null +++ b/packages/slate/test/queries/getPoint/range.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPoint({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 1], offset: 2 }, + }) +} + +export const output = { path: [0, 0], offset: 1 } diff --git a/packages/slate/test/queries/getPrevious/block.js b/packages/slate/test/queries/getPrevious/block.js new file mode 100644 index 0000000000..a9b34ad63b --- /dev/null +++ b/packages/slate/test/queries/getPrevious/block.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPrevious([1], 'block') +} + +export const output = [one, [0]] diff --git a/packages/slate/test/queries/getPrevious/text.js b/packages/slate/test/queries/getPrevious/text.js new file mode 100644 index 0000000000..4ef4ca1a03 --- /dev/null +++ b/packages/slate/test/queries/getPrevious/text.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + two + +) + +export const run = editor => { + return editor.getPrevious([1], 'text') +} + +export const output = [one, [0, 0]] diff --git a/packages/slate/test/queries/getRange/path.js b/packages/slate/test/queries/getRange/path.js new file mode 100644 index 0000000000..500e1f4701 --- /dev/null +++ b/packages/slate/test/queries/getRange/path.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getRange([0]) +} + +export const output = { + anchor: { path: [0, 0], offset: 0 }, + focus: { path: [0, 0], offset: 3 }, +} diff --git a/packages/slate/test/queries/getRange/point.js b/packages/slate/test/queries/getRange/point.js new file mode 100644 index 0000000000..b47f88e781 --- /dev/null +++ b/packages/slate/test/queries/getRange/point.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getRange({ path: [0, 0], offset: 1 }) +} + +export const output = { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 1 }, +} diff --git a/packages/slate/test/queries/getRange/range.js b/packages/slate/test/queries/getRange/range.js new file mode 100644 index 0000000000..1e6e84c38b --- /dev/null +++ b/packages/slate/test/queries/getRange/range.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getRange({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 2 }, + }) +} + +export const output = { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 2 }, +} diff --git a/packages/slate/test/queries/getStart/path.js b/packages/slate/test/queries/getStart/path.js new file mode 100644 index 0000000000..dc6b684b9c --- /dev/null +++ b/packages/slate/test/queries/getStart/path.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getStart([0]) +} + +export const output = { path: [0, 0], offset: 0 } diff --git a/packages/slate/test/queries/getStart/point.js b/packages/slate/test/queries/getStart/point.js new file mode 100644 index 0000000000..1aa191e548 --- /dev/null +++ b/packages/slate/test/queries/getStart/point.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getStart({ path: [0, 0], offset: 1 }) +} + +export const output = { path: [0, 0], offset: 1 } diff --git a/packages/slate/test/queries/getStart/range.js b/packages/slate/test/queries/getStart/range.js new file mode 100644 index 0000000000..2c4aa5dc20 --- /dev/null +++ b/packages/slate/test/queries/getStart/range.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getStart({ + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 3 }, + }) +} + +export const output = { path: [0, 0], offset: 1 } diff --git a/packages/slate/test/queries/leafInlines/inline.js b/packages/slate/test/queries/isEdge/path-end.js similarity index 54% rename from packages/slate/test/queries/leafInlines/inline.js rename to packages/slate/test/queries/isEdge/path-end.js index 6ef8643444..93d4f48a32 100644 --- a/packages/slate/test/queries/leafInlines/inline.js +++ b/packages/slate/test/queries/isEdge/path-end.js @@ -5,13 +5,14 @@ import { h } from '../../helpers' export const input = ( - onetwothree + one ) export const run = editor => { - return Array.from(editor.leafInlines()) + const { anchor } = editor.value.selection + return editor.isEdge(anchor, [0]) } -export const output = [[two, [0, 1]]] +export const output = true diff --git a/packages/slate/test/queries/isEdge/path-middle.js b/packages/slate/test/queries/isEdge/path-middle.js new file mode 100644 index 0000000000..6478a054ce --- /dev/null +++ b/packages/slate/test/queries/isEdge/path-middle.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const { anchor } = editor.value.selection + return editor.isEdge(anchor, [0]) +} + +export const output = false diff --git a/packages/slate/test/queries/isEdge/path-start.js b/packages/slate/test/queries/isEdge/path-start.js new file mode 100644 index 0000000000..b8b3f58664 --- /dev/null +++ b/packages/slate/test/queries/isEdge/path-start.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const { anchor } = editor.value.selection + return editor.isEdge(anchor, [0]) +} + +export const output = true diff --git a/packages/slate/test/queries/isAtomic/atomic.js b/packages/slate/test/queries/isEmpty/block-blank.js similarity index 65% rename from packages/slate/test/queries/isAtomic/atomic.js rename to packages/slate/test/queries/isEmpty/block-blank.js index 92950eba95..7d5e6c8d97 100644 --- a/packages/slate/test/queries/isAtomic/atomic.js +++ b/packages/slate/test/queries/isEmpty/block-blank.js @@ -5,14 +5,14 @@ import { h } from '../../helpers' export const input = ( - one + ) export const run = editor => { - const [[mark]] = editor.marks() - return editor.isAtomic(mark) + const block = editor.value.nodes[0] + return editor.isEmpty(block) } export const output = true diff --git a/packages/slate/test/queries/isEmpty/block-empty.js b/packages/slate/test/queries/isEmpty/block-empty.js new file mode 100644 index 0000000000..f2fba31879 --- /dev/null +++ b/packages/slate/test/queries/isEmpty/block-empty.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.isEmpty(block) +} + +export const output = true diff --git a/packages/slate/test/queries/isEmpty/block-full.js b/packages/slate/test/queries/isEmpty/block-full.js new file mode 100644 index 0000000000..1cca20fa8f --- /dev/null +++ b/packages/slate/test/queries/isEmpty/block-full.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.isEmpty(block) +} + +export const output = false diff --git a/packages/slate/test/queries/isEmpty/block-void.js b/packages/slate/test/queries/isEmpty/block-void.js new file mode 100644 index 0000000000..7a721a5c68 --- /dev/null +++ b/packages/slate/test/queries/isEmpty/block-void.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + + + +) + +export const run = editor => { + const block = editor.value.nodes[0] + return editor.isEmpty(block) +} + +export const output = false diff --git a/packages/slate/test/queries/isEmpty/inline-blank.js b/packages/slate/test/queries/isEmpty/inline-blank.js new file mode 100644 index 0000000000..5a06299741 --- /dev/null +++ b/packages/slate/test/queries/isEmpty/inline-blank.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + + + three + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.isEmpty(inline) +} + +export const output = true diff --git a/packages/slate/test/queries/leafInlines/inline-void.js b/packages/slate/test/queries/isEmpty/inline-empty.js similarity index 51% rename from packages/slate/test/queries/leafInlines/inline-void.js rename to packages/slate/test/queries/isEmpty/inline-empty.js index 74f2b92efc..f8fd5f7fad 100644 --- a/packages/slate/test/queries/leafInlines/inline-void.js +++ b/packages/slate/test/queries/isEmpty/inline-empty.js @@ -5,13 +5,16 @@ import { h } from '../../helpers' export const input = ( - onetwothree + one + + three ) export const run = editor => { - return Array.from(editor.leafInlines()) + const inline = editor.value.nodes[0].nodes[1] + return editor.isEmpty(inline) } -export const output = [[two, [0, 1]]] +export const output = true diff --git a/packages/slate/test/queries/rootInlines/inline.js b/packages/slate/test/queries/isEmpty/inline-full.js similarity index 63% rename from packages/slate/test/queries/rootInlines/inline.js rename to packages/slate/test/queries/isEmpty/inline-full.js index e34c6d580b..2115bdbced 100644 --- a/packages/slate/test/queries/rootInlines/inline.js +++ b/packages/slate/test/queries/isEmpty/inline-full.js @@ -11,7 +11,8 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.rootInlines()) + const inline = editor.value.nodes[0].nodes[1] + return editor.isEmpty(inline) } -export const output = [[two, [0, 1]]] +export const output = false diff --git a/packages/slate/test/queries/isEmpty/inline-void.js b/packages/slate/test/queries/isEmpty/inline-void.js new file mode 100644 index 0000000000..413cec2c8d --- /dev/null +++ b/packages/slate/test/queries/isEmpty/inline-void.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + + + three + + +) + +export const run = editor => { + const inline = editor.value.nodes[0].nodes[1] + return editor.isEmpty(inline) +} + +export const output = false diff --git a/packages/slate/test/queries/isEnd/path-end.js b/packages/slate/test/queries/isEnd/path-end.js new file mode 100644 index 0000000000..9869c93a6d --- /dev/null +++ b/packages/slate/test/queries/isEnd/path-end.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const { anchor } = editor.value.selection + return editor.isEnd(anchor, [0]) +} + +export const output = true diff --git a/packages/slate/test/queries/isAtomic/non-atomic.js b/packages/slate/test/queries/isEnd/path-middle.js similarity index 65% rename from packages/slate/test/queries/isAtomic/non-atomic.js rename to packages/slate/test/queries/isEnd/path-middle.js index 703eb34ea5..f610162d1d 100644 --- a/packages/slate/test/queries/isAtomic/non-atomic.js +++ b/packages/slate/test/queries/isEnd/path-middle.js @@ -5,14 +5,14 @@ import { h } from '../../helpers' export const input = ( - one + one ) export const run = editor => { - const [[mark]] = editor.marks() - return editor.isAtomic(mark) + const { anchor } = editor.value.selection + return editor.isEnd(anchor, [0]) } export const output = false diff --git a/packages/slate/test/queries/isEnd/path-start.js b/packages/slate/test/queries/isEnd/path-start.js new file mode 100644 index 0000000000..db97283588 --- /dev/null +++ b/packages/slate/test/queries/isEnd/path-start.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const { anchor } = editor.value.selection + return editor.isEnd(anchor, [0]) +} + +export const output = false diff --git a/packages/slate/test/queries/isStart/path-end.js b/packages/slate/test/queries/isStart/path-end.js new file mode 100644 index 0000000000..2accb93784 --- /dev/null +++ b/packages/slate/test/queries/isStart/path-end.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const { anchor } = editor.value.selection + return editor.isStart(anchor, [0]) +} + +export const output = false diff --git a/packages/slate/test/queries/isStart/path-middle.js b/packages/slate/test/queries/isStart/path-middle.js new file mode 100644 index 0000000000..f44dcbabd5 --- /dev/null +++ b/packages/slate/test/queries/isStart/path-middle.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const { anchor } = editor.value.selection + return editor.isStart(anchor, [0]) +} + +export const output = false diff --git a/packages/slate/test/queries/isStart/path-start.js b/packages/slate/test/queries/isStart/path-start.js new file mode 100644 index 0000000000..441c3f7114 --- /dev/null +++ b/packages/slate/test/queries/isStart/path-start.js @@ -0,0 +1,18 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + const { anchor } = editor.value.selection + return editor.isStart(anchor, [0]) +} + +export const output = true diff --git a/packages/slate/test/queries/leafBlocks/block-void.js b/packages/slate/test/queries/leafBlocks/block-void.js deleted file mode 100644 index 33dbcdbbc0..0000000000 --- a/packages/slate/test/queries/leafBlocks/block-void.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - one - - -) - -export const run = editor => { - return Array.from(editor.leafBlocks()) -} - -export const output = [ - [ - - one - , - [0], - ], -] diff --git a/packages/slate/test/queries/leafBlocks/inline.js b/packages/slate/test/queries/leafBlocks/inline.js deleted file mode 100644 index f1685c62ac..0000000000 --- a/packages/slate/test/queries/leafBlocks/inline.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from(editor.leafBlocks()) -} - -export const output = [ - [ - - onetwothree - , - [0], - ], -] diff --git a/packages/slate/test/queries/leafInlines/inline-nested.js b/packages/slate/test/queries/leafInlines/inline-nested.js deleted file mode 100644 index 4454e30427..0000000000 --- a/packages/slate/test/queries/leafInlines/inline-nested.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - one - twothreefour - five - - -) - -export const run = editor => { - return Array.from(editor.leafInlines()) -} - -export const output = [[three, [0, 1, 1]]] diff --git a/packages/slate/test/queries/rootBlocks/block-multiple.js b/packages/slate/test/queries/matches/block/block-multiple.js similarity index 75% rename from packages/slate/test/queries/rootBlocks/block-multiple.js rename to packages/slate/test/queries/matches/block/block-multiple.js index 5a731b0cbc..7a6ad7c729 100644 --- a/packages/slate/test/queries/rootBlocks/block-multiple.js +++ b/packages/slate/test/queries/matches/block/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.rootBlocks()) + return Array.from(editor.matches({ match: 'block' })) } export const output = [ diff --git a/packages/slate/test/queries/leafBlocks/block-nested.js b/packages/slate/test/queries/matches/block/block-nested.js similarity index 75% rename from packages/slate/test/queries/leafBlocks/block-nested.js rename to packages/slate/test/queries/matches/block/block-nested.js index 5892bd56ef..563f5bad4d 100644 --- a/packages/slate/test/queries/leafBlocks/block-nested.js +++ b/packages/slate/test/queries/matches/block/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -14,7 +14,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.leafBlocks()) + return Array.from(editor.matches({ match: 'block' })) } export const output = [ diff --git a/packages/slate/test/queries/leafBlocks/block-reverse.js b/packages/slate/test/queries/matches/block/block-reverse.js similarity index 72% rename from packages/slate/test/queries/leafBlocks/block-reverse.js rename to packages/slate/test/queries/matches/block/block-reverse.js index 3fa0989227..a4bf023a12 100644 --- a/packages/slate/test/queries/leafBlocks/block-reverse.js +++ b/packages/slate/test/queries/matches/block/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.leafBlocks({ reverse: true })) + return Array.from(editor.matches({ match: 'block', reverse: true })) } export const output = [ diff --git a/packages/slate/test/queries/matches/block/block-void.js b/packages/slate/test/queries/matches/block/block-void.js new file mode 100644 index 0000000000..1281280fc7 --- /dev/null +++ b/packages/slate/test/queries/matches/block/block-void.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + + +) + +export const run = editor => { + return Array.from(editor.matches({ match: 'block' })) +} + +export const output = [] diff --git a/packages/slate/test/queries/leafBlocks/block.js b/packages/slate/test/queries/matches/block/block.js similarity index 64% rename from packages/slate/test/queries/leafBlocks/block.js rename to packages/slate/test/queries/matches/block/block.js index e6dc53c211..45a1d88d9e 100644 --- a/packages/slate/test/queries/leafBlocks/block.js +++ b/packages/slate/test/queries/matches/block/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -9,7 +9,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.leafBlocks()) + return Array.from(editor.matches({ match: 'block' })) } export const output = [[one, [0]]] diff --git a/packages/slate/test/queries/rootBlocks/inline.js b/packages/slate/test/queries/matches/block/inline.js similarity index 73% rename from packages/slate/test/queries/rootBlocks/inline.js rename to packages/slate/test/queries/matches/block/inline.js index 7cddd4b285..6d0180439e 100644 --- a/packages/slate/test/queries/rootBlocks/inline.js +++ b/packages/slate/test/queries/matches/block/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.rootBlocks()) + return Array.from(editor.matches({ match: 'block' })) } export const output = [ diff --git a/packages/slate/test/queries/leafBlocks/block-multiple.js b/packages/slate/test/queries/matches/depth/one.js similarity index 76% rename from packages/slate/test/queries/leafBlocks/block-multiple.js rename to packages/slate/test/queries/matches/depth/one.js index a183c1c87a..00b78f7555 100644 --- a/packages/slate/test/queries/leafBlocks/block-multiple.js +++ b/packages/slate/test/queries/matches/depth/one.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,7 +11,7 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.leafBlocks()) + return Array.from(editor.matches({ match: 1 })) } export const output = [ diff --git a/packages/slate/test/queries/matches/inline/block.js b/packages/slate/test/queries/matches/inline/block.js new file mode 100644 index 0000000000..87972250bf --- /dev/null +++ b/packages/slate/test/queries/matches/inline/block.js @@ -0,0 +1,15 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return Array.from(editor.matches({ match: 'inline' })) +} + +export const output = [[one, [0, 0]]] diff --git a/packages/slate/test/queries/leafInlines/inline-multiple.js b/packages/slate/test/queries/matches/inline/inline-multiple.js similarity index 59% rename from packages/slate/test/queries/leafInlines/inline-multiple.js rename to packages/slate/test/queries/matches/inline/inline-multiple.js index 3c20e1277d..5ec89146f5 100644 --- a/packages/slate/test/queries/leafInlines/inline-multiple.js +++ b/packages/slate/test/queries/matches/inline/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,10 +11,13 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.leafInlines()) + return Array.from(editor.matches({ match: 'inline' })) } export const output = [ + [one, [0, 0]], [two, [0, 1]], + [three, [0, 2]], [four, [0, 3]], + [five, [0, 4]], ] diff --git a/packages/slate/test/queries/rootInlines/inline-nested.js b/packages/slate/test/queries/matches/inline/inline-nested.js similarity index 66% rename from packages/slate/test/queries/rootInlines/inline-nested.js rename to packages/slate/test/queries/matches/inline/inline-nested.js index f53d1a819f..8ff1045311 100644 --- a/packages/slate/test/queries/rootInlines/inline-nested.js +++ b/packages/slate/test/queries/matches/inline/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -13,14 +13,16 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.rootInlines()) + return Array.from(editor.matches({ match: 'inline' })) } export const output = [ + [one, [0, 0]], [ twothreefour , [0, 1], ], + [five, [0, 2]], ] diff --git a/packages/slate/test/queries/leafInlines/inline-reverse.js b/packages/slate/test/queries/matches/inline/inline-reverse.js similarity index 57% rename from packages/slate/test/queries/leafInlines/inline-reverse.js rename to packages/slate/test/queries/matches/inline/inline-reverse.js index c98273f378..9672168e02 100644 --- a/packages/slate/test/queries/leafInlines/inline-reverse.js +++ b/packages/slate/test/queries/matches/inline/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,10 +11,13 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.leafInlines({ reverse: true })) + return Array.from(editor.matches({ match: 'inline', reverse: true })) } export const output = [ + [five, [0, 4]], [four, [0, 3]], + [three, [0, 2]], [two, [0, 1]], + [one, [0, 0]], ] diff --git a/packages/slate/test/queries/matches/inline/inline-void.js b/packages/slate/test/queries/matches/inline/inline-void.js new file mode 100644 index 0000000000..cabbefe0cf --- /dev/null +++ b/packages/slate/test/queries/matches/inline/inline-void.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.matches({ match: 'inline' })) +} + +export const output = [ + [one, [0, 0]], + [two, [0, 1]], + [three, [0, 2]], +] diff --git a/packages/slate/test/queries/matches/inline/inline.js b/packages/slate/test/queries/matches/inline/inline.js new file mode 100644 index 0000000000..a4066fa735 --- /dev/null +++ b/packages/slate/test/queries/matches/inline/inline.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.matches({ match: 'inline' })) +} + +export const output = [ + [one, [0, 0]], + [two, [0, 1]], + [three, [0, 2]], +] diff --git a/packages/slate/test/queries/positions/all/block-multiple-reverse.js b/packages/slate/test/queries/positions/all/block-multiple-reverse.js index 9f14aca6c0..85492fb1bc 100644 --- a/packages/slate/test/queries/positions/all/block-multiple-reverse.js +++ b/packages/slate/test/queries/positions/all/block-multiple-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/block-multiple.js b/packages/slate/test/queries/positions/all/block-multiple.js index 9ad9e0a36c..57161e9e46 100644 --- a/packages/slate/test/queries/positions/all/block-multiple.js +++ b/packages/slate/test/queries/positions/all/block-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/block-nested.js b/packages/slate/test/queries/positions/all/block-nested.js index b3acda204e..7ea1c3b575 100644 --- a/packages/slate/test/queries/positions/all/block-nested.js +++ b/packages/slate/test/queries/positions/all/block-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/block-reverse.js b/packages/slate/test/queries/positions/all/block-reverse.js index 534574327b..fc1d861094 100644 --- a/packages/slate/test/queries/positions/all/block-reverse.js +++ b/packages/slate/test/queries/positions/all/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/block.js b/packages/slate/test/queries/positions/all/block.js index e2659bf62c..35369ef9e8 100644 --- a/packages/slate/test/queries/positions/all/block.js +++ b/packages/slate/test/queries/positions/all/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/inline-multiple.js b/packages/slate/test/queries/positions/all/inline-multiple.js index f1a4acf56f..ba5ea0db70 100644 --- a/packages/slate/test/queries/positions/all/inline-multiple.js +++ b/packages/slate/test/queries/positions/all/inline-multiple.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/inline-nested.js b/packages/slate/test/queries/positions/all/inline-nested.js index 44f3d5e4ed..3b5d9b181c 100644 --- a/packages/slate/test/queries/positions/all/inline-nested.js +++ b/packages/slate/test/queries/positions/all/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/inline-reverse.js b/packages/slate/test/queries/positions/all/inline-reverse.js index 669ff477ee..62c1ae13b2 100644 --- a/packages/slate/test/queries/positions/all/inline-reverse.js +++ b/packages/slate/test/queries/positions/all/inline-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/inline.js b/packages/slate/test/queries/positions/all/inline.js index a296b7c7b1..a107e29f80 100644 --- a/packages/slate/test/queries/positions/all/inline.js +++ b/packages/slate/test/queries/positions/all/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-block-reverse.js b/packages/slate/test/queries/positions/all/unit-block-reverse.js index b4e13e68ff..458e48eec1 100644 --- a/packages/slate/test/queries/positions/all/unit-block-reverse.js +++ b/packages/slate/test/queries/positions/all/unit-block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-block.js b/packages/slate/test/queries/positions/all/unit-block.js index 199fbeab11..1d68defd72 100644 --- a/packages/slate/test/queries/positions/all/unit-block.js +++ b/packages/slate/test/queries/positions/all/unit-block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-character-reverse.js b/packages/slate/test/queries/positions/all/unit-character-reverse.js index 3acf1a1c57..3201fa1497 100644 --- a/packages/slate/test/queries/positions/all/unit-character-reverse.js +++ b/packages/slate/test/queries/positions/all/unit-character-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-character.js b/packages/slate/test/queries/positions/all/unit-character.js index c4b93144b6..f548a3875e 100644 --- a/packages/slate/test/queries/positions/all/unit-character.js +++ b/packages/slate/test/queries/positions/all/unit-character.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-line-reverse.js b/packages/slate/test/queries/positions/all/unit-line-reverse.js index 88e761a894..d5b1191fe7 100644 --- a/packages/slate/test/queries/positions/all/unit-line-reverse.js +++ b/packages/slate/test/queries/positions/all/unit-line-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-line.js b/packages/slate/test/queries/positions/all/unit-line.js index 0ec17522fc..a80aede6bd 100644 --- a/packages/slate/test/queries/positions/all/unit-line.js +++ b/packages/slate/test/queries/positions/all/unit-line.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-word-reverse.js b/packages/slate/test/queries/positions/all/unit-word-reverse.js index 63fbe6b4d0..87e002bee7 100644 --- a/packages/slate/test/queries/positions/all/unit-word-reverse.js +++ b/packages/slate/test/queries/positions/all/unit-word-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/all/unit-word.js b/packages/slate/test/queries/positions/all/unit-word.js index 9d29d5d23f..e56f726792 100644 --- a/packages/slate/test/queries/positions/all/unit-word.js +++ b/packages/slate/test/queries/positions/all/unit-word.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( diff --git a/packages/slate/test/queries/positions/path/block-nested.js b/packages/slate/test/queries/positions/path/block-nested.js new file mode 100644 index 0000000000..a1f2cb9113 --- /dev/null +++ b/packages/slate/test/queries/positions/path/block-nested.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + one + two + + +) + +export const run = editor => { + return Array.from(editor.positions({ at: [0] })) +} + +export const output = [ + { path: [0, 0, 0], offset: 0 }, + { path: [0, 0, 0], offset: 1 }, + { path: [0, 0, 0], offset: 2 }, + { path: [0, 0, 0], offset: 3 }, + { path: [0, 1, 0], offset: 0 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, +] diff --git a/packages/slate/test/queries/positions/point/block-edge-reverse.js b/packages/slate/test/queries/positions/path/block-reverse.js similarity index 63% rename from packages/slate/test/queries/positions/point/block-edge-reverse.js rename to packages/slate/test/queries/positions/path/block-reverse.js index ae3c87f009..9b746e3a83 100644 --- a/packages/slate/test/queries/positions/point/block-edge-reverse.js +++ b/packages/slate/test/queries/positions/path/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -10,13 +10,10 @@ export const input = ( ) export const run = editor => { - return Array.from( - editor.positions({ reverse: true, point: { path: [1, 0], offset: 0 } }) - ) + return Array.from(editor.positions({ reverse: true, at: [0, 0] })) } export const output = [ - { path: [1, 0], offset: 0 }, { path: [0, 0], offset: 3 }, { path: [0, 0], offset: 2 }, { path: [0, 0], offset: 1 }, diff --git a/packages/slate/test/queries/positions/point/block-edge.js b/packages/slate/test/queries/positions/path/block.js similarity index 66% rename from packages/slate/test/queries/positions/point/block-edge.js rename to packages/slate/test/queries/positions/path/block.js index b464de97e8..803ccd097e 100644 --- a/packages/slate/test/queries/positions/point/block-edge.js +++ b/packages/slate/test/queries/positions/path/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -10,11 +10,10 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.positions({ point: { path: [0, 0], offset: 3 } })) + return Array.from(editor.positions({ at: [1, 0] })) } export const output = [ - { path: [0, 0], offset: 3 }, { path: [1, 0], offset: 0 }, { path: [1, 0], offset: 1 }, { path: [1, 0], offset: 2 }, diff --git a/packages/slate/test/queries/positions/point/inline-nested.js b/packages/slate/test/queries/positions/path/inline-nested.js similarity index 69% rename from packages/slate/test/queries/positions/point/inline-nested.js rename to packages/slate/test/queries/positions/path/inline-nested.js index 6d677a4803..bbe48bdc21 100644 --- a/packages/slate/test/queries/positions/point/inline-nested.js +++ b/packages/slate/test/queries/positions/path/inline-nested.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -13,12 +13,10 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) + return Array.from(editor.positions({ at: [0, 1] })) } export const output = [ - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 3 }, { path: [0, 1, 0], offset: 0 }, { path: [0, 1, 0], offset: 1 }, { path: [0, 1, 0], offset: 2 }, @@ -34,9 +32,4 @@ export const output = [ { path: [0, 1, 2], offset: 2 }, { path: [0, 1, 2], offset: 3 }, { path: [0, 1, 2], offset: 4 }, - { path: [0, 2], offset: 0 }, - { path: [0, 2], offset: 1 }, - { path: [0, 2], offset: 2 }, - { path: [0, 2], offset: 3 }, - { path: [0, 2], offset: 4 }, ] diff --git a/packages/slate/test/queries/positions/path/inline-reverse.js b/packages/slate/test/queries/positions/path/inline-reverse.js new file mode 100644 index 0000000000..0520e9e13a --- /dev/null +++ b/packages/slate/test/queries/positions/path/inline-reverse.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.positions({ reverse: true, at: [0, 1] })) +} + +export const output = [ + { path: [0, 1, 0], offset: 3 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 0 }, +] diff --git a/packages/slate/test/queries/positions/path/inline.js b/packages/slate/test/queries/positions/path/inline.js new file mode 100644 index 0000000000..7be856427b --- /dev/null +++ b/packages/slate/test/queries/positions/path/inline.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const input = ( + + + onetwothree + + +) + +export const run = editor => { + return Array.from(editor.positions({ at: [0, 1] })) +} + +export const output = [ + { path: [0, 1, 0], offset: 0 }, + { path: [0, 1, 0], offset: 1 }, + { path: [0, 1, 0], offset: 2 }, + { path: [0, 1, 0], offset: 3 }, +] diff --git a/packages/slate/test/queries/positions/point/block-nested.js b/packages/slate/test/queries/positions/point/block-nested.js deleted file mode 100644 index fc5718cb63..0000000000 --- a/packages/slate/test/queries/positions/point/block-nested.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - - one - - - two - - -) - -export const run = editor => { - return Array.from(editor.positions({ point: { path: [0, 0, 0], offset: 2 } })) -} - -export const output = [ - { path: [0, 0, 0], offset: 2 }, - { path: [0, 0, 0], offset: 3 }, - { path: [1, 0, 0], offset: 0 }, - { path: [1, 0, 0], offset: 1 }, - { path: [1, 0, 0], offset: 2 }, - { path: [1, 0, 0], offset: 3 }, -] diff --git a/packages/slate/test/queries/positions/point/block-reverse.js b/packages/slate/test/queries/positions/point/block-reverse.js deleted file mode 100644 index 23ac2504fd..0000000000 --- a/packages/slate/test/queries/positions/point/block-reverse.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one - -) - -export const run = editor => { - return Array.from( - editor.positions({ reverse: true, point: { path: [0, 0], offset: 2 } }) - ) -} - -export const output = [ - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 1 }, - { path: [0, 0], offset: 0 }, -] diff --git a/packages/slate/test/queries/positions/point/block.js b/packages/slate/test/queries/positions/point/block.js deleted file mode 100644 index 341ae6e587..0000000000 --- a/packages/slate/test/queries/positions/point/block.js +++ /dev/null @@ -1,19 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one - -) - -export const run = editor => { - return Array.from(editor.positions({ point: { path: [0, 0], offset: 1 } })) -} - -export const output = [ - { path: [0, 0], offset: 1 }, - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 3 }, -] diff --git a/packages/slate/test/queries/positions/point/inline-reverse.js b/packages/slate/test/queries/positions/point/inline-reverse.js deleted file mode 100644 index 97a16e73ab..0000000000 --- a/packages/slate/test/queries/positions/point/inline-reverse.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from( - editor.positions({ reverse: true, point: { path: [0, 2], offset: 2 } }) - ) -} - -export const output = [ - { path: [0, 2], offset: 2 }, - { path: [0, 2], offset: 1 }, - { path: [0, 2], offset: 0 }, - { path: [0, 1, 0], offset: 3 }, - { path: [0, 1, 0], offset: 2 }, - { path: [0, 1, 0], offset: 1 }, - { path: [0, 1, 0], offset: 0 }, - { path: [0, 0], offset: 3 }, - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 1 }, - { path: [0, 0], offset: 0 }, -] diff --git a/packages/slate/test/queries/positions/point/inline.js b/packages/slate/test/queries/positions/point/inline.js deleted file mode 100644 index a296b7c7b1..0000000000 --- a/packages/slate/test/queries/positions/point/inline.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from(editor.positions()) -} - -export const output = [ - { path: [0, 0], offset: 0 }, - { path: [0, 0], offset: 1 }, - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 3 }, - { path: [0, 1, 0], offset: 0 }, - { path: [0, 1, 0], offset: 1 }, - { path: [0, 1, 0], offset: 2 }, - { path: [0, 1, 0], offset: 3 }, - { path: [0, 2], offset: 0 }, - { path: [0, 2], offset: 1 }, - { path: [0, 2], offset: 2 }, - { path: [0, 2], offset: 3 }, - { path: [0, 2], offset: 4 }, - { path: [0, 2], offset: 5 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-block-reverse.js b/packages/slate/test/queries/positions/point/unit-block-reverse.js deleted file mode 100644 index 9985e4d3ac..0000000000 --- a/packages/slate/test/queries/positions/point/unit-block-reverse.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one two three - four five six - -) - -export const run = editor => { - return Array.from( - editor.positions({ - unit: 'block', - reverse: true, - point: { path: [1, 0], offset: 4 }, - }) - ) -} - -export const output = [ - { path: [1, 0], offset: 4 }, - { path: [1, 0], offset: 0 }, - { path: [0, 0], offset: 13 }, - { path: [0, 0], offset: 0 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-block.js b/packages/slate/test/queries/positions/point/unit-block.js deleted file mode 100644 index 4625c4475d..0000000000 --- a/packages/slate/test/queries/positions/point/unit-block.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one two three - four five six - -) - -export const run = editor => { - return Array.from( - editor.positions({ unit: 'block', point: { path: [0, 0], offset: 3 } }) - ) -} - -export const output = [ - { path: [0, 0], offset: 3 }, - { path: [0, 0], offset: 13 }, - { path: [0, 0], offset: 0 }, - { path: [1, 0], offset: 13 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-character-reverse.js b/packages/slate/test/queries/positions/point/unit-character-reverse.js deleted file mode 100644 index a5b70bf978..0000000000 --- a/packages/slate/test/queries/positions/point/unit-character-reverse.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from( - editor.positions({ - unit: 'character', - reverse: true, - point: { path: [0, 2], offset: 3 }, - }) - ) -} - -export const output = [ - { path: [0, 2], offset: 3 }, - { path: [0, 2], offset: 2 }, - { path: [0, 2], offset: 1 }, - { path: [0, 2], offset: 0 }, - { path: [0, 1, 0], offset: 2 }, - { path: [0, 1, 0], offset: 1 }, - { path: [0, 1, 0], offset: 0 }, - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 1 }, - { path: [0, 0], offset: 0 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-character.js b/packages/slate/test/queries/positions/point/unit-character.js deleted file mode 100644 index 30be6af250..0000000000 --- a/packages/slate/test/queries/positions/point/unit-character.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from( - editor.positions({ unit: 'character', point: { path: [0, 0], offset: 2 } }) - ) -} - -export const output = [ - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 3 }, - { path: [0, 1, 0], offset: 1 }, - { path: [0, 1, 0], offset: 2 }, - { path: [0, 1, 0], offset: 3 }, - { path: [0, 2], offset: 1 }, - { path: [0, 2], offset: 2 }, - { path: [0, 2], offset: 3 }, - { path: [0, 2], offset: 4 }, - { path: [0, 2], offset: 5 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-line-reverse.js b/packages/slate/test/queries/positions/point/unit-line-reverse.js deleted file mode 100644 index a608cbbaa0..0000000000 --- a/packages/slate/test/queries/positions/point/unit-line-reverse.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one two three - four five six - -) - -export const run = editor => { - return Array.from( - editor.positions({ - unit: 'line', - reverse: true, - point: { path: [1, 0], offset: 3 }, - }) - ) -} - -export const output = [ - { path: [1, 0], offset: 3 }, - { path: [1, 0], offset: 0 }, - { path: [0, 0], offset: 13 }, - { path: [0, 0], offset: 0 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-line.js b/packages/slate/test/queries/positions/point/unit-line.js deleted file mode 100644 index f525831007..0000000000 --- a/packages/slate/test/queries/positions/point/unit-line.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one two three - four five six - -) - -export const run = editor => { - return Array.from( - editor.positions({ unit: 'line', point: { path: [0, 0], offset: 3 } }) - ) -} - -export const output = [ - { path: [0, 0], offset: 3 }, - { path: [0, 0], offset: 13 }, - { path: [1, 0], offset: 0 }, - { path: [1, 0], offset: 13 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-word-reverse.js b/packages/slate/test/queries/positions/point/unit-word-reverse.js deleted file mode 100644 index e3c749eb51..0000000000 --- a/packages/slate/test/queries/positions/point/unit-word-reverse.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one two three - four five six - -) - -export const run = editor => { - return Array.from( - editor.positions({ - unit: 'word', - reverse: true, - point: { path: [1, 0], offset: 11 }, - }) - ) -} - -export const output = [ - { path: [1, 0], offset: 11 }, - { path: [1, 0], offset: 10 }, - { path: [1, 0], offset: 5 }, - { path: [1, 0], offset: 0 }, - { path: [0, 0], offset: 13 }, - { path: [0, 0], offset: 8 }, - { path: [0, 0], offset: 4 }, - { path: [0, 0], offset: 0 }, -] diff --git a/packages/slate/test/queries/positions/point/unit-word.js b/packages/slate/test/queries/positions/point/unit-word.js deleted file mode 100644 index 89340701f5..0000000000 --- a/packages/slate/test/queries/positions/point/unit-word.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../../../helpers' - -export const input = ( - - one two three - four five six - -) - -export const run = editor => { - return Array.from( - editor.positions({ unit: 'word', point: { path: [0, 0], offset: 1 } }) - ) -} - -export const output = [ - { path: [0, 0], offset: 1 }, - { path: [0, 0], offset: 3 }, - { path: [0, 0], offset: 7 }, - { path: [0, 0], offset: 13 }, - { path: [1, 0], offset: 0 }, - { path: [1, 0], offset: 4 }, - { path: [1, 0], offset: 9 }, - { path: [1, 0], offset: 13 }, -] diff --git a/packages/slate/test/queries/positions/point/block-multiple.js b/packages/slate/test/queries/positions/range/block-reverse.js similarity index 65% rename from packages/slate/test/queries/positions/point/block-multiple.js rename to packages/slate/test/queries/positions/range/block-reverse.js index 4a6ca82783..fc993db1a2 100644 --- a/packages/slate/test/queries/positions/point/block-multiple.js +++ b/packages/slate/test/queries/positions/range/block-reverse.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,20 +11,26 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) + return Array.from( + editor.positions({ + reverse: true, + at: { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [2, 0], offset: 2 }, + }, + }) + ) } export const output = [ - { path: [0, 0], offset: 2 }, - { path: [0, 0], offset: 3 }, - { path: [1, 0], offset: 0 }, - { path: [1, 0], offset: 1 }, - { path: [1, 0], offset: 2 }, - { path: [1, 0], offset: 3 }, - { path: [2, 0], offset: 0 }, - { path: [2, 0], offset: 1 }, { path: [2, 0], offset: 2 }, - { path: [2, 0], offset: 3 }, - { path: [2, 0], offset: 4 }, - { path: [2, 0], offset: 5 }, + { path: [2, 0], offset: 1 }, + { path: [2, 0], offset: 0 }, + { path: [1, 0], offset: 3 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 0 }, + { path: [0, 0], offset: 3 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 1 }, ] diff --git a/packages/slate/test/queries/positions/point/block-multiple-reverse.js b/packages/slate/test/queries/positions/range/block.js similarity index 74% rename from packages/slate/test/queries/positions/point/block-multiple-reverse.js rename to packages/slate/test/queries/positions/range/block.js index 1a20c6f484..b3bae8ed8b 100644 --- a/packages/slate/test/queries/positions/point/block-multiple-reverse.js +++ b/packages/slate/test/queries/positions/range/block.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -12,20 +12,24 @@ export const input = ( export const run = editor => { return Array.from( - editor.positions({ reverse: true, point: { path: [2, 0], offset: 2 } }) + editor.positions({ + at: { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [2, 0], offset: 2 }, + }, + }) ) } export const output = [ - { path: [2, 0], offset: 2 }, - { path: [2, 0], offset: 1 }, - { path: [2, 0], offset: 0 }, - { path: [1, 0], offset: 3 }, - { path: [1, 0], offset: 2 }, - { path: [1, 0], offset: 1 }, - { path: [1, 0], offset: 0 }, - { path: [0, 0], offset: 3 }, - { path: [0, 0], offset: 2 }, { path: [0, 0], offset: 1 }, - { path: [0, 0], offset: 0 }, + { path: [0, 0], offset: 2 }, + { path: [0, 0], offset: 3 }, + { path: [1, 0], offset: 0 }, + { path: [1, 0], offset: 1 }, + { path: [1, 0], offset: 2 }, + { path: [1, 0], offset: 3 }, + { path: [2, 0], offset: 0 }, + { path: [2, 0], offset: 1 }, + { path: [2, 0], offset: 2 }, ] diff --git a/packages/slate/test/queries/positions/point/inline-multiple.js b/packages/slate/test/queries/positions/range/inline.js similarity index 80% rename from packages/slate/test/queries/positions/point/inline-multiple.js rename to packages/slate/test/queries/positions/range/inline.js index d28f326670..4c2c6eb75f 100644 --- a/packages/slate/test/queries/positions/point/inline-multiple.js +++ b/packages/slate/test/queries/positions/range/inline.js @@ -1,6 +1,6 @@ /** @jsx h */ -import { h } from '../../../../helpers' +import { h } from '../../../helpers' export const input = ( @@ -11,7 +11,14 @@ export const input = ( ) export const run = editor => { - return Array.from(editor.positions({ point: { path: [0, 0], offset: 2 } })) + return Array.from( + editor.positions({ + at: { + anchor: { path: [0, 0], offset: 2 }, + focus: { path: [0, 4], offset: 2 }, + }, + }) + ) } export const output = [ @@ -35,6 +42,4 @@ export const output = [ { path: [0, 4], offset: 0 }, { path: [0, 4], offset: 1 }, { path: [0, 4], offset: 2 }, - { path: [0, 4], offset: 3 }, - { path: [0, 4], offset: 4 }, ] diff --git a/packages/slate/test/queries/rootBlocks/block-nested.js b/packages/slate/test/queries/rootBlocks/block-nested.js deleted file mode 100644 index c9973946e1..0000000000 --- a/packages/slate/test/queries/rootBlocks/block-nested.js +++ /dev/null @@ -1,33 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - one - - - two - - -) - -export const run = editor => { - return Array.from(editor.rootBlocks()) -} - -export const output = [ - [ - - one - , - [0], - ], - [ - - two - , - [1], - ], -] diff --git a/packages/slate/test/queries/rootBlocks/block-void.js b/packages/slate/test/queries/rootBlocks/block-void.js deleted file mode 100644 index 659720e1cf..0000000000 --- a/packages/slate/test/queries/rootBlocks/block-void.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - one - - -) - -export const run = editor => { - return Array.from(editor.rootBlocks()) -} - -export const output = [ - [ - - one - , - [0], - ], -] diff --git a/packages/slate/test/queries/rootInlines/inline-multiple.js b/packages/slate/test/queries/rootInlines/inline-multiple.js deleted file mode 100644 index a3c64ea6f0..0000000000 --- a/packages/slate/test/queries/rootInlines/inline-multiple.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothreefourfive - - -) - -export const run = editor => { - return Array.from(editor.rootInlines()) -} - -export const output = [ - [two, [0, 1]], - [four, [0, 3]], -] diff --git a/packages/slate/test/queries/rootInlines/inline-reverse.js b/packages/slate/test/queries/rootInlines/inline-reverse.js deleted file mode 100644 index 1f8ce7d4c7..0000000000 --- a/packages/slate/test/queries/rootInlines/inline-reverse.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothreefourfive - - -) - -export const run = editor => { - return Array.from(editor.rootInlines({ reverse: true })) -} - -export const output = [ - [four, [0, 3]], - [two, [0, 1]], -] diff --git a/packages/slate/test/queries/rootInlines/inline-void.js b/packages/slate/test/queries/rootInlines/inline-void.js deleted file mode 100644 index 9ddbb9a2cc..0000000000 --- a/packages/slate/test/queries/rootInlines/inline-void.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from(editor.rootInlines()) -} - -export const output = [[two, [0, 1]]] From f03a00321b9f727599e87400e2f8410e0a012828 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 28 Oct 2019 22:50:23 -0400 Subject: [PATCH 077/165] fixing more delete logic --- packages/slate/src/classes/commands/node.ts | 211 +++++++++++------- packages/slate/src/classes/commands/text.ts | 86 +++---- .../slate/src/classes/queries/location.ts | 143 +++++++----- packages/slate/src/classes/queries/value.ts | 153 ++++++------- packages/slate/src/interfaces/node.ts | 154 ++----------- packages/slate/src/interfaces/range.ts | 12 +- packages/slate/src/interfaces/value.ts | 40 ++-- .../commands/delete/point/inline-before.js | 2 - .../Node/descendants/{path.js => from.js} | 2 +- .../test/interfaces/Node/descendants/point.js | 30 --- .../Node/descendants/{range.js => to.js} | 13 +- .../Node/entries/{path.js => from.js} | 12 +- .../Node/entries/{range.js => to.js} | 12 +- .../Node/marks/{path.js => from.js} | 2 +- .../interfaces/Node/marks/{range.js => to.js} | 12 +- .../Node/texts/{path.js => from.js} | 2 +- .../interfaces/Node/texts/{range.js => to.js} | 12 +- packages/slate/test/queries/blocks/at-path.js | 17 -- .../slate/test/queries/blocks/at-range.js | 21 -- .../test/queries/blocks/block-multiple.js | 21 -- .../slate/test/queries/blocks/block-nested.js | 36 --- .../test/queries/blocks/block-reverse.js | 21 -- .../slate/test/queries/blocks/block-void.js | 24 -- packages/slate/test/queries/blocks/block.js | 15 -- packages/slate/test/queries/blocks/inline.js | 24 -- .../slate/test/queries/getPath/range-end.js | 2 +- packages/slate/test/queries/getPath/range.js | 2 +- packages/slate/test/queries/inlines/block.js | 15 -- .../test/queries/inlines/inline-multiple.js | 20 -- .../test/queries/inlines/inline-nested.js | 27 --- .../test/queries/inlines/inline-reverse.js | 20 -- .../slate/test/queries/inlines/inline-void.js | 17 -- packages/slate/test/queries/inlines/inline.js | 17 -- 33 files changed, 400 insertions(+), 797 deletions(-) rename packages/slate/test/interfaces/Node/descendants/{path.js => from.js} (85%) delete mode 100644 packages/slate/test/interfaces/Node/descendants/point.js rename packages/slate/test/interfaces/Node/descendants/{range.js => to.js} (76%) rename packages/slate/test/interfaces/Node/entries/{path.js => from.js} (75%) rename packages/slate/test/interfaces/Node/entries/{range.js => to.js} (81%) rename packages/slate/test/interfaces/Node/marks/{path.js => from.js} (85%) rename packages/slate/test/interfaces/Node/marks/{range.js => to.js} (73%) rename packages/slate/test/interfaces/Node/texts/{path.js => from.js} (83%) rename packages/slate/test/interfaces/Node/texts/{range.js => to.js} (71%) delete mode 100644 packages/slate/test/queries/blocks/at-path.js delete mode 100644 packages/slate/test/queries/blocks/at-range.js delete mode 100644 packages/slate/test/queries/blocks/block-multiple.js delete mode 100644 packages/slate/test/queries/blocks/block-nested.js delete mode 100644 packages/slate/test/queries/blocks/block-reverse.js delete mode 100644 packages/slate/test/queries/blocks/block-void.js delete mode 100644 packages/slate/test/queries/blocks/block.js delete mode 100644 packages/slate/test/queries/blocks/inline.js delete mode 100644 packages/slate/test/queries/inlines/block.js delete mode 100644 packages/slate/test/queries/inlines/inline-multiple.js delete mode 100644 packages/slate/test/queries/inlines/inline-nested.js delete mode 100644 packages/slate/test/queries/inlines/inline-reverse.js delete mode 100644 packages/slate/test/queries/inlines/inline-void.js delete mode 100644 packages/slate/test/queries/inlines/inline.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index 2ed744aec4..fed2bc0ff5 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -172,16 +172,24 @@ class NodeCommands { options: { at?: Location match?: Match + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { let { at = this.value.selection } = options - const { match = Path.isPath(at) ? at.length : 'block' } = options + const { + match = Path.isPath(at) ? at.length : 'block', + hanging = false, + } = options if (!at) { return } + if (!hanging && Range.isRange(at)) { + at = unhangRange(this, at) + } + if (Range.isRange(at)) { if (Range.isCollapsed(at)) { at = at.anchor @@ -197,85 +205,87 @@ class NodeCommands { } } - for (const [node, path] of this.matches({ at, match })) { - const prev = this.getPrevious(at, match) - - if (!prev) { - return - } - - const [prevNode, prevPath] = prev - const newPath = Path.next(prevPath) - const commonPath = Path.common(path, prevPath) - const isPreviousSibling = Path.isSibling(path, prevPath) - - // Determine if the merge will leave an ancestor of the path empty as a - // result, in which case we'll want to remove it after merging. - const emptyAncestor = Node.furthest(this.value, path, ([n, p]) => { - return ( - Path.isDescendant(p, commonPath) && - Path.isAncestor(p, path) && - Element.isElement(n) && - n.nodes.length === 1 - ) - }) - - const emptyRef = emptyAncestor && this.createPathRef(emptyAncestor[1]) - let properties - let position - - // Ensure that the nodes are equivalent, and figure out what the position - // and extra properties of the merge will be. - if (Text.isText(node) && Text.isText(prevNode)) { - const { text, marks, ...rest } = node - position = prevNode.text.length - properties = rest as Partial - } else if (Element.isElement(node) && Element.isElement(prevNode)) { - const { nodes, ...rest } = node - position = prevNode.nodes.length - properties = rest as Partial - } else { - throw new Error( - `Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify( - node - )} ${JSON.stringify(prevNode)}` - ) - } + const current = this.getMatch(at, match) + const prev = this.getPrevious(at, match) + debugger - // If the node isn't already the next sibling of the previous node, move - // it so that it is before merging. - if (!isPreviousSibling) { - this.moveNodes({ at: path, to: newPath }) - } + if (!current || !prev) { + return + } - // If there was going to be an empty ancestor of the node that was merged, - // we remove it from the tree. - if (emptyRef) { - this.removeNodes({ at: emptyRef.current! }) - } + debugger + const [node, path] = current + const [prevNode, prevPath] = prev + const newPath = Path.next(prevPath) + const commonPath = Path.common(path, prevPath) + const isPreviousSibling = Path.isSibling(path, prevPath) + + // Determine if the merge will leave an ancestor of the path empty as a + // result, in which case we'll want to remove it after merging. + const emptyAncestor = Node.furthest(this.value, path, ([n, p]) => { + return ( + Path.isDescendant(p, commonPath) && + Path.isAncestor(p, path) && + Element.isElement(n) && + n.nodes.length === 1 + ) + }) + + const emptyRef = emptyAncestor && this.createPathRef(emptyAncestor[1]) + let properties + let position - // If the target node that we're merging with is empty, remove it instead - // of merging the two. This is a common rich text editor behavior to - // prevent losing formatting when deleting entire nodes when you have a - // hanging selection. - if ( - (Element.isElement(prevNode) && this.isEmpty(prevNode)) || - (Text.isText(prevNode) && prevNode.text === '') - ) { - this.removeNodes({ at: prevPath }) - } else { - this.apply({ - type: 'merge_node', - path: newPath, - position, - target: null, - properties, - }) - } + // Ensure that the nodes are equivalent, and figure out what the position + // and extra properties of the merge will be. + if (Text.isText(node) && Text.isText(prevNode)) { + const { text, marks, ...rest } = node + position = prevNode.text.length + properties = rest as Partial + } else if (Element.isElement(node) && Element.isElement(prevNode)) { + const { nodes, ...rest } = node + position = prevNode.nodes.length + properties = rest as Partial + } else { + throw new Error( + `Cannot merge the node at path [${path}] with the previous sibling because it is not the same kind: ${JSON.stringify( + node + )} ${JSON.stringify(prevNode)}` + ) + } + + // If the node isn't already the next sibling of the previous node, move + // it so that it is before merging. + if (!isPreviousSibling) { + this.moveNodes({ at: path, to: newPath }) + } + + // If there was going to be an empty ancestor of the node that was merged, + // we remove it from the tree. + if (emptyRef) { + this.removeNodes({ at: emptyRef.current! }) + } + + // If the target node that we're merging with is empty, remove it instead + // of merging the two. This is a common rich text editor behavior to + // prevent losing formatting when deleting entire nodes when you have a + // hanging selection. + if ( + (Element.isElement(prevNode) && this.isEmpty(prevNode)) || + (Text.isText(prevNode) && prevNode.text === '') + ) { + this.removeNodes({ at: prevPath }) + } else { + this.apply({ + type: 'merge_node', + path: newPath, + position, + target: null, + properties, + }) + } - if (emptyRef) { - emptyRef.unref() - } + if (emptyRef) { + emptyRef.unref() } }) } @@ -416,18 +426,24 @@ class NodeCommands { options: { at?: Location match?: Match + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { + let { at = this.value.selection } = options const { - at = this.value.selection, match = Path.isPath(at) ? at.length : 'block', + hanging = false, } = options if (!at) { return } + if (!hanging && Range.isRange(at)) { + at = unhangRange(this, at) + } + const depths = this.matches({ at, match }) const pathRefs = Array.from(depths, ([, p]) => this.createPathRef(p)) @@ -449,18 +465,24 @@ class NodeCommands { options: { at?: Location match?: Match + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { + let { at = this.value.selection } = options const { - at = this.value.selection, match = Path.isPath(at) ? at.length : 'block', + hanging = false, } = options if (!at) { return } + if (!hanging && Range.isRange(at)) { + at = unhangRange(this, at) + } + for (const [node, path] of this.matches({ at, match })) { const properties: Partial = {} const newProperties: Partial = {} @@ -707,4 +729,37 @@ class NodeCommands { } } +/** + * Convert a range into a non-hanging one. + */ + +const unhangRange = (editor: Editor, range: Range): Range => { + let [start, end] = Range.edges(range) + + // PERF: exit early if we can guarantee that the range isn't hanging. + if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) { + return range + } + + const closestBlock = editor.getMatch(end.path, 'block') + const blockPath = closestBlock ? closestBlock[1] : [] + const first = editor.getStart() + const before = { anchor: first, focus: end } + let skip = true + + for (const [node, path] of editor.texts({ at: before, reverse: true })) { + if (skip) { + skip = false + continue + } + + if (node.text !== '' || Path.isBefore(path, blockPath)) { + end = { path, offset: node.text.length } + break + } + } + + return { anchor: start, focus: end } +} + export default NodeCommands diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 77939c6913..e26a3a1016 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -2,6 +2,7 @@ import { Editor, Element, Node, + PathRef, Fragment, Path, Location, @@ -25,16 +26,11 @@ class DeletingCommands { } = {} ) { this.withoutNormalizing(() => { - const { selection } = this.value const { reverse = false, unit = 'character', distance = 1 } = options - let { at } = options - let isSelection = false - let ancestorPath: Path = [] - let ancestor: Node = this.value + let { at = this.value.selection } = options - if (!at && selection) { - at = selection - isSelection = true + if (!at) { + return } if (Range.isRange(at) && Range.isCollapsed(at)) { @@ -50,58 +46,46 @@ class DeletingCommands { } else { const opts = { unit, distance } const target = reverse - ? this.getBefore(at, opts) - : this.getAfter(at, opts) - - if (target) { - at = { anchor: at, focus: target } - } + ? this.getBefore(at, opts) || this.getStart() + : this.getAfter(at, opts) || this.getEnd() + at = { anchor: at, focus: target } } } - if (Range.isRange(at)) { - const [start, end] = Range.edges(at) - const [, ancestorPath] = this.getAncestor(at) - const d = Range.isCollapsed(at) ? 'text' : ancestorPath.length - const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) - this.splitNodes({ at: end, match: d, always: true }) - this.splitNodes({ at: start, match: d, always: true }) - at = rangeRef.unref()! - } - if (Path.isPath(at)) { - const node = Node.get(this.value, at) - this.apply({ type: 'remove_node', path: at, node }) + this.removeNodes({ at }) + return } - if (Range.isRange(at)) { - const [start, end] = Range.edges(at) - const after = this.getAfter(end)! - const afterRef = this.createPointRef(after) - const l = ancestorPath.length - const startIndex = start.path[l] - const endIndex = end.path[l] - const hasBlocks = - Value.isValue(ancestor) || - (Element.isElement(ancestor) && this.hasBlocks(ancestor)) - - // Iterate backwards so the paths are unaffected. - for (let i = endIndex; i >= startIndex; i--) { - const path = ancestorPath.concat(i) - const node = Node.get(this.value, path) - this.apply({ type: 'remove_node', path, node }) - } - - if (hasBlocks) { - this.mergeNodes({ at: afterRef.current!.path }) - } + if (Range.isCollapsed(at)) { + return + } - if (isSelection) { - this.select(afterRef.current!) - } + const [start, end] = Range.edges(at) + const [ancestor, ancestorPath] = this.getAncestor(at) + const depth = ancestorPath.length + 1 + const afterRef = this.createPointRef(end) + const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) + debugger + this.splitNodes({ at: end, match: depth, always: true }) + this.splitNodes({ at: start, match: depth, always: true }) + const range = rangeRef.unref()! + debugger + this.removeNodes({ at: range, match: depth, hanging: true }) + + debugger + if ( + Value.isValue(ancestor) || + (Element.isElement(ancestor) && !this.isInline(ancestor)) + ) { + this.mergeNodes({ at: afterRef.current!, hanging: true }) + } - afterRef.unref() + if (options.at == null) { + this.select(afterRef.current!) } + + afterRef.unref() }) } diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 2f71ee9ad3..3faca1a65f 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -84,8 +84,8 @@ class LocationQueries { unit?: 'offset' | 'character' | 'word' | 'line' | 'block' } = {} ): Point | undefined { - const focus = this.getPoint(at, { edge: 'start' }) const anchor = this.getStart() + const focus = this.getPoint(at, { edge: 'start' }) const range = { anchor, focus } const { distance = 1 } = options let d = 0 @@ -128,7 +128,7 @@ class LocationQueries { getMatch(this: Editor, at: Location, match: Match): NodeEntry | undefined { // PERF: If the target is a path and the match is a depth, don't traverse. - if (Path.isPath(at) && typeof match === 'number' && match <= at.length) { + if (typeof match === 'number' && match <= at.length && Path.isPath(at)) { const p = at.slice(0, match) return this.getNode(p) } @@ -147,13 +147,15 @@ class LocationQueries { */ getNext(this: Editor, at: Location, match: Match): NodeEntry | undefined { - const point = this.getAfter(at) + let i = 0 - if (!point) { - return - } + for (const entry of this.matches({ at, match })) { + if (i === 1) { + return entry + } - return this.getMatch(point, match) + i++ + } } /** @@ -203,8 +205,37 @@ class LocationQueries { edge?: 'start' | 'end' } = {} ): Path { - const path = Node.path(this.value, at, options) - return path + const { depth, edge } = options + + if (Path.isPath(at)) { + if (edge === 'start') { + const [, firstPath] = Node.first(this.value, at) + at = firstPath + } else if (edge === 'end') { + const [, lastPath] = Node.last(this.value, at) + at = lastPath + } + } + + if (Range.isRange(at)) { + if (edge === 'start') { + at = Range.start(at) + } else if (edge === 'end') { + at = Range.end(at) + } else { + at = Path.common(at.anchor.path, at.focus.path) + } + } + + if (Point.isPoint(at)) { + at = at.path + } + + if (depth != null) { + at = at.slice(0, depth) + } + + return at } /** @@ -218,8 +249,36 @@ class LocationQueries { edge?: 'start' | 'end' } = {} ): Point { - const point = Node.point(this.value, at, options) - return point + const { edge = 'start' } = options + + if (Path.isPath(at)) { + let path + + if (edge === 'end') { + const [, lastPath] = Node.last(this.value, at) + path = lastPath + } else { + const [, firstPath] = Node.first(this.value, at) + path = firstPath + } + + const node = Node.get(this.value, path) + + if (!Text.isText(node)) { + throw new Error( + `Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.` + ) + } + + return { path, offset: edge === 'end' ? node.text.length : 0 } + } + + if (Range.isRange(at)) { + const [start, end] = Range.edges(at) + return edge === 'start' ? start : end + } + + return at } /** @@ -227,61 +286,29 @@ class LocationQueries { */ getPrevious(this: Editor, at: Location, match: Match): NodeEntry | undefined { - const point = this.getBefore(at) + const first = this.getStart(at) + const start = this.getStart() + const range = { anchor: start, focus: first } + let i = 0 + + for (const entry of this.matches({ at: range, match, reverse: true })) { + debugger + if (i === 1) { + return entry + } - if (!point) { - return + i++ } - - return this.getMatch(point, match) } /** * Get a range of a location. */ - getRange( - this: Editor, - at: Location = [], - options: { - to?: Location - hanging?: boolean - } = {} - ): Range { - const { to, hanging = false } = options - const range = Node.range(this.value, at, to) - - // PERF: exit early if we can guarantee that the range isn't hanging, or - // that they don't mind receiving hanging ranges. - if ( - hanging || - range.anchor.offset !== 0 || - range.focus.offset !== 0 || - Range.isCollapsed(range) - ) { - return range - } - - let [start, end] = Range.edges(range) - const closestBlock = this.getMatch(end.path, 'block') - const blockPath = closestBlock ? closestBlock[1] : [] - const last = this.getEnd() - const rest = { anchor: end, focus: last } - let skip = true - - for (const [node, path] of this.texts({ at: rest, reverse: true })) { - if (skip) { - skip = false - continue - } - - if (node.text !== '' || Path.isBefore(path, blockPath)) { - const point = { path, offset: node.text.length } - return { anchor: start, focus: point } - } - } - - return range + getRange(this: Editor, at: Location = [], to: Location = at): Range { + const start = this.getStart(at) + const end = this.getEnd(to) + return { anchor: start, focus: end } } /** diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts index f43ac7c456..7f0fb4982f 100644 --- a/packages/slate/src/classes/queries/value.ts +++ b/packages/slate/src/classes/queries/value.ts @@ -31,18 +31,13 @@ class ValueQueries { } = {} ): Iterable { const { annotations } = this.value - let { at } = options - - if (Path.isPath(at)) { - at = this.getRange(at) - } else if (Point.isPoint(at)) { - at = { anchor: at, focus: at } - } + const { at } = options + const range = this.getRange(at) for (const key in annotations) { const annotation = annotations[key] - if (at && !Range.includes(at, annotation)) { + if (at && !Range.includes(range, annotation)) { continue } @@ -51,23 +46,9 @@ class ValueQueries { } /** - * Iterate through all of the block nodes in the editor. + * Check if a node is a match. */ - *blocks( - this: Editor, - options: { - at?: Location - reverse?: boolean - } = {} - ): Iterable { - yield* Node.elements(this.value, { - ...options, - pass: ([n]) => - Element.isElement(n) && (this.isVoid(n) || this.hasInlines(n)), - }) - } - isMatch(this: Editor, entry: NodeEntry, match: Match) { const [node, path] = entry @@ -94,15 +75,20 @@ class ValueQueries { } } + /** + * Iterate through all of the levels at a location. + */ + *levels( this: Editor, - path: Path, + at: Location, options: { reverse?: boolean } = {} ): Iterable { const { reverse = false } = options const levels: NodeEntry[] = [] + const path = this.getPath(at) for (const [n, p] of Node.levels(this.value, path)) { levels.push([n, p]) @@ -119,44 +105,6 @@ class ValueQueries { yield* levels } - *matches( - this: Editor, - options: { - match: Match - at: Location - hanging?: boolean - reverse?: boolean - } - ): Iterable { - const { reverse, match, hanging } = options - let { at } = options - let prevPath: Path | undefined - - // PERF: If the target is a path, don't traverse. - if (Path.isPath(at)) { - const m = this.getMatch(at, match) - - if (m) { - yield m - } - - return - } - - at = this.getRange(at, { hanging }) - - for (const [n, p] of this.entries({ at, reverse })) { - if (prevPath && Path.compare(p, prevPath) === 0) { - continue - } - - if (this.isMatch([n, p], match)) { - prevPath = p - yield [n, p] - } - } - } - /** * Iterate through all of the elements in the editor. */ @@ -168,8 +116,14 @@ class ValueQueries { reverse?: boolean } = {} ): Iterable { + const { at } = options + const range = this.getRange(at) + const [from, to] = Range.edges(range, options) + yield* Node.elements(this.value, { ...options, + from: from.path, + to: to.path, pass: ([n]) => Element.isElement(n) && this.isVoid(n), }) } @@ -185,8 +139,14 @@ class ValueQueries { reverse?: boolean } = {} ): Iterable { + const { at } = options + const range = this.getRange(at) + const [from, to] = Range.edges(range, options) + yield* Node.entries(this.value, { ...options, + from: from.path, + to: to.path, pass: ([n]) => Element.isElement(n) && this.isVoid(n), }) } @@ -274,38 +234,67 @@ class ValueQueries { } /** - * Iterate through all of the inline nodes in the editor. + * Iterate through all of the text nodes in the editor. */ - *inlines( + *marks( this: Editor, options: { at?: Location reverse?: boolean } = {} - ): Iterable { - for (const [n, p] of this.elements(options)) { - if (this.isInline(n)) { - yield [n, p] - } - } + ): Iterable { + const { at } = options + const range = this.getRange(at) + const [from, to] = Range.edges(range, options) + + yield* Node.marks(this.value, { + ...options, + from: from.path, + to: to.path, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) } /** - * Iterate through all of the text nodes in the editor. + * Iterate through all of the nodes that match. */ - *marks( + *matches( this: Editor, options: { - at?: Location + match: Match + at: Location reverse?: boolean - } = {} - ): Iterable { - yield* Node.marks(this.value, { - ...options, - pass: ([n]) => Element.isElement(n) && this.isVoid(n), - }) + } + ): Iterable { + const { reverse, match } = options + let { at } = options + let prevPath: Path | undefined + + // PERF: If the target is a path, don't traverse. + if (Path.isPath(at)) { + const m = this.getMatch(at, match) + + if (m) { + yield m + } + + return + } + + at = this.getRange(at) + + for (const [n, p] of this.entries({ at, reverse })) { + if (prevPath && Path.compare(p, prevPath) === 0) { + continue + } + + if (this.isMatch([n, p], match)) { + prevPath = p + yield [n, p] + } + } } /** @@ -434,8 +423,14 @@ class ValueQueries { reverse?: boolean } = {} ): Iterable { + const { at } = options + const range = this.getRange(at) + const [from, to] = Range.edges(range, options) + yield* Node.texts(this.value, { ...options, + from: from.path, + to: to.path, pass: ([n]) => Element.isElement(n) && this.isVoid(n), }) } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index ca90611c84..608c81c65c 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -3,13 +3,11 @@ import { Element, ElementEntry, Fragment, - Location, MarkEntry, Path, Range, Text, TextEntry, - Point, Value, } from '..' @@ -177,7 +175,8 @@ namespace Node { export function* descendants( root: Node, options: { - at?: Location + from?: Path + to?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -200,7 +199,8 @@ namespace Node { export function* elements( root: Node, options: { - at?: Location + from?: Path + to?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -212,15 +212,6 @@ namespace Node { } } - /** - * Get the end point of a location inside the root node. - */ - - export const end = (root: Node, at: Location): Point => { - const end = Node.point(root, at, { edge: 'end' }) - return end - } - /** * Return an iterable of all the node entries of a root node. Each entry is * returned as a `[Node, Path]` tuple, with the path referring to the node's @@ -230,25 +221,28 @@ namespace Node { export function* entries( root: Node, options: { - at?: Location + from?: Path + to?: Path reverse?: boolean pass?: (entry: NodeEntry) => boolean } = {} ): Iterable { - const { at = [], pass, reverse = false } = options - const startPath = Node.path(root, at, { edge: 'start' }) - const endPath = Node.path(root, at, { edge: 'end' }) - const fromPath = reverse ? endPath : startPath - const toPath = reverse ? startPath : endPath + const { pass, reverse = false } = options + let { from = [], to } = options + const start = reverse ? Node.last(root, from) : Node.first(root, from) + from = start[1] + + if (to != null) { + const end = reverse ? Node.first(root, to) : Node.last(root, to) + to = end[1] + } + const visited = new Set() let p: Path = [] let n = root while (true) { - if ( - (!reverse && Path.isAfter(p, toPath)) || - (reverse && Path.isBefore(p, toPath)) - ) { + if (to && (reverse ? Path.isBefore(p, to) : Path.isAfter(p, to))) { break } @@ -266,8 +260,8 @@ namespace Node { visited.add(n) let nextIndex = reverse ? n.nodes.length - 1 : 0 - if (Path.isAncestor(p, fromPath)) { - nextIndex = fromPath[p.length] + if (Path.isAncestor(p, from)) { + nextIndex = from[p.length] } p = p.concat(nextIndex) @@ -505,7 +499,8 @@ namespace Node { export function* marks( root: Node, options: { - at?: Location + from?: Path + to?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} @@ -535,110 +530,6 @@ namespace Node { return parent } - /** - * Get the path of a location inside the root node. - */ - - export const path = ( - root: Node, - at: Location, - options: { - depth?: number - edge?: 'start' | 'end' - } - ): Path => { - const { depth, edge } = options - - if (Path.isPath(at)) { - if (edge === 'start') { - const [, firstPath] = Node.first(root, at) - at = firstPath - } else if (edge === 'end') { - const [, lastPath] = Node.last(root, at) - at = lastPath - } - } - - if (Range.isRange(at)) { - if (edge === 'start') { - at = Range.start(at) - } else if (edge === 'end') { - at = Range.end(at) - } else { - at = Path.common(at.anchor.path, at.focus.path) - } - } - - if (Point.isPoint(at)) { - at = at.path - } - - if (depth != null) { - at = at.slice(0, depth) - } - - return at - } - - /** - * Get the start of end point of a location inside the root node. - */ - - export const point = ( - root: Node, - at: Location, - options: { - edge?: 'start' | 'end' - } - ): Point => { - const { edge = 'start' } = options - - if (Path.isPath(at)) { - debugger - const path = Node.path(root, at, { edge }) - const node = Node.get(root, path) - - if (!Text.isText(node)) { - debugger - throw new Error( - `Cannot get the ${edge} point in the node at path [${at}] because it has no ${edge} text node.` - ) - } - - return { path, offset: edge === 'start' ? 0 : node.text.length } - } - - if (Range.isRange(at)) { - const [start, end] = Range.edges(at) - return edge === 'start' ? start : end - } - - return at - } - - /** - * Get the range from one location to another inside the root node. - */ - - export const range = ( - root: Node, - from: Location, - to: Location = from - ): Range => { - const anchor = Node.start(root, from) - const focus = Node.end(root, to) - return { anchor, focus } - } - - /** - * Get the start point of a location inside the root node. - */ - - export const start = (root: Node, at: Location): Point => { - const start = Node.point(root, at, { edge: 'start' }) - return start - } - /** * Get the concatenated text string of a node's content. * @@ -662,7 +553,8 @@ namespace Node { export function* texts( root: Node, options: { - at?: Location + from?: Path + to?: Path reverse?: boolean pass?: (node: NodeEntry) => boolean } = {} diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index d553639878..910700de04 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -136,9 +136,17 @@ namespace Range { * in the document. */ - export const edges = (range: Range): [Point, Point] => { + export const edges = ( + range: Range, + options: { + reverse?: boolean + } = {} + ): [Point, Point] => { + const { reverse = false } = options const { anchor, focus } = range - return Range.isBackward(range) ? [focus, anchor] : [anchor, focus] + return Range.isBackward(range) === reverse + ? [anchor, focus] + : [focus, anchor] } /** diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index d2ebe75398..771416f1f3 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -243,14 +243,8 @@ namespace Value { const { path } = op const index = path[path.length - 1] const parent = Node.parent(v, path) - const rootStart = Node.start(v, []) - const rootEnd = Node.end(v, []) - const nodeStart = Node.start(v, path) - const nodeEnd = Node.end(v, path) - const before = { anchor: rootStart, focus: nodeStart } - const after = { anchor: nodeEnd, focus: rootEnd } - const [, prev] = Node.texts(v, { at: before, reverse: true }) - const [, next] = Node.texts(v, { at: after }) + const [, prev] = Node.texts(v, { from: path, reverse: true }) + const [, next] = Node.texts(v, { from: path }) parent.nodes.splice(index, 1) // Transform all of the points in the value, but if the point was in the @@ -258,23 +252,21 @@ namespace Value { for (const [point, k, range, key] of Value.points(v)) { const result = Point.transform(point, op) - if (result == null) { - if (prev) { - const [prevNode, prevPath] = prev - point.path = prevPath - point.offset = prevNode.text.length - } else if (next) { - const [, nextPath] = next - const newNextPath = Path.transform(nextPath, op)! - point.path = newNextPath - point.offset = 0 - } else if (key != null) { - delete v.annotations[key!] - } else { - v.selection = null - } - } else { + if (result != null) { range[k] = result + } else if (prev) { + const [prevNode, prevPath] = prev + point.path = prevPath + point.offset = prevNode.text.length + } else if (next) { + const [, nextPath] = next + const newNextPath = Path.transform(nextPath, op)! + point.path = newNextPath + point.offset = 0 + } else if (key != null) { + delete v.annotations[key] + } else { + v.selection = null } } diff --git a/packages/slate/test/commands/delete/point/inline-before.js b/packages/slate/test/commands/delete/point/inline-before.js index 6cd8749361..9ad8fee384 100644 --- a/packages/slate/test/commands/delete/point/inline-before.js +++ b/packages/slate/test/commands/delete/point/inline-before.js @@ -32,5 +32,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/interfaces/Node/descendants/path.js b/packages/slate/test/interfaces/Node/descendants/from.js similarity index 85% rename from packages/slate/test/interfaces/Node/descendants/path.js rename to packages/slate/test/interfaces/Node/descendants/from.js index 1f052a774d..49d4cac85a 100644 --- a/packages/slate/test/interfaces/Node/descendants/path.js +++ b/packages/slate/test/interfaces/Node/descendants/from.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.descendants(value, { at: [0, 1] })) + return Array.from(Node.descendants(value, { from: [0, 1] })) } export const output = [ diff --git a/packages/slate/test/interfaces/Node/descendants/point.js b/packages/slate/test/interfaces/Node/descendants/point.js deleted file mode 100644 index 829561c765..0000000000 --- a/packages/slate/test/interfaces/Node/descendants/point.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import { Node } from 'slate' -import h from 'slate-hyperscript' - -export const input = ( - - - - - - -) - -export const test = value => { - return Array.from( - Node.descendants(value, { at: { path: [0, 1], offset: 0 } }) - ) -} - -export const output = [ - [ - - - - , - [0], - ], - [, [0, 1]], -] diff --git a/packages/slate/test/interfaces/Node/descendants/range.js b/packages/slate/test/interfaces/Node/descendants/to.js similarity index 76% rename from packages/slate/test/interfaces/Node/descendants/range.js rename to packages/slate/test/interfaces/Node/descendants/to.js index 9e18bd5469..e75e8470e5 100644 --- a/packages/slate/test/interfaces/Node/descendants/range.js +++ b/packages/slate/test/interfaces/Node/descendants/to.js @@ -17,16 +17,8 @@ export const input = ( export const test = value => { return Array.from( Node.descendants(value, { - at: { - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, - }, + from: [0, 1], + to: [0, 2], }) ) } @@ -42,4 +34,5 @@ export const output = [ [0], ], [, [0, 1]], + [, [0, 2]], ] diff --git a/packages/slate/test/interfaces/Node/entries/path.js b/packages/slate/test/interfaces/Node/entries/from.js similarity index 75% rename from packages/slate/test/interfaces/Node/entries/path.js rename to packages/slate/test/interfaces/Node/entries/from.js index 860b099143..df5af942ff 100644 --- a/packages/slate/test/interfaces/Node/entries/path.js +++ b/packages/slate/test/interfaces/Node/entries/from.js @@ -17,7 +17,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.entries(value, { at: [0] })) + return Array.from(Node.entries(value, { from: [0, 1] })) } export const output = [ @@ -41,6 +41,14 @@ export const output = [ , [0], ], - [, [0, 0]], [, [0, 1]], + [ + + + + , + [1], + ], + [, [1, 0]], + [, [1, 1]], ] diff --git a/packages/slate/test/interfaces/Node/entries/range.js b/packages/slate/test/interfaces/Node/entries/to.js similarity index 81% rename from packages/slate/test/interfaces/Node/entries/range.js rename to packages/slate/test/interfaces/Node/entries/to.js index eff10a7ee0..f1a3c2bd34 100644 --- a/packages/slate/test/interfaces/Node/entries/range.js +++ b/packages/slate/test/interfaces/Node/entries/to.js @@ -17,16 +17,8 @@ export const input = ( export const test = value => { return Array.from( Node.entries(value, { - at: { - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 2], - offset: 0, - }, - }, + from: [0, 1], + to: [0, 2], }) ) } diff --git a/packages/slate/test/interfaces/Node/marks/path.js b/packages/slate/test/interfaces/Node/marks/from.js similarity index 85% rename from packages/slate/test/interfaces/Node/marks/path.js rename to packages/slate/test/interfaces/Node/marks/from.js index 2f8181f33c..b982533e1d 100644 --- a/packages/slate/test/interfaces/Node/marks/path.js +++ b/packages/slate/test/interfaces/Node/marks/from.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.marks(value, { at: [0, 1] })) + return Array.from(Node.marks(value, { from: [0, 1] })) } export const output = [[{ key: 'b' }, 0, two, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/marks/range.js b/packages/slate/test/interfaces/Node/marks/to.js similarity index 73% rename from packages/slate/test/interfaces/Node/marks/range.js rename to packages/slate/test/interfaces/Node/marks/to.js index 9c61bd2978..729ecf1a59 100644 --- a/packages/slate/test/interfaces/Node/marks/range.js +++ b/packages/slate/test/interfaces/Node/marks/to.js @@ -16,16 +16,8 @@ export const input = ( export const test = value => { return Array.from( Node.marks(value, { - at: { - anchor: { - path: [0, 0], - offset: 0, - }, - focus: { - path: [0, 1], - offset: 0, - }, - }, + from: [0, 0], + to: [0, 1], }) ) } diff --git a/packages/slate/test/interfaces/Node/texts/path.js b/packages/slate/test/interfaces/Node/texts/from.js similarity index 83% rename from packages/slate/test/interfaces/Node/texts/path.js rename to packages/slate/test/interfaces/Node/texts/from.js index af835df35b..30b8963c4d 100644 --- a/packages/slate/test/interfaces/Node/texts/path.js +++ b/packages/slate/test/interfaces/Node/texts/from.js @@ -13,7 +13,7 @@ export const input = ( ) export const test = value => { - return Array.from(Node.texts(value, { at: [0, 1] })) + return Array.from(Node.texts(value, { from: [0, 1] })) } export const output = [[, [0, 1]]] diff --git a/packages/slate/test/interfaces/Node/texts/range.js b/packages/slate/test/interfaces/Node/texts/to.js similarity index 71% rename from packages/slate/test/interfaces/Node/texts/range.js rename to packages/slate/test/interfaces/Node/texts/to.js index 9db4722845..02c927a55e 100644 --- a/packages/slate/test/interfaces/Node/texts/range.js +++ b/packages/slate/test/interfaces/Node/texts/to.js @@ -17,16 +17,8 @@ export const input = ( export const test = value => { return Array.from( Node.texts(value, { - at: { - anchor: { - path: [0, 1], - offset: 0, - }, - focus: { - path: [0, 2], - offset: 0, - }, - }, + from: [0, 1], + to: [0, 2], }) ) } diff --git a/packages/slate/test/queries/blocks/at-path.js b/packages/slate/test/queries/blocks/at-path.js deleted file mode 100644 index 7a87a5ba43..0000000000 --- a/packages/slate/test/queries/blocks/at-path.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - one - two - three - -) - -export const run = editor => { - return Array.from(editor.blocks({ at: [1] })) -} - -export const output = [[two, [1]]] diff --git a/packages/slate/test/queries/blocks/at-range.js b/packages/slate/test/queries/blocks/at-range.js deleted file mode 100644 index 32276bcc11..0000000000 --- a/packages/slate/test/queries/blocks/at-range.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - one - two - three - -) - -export const run = editor => { - return Array.from( - editor.blocks({ - at: { anchor: { path: [1], offset: 0 }, focus: { path: [1], offset: 3 } }, - }) - ) -} - -export const output = [[two, [1]]] diff --git a/packages/slate/test/queries/blocks/block-multiple.js b/packages/slate/test/queries/blocks/block-multiple.js deleted file mode 100644 index 5c7bd9f003..0000000000 --- a/packages/slate/test/queries/blocks/block-multiple.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - one - two - three - -) - -export const run = editor => { - return Array.from(editor.blocks()) -} - -export const output = [ - [one, [0]], - [two, [1]], - [three, [2]], -] diff --git a/packages/slate/test/queries/blocks/block-nested.js b/packages/slate/test/queries/blocks/block-nested.js deleted file mode 100644 index 5f6f4233cb..0000000000 --- a/packages/slate/test/queries/blocks/block-nested.js +++ /dev/null @@ -1,36 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - one - - - two - - -) - -export const run = editor => { - return Array.from(editor.blocks()) -} - -export const output = [ - [ - - one - , - [0], - ], - [one, [0, 0]], - [ - - two - , - [1], - ], - - [two, [1, 0]], -] diff --git a/packages/slate/test/queries/blocks/block-reverse.js b/packages/slate/test/queries/blocks/block-reverse.js deleted file mode 100644 index 64511896df..0000000000 --- a/packages/slate/test/queries/blocks/block-reverse.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - one - two - three - -) - -export const run = editor => { - return Array.from(editor.blocks({ reverse: true })) -} - -export const output = [ - [three, [2]], - [two, [1]], - [one, [0]], -] diff --git a/packages/slate/test/queries/blocks/block-void.js b/packages/slate/test/queries/blocks/block-void.js deleted file mode 100644 index fe20f3c614..0000000000 --- a/packages/slate/test/queries/blocks/block-void.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - one - - -) - -export const run = editor => { - return Array.from(editor.blocks()) -} - -export const output = [ - [ - - one - , - [0], - ], -] diff --git a/packages/slate/test/queries/blocks/block.js b/packages/slate/test/queries/blocks/block.js deleted file mode 100644 index 8d6e4c8c5b..0000000000 --- a/packages/slate/test/queries/blocks/block.js +++ /dev/null @@ -1,15 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - one - -) - -export const run = editor => { - return Array.from(editor.blocks()) -} - -export const output = [[one, [0]]] diff --git a/packages/slate/test/queries/blocks/inline.js b/packages/slate/test/queries/blocks/inline.js deleted file mode 100644 index d46c4d1fcd..0000000000 --- a/packages/slate/test/queries/blocks/inline.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from(editor.blocks()) -} - -export const output = [ - [ - - onetwothree - , - [0], - ], -] diff --git a/packages/slate/test/queries/getPath/range-end.js b/packages/slate/test/queries/getPath/range-end.js index d7107471a1..2d4efc361f 100644 --- a/packages/slate/test/queries/getPath/range-end.js +++ b/packages/slate/test/queries/getPath/range-end.js @@ -19,4 +19,4 @@ export const run = editor => { ) } -export const output = [0, 1] +export const output = [1, 0] diff --git a/packages/slate/test/queries/getPath/range.js b/packages/slate/test/queries/getPath/range.js index 3f1f06c159..7931d78ff9 100644 --- a/packages/slate/test/queries/getPath/range.js +++ b/packages/slate/test/queries/getPath/range.js @@ -16,4 +16,4 @@ export const run = editor => { }) } -export const output = [0] +export const output = [] diff --git a/packages/slate/test/queries/inlines/block.js b/packages/slate/test/queries/inlines/block.js deleted file mode 100644 index 5877ad11d0..0000000000 --- a/packages/slate/test/queries/inlines/block.js +++ /dev/null @@ -1,15 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - one - -) - -export const run = editor => { - return Array.from(editor.inlines()) -} - -export const output = [] diff --git a/packages/slate/test/queries/inlines/inline-multiple.js b/packages/slate/test/queries/inlines/inline-multiple.js deleted file mode 100644 index fb3567f963..0000000000 --- a/packages/slate/test/queries/inlines/inline-multiple.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothreefourfive - - -) - -export const run = editor => { - return Array.from(editor.inlines()) -} - -export const output = [ - [two, [0, 1]], - [four, [0, 3]], -] diff --git a/packages/slate/test/queries/inlines/inline-nested.js b/packages/slate/test/queries/inlines/inline-nested.js deleted file mode 100644 index 91955e09ff..0000000000 --- a/packages/slate/test/queries/inlines/inline-nested.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - one - twothreefour - five - - -) - -export const run = editor => { - return Array.from(editor.inlines()) -} - -export const output = [ - [ - - twothreefour - , - [0, 1], - ], - [three, [0, 1, 1]], -] diff --git a/packages/slate/test/queries/inlines/inline-reverse.js b/packages/slate/test/queries/inlines/inline-reverse.js deleted file mode 100644 index 6b68cdbbad..0000000000 --- a/packages/slate/test/queries/inlines/inline-reverse.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothreefourfive - - -) - -export const run = editor => { - return Array.from(editor.inlines({ reverse: true })) -} - -export const output = [ - [four, [0, 3]], - [two, [0, 1]], -] diff --git a/packages/slate/test/queries/inlines/inline-void.js b/packages/slate/test/queries/inlines/inline-void.js deleted file mode 100644 index b6c7cfb33b..0000000000 --- a/packages/slate/test/queries/inlines/inline-void.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from(editor.inlines()) -} - -export const output = [[two, [0, 1]]] diff --git a/packages/slate/test/queries/inlines/inline.js b/packages/slate/test/queries/inlines/inline.js deleted file mode 100644 index 35e21d26c5..0000000000 --- a/packages/slate/test/queries/inlines/inline.js +++ /dev/null @@ -1,17 +0,0 @@ -/** @jsx h */ - -import { h } from '../../helpers' - -export const input = ( - - - onetwothree - - -) - -export const run = editor => { - return Array.from(editor.inlines()) -} - -export const output = [[two, [0, 1]]] From a36344f4a6033c450c7c1809a2b7e5c4b2d0f904 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 29 Oct 2019 10:17:56 -0400 Subject: [PATCH 078/165] add more splitNodes tests --- packages/slate/src/classes/commands/node.ts | 95 +++++++++++-------- packages/slate/src/classes/commands/text.ts | 41 +++++++- packages/slate/src/interfaces/value.ts | 6 +- .../splitNodes/path/block-nested-void.js | 27 ++++++ .../commands/splitNodes/path/block-void.js | 25 +++++ .../commands/splitNodes/path/inline-void.js | 31 ++++++ .../test/commands/splitNodes/path/inline.js | 35 +++++++ .../commands/splitNodes/point/block-void.js | 19 ++++ .../commands/splitNodes/point/inline-void.js | 34 +++++++ ...elete-across-blocks.js => block-across.js} | 4 +- .../{with-delete.js => block-expanded.js} | 4 +- ...-hanging-selection.js => block-hanging.js} | 2 +- .../splitNodes/selection/block-nested-void.js | 28 ++++++ .../splitNodes/selection/block-void-end.js | 26 +++++ .../splitNodes/selection/block-void-middle.js | 28 ++++++ .../splitNodes/selection/block-void-start.js | 26 +++++ ...blocks-and-inlines.js => inline-across.js} | 14 +-- .../{expanded.js => inline-expanded.js} | 7 +- .../splitNodes/selection/inline-void.js | 34 +++++++ 19 files changed, 425 insertions(+), 61 deletions(-) create mode 100644 packages/slate/test/commands/splitNodes/path/block-nested-void.js create mode 100644 packages/slate/test/commands/splitNodes/path/block-void.js create mode 100644 packages/slate/test/commands/splitNodes/path/inline-void.js create mode 100644 packages/slate/test/commands/splitNodes/path/inline.js create mode 100644 packages/slate/test/commands/splitNodes/point/block-void.js create mode 100644 packages/slate/test/commands/splitNodes/point/inline-void.js rename packages/slate/test/commands/splitNodes/selection/{with-delete-across-blocks.js => block-across.js} (83%) rename packages/slate/test/commands/splitNodes/selection/{with-delete.js => block-expanded.js} (81%) rename packages/slate/test/commands/splitNodes/selection/{with-delete-hanging-selection.js => block-hanging.js} (91%) create mode 100644 packages/slate/test/commands/splitNodes/selection/block-nested-void.js create mode 100644 packages/slate/test/commands/splitNodes/selection/block-void-end.js create mode 100644 packages/slate/test/commands/splitNodes/selection/block-void-middle.js create mode 100644 packages/slate/test/commands/splitNodes/selection/block-void-start.js rename packages/slate/test/commands/splitNodes/selection/{with-delete-across-blocks-and-inlines.js => inline-across.js} (82%) rename packages/slate/test/commands/splitNodes/selection/{expanded.js => inline-expanded.js} (86%) create mode 100644 packages/slate/test/commands/splitNodes/selection/inline-void.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index fed2bc0ff5..df601afb5d 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -275,6 +275,7 @@ class NodeCommands { ) { this.removeNodes({ at: prevPath }) } else { + debugger this.apply({ type: 'merge_node', path: newPath, @@ -282,6 +283,7 @@ class NodeCommands { target: null, properties, }) + debugger } if (emptyRef) { @@ -530,37 +532,19 @@ class NodeCommands { } = {} ) { this.withoutNormalizing(() => { - const { always = false } = options - let { at = this.value.selection, match, height = 0 } = options - let target: number | null = null - let position - let edgeRef - - if (!at) { - return - } + let { + match, + at = this.value.selection, + height = 0, + always = false, + } = options if (match == null) { - if (Path.isPath(at)) { - match = at.length - } else { - match = 'block' - } + match = Path.isPath(at) ? at.length : 'block' } if (Range.isRange(at)) { - if (Range.isCollapsed(at)) { - at = at.anchor - } else { - const [, end] = Range.edges(at) - const pointRef = this.createPointRef(end) - this.delete({ at }) - at = pointRef.unref()! - - if (options.at == null) { - this.select(at) - } - } + at = deleteRange(this, at) } // If the target is a path, the default height-skipping and position @@ -568,32 +552,49 @@ class NodeCommands { if (Path.isPath(at)) { const point = this.getPoint(at) match = at.length - 1 - position = at[at.length - 1] height = point.path.length - at.length + 1 + always = true at = point - } else { - position = at.offset - edgeRef = this.createPointRef(at, { affinity: 'backward' }) } + if (!at) { + return + } + + const beforeRef = this.createPointRef(at, { affinity: 'backward' }) + const afterRef = this.createPointRef(at) const highest = this.getMatch(at, match) if (!highest) { return } - const [, highestPath] = highest - const lowestPath = at.path.slice(0, at.path.length - height) + let depth = at.path.length - height + const voidMatch = this.getMatch(at, 'void') + + if (voidMatch) { + const [, voidPath] = voidMatch + depth = Math.min(voidPath.length - 1, depth) + } + + let [, highestPath] = highest + let lowestPath = at.path.slice(0, depth) + let position = height === 0 ? at.offset : at.path[depth] + let target: number | null = null - for (const [n, path] of this.levels(lowestPath, { reverse: true })) { + for (const [node, path] of this.levels(lowestPath, { reverse: true })) { let split = false - if (path.length < highestPath.length || path.length === 0) { + if ( + path.length < highestPath.length || + path.length === 0 || + (Element.isElement(node) && this.isVoid(node)) + ) { break } - if (always || !edgeRef || !this.isEdge(edgeRef.current!, path)) { - const { text, marks, nodes, ...properties } = n + if (always || !beforeRef || !this.isEdge(beforeRef.current!, path)) { + const { text, marks, nodes, ...properties } = node this.apply({ type: 'split_node', path, position, target, properties }) split = true } @@ -602,9 +603,12 @@ class NodeCommands { position = path[path.length - 1] + (split ? 1 : 0) } - if (edgeRef) { - edgeRef.unref() + if (options.at == null) { + this.select(afterRef.current!) } + + beforeRef.unref() + afterRef.unref() }) } @@ -762,4 +766,19 @@ const unhangRange = (editor: Editor, range: Range): Range => { return { anchor: start, focus: end } } +/** + * Convert a range into a point by deleting it's content. + */ + +const deleteRange = (editor: Editor, range: Range): Point | null => { + if (Range.isCollapsed(range)) { + return range.anchor + } else { + const [, end] = Range.edges(range) + const pointRef = editor.createPointRef(end) + editor.delete({ at: range }) + return pointRef.unref() + } +} + export default NodeCommands diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index e26a3a1016..6b44a14b77 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -23,11 +23,12 @@ class DeletingCommands { distance?: number unit?: 'character' | 'word' | 'line' | 'block' reverse?: boolean + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { const { reverse = false, unit = 'character', distance = 1 } = options - let { at = this.value.selection } = options + let { at = this.value.selection, hanging = false } = options if (!at) { return @@ -49,6 +50,7 @@ class DeletingCommands { ? this.getBefore(at, opts) || this.getStart() : this.getAfter(at, opts) || this.getEnd() at = { anchor: at, focus: target } + hanging = true } } @@ -61,6 +63,10 @@ class DeletingCommands { return } + if (!hanging) { + at = unhangRange(this, at) + } + const [start, end] = Range.edges(at) const [ancestor, ancestorPath] = this.getAncestor(at) const depth = ancestorPath.length + 1 @@ -189,4 +195,37 @@ class DeletingCommands { } } +/** + * Convert a range into a non-hanging one. + */ + +const unhangRange = (editor: Editor, range: Range): Range => { + let [start, end] = Range.edges(range) + + // PERF: exit early if we can guarantee that the range isn't hanging. + if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) { + return range + } + + const closestBlock = editor.getMatch(end.path, 'block') + const blockPath = closestBlock ? closestBlock[1] : [] + const first = editor.getStart() + const before = { anchor: first, focus: end } + let skip = true + + for (const [node, path] of editor.texts({ at: before, reverse: true })) { + if (skip) { + skip = false + continue + } + + if (node.text !== '' || Path.isBefore(path, blockPath)) { + end = { path, offset: node.text.length } + break + } + } + + return { anchor: start, focus: end } +} + export default DeletingCommands diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 771416f1f3..0d735f8232 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -160,17 +160,19 @@ namespace Value { } case 'merge_node': { + debugger const { path } = op const node = Node.get(v, path) const prevPath = Path.previous(path) const prev = Node.get(v, prevPath) const parent = Node.parent(v, path) const index = path[path.length - 1] + debugger if (Text.isText(node) && Text.isText(prev)) { - prev.text = prev.text + node.text + prev.text += node.text } else if (!Text.isText(node) && !Text.isText(prev)) { - prev.nodes = prev.nodes.concat(node.nodes) + prev.nodes.push(...node.nodes) } else { throw new Error( `Cannot apply a "merge_node" operation at path [${path}] to nodes of different interaces: ${node} ${prev}` diff --git a/packages/slate/test/commands/splitNodes/path/block-nested-void.js b/packages/slate/test/commands/splitNodes/path/block-nested-void.js new file mode 100644 index 0000000000..8e6b3350d9 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/path/block-nested-void.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ at: [0, 1] }) +} + +export const input = ( + + + one + two + + +) + +export const output = ( + + + one + + + two + + +) diff --git a/packages/slate/test/commands/splitNodes/path/block-void.js b/packages/slate/test/commands/splitNodes/path/block-void.js new file mode 100644 index 0000000000..bb650123d2 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/path/block-void.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ at: [0, 1] }) +} + +export const input = ( + + + one + two + + +) + +export const output = ( + + + one + two + + +) diff --git a/packages/slate/test/commands/splitNodes/path/inline-void.js b/packages/slate/test/commands/splitNodes/path/inline-void.js new file mode 100644 index 0000000000..e430433e19 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/path/inline-void.js @@ -0,0 +1,31 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ at: [0, 1, 0] }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + word + + + + +) diff --git a/packages/slate/test/commands/splitNodes/path/inline.js b/packages/slate/test/commands/splitNodes/path/inline.js new file mode 100644 index 0000000000..9afed18101 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/path/inline.js @@ -0,0 +1,35 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ at: [0, 1, 0] }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + + + + + word + + + + +) diff --git a/packages/slate/test/commands/splitNodes/point/block-void.js b/packages/slate/test/commands/splitNodes/point/block-void.js new file mode 100644 index 0000000000..a2df34b186 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/point/block-void.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ at: { path: [0, 0], offset: 2 } }) +} + +export const input = ( + + word + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/commands/splitNodes/point/inline-void.js b/packages/slate/test/commands/splitNodes/point/inline-void.js new file mode 100644 index 0000000000..f7356e89a3 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/point/inline-void.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes({ at: { path: [0, 1, 0], offset: 2 } }) +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + + word + + + + + + + +) diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js b/packages/slate/test/commands/splitNodes/selection/block-across.js similarity index 83% rename from packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js rename to packages/slate/test/commands/splitNodes/selection/block-across.js index 4a586e465e..3980ec3753 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks.js +++ b/packages/slate/test/commands/splitNodes/selection/block-across.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'block' }) + editor.splitNodes() } export const input = ( @@ -25,5 +25,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete.js b/packages/slate/test/commands/splitNodes/selection/block-expanded.js similarity index 81% rename from packages/slate/test/commands/splitNodes/selection/with-delete.js rename to packages/slate/test/commands/splitNodes/selection/block-expanded.js index a660b37290..91aa3df362 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete.js +++ b/packages/slate/test/commands/splitNodes/selection/block-expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'block' }) + editor.splitNodes() } export const input = ( @@ -22,5 +22,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js b/packages/slate/test/commands/splitNodes/selection/block-hanging.js similarity index 91% rename from packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js rename to packages/slate/test/commands/splitNodes/selection/block-hanging.js index f346e95b40..7ec6168cb3 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete-hanging-selection.js +++ b/packages/slate/test/commands/splitNodes/selection/block-hanging.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'block' }) + editor.splitNodes() } export const input = ( diff --git a/packages/slate/test/commands/splitNodes/selection/block-nested-void.js b/packages/slate/test/commands/splitNodes/selection/block-nested-void.js new file mode 100644 index 0000000000..e16cf4deb5 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/selection/block-nested-void.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes() +} + +export const input = ( + + + + word + + + another + + + +) + +export const output = ( + + + + + +) diff --git a/packages/slate/test/commands/splitNodes/selection/block-void-end.js b/packages/slate/test/commands/splitNodes/selection/block-void-end.js new file mode 100644 index 0000000000..8fc9649513 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/selection/block-void-end.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes() +} + +export const input = ( + + + word + + + another + + +) + +export const output = ( + + + wo + + +) diff --git a/packages/slate/test/commands/splitNodes/selection/block-void-middle.js b/packages/slate/test/commands/splitNodes/selection/block-void-middle.js new file mode 100644 index 0000000000..495c26a029 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/selection/block-void-middle.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes() +} + +export const input = ( + + + one + + two + + three + + +) + +export const output = ( + + on + + ree + + +) diff --git a/packages/slate/test/commands/splitNodes/selection/block-void-start.js b/packages/slate/test/commands/splitNodes/selection/block-void-start.js new file mode 100644 index 0000000000..0616423ae6 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/selection/block-void-start.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes() +} + +export const input = ( + + + word + + + another + + +) + +export const output = ( + + + other + + +) diff --git a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js b/packages/slate/test/commands/splitNodes/selection/inline-across.js similarity index 82% rename from packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js rename to packages/slate/test/commands/splitNodes/selection/inline-across.js index fa2d01509b..76ee74b9bc 100644 --- a/packages/slate/test/commands/splitNodes/selection/with-delete-across-blocks-and-inlines.js +++ b/packages/slate/test/commands/splitNodes/selection/inline-across.js @@ -2,10 +2,6 @@ import { h } from '../../../helpers' -export const run = editor => { - editor.splitNodes({ match: 'block' }) -} - export const input = ( @@ -25,16 +21,16 @@ export const input = ( ) +export const run = editor => { + editor.splitNodes() +} + export const output = ( wo - - - - @@ -45,5 +41,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/expanded.js b/packages/slate/test/commands/splitNodes/selection/inline-expanded.js similarity index 86% rename from packages/slate/test/commands/splitNodes/selection/expanded.js rename to packages/slate/test/commands/splitNodes/selection/inline-expanded.js index 2df7a93576..4d977c51fe 100644 --- a/packages/slate/test/commands/splitNodes/selection/expanded.js +++ b/packages/slate/test/commands/splitNodes/selection/inline-expanded.js @@ -3,7 +3,7 @@ import { h } from '../../../helpers' export const run = editor => { - editor.splitNodes({ match: 'inline' }) + editor.splitNodes() } export const input = ( @@ -24,6 +24,9 @@ export const output = ( w + + + d @@ -31,5 +34,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/inline-void.js b/packages/slate/test/commands/splitNodes/selection/inline-void.js new file mode 100644 index 0000000000..b2e3cdff30 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/selection/inline-void.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes() +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + word + + + + + + +) + +export const skip = true From 1e9aa87d12f30a2d1d33c62555d6b1d8744b870b Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 29 Oct 2019 15:26:27 -0400 Subject: [PATCH 079/165] get rest of delete tests passing --- packages/slate/src/classes/commands/node.ts | 34 ++-- .../slate/src/classes/commands/selection.ts | 7 +- packages/slate/src/classes/commands/text.ts | 146 ++++++++++++++---- .../slate/src/classes/queries/location.ts | 21 ++- packages/slate/src/interfaces/path.ts | 8 + packages/slate/src/interfaces/value.ts | 2 - .../selection/block-hanging-multiple.js | 3 +- .../delete/selection/block-hanging-single.js | 3 +- .../delete/voids/block-after-reverse.js | 2 - .../commands/delete/voids/block-before.js | 4 +- .../test/commands/delete/voids/block-end.js | 26 ++++ .../delete/voids/block-hanging-into.js | 6 +- .../delete/voids/inline-after-reverse.js | 2 - .../test/commands/delete/voids/inline-over.js | 15 +- .../delete/voids/inline-start-across.js | 6 +- .../commands/delete/voids/inline-start.js | 2 - .../splitNodes/selection/block-hanging.js | 5 - .../splitNodes/selection/block-nested-void.js | 2 +- .../splitNodes/selection/inline-void-end.js | 34 ++++ .../splitNodes/selection/inline-void.js | 2 - 20 files changed, 247 insertions(+), 83 deletions(-) create mode 100644 packages/slate/test/commands/delete/voids/block-end.js create mode 100644 packages/slate/test/commands/splitNodes/selection/inline-void-end.js diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index df601afb5d..5155c8a99a 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -206,14 +206,13 @@ class NodeCommands { } const current = this.getMatch(at, match) - const prev = this.getPrevious(at, match) debugger + const prev = this.getPrevious(at, match) if (!current || !prev) { return } - debugger const [node, path] = current const [prevNode, prevPath] = prev const newPath = Path.next(prevPath) @@ -275,7 +274,6 @@ class NodeCommands { ) { this.removeNodes({ at: prevPath }) } else { - debugger this.apply({ type: 'merge_node', path: newPath, @@ -283,7 +281,6 @@ class NodeCommands { target: null, properties, }) - debugger } if (emptyRef) { @@ -553,8 +550,8 @@ class NodeCommands { const point = this.getPoint(at) match = at.length - 1 height = point.path.length - at.length + 1 - always = true at = point + always = true } if (!at) { @@ -562,24 +559,41 @@ class NodeCommands { } const beforeRef = this.createPointRef(at, { affinity: 'backward' }) - const afterRef = this.createPointRef(at) const highest = this.getMatch(at, match) if (!highest) { return } - let depth = at.path.length - height const voidMatch = this.getMatch(at, 'void') + let nudge = 0 if (voidMatch) { - const [, voidPath] = voidMatch - depth = Math.min(voidPath.length - 1, depth) + const [voidNode, voidPath] = voidMatch + let after = this.getAfter(voidPath) + + if (!after) { + if (Element.isElement(voidNode) && this.isInline(voidNode)) { + const text = { text: '', marks: [] } + const afterPath = Path.next(voidPath) + this.insertNodes(text, { at: afterPath }) + after = this.getPoint(afterPath) + } else { + return + } + } + + const siblingHeight = after.path.length - voidPath.length + height = siblingHeight + 1 + at = after + always = true } + const afterRef = this.createPointRef(at) + const depth = at.path.length - height let [, highestPath] = highest let lowestPath = at.path.slice(0, depth) - let position = height === 0 ? at.offset : at.path[depth] + let position = height === 0 ? at.offset : at.path[depth] + nudge let target: number | null = null for (const [node, path] of this.levels(lowestPath, { reverse: true })) { diff --git a/packages/slate/src/classes/commands/selection.ts b/packages/slate/src/classes/commands/selection.ts index bc55c7a2e1..51b5139b9d 100755 --- a/packages/slate/src/classes/commands/selection.ts +++ b/packages/slate/src/classes/commands/selection.ts @@ -107,12 +107,7 @@ class SelectionCommands { select(this: Editor, target: Location) { const { selection } = this.value - - if (Point.isPoint(target)) { - target = { anchor: target, focus: target } - } else if (Path.isPath(target)) { - target = this.getRange(target) - } + target = this.getRange(target) if (selection) { this.setSelection(target) diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 6b44a14b77..7def6eb37e 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -9,6 +9,7 @@ import { Range, Point, Value, + Text, } from '../..' class DeletingCommands { @@ -67,31 +68,80 @@ class DeletingCommands { at = unhangRange(this, at) } - const [start, end] = Range.edges(at) - const [ancestor, ancestorPath] = this.getAncestor(at) - const depth = ancestorPath.length + 1 - const afterRef = this.createPointRef(end) - const rangeRef = this.createRangeRef(at, { affinity: 'inward' }) - debugger - this.splitNodes({ at: end, match: depth, always: true }) - this.splitNodes({ at: start, match: depth, always: true }) - const range = rangeRef.unref()! - debugger - this.removeNodes({ at: range, match: depth, hanging: true }) - - debugger - if ( + let [start, end] = Range.edges(at) + const [ancestor] = this.getAncestor(at) + const isSingleText = Path.equals(start.path, end.path) + const startVoid = this.getMatch(start.path, 'void') + const endVoid = this.getMatch(end.path, 'void') + + // If the start or end points are inside an inline void, nudge them out. + if (startVoid) { + const block = this.getMatch(start.path, 'block') + const before = this.getBefore(start) + + if (before && block && Path.isAncestor(block[1], before.path)) { + start = before + } + } + + if (endVoid) { + const block = this.getMatch(end.path, 'block') + const after = this.getAfter(end) + + if (after && block && Path.isAncestor(block[1], after.path)) { + end = after + } + } + + // Get the highest nodes that are completely inside the range, as well as + // the start and end nodes. + const matches = this.matches({ + at, + match: ([n, p]) => + (Element.isElement(n) && this.isVoid(n)) || + (!Path.isCommon(p, start.path) && !Path.isCommon(p, end.path)), + }) + + const pathRefs = Array.from(matches, ([, p]) => this.createPathRef(p)) + const startRef = this.createPointRef(start) + const endRef = this.createPointRef(end) + + if (!isSingleText && !startVoid) { + const point = startRef.current! + const [node] = this.getLeaf(point) + const { path } = point + const { offset } = start + const text = node.text.slice(offset) + this.apply({ type: 'remove_text', path, offset, text }) + } + + for (const pathRef of pathRefs) { + const path = pathRef.unref()! + this.removeNodes({ at: path }) + } + + if (!endVoid) { + const point = endRef.current! + const [node] = this.getLeaf(point) + const { path } = point + const offset = isSingleText ? start.offset : 0 + const text = node.text.slice(offset, end.offset) + this.apply({ type: 'remove_text', path, offset, text }) + } + + const isBlockAncestor = Value.isValue(ancestor) || (Element.isElement(ancestor) && !this.isInline(ancestor)) - ) { - this.mergeNodes({ at: afterRef.current!, hanging: true }) - } - if (options.at == null) { - this.select(afterRef.current!) + if (isBlockAncestor && endRef.current && startRef.current) { + this.mergeNodes({ at: endRef.current, hanging: true }) } - afterRef.unref() + const point = endRef.unref() || startRef.unref() + + if (options.at == null && point) { + this.select(point) + } }) } @@ -103,7 +153,7 @@ class DeletingCommands { this: Editor, fragment: Fragment, options: { - at?: Range | Point + at?: Location } = {} ) { this.withoutNormalizing(() => { @@ -193,6 +243,36 @@ class DeletingCommands { } }) } + + /** + * Remove a string of text in the editor. + */ + + removeText( + this: Editor, + text: string, + options: { + at?: Range + } = {} + ) { + this.withoutNormalizing(() => { + let { at = this.value.selection } = options + + if (!at || Range.isCollapsed(at)) { + return + } + + const [start, end] = Range.edges(at) + const texts = this.texts({ at }) + const pathRefs = Array.from(texts, ([, p]) => this.createPathRef(p)) + + for (const [node, path] of this.texts({ at })) + if (Point.isPoint(at) && !this.getMatch(at.path, 'void')) { + const { path, offset } = at + this.apply({ type: 'insert_text', path, offset, text }) + } + }) + } } /** @@ -213,15 +293,25 @@ const unhangRange = (editor: Editor, range: Range): Range => { const before = { anchor: first, focus: end } let skip = true - for (const [node, path] of editor.texts({ at: before, reverse: true })) { - if (skip) { - skip = false - continue + for (const [node, path] of editor.entries({ at: before, reverse: true })) { + if (Element.isElement(node) && editor.isVoid(node)) { + end = editor.getStart(path) + break } - if (node.text !== '' || Path.isBefore(path, blockPath)) { - end = { path, offset: node.text.length } - break + if ( + Text.isText(node) || + (Element.isElement(node) && editor.isInline(node)) + ) { + if (skip) { + skip = false + continue + } + + if (node.text !== '' || Path.isBefore(path, blockPath)) { + end = { path, offset: node.text.length } + break + } } } diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 3faca1a65f..ef91506e62 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -4,11 +4,12 @@ import { Editor, Location, Node, - Path, NodeEntry, + Path, Point, Range, Text, + TextEntry, } from '../..' import { Match } from '../utils' @@ -122,6 +123,23 @@ class LocationQueries { return this.getPoint(at, { edge: 'end' }) } + /** + * Get the leaf text node at a location. + */ + + getLeaf( + this: Editor, + at: Location = [], + options: { + depth?: number + edge?: 'start' | 'end' + } = {} + ): TextEntry { + const path = this.getPath(at, options) + const node = Node.leaf(this.value, path) + return [node, path] + } + /** * Get the first matching node in a single branch of the document. */ @@ -292,7 +310,6 @@ class LocationQueries { let i = 0 for (const entry of this.matches({ at: range, match, reverse: true })) { - debugger if (i === 1) { return entry } diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index eacf986767..639f9733fe 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -155,6 +155,14 @@ namespace Path { ) } + /** + * Check if a path is equal to or an ancestor of another. + */ + + export const isCommon = (path: Path, another: Path): boolean => { + return path.length <= another.length && Path.compare(path, another) === 0 + } + /** * Check if a path is a descendant of another. */ diff --git a/packages/slate/src/interfaces/value.ts b/packages/slate/src/interfaces/value.ts index 0d735f8232..3026beaeca 100755 --- a/packages/slate/src/interfaces/value.ts +++ b/packages/slate/src/interfaces/value.ts @@ -160,14 +160,12 @@ namespace Value { } case 'merge_node': { - debugger const { path } = op const node = Node.get(v, path) const prevPath = Path.previous(path) const prev = Node.get(v, prevPath) const parent = Node.parent(v, path) const index = path[path.length - 1] - debugger if (Text.isText(node) && Text.isText(prev)) { prev.text += node.text diff --git a/packages/slate/test/commands/delete/selection/block-hanging-multiple.js b/packages/slate/test/commands/delete/selection/block-hanging-multiple.js index 549db4b30a..6a3253a916 100644 --- a/packages/slate/test/commands/delete/selection/block-hanging-multiple.js +++ b/packages/slate/test/commands/delete/selection/block-hanging-multiple.js @@ -21,7 +21,8 @@ export const input = ( export const output = ( - three + + three ) diff --git a/packages/slate/test/commands/delete/selection/block-hanging-single.js b/packages/slate/test/commands/delete/selection/block-hanging-single.js index 804f8756b0..b987419a34 100644 --- a/packages/slate/test/commands/delete/selection/block-hanging-single.js +++ b/packages/slate/test/commands/delete/selection/block-hanging-single.js @@ -20,7 +20,8 @@ export const input = ( export const output = ( - two + + two ) diff --git a/packages/slate/test/commands/delete/voids/block-after-reverse.js b/packages/slate/test/commands/delete/voids/block-after-reverse.js index 37ce0bc82f..1637614f21 100644 --- a/packages/slate/test/commands/delete/voids/block-after-reverse.js +++ b/packages/slate/test/commands/delete/voids/block-after-reverse.js @@ -24,5 +24,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/commands/delete/voids/block-before.js b/packages/slate/test/commands/delete/voids/block-before.js index 19d9997eca..3ce9fba122 100644 --- a/packages/slate/test/commands/delete/voids/block-before.js +++ b/packages/slate/test/commands/delete/voids/block-before.js @@ -19,10 +19,8 @@ export const input = ( export const output = ( - + ) - -export const skip = true diff --git a/packages/slate/test/commands/delete/voids/block-end.js b/packages/slate/test/commands/delete/voids/block-end.js new file mode 100644 index 0000000000..0483a61a2e --- /dev/null +++ b/packages/slate/test/commands/delete/voids/block-end.js @@ -0,0 +1,26 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.delete() +} + +export const input = ( + + + word + + + another + + +) + +export const output = ( + + + wo + + +) diff --git a/packages/slate/test/commands/delete/voids/block-hanging-into.js b/packages/slate/test/commands/delete/voids/block-hanging-into.js index 93f7abad7c..d352a6d1cc 100644 --- a/packages/slate/test/commands/delete/voids/block-hanging-into.js +++ b/packages/slate/test/commands/delete/voids/block-hanging-into.js @@ -12,9 +12,9 @@ export const input = ( one - + two - two + three ) @@ -23,6 +23,6 @@ export const output = ( - two + three ) diff --git a/packages/slate/test/commands/delete/voids/inline-after-reverse.js b/packages/slate/test/commands/delete/voids/inline-after-reverse.js index dfce0d085f..6494259079 100644 --- a/packages/slate/test/commands/delete/voids/inline-after-reverse.js +++ b/packages/slate/test/commands/delete/voids/inline-after-reverse.js @@ -27,5 +27,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/commands/delete/voids/inline-over.js b/packages/slate/test/commands/delete/voids/inline-over.js index 976711bd55..f64fcf5ce7 100644 --- a/packages/slate/test/commands/delete/voids/inline-over.js +++ b/packages/slate/test/commands/delete/voids/inline-over.js @@ -9,14 +9,13 @@ export const run = editor => { export const input = ( - Hi + one - there + two - - - - + three + four + five ) @@ -24,9 +23,7 @@ export const input = ( export const output = ( - + five ) - -export const skip = true diff --git a/packages/slate/test/commands/delete/voids/inline-start-across.js b/packages/slate/test/commands/delete/voids/inline-start-across.js index 241d58b8ca..075787644b 100644 --- a/packages/slate/test/commands/delete/voids/inline-start-across.js +++ b/packages/slate/test/commands/delete/voids/inline-start-across.js @@ -16,7 +16,7 @@ export const input = ( two - three + three ) @@ -24,9 +24,7 @@ export const input = ( export const output = ( - onethree + one ) - -export const skip = true diff --git a/packages/slate/test/commands/delete/voids/inline-start.js b/packages/slate/test/commands/delete/voids/inline-start.js index 501e79e4b3..818300fd15 100644 --- a/packages/slate/test/commands/delete/voids/inline-start.js +++ b/packages/slate/test/commands/delete/voids/inline-start.js @@ -27,5 +27,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/block-hanging.js b/packages/slate/test/commands/splitNodes/selection/block-hanging.js index 7ec6168cb3..347b1c3779 100644 --- a/packages/slate/test/commands/splitNodes/selection/block-hanging.js +++ b/packages/slate/test/commands/splitNodes/selection/block-hanging.js @@ -21,13 +21,8 @@ export const input = ( export const output = ( zero - - - cat is cute ) - -export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/block-nested-void.js b/packages/slate/test/commands/splitNodes/selection/block-nested-void.js index e16cf4deb5..94fe49aeb3 100644 --- a/packages/slate/test/commands/splitNodes/selection/block-nested-void.js +++ b/packages/slate/test/commands/splitNodes/selection/block-nested-void.js @@ -22,7 +22,7 @@ export const input = ( export const output = ( - + ) diff --git a/packages/slate/test/commands/splitNodes/selection/inline-void-end.js b/packages/slate/test/commands/splitNodes/selection/inline-void-end.js new file mode 100644 index 0000000000..a8036a99a7 --- /dev/null +++ b/packages/slate/test/commands/splitNodes/selection/inline-void-end.js @@ -0,0 +1,34 @@ +/** @jsx h */ + +import { h } from '../../../helpers' + +export const run = editor => { + editor.splitNodes() +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + word + + + + + + +) + +export const skip = true diff --git a/packages/slate/test/commands/splitNodes/selection/inline-void.js b/packages/slate/test/commands/splitNodes/selection/inline-void.js index b2e3cdff30..89cadb0716 100644 --- a/packages/slate/test/commands/splitNodes/selection/inline-void.js +++ b/packages/slate/test/commands/splitNodes/selection/inline-void.js @@ -30,5 +30,3 @@ export const output = ( ) - -export const skip = true From a0fa04008dfcacdef387ee6814c8a09334ae566c Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 29 Oct 2019 17:58:44 -0400 Subject: [PATCH 080/165] fix location-based logic in some commands --- packages/slate/src/classes/commands/mark.ts | 16 +- packages/slate/src/classes/commands/node.ts | 67 +-- packages/slate/src/classes/commands/text.ts | 45 +- packages/slate/src/classes/editor.ts | 6 +- .../slate/src/classes/queries/location.ts | 507 +++++++++++++++++- packages/slate/src/classes/queries/range.ts | 38 ++ packages/slate/src/classes/queries/value.ts | 439 --------------- packages/slate/src/interfaces/location.ts | 16 +- packages/slate/src/interfaces/node.ts | 10 +- .../splitNodes/selection/block-nested-void.js | 2 +- .../splitNodes/selection/inline-void-end.js | 2 - .../test/queries/getRange/range-backward.js | 21 + 12 files changed, 604 insertions(+), 565 deletions(-) create mode 100644 packages/slate/src/classes/queries/range.ts delete mode 100644 packages/slate/src/classes/queries/value.ts create mode 100644 packages/slate/test/queries/getRange/range-backward.js diff --git a/packages/slate/src/classes/commands/mark.ts b/packages/slate/src/classes/commands/mark.ts index f842f178f4..c87cd52d9f 100644 --- a/packages/slate/src/classes/commands/mark.ts +++ b/packages/slate/src/classes/commands/mark.ts @@ -10,6 +10,7 @@ class MarkCommands { marks: Mark[], options: { at?: Location + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { @@ -43,6 +44,7 @@ class MarkCommands { marks: Mark[], options: { at?: Location + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { @@ -64,6 +66,7 @@ class MarkCommands { props: Partial, options: { at?: Location + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { @@ -99,10 +102,12 @@ class MarkCommands { marks: Mark[], options: { at?: Location + hanging?: boolean } = {} ) { this.withoutNormalizing(() => { const existing = this.getActiveMarks(options) + debugger const exists = marks.every(m => Mark.exists(m, existing)) if (exists) { @@ -120,15 +125,22 @@ class MarkCommands { const splitLocation = ( editor: Editor, - options: { at?: Location } = {} + options: { + at?: Location + hanging?: boolean + } = {} ): Location | undefined => { - const { at = editor.value.selection } = options + let { at = editor.value.selection, hanging = false } = options if (!at) { return } if (Range.isRange(at)) { + if (!hanging) { + at = editor.unhangRange(at) + } + const rangeRef = editor.createRangeRef(at, { affinity: 'inward' }) const [start, end] = Range.edges(at) editor.splitNodes({ at: end, match: 'text' }) diff --git a/packages/slate/src/classes/commands/node.ts b/packages/slate/src/classes/commands/node.ts index 5155c8a99a..18a7e0465d 100644 --- a/packages/slate/src/classes/commands/node.ts +++ b/packages/slate/src/classes/commands/node.ts @@ -187,7 +187,7 @@ class NodeCommands { } if (!hanging && Range.isRange(at)) { - at = unhangRange(this, at) + at = this.unhangRange(at) } if (Range.isRange(at)) { @@ -206,7 +206,6 @@ class NodeCommands { } const current = this.getMatch(at, match) - debugger const prev = this.getPrevious(at, match) if (!current || !prev) { @@ -440,7 +439,7 @@ class NodeCommands { } if (!hanging && Range.isRange(at)) { - at = unhangRange(this, at) + at = this.unhangRange(at) } const depths = this.matches({ at, match }) @@ -479,7 +478,7 @@ class NodeCommands { } if (!hanging && Range.isRange(at)) { - at = unhangRange(this, at) + at = this.unhangRange(at) } for (const [node, path] of this.matches({ at, match })) { @@ -570,22 +569,23 @@ class NodeCommands { if (voidMatch) { const [voidNode, voidPath] = voidMatch - let after = this.getAfter(voidPath) - if (!after) { - if (Element.isElement(voidNode) && this.isInline(voidNode)) { + if (Element.isElement(voidNode) && this.isInline(voidNode)) { + let after = this.getAfter(voidPath) + + if (!after) { const text = { text: '', marks: [] } const afterPath = Path.next(voidPath) this.insertNodes(text, { at: afterPath }) - after = this.getPoint(afterPath) - } else { - return + after = this.getPoint(afterPath)! } + + at = after + always = true } - const siblingHeight = after.path.length - voidPath.length + const siblingHeight = at.path.length - voidPath.length height = siblingHeight + 1 - at = after always = true } @@ -596,7 +596,10 @@ class NodeCommands { let position = height === 0 ? at.offset : at.path[depth] + nudge let target: number | null = null - for (const [node, path] of this.levels(lowestPath, { reverse: true })) { + for (const [node, path] of this.levels({ + at: lowestPath, + reverse: true, + })) { let split = false if ( @@ -618,7 +621,8 @@ class NodeCommands { } if (options.at == null) { - this.select(afterRef.current!) + const point = afterRef.current || this.getEnd() + this.select(point) } beforeRef.unref() @@ -731,7 +735,7 @@ class NodeCommands { ? Path.parent(firstPath) : Path.common(firstPath, lastPath) - const range = this.getRange(firstPath, { to: lastPath }) + const range = this.getRange(firstPath, lastPath) const depth = commonPath.length + 1 const wrapperPath = Path.next(lastPath).slice(0, depth) const wrapper = { ...element, nodes: [] } @@ -747,39 +751,6 @@ class NodeCommands { } } -/** - * Convert a range into a non-hanging one. - */ - -const unhangRange = (editor: Editor, range: Range): Range => { - let [start, end] = Range.edges(range) - - // PERF: exit early if we can guarantee that the range isn't hanging. - if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) { - return range - } - - const closestBlock = editor.getMatch(end.path, 'block') - const blockPath = closestBlock ? closestBlock[1] : [] - const first = editor.getStart() - const before = { anchor: first, focus: end } - let skip = true - - for (const [node, path] of editor.texts({ at: before, reverse: true })) { - if (skip) { - skip = false - continue - } - - if (node.text !== '' || Path.isBefore(path, blockPath)) { - end = { path, offset: node.text.length } - break - } - } - - return { anchor: start, focus: end } -} - /** * Convert a range into a point by deleting it's content. */ diff --git a/packages/slate/src/classes/commands/text.ts b/packages/slate/src/classes/commands/text.ts index 7def6eb37e..2641517d39 100644 --- a/packages/slate/src/classes/commands/text.ts +++ b/packages/slate/src/classes/commands/text.ts @@ -65,7 +65,7 @@ class DeletingCommands { } if (!hanging) { - at = unhangRange(this, at) + at = this.unhangRange(at) } let [start, end] = Range.edges(at) @@ -275,47 +275,4 @@ class DeletingCommands { } } -/** - * Convert a range into a non-hanging one. - */ - -const unhangRange = (editor: Editor, range: Range): Range => { - let [start, end] = Range.edges(range) - - // PERF: exit early if we can guarantee that the range isn't hanging. - if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) { - return range - } - - const closestBlock = editor.getMatch(end.path, 'block') - const blockPath = closestBlock ? closestBlock[1] : [] - const first = editor.getStart() - const before = { anchor: first, focus: end } - let skip = true - - for (const [node, path] of editor.entries({ at: before, reverse: true })) { - if (Element.isElement(node) && editor.isVoid(node)) { - end = editor.getStart(path) - break - } - - if ( - Text.isText(node) || - (Element.isElement(node) && editor.isInline(node)) - ) { - if (skip) { - skip = false - continue - } - - if (node.text !== '' || Path.isBefore(path, blockPath)) { - end = { path, offset: node.text.length } - break - } - } - } - - return { anchor: start, focus: end } -} - export default DeletingCommands diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index aeb94ece27..97c31590e2 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -17,7 +17,7 @@ import GeneralCommands from './commands/general' import ElementQueries from './queries/element' import GeneralQueries from './queries/general' import LocationQueries from './queries/location' -import ValueQueries from './queries/value' +import RangeQueries from './queries/range' /** * The `EditorConstructor` interface is provided as a convenience for plugins @@ -82,7 +82,7 @@ interface Editor ElementQueries, GeneralQueries, LocationQueries, - ValueQueries {} + RangeQueries {} const mixin = (Mixins: Array any>) => { for (const Mixin of Mixins) { @@ -104,7 +104,7 @@ mixin([ ElementQueries, GeneralQueries, LocationQueries, - ValueQueries, + RangeQueries, ]) export { Editor, EditorConstructor } diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index ef91506e62..79dcba8b72 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -1,19 +1,187 @@ +import { reverse as reverseText } from 'esrever' import { Ancestor, AncestorEntry, + AnnotationEntry, Editor, + Element, + ElementEntry, Location, + Mark, + MarkEntry, Node, NodeEntry, Path, Point, Range, + Span, + String, Text, TextEntry, + Value, } from '../..' import { Match } from '../utils' class LocationQueries { + /** + * Iterate through all of the annotations in the editor. + */ + + *annotations( + this: Editor, + options: { + at?: Location + } = {} + ): Iterable { + const { annotations } = this.value + const { at = [] } = options + const range = this.getRange(at) + + for (const key in annotations) { + const annotation = annotations[key] + + if (at && !Range.includes(range, annotation)) { + continue + } + + yield [annotation, key] + } + } + + /** + * Iterate through all of the elements in the editor. + */ + + *elements( + this: Editor, + options: { + at?: Location | Span + reverse?: boolean + } = {} + ): Iterable { + const [from, to] = getSpan(this, options) + + yield* Node.elements(this.value, { + ...options, + from, + to, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) + } + + /** + * Iterate through all of the nodes in the editor. + */ + + *entries( + this: Editor, + options: { + at?: Location | Span + reverse?: boolean + } = {} + ): Iterable { + const [from, to] = getSpan(this, options) + const iterable = Node.entries(this.value, { + ...options, + from, + to, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) + + for (const entry of iterable) { + yield entry + } + } + + /** + * Get the marks that are "active" at a location. These are the + * marks that will be added to any text that is inserted. + * + * The `union: true` option can be passed to create a union of marks across + * the text nodes in the selection, instead of creating an intersection, which + * is the default. + * + * Note: to obey common rich text behavior, if the selection is collapsed at + * the start of a text node and there are previous text nodes in the same + * block, it will carry those marks forward from the previous text node. This + * allows for continuation of marks from previous words. + */ + + getActiveMarks( + this: Editor, + options: { + at?: Location + union?: boolean + hanging?: boolean + } = {} + ): Mark[] { + const { union = false, hanging = false } = options + let { at = this.value.selection } = options + + if (!at) { + return [] + } + + at = this.getRange(at) + + if (!hanging) { + at = this.unhangRange(at) + } + + // If the range is collapsed at the start of a text node, it should carry + // over the marks from the previous text node in the same block. + if (Range.isCollapsed(at) && at.anchor.offset === 0) { + const { anchor } = at + const prev = this.getPrevious(anchor, 'text') + + if (prev && Path.isSibling(anchor.path, prev[1])) { + const [prevNode, prevPath] = prev + + if (Text.isText(prevNode)) { + at = this.getRange(prevPath) + } + } + } + + const marks: Mark[] = [] + let first = true + + for (const [node] of this.texts({ at })) { + debugger + + if (first) { + marks.push(...node.marks) + first = false + continue + } + + if (union) { + for (const mark of node.marks) { + if (!Mark.exists(mark, marks)) { + marks.push(mark) + } + } + } else { + // PERF: If we're doing an intersection and the result hits zero it can + // never increase again, so we can exit early. + if (marks.length === 0) { + break + } + + // Iterate backwards so that removing marks doesn't impact indexing. + for (let i = marks.length - 1; i >= 0; i--) { + const existing = marks[i] + + if (!Mark.exists(existing, node.marks)) { + marks.splice(i, 1) + } + } + } + } + + return marks + } + /** * Get the point after a location. */ @@ -54,7 +222,7 @@ class LocationQueries { getAncestor( this: Editor, - at: Location = [], + at: Location, options: { depth?: number edge?: 'start' | 'end' @@ -123,13 +291,31 @@ class LocationQueries { return this.getPoint(at, { edge: 'end' }) } + /** + * Get the first node at a location. + */ + + getFirst(this: Editor, at: Location): NodeEntry { + const path = this.getPath(at, { edge: 'start' }) + return this.getNode(path) + } + + /** + * Get the last node at a location. + */ + + getLast(this: Editor, at: Location): NodeEntry { + const path = this.getPath(at, { edge: 'end' }) + return this.getNode(path) + } + /** * Get the leaf text node at a location. */ getLeaf( this: Editor, - at: Location = [], + at: Location, options: { depth?: number edge?: 'start' | 'end' @@ -153,8 +339,8 @@ class LocationQueries { const path = this.getPath(at) - for (const entry of this.levels(path)) { - if (this.isMatch(entry, match)) { + for (const entry of this.levels({ at: path })) { + if (isMatch(this, entry, match)) { return entry } } @@ -165,9 +351,12 @@ class LocationQueries { */ getNext(this: Editor, at: Location, match: Match): NodeEntry | undefined { + const [, from] = this.getLast(at) + const [, to] = this.getLast([]) + const span: Span = [from, to] let i = 0 - for (const entry of this.matches({ at, match })) { + for (const entry of this.matches({ at: span, match })) { if (i === 1) { return entry } @@ -182,7 +371,7 @@ class LocationQueries { getNode( this: Editor, - at: Location = [], + at: Location, options: { depth?: number edge?: 'start' | 'end' @@ -199,7 +388,7 @@ class LocationQueries { getParent( this: Editor, - at: Location = [], + at: Location, options: { depth?: number edge?: 'start' | 'end' @@ -217,7 +406,7 @@ class LocationQueries { getPath( this: Editor, - at: Location = [], + at: Location, options: { depth?: number edge?: 'start' | 'end' @@ -262,7 +451,7 @@ class LocationQueries { getPoint( this: Editor, - at: Location = [], + at: Location, options: { edge?: 'start' | 'end' } = {} @@ -304,12 +493,12 @@ class LocationQueries { */ getPrevious(this: Editor, at: Location, match: Match): NodeEntry | undefined { - const first = this.getStart(at) - const start = this.getStart() - const range = { anchor: start, focus: first } + const [, from] = this.getFirst(at) + const [, to] = this.getFirst([]) + const span: Span = [from, to] let i = 0 - for (const entry of this.matches({ at: range, match, reverse: true })) { + for (const entry of this.matches({ at: span, match, reverse: true })) { if (i === 1) { return entry } @@ -322,9 +511,13 @@ class LocationQueries { * Get a range of a location. */ - getRange(this: Editor, at: Location = [], to: Location = at): Range { + getRange(this: Editor, at: Location, to?: Location): Range { + if (Range.isRange(at) && !to) { + return at + } + const start = this.getStart(at) - const end = this.getEnd(to) + const end = this.getEnd(to || at) return { anchor: start, focus: end } } @@ -371,7 +564,7 @@ class LocationQueries { hasNode( this: Editor, - at: Location = [], + at: Location, options: { depth?: number edge?: 'start' | 'end' @@ -412,6 +605,288 @@ class LocationQueries { isEdge(this: Editor, point: Point, at: Location = []): boolean { return this.isStart(point, at) || this.isEnd(point, at) } + + /** + * Iterate through all of the levels at a location. + */ + + *levels( + this: Editor, + options: { + at?: Location + reverse?: boolean + } = {} + ): Iterable { + const { at = [], reverse = false } = options + const levels: NodeEntry[] = [] + const path = this.getPath(at) + + for (const [n, p] of Node.levels(this.value, path)) { + levels.push([n, p]) + + if (Element.isElement(n) && this.isVoid(n)) { + break + } + } + + if (reverse) { + levels.reverse() + } + + yield* levels + } + + /** + * Iterate through all of the text nodes in the editor. + */ + + *marks( + this: Editor, + options: { + at?: Location | Span + reverse?: boolean + } = {} + ): Iterable { + const [from, to] = getSpan(this, options) + + yield* Node.marks(this.value, { + ...options, + from, + to, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) + } + + /** + * Iterate through all of the nodes that match. + */ + + *matches( + this: Editor, + options: { + match: Match + at?: Location | Span + reverse?: boolean + } + ): Iterable { + const { reverse, match } = options + let { at } = options + let prevPath: Path | undefined + + // PERF: If the target is a path, don't traverse. + if (Path.isPath(at)) { + const m = this.getMatch(at, match) + + if (m) { + yield m + } + + return + } + + for (const [n, p] of this.entries({ at, reverse })) { + if (prevPath && Path.compare(p, prevPath) === 0) { + continue + } + + if (isMatch(this, [n, p], match)) { + prevPath = p + yield [n, p] + } + } + } + + /** + * Iterate through all of the positions in the document where a `Point` can be + * placed. + * + * By default it will move forward by individual offsets at a time, but you + * can pass the `unit: 'character'` option to moved forward one character, word, + * or line at at time. + * + * Note: void nodes are treated as a single point, and iteration will not + * happen inside their content. + */ + + *positions( + this: Editor, + options: { + at?: Location + unit?: 'offset' | 'character' | 'word' | 'line' | 'block' + reverse?: boolean + } = {} + ): Iterable { + const { at = [], unit = 'offset', reverse = false } = options + const range = this.getRange(at) + const [start, end] = Range.edges(range) + const first = reverse ? end : start + let string = '' + let available = 0 + let offset = 0 + let distance: number | null = null + let isNewBlock = false + + const advance = () => { + if (distance == null) { + if (unit === 'character') { + distance = String.getCharacterDistance(string) + } else if (unit === 'word') { + distance = String.getWordDistance(string) + } else if (unit === 'line' || unit === 'block') { + distance = string.length + } else { + distance = 1 + } + + string = string.slice(distance) + } + + // Add or substract the offset. + offset = reverse ? offset - distance : offset + distance + // Subtract the distance traveled from the available text. + available = available - distance! + // If the available had room to spare, reset the distance so that it will + // advance again next time. Otherwise, set it to the overflow amount. + distance = available >= 0 ? null : 0 - available + } + + for (const [node, path] of this.entries({ at, reverse })) { + if (Element.isElement(node)) { + // Void nodes are a special case, since we don't want to iterate over + // their content. We instead always just yield their first point. + if (this.isVoid(node)) { + yield this.getStart(path) + continue + } + + if (this.isInline(node)) { + continue + } + + if (this.hasInlines(node)) { + let e = Path.isAncestor(path, end.path) ? end : this.getEnd(path) + let s = Path.isAncestor(path, start.path) + ? start + : this.getStart(path) + + const text = this.getText({ anchor: s, focus: e }) + string = reverse ? reverseText(text) : text + isNewBlock = true + } + } + + if (Text.isText(node)) { + const isFirst = Path.equals(path, first.path) + available = node.text.length + offset = reverse ? available : 0 + + if (isFirst) { + available = reverse ? first.offset : available - first.offset + offset = first.offset + } + + if (isFirst || isNewBlock || unit === 'offset') { + yield { path, offset } + } + + while (true) { + // If there's no more string, continue to the next block. + if (string === '') { + break + } else { + advance() + } + + // If the available space hasn't overflow, we have another point to + // yield in the current text node. + if (available >= 0) { + yield { path, offset } + } else { + break + } + } + + isNewBlock = false + } + } + } + + /** + * Iterate through all of the text nodes in the editor. + */ + + *texts( + this: Editor, + options: { + at?: Location | Span + reverse?: boolean + } = {} + ): Iterable { + const [from, to] = getSpan(this, options) + + yield* Node.texts(this.value, { + ...options, + from, + to, + pass: ([n]) => Element.isElement(n) && this.isVoid(n), + }) + } +} + +/** + * Get the from and to path span from a location. + */ + +const getSpan = ( + editor: Editor, + options: { + at?: Location | Span + reverse?: boolean + } = {} +): Span => { + const { at = [], reverse = false } = options + + if (Span.isSpan(at)) { + return at + } + + const first = editor.getPath(at, { edge: 'start' }) + const last = editor.getPath(at, { edge: 'end' }) + const from = reverse ? last : first + const to = reverse ? first : last + return [from, to] +} + +/** + * Check if a node is a match. + */ + +const isMatch = (editor: Editor, entry: NodeEntry, match: Match) => { + const [node, path] = entry + + if (typeof match === 'function') { + return match(entry) + } else if (typeof match === 'number') { + return path.length === match + } else if (match === 'text') { + return Text.isText(node) + } else if (match === 'value') { + return Value.isValue(node) + } else if (match === 'inline') { + return ( + (Element.isElement(node) && editor.isInline(node)) || Text.isText(node) + ) + } else if (match === 'block') { + return ( + Element.isElement(node) && + !editor.isInline(node) && + editor.hasInlines(node) + ) + } else if (match === 'void') { + return Element.isElement(node) && editor.isVoid(node) + } else { + return Node.matches(node, match) + } } export default LocationQueries diff --git a/packages/slate/src/classes/queries/range.ts b/packages/slate/src/classes/queries/range.ts new file mode 100644 index 0000000000..ecf1bc1cbc --- /dev/null +++ b/packages/slate/src/classes/queries/range.ts @@ -0,0 +1,38 @@ +import { Editor, Path, Range } from '../..' + +class RangeQueries { + /** + * Convert a range into a non-hanging one. + */ + + unhangRange(this: Editor, range: Range): Range { + let [start, end] = Range.edges(range) + + // PERF: exit early if we can guarantee that the range isn't hanging. + if (start.offset !== 0 || end.offset !== 0 || Range.isCollapsed(range)) { + return range + } + + const closestBlock = this.getMatch(end.path, 'block') + const blockPath = closestBlock ? closestBlock[1] : [] + const first = this.getStart() + const before = { anchor: first, focus: end } + let skip = true + + for (const [node, path] of this.texts({ at: before, reverse: true })) { + if (skip) { + skip = false + continue + } + + if (node.text !== '' || Path.isBefore(path, blockPath)) { + end = { path, offset: node.text.length } + break + } + } + + return { anchor: start, focus: end } + } +} + +export default RangeQueries diff --git a/packages/slate/src/classes/queries/value.ts b/packages/slate/src/classes/queries/value.ts deleted file mode 100644 index 7f0fb4982f..0000000000 --- a/packages/slate/src/classes/queries/value.ts +++ /dev/null @@ -1,439 +0,0 @@ -import { reverse as reverseText } from 'esrever' -import { - AnnotationEntry, - Editor, - Element, - ElementEntry, - Mark, - Node, - Location, - NodeEntry, - MarkEntry, - Path, - Point, - Range, - String, - Text, - TextEntry, - Value, -} from '../..' -import { Match } from '../utils' - -class ValueQueries { - /** - * Iterate through all of the annotations in the editor. - */ - - *annotations( - this: Editor, - options: { - at?: Location - } = {} - ): Iterable { - const { annotations } = this.value - const { at } = options - const range = this.getRange(at) - - for (const key in annotations) { - const annotation = annotations[key] - - if (at && !Range.includes(range, annotation)) { - continue - } - - yield [annotation, key] - } - } - - /** - * Check if a node is a match. - */ - - isMatch(this: Editor, entry: NodeEntry, match: Match) { - const [node, path] = entry - - if (typeof match === 'function') { - return match(entry) - } else if (typeof match === 'number') { - return path.length === match - } else if (match === 'text') { - return Text.isText(node) - } else if (match === 'value') { - return Value.isValue(node) - } else if (match === 'inline') { - return ( - (Element.isElement(node) && this.isInline(node)) || Text.isText(node) - ) - } else if (match === 'block') { - return ( - Element.isElement(node) && !this.isInline(node) && this.hasInlines(node) - ) - } else if (match === 'void') { - return Element.isElement(node) && this.isVoid(node) - } else { - return Node.matches(node, match) - } - } - - /** - * Iterate through all of the levels at a location. - */ - - *levels( - this: Editor, - at: Location, - options: { - reverse?: boolean - } = {} - ): Iterable { - const { reverse = false } = options - const levels: NodeEntry[] = [] - const path = this.getPath(at) - - for (const [n, p] of Node.levels(this.value, path)) { - levels.push([n, p]) - - if (Element.isElement(n) && this.isVoid(n)) { - break - } - } - - if (reverse) { - levels.reverse() - } - - yield* levels - } - - /** - * Iterate through all of the elements in the editor. - */ - - *elements( - this: Editor, - options: { - at?: Location - reverse?: boolean - } = {} - ): Iterable { - const { at } = options - const range = this.getRange(at) - const [from, to] = Range.edges(range, options) - - yield* Node.elements(this.value, { - ...options, - from: from.path, - to: to.path, - pass: ([n]) => Element.isElement(n) && this.isVoid(n), - }) - } - - /** - * Iterate through all of the nodes in the editor. - */ - - *entries( - this: Editor, - options: { - at?: Location - reverse?: boolean - } = {} - ): Iterable { - const { at } = options - const range = this.getRange(at) - const [from, to] = Range.edges(range, options) - - yield* Node.entries(this.value, { - ...options, - from: from.path, - to: to.path, - pass: ([n]) => Element.isElement(n) && this.isVoid(n), - }) - } - - /** - * Get the marks that are "active" at a location. These are the - * marks that will be added to any text that is inserted. - * - * The `union: true` option can be passed to create a union of marks across - * the text nodes in the selection, instead of creating an intersection, which - * is the default. - * - * Note: to obey common rich text behavior, if the selection is collapsed at - * the start of a text node and there are previous text nodes in the same - * block, it will carry those marks forward from the previous text node. This - * allows for continuation of marks from previous words. - */ - - getActiveMarks( - this: Editor, - options: { - at?: Location - union?: boolean - } = {} - ): Mark[] { - const { union = false } = options - let { at = this.value.selection } = options - - if (!at) { - return [] - } - - at = this.getRange(at) - - // If the range is collapsed at the start of a text node, it should carry - // over the marks from the previous text node in the same block. - if (Range.isCollapsed(at) && at.anchor.offset === 0) { - const { anchor } = at - const prev = this.getPrevious(anchor, 'text') - - if (prev && Path.isSibling(anchor.path, prev[1])) { - const [prevNode, prevPath] = prev - - if (Text.isText(prevNode)) { - at = this.getRange(prevPath) - } - } - } - - const marks: Mark[] = [] - let first = true - - for (const [node] of this.texts({ at })) { - if (first) { - marks.push(...node.marks) - first = false - continue - } - - if (union) { - for (const mark of node.marks) { - if (!Mark.exists(mark, marks)) { - marks.push(mark) - } - } - } else { - // PERF: If we're doing an intersection and the result hits zero it can - // never increase again, so we can exit early. - if (marks.length === 0) { - break - } - - // Iterate backwards so that removing marks doesn't impact indexing. - for (let i = marks.length - 1; i >= 0; i--) { - const existing = marks[i] - - if (!Mark.exists(existing, node.marks)) { - marks.splice(i, 1) - } - } - } - } - - return marks - } - - /** - * Iterate through all of the text nodes in the editor. - */ - - *marks( - this: Editor, - options: { - at?: Location - reverse?: boolean - } = {} - ): Iterable { - const { at } = options - const range = this.getRange(at) - const [from, to] = Range.edges(range, options) - - yield* Node.marks(this.value, { - ...options, - from: from.path, - to: to.path, - pass: ([n]) => Element.isElement(n) && this.isVoid(n), - }) - } - - /** - * Iterate through all of the nodes that match. - */ - - *matches( - this: Editor, - options: { - match: Match - at: Location - reverse?: boolean - } - ): Iterable { - const { reverse, match } = options - let { at } = options - let prevPath: Path | undefined - - // PERF: If the target is a path, don't traverse. - if (Path.isPath(at)) { - const m = this.getMatch(at, match) - - if (m) { - yield m - } - - return - } - - at = this.getRange(at) - - for (const [n, p] of this.entries({ at, reverse })) { - if (prevPath && Path.compare(p, prevPath) === 0) { - continue - } - - if (this.isMatch([n, p], match)) { - prevPath = p - yield [n, p] - } - } - } - - /** - * Iterate through all of the positions in the document where a `Point` can be - * placed. - * - * By default it will move forward by individual offsets at a time, but you - * can pass the `unit: 'character'` option to moved forward one character, word, - * or line at at time. - * - * Note: void nodes are treated as a single point, and iteration will not - * happen inside their content. - */ - - *positions( - this: Editor, - options: { - at?: Location - unit?: 'offset' | 'character' | 'word' | 'line' | 'block' - reverse?: boolean - } = {} - ): Iterable { - const { at = [], unit = 'offset', reverse = false } = options - const range = this.getRange(at) - const [start, end] = Range.edges(range) - const first = reverse ? end : start - let string = '' - let available = 0 - let offset = 0 - let distance: number | null = null - let isNewBlock = false - - const advance = () => { - if (distance == null) { - if (unit === 'character') { - distance = String.getCharacterDistance(string) - } else if (unit === 'word') { - distance = String.getWordDistance(string) - } else if (unit === 'line' || unit === 'block') { - distance = string.length - } else { - distance = 1 - } - - string = string.slice(distance) - } - - // Add or substract the offset. - offset = reverse ? offset - distance : offset + distance - // Subtract the distance traveled from the available text. - available = available - distance! - // If the available had room to spare, reset the distance so that it will - // advance again next time. Otherwise, set it to the overflow amount. - distance = available >= 0 ? null : 0 - available - } - - for (const [node, path] of this.entries({ at, reverse })) { - if (Element.isElement(node)) { - // Void nodes are a special case, since we don't want to iterate over - // their content. We instead always just yield their first point. - if (this.isVoid(node)) { - yield this.getStart(path) - continue - } - - if (this.isInline(node)) { - continue - } - - if (this.hasInlines(node)) { - let e = Path.isAncestor(path, end.path) ? end : this.getEnd(path) - let s = Path.isAncestor(path, start.path) - ? start - : this.getStart(path) - - const text = this.getText({ anchor: s, focus: e }) - string = reverse ? reverseText(text) : text - isNewBlock = true - } - } - - if (Text.isText(node)) { - const isFirst = Path.equals(path, first.path) - available = node.text.length - offset = reverse ? available : 0 - - if (isFirst) { - available = reverse ? first.offset : available - first.offset - offset = first.offset - } - - if (isFirst || isNewBlock || unit === 'offset') { - yield { path, offset } - } - - while (true) { - // If there's no more string, continue to the next block. - if (string === '') { - break - } else { - advance() - } - - // If the available space hasn't overflow, we have another point to - // yield in the current text node. - if (available >= 0) { - yield { path, offset } - } else { - break - } - } - - isNewBlock = false - } - } - } - - /** - * Iterate through all of the text nodes in the editor. - */ - - *texts( - this: Editor, - options: { - at?: Location - reverse?: boolean - } = {} - ): Iterable { - const { at } = options - const range = this.getRange(at) - const [from, to] = Range.edges(range, options) - - yield* Node.texts(this.value, { - ...options, - from: from.path, - to: to.path, - pass: ([n]) => Element.isElement(n) && this.isVoid(n), - }) - } -} - -export default ValueQueries diff --git a/packages/slate/src/interfaces/location.ts b/packages/slate/src/interfaces/location.ts index 45fd2eba44..923dcb0359 100755 --- a/packages/slate/src/interfaces/location.ts +++ b/packages/slate/src/interfaces/location.ts @@ -21,4 +21,18 @@ namespace Location { } } -export { Location } +type Span = [Path, Path] + +namespace Span { + /** + * Check if a value implements the `Span` interface. + */ + + export const isSpan = (value: any): value is Span => { + return ( + Array.isArray(value) && value.length === 2 && value.every(Path.isPath) + ) + } +} + +export { Location, Span } diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index 608c81c65c..9da00e3f84 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -228,15 +228,7 @@ namespace Node { } = {} ): Iterable { const { pass, reverse = false } = options - let { from = [], to } = options - const start = reverse ? Node.last(root, from) : Node.first(root, from) - from = start[1] - - if (to != null) { - const end = reverse ? Node.first(root, to) : Node.last(root, to) - to = end[1] - } - + const { from = [], to } = options const visited = new Set() let p: Path = [] let n = root diff --git a/packages/slate/test/commands/splitNodes/selection/block-nested-void.js b/packages/slate/test/commands/splitNodes/selection/block-nested-void.js index 94fe49aeb3..e16cf4deb5 100644 --- a/packages/slate/test/commands/splitNodes/selection/block-nested-void.js +++ b/packages/slate/test/commands/splitNodes/selection/block-nested-void.js @@ -22,7 +22,7 @@ export const input = ( export const output = ( - + ) diff --git a/packages/slate/test/commands/splitNodes/selection/inline-void-end.js b/packages/slate/test/commands/splitNodes/selection/inline-void-end.js index a8036a99a7..addd884b8e 100644 --- a/packages/slate/test/commands/splitNodes/selection/inline-void-end.js +++ b/packages/slate/test/commands/splitNodes/selection/inline-void-end.js @@ -30,5 +30,3 @@ export const output = ( ) - -export const skip = true diff --git a/packages/slate/test/queries/getRange/range-backward.js b/packages/slate/test/queries/getRange/range-backward.js new file mode 100644 index 0000000000..938550e805 --- /dev/null +++ b/packages/slate/test/queries/getRange/range-backward.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const input = ( + + one + +) + +export const run = editor => { + return editor.getRange({ + anchor: { path: [0, 0], offset: 2 }, + focus: { path: [0, 0], offset: 1 }, + }) +} + +export const output = { + anchor: { path: [0, 0], offset: 2 }, + focus: { path: [0, 0], offset: 1 }, +} From 93b3ea76213f8c6bbd2fdd1d65dc55f468dc11dc Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 29 Oct 2019 18:00:15 -0400 Subject: [PATCH 081/165] cleanup --- packages/slate/src/classes/commands/mark.ts | 1 - .../slate/src/classes/queries/location.ts | 2 -- .../selection/flat-blocks/end-block.js | 24 ++++++++----------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/slate/src/classes/commands/mark.ts b/packages/slate/src/classes/commands/mark.ts index c87cd52d9f..deaef389bc 100644 --- a/packages/slate/src/classes/commands/mark.ts +++ b/packages/slate/src/classes/commands/mark.ts @@ -107,7 +107,6 @@ class MarkCommands { ) { this.withoutNormalizing(() => { const existing = this.getActiveMarks(options) - debugger const exists = marks.every(m => Mark.exists(m, existing)) if (exists) { diff --git a/packages/slate/src/classes/queries/location.ts b/packages/slate/src/classes/queries/location.ts index 79dcba8b72..6a94140a22 100644 --- a/packages/slate/src/classes/queries/location.ts +++ b/packages/slate/src/classes/queries/location.ts @@ -147,8 +147,6 @@ class LocationQueries { let first = true for (const [node] of this.texts({ at })) { - debugger - if (first) { marks.push(...node.marks) first = false diff --git a/packages/slate/test/commands/insertFragment/selection/flat-blocks/end-block.js b/packages/slate/test/commands/insertFragment/selection/flat-blocks/end-block.js index 03f8a3c619..4dc1ac03ba 100644 --- a/packages/slate/test/commands/insertFragment/selection/flat-blocks/end-block.js +++ b/packages/slate/test/commands/insertFragment/selection/flat-blocks/end-block.js @@ -4,32 +4,28 @@ import h from '../../../../helpers/h' export const run = editor => { editor.insertFragment( - + one two three - + ) } export const input = ( - - - word - - + + word + ) export const output = ( - - wordone - two - - three - - + wordone + two + + three + ) From 880dbf18c3d08810d72fa3e0e2ac23ef1bf5d828 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 29 Oct 2019 18:04:01 -0400 Subject: [PATCH 082/165] get previous packages tests passing again --- .../test/fixtures/cursor-across-element.js | 2 -- .../fixtures/cursor-across-elements-empty.js | 2 -- .../fixtures/cursor-across-elements-end.js | 2 -- .../fixtures/cursor-across-elements-middle.js | 2 -- .../fixtures/cursor-across-elements-start.js | 2 -- .../test/fixtures/cursor-element-empty.js | 2 -- .../test/fixtures/cursor-element-end.js | 2 -- .../test/fixtures/cursor-element-middle.js | 2 -- .../fixtures/cursor-element-nested-end.js | 2 -- .../fixtures/cursor-element-nested-middle.js | 2 -- .../fixtures/cursor-element-nested-start.js | 2 -- .../test/fixtures/cursor-element-start.js | 2 -- .../test/fixtures/cursor-is-focused-false.js | 2 -- .../test/fixtures/cursor-mark-after.js | 2 -- .../test/fixtures/cursor-mark-end.js | 2 -- .../test/fixtures/cursor-mark-middle.js | 2 -- .../test/fixtures/cursor-mark-start.js | 2 -- .../test/fixtures/cursor-marks-empty.js | 2 -- .../test/fixtures/cursor-text-empty.js | 2 -- .../test/fixtures/selection.js | 2 -- ...ustom-property.js => block-custom-prop.js} | 2 +- .../test/fixtures/custom-is-inline.js | 20 ------------------- .../{custom-delimiter.js => delimiter.js} | 0 ...stom-property.js => inline-custom-prop.js} | 0 24 files changed, 1 insertion(+), 61 deletions(-) rename packages/slate-render-plaintext/test/fixtures/{block-custom-property.js => block-custom-prop.js} (76%) delete mode 100644 packages/slate-render-plaintext/test/fixtures/custom-is-inline.js rename packages/slate-render-plaintext/test/fixtures/{custom-delimiter.js => delimiter.js} (100%) rename packages/slate-render-plaintext/test/fixtures/{inline-custom-property.js => inline-custom-prop.js} (100%) diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-element.js b/packages/slate-hyperscript/test/fixtures/cursor-across-element.js index 58f95aef7d..a48b02e2d3 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-element.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-element.js @@ -30,8 +30,6 @@ export const output = { path: [0, 0], offset: 3, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js index 8674741ce7..0d17a7ab75 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-empty.js @@ -45,8 +45,6 @@ export const output = { path: [1, 0], offset: 0, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js index 411f4043b4..bed400d344 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-end.js @@ -41,8 +41,6 @@ export const output = { path: [1, 0], offset: 3, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js index 31b501e6b8..528d6595d2 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-middle.js @@ -41,8 +41,6 @@ export const output = { path: [1, 0], offset: 1, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js index 316ebe2f56..850434bb96 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-across-elements-start.js @@ -41,8 +41,6 @@ export const output = { path: [1, 0], offset: 0, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-element-empty.js index 417718dd83..27e61b2960 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-element-empty.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-empty.js @@ -30,8 +30,6 @@ export const output = { path: [0, 0], offset: 0, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-end.js b/packages/slate-hyperscript/test/fixtures/cursor-element-end.js index f515bb5a75..375536a17e 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-element-end.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-end.js @@ -30,8 +30,6 @@ export const output = { path: [0, 0], offset: 3, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-element-middle.js index 5457c1996a..33fcb62710 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-element-middle.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-middle.js @@ -30,8 +30,6 @@ export const output = { path: [0, 0], offset: 1, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js index 639e0053ed..9d56c7b18b 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-end.js @@ -36,8 +36,6 @@ export const output = { path: [0, 0, 0], offset: 4, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js index 2410501549..cc153ba672 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-middle.js @@ -36,8 +36,6 @@ export const output = { path: [0, 0, 0], offset: 2, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js index 1dce9da12a..5101810662 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-nested-start.js @@ -36,8 +36,6 @@ export const output = { path: [0, 0, 0], offset: 0, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-element-start.js b/packages/slate-hyperscript/test/fixtures/cursor-element-start.js index 66304c6419..797c86b852 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-element-start.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-element-start.js @@ -30,8 +30,6 @@ export const output = { path: [0, 0], offset: 0, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js b/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js index 73a761938a..c37f72a10a 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-is-focused-false.js @@ -30,8 +30,6 @@ export const output = { path: [0, 0], offset: 0, }, - isFocused: false, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js index 34295d6b79..c8984b45e6 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-after.js @@ -35,8 +35,6 @@ export const output = { path: [0, 0], offset: 3, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js index 37ed995ed6..20bc533280 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-end.js @@ -37,8 +37,6 @@ export const output = { path: [0, 0], offset: 3, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js index 24cbb30bca..fdd5f08d5c 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-middle.js @@ -37,8 +37,6 @@ export const output = { path: [0, 0], offset: 1, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js b/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js index 772689ae0f..6c41d7cf52 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-mark-start.js @@ -37,8 +37,6 @@ export const output = { path: [0, 0], offset: 0, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js index 503d26439a..68abe5ea21 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-marks-empty.js @@ -30,8 +30,6 @@ export const output = { path: [0, 0], offset: 0, }, - isFocused: true, - marks: [], }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/cursor-text-empty.js b/packages/slate-hyperscript/test/fixtures/cursor-text-empty.js index 7323b42d05..e9e053a448 100644 --- a/packages/slate-hyperscript/test/fixtures/cursor-text-empty.js +++ b/packages/slate-hyperscript/test/fixtures/cursor-text-empty.js @@ -32,8 +32,6 @@ export const output = { path: [0, 0], offset: 0, }, - isFocused: true, - marks: null, }, annotations: {}, } diff --git a/packages/slate-hyperscript/test/fixtures/selection.js b/packages/slate-hyperscript/test/fixtures/selection.js index 4ceee3a250..880af41bc2 100644 --- a/packages/slate-hyperscript/test/fixtures/selection.js +++ b/packages/slate-hyperscript/test/fixtures/selection.js @@ -32,8 +32,6 @@ export const output = { path: [0, 0], offset: 2, }, - isFocused: false, - marks: null, }, annotations: {}, } diff --git a/packages/slate-render-plaintext/test/fixtures/block-custom-property.js b/packages/slate-render-plaintext/test/fixtures/block-custom-prop.js similarity index 76% rename from packages/slate-render-plaintext/test/fixtures/block-custom-property.js rename to packages/slate-render-plaintext/test/fixtures/block-custom-prop.js index eb0ccbcfab..1449bf492f 100644 --- a/packages/slate-render-plaintext/test/fixtures/block-custom-property.js +++ b/packages/slate-render-plaintext/test/fixtures/block-custom-prop.js @@ -4,7 +4,7 @@ import h from 'slate-hyperscript' export const input = ( - one + one ) diff --git a/packages/slate-render-plaintext/test/fixtures/custom-is-inline.js b/packages/slate-render-plaintext/test/fixtures/custom-is-inline.js deleted file mode 100644 index fdebb7a3f0..0000000000 --- a/packages/slate-render-plaintext/test/fixtures/custom-is-inline.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx h */ - -import h from 'slate-hyperscript' - -export const input = ( - - one{'\n'}same paragraph - two - three - -) - -export const options = { - isInline: () => true, -} - -export const output = ` -one -same paragraphtwothree -`.trim() diff --git a/packages/slate-render-plaintext/test/fixtures/custom-delimiter.js b/packages/slate-render-plaintext/test/fixtures/delimiter.js similarity index 100% rename from packages/slate-render-plaintext/test/fixtures/custom-delimiter.js rename to packages/slate-render-plaintext/test/fixtures/delimiter.js diff --git a/packages/slate-render-plaintext/test/fixtures/inline-custom-property.js b/packages/slate-render-plaintext/test/fixtures/inline-custom-prop.js similarity index 100% rename from packages/slate-render-plaintext/test/fixtures/inline-custom-property.js rename to packages/slate-render-plaintext/test/fixtures/inline-custom-prop.js From da8e1b70fb8c3e1986c6575f2f6af07c30b3d600 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 29 Oct 2019 19:46:03 -0400 Subject: [PATCH 083/165] add slate-history package --- config/rollup/factory.js | 166 ----------------- config/rollup/rollup.config.js | 170 +++++++++++++++++- packages/slate-history/Changelog.md | 5 + packages/slate-history/Readme.md | 1 + packages/slate-history/package.json | 37 ++++ packages/slate-history/src/history.ts | 30 ++++ packages/slate-history/src/index.ts | 2 + .../history => slate-history/src}/plugin.ts | 13 +- packages/slate-history/test/helpers/index.js | 26 +++ packages/slate-history/test/index.js | 19 ++ .../test/undo/addMarks/block-across.js | 20 +++ .../test/undo/addMarks/mark-across.js | 22 +++ .../test/undo/addMarks/mark-from.js | 21 +++ .../slate-history/test/undo/addMarks/text.js | 19 ++ .../test/undo/delete/block-join-reverse.js | 25 +++ .../test/undo/delete/block-nested-reverse.js | 29 +++ .../test/undo/delete/block-text.js | 19 ++ .../test/undo/delete/custom-prop.js | 22 +++ .../test/undo/delete/inline-across.js | 30 ++++ .../test/undo/delete/mark-across.js | 24 +++ .../test/undo/insertFragment/basic.js | 42 +++++ .../test/undo/insertNodes/basic.js | 17 ++ .../test/undo/insertText/basic.js | 17 ++ .../test/undo/insertText/contiguous.js | 21 +++ .../test/undo/insertText/non-contiguous.js | 29 +++ .../slate-history/test/undo/moveNodes/path.js | 16 ++ .../test/undo/removeMarks/basic.js | 19 ++ .../test/undo/removeNodes/path.js | 16 ++ .../slate-history/test/undo/setNodes/basic.js | 16 ++ .../test/undo/splitNodes/basic.js | 20 +++ .../test/undo/toggleMarks/basic.js | 21 +++ .../test/undo/unwrapNodes/basic.js | 24 +++ .../test/undo/wrapNodes/inline.js | 20 +++ packages/slate-history/tsconfig.json | 9 + packages/slate-hyperscript/src/index.ts | 6 +- packages/slate/package.json | 2 - packages/slate/src/classes/editor.ts | 11 +- packages/slate/src/index.ts | 2 +- packages/slate/src/interfaces/operation.ts | 10 +- packages/slate/src/interfaces/path.ts | 8 +- packages/slate/src/plugins/history/history.ts | 46 ----- packages/slate/src/plugins/history/index.ts | 2 - packages/slate/test/helpers/h.js | 52 ------ tsconfig.json | 6 +- 44 files changed, 837 insertions(+), 295 deletions(-) delete mode 100644 config/rollup/factory.js create mode 100644 packages/slate-history/Changelog.md create mode 100644 packages/slate-history/Readme.md create mode 100644 packages/slate-history/package.json create mode 100644 packages/slate-history/src/history.ts create mode 100644 packages/slate-history/src/index.ts rename packages/{slate/src/plugins/history => slate-history/src}/plugin.ts (93%) create mode 100644 packages/slate-history/test/helpers/index.js create mode 100644 packages/slate-history/test/index.js create mode 100644 packages/slate-history/test/undo/addMarks/block-across.js create mode 100644 packages/slate-history/test/undo/addMarks/mark-across.js create mode 100644 packages/slate-history/test/undo/addMarks/mark-from.js create mode 100644 packages/slate-history/test/undo/addMarks/text.js create mode 100644 packages/slate-history/test/undo/delete/block-join-reverse.js create mode 100644 packages/slate-history/test/undo/delete/block-nested-reverse.js create mode 100644 packages/slate-history/test/undo/delete/block-text.js create mode 100644 packages/slate-history/test/undo/delete/custom-prop.js create mode 100644 packages/slate-history/test/undo/delete/inline-across.js create mode 100644 packages/slate-history/test/undo/delete/mark-across.js create mode 100644 packages/slate-history/test/undo/insertFragment/basic.js create mode 100644 packages/slate-history/test/undo/insertNodes/basic.js create mode 100644 packages/slate-history/test/undo/insertText/basic.js create mode 100644 packages/slate-history/test/undo/insertText/contiguous.js create mode 100644 packages/slate-history/test/undo/insertText/non-contiguous.js create mode 100644 packages/slate-history/test/undo/moveNodes/path.js create mode 100644 packages/slate-history/test/undo/removeMarks/basic.js create mode 100644 packages/slate-history/test/undo/removeNodes/path.js create mode 100644 packages/slate-history/test/undo/setNodes/basic.js create mode 100644 packages/slate-history/test/undo/splitNodes/basic.js create mode 100644 packages/slate-history/test/undo/toggleMarks/basic.js create mode 100644 packages/slate-history/test/undo/unwrapNodes/basic.js create mode 100644 packages/slate-history/test/undo/wrapNodes/inline.js create mode 100644 packages/slate-history/tsconfig.json delete mode 100644 packages/slate/src/plugins/history/history.ts delete mode 100644 packages/slate/src/plugins/history/index.ts delete mode 100644 packages/slate/test/helpers/h.js diff --git a/config/rollup/factory.js b/config/rollup/factory.js deleted file mode 100644 index 03bfa2dad0..0000000000 --- a/config/rollup/factory.js +++ /dev/null @@ -1,166 +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 typescript from 'rollup-plugin-typescript2' -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, { ts }) { - const isProd = env === 'production' - const isUmd = target === 'umd' - const isModule = target === 'module' - const input = `packages/${pkg.name}/src/index.${ts ? 'ts' : 'js'}` - const deps = [] - .concat(pkg.dependencies ? Object.keys(pkg.dependencies) : []) - .concat(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []) - - // Stop Rollup from warning about circular dependencies. - const onwarn = warning => { - if (warning.code !== 'CIRCULAR_DEPENDENCY') { - console.warn(`(!) ${warning.message}`) // eslint-disable-line no-console - } - } - - const plugins = [ - // Allow Rollup to resolve modules from `node_modules`, since it only - // resolves local modules by default. - resolve({ - browser: true, - }), - - ts && - typescript({ - abortOnError: false, - tsconfig: `./packages/${pkg.name}/tsconfig.json`, - }), - - // Allow Rollup to resolve CommonJS modules, since it only resolves ES2015 - // modules by default. - 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({ - runtimeHelpers: true, - include: [`packages/${pkg.name}/src/**`], - extensions: ['.js', '.ts'], - // configFile: '../../babel.config.js', - }), - - // 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, - // onwarn, - 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, - // onwarn, - 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, options = {}) { - const isProd = process.env.NODE_ENV === 'production' - return [ - configure(pkg, 'development', 'module', options), - isProd && configure(pkg, 'development', 'umd', options), - isProd && configure(pkg, 'production', 'umd', options), - ].filter(Boolean) -} - -/** - * Export. - * - * @type {Function} - */ - -export default factory diff --git a/config/rollup/rollup.config.js b/config/rollup/rollup.config.js index abeaea5006..0c56b7b2b9 100644 --- a/config/rollup/rollup.config.js +++ b/config/rollup/rollup.config.js @@ -1,7 +1,18 @@ -import factory from './factory' +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 typescript from 'rollup-plugin-typescript2' +import uglify from 'rollup-plugin-uglify' +import { startCase } from 'lodash' + import core from '../../packages/slate/package.json' import base64Serializer from '../../packages/slate-base64-serializer/package.json' import devEnvironment from '../../packages/slate-dev-environment/package.json' +import history from '../../packages/slate-history/package.json' import hotkeys from '../../packages/slate-hotkeys/package.json' import htmlSerializer from '../../packages/slate-html-serializer/package.json' import hyperscript from '../../packages/slate-hyperscript/package.json' @@ -12,10 +23,163 @@ import react from '../../packages/slate-react/package.json' import reactPlaceholder from '../../packages/slate-react-placeholder/package.json' import renderPlaintext from '../../packages/slate-render-plaintext/package.json' -const configurations = [ +/** + * 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, { ts }) { + const isProd = env === 'production' + const isUmd = target === 'umd' + const isModule = target === 'module' + const input = `packages/${pkg.name}/src/index.${ts ? 'ts' : 'js'}` + const deps = [] + .concat(pkg.dependencies ? Object.keys(pkg.dependencies) : []) + .concat(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []) + + // Stop Rollup from warning about circular dependencies. + const onwarn = warning => { + if (warning.code !== 'CIRCULAR_DEPENDENCY') { + console.warn(`(!) ${warning.message}`) // eslint-disable-line no-console + } + } + + const plugins = [ + // Allow Rollup to resolve modules from `node_modules`, since it only + // resolves local modules by default. + resolve({ + browser: true, + }), + + ts && + typescript({ + abortOnError: false, + tsconfig: `./packages/${pkg.name}/tsconfig.json`, + }), + + // Allow Rollup to resolve CommonJS modules, since it only resolves ES2015 + // modules by default. + 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({ + runtimeHelpers: true, + include: [`packages/${pkg.name}/src/**`], + extensions: ['.js', '.ts'], + // configFile: '../../babel.config.js', + }), + + // 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, + // onwarn, + 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, + // onwarn, + 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, options = {}) { + const isProd = process.env.NODE_ENV === 'production' + return [ + configure(pkg, 'development', 'module', options), + isProd && configure(pkg, 'development', 'umd', options), + isProd && configure(pkg, 'production', 'umd', options), + ].filter(Boolean) +} + +/** + * Config. + */ + +export default [ ...factory(core, { ts: true }), ...factory(base64Serializer), ...factory(devEnvironment), + ...factory(history, { ts: true }), ...factory(hotkeys), ...factory(htmlSerializer), ...factory(hyperscript, { ts: true }), @@ -26,5 +190,3 @@ const configurations = [ ...factory(reactPlaceholder), ...factory(renderPlaintext, { ts: true }), ] - -export default configurations diff --git a/packages/slate-history/Changelog.md b/packages/slate-history/Changelog.md new file mode 100644 index 0000000000..b79fccc567 --- /dev/null +++ b/packages/slate-history/Changelog.md @@ -0,0 +1,5 @@ +# Changelog + +A list of changes to the `slate-history` package with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and smaller changes won't be accounted for since the library is moving quickly. + +--- diff --git a/packages/slate-history/Readme.md b/packages/slate-history/Readme.md new file mode 100644 index 0000000000..47ac3a1b6d --- /dev/null +++ b/packages/slate-history/Readme.md @@ -0,0 +1 @@ +This package contains the core logic of Slate. Feel free to poke around to learn more! diff --git a/packages/slate-history/package.json b/packages/slate-history/package.json new file mode 100644 index 0000000000..316c222ae6 --- /dev/null +++ b/packages/slate-history/package.json @@ -0,0 +1,37 @@ +{ + "name": "slate-history", + "description": "An operation-based history implementation for Slate editors.", + "version": "0.47.8", + "license": "MIT", + "repository": "git://github.com/ianstormtaylor/slate.git", + "main": "lib/index.js", + "module": "lib/index.es.js", + "types": "lib/index.d.ts", + "umd": "dist/slate-history.js", + "umdMin": "dist/slate-history.min.js", + "files": [ + "dist/", + "lib/" + ], + "dependencies": { + "immer": "^4.0.1", + "is-plain-object": "^2.0.4", + "tiny-invariant": "^1.0.1", + "tiny-warning": "^0.0.3" + }, + "peerDependencies": { + "slate": ">=0.47.0" + }, + "devDependencies": { + "slate": "^0.47.8", + "slate-hyperscript": "^0.13.8" + }, + "keywords": [ + "editor", + "history", + "operation", + "redo", + "slate", + "undo" + ] +} diff --git a/packages/slate-history/src/history.ts b/packages/slate-history/src/history.ts new file mode 100644 index 0000000000..8451e58f66 --- /dev/null +++ b/packages/slate-history/src/history.ts @@ -0,0 +1,30 @@ +import isPlainObject from 'is-plain-object' +import { Operation } from 'slate' + +/** + * `History` objects hold all of the operations that are applied to a value, so + * they can be undone or redone as necessary. + */ + +interface History { + redos: Operation[][] + undos: Operation[][] +} + +namespace History { + /** + * Check if a value is a `History` object. + */ + + export const isHistory = (value: any): value is History => { + return ( + isPlainObject(value) && + Array.isArray(value.redos) && + Array.isArray(value.undos) && + (value.redos.length === 0 || Operation.isOperationList(value.redos[0])) && + (value.undos.length === 0 || Operation.isOperationList(value.undos[0])) + ) + } +} + +export { History } diff --git a/packages/slate-history/src/index.ts b/packages/slate-history/src/index.ts new file mode 100644 index 0000000000..a2764a987d --- /dev/null +++ b/packages/slate-history/src/index.ts @@ -0,0 +1,2 @@ +export { HistoryPlugin } from './plugin' +export { History } from './history' diff --git a/packages/slate/src/plugins/history/plugin.ts b/packages/slate-history/src/plugin.ts similarity index 93% rename from packages/slate/src/plugins/history/plugin.ts rename to packages/slate-history/src/plugin.ts index 5398e51ae8..923c037f16 100644 --- a/packages/slate/src/plugins/history/plugin.ts +++ b/packages/slate-history/src/plugin.ts @@ -1,5 +1,5 @@ import { produce } from 'immer' -import { EditorConstructor, Operation, Path } from '../..' +import { EditorPlugin, EditorConstructor, Operation, Path } from 'slate' import { History } from './history' const HISTORY = Symbol('history') @@ -11,9 +11,9 @@ const MERGING = Symbol('merging') * operations are applied to it, using undo and redo stacks. */ -const HistoryPlugin = () => { - return (Base: EditorConstructor) => { - return class extends Base { +const HistoryPlugin: EditorPlugin = () => { + return (Editor: EditorConstructor) => { + return class extends Editor { [HISTORY]: History; [MERGING]: boolean | null; [SAVING]: boolean @@ -88,7 +88,7 @@ const HistoryPlugin = () => { } /** - * Redo to the next value in the history. + * Redo the last batch of operations in the history. */ redo(): void { @@ -116,7 +116,7 @@ const HistoryPlugin = () => { } /** - * Undo the previous operations in the history. + * Undo the last batch of operations in the history. */ undo(): void { @@ -132,6 +132,7 @@ const HistoryPlugin = () => { this.withoutSaving(() => { this.withoutNormalizing(() => { const inverseOps = batch.map(Operation.inverse).reverse() + debugger for (const op of inverseOps) { this.apply(op) diff --git a/packages/slate-history/test/helpers/index.js b/packages/slate-history/test/helpers/index.js new file mode 100644 index 0000000000..5167f6b467 --- /dev/null +++ b/packages/slate-history/test/helpers/index.js @@ -0,0 +1,26 @@ +import { createHyperscript } from 'slate-hyperscript' + +const h = createHyperscript({ + elements: { + block: {}, + inline: { inline: true }, + }, +}) + +const HelpersPlugin = () => Editor => { + return class extends Editor { + isAtomic(mark) { + return mark.atomic === true ? true : super.isAtomic(mark) + } + + isInline(node) { + return node.inline === true ? true : super.isInline(node) + } + + isVoid(node) { + return node.void === true ? true : super.isVoid(node) + } + } +} + +export { h, HelpersPlugin } diff --git a/packages/slate-history/test/index.js b/packages/slate-history/test/index.js new file mode 100644 index 0000000000..24edac81f3 --- /dev/null +++ b/packages/slate-history/test/index.js @@ -0,0 +1,19 @@ +import assert from 'assert' +import { fixtures } from '../../../support/fixtures' +import { Editor } from 'slate' +import { HelpersPlugin } from './helpers' +import { HistoryPlugin } from '..' + +describe('slate-history', () => { + fixtures(__dirname, 'undo', ({ module }) => { + const { input, run, output } = module + const withHistory = HistoryPlugin() + const withHelpers = HelpersPlugin() + const TestEditor = withHelpers(withHistory(Editor)) + const editor = new TestEditor({ value: input }) + run(editor) + editor.flush() + editor.undo() + assert.deepEqual(editor.value, output) + }) +}) diff --git a/packages/slate-history/test/undo/addMarks/block-across.js b/packages/slate-history/test/undo/addMarks/block-across.js new file mode 100644 index 0000000000..700aee0fd9 --- /dev/null +++ b/packages/slate-history/test/undo/addMarks/block-across.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.addMarks([{ key: 'a' }]) +} + +export const input = ( + + + one + + + two + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/addMarks/mark-across.js b/packages/slate-history/test/undo/addMarks/mark-across.js new file mode 100644 index 0000000000..eab9defa73 --- /dev/null +++ b/packages/slate-history/test/undo/addMarks/mark-across.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.addMarks([{ key: 'a' }]) + editor.flush() + editor.undo() +} + +export const input = ( + + + + wo + + rd + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/addMarks/mark-from.js b/packages/slate-history/test/undo/addMarks/mark-from.js new file mode 100644 index 0000000000..250e41982e --- /dev/null +++ b/packages/slate-history/test/undo/addMarks/mark-from.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.addMarks([{ key: 'a' }]) + editor.flush() + editor.undo() +} + +export const input = ( + + + + wo + rd + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/addMarks/text.js b/packages/slate-history/test/undo/addMarks/text.js new file mode 100644 index 0000000000..60441ce9ea --- /dev/null +++ b/packages/slate-history/test/undo/addMarks/text.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.addMarks([{ key: 'a' }]) + editor.flush() + editor.undo() +} + +export const input = ( + + + word + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/delete/block-join-reverse.js b/packages/slate-history/test/undo/delete/block-join-reverse.js new file mode 100644 index 0000000000..29658c607a --- /dev/null +++ b/packages/slate-history/test/undo/delete/block-join-reverse.js @@ -0,0 +1,25 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.delete({ reverse: true }) +} + +export const input = ( + + Hello + + world! + + +) + +export const output = ( + + Hello + + world! + + +) diff --git a/packages/slate-history/test/undo/delete/block-nested-reverse.js b/packages/slate-history/test/undo/delete/block-nested-reverse.js new file mode 100644 index 0000000000..6538b79314 --- /dev/null +++ b/packages/slate-history/test/undo/delete/block-nested-reverse.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.delete({ reverse: true }) +} + +export const input = ( + + Hello + + + world! + + + +) + +export const output = ( + + Hello + + + world! + + + +) diff --git a/packages/slate-history/test/undo/delete/block-text.js b/packages/slate-history/test/undo/delete/block-text.js new file mode 100644 index 0000000000..c29d1ac59f --- /dev/null +++ b/packages/slate-history/test/undo/delete/block-text.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.delete() +} + +export const input = ( + + + word + + +) + +export const output = input + +export const skip = true diff --git a/packages/slate-history/test/undo/delete/custom-prop.js b/packages/slate-history/test/undo/delete/custom-prop.js new file mode 100644 index 0000000000..71655a89a1 --- /dev/null +++ b/packages/slate-history/test/undo/delete/custom-prop.js @@ -0,0 +1,22 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.delete() +} + +export const input = ( + + + one + + + two + + +) + +export const output = input + +export const skip = true diff --git a/packages/slate-history/test/undo/delete/inline-across.js b/packages/slate-history/test/undo/delete/inline-across.js new file mode 100644 index 0000000000..ee8bd63af9 --- /dev/null +++ b/packages/slate-history/test/undo/delete/inline-across.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.delete() +} + +export const input = ( + + + + + one + + + + + + + two + + + + +) + +export const output = input + +export const skip = true diff --git a/packages/slate-history/test/undo/delete/mark-across.js b/packages/slate-history/test/undo/delete/mark-across.js new file mode 100644 index 0000000000..7f1a8be151 --- /dev/null +++ b/packages/slate-history/test/undo/delete/mark-across.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.delete() +} + +export const input = ( + + + + one + + + two + + + +) + +export const output = input + +export const skip = true diff --git a/packages/slate-history/test/undo/insertFragment/basic.js b/packages/slate-history/test/undo/insertFragment/basic.js new file mode 100644 index 0000000000..d5983d7997 --- /dev/null +++ b/packages/slate-history/test/undo/insertFragment/basic.js @@ -0,0 +1,42 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +const fragment = ( + + A + + + B + + + C + + + + + D + + + +) + +export const run = editor => { + editor.insertFragment(fragment) +} + +export const input = ( + + + + + + + + + +) + +export const output = input + +export const skip = true diff --git a/packages/slate-history/test/undo/insertNodes/basic.js b/packages/slate-history/test/undo/insertNodes/basic.js new file mode 100644 index 0000000000..ada9131e2f --- /dev/null +++ b/packages/slate-history/test/undo/insertNodes/basic.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.insertNodes(two) +} + +export const input = ( + + + one + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/insertText/basic.js b/packages/slate-history/test/undo/insertText/basic.js new file mode 100644 index 0000000000..dc35bfe4bb --- /dev/null +++ b/packages/slate-history/test/undo/insertText/basic.js @@ -0,0 +1,17 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.insertText('text') +} + +export const input = ( + + + one + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/insertText/contiguous.js b/packages/slate-history/test/undo/insertText/contiguous.js new file mode 100644 index 0000000000..18b0498edb --- /dev/null +++ b/packages/slate-history/test/undo/insertText/contiguous.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.insertText('t') + editor.flush() + editor.insertText('w') + editor.flush() + editor.insertText('o') +} + +export const input = ( + + + one + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/insertText/non-contiguous.js b/packages/slate-history/test/undo/insertText/non-contiguous.js new file mode 100644 index 0000000000..6c15f9a6e2 --- /dev/null +++ b/packages/slate-history/test/undo/insertText/non-contiguous.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.insertText('t') + editor.flush() + editor.move({ reverse: true }) + editor.insertText('w') + editor.flush() + editor.move({ reverse: true }) + editor.insertText('o') +} + +export const input = ( + + + one + + +) + +export const output = ( + + + onewt + + +) diff --git a/packages/slate-history/test/undo/moveNodes/path.js b/packages/slate-history/test/undo/moveNodes/path.js new file mode 100644 index 0000000000..cee13f4864 --- /dev/null +++ b/packages/slate-history/test/undo/moveNodes/path.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.moveNodes({ at: [0], to: [1] }) +} + +export const input = ( + + one + two + +) + +export const output = input diff --git a/packages/slate-history/test/undo/removeMarks/basic.js b/packages/slate-history/test/undo/removeMarks/basic.js new file mode 100644 index 0000000000..5aebdc8249 --- /dev/null +++ b/packages/slate-history/test/undo/removeMarks/basic.js @@ -0,0 +1,19 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.removeMarks([{ key: true }]) +} + +export const input = ( + + + + one + + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/removeNodes/path.js b/packages/slate-history/test/undo/removeNodes/path.js new file mode 100644 index 0000000000..2fba08b5ff --- /dev/null +++ b/packages/slate-history/test/undo/removeNodes/path.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.removeNodes({ at: [0] }) +} + +export const input = ( + + one + two + +) + +export const output = input diff --git a/packages/slate-history/test/undo/setNodes/basic.js b/packages/slate-history/test/undo/setNodes/basic.js new file mode 100644 index 0000000000..24623152e1 --- /dev/null +++ b/packages/slate-history/test/undo/setNodes/basic.js @@ -0,0 +1,16 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.setNodes({ key: true }) +} + +export const input = ( + + one + two + +) + +export const output = input diff --git a/packages/slate-history/test/undo/splitNodes/basic.js b/packages/slate-history/test/undo/splitNodes/basic.js new file mode 100644 index 0000000000..2e6703a61c --- /dev/null +++ b/packages/slate-history/test/undo/splitNodes/basic.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.splitNodes() +} + +export const input = ( + + + + one + + two + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/toggleMarks/basic.js b/packages/slate-history/test/undo/toggleMarks/basic.js new file mode 100644 index 0000000000..cb3a93d79d --- /dev/null +++ b/packages/slate-history/test/undo/toggleMarks/basic.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.toggleMarks([{ key: 'a' }]) +} + +export const input = ( + + + one + + two + + three + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/unwrapNodes/basic.js b/packages/slate-history/test/undo/unwrapNodes/basic.js new file mode 100644 index 0000000000..eba4186392 --- /dev/null +++ b/packages/slate-history/test/undo/unwrapNodes/basic.js @@ -0,0 +1,24 @@ +/** @jsx h */ + +import { h } from '../../helpers' +import { PathUtils } from 'slate' + +export const run = editor => { + editor.unwrapNodes({ key: 'a' }) + editor.flush() + editor.undo() +} + +export const input = ( + + + + one + + two + three + + +) + +export const output = input diff --git a/packages/slate-history/test/undo/wrapNodes/inline.js b/packages/slate-history/test/undo/wrapNodes/inline.js new file mode 100644 index 0000000000..ee3c08fb33 --- /dev/null +++ b/packages/slate-history/test/undo/wrapNodes/inline.js @@ -0,0 +1,20 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const run = editor => { + editor.wrapNodes() +} + +export const input = ( + + + word + + + another + + +) + +export const output = input diff --git a/packages/slate-history/tsconfig.json b/packages/slate-history/tsconfig.json new file mode 100644 index 0000000000..4463c7357c --- /dev/null +++ b/packages/slate-history/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../config/typescript/tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib", + "composite": true + }, + "references": [] +} diff --git a/packages/slate-hyperscript/src/index.ts b/packages/slate-hyperscript/src/index.ts index bb2a3524f6..6f97015c64 100644 --- a/packages/slate-hyperscript/src/index.ts +++ b/packages/slate-hyperscript/src/index.ts @@ -122,7 +122,7 @@ const normalizeElements = (elements: HyperscriptShorthands) => { if (typeof props !== 'object') { throw new Error( - `Properties specified for a hyperscript shorthand should be an object, but for the custom <${tagName}> tag you passed: ${props}` + `Properties specified for a hyperscript shorthand should be an object, but for the custom element <${tagName}> tag you passed: ${props}` ) } @@ -150,7 +150,7 @@ const normalizeMarks = (marks: HyperscriptShorthands) => { if (typeof props !== 'object') { throw new Error( - `Properties specified for a hyperscript shorthand should be an object, but for the custom <${tagName}> tag you passed: ${props}` + `Properties specified for a hyperscript shorthand should be an object, but for the custom mark <${tagName}> tag you passed: ${props}` ) } @@ -178,7 +178,7 @@ const normalizeAnnotations = (annotations: HyperscriptShorthands) => { if (typeof props !== 'object') { throw new Error( - `Properties specified for a hyperscript shorthand should be an object, but for the custom <${tagName}> tag you passed: ${props}` + `Properties specified for a hyperscript shorthand should be an object, but for the custom annotation <${tagName}> tag you passed: ${props}` ) } diff --git a/packages/slate/package.json b/packages/slate/package.json index effeedc271..b74b761f94 100644 --- a/packages/slate/package.json +++ b/packages/slate/package.json @@ -15,7 +15,6 @@ ], "dependencies": { "@types/esrever": "^0.2.0", - "debug": "^3.1.0", "esrever": "^0.2.0", "immer": "^4.0.1", "is-plain-object": "^2.0.4", @@ -23,7 +22,6 @@ "tiny-warning": "^0.0.3" }, "devDependencies": { - "slate-dev-test-utils": "^0.0.1", "slate-hyperscript": "^0.13.8" }, "keywords": [ diff --git a/packages/slate/src/classes/editor.ts b/packages/slate/src/classes/editor.ts index 97c31590e2..13f6d71174 100755 --- a/packages/slate/src/classes/editor.ts +++ b/packages/slate/src/classes/editor.ts @@ -26,6 +26,15 @@ import RangeQueries from './queries/range' type EditorConstructor = new (...args: any[]) => Editor +/** + * The `EditorPlugin` interface is provided as a convenience for plugins + * who can use it when writing the typings for their plugin functions. + */ + +type EditorPlugin = ( + ...args: any +) => ((Editor: EditorConstructor) => EditorConstructor) + /** * The `Editor` class stores all the state of a Slate editor. It is extended by * plugins that wish to add their own methods that implement new behaviors. @@ -107,4 +116,4 @@ mixin([ RangeQueries, ]) -export { Editor, EditorConstructor } +export { Editor, EditorConstructor, EditorPlugin } diff --git a/packages/slate/src/index.ts b/packages/slate/src/index.ts index 342712642f..44a3ab4553 100755 --- a/packages/slate/src/index.ts +++ b/packages/slate/src/index.ts @@ -1,4 +1,4 @@ -export { Editor, EditorConstructor } from './classes/editor' +export { Editor, EditorConstructor, EditorPlugin } from './classes/editor' export { PathRef } from './classes/path-ref' export { PointRef } from './classes/point-ref' export { RangeRef } from './classes/range-ref' diff --git a/packages/slate/src/interfaces/operation.ts b/packages/slate/src/interfaces/operation.ts index f6008307ca..1f0b44f9b9 100755 --- a/packages/slate/src/interfaces/operation.ts +++ b/packages/slate/src/interfaces/operation.ts @@ -365,7 +365,7 @@ namespace Operation { } case 'insert_node': { - return { ...op, type: 'insert_node' } + return { ...op, type: 'remove_node' } } case 'insert_text': { @@ -387,11 +387,9 @@ namespace Operation { // We need to get the original path here, but sometimes the `newPath` // is a younger sibling of (or ends before) the original, and this // accounts for it. - return { - ...op, - path: Path.transform(path, op)!, - newPath: Path.transform(Path.next(path), op)!, - } + const inversePath = Path.transform(path, op)! + const inverseNewPath = Path.transform(Path.next(path), op)! + return { ...op, path: inversePath, newPath: inverseNewPath } } case 'remove_annotation': { diff --git a/packages/slate/src/interfaces/path.ts b/packages/slate/src/interfaces/path.ts index 639f9733fe..9fb54929b9 100755 --- a/packages/slate/src/interfaces/path.ts +++ b/packages/slate/src/interfaces/path.ts @@ -410,16 +410,14 @@ namespace Path { return copy.concat(p.slice(op.length)) } else { - const copy = p.slice() - if (Path.endsBefore(op, p)) { p[op.length - 1] -= 1 } if ( - Path.endsBefore(onp, copy) || - Path.equals(onp, copy) || - Path.isAncestor(onp, copy) + Path.endsBefore(onp, p) || + Path.equals(onp, p) || + Path.isAncestor(onp, p) ) { p[onp.length - 1] += 1 } diff --git a/packages/slate/src/plugins/history/history.ts b/packages/slate/src/plugins/history/history.ts deleted file mode 100644 index a016467ca4..0000000000 --- a/packages/slate/src/plugins/history/history.ts +++ /dev/null @@ -1,46 +0,0 @@ -import isPlainObject from 'is-plain-object' -import { Operation } from '../..' - -/** - * `HistoryBatch` arrays hold a batch of operations that are applied as a single - * step in the history. They can be merged together with previous batches. - */ - -type HistoryBatch = Operation[] - -/** - * `History` objects hold all of the operations that are applied to a value, so - * they can be undone or redone as necessary. - */ - -interface History { - redos: HistoryBatch[] - undos: HistoryBatch[] -} - -namespace History { - /** - * Check if an object implements the `History` interface. - */ - - export const isHistory = (object: any): object is History => { - return ( - isPlainObject(object) && - isHistoryBatch(object.redos) && - isHistoryBatch(object.undos) - ) - } - - /** - * Check if an object implements the `HistoryBatch` interface. - */ - - export const isHistoryBatch = (object: any): object is HistoryBatch => { - return ( - Array.isArray(object) && - (object.length === 0 || Operation.isOperation(object[0])) - ) - } -} - -export { History, HistoryBatch } diff --git a/packages/slate/src/plugins/history/index.ts b/packages/slate/src/plugins/history/index.ts deleted file mode 100644 index 973119ebbc..0000000000 --- a/packages/slate/src/plugins/history/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { HistoryPlugin } from './plugin' -export { History, HistoryBatch } from './history' diff --git a/packages/slate/test/helpers/h.js b/packages/slate/test/helpers/h.js deleted file mode 100644 index dea1347561..0000000000 --- a/packages/slate/test/helpers/h.js +++ /dev/null @@ -1,52 +0,0 @@ -import { createHyperscript } from 'slate-hyperscript' - -const h = createHyperscript({ - blocks: { - line: 'line', - paragraph: 'paragraph', - quote: 'quote', - code: 'code', - list: 'list', - item: 'item', - image: 'image', - table: 'table', - table_body: 'table_body', - table_row: 'table_row', - table_cell: 'table_cell', - }, - inlines: { - link: 'link', - hashtag: 'hashtag', - comment: 'comment', - emoji: 'emoji', - }, - marks: { - b: 'bold', - i: 'italic', - u: 'underline', - fontSize: 'font-size', - }, - annotations: { - result: 'result', - highlight: 'highlight', - }, - schema: { - blocks: { - image: { - isVoid: true, - }, - }, - inlines: { - emoji: { - isVoid: true, - }, - }, - annotations: { - result: { - isAtomic: true, - }, - }, - }, -}) - -export default h diff --git a/tsconfig.json b/tsconfig.json index 607f062545..b2c67b28f3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,10 @@ { "extends": "./config/typescript/tsconfig.json", - "references": [{ "path": "./packages/slate" }], + "references": [ + { "path": "./packages/slate" }, + { "path": "./packages/slate-hyperscript" }, + { "path": "./packages/slate-history" } + ], "files": [], "typedocOptions": { "excludeExternals": true, From b3ea0093be83e72387334b0db6c60b6ab92d8589 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 30 Oct 2019 12:04:23 -0400 Subject: [PATCH 084/165] start slate-schema work --- config/rollup/rollup.config.js | 54 +++--- packages/slate-schema/Changelog.md | 5 + packages/slate-schema/Readme.md | 1 + packages/slate-schema/package.json | 33 ++++ .../schema => slate-schema/src}/checkers.ts | 166 ++++++++-------- .../schema => slate-schema/src}/error.ts | 85 ++++---- .../schema => slate-schema/src}/index.ts | 0 .../schema => slate-schema/src}/plugin.ts | 183 +++++++++++------- .../schema => slate-schema/src}/rule.ts | 18 +- ...hild-kind-invalid-custom-optional-first.js | 0 .../test/errors}/child-kind-invalid-custom.js | 0 .../errors}/child-kind-invalid-default.js | 0 .../errors}/child-kind-invalid-function.js | 0 .../child-min-invalid-at-end-custom.js | 0 .../child-min-invalid-at-end-default.js | 0 .../test/errors}/child-min-invalid-custom.js | 0 .../test/errors}/child-min-invalid-default.js | 0 .../child-min-invalid-with-invalid-default.js | 0 .../test/errors/child-min-invalid/remove.js | 23 +++ .../errors/child-min-invalid/second-group.js | 23 +++ .../errors}/child-min-max-invalid-default.js | 0 .../child-min-max-invalid-similar-valid.js | 0 .../errors}/child-min-max-invalid-valid.js | 0 .../errors/child-object-invalid/remove.js | 29 +++ .../child-property-invalid/unset-function.js | 37 ++++ .../child-property-invalid/unset-value.js | 37 ++++ .../test/errors}/child-type-invalid-custom.js | 0 .../errors}/child-type-invalid-default.js | 0 .../errors}/child-type-invalid-function.js | 0 .../test/errors/child-unexpected/remove.js | 30 +++ .../errors/child-unexpected/second-group.js | 32 +++ .../test/errors}/child-unknown-custom.js | 0 .../test/errors}/child-unknown-default.js | 0 .../first-child-kind-invalid-custom.js | 0 .../first-child-kind-invalid-default.js | 0 .../first-child-kind-invalid-function.js | 0 .../first-child-object-invalid/remove.js | 23 +++ .../first-child-type-invalid-custom.js | 0 .../first-child-type-invalid-default.js | 0 .../first-child-type-invalid-function.js | 0 .../errors}/last-child-kind-invalid-custom.js | 0 .../last-child-kind-invalid-default.js | 0 .../last-child-kind-invalid-function.js | 0 .../errors}/last-child-type-invalid-custom.js | 0 .../last-child-type-invalid-default.js | 0 .../last-child-type-invalid-function.js | 0 .../test/errors}/match-data.js | 0 .../test/errors}/match-object.js | 0 .../test/errors}/match-type.js | 0 .../test/errors}/next-kind-invalid-custom.js | 0 .../test/errors}/next-kind-invalid-default.js | 0 .../errors}/next-kind-invalid-function.js | 0 .../test/errors}/next-type-invalid-custom.js | 0 .../test/errors}/next-type-invalid-default.js | 0 .../errors}/next-type-invalid-function.js | 0 .../test/errors}/node-data-invalid-custom.js | 0 .../node-data-invalid-default-undefined.js | 0 .../test/errors}/node-data-invalid-default.js | 0 .../errors}/node-data-invalid-function.js | 0 .../test/errors}/node-mark-invalid-custom.js | 0 .../test/errors}/node-mark-invalid-default.js | 0 .../errors}/node-mark-invalid-function.js | 0 .../test/errors}/node-mark-valid-default.js | 0 .../node-property-invalid/remove-function.js | 27 +++ .../node-property-invalid/remove-value.js | 23 +++ .../node-property-invalid/unset-value.js | 27 +++ .../test/errors}/node-text-invalid-custom.js | 0 .../test/errors}/node-text-invalid-default.js | 0 .../errors}/node-text-invalid-function.js | 0 .../node-text-invalid/remove-function.js | 21 ++ .../test/errors}/node-text-valid-function.js | 0 .../test/errors}/node-text-valid.js | 0 .../test/errors}/node-type-invalid-default.js | 0 .../errors}/node-type-invalid-function.js | 0 .../errors}/parent-kind-invalid-custom.js | 0 .../errors}/parent-kind-invalid-default.js | 0 .../errors}/parent-kind-invalid-function.js | 0 .../errors}/parent-type-invalid-custom.js | 0 .../errors}/parent-type-invalid-default.js | 0 .../errors}/parent-type-invalid-function.js | 0 .../errors}/previous-kind-invalid-custom.js | 0 .../errors}/previous-kind-invalid-default.js | 0 .../errors}/previous-kind-invalid-function.js | 0 .../errors}/previous-type-invalid-custom.js | 0 .../errors}/previous-type-invalid-default.js | 0 .../errors}/previous-type-invalid-function.js | 0 packages/slate-schema/test/helpers/index.js | 11 ++ packages/slate-schema/test/index.js | 15 ++ packages/slate-schema/tsconfig.json | 9 + .../history/undo/add-mark-across-blocks.js | 24 --- .../history/undo/add-mark-across-marks.js | 23 --- .../history/undo/add-mark-across-same-mark.js | 23 --- packages/slate/test/history/undo/add-mark.js | 21 -- .../test/history/undo/delete-across-blocks.js | 26 --- .../history/undo/delete-across-inlines.js | 32 --- .../test/history/undo/delete-across-marks.js | 26 --- .../undo/delete-backward-nested-blocks.js | 34 ---- .../test/history/undo/delete-backward.js | 30 --- packages/slate/test/history/undo/delete.js | 21 -- .../slate/test/history/undo/insert-block.js | 21 -- .../test/history/undo/insert-fragment.js | 46 ----- .../history/undo/insert-text-contiguous.js | 25 --- .../undo/insert-text-not-contiguous.js | 38 ---- .../slate/test/history/undo/insert-text.js | 21 -- .../history/undo/move-node-affecting-path.js | 25 --- .../history/undo/move-node-before-itself.js | 30 --- ...move-node-by-path-ancestor-left-sibling.js | 25 --- .../test/history/undo/move-node-by-path.js | 25 --- .../slate/test/history/undo/remove-mark.js | 23 --- .../test/history/undo/remove-node-by-path.js | 22 --- .../slate/test/history/undo/remove-text.js | 31 --- .../undo/set-node-by-path-with-data.js | 23 --- .../history/undo/split-node-by-path-block.js | 28 --- .../slate/test/history/undo/toggle-mark.js | 35 ---- .../test/history/undo/unwrap-node-by-path.js | 26 --- .../history/undo/wrap-inline-across-blocks.js | 24 --- .../child-max-invalid-at-end-default.js | 44 ----- .../schema/custom/child-max-invalid-custom.js | 52 ----- .../custom/child-max-invalid-default.js | 47 ----- .../custom/node-object-invalid-default.js | 25 --- .../custom/node-object-invalid-function.js | 25 --- tsconfig.json | 1 + 122 files changed, 688 insertions(+), 1146 deletions(-) create mode 100644 packages/slate-schema/Changelog.md create mode 100644 packages/slate-schema/Readme.md create mode 100644 packages/slate-schema/package.json rename packages/{slate/src/plugins/schema => slate-schema/src}/checkers.ts (72%) rename packages/{slate/src/plugins/schema => slate-schema/src}/error.ts (68%) rename packages/{slate/src/plugins/schema => slate-schema/src}/index.ts (100%) rename packages/{slate/src/plugins/schema => slate-schema/src}/plugin.ts (59%) rename packages/{slate/src/plugins/schema => slate-schema/src}/rule.ts (93%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-kind-invalid-custom-optional-first.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-kind-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-kind-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-kind-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-invalid-at-end-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-invalid-at-end-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-invalid-with-invalid-default.js (100%) create mode 100644 packages/slate-schema/test/errors/child-min-invalid/remove.js create mode 100644 packages/slate-schema/test/errors/child-min-invalid/second-group.js rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-max-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-max-invalid-similar-valid.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-min-max-invalid-valid.js (100%) create mode 100644 packages/slate-schema/test/errors/child-object-invalid/remove.js create mode 100644 packages/slate-schema/test/errors/child-property-invalid/unset-function.js create mode 100644 packages/slate-schema/test/errors/child-property-invalid/unset-value.js rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-type-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-type-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-type-invalid-function.js (100%) create mode 100644 packages/slate-schema/test/errors/child-unexpected/remove.js create mode 100644 packages/slate-schema/test/errors/child-unexpected/second-group.js rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-unknown-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/child-unknown-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/first-child-kind-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/first-child-kind-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/first-child-kind-invalid-function.js (100%) create mode 100644 packages/slate-schema/test/errors/first-child-object-invalid/remove.js rename packages/{slate/test/schema/custom => slate-schema/test/errors}/first-child-type-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/first-child-type-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/first-child-type-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/last-child-kind-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/last-child-kind-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/last-child-kind-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/last-child-type-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/last-child-type-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/last-child-type-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/match-data.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/match-object.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/match-type.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/next-kind-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/next-kind-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/next-kind-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/next-type-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/next-type-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/next-type-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-data-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-data-invalid-default-undefined.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-data-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-data-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-mark-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-mark-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-mark-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-mark-valid-default.js (100%) create mode 100644 packages/slate-schema/test/errors/node-property-invalid/remove-function.js create mode 100644 packages/slate-schema/test/errors/node-property-invalid/remove-value.js create mode 100644 packages/slate-schema/test/errors/node-property-invalid/unset-value.js rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-text-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-text-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-text-invalid-function.js (100%) create mode 100644 packages/slate-schema/test/errors/node-text-invalid/remove-function.js rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-text-valid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-text-valid.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-type-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/node-type-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/parent-kind-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/parent-kind-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/parent-kind-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/parent-type-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/parent-type-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/parent-type-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/previous-kind-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/previous-kind-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/previous-kind-invalid-function.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/previous-type-invalid-custom.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/previous-type-invalid-default.js (100%) rename packages/{slate/test/schema/custom => slate-schema/test/errors}/previous-type-invalid-function.js (100%) create mode 100644 packages/slate-schema/test/helpers/index.js create mode 100644 packages/slate-schema/test/index.js create mode 100644 packages/slate-schema/tsconfig.json delete mode 100644 packages/slate/test/history/undo/add-mark-across-blocks.js delete mode 100644 packages/slate/test/history/undo/add-mark-across-marks.js delete mode 100644 packages/slate/test/history/undo/add-mark-across-same-mark.js delete mode 100644 packages/slate/test/history/undo/add-mark.js delete mode 100644 packages/slate/test/history/undo/delete-across-blocks.js delete mode 100644 packages/slate/test/history/undo/delete-across-inlines.js delete mode 100644 packages/slate/test/history/undo/delete-across-marks.js delete mode 100644 packages/slate/test/history/undo/delete-backward-nested-blocks.js delete mode 100644 packages/slate/test/history/undo/delete-backward.js delete mode 100644 packages/slate/test/history/undo/delete.js delete mode 100644 packages/slate/test/history/undo/insert-block.js delete mode 100644 packages/slate/test/history/undo/insert-fragment.js delete mode 100644 packages/slate/test/history/undo/insert-text-contiguous.js delete mode 100644 packages/slate/test/history/undo/insert-text-not-contiguous.js delete mode 100644 packages/slate/test/history/undo/insert-text.js delete mode 100644 packages/slate/test/history/undo/move-node-affecting-path.js delete mode 100644 packages/slate/test/history/undo/move-node-before-itself.js delete mode 100644 packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js delete mode 100644 packages/slate/test/history/undo/move-node-by-path.js delete mode 100644 packages/slate/test/history/undo/remove-mark.js delete mode 100644 packages/slate/test/history/undo/remove-node-by-path.js delete mode 100644 packages/slate/test/history/undo/remove-text.js delete mode 100644 packages/slate/test/history/undo/set-node-by-path-with-data.js delete mode 100644 packages/slate/test/history/undo/split-node-by-path-block.js delete mode 100644 packages/slate/test/history/undo/toggle-mark.js delete mode 100644 packages/slate/test/history/undo/unwrap-node-by-path.js delete mode 100644 packages/slate/test/history/undo/wrap-inline-across-blocks.js delete mode 100644 packages/slate/test/schema/custom/child-max-invalid-at-end-default.js delete mode 100644 packages/slate/test/schema/custom/child-max-invalid-custom.js delete mode 100644 packages/slate/test/schema/custom/child-max-invalid-default.js delete mode 100644 packages/slate/test/schema/custom/node-object-invalid-default.js delete mode 100644 packages/slate/test/schema/custom/node-object-invalid-function.js diff --git a/config/rollup/rollup.config.js b/config/rollup/rollup.config.js index 0c56b7b2b9..3e91b43a0b 100644 --- a/config/rollup/rollup.config.js +++ b/config/rollup/rollup.config.js @@ -9,19 +9,20 @@ import typescript from 'rollup-plugin-typescript2' import uglify from 'rollup-plugin-uglify' import { startCase } from 'lodash' -import core from '../../packages/slate/package.json' -import base64Serializer from '../../packages/slate-base64-serializer/package.json' -import devEnvironment from '../../packages/slate-dev-environment/package.json' -import history from '../../packages/slate-history/package.json' -import hotkeys from '../../packages/slate-hotkeys/package.json' -import htmlSerializer from '../../packages/slate-html-serializer/package.json' -import hyperscript from '../../packages/slate-hyperscript/package.json' -import parsePlaintext from '../../packages/slate-parse-plaintext/package.json' -import plainSerializer from '../../packages/slate-plain-serializer/package.json' -import propTypes from '../../packages/slate-prop-types/package.json' -import react from '../../packages/slate-react/package.json' -import reactPlaceholder from '../../packages/slate-react-placeholder/package.json' -import renderPlaintext from '../../packages/slate-render-plaintext/package.json' +import Core from '../../packages/slate/package.json' +import Base64Serializer from '../../packages/slate-base64-serializer/package.json' +import DevEnvironment from '../../packages/slate-dev-environment/package.json' +import History from '../../packages/slate-history/package.json' +import Hotkeys from '../../packages/slate-hotkeys/package.json' +import HtmlSerializer from '../../packages/slate-html-serializer/package.json' +import Hyperscript from '../../packages/slate-hyperscript/package.json' +import ParsePlaintext from '../../packages/slate-parse-plaintext/package.json' +import PlainSerializer from '../../packages/slate-plain-serializer/package.json' +import PropTypes from '../../packages/slate-prop-types/package.json' +import React from '../../packages/slate-react/package.json' +import ReactPlaceholder from '../../packages/slate-react-placeholder/package.json' +import RenderPlaintext from '../../packages/slate-render-plaintext/package.json' +import Schema from '../../packages/slate-schema/package.json' /** * Return a Rollup configuration for a `pkg` with `env` and `target`. @@ -176,17 +177,18 @@ function factory(pkg, options = {}) { */ export default [ - ...factory(core, { ts: true }), - ...factory(base64Serializer), - ...factory(devEnvironment), - ...factory(history, { ts: true }), - ...factory(hotkeys), - ...factory(htmlSerializer), - ...factory(hyperscript, { ts: true }), - ...factory(plainSerializer), - ...factory(parsePlaintext, { ts: true }), - ...factory(propTypes), - ...factory(react), - ...factory(reactPlaceholder), - ...factory(renderPlaintext, { ts: true }), + ...factory(Core, { ts: true }), + ...factory(Base64Serializer), + ...factory(DevEnvironment), + ...factory(History, { ts: true }), + ...factory(Hotkeys), + ...factory(HtmlSerializer), + ...factory(Hyperscript, { ts: true }), + ...factory(PlainSerializer), + ...factory(ParsePlaintext, { ts: true }), + ...factory(PropTypes), + ...factory(React), + ...factory(ReactPlaceholder), + ...factory(RenderPlaintext, { ts: true }), + ...factory(Schema, { ts: true }), ] diff --git a/packages/slate-schema/Changelog.md b/packages/slate-schema/Changelog.md new file mode 100644 index 0000000000..b79fccc567 --- /dev/null +++ b/packages/slate-schema/Changelog.md @@ -0,0 +1,5 @@ +# Changelog + +A list of changes to the `slate-history` package with each new version. Until `1.0.0` is released, breaking changes will be added as minor version bumps, and smaller changes won't be accounted for since the library is moving quickly. + +--- diff --git a/packages/slate-schema/Readme.md b/packages/slate-schema/Readme.md new file mode 100644 index 0000000000..47ac3a1b6d --- /dev/null +++ b/packages/slate-schema/Readme.md @@ -0,0 +1 @@ +This package contains the core logic of Slate. Feel free to poke around to learn more! diff --git a/packages/slate-schema/package.json b/packages/slate-schema/package.json new file mode 100644 index 0000000000..3cf77b2a57 --- /dev/null +++ b/packages/slate-schema/package.json @@ -0,0 +1,33 @@ +{ + "name": "slate-schema", + "description": "A plugin that ensures your Slate editors obey the rules of your schema.", + "version": "0.47.8", + "license": "MIT", + "repository": "git://github.com/ianstormtaylor/slate.git", + "main": "lib/index.js", + "module": "lib/index.es.js", + "types": "lib/index.d.ts", + "umd": "dist/slate-schema.js", + "umdMin": "dist/slate-schema.min.js", + "files": [ + "dist/", + "lib/" + ], + "dependencies": {}, + "peerDependencies": { + "slate": ">=0.47.0" + }, + "devDependencies": { + "slate": "^0.47.8", + "slate-hyperscript": "^0.13.8" + }, + "keywords": [ + "customize", + "editor", + "normalization", + "rules", + "schema", + "slate", + "validation" + ] +} diff --git a/packages/slate/src/plugins/schema/checkers.ts b/packages/slate-schema/src/checkers.ts similarity index 72% rename from packages/slate/src/plugins/schema/checkers.ts rename to packages/slate-schema/src/checkers.ts index 02da002cb6..cf3f0456e0 100644 --- a/packages/slate/src/plugins/schema/checkers.ts +++ b/packages/slate-schema/src/checkers.ts @@ -1,6 +1,10 @@ -import { Ancestor, Range, Element, Mark, Node, Path, Text, Value } from '../..' -import { SchemaError } from './error' +import { Ancestor, Range, Element, Mark, Node, Path, Text, Value } from 'slate' import { SchemaRule, SchemaCheck } from './rule' +import { + AnnotationSchemaError, + MarkSchemaError, + NodeSchemaError, +} from './error' /** * Check an annotation object. @@ -10,12 +14,16 @@ export const checkAnnotation = ( annotation: Range, key: string, check: SchemaCheck -): SchemaError | undefined => { +): AnnotationSchemaError | undefined => { if (typeof check === 'function') { if (check(annotation)) { return } else { - return { code: 'annotation_invalid', annotation, key } + return { + code: 'annotation_invalid', + annotation, + key, + } } } @@ -24,7 +32,11 @@ export const checkAnnotation = ( check.object === 'annotation' && !Range.isRange(annotation) ) { - return { code: 'annotation_object_invalid', annotation, key } + return { + code: 'annotation_object_invalid', + annotation, + key, + } } if ('properties' in check) { @@ -54,7 +66,7 @@ export const checkMark = ( node: Text, path: Path, check: SchemaCheck -): SchemaError | undefined => { +): MarkSchemaError | undefined => { if (typeof check === 'function') { if (check(mark)) { return @@ -95,7 +107,7 @@ export const checkNode = ( path: Path, check: SchemaCheck, rules: SchemaRule[] -): SchemaError | undefined => { +): NodeSchemaError | MarkSchemaError | undefined => { if (typeof check === 'function') { if (check(node)) { return @@ -117,8 +129,9 @@ export const checkNode = ( for (const k in check.properties) { const p = check.properties[k] const value = node[k] + const isInvalid = typeof p === 'function' ? !p(value) : p !== value - if ((typeof p === 'function' && !p(value)) || p !== value) { + if (isInvalid) { return { code: 'node_property_invalid', node, path, property: k } } } @@ -166,11 +179,12 @@ export const checkAncestor = ( path: Path, check: SchemaCheck, rules: SchemaRule[] -): SchemaError | undefined => { +): NodeSchemaError | undefined => { if ('first' in check && check.first != null && node.nodes.length !== 0) { const n = Node.child(node, 0) const p = path.concat(0) const e = checkNode(n, p, check.first, rules) + debugger if (e) { if (e.code === 'node_invalid') { @@ -202,7 +216,7 @@ export const checkAncestor = ( const processed = new Set() let d = 0 - let m = 0 + let m = 1 let i = 0 while (i < node.nodes.length) { @@ -272,93 +286,93 @@ export const checkAncestor = ( const child = check.children[d] const max = child.max != null ? child.max : Infinity const min = child.min != null ? child.min : 0 + debugger // If the children assertion was defined, but we don't current have a // definition, we've reached the end so any other children are overflows. if (!child) { - return { code: 'child_overflow', node: n, path: p, index: i } + return { code: 'child_unexpected', node: n, path: p, index: i } } - if (child.match != null) { - const e = checkNode(n, p, child.match, rules) - - if (e) { - // Since we want to report overflow on last matching child we don't - // immediately check for count > max, but instead do so once we find - // a child that doesn't match. - if (m - 1 > max) { - return { - code: 'child_max_invalid', - node: n, - path: p, - index: i, - count: m, - max, - } - } + // Since we want to report overflow on last matching child we don't + // immediately check for count > max, but instead do so once we find + // a child that doesn't match. + if (m - 1 > max) { + return { + code: 'child_max_invalid', + node: n, + path: p, + index: i, + count: m, + max, + } + } - // If there are more children definitions after this one, then this - // child might actually be valid for a future one. - if (check.children.length > d + 1) { - // If we've already satisfied the current child definition's minimum - // then we can proceed to the next definition. - if (m >= min) { - d++ - continue - } + // Otherwise either we exhausted the last group, in which case it's + // an unexpected child that has overflowed. + if (m > max) { + return { code: 'child_unexpected', node: n, path: p, index: i } + } - // There might just not be enough elements for current group, and - // current child is in fact the first of the next group. If so, the - // next def will not report errors, in which case we can rewind and - // report an minimum error. - const nextChild = check.children[d + 1] - - if ( - nextChild && - nextChild.match != null && - checkNode(n, p, nextChild.match, rules) === undefined - ) { - return { - code: 'child_min_invalid', - node: n, - path: p, - index: i, - count: m, - min, - } - } + const e = checkNode(n, p, child.match || {}, rules) + + if (e) { + // If there are more children definitions after this one, then this + // child might actually be valid for a future one. + if (check.children.length > d + 1) { + // If we've already satisfied the current child definition's minimum + // then we can proceed to the next definition. + if (m >= min) { + d++ + m = 1 + continue } - // Otherwise either we exhausted the last group, in which case it's - // an unknown child, ... - if (m > max) { - return { code: 'child_overflow', node: n, path: p, index: i } - } + // There might just not be enough elements for current group, and + // current child is in fact the first of the next group. If so, the + // next def will not report errors, in which case we can rewind and + // report an minimum error. + const nextChild = check.children[d + 1] - // ... or it's an invalid child. - if (e.code === 'node_invalid') { - return { ...e, node: n, path: p, index: i, code: 'child_invalid' } - } else if (e.code === 'node_object_invalid') { + if ( + nextChild && + checkNode(n, p, nextChild.match || {}, rules) === undefined + ) { return { - ...e, - code: 'child_object_invalid', - node: n, - path: p, - index: i, - } - } else if (e.code === 'node_property_invalid') { - return { - ...e, - code: 'child_property_invalid', + code: 'child_min_invalid', node: n, path: p, index: i, + count: m, + min, } } } + + // Or the child is invalid against the definition. + if (e.code === 'node_invalid') { + return { ...e, node: n, path: p, index: i, code: 'child_invalid' } + } else if (e.code === 'node_object_invalid') { + return { + ...e, + code: 'child_object_invalid', + node: n, + path: p, + index: i, + } + } else if (e.code === 'node_property_invalid') { + return { + ...e, + code: 'child_property_invalid', + node: n, + path: p, + index: i, + } + } } } i++ + m++ } } diff --git a/packages/slate/src/plugins/schema/error.ts b/packages/slate-schema/src/error.ts similarity index 68% rename from packages/slate/src/plugins/schema/error.ts rename to packages/slate-schema/src/error.ts index da6b943f40..88fff5f3c1 100644 --- a/packages/slate/src/plugins/schema/error.ts +++ b/packages/slate-schema/src/error.ts @@ -1,32 +1,32 @@ -import { Ancestor, Descendant, Range, Mark, Node, Path, Text } from '../..' +import { Ancestor, Descendant, Range, Mark, Node, Path, Text } from 'slate' -interface AnnotationInvalidError { +export interface AnnotationInvalidError { code: 'annotation_invalid' annotation: Range key: string } -interface AnnotationObjectInvalidError { +export interface AnnotationObjectInvalidError { code: 'annotation_object_invalid' annotation: Range key: string } -interface AnnotationPropertyInvalidError { +export interface AnnotationPropertyInvalidError { code: 'annotation_property_invalid' annotation: Range key: string property: string } -interface ChildInvalidError { +export interface ChildInvalidError { code: 'child_invalid' node: Descendant path: Path index: number } -interface ChildMaxInvalidError { +export interface ChildMaxInvalidError { code: 'child_max_invalid' node: Descendant path: Path @@ -35,7 +35,7 @@ interface ChildMaxInvalidError { max: number } -interface ChildMinInvalidError { +export interface ChildMinInvalidError { code: 'child_min_invalid' node: Descendant path: Path @@ -44,21 +44,21 @@ interface ChildMinInvalidError { min: number } -interface ChildObjectInvalidError { +export interface ChildObjectInvalidError { code: 'child_object_invalid' node: Descendant path: Path index: number } -interface ChildOverflowError { - code: 'child_overflow' +export interface ChildUnexpectedError { + code: 'child_unexpected' node: Descendant path: Path index: number } -interface ChildPropertyInvalidError { +export interface ChildPropertyInvalidError { code: 'child_property_invalid' node: Descendant path: Path @@ -66,21 +66,21 @@ interface ChildPropertyInvalidError { property: string } -interface FirstChildInvalidError { +export interface FirstChildInvalidError { code: 'first_child_invalid' node: Descendant path: Path index: number } -interface FirstChildObjectInvalidError { +export interface FirstChildObjectInvalidError { code: 'first_child_object_invalid' node: Descendant path: Path index: number } -interface FirstChildPropertyInvalidError { +export interface FirstChildPropertyInvalidError { code: 'first_child_property_invalid' node: Descendant path: Path @@ -88,21 +88,21 @@ interface FirstChildPropertyInvalidError { property: string } -interface LastChildInvalidError { +export interface LastChildInvalidError { code: 'last_child_invalid' node: Descendant path: Path index: number } -interface LastChildObjectInvalidError { +export interface LastChildObjectInvalidError { code: 'last_child_object_invalid' node: Descendant path: Path index: number } -interface LastChildPropertyInvalidError { +export interface LastChildPropertyInvalidError { code: 'last_child_property_invalid' node: Descendant path: Path @@ -110,52 +110,52 @@ interface LastChildPropertyInvalidError { property: string } -interface NextSiblingInvalidError { +export interface NextSiblingInvalidError { code: 'next_sibling_invalid' node: Node path: Path } -interface NextSiblingObjectInvalidError { +export interface NextSiblingObjectInvalidError { code: 'next_sibling_object_invalid' node: Node path: Path } -interface NextSiblingPropertyInvalidError { +export interface NextSiblingPropertyInvalidError { code: 'next_sibling_property_invalid' node: Node path: Path property: string } -interface NodeTextInvalidError { +export interface NodeTextInvalidError { code: 'node_text_invalid' node: Node path: Path text: string } -interface NodeInvalidError { +export interface NodeInvalidError { code: 'node_invalid' node: Node path: Path } -interface NodePropertyInvalidError { +export interface NodePropertyInvalidError { code: 'node_property_invalid' node: Node path: Path property: string } -interface NodeObjectInvalidError { +export interface NodeObjectInvalidError { code: 'node_object_invalid' node: Node path: Path } -interface MarkInvalidError { +export interface MarkInvalidError { code: 'mark_invalid' mark: Mark index: number @@ -163,7 +163,7 @@ interface MarkInvalidError { path: Path } -interface MarkObjectInvalidError { +export interface MarkObjectInvalidError { code: 'mark_object_invalid' mark: Mark index: number @@ -171,7 +171,7 @@ interface MarkObjectInvalidError { path: Path } -interface MarkPropertyInvalidError { +export interface MarkPropertyInvalidError { code: 'mark_property_invalid' mark: Mark index: number @@ -180,21 +180,21 @@ interface MarkPropertyInvalidError { property: string } -interface ParentInvalidError { +export interface ParentInvalidError { code: 'parent_invalid' node: Ancestor path: Path index: number } -interface ParentObjectInvalidError { +export interface ParentObjectInvalidError { code: 'parent_object_invalid' node: Ancestor path: Path index: number } -interface ParentPropertyInvalidError { +export interface ParentPropertyInvalidError { code: 'parent_property_invalid' node: Ancestor path: Path @@ -202,34 +202,41 @@ interface ParentPropertyInvalidError { property: string } -interface PreviousSiblingInvalidError { +export interface PreviousSiblingInvalidError { code: 'previous_sibling_invalid' node: Node path: Path } -interface PreviousSiblingObjectInvalidError { +export interface PreviousSiblingObjectInvalidError { code: 'previous_sibling_object_invalid' node: Node path: Path } -interface PreviousSiblingPropertyInvalidError { +export interface PreviousSiblingPropertyInvalidError { code: 'previous_sibling_property_invalid' node: Node path: Path property: string } -type SchemaError = +export type AnnotationSchemaError = | AnnotationInvalidError | AnnotationObjectInvalidError | AnnotationPropertyInvalidError + +export type MarkSchemaError = + | MarkInvalidError + | MarkObjectInvalidError + | MarkPropertyInvalidError + +export type NodeSchemaError = | ChildInvalidError | ChildMaxInvalidError | ChildMinInvalidError | ChildObjectInvalidError - | ChildOverflowError + | ChildUnexpectedError | ChildPropertyInvalidError | FirstChildInvalidError | FirstChildObjectInvalidError @@ -237,9 +244,6 @@ type SchemaError = | LastChildInvalidError | LastChildObjectInvalidError | LastChildPropertyInvalidError - | MarkInvalidError - | MarkObjectInvalidError - | MarkPropertyInvalidError | NextSiblingInvalidError | NextSiblingObjectInvalidError | NextSiblingPropertyInvalidError @@ -254,4 +258,7 @@ type SchemaError = | PreviousSiblingObjectInvalidError | PreviousSiblingPropertyInvalidError -export { SchemaError } +export type SchemaError = + | AnnotationSchemaError + | MarkSchemaError + | NodeSchemaError diff --git a/packages/slate/src/plugins/schema/index.ts b/packages/slate-schema/src/index.ts similarity index 100% rename from packages/slate/src/plugins/schema/index.ts rename to packages/slate-schema/src/index.ts diff --git a/packages/slate/src/plugins/schema/plugin.ts b/packages/slate-schema/src/plugin.ts similarity index 59% rename from packages/slate/src/plugins/schema/plugin.ts rename to packages/slate-schema/src/plugin.ts index 6975b09e7f..714ce20a01 100644 --- a/packages/slate/src/plugins/schema/plugin.ts +++ b/packages/slate-schema/src/plugin.ts @@ -1,24 +1,19 @@ -import { - Editor, - Mark, - Range, - EditorConstructor, - Element, - Node, - Path, -} from '../..' +import { EditorPlugin, EditorConstructor, Element, Node, Path } from 'slate' import { SchemaError } from './error' import { SchemaRule } from './rule' -import { checkNode, checkMark, checkAnnotation } from './checkers' +import { checkNode } from './checkers' -const SchemaPlugin = ( +const SchemaPlugin: EditorPlugin = ( options: { rules?: SchemaRule[] value?: Omit annotations?: { [type: string]: Omit } - elements?: { + blocks?: { + [type: string]: Omit + } + inlines?: { [type: string]: Omit } marks?: { @@ -26,17 +21,40 @@ const SchemaPlugin = ( } } = {} ) => { - const { value, elements = {}, marks = {}, annotations = {} } = options const rules = options.rules ? [...options.rules] : [] + const { + value, + blocks = {}, + inlines = {}, + marks = {}, + annotations = {}, + } = options if (value) { rules.push({ match: { object: 'value' }, ...value }) } - for (const type in elements) { + for (const type in blocks) { + const rule = blocks[type] + rules.push({ + match: { object: 'element', properties: { type } }, + ...rule, + define: { + ...rule.define, + isInline: false, + }, + }) + } + + for (const type in inlines) { + const rule = inlines[type] rules.push({ match: { object: 'element', properties: { type } }, - ...elements[type], + ...rule, + define: { + ...rule.define, + isInline: true, + }, }) } @@ -54,13 +72,13 @@ const SchemaPlugin = ( }) } - return (Base: EditorConstructor) => { - return class extends Base { + return (Editor: EditorConstructor) => { + return class extends Editor { /** * Check if a node is inline based on the schema rules. */ - isInline(this: Editor, element: Element): boolean { + isInline(element: Element): boolean { // HACK: The node-checking logic needs a path for creating an error with // details. But we don't care about the error, so we use a fake path. const path: Path = [] @@ -82,7 +100,7 @@ const SchemaPlugin = ( * Check if a node is void based on the schema rules. */ - isVoid(this: Editor, element: Element): boolean { + isVoid(element: Element): boolean { // HACK: The node-checking logic needs a path for creating an error with // details. But we don't care about the error, so we use a fake path. const path: Path = [] @@ -105,26 +123,29 @@ const SchemaPlugin = ( * valid state if it is currently invalid. */ - normalizeNodeAtPath(this: Editor, options: { at?: Path } = {}): void { + normalizeNodes(options: { at: Path }): void { const { at } = options - - if (!Path.isPath(at)) { - return super.normalizeNodes(options) - } - - const node = this.getNode(at) + const [node] = this.getNode(at) let error: SchemaError | undefined let rule: SchemaRule | undefined for (const r of rules) { - if ('validate' in r) { - const e = checkNode(node, at, r.match, rules) + if (r.match == null || r.validate == null) { + continue + } - if (e) { - error = e - rule = r - break - } + const isMatch = !checkNode(node, at, r.match, rules) + + if (!isMatch) { + continue + } + + const e = checkNode(node, at, r.validate, rules) + + if (e) { + error = e + rule = r + break } } @@ -136,7 +157,7 @@ const SchemaPlugin = ( // First run the user-provided `normalize` function if one exists... if (rule != null && rule.normalize) { - rule.normalize.call(this, error) + rule.normalize(this, error) } // If the `normalize` function did add any operations to the editor, @@ -154,63 +175,66 @@ const SchemaPlugin = ( break } - case 'child_invalid': case 'child_max_invalid': - case 'child_object_invalid': - case 'child_overflow': + case 'child_min_invalid': case 'first_child_invalid': case 'first_child_object_invalid': + case 'first_child_property_invalid': case 'last_child_invalid': case 'last_child_object_invalid': - case 'next_sibling_invalid': - case 'next_sibling_object_invalid': - case 'node_invalid': - case 'node_object_invalid': - case 'node_text_invalid': - case 'parent_invalid': - case 'parent_object_invalid': - case 'previous_sibling_invalid': - case 'previous_sibling_object_invalid': { - const { path } = error - - if (path.length === 0) { - this.removeChildrenAtPath(path) + case 'last_child_property_invalid': { + const { code, path } = error + const [parent, parentPath] = this.getParent(path) + + if (parent.nodes.length > 1 || code === 'child_min_invalid') { + this.removeNodes({ at: path }) + } else if (parentPath.length === 0) { + const range = this.getRange(parentPath) + this.removeNodes({ at: range, match: 1 }) } else { - this.removeNodeAtPath(path) + this.removeNodes({ at: parentPath }) } break } - case 'child_min_invalid': { + case 'child_invalid': + case 'child_object_invalid': + case 'child_property_invalid': + case 'child_unexpected': + case 'node_invalid': + case 'node_object_invalid': + case 'node_property_invalid': + case 'node_text_invalid': { const { path } = error + this.removeNodes({ at: path }) + break + } - if (path.length === 1) { - this.removeChildrenAtPath([]) - } else { - this.removeParentAtPath(path) - } + case 'next_sibling_invalid': + case 'next_sibling_object_invalid': + case 'next_sibling_property_invalid': { + const { path } = error + const prevPath = Path.previous(path) + this.removeNodes({ at: prevPath }) + break + } + case 'parent_invalid': + case 'parent_object_invalid': + case 'parent_property_invalid': { + const { path, index } = error + const childPath = path.concat(index) + this.removeNodes({ at: childPath }) break } - case 'child_property_invalid': - case 'first_child_property_invalid': - case 'last_child_property_invalid': - case 'next_sibling_property_invalid': - case 'node_property_invalid': - case 'parent_property_invalid': + case 'previous_sibling_invalid': + case 'previous_sibling_object_invalid': case 'previous_sibling_property_invalid': { - const { value } = this - const { path, property } = error - const node = Node.get(value, path) - - if (node[property] == null) { - this.removeNodeAtPath(path) - } else { - this.setNodeAtPath(path, { [property]: null }) - } - + const { path } = error + const nextPath = Path.next(path) + this.removeNodes({ at: nextPath }) break } @@ -218,13 +242,22 @@ const SchemaPlugin = ( case 'mark_object_invalid': case 'mark_property_invalid': { const { path, mark } = error - this.removeMarkAtPath(path, mark) + this.removeMarks([mark], { at: path }) break } + + default: { + const _: never = error + throw new Error( + `Cannot normalize unknown validation error: "${JSON.stringify( + error + )}"` + ) + } } } } } } -export default SchemaPlugin +export { SchemaPlugin } diff --git a/packages/slate/src/plugins/schema/rule.ts b/packages/slate-schema/src/rule.ts similarity index 93% rename from packages/slate/src/plugins/schema/rule.ts rename to packages/slate-schema/src/rule.ts index 822f1f9c03..d6092e9161 100644 --- a/packages/slate/src/plugins/schema/rule.ts +++ b/packages/slate-schema/src/rule.ts @@ -1,12 +1,6 @@ -import { Editor } from '../..' +import { Editor } from 'slate' import { SchemaError } from './error' -type SchemaCheck = - | SchemaNodeCheck - | SchemaAnnotationCheck - | SchemaMarkCheck - | SchemaFunctionCheck - interface SchemaValueCheck { object?: 'value' children?: SchemaChildCheck[] @@ -26,7 +20,7 @@ interface SchemaElementCheck { last?: SchemaDescendantCheck parent?: SchemaAncestorCheck marks?: SchemaMarkCheck[] - text?: RegExp | ((text: string) => boolean) + text?: (text: string) => boolean properties?: {} } @@ -64,13 +58,19 @@ interface SchemaFunctionCheck { (object: any): boolean } +type SchemaCheck = + | SchemaNodeCheck + | SchemaAnnotationCheck + | SchemaMarkCheck + | SchemaFunctionCheck + interface SchemaDefine { isInline?: boolean isVoid?: boolean } interface SchemaNormalize { - (this: Editor, error: SchemaError): void + (editor: Editor, error: SchemaError): void } interface SchemaRule { diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js b/packages/slate-schema/test/errors/child-kind-invalid-custom-optional-first.js similarity index 100% rename from packages/slate/test/schema/custom/child-kind-invalid-custom-optional-first.js rename to packages/slate-schema/test/errors/child-kind-invalid-custom-optional-first.js diff --git a/packages/slate/test/schema/custom/child-kind-invalid-custom.js b/packages/slate-schema/test/errors/child-kind-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/child-kind-invalid-custom.js rename to packages/slate-schema/test/errors/child-kind-invalid-custom.js diff --git a/packages/slate/test/schema/custom/child-kind-invalid-default.js b/packages/slate-schema/test/errors/child-kind-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/child-kind-invalid-default.js rename to packages/slate-schema/test/errors/child-kind-invalid-default.js diff --git a/packages/slate/test/schema/custom/child-kind-invalid-function.js b/packages/slate-schema/test/errors/child-kind-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/child-kind-invalid-function.js rename to packages/slate-schema/test/errors/child-kind-invalid-function.js diff --git a/packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js b/packages/slate-schema/test/errors/child-min-invalid-at-end-custom.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-invalid-at-end-custom.js rename to packages/slate-schema/test/errors/child-min-invalid-at-end-custom.js diff --git a/packages/slate/test/schema/custom/child-min-invalid-at-end-default.js b/packages/slate-schema/test/errors/child-min-invalid-at-end-default.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-invalid-at-end-default.js rename to packages/slate-schema/test/errors/child-min-invalid-at-end-default.js diff --git a/packages/slate/test/schema/custom/child-min-invalid-custom.js b/packages/slate-schema/test/errors/child-min-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-invalid-custom.js rename to packages/slate-schema/test/errors/child-min-invalid-custom.js diff --git a/packages/slate/test/schema/custom/child-min-invalid-default.js b/packages/slate-schema/test/errors/child-min-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-invalid-default.js rename to packages/slate-schema/test/errors/child-min-invalid-default.js diff --git a/packages/slate/test/schema/custom/child-min-invalid-with-invalid-default.js b/packages/slate-schema/test/errors/child-min-invalid-with-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-invalid-with-invalid-default.js rename to packages/slate-schema/test/errors/child-min-invalid-with-invalid-default.js diff --git a/packages/slate-schema/test/errors/child-min-invalid/remove.js b/packages/slate-schema/test/errors/child-min-invalid/remove.js new file mode 100644 index 0000000000..819df70aed --- /dev/null +++ b/packages/slate-schema/test/errors/child-min-invalid/remove.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + children: [{ min: 2 }], + }, + }, + }, +} + +export const input = ( + + + one + + +) + +export const output = diff --git a/packages/slate-schema/test/errors/child-min-invalid/second-group.js b/packages/slate-schema/test/errors/child-min-invalid/second-group.js new file mode 100644 index 0000000000..372e50f6aa --- /dev/null +++ b/packages/slate-schema/test/errors/child-min-invalid/second-group.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + children: [{ max: 1 }, { min: 1 }], + }, + }, + }, +} + +export const input = ( + + + one + + +) + +export const output = diff --git a/packages/slate/test/schema/custom/child-min-max-invalid-default.js b/packages/slate-schema/test/errors/child-min-max-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-max-invalid-default.js rename to packages/slate-schema/test/errors/child-min-max-invalid-default.js diff --git a/packages/slate/test/schema/custom/child-min-max-invalid-similar-valid.js b/packages/slate-schema/test/errors/child-min-max-invalid-similar-valid.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-max-invalid-similar-valid.js rename to packages/slate-schema/test/errors/child-min-max-invalid-similar-valid.js diff --git a/packages/slate/test/schema/custom/child-min-max-invalid-valid.js b/packages/slate-schema/test/errors/child-min-max-invalid-valid.js similarity index 100% rename from packages/slate/test/schema/custom/child-min-max-invalid-valid.js rename to packages/slate-schema/test/errors/child-min-max-invalid-valid.js diff --git a/packages/slate-schema/test/errors/child-object-invalid/remove.js b/packages/slate-schema/test/errors/child-object-invalid/remove.js new file mode 100644 index 0000000000..cabbb3c28f --- /dev/null +++ b/packages/slate-schema/test/errors/child-object-invalid/remove.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + children: [{ match: { object: 'text' } }], + }, + }, + }, +} + +export const input = ( + + + word + + +) + +export const output = ( + + + + + +) diff --git a/packages/slate-schema/test/errors/child-property-invalid/unset-function.js b/packages/slate-schema/test/errors/child-property-invalid/unset-function.js new file mode 100644 index 0000000000..97a56b2386 --- /dev/null +++ b/packages/slate-schema/test/errors/child-property-invalid/unset-function.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + children: [ + { + match: { + properties: { + key: v => v == null, + }, + }, + }, + ], + }, + }, + }, +} + +export const input = ( + + + word + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate-schema/test/errors/child-property-invalid/unset-value.js b/packages/slate-schema/test/errors/child-property-invalid/unset-value.js new file mode 100644 index 0000000000..23f5569246 --- /dev/null +++ b/packages/slate-schema/test/errors/child-property-invalid/unset-value.js @@ -0,0 +1,37 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + children: [ + { + match: { + properties: { + key: null, + }, + }, + }, + ], + }, + }, + }, +} + +export const input = ( + + + word + + +) + +export const output = ( + + + word + + +) diff --git a/packages/slate/test/schema/custom/child-type-invalid-custom.js b/packages/slate-schema/test/errors/child-type-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/child-type-invalid-custom.js rename to packages/slate-schema/test/errors/child-type-invalid-custom.js diff --git a/packages/slate/test/schema/custom/child-type-invalid-default.js b/packages/slate-schema/test/errors/child-type-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/child-type-invalid-default.js rename to packages/slate-schema/test/errors/child-type-invalid-default.js diff --git a/packages/slate/test/schema/custom/child-type-invalid-function.js b/packages/slate-schema/test/errors/child-type-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/child-type-invalid-function.js rename to packages/slate-schema/test/errors/child-type-invalid-function.js diff --git a/packages/slate-schema/test/errors/child-unexpected/remove.js b/packages/slate-schema/test/errors/child-unexpected/remove.js new file mode 100644 index 0000000000..61e2ad4196 --- /dev/null +++ b/packages/slate-schema/test/errors/child-unexpected/remove.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + children: [{ match: {}, max: 1 }], + }, + }, + }, +} + +export const input = ( + + + one + two + + +) + +export const output = ( + + + one + + +) diff --git a/packages/slate-schema/test/errors/child-unexpected/second-group.js b/packages/slate-schema/test/errors/child-unexpected/second-group.js new file mode 100644 index 0000000000..8af23ce0c6 --- /dev/null +++ b/packages/slate-schema/test/errors/child-unexpected/second-group.js @@ -0,0 +1,32 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + children: [{ max: 1 }, { max: 1 }], + }, + }, + }, +} + +export const input = ( + + + one + two + three + + +) + +export const output = ( + + + one + two + + +) diff --git a/packages/slate/test/schema/custom/child-unknown-custom.js b/packages/slate-schema/test/errors/child-unknown-custom.js similarity index 100% rename from packages/slate/test/schema/custom/child-unknown-custom.js rename to packages/slate-schema/test/errors/child-unknown-custom.js diff --git a/packages/slate/test/schema/custom/child-unknown-default.js b/packages/slate-schema/test/errors/child-unknown-default.js similarity index 100% rename from packages/slate/test/schema/custom/child-unknown-default.js rename to packages/slate-schema/test/errors/child-unknown-default.js diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-custom.js b/packages/slate-schema/test/errors/first-child-kind-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/first-child-kind-invalid-custom.js rename to packages/slate-schema/test/errors/first-child-kind-invalid-custom.js diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-default.js b/packages/slate-schema/test/errors/first-child-kind-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/first-child-kind-invalid-default.js rename to packages/slate-schema/test/errors/first-child-kind-invalid-default.js diff --git a/packages/slate/test/schema/custom/first-child-kind-invalid-function.js b/packages/slate-schema/test/errors/first-child-kind-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/first-child-kind-invalid-function.js rename to packages/slate-schema/test/errors/first-child-kind-invalid-function.js diff --git a/packages/slate-schema/test/errors/first-child-object-invalid/remove.js b/packages/slate-schema/test/errors/first-child-object-invalid/remove.js new file mode 100644 index 0000000000..0ae54d1014 --- /dev/null +++ b/packages/slate-schema/test/errors/first-child-object-invalid/remove.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + first: { properties: { type: 'a' } }, + }, + }, + }, +} + +export const input = ( + + + word + + +) + +export const output = diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-custom.js b/packages/slate-schema/test/errors/first-child-type-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/first-child-type-invalid-custom.js rename to packages/slate-schema/test/errors/first-child-type-invalid-custom.js diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-default.js b/packages/slate-schema/test/errors/first-child-type-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/first-child-type-invalid-default.js rename to packages/slate-schema/test/errors/first-child-type-invalid-default.js diff --git a/packages/slate/test/schema/custom/first-child-type-invalid-function.js b/packages/slate-schema/test/errors/first-child-type-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/first-child-type-invalid-function.js rename to packages/slate-schema/test/errors/first-child-type-invalid-function.js diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-custom.js b/packages/slate-schema/test/errors/last-child-kind-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/last-child-kind-invalid-custom.js rename to packages/slate-schema/test/errors/last-child-kind-invalid-custom.js diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-default.js b/packages/slate-schema/test/errors/last-child-kind-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/last-child-kind-invalid-default.js rename to packages/slate-schema/test/errors/last-child-kind-invalid-default.js diff --git a/packages/slate/test/schema/custom/last-child-kind-invalid-function.js b/packages/slate-schema/test/errors/last-child-kind-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/last-child-kind-invalid-function.js rename to packages/slate-schema/test/errors/last-child-kind-invalid-function.js diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-custom.js b/packages/slate-schema/test/errors/last-child-type-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/last-child-type-invalid-custom.js rename to packages/slate-schema/test/errors/last-child-type-invalid-custom.js diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-default.js b/packages/slate-schema/test/errors/last-child-type-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/last-child-type-invalid-default.js rename to packages/slate-schema/test/errors/last-child-type-invalid-default.js diff --git a/packages/slate/test/schema/custom/last-child-type-invalid-function.js b/packages/slate-schema/test/errors/last-child-type-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/last-child-type-invalid-function.js rename to packages/slate-schema/test/errors/last-child-type-invalid-function.js diff --git a/packages/slate/test/schema/custom/match-data.js b/packages/slate-schema/test/errors/match-data.js similarity index 100% rename from packages/slate/test/schema/custom/match-data.js rename to packages/slate-schema/test/errors/match-data.js diff --git a/packages/slate/test/schema/custom/match-object.js b/packages/slate-schema/test/errors/match-object.js similarity index 100% rename from packages/slate/test/schema/custom/match-object.js rename to packages/slate-schema/test/errors/match-object.js diff --git a/packages/slate/test/schema/custom/match-type.js b/packages/slate-schema/test/errors/match-type.js similarity index 100% rename from packages/slate/test/schema/custom/match-type.js rename to packages/slate-schema/test/errors/match-type.js diff --git a/packages/slate/test/schema/custom/next-kind-invalid-custom.js b/packages/slate-schema/test/errors/next-kind-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/next-kind-invalid-custom.js rename to packages/slate-schema/test/errors/next-kind-invalid-custom.js diff --git a/packages/slate/test/schema/custom/next-kind-invalid-default.js b/packages/slate-schema/test/errors/next-kind-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/next-kind-invalid-default.js rename to packages/slate-schema/test/errors/next-kind-invalid-default.js diff --git a/packages/slate/test/schema/custom/next-kind-invalid-function.js b/packages/slate-schema/test/errors/next-kind-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/next-kind-invalid-function.js rename to packages/slate-schema/test/errors/next-kind-invalid-function.js diff --git a/packages/slate/test/schema/custom/next-type-invalid-custom.js b/packages/slate-schema/test/errors/next-type-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/next-type-invalid-custom.js rename to packages/slate-schema/test/errors/next-type-invalid-custom.js diff --git a/packages/slate/test/schema/custom/next-type-invalid-default.js b/packages/slate-schema/test/errors/next-type-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/next-type-invalid-default.js rename to packages/slate-schema/test/errors/next-type-invalid-default.js diff --git a/packages/slate/test/schema/custom/next-type-invalid-function.js b/packages/slate-schema/test/errors/next-type-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/next-type-invalid-function.js rename to packages/slate-schema/test/errors/next-type-invalid-function.js diff --git a/packages/slate/test/schema/custom/node-data-invalid-custom.js b/packages/slate-schema/test/errors/node-data-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/node-data-invalid-custom.js rename to packages/slate-schema/test/errors/node-data-invalid-custom.js diff --git a/packages/slate/test/schema/custom/node-data-invalid-default-undefined.js b/packages/slate-schema/test/errors/node-data-invalid-default-undefined.js similarity index 100% rename from packages/slate/test/schema/custom/node-data-invalid-default-undefined.js rename to packages/slate-schema/test/errors/node-data-invalid-default-undefined.js diff --git a/packages/slate/test/schema/custom/node-data-invalid-default.js b/packages/slate-schema/test/errors/node-data-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/node-data-invalid-default.js rename to packages/slate-schema/test/errors/node-data-invalid-default.js diff --git a/packages/slate/test/schema/custom/node-data-invalid-function.js b/packages/slate-schema/test/errors/node-data-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/node-data-invalid-function.js rename to packages/slate-schema/test/errors/node-data-invalid-function.js diff --git a/packages/slate/test/schema/custom/node-mark-invalid-custom.js b/packages/slate-schema/test/errors/node-mark-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/node-mark-invalid-custom.js rename to packages/slate-schema/test/errors/node-mark-invalid-custom.js diff --git a/packages/slate/test/schema/custom/node-mark-invalid-default.js b/packages/slate-schema/test/errors/node-mark-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/node-mark-invalid-default.js rename to packages/slate-schema/test/errors/node-mark-invalid-default.js diff --git a/packages/slate/test/schema/custom/node-mark-invalid-function.js b/packages/slate-schema/test/errors/node-mark-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/node-mark-invalid-function.js rename to packages/slate-schema/test/errors/node-mark-invalid-function.js diff --git a/packages/slate/test/schema/custom/node-mark-valid-default.js b/packages/slate-schema/test/errors/node-mark-valid-default.js similarity index 100% rename from packages/slate/test/schema/custom/node-mark-valid-default.js rename to packages/slate-schema/test/errors/node-mark-valid-default.js diff --git a/packages/slate-schema/test/errors/node-property-invalid/remove-function.js b/packages/slate-schema/test/errors/node-property-invalid/remove-function.js new file mode 100644 index 0000000000..529cf43ed3 --- /dev/null +++ b/packages/slate-schema/test/errors/node-property-invalid/remove-function.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + properties: { + key: v => v == null, + }, + }, + }, + }, +} + +export const input = ( + + word + +) + +export const output = ( + + word + +) diff --git a/packages/slate-schema/test/errors/node-property-invalid/remove-value.js b/packages/slate-schema/test/errors/node-property-invalid/remove-value.js new file mode 100644 index 0000000000..cd5f88e1a9 --- /dev/null +++ b/packages/slate-schema/test/errors/node-property-invalid/remove-value.js @@ -0,0 +1,23 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + properties: { + key: true, + }, + }, + }, + }, +} + +export const input = ( + + word + +) + +export const output = diff --git a/packages/slate-schema/test/errors/node-property-invalid/unset-value.js b/packages/slate-schema/test/errors/node-property-invalid/unset-value.js new file mode 100644 index 0000000000..fe9d10230b --- /dev/null +++ b/packages/slate-schema/test/errors/node-property-invalid/unset-value.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + properties: { + key: null, + }, + }, + }, + }, +} + +export const input = ( + + word + +) + +export const output = ( + + word + +) diff --git a/packages/slate/test/schema/custom/node-text-invalid-custom.js b/packages/slate-schema/test/errors/node-text-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/node-text-invalid-custom.js rename to packages/slate-schema/test/errors/node-text-invalid-custom.js diff --git a/packages/slate/test/schema/custom/node-text-invalid-default.js b/packages/slate-schema/test/errors/node-text-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/node-text-invalid-default.js rename to packages/slate-schema/test/errors/node-text-invalid-default.js diff --git a/packages/slate/test/schema/custom/node-text-invalid-function.js b/packages/slate-schema/test/errors/node-text-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/node-text-invalid-function.js rename to packages/slate-schema/test/errors/node-text-invalid-function.js diff --git a/packages/slate-schema/test/errors/node-text-invalid/remove-function.js b/packages/slate-schema/test/errors/node-text-invalid/remove-function.js new file mode 100644 index 0000000000..e6a550106f --- /dev/null +++ b/packages/slate-schema/test/errors/node-text-invalid/remove-function.js @@ -0,0 +1,21 @@ +/** @jsx h */ + +import { h } from '../../helpers' + +export const schema = { + blocks: { + a: { + validate: { + text: v => v === 'valid', + }, + }, + }, +} + +export const input = ( + + invalid + +) + +export const output = diff --git a/packages/slate/test/schema/custom/node-text-valid-function.js b/packages/slate-schema/test/errors/node-text-valid-function.js similarity index 100% rename from packages/slate/test/schema/custom/node-text-valid-function.js rename to packages/slate-schema/test/errors/node-text-valid-function.js diff --git a/packages/slate/test/schema/custom/node-text-valid.js b/packages/slate-schema/test/errors/node-text-valid.js similarity index 100% rename from packages/slate/test/schema/custom/node-text-valid.js rename to packages/slate-schema/test/errors/node-text-valid.js diff --git a/packages/slate/test/schema/custom/node-type-invalid-default.js b/packages/slate-schema/test/errors/node-type-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/node-type-invalid-default.js rename to packages/slate-schema/test/errors/node-type-invalid-default.js diff --git a/packages/slate/test/schema/custom/node-type-invalid-function.js b/packages/slate-schema/test/errors/node-type-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/node-type-invalid-function.js rename to packages/slate-schema/test/errors/node-type-invalid-function.js diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-custom.js b/packages/slate-schema/test/errors/parent-kind-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/parent-kind-invalid-custom.js rename to packages/slate-schema/test/errors/parent-kind-invalid-custom.js diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-default.js b/packages/slate-schema/test/errors/parent-kind-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/parent-kind-invalid-default.js rename to packages/slate-schema/test/errors/parent-kind-invalid-default.js diff --git a/packages/slate/test/schema/custom/parent-kind-invalid-function.js b/packages/slate-schema/test/errors/parent-kind-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/parent-kind-invalid-function.js rename to packages/slate-schema/test/errors/parent-kind-invalid-function.js diff --git a/packages/slate/test/schema/custom/parent-type-invalid-custom.js b/packages/slate-schema/test/errors/parent-type-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/parent-type-invalid-custom.js rename to packages/slate-schema/test/errors/parent-type-invalid-custom.js diff --git a/packages/slate/test/schema/custom/parent-type-invalid-default.js b/packages/slate-schema/test/errors/parent-type-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/parent-type-invalid-default.js rename to packages/slate-schema/test/errors/parent-type-invalid-default.js diff --git a/packages/slate/test/schema/custom/parent-type-invalid-function.js b/packages/slate-schema/test/errors/parent-type-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/parent-type-invalid-function.js rename to packages/slate-schema/test/errors/parent-type-invalid-function.js diff --git a/packages/slate/test/schema/custom/previous-kind-invalid-custom.js b/packages/slate-schema/test/errors/previous-kind-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/previous-kind-invalid-custom.js rename to packages/slate-schema/test/errors/previous-kind-invalid-custom.js diff --git a/packages/slate/test/schema/custom/previous-kind-invalid-default.js b/packages/slate-schema/test/errors/previous-kind-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/previous-kind-invalid-default.js rename to packages/slate-schema/test/errors/previous-kind-invalid-default.js diff --git a/packages/slate/test/schema/custom/previous-kind-invalid-function.js b/packages/slate-schema/test/errors/previous-kind-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/previous-kind-invalid-function.js rename to packages/slate-schema/test/errors/previous-kind-invalid-function.js diff --git a/packages/slate/test/schema/custom/previous-type-invalid-custom.js b/packages/slate-schema/test/errors/previous-type-invalid-custom.js similarity index 100% rename from packages/slate/test/schema/custom/previous-type-invalid-custom.js rename to packages/slate-schema/test/errors/previous-type-invalid-custom.js diff --git a/packages/slate/test/schema/custom/previous-type-invalid-default.js b/packages/slate-schema/test/errors/previous-type-invalid-default.js similarity index 100% rename from packages/slate/test/schema/custom/previous-type-invalid-default.js rename to packages/slate-schema/test/errors/previous-type-invalid-default.js diff --git a/packages/slate/test/schema/custom/previous-type-invalid-function.js b/packages/slate-schema/test/errors/previous-type-invalid-function.js similarity index 100% rename from packages/slate/test/schema/custom/previous-type-invalid-function.js rename to packages/slate-schema/test/errors/previous-type-invalid-function.js diff --git a/packages/slate-schema/test/helpers/index.js b/packages/slate-schema/test/helpers/index.js new file mode 100644 index 0000000000..01de294bea --- /dev/null +++ b/packages/slate-schema/test/helpers/index.js @@ -0,0 +1,11 @@ +import { createHyperscript } from 'slate-hyperscript' + +const h = createHyperscript({ + elements: { + a: { type: 'a' }, + b: { type: 'b' }, + c: { type: 'c' }, + }, +}) + +export { h } diff --git a/packages/slate-schema/test/index.js b/packages/slate-schema/test/index.js new file mode 100644 index 0000000000..ab8b1cd5fa --- /dev/null +++ b/packages/slate-schema/test/index.js @@ -0,0 +1,15 @@ +import assert from 'assert' +import { fixtures } from '../../../support/fixtures' +import { Editor } from 'slate' +import { SchemaPlugin } from '..' + +describe('slate-schema', () => { + fixtures(__dirname, 'errors', ({ module }) => { + const { input, schema, output } = module + const withSchema = SchemaPlugin(schema) + const TestEditor = withSchema(Editor) + const editor = new TestEditor({ value: input }) + editor.normalize({ force: true }) + assert.deepEqual(editor.value, output) + }) +}) diff --git a/packages/slate-schema/tsconfig.json b/packages/slate-schema/tsconfig.json new file mode 100644 index 0000000000..4463c7357c --- /dev/null +++ b/packages/slate-schema/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../config/typescript/tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib", + "composite": true + }, + "references": [] +} diff --git a/packages/slate/test/history/undo/add-mark-across-blocks.js b/packages/slate/test/history/undo/add-mark-across-blocks.js deleted file mode 100644 index ca514925f3..0000000000 --- a/packages/slate/test/history/undo/add-mark-across-blocks.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.addMarks([{ key: 'a' }]) - editor.flush() - editor.undo() -} - -export const input = ( - - - - one - - - two - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/add-mark-across-marks.js b/packages/slate/test/history/undo/add-mark-across-marks.js deleted file mode 100644 index a2a0c9e3fd..0000000000 --- a/packages/slate/test/history/undo/add-mark-across-marks.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.addMarks([{ key: 'a' }]) - editor.flush() - editor.undo() -} - -export const input = ( - - - - - wo - rd - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/add-mark-across-same-mark.js b/packages/slate/test/history/undo/add-mark-across-same-mark.js deleted file mode 100644 index 4d16bf27b8..0000000000 --- a/packages/slate/test/history/undo/add-mark-across-same-mark.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.addMarks([{ key: 'a' }]) - editor.flush() - editor.undo() -} - -export const input = ( - - - - - wo - rd - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/add-mark.js b/packages/slate/test/history/undo/add-mark.js deleted file mode 100644 index 236fc83094..0000000000 --- a/packages/slate/test/history/undo/add-mark.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.addMarks([{ key: 'a' }]) - editor.flush() - editor.undo() -} - -export const input = ( - - - - word - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/delete-across-blocks.js b/packages/slate/test/history/undo/delete-across-blocks.js deleted file mode 100644 index 106ad26a24..0000000000 --- a/packages/slate/test/history/undo/delete-across-blocks.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.delete() - editor.flush() - editor.undo() -} - -// the paragraph and code blocks have some random data -// to verify that the data objects get restored to what they were after undo -export const input = ( - - - - one - - - two - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/delete-across-inlines.js b/packages/slate/test/history/undo/delete-across-inlines.js deleted file mode 100644 index aeed2562ec..0000000000 --- a/packages/slate/test/history/undo/delete-across-inlines.js +++ /dev/null @@ -1,32 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.delete() - editor.flush() - editor.undo() -} - -export const input = ( - - - - - - one - - - - - - - two - - - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/delete-across-marks.js b/packages/slate/test/history/undo/delete-across-marks.js deleted file mode 100644 index 0f85d20bdc..0000000000 --- a/packages/slate/test/history/undo/delete-across-marks.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.delete() - editor.flush() - editor.undo() -} - -export const input = ( - - - - - one - - - two - - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/delete-backward-nested-blocks.js b/packages/slate/test/history/undo/delete-backward-nested-blocks.js deleted file mode 100644 index 71da483ccd..0000000000 --- a/packages/slate/test/history/undo/delete-backward-nested-blocks.js +++ /dev/null @@ -1,34 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.deleteBackward() - editor.undo() -} - -export const input = ( - - - Hello - - - world! - - - - -) - -export const output = ( - - - Hello - - - world! - - - - -) diff --git a/packages/slate/test/history/undo/delete-backward.js b/packages/slate/test/history/undo/delete-backward.js deleted file mode 100644 index 840d2572db..0000000000 --- a/packages/slate/test/history/undo/delete-backward.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.deleteBackward() - editor.undo() -} - -export const input = ( - - - Hello - - world! - - - -) - -export const output = ( - - - Hello - - world! - - - -) diff --git a/packages/slate/test/history/undo/delete.js b/packages/slate/test/history/undo/delete.js deleted file mode 100644 index 25df4beb00..0000000000 --- a/packages/slate/test/history/undo/delete.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.delete() - editor.flush() - editor.undo() -} - -export const input = ( - - - - word - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/insert-block.js b/packages/slate/test/history/undo/insert-block.js deleted file mode 100644 index c9f06c2d7d..0000000000 --- a/packages/slate/test/history/undo/insert-block.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.insertBlock('quote') - editor.flush() - editor.undo() -} - -export const input = ( - - - - one - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/insert-fragment.js b/packages/slate/test/history/undo/insert-fragment.js deleted file mode 100644 index 354353cd78..0000000000 --- a/packages/slate/test/history/undo/insert-fragment.js +++ /dev/null @@ -1,46 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -const fragment = ( - - - A - - - B - - - C - - - - - D - - - - -) - -export default function (editor) { - editor.insertFragment(fragment) - editor.flush() - editor.undo() -} - -export const input = ( - - - - - - - - - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/insert-text-contiguous.js b/packages/slate/test/history/undo/insert-text-contiguous.js deleted file mode 100644 index 8ebebbcb8c..0000000000 --- a/packages/slate/test/history/undo/insert-text-contiguous.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.insertText('t') - editor.flush() - editor.insertText('w') - editor.flush() - editor.insertText('o') - editor.flush() - editor.undo() -} - -export const input = ( - - - - one - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/insert-text-not-contiguous.js b/packages/slate/test/history/undo/insert-text-not-contiguous.js deleted file mode 100644 index 368a0a4e0f..0000000000 --- a/packages/slate/test/history/undo/insert-text-not-contiguous.js +++ /dev/null @@ -1,38 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.insertText('t') - - editor.flush() - editor.moveBackward(1) - editor.insertText('w') - - editor.flush() - editor.moveBackward(1) - editor.insertText('o') - - editor.flush() - editor.undo() -} - -export const input = ( - - - - one - - - -) - -export const output = ( - - - - onewt - - - -) diff --git a/packages/slate/test/history/undo/insert-text.js b/packages/slate/test/history/undo/insert-text.js deleted file mode 100644 index f857404a39..0000000000 --- a/packages/slate/test/history/undo/insert-text.js +++ /dev/null @@ -1,21 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.insertText('text') - editor.flush() - editor.undo() -} - -export const input = ( - - - - one - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/move-node-affecting-path.js b/packages/slate/test/history/undo/move-node-affecting-path.js deleted file mode 100644 index d1d8f7f14f..0000000000 --- a/packages/slate/test/history/undo/move-node-affecting-path.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.moveNodeByPath(PathUtils.create([1]), PathUtils.create([2, 1])) - editor.flush() - editor.undo() -} - -export const input = ( - - - one - two - - three - - four - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/move-node-before-itself.js b/packages/slate/test/history/undo/move-node-before-itself.js deleted file mode 100644 index 61c5aca2f6..0000000000 --- a/packages/slate/test/history/undo/move-node-before-itself.js +++ /dev/null @@ -1,30 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.moveNodeByPath(PathUtils.create([1, 1, 2]), PathUtils.create([0])) - editor.flush() - editor.undo() -} - -export const input = ( - - - one - - two - - three - four - five - - - six - seven - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js b/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js deleted file mode 100644 index aadd933151..0000000000 --- a/packages/slate/test/history/undo/move-node-by-path-ancestor-left-sibling.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.moveNodeByPath(PathUtils.create([0]), PathUtils.create([1, 1])) - editor.flush() - editor.undo() -} - -export const input = ( - - - - I am gonna move - - - I am an existing node in newParent - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/move-node-by-path.js b/packages/slate/test/history/undo/move-node-by-path.js deleted file mode 100644 index b267f27dda..0000000000 --- a/packages/slate/test/history/undo/move-node-by-path.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.moveNodeByPath(PathUtils.create([0, 0]), PathUtils.create([1, 1])) - editor.flush() - editor.undo() -} - -export const input = ( - - - - I am gonna move - - - I am an existing node at newPath - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/remove-mark.js b/packages/slate/test/history/undo/remove-mark.js deleted file mode 100644 index e1dbad4f8c..0000000000 --- a/packages/slate/test/history/undo/remove-mark.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.removeMark('bold') - editor.flush() - editor.undo() -} - -export const input = ( - - - - - one - - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/remove-node-by-path.js b/packages/slate/test/history/undo/remove-node-by-path.js deleted file mode 100644 index 8fddc626d7..0000000000 --- a/packages/slate/test/history/undo/remove-node-by-path.js +++ /dev/null @@ -1,22 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.removeNodeByPath(PathUtils.create([0])) - editor.flush() - editor.undo() -} - -export const input = ( - - - one - - -) - -export const output = input - -export const skip = true diff --git a/packages/slate/test/history/undo/remove-text.js b/packages/slate/test/history/undo/remove-text.js deleted file mode 100644 index 6e03eca531..0000000000 --- a/packages/slate/test/history/undo/remove-text.js +++ /dev/null @@ -1,31 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.moveAnchorForward(4) - editor.moveFocusForward(7) - editor.delete() - editor.flush() - editor.undo() -} - -export const input = ( - - - - one two - - - -) - -export const output = ( - - - - one two - - - -) diff --git a/packages/slate/test/history/undo/set-node-by-path-with-data.js b/packages/slate/test/history/undo/set-node-by-path-with-data.js deleted file mode 100644 index 99011e5634..0000000000 --- a/packages/slate/test/history/undo/set-node-by-path-with-data.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.setNodeByPath(PathUtils.create([0]), { - data: { thing: 'value' }, - }) - - editor.flush() - editor.undo() -} - -export const input = ( - - - one - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/split-node-by-path-block.js b/packages/slate/test/history/undo/split-node-by-path-block.js deleted file mode 100644 index e445f8c173..0000000000 --- a/packages/slate/test/history/undo/split-node-by-path-block.js +++ /dev/null @@ -1,28 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.splitNodeByPath(PathUtils.create([0]), 2) - editor.flush() - editor.undo() -} - -export const input = ( - - - - - one - - - - two - - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/toggle-mark.js b/packages/slate/test/history/undo/toggle-mark.js deleted file mode 100644 index 8b4204e4cc..0000000000 --- a/packages/slate/test/history/undo/toggle-mark.js +++ /dev/null @@ -1,35 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.addMarks([{ key: 'a' }]) - editor.flush() - editor.removeMark('bold') - editor.flush() - editor.undo() -} - -export const input = ( - - - - one two three - - - -) - -export const output = ( - - - - one{' '} - - two - - three - - - -) diff --git a/packages/slate/test/history/undo/unwrap-node-by-path.js b/packages/slate/test/history/undo/unwrap-node-by-path.js deleted file mode 100644 index 12e978da81..0000000000 --- a/packages/slate/test/history/undo/unwrap-node-by-path.js +++ /dev/null @@ -1,26 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' -import { PathUtils } from 'slate' - -export default function (editor) { - editor.unwrapNodeByPath(PathUtils.create([0, 0])) - editor.flush() - editor.undo() -} - -export const input = ( - - - - - one - - two - three - - - -) - -export const output = input diff --git a/packages/slate/test/history/undo/wrap-inline-across-blocks.js b/packages/slate/test/history/undo/wrap-inline-across-blocks.js deleted file mode 100644 index 9ffd57de51..0000000000 --- a/packages/slate/test/history/undo/wrap-inline-across-blocks.js +++ /dev/null @@ -1,24 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export default function (editor) { - editor.wrapInline('hashtag') - editor.flush() - editor.undo() -} - -export const input = ( - - - - word - - - another - - - -) - -export const output = input diff --git a/packages/slate/test/schema/custom/child-max-invalid-at-end-default.js b/packages/slate/test/schema/custom/child-max-invalid-at-end-default.js deleted file mode 100644 index 2aaec1f250..0000000000 --- a/packages/slate/test/schema/custom/child-max-invalid-at-end-default.js +++ /dev/null @@ -1,44 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = { - blocks: { - paragraph: {}, - quote: { - nodes: [ - { - match: [{ type: 'paragraph' }], - max: 1, - }, - ], - }, - }, -} - -export const input = ( - - - - - - - - - - - - -) - -export const output = ( - - - - - - - - - -) diff --git a/packages/slate/test/schema/custom/child-max-invalid-custom.js b/packages/slate/test/schema/custom/child-max-invalid-custom.js deleted file mode 100644 index cf80062374..0000000000 --- a/packages/slate/test/schema/custom/child-max-invalid-custom.js +++ /dev/null @@ -1,52 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = { - blocks: { - paragraph: {}, - quote: { - nodes: [ - { - match: [{ type: 'title' }], - max: 1, - }, - { - match: [{ type: 'paragraph' }], - }, - ], - normalize: (editor, { code, path }) => { - if (code === 'child_max_invalid') { - editor.mergeNodeByPath(path) - } - }, - }, - }, -} - -export const input = ( - - - - One - Two - - - - - - -) - -export const output = ( - - - - OneTwo - - - - - - -) diff --git a/packages/slate/test/schema/custom/child-max-invalid-default.js b/packages/slate/test/schema/custom/child-max-invalid-default.js deleted file mode 100644 index e134284375..0000000000 --- a/packages/slate/test/schema/custom/child-max-invalid-default.js +++ /dev/null @@ -1,47 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = { - blocks: { - paragraph: {}, - quote: { - nodes: [ - { - match: [{ type: 'title' }], - max: 1, - }, - { - match: [{ type: 'paragraph' }], - }, - ], - }, - }, -} - -export const input = ( - - - - One - Two - - - - - - -) - -export const output = ( - - - - One - - - - - - -) diff --git a/packages/slate/test/schema/custom/node-object-invalid-default.js b/packages/slate/test/schema/custom/node-object-invalid-default.js deleted file mode 100644 index 092b705b62..0000000000 --- a/packages/slate/test/schema/custom/node-object-invalid-default.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = { - blocks: { - paragraph: { - object: 'inline', - }, - }, -} - -export const input = ( - - - invalid - - -) - -export const output = ( - - - -) diff --git a/packages/slate/test/schema/custom/node-object-invalid-function.js b/packages/slate/test/schema/custom/node-object-invalid-function.js deleted file mode 100644 index 8ae79be94c..0000000000 --- a/packages/slate/test/schema/custom/node-object-invalid-function.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx h */ - -import h from '../../helpers/h' - -export const schema = { - blocks: { - paragraph: { - object: o => o === 'inline', - }, - }, -} - -export const input = ( - - - invalid - - -) - -export const output = ( - - - -) diff --git a/tsconfig.json b/tsconfig.json index b2c67b28f3..8044c96b77 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "references": [ { "path": "./packages/slate" }, { "path": "./packages/slate-hyperscript" }, + { "path": "./packages/slate-schema" }, { "path": "./packages/slate-history" } ], "files": [], From 9defac58e348929a01714ef532c9253296d673c2 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Mon, 4 Nov 2019 11:15:34 -0500 Subject: [PATCH 085/165] start of react working --- config/rollup/rollup.config.js | 8 +- config/typescript/tsconfig.json | 2 + examples/index.js | 12 - examples/rich-text/index.js | 431 ++++------- examples/rich-text/value.json | 150 ++-- packages/slate-base64-serializer/Changelog.md | 17 - packages/slate-base64-serializer/Readme.md | 1 - packages/slate-base64-serializer/package.json | 39 - packages/slate-base64-serializer/src/index.js | 93 --- .../slate-base64-serializer/test/index.js | 0 packages/slate-dev-environment/Readme.md | 1 - packages/slate-dev-environment/package.json | 21 - packages/slate-dev-environment/test/index.js | 0 packages/slate-history/src/index.ts | 2 +- packages/slate-history/src/plugin.ts | 16 +- packages/slate-hotkeys/Changelog.md | 17 - packages/slate-hotkeys/Readme.md | 1 - packages/slate-hotkeys/package.json | 30 - packages/slate-hotkeys/test/index.js | 0 packages/slate-parse-plaintext/package.json | 2 +- packages/slate-react/package.json | 30 +- .../slate-react/src/components/children.tsx | 79 ++ .../slate-react/src/components/content.js | 644 ---------------- .../slate-react/src/components/defaults.tsx | 31 + packages/slate-react/src/components/editor.js | 399 ---------- .../slate-react/src/components/editor.tsx | 548 ++++++++++++++ .../slate-react/src/components/element.tsx | 114 +++ packages/slate-react/src/components/leaf.js | 220 ------ packages/slate-react/src/components/leaf.tsx | 104 +++ packages/slate-react/src/components/node.js | 331 --------- .../slate-react/src/components/string.tsx | 100 +++ packages/slate-react/src/components/text.js | 102 --- packages/slate-react/src/components/text.tsx | 60 ++ packages/slate-react/src/components/void.js | 146 ---- .../src/constants/data-attributes.js | 20 - .../src/constants/event-handlers.js | 39 - .../src/constants/other-handlers.js | 24 - .../slate-react/src/constants/selectors.js | 20 - .../src/constants/transfer-types.js | 13 - packages/slate-react/src/hooks/use-editor.ts | 24 + .../slate-react/src/hooks/use-read-only.ts | 15 + packages/slate-react/src/hooks/use-slate.ts | 14 + packages/slate-react/src/index.js | 51 -- packages/slate-react/src/index.ts | 5 + packages/slate-react/src/plugin/commands.ts | 73 ++ .../slate-react/src/plugin/dom-helpers.ts | 641 ++++++++++++++++ packages/slate-react/src/plugin/events.ts | 557 ++++++++++++++ packages/slate-react/src/plugin/index.ts | 56 ++ packages/slate-react/src/plugin/queries.ts | 65 ++ packages/slate-react/src/plugin/rendering.tsx | 89 +++ .../plugins/android/composition-manager.js | 610 --------------- .../plugins/android/composition-manager.md | 32 - .../src/plugins/android/diff-text.js | 97 --- .../src/plugins/android/dom-snapshot.js | 67 -- .../src/plugins/android/element-snapshot.js | 166 ----- .../src/plugins/android/executor.js | 96 --- .../slate-react/src/plugins/android/index.js | 122 --- .../src/plugins/debug/debug-batch-events.js | 111 --- .../src/plugins/debug/debug-events.js | 52 -- .../src/plugins/debug/debug-mutations.js | 147 ---- .../slate-react/src/plugins/debug/noop.js | 45 -- .../src/plugins/debug/stringify-event.js | 21 - packages/slate-react/src/plugins/dom/after.js | 702 ------------------ .../slate-react/src/plugins/dom/before.js | 492 ------------ packages/slate-react/src/plugins/dom/index.js | 37 - .../slate-react/src/plugins/react/commands.js | 68 -- .../src/plugins/react/editor-props.js | 46 -- .../slate-react/src/plugins/react/index.js | 74 -- .../slate-react/src/plugins/react/queries.js | 642 ---------------- .../src/plugins/react/rendering.js | 65 -- .../src/plugins/react/restore-dom.js | 15 - packages/slate-react/src/utils/base-64.ts | 19 + .../{clone-fragment.js => clone-fragment.ts} | 116 ++- packages/slate-react/src/utils/constants.ts | 47 ++ packages/slate-react/src/utils/dom.ts | 142 ++++ .../src/utils/environment.ts} | 26 +- .../slate-react/src/utils/find-dom-node.js | 41 - .../slate-react/src/utils/find-dom-point.js | 59 -- .../slate-react/src/utils/find-dom-range.js | 38 - packages/slate-react/src/utils/find-node.js | 45 -- packages/slate-react/src/utils/find-path.js | 36 - packages/slate-react/src/utils/find-point.js | 184 ----- packages/slate-react/src/utils/find-range.js | 73 -- .../slate-react/src/utils/get-event-range.js | 102 --- .../src/utils/get-event-transfer.js | 167 ----- .../src/utils/get-selection-from-dom.js | 99 --- .../src/utils/hotkeys.ts} | 65 +- packages/slate-react/src/utils/offset-key.js | 52 -- packages/slate-react/src/utils/react.ts | 9 + .../src/utils/remove-all-ranges.js | 27 - ...to-selection.js => scroll-to-selection.ts} | 57 +- .../src/utils/set-event-transfer.js | 71 -- packages/slate-react/src/utils/weak-maps.ts | 26 + packages/slate-react/tsconfig.json | 9 + packages/slate-render-plaintext/package.json | 2 +- packages/slate-schema/src/plugin.ts | 4 +- .../slate/src/classes/commands/general.ts | 36 +- packages/slate/src/classes/editor.ts | 54 +- packages/slate/src/classes/path-ref.ts | 26 +- packages/slate/src/classes/point-ref.ts | 26 +- packages/slate/src/classes/queries/general.ts | 26 +- packages/slate/src/classes/queries/value.ts | 45 ++ packages/slate/src/classes/range-ref.ts | 26 +- packages/slate/src/classes/utils.ts | 13 +- packages/slate/src/index.ts | 7 +- packages/slate/src/symbols.ts | 6 - tsconfig.json | 7 +- yarn.lock | 58 +- 108 files changed, 3380 insertions(+), 7630 deletions(-) delete mode 100644 packages/slate-base64-serializer/Changelog.md delete mode 100644 packages/slate-base64-serializer/Readme.md delete mode 100644 packages/slate-base64-serializer/package.json delete mode 100644 packages/slate-base64-serializer/src/index.js delete mode 100644 packages/slate-base64-serializer/test/index.js delete mode 100644 packages/slate-dev-environment/Readme.md delete mode 100644 packages/slate-dev-environment/package.json delete mode 100644 packages/slate-dev-environment/test/index.js delete mode 100644 packages/slate-hotkeys/Changelog.md delete mode 100644 packages/slate-hotkeys/Readme.md delete mode 100644 packages/slate-hotkeys/package.json delete mode 100644 packages/slate-hotkeys/test/index.js create mode 100644 packages/slate-react/src/components/children.tsx delete mode 100644 packages/slate-react/src/components/content.js create mode 100644 packages/slate-react/src/components/defaults.tsx delete mode 100644 packages/slate-react/src/components/editor.js create mode 100644 packages/slate-react/src/components/editor.tsx create mode 100644 packages/slate-react/src/components/element.tsx delete mode 100644 packages/slate-react/src/components/leaf.js create mode 100644 packages/slate-react/src/components/leaf.tsx delete mode 100644 packages/slate-react/src/components/node.js create mode 100644 packages/slate-react/src/components/string.tsx delete mode 100644 packages/slate-react/src/components/text.js create mode 100644 packages/slate-react/src/components/text.tsx delete mode 100644 packages/slate-react/src/components/void.js delete mode 100644 packages/slate-react/src/constants/data-attributes.js delete mode 100644 packages/slate-react/src/constants/event-handlers.js delete mode 100644 packages/slate-react/src/constants/other-handlers.js delete mode 100644 packages/slate-react/src/constants/selectors.js delete mode 100644 packages/slate-react/src/constants/transfer-types.js create mode 100644 packages/slate-react/src/hooks/use-editor.ts create mode 100644 packages/slate-react/src/hooks/use-read-only.ts create mode 100644 packages/slate-react/src/hooks/use-slate.ts delete mode 100644 packages/slate-react/src/index.js create mode 100644 packages/slate-react/src/index.ts create mode 100644 packages/slate-react/src/plugin/commands.ts create mode 100644 packages/slate-react/src/plugin/dom-helpers.ts create mode 100644 packages/slate-react/src/plugin/events.ts create mode 100644 packages/slate-react/src/plugin/index.ts create mode 100644 packages/slate-react/src/plugin/queries.ts create mode 100644 packages/slate-react/src/plugin/rendering.tsx delete mode 100644 packages/slate-react/src/plugins/android/composition-manager.js delete mode 100644 packages/slate-react/src/plugins/android/composition-manager.md delete mode 100644 packages/slate-react/src/plugins/android/diff-text.js delete mode 100644 packages/slate-react/src/plugins/android/dom-snapshot.js delete mode 100644 packages/slate-react/src/plugins/android/element-snapshot.js delete mode 100644 packages/slate-react/src/plugins/android/executor.js delete mode 100644 packages/slate-react/src/plugins/android/index.js delete mode 100644 packages/slate-react/src/plugins/debug/debug-batch-events.js delete mode 100644 packages/slate-react/src/plugins/debug/debug-events.js delete mode 100644 packages/slate-react/src/plugins/debug/debug-mutations.js delete mode 100644 packages/slate-react/src/plugins/debug/noop.js delete mode 100644 packages/slate-react/src/plugins/debug/stringify-event.js delete mode 100644 packages/slate-react/src/plugins/dom/after.js delete mode 100644 packages/slate-react/src/plugins/dom/before.js delete mode 100644 packages/slate-react/src/plugins/dom/index.js delete mode 100644 packages/slate-react/src/plugins/react/commands.js delete mode 100644 packages/slate-react/src/plugins/react/editor-props.js delete mode 100644 packages/slate-react/src/plugins/react/index.js delete mode 100644 packages/slate-react/src/plugins/react/queries.js delete mode 100644 packages/slate-react/src/plugins/react/rendering.js delete mode 100644 packages/slate-react/src/plugins/react/restore-dom.js create mode 100644 packages/slate-react/src/utils/base-64.ts rename packages/slate-react/src/utils/{clone-fragment.js => clone-fragment.ts} (55%) create mode 100644 packages/slate-react/src/utils/constants.ts create mode 100644 packages/slate-react/src/utils/dom.ts rename packages/{slate-dev-environment/src/index.js => slate-react/src/utils/environment.ts} (91%) delete mode 100644 packages/slate-react/src/utils/find-dom-node.js delete mode 100644 packages/slate-react/src/utils/find-dom-point.js delete mode 100644 packages/slate-react/src/utils/find-dom-range.js delete mode 100644 packages/slate-react/src/utils/find-node.js delete mode 100644 packages/slate-react/src/utils/find-path.js delete mode 100644 packages/slate-react/src/utils/find-point.js delete mode 100644 packages/slate-react/src/utils/find-range.js delete mode 100644 packages/slate-react/src/utils/get-event-range.js delete mode 100644 packages/slate-react/src/utils/get-event-transfer.js delete mode 100644 packages/slate-react/src/utils/get-selection-from-dom.js rename packages/{slate-hotkeys/src/index.js => slate-react/src/utils/hotkeys.ts} (50%) delete mode 100644 packages/slate-react/src/utils/offset-key.js create mode 100644 packages/slate-react/src/utils/react.ts delete mode 100644 packages/slate-react/src/utils/remove-all-ranges.js rename packages/slate-react/src/utils/{scroll-to-selection.js => scroll-to-selection.ts} (77%) delete mode 100644 packages/slate-react/src/utils/set-event-transfer.js create mode 100644 packages/slate-react/src/utils/weak-maps.ts create mode 100644 packages/slate-react/tsconfig.json create mode 100644 packages/slate/src/classes/queries/value.ts delete mode 100644 packages/slate/src/symbols.ts diff --git a/config/rollup/rollup.config.js b/config/rollup/rollup.config.js index 3e91b43a0b..4d8e06043d 100644 --- a/config/rollup/rollup.config.js +++ b/config/rollup/rollup.config.js @@ -10,10 +10,7 @@ import uglify from 'rollup-plugin-uglify' import { startCase } from 'lodash' import Core from '../../packages/slate/package.json' -import Base64Serializer from '../../packages/slate-base64-serializer/package.json' -import DevEnvironment from '../../packages/slate-dev-environment/package.json' import History from '../../packages/slate-history/package.json' -import Hotkeys from '../../packages/slate-hotkeys/package.json' import HtmlSerializer from '../../packages/slate-html-serializer/package.json' import Hyperscript from '../../packages/slate-hyperscript/package.json' import ParsePlaintext from '../../packages/slate-parse-plaintext/package.json' @@ -178,16 +175,13 @@ function factory(pkg, options = {}) { export default [ ...factory(Core, { ts: true }), - ...factory(Base64Serializer), - ...factory(DevEnvironment), ...factory(History, { ts: true }), - ...factory(Hotkeys), ...factory(HtmlSerializer), ...factory(Hyperscript, { ts: true }), ...factory(PlainSerializer), ...factory(ParsePlaintext, { ts: true }), ...factory(PropTypes), - ...factory(React), + ...factory(React, { ts: true }), ...factory(ReactPlaceholder), ...factory(RenderPlaintext, { ts: true }), ...factory(Schema, { ts: true }), diff --git a/config/typescript/tsconfig.json b/config/typescript/tsconfig.json index 278abb318f..5f3f64222a 100644 --- a/config/typescript/tsconfig.json +++ b/config/typescript/tsconfig.json @@ -5,8 +5,10 @@ "declaration": true, "declarationMap": true, "esModuleInterop": true, + "jsx": "react", "module": "esnext", "moduleResolution": "node", + "resolveJsonModule": true, "sourceMap": true, "strict": true, "suppressImplicitAnyIndexErrors": true, diff --git a/examples/index.js b/examples/index.js index 94905494c0..71671bdca2 100644 --- a/examples/index.js +++ b/examples/index.js @@ -4,10 +4,6 @@ import { AppContainer } from 'react-hot-loader' import App from './app' import './index.css' -/** - * Render the app. - */ - const root = window.document.createElement('div') root.id = 'root' window.document.body.appendChild(root) @@ -22,11 +18,3 @@ const render = Component => { } render(App) - -/** - * Re-render for hot module replacement in development. - */ - -if (module.hot) { - module.hot.accept('./app', () => render(App)) -} diff --git a/examples/rich-text/index.js b/examples/rich-text/index.js index 38cc3ed167..00158d7ddf 100644 --- a/examples/rich-text/index.js +++ b/examples/rich-text/index.js @@ -1,322 +1,173 @@ -import { Editor } from 'slate-react' -import { Value } from 'slate' +import React, { useState, useMemo } from 'react' +import isHotkey from 'is-hotkey' +import { Editor as BaseEditor } from 'slate' +import { Editor, withReact } from 'slate-react' +import { withHistory } from 'slate-history' -import React from 'react' import initialValue from './value.json' -import { isKeyHotkey } from 'is-hotkey' import { Button, Icon, Toolbar } from '../components' -/** - * Define the default node type. - * - * @type {String} - */ - -const DEFAULT_NODE = 'paragraph' - -/** - * Define hotkey matchers. - * - * @type {Function} - */ - -const isBoldHotkey = isKeyHotkey('mod+b') -const isItalicHotkey = isKeyHotkey('mod+i') -const isUnderlinedHotkey = isKeyHotkey('mod+u') -const isCodeHotkey = isKeyHotkey('mod+`') - -/** - * The rich text example. - * - * @type {Component} - */ - -class RichTextExample extends React.Component { - /** - * Deserialize the initial editor value. - * - * @type {Object} - */ - - state = { - value: Value.fromJSON(initialValue), - } - - /** - * Check if the current selection has a mark with `type` in it. - * - * @param {String} type - * @return {Boolean} - */ - - hasMark = type => { - const { value } = this.state - return value.activeMarks.some(mark => mark.type === type) - } - - /** - * Check if the any of the currently selected blocks are of `type`. - * - * @param {String} type - * @return {Boolean} - */ +class ExampleEditor extends withHistory(withReact(BaseEditor)) { + onKeyDown(event) { + let type + + if (isHotkey('mod+b', event)) { + type = 'bold' + } else if (isHotkey('mod+i', event)) { + type = 'italic' + } else if (isHotkey('mod+u', event)) { + type = 'underlined' + } else if (isHotkey('mod+`', event)) { + type = 'code' + } else { + return super.onKeyDown(event) + } - hasBlock = type => { - const { value } = this.state - return value.blocks.some(node => node.type === type) + event.preventDefault() + this.toggleMarks([{ type }]) } - /** - * Store a reference to the `editor`. - * - * @param {Editor} editor - */ - - ref = editor => { - this.editor = editor + renderElement(props) { + return } - /** - * Render. - * - * @return {Element} - */ - - render() { - return ( -
- - {this.renderMarkButton('bold', 'format_bold')} - {this.renderMarkButton('italic', 'format_italic')} - {this.renderMarkButton('underlined', 'format_underlined')} - {this.renderMarkButton('code', 'code')} - {this.renderBlockButton('heading-one', 'looks_one')} - {this.renderBlockButton('heading-two', 'looks_two')} - {this.renderBlockButton('block-quote', 'format_quote')} - {this.renderBlockButton('numbered-list', 'format_list_numbered')} - {this.renderBlockButton('bulleted-list', 'format_list_bulleted')} - - -
- ) + renderMark(props) { + return } - /** - * Render a mark-toggling toolbar button. - * - * @param {String} type - * @param {String} icon - * @return {Element} - */ - - renderMarkButton = (type, icon) => { - const isActive = this.hasMark(type) - - return ( - - ) + isMarkActive(type) { + const marks = this.getActiveMarks() + const isActive = marks.some(m => m.type === type) + return isActive } - /** - * Render a block-toggling toolbar button. - * - * @param {String} type - * @param {String} icon - * @return {Element} - */ - - renderBlockButton = (type, icon) => { - let isActive = this.hasBlock(type) - - if (['numbered-list', 'bulleted-list'].includes(type)) { - const { value: { document, blocks } } = this.state + isBlockActive(type) { + const { selection } = this.value - if (blocks.size > 0) { - const parent = document.getParent(blocks.first().key) - isActive = this.hasBlock('list-item') && parent && parent.type === type + if (selection) { + for (const [node] of this.elements({ at: selection })) { + if (node.type === type) { + return true + } } } - return ( - - ) + return false } - /** - * Render a Slate block. - * - * @param {Object} props - * @return {Element} - */ + toggleBlocks(type) { + const isActive = this.isBlockActive(type) + const isListType = type === 'bulleted-list' || type === 'numbered-list' + this.unwrapNodes({ match: { type: 'bulleted-list' } }) + this.unwrapNodes({ match: { type: 'numbered-list' } }) - renderBlock = (fn, editor) => props => { - const { attributes, children, node } = props + const newType = isActive ? 'paragraph' : isListType ? 'list-item' : type + this.setNodes({ type: newType }) - switch (node.type) { - case 'block-quote': - return
{children}
- case 'bulleted-list': - return
    {children}
- case 'heading-one': - return

{children}

- case 'heading-two': - return

{children}

- case 'list-item': - return
  • {children}
  • - case 'numbered-list': - return
      {children}
    - default: - return fn(props) + if (!isActive && isListType) { + this.wrapNodes({ type, nodes: [] }) } } +} - /** - * Render a Slate mark. - * - * @param {Object} props - * @return {Element} - */ - - renderMark = (fn, editor) => props => { - const { children, mark, attributes } = props - - switch (mark.type) { - case 'bold': - return {children} - case 'code': - return {children} - case 'italic': - return {children} - case 'underlined': - return {children} - default: - return fn(props) - } - } - - /** - * On change, save the new `value`. - * - * @param {Editor} editor - */ - - onChange = ({ value }) => { - this.setState({ value }) - } - - /** - * On key down, if it's a formatting command toggle a mark. - * - * @param {Event} event - * @param {Editor} editor - * @return {Change} - */ - - onKeyDown = (fn, editor) => event => { - let mark - - if (isBoldHotkey(event)) { - mark = 'bold' - } else if (isItalicHotkey(event)) { - mark = 'italic' - } else if (isUnderlinedHotkey(event)) { - mark = 'underlined' - } else if (isCodeHotkey(event)) { - mark = 'code' - } else { - return fn(event) - } +const Example = () => { + const [value, setValue] = useState(initialValue) + const editor = useSlate(ExampleEditor) + return ( +
    + + + + + + + + + + + + setValue(change.value)} + /> +
    + ) +} - event.preventDefault() - editor.toggleMark(mark) +const Element = ({ attributes, children, element }) => { + switch (element.type) { + case 'block-quote': + return
    {children}
    + case 'bulleted-list': + return
      {children}
    + case 'heading-one': + return

    {children}

    + case 'heading-two': + return

    {children}

    + case 'list-item': + return
  • {children}
  • + case 'numbered-list': + return
      {children}
    + default: + return

    {children}

    } +} - /** - * When a mark button is clicked, toggle the current mark. - * - * @param {Event} event - * @param {String} type - */ - - onClickMark = (event, type) => { - event.preventDefault() - this.editor.toggleMark(type) +const Mark = ({ attributes, children, mark }) => { + switch (mark.type) { + case 'bold': + return {children} + case 'code': + return {children} + case 'italic': + return {children} + case 'underlined': + return {children} } +} - /** - * When a block button is clicked, toggle the block type. - * - * @param {Event} event - * @param {String} type - */ - - onClickBlock = (event, type) => { - event.preventDefault() - - const { editor } = this - const { value } = editor - const { document } = value - - // Handle everything but list buttons. - if (type !== 'bulleted-list' && type !== 'numbered-list') { - const isActive = this.hasBlock(type) - const isList = this.hasBlock('list-item') - - if (isList) { - editor - .setBlocks(isActive ? DEFAULT_NODE : type) - .unwrapBlock('bulleted-list') - .unwrapBlock('numbered-list') - } else { - editor.setBlocks(isActive ? DEFAULT_NODE : type) - } - } else { - // Handle the extra wrapping required for list buttons. - const isList = this.hasBlock('list-item') - const isType = value.blocks.some(block => { - return !!document.getClosest(block.key, parent => parent.type === type) - }) - - if (isList && isType) { - editor - .setBlocks(DEFAULT_NODE) - .unwrapBlock('bulleted-list') - .unwrapBlock('numbered-list') - } else if (isList) { - editor - .unwrapBlock( - type === 'bulleted-list' ? 'numbered-list' : 'bulleted-list' - ) - .wrapBlock(type) - } else { - editor.setBlocks('list-item').wrapBlock(type) - } - } - } +const MarkButton = ({ editor, type, icon }) => { + return ( + + ) } -/** - * Export. - */ +const BlockButton = ({ editor, type, icon }) => { + return ( + + ) +} -export default RichTextExample +export default Example diff --git a/examples/rich-text/value.json b/examples/rich-text/value.json index eefd1640b9..2b4a770a61 100644 --- a/examples/rich-text/value.json +++ b/examples/rich-text/value.json @@ -1,86 +1,68 @@ { - "object": "value", - "document": { - "object": "document", - "nodes": [ - { - "object": "block", - "type": "paragraph", - "nodes": [ - { - "object": "text", - "text": "This is editable " - }, - { - "object": "text", - "text": "rich", - "marks": [{ "type": "bold" }] - }, - { - "object": "text", - "text": " text, " - }, - { - "object": "text", - "text": "much", - "marks": [{ "type": "italic" }] - }, - { - "object": "text", - "text": " better than a " - }, - { - "object": "text", - "text": "