diff --git a/packages/slate/src/interfaces/editor/queries/location.ts b/packages/slate/src/interfaces/editor/queries/location.ts index 402ee5fab..bd8c33c30 100644 --- a/packages/slate/src/interfaces/editor/queries/location.ts +++ b/packages/slate/src/interfaces/editor/queries/location.ts @@ -55,31 +55,6 @@ export const LocationQueries = { return target }, - /** - * Get the common ancestor node of a location. - */ - - ancestor( - editor: Editor, - at: Location, - options: { - depth?: number - edge?: 'start' | 'end' - } = {} - ): AncestorEntry { - if (Path.isPath(at) || Point.isPoint(at)) { - return Editor.parent(editor, at, options) - } - - const path = Editor.path(editor, at, options) - const ancestorPath = Path.equals(at.anchor.path, at.focus.path) - ? Path.parent(path) - : path - - const ancestor = Node.get(editor, ancestorPath) as Ancestor - return [ancestor, ancestorPath] - }, - /** * Get the point before a location. */ @@ -174,20 +149,6 @@ export const LocationQueries = { return fragment }, - /** - * Check if a point the start point of a location. - */ - - isStart(editor: 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 = Editor.start(editor, at) - return Point.equals(point, start) - }, - /** * Check if a point is the end point of a location. */ @@ -205,6 +166,20 @@ export const LocationQueries = { return Editor.isStart(editor, point, at) || Editor.isEnd(editor, point, at) }, + /** + * Check if a point is the start point of a location. + */ + + isStart(editor: 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 = Editor.start(editor, at) + return Point.equals(point, start) + }, + /** * Get the last node at a location. */ diff --git a/packages/slate/src/interfaces/editor/transforms/node.ts b/packages/slate/src/interfaces/editor/transforms/node.ts index b6ab6ab3f..2d16624b0 100644 --- a/packages/slate/src/interfaces/editor/transforms/node.ts +++ b/packages/slate/src/interfaces/editor/transforms/node.ts @@ -244,7 +244,7 @@ export const NodeTransforms = { // 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(editor, path, ([n, p]) => { + const emptyAncestor = Editor.match(editor, path, ([n, p]) => { return ( Path.isDescendant(p, commonPath) && Path.isAncestor(p, path) && diff --git a/packages/slate/src/interfaces/node.ts b/packages/slate/src/interfaces/node.ts index f0d7fd3fd..9d34856f8 100755 --- a/packages/slate/src/interfaces/node.ts +++ b/packages/slate/src/interfaces/node.ts @@ -9,13 +9,6 @@ import { Editor, Element, ElementEntry, Path, Range, Text, TextEntry } from '..' export type Node = Editor | Element | Text export const Node = { - matches(node: Node, props: Partial): boolean { - return ( - (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. */ @@ -101,22 +94,6 @@ export const Node = { } }, - /** - * Find the closest matching node entry starting from a specific path. - */ - - closest( - 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 an entry for the common ancesetor node of two paths. */ @@ -251,22 +228,6 @@ export const Node = { return newRoot.children }, - /** - * Find the furthest matching node entry starting from a specific path. - */ - - furthest( - 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 descendant node referred to by a specific path. If the path is an * empty array, it refers to the root node itself. @@ -387,6 +348,17 @@ export const Node = { } }, + /** + * Check if a node matches a set of props. + */ + + matches(node: Node, props: Partial): boolean { + return ( + (Element.isElement(node) && Element.matches(node, props)) || + (Text.isText(node) && Text.matches(node, props)) + ) + }, + /** * 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 diff --git a/packages/slate/src/interfaces/range.ts b/packages/slate/src/interfaces/range.ts index d2613819c..e2d60c681 100755 --- a/packages/slate/src/interfaces/range.ts +++ b/packages/slate/src/interfaces/range.ts @@ -53,26 +53,6 @@ export const Range = { ) }, - /** - * Check if a range exists in a list or map of ranges. - */ - - exists(range: Range, target: Range[] | Record): boolean { - if (Range.isRangeList(target)) { - return !!target.find(r => Range.equals(r, range)) - } - - if (Range.isRangeMap(target)) { - for (const key in target) { - if (Range.equals(range, target[key])) { - return true - } - } - } - - return false - }, - /** * Check if a range includes a path, a point or part of another range. */ @@ -176,32 +156,6 @@ export const Range = { ) }, - /** - * Check if a value is an array of `Range` objects. - */ - - isRangeList(value: any): value is Range[] { - return ( - Array.isArray(value) && (value.length === 0 || Range.isRange(value[0])) - ) - }, - - /** - * Check if a value is a map of `Range` objects. - */ - - isRangeMap(value: any): value is Record { - if (!isPlainObject(value)) { - return false - } - - for (const key in value) { - return Range.isRange(value[key]) - } - - return true - }, - /** * Iterate through all of the point entries in a range. */ diff --git a/packages/slate/test/interfaces/Node/closest/success.js b/packages/slate/test/interfaces/Node/closest/success.js deleted file mode 100644 index 9fac3ac44..000000000 --- a/packages/slate/test/interfaces/Node/closest/success.js +++ /dev/null @@ -1,25 +0,0 @@ -/** @jsx jsx */ - -import { Element, Node } from 'slate' -import { jsx } 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/furthest/success.js b/packages/slate/test/interfaces/Node/furthest/success.js deleted file mode 100644 index ba285c855..000000000 --- a/packages/slate/test/interfaces/Node/furthest/success.js +++ /dev/null @@ -1,27 +0,0 @@ -/** @jsx jsx */ - -import { Element, Node } from 'slate' -import { jsx } 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/queries/ancestor/path.js b/packages/slate/test/queries/ancestor/path.js deleted file mode 100644 index 083449b54..000000000 --- a/packages/slate/test/queries/ancestor/path.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @jsx jsx */ - -import { Editor } from 'slate' -import { jsx } from '../..' - -export const input = ( - - one - -) - -export const run = editor => { - return Editor.ancestor(editor, [0, 0]) -} - -export const output = [one, [0]] diff --git a/packages/slate/test/queries/ancestor/point.js b/packages/slate/test/queries/ancestor/point.js deleted file mode 100644 index 9cd907979..000000000 --- a/packages/slate/test/queries/ancestor/point.js +++ /dev/null @@ -1,16 +0,0 @@ -/** @jsx jsx */ - -import { Editor } from 'slate' -import { jsx } from '../..' - -export const input = ( - - one - -) - -export const run = editor => { - return Editor.ancestor(editor, { path: [0, 0], offset: 1 }) -} - -export const output = [one, [0]] diff --git a/packages/slate/test/queries/ancestor/range-text.js b/packages/slate/test/queries/ancestor/range-text.js deleted file mode 100644 index 0892a7fc9..000000000 --- a/packages/slate/test/queries/ancestor/range-text.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx jsx */ - -import { Editor } from 'slate' -import { jsx } from '../..' - -export const input = ( - - one - two - -) - -export const run = editor => { - return Editor.ancestor(editor, { - anchor: { path: [0, 0], offset: 1 }, - focus: { path: [0, 0], offset: 2 }, - }) -} - -export const output = [one, [0]] diff --git a/packages/slate/test/queries/ancestor/range.js b/packages/slate/test/queries/ancestor/range.js deleted file mode 100644 index ba74b4bed..000000000 --- a/packages/slate/test/queries/ancestor/range.js +++ /dev/null @@ -1,20 +0,0 @@ -/** @jsx jsx */ - -import { Editor } from 'slate' -import { jsx } from '../..' - -export const input = ( - - one - two - -) - -export const run = editor => { - return Editor.ancestor(editor, { - anchor: { path: [0, 0], offset: 1 }, - focus: { path: [1, 0], offset: 2 }, - }) -} - -export const output = [input, []]