mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-07-31 12:30:11 +02:00
Adds path parameter to NodeMatch (#4054)
* Add path to NodeMatch function.
This commit is contained in:
committed by
GitHub
parent
0513539ed7
commit
2bba0e68c6
@@ -699,7 +699,7 @@ export const Editor: EditorInterface = {
|
|||||||
const path = Editor.path(editor, at)
|
const path = Editor.path(editor, at)
|
||||||
|
|
||||||
for (const [n, p] of Node.levels(editor, path)) {
|
for (const [n, p] of Node.levels(editor, path)) {
|
||||||
if (!match(n)) {
|
if (!match(n, p)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,7 +893,7 @@ export const Editor: EditorInterface = {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!match(node)) {
|
if (!match(node, path)) {
|
||||||
// If we've arrived at a leaf text node that is not lower than the last
|
// 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
|
// hit, then we've found a branch that doesn't include a match, which
|
||||||
// means the match is not universal.
|
// means the match is not universal.
|
||||||
@@ -1575,6 +1575,6 @@ export const Editor: EditorInterface = {
|
|||||||
* A helper type for narrowing matched nodes with a predicate.
|
* A helper type for narrowing matched nodes with a predicate.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type NodeMatch<T extends Node> =
|
export type NodeMatch<T extends Node> =
|
||||||
| ((node: Node) => node is T)
|
| ((node: Node, path: Path) => node is T)
|
||||||
| ((node: Node) => boolean)
|
| ((node: Node, path: Path) => boolean)
|
||||||
|
@@ -11,109 +11,110 @@ import {
|
|||||||
NodeEntry,
|
NodeEntry,
|
||||||
Ancestor,
|
Ancestor,
|
||||||
} from '..'
|
} from '..'
|
||||||
|
import { NodeMatch } from '../interfaces/editor'
|
||||||
|
|
||||||
export interface NodeTransforms {
|
export interface NodeTransforms {
|
||||||
insertNodes: (
|
insertNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
nodes: Node | Node[],
|
nodes: Node | Node[],
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
select?: boolean
|
select?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
liftNodes: (
|
liftNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
mergeNodes: (
|
mergeNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
moveNodes: (
|
moveNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
to: Path
|
to: Path
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
removeNodes: (
|
removeNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
setNodes: (
|
setNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
props: Partial<Node>,
|
props: Partial<Node>,
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
splitNodes: (
|
splitNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
always?: boolean
|
always?: boolean
|
||||||
height?: number
|
height?: number
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
unsetNodes: (
|
unsetNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
props: string | string[],
|
props: string | string[],
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
unwrapNodes: (
|
unwrapNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
}
|
}
|
||||||
) => void
|
) => void
|
||||||
wrapNodes: (
|
wrapNodes: <T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
element: Element,
|
element: Element,
|
||||||
options?: {
|
options?: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -126,12 +127,12 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* Insert nodes at a specific location in the Editor.
|
* Insert nodes at a specific location in the Editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
insertNodes(
|
insertNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
nodes: Node | Node[],
|
nodes: Node | Node[],
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
select?: boolean
|
select?: boolean
|
||||||
@@ -244,11 +245,11 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* their parent in two if necessary.
|
* their parent in two if necessary.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
liftNodes(
|
liftNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
@@ -308,11 +309,11 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* removing any empty containing nodes after the merge if necessary.
|
* removing any empty containing nodes after the merge if necessary.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mergeNodes(
|
mergeNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -446,11 +447,11 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* Move the nodes at a location to a new location.
|
* Move the nodes at a location to a new location.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
moveNodes(
|
moveNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
to: Path
|
to: Path
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -496,11 +497,11 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* Remove the nodes at a specific location in the document.
|
* Remove the nodes at a specific location in the document.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
removeNodes(
|
removeNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -542,12 +543,12 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* Set new properties on the nodes at a location.
|
* Set new properties on the nodes at a location.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
setNodes(
|
setNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
props: Partial<Node>,
|
props: Partial<Node>,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
hanging?: boolean
|
hanging?: boolean
|
||||||
split?: boolean
|
split?: boolean
|
||||||
@@ -641,11 +642,11 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* Split the nodes at a specific location.
|
* Split the nodes at a specific location.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
splitNodes(
|
splitNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'highest' | 'lowest'
|
mode?: 'highest' | 'lowest'
|
||||||
always?: boolean
|
always?: boolean
|
||||||
height?: number
|
height?: number
|
||||||
@@ -766,12 +767,12 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* Unset properties on the nodes at a location.
|
* Unset properties on the nodes at a location.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsetNodes(
|
unsetNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
props: string | string[],
|
props: string | string[],
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
@@ -795,11 +796,11 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
* necessary to ensure that only the content in the range is unwrapped.
|
* necessary to ensure that only the content in the range is unwrapped.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unwrapNodes(
|
unwrapNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: 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.
|
* of the range first to ensure that only the content in the range is wrapped.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
wrapNodes(
|
wrapNodes<T extends Node>(
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
element: Element,
|
element: Element,
|
||||||
options: {
|
options: {
|
||||||
at?: Location
|
at?: Location
|
||||||
match?: (node: Node) => boolean
|
match?: NodeMatch<T>
|
||||||
mode?: 'all' | 'highest' | 'lowest'
|
mode?: 'all' | 'highest' | 'lowest'
|
||||||
split?: boolean
|
split?: boolean
|
||||||
voids?: boolean
|
voids?: boolean
|
||||||
|
Reference in New Issue
Block a user