Path
API reference for paths in Slate.
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 Editor
object, they can be relative to any Node
object.
Path
Find the corresponding documentation in the Slate docs.
operationCanTransformPath
Returns whether an operation can affect paths or not. Used as an optimization when updating dirty paths during normalization.
Parameters
The operation to check.
Returns
Returns true
if the operation can transform paths (insert, merge, move, remove, or split operations).
transform
Transforms a path by an operation.
Parameters
The path to transform.
The operation to apply.
Returns
Returns the transformed path, or null
if the path was deleted.
ancestors
Gets a list of ancestor paths for a given path.
Parameters
The path to get ancestors for.
Returns
Returns an array of paths sorted from shallowest to deepest ancestor (unless reversed).
child
Gets a path to a child at the given index.
Parameters
The parent path.
The child index.
Returns
Returns the path to the child node.
common
Gets the common ancestor path of two paths.
Parameters
The first path.
The second path.
Returns
Returns the common ancestor path.
compare
Compares a path to another, returning an integer indicating whether the path was before, at, or after the other.
Parameters
The first path to compare.
The second path to compare.
Returns
-1
if the first path is before the second0
if the paths are at the same location1
if the first path is after the second
Returns:
Note: Two paths of unequal length can still receive a 0
result if one is directly above or below the other. For exact matching, use equals
instead.
endsAfter
Checks if a path ends after one of the indexes in another.
Parameters
The path to check.
The path to compare against.
Returns
Returns true
if the path ends after the other path.
endsAt
Checks if a path ends at one of the indexes in another.
Parameters
The path to check.
The path to compare against.
Returns
Returns true
if the path ends at the same index as the other path.
endsBefore
Checks if a path ends before one of the indexes in another.
Parameters
The path to check.
The path to compare against.
Returns
Returns true
if the path ends before the other path.
equals
Checks if a path is exactly equal to another.
Parameters
The first path.
The second path.
Returns
Returns true
if the paths are exactly equal.
firstChild
Gets a path to the first child of a path.
Parameters
The parent path.
Returns
Returns the path to the first child node.
hasPrevious
Checks if the path of previous sibling node exists.
Parameters
The path to check.
Returns
Returns true
if a previous sibling exists.
isAfter
Checks if a path is after another.
Parameters
The path to check.
The path to compare against.
Returns
Returns true
if the first path is after the second.
isAncestor
Checks if a path is an ancestor of another.
Parameters
The potential ancestor path.
The potential descendant path.
Returns
Returns true
if the path is an ancestor of the other path.
isBefore
Checks if a path is before another.
Parameters
The path to check.
The path to compare against.
Returns
Returns true
if the first path is before the second.
isChild
Checks if a path is a child of another.
Parameters
The potential child path.
The potential parent path.
Returns
Returns true
if the path is a child of the other path.
isCommon
Checks if a path is equal to or an ancestor of another.
Parameters
The path to check.
The path to compare against.
Returns
Returns true
if the path is equal to or an ancestor of the other path.
isDescendant
Checks if a path is a descendant of another.
Parameters
The potential descendant path.
The potential ancestor path.
Returns
Returns true
if the path is a descendant of the other path.
isParent
Checks if a path is the parent of another.
Parameters
The potential parent path.
The potential child path.
Returns
Returns true
if the path is the parent of the other path.
isPath
Checks if a value implements the Path
interface.
Parameters
The value to check.
Returns
Returns true
if the value is a path.
isSibling
Checks if a path is a sibling of another.
Parameters
The path to check.
The path to compare against.
Returns
Returns true
if the paths are siblings.
lastIndex
Gets the last index of a path.
Parameters
The path to check.
Returns
Returns the last index, or -1 if the path is empty.
levels
Gets a list of paths at every level down to a path.
Parameters
The path to get levels for.
Returns
Returns an array of paths including the path itself and all its ancestors.
next
Gets the path to the next sibling node.
Parameters
The current path.
Returns
Returns the path to the next sibling.
parent
Gets the path to the parent node.
Parameters
The current path.
Returns
Returns the path to the parent node.
previous
Gets the path to the previous sibling node.
Parameters
The current path.
Returns
Returns the path to the previous sibling, or undefined
if there is none.
relative
Gets a path relative to an ancestor.
Parameters
The path to make relative.
The ancestor path.
Returns
Returns the relative path.
Types
Path
An array of numbers representing the indexes to traverse to reach a specific node in the document tree.
PathAncestorsOptions
Options for getting ancestor paths.
Attributes
If true, the paths are returned in reverse order.
PathLevelsOptions
Options for getting path levels.
Attributes
If true, the paths are returned in reverse order.
PathTransformOptions
Options for transforming paths.
Attributes
The affinity of the transform.