diff --git a/packages/slate/src/interfaces/editor.ts b/packages/slate/src/interfaces/editor.ts index 5bc12f2b1..58876211c 100755 --- a/packages/slate/src/interfaces/editor.ts +++ b/packages/slate/src/interfaces/editor.ts @@ -699,7 +699,7 @@ export const Editor: EditorInterface = { const path = Editor.path(editor, at) for (const [n, p] of Node.levels(editor, path)) { - if (!match(n)) { + if (!match(n, p)) { continue } @@ -893,7 +893,7 @@ export const Editor: EditorInterface = { continue } - if (!match(node)) { + if (!match(node, path)) { // If we've arrived at a leaf text node that is not lower than the last // hit, then we've found a branch that doesn't include a match, which // means the match is not universal. @@ -1575,6 +1575,6 @@ export const Editor: EditorInterface = { * A helper type for narrowing matched nodes with a predicate. */ -type NodeMatch = - | ((node: Node) => node is T) - | ((node: Node) => boolean) +export type NodeMatch = + | ((node: Node, path: Path) => node is T) + | ((node: Node, path: Path) => boolean) diff --git a/packages/slate/src/transforms/node.ts b/packages/slate/src/transforms/node.ts index 764a7f5a8..41a88f21f 100644 --- a/packages/slate/src/transforms/node.ts +++ b/packages/slate/src/transforms/node.ts @@ -11,109 +11,110 @@ import { NodeEntry, Ancestor, } from '..' +import { NodeMatch } from '../interfaces/editor' export interface NodeTransforms { - insertNodes: ( + insertNodes: ( editor: Editor, nodes: Node | Node[], options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' hanging?: boolean select?: boolean voids?: boolean } ) => void - liftNodes: ( + liftNodes: ( editor: Editor, options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' voids?: boolean } ) => void - mergeNodes: ( + mergeNodes: ( editor: Editor, options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' hanging?: boolean voids?: boolean } ) => void - moveNodes: ( + moveNodes: ( editor: Editor, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' to: Path voids?: boolean } ) => void - removeNodes: ( + removeNodes: ( editor: Editor, options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' hanging?: boolean voids?: boolean } ) => void - setNodes: ( + setNodes: ( editor: Editor, props: Partial, options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' hanging?: boolean split?: boolean voids?: boolean } ) => void - splitNodes: ( + splitNodes: ( editor: Editor, options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' always?: boolean height?: number voids?: boolean } ) => void - unsetNodes: ( + unsetNodes: ( editor: Editor, props: string | string[], options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' split?: boolean voids?: boolean } ) => void - unwrapNodes: ( + unwrapNodes: ( editor: Editor, options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' split?: boolean voids?: boolean } ) => void - wrapNodes: ( + wrapNodes: ( editor: Editor, element: Element, options?: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' split?: boolean voids?: boolean @@ -126,12 +127,12 @@ export const NodeTransforms: NodeTransforms = { * Insert nodes at a specific location in the Editor. */ - insertNodes( + insertNodes( editor: Editor, nodes: Node | Node[], options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' hanging?: boolean select?: boolean @@ -244,11 +245,11 @@ export const NodeTransforms: NodeTransforms = { * their parent in two if necessary. */ - liftNodes( + liftNodes( editor: Editor, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' voids?: boolean } = {} @@ -308,11 +309,11 @@ export const NodeTransforms: NodeTransforms = { * removing any empty containing nodes after the merge if necessary. */ - mergeNodes( + mergeNodes( editor: Editor, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' hanging?: boolean voids?: boolean @@ -446,11 +447,11 @@ export const NodeTransforms: NodeTransforms = { * Move the nodes at a location to a new location. */ - moveNodes( + moveNodes( editor: Editor, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' to: Path voids?: boolean @@ -496,11 +497,11 @@ export const NodeTransforms: NodeTransforms = { * Remove the nodes at a specific location in the document. */ - removeNodes( + removeNodes( editor: Editor, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' hanging?: boolean voids?: boolean @@ -542,12 +543,12 @@ export const NodeTransforms: NodeTransforms = { * Set new properties on the nodes at a location. */ - setNodes( + setNodes( editor: Editor, props: Partial, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' hanging?: boolean split?: boolean @@ -641,11 +642,11 @@ export const NodeTransforms: NodeTransforms = { * Split the nodes at a specific location. */ - splitNodes( + splitNodes( editor: Editor, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'highest' | 'lowest' always?: boolean height?: number @@ -766,12 +767,12 @@ export const NodeTransforms: NodeTransforms = { * Unset properties on the nodes at a location. */ - unsetNodes( + unsetNodes( editor: Editor, props: string | string[], options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' split?: boolean voids?: boolean @@ -795,11 +796,11 @@ export const NodeTransforms: NodeTransforms = { * necessary to ensure that only the content in the range is unwrapped. */ - unwrapNodes( + unwrapNodes( editor: Editor, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' split?: boolean voids?: boolean @@ -854,12 +855,12 @@ export const NodeTransforms: NodeTransforms = { * of the range first to ensure that only the content in the range is wrapped. */ - wrapNodes( + wrapNodes( editor: Editor, element: Element, options: { at?: Location - match?: (node: Node) => boolean + match?: NodeMatch mode?: 'all' | 'highest' | 'lowest' split?: boolean voids?: boolean