Node
API reference for nodes in Slate.
The Node
union type represents all of the different types of nodes that occur in a Slate document tree. This includes Editors, Elements, and Text nodes.
Node
Find the corresponding documentation in the Slate docs.
ancestor
Gets the node at a specific path, asserting that it's an ancestor node.
Parameters
The root node to start from.
The path to the ancestor node.
Returns
Returns the ancestor node if found, undefined
otherwise.
ancestors
Returns a generator of all the ancestor nodes above a specific path.
Parameters
The root node to start from.
The path to get ancestors for.
Returns
Returns a generator of [Node, Path]
tuples.
child
Gets the child of a node at a specific index.
Parameters
The parent node.
The index of the child.
Returns
Returns the child node if found, undefined
otherwise.
children
Iterates over the children of a node at a specific path.
Parameters
The root node.
The path to the parent node.
Returns
Returns a generator of [Node, Path]
tuples.
common
Gets an entry for the common ancestor node of two paths.
Parameters
The root node.
First path.
Second path.
Returns
Returns the common ancestor entry if found, undefined
otherwise.
descendant
Gets the node at a specific path, asserting that it's a descendant node.
Parameters
The root node.
The path to the descendant.
Returns
Returns the descendant node if found, undefined
otherwise.
descendants
Returns a generator of all the descendant node entries inside a root node.
Parameters
The root node.
Returns
Returns a generator of [Node, Path]
tuples.
elements
Returns a generator of all the element nodes inside a root node.
Parameters
The root node.
Similar options to descendants
.
Returns
Returns a generator of element entries.
texts
Returns a generator of all leaf text nodes in a root node.
Parameters
The root node.
Similar options to descendants
.
Returns
Returns a generator of text node entries.
matches
Checks if a node matches a set of props.
Parameters
The node to check.
The properties to match against.
Returns
Returns true
if the node matches all properties.
string
Gets the concatenated text string of a node's content.
Parameters
The node to get text from.
Returns
Returns the concatenated text content.
Types
Node
The base node type that can be either an Editor, Element, or Text node.
Descendant
Represents nodes that can be descendants in the tree (Element or Text nodes).
Ancestor
Represents nodes that can be ancestors in the tree (Editor or Element nodes).
NodeProps
Convenience type for returning the props of a node, omitting the children
or text
property.
NodeEntry
A tuple type of [Node, Path]
representing a node and its location in the tree.
Options Interfaces
Attributes
reverse?: boolean
- Reverse traversal orderreverse?: boolean
- Reverse traversal orderfrom?: number
- Start index (inclusive)to?: number
- End index (exclusive)reverse?: boolean
- Reverse traversal orderfrom?: Path
- Starting pathto?: Path
- Ending pathpass?: function
- Filter function