Path

API reference for paths in Slate.

A Path is 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.

type Path = number[];

PathApi

operationCanTransformPath

Check if an operation can affect paths (used as an optimization for dirty-path updates during normalization).

Parameters

Collapse all

    The operation to check.

Returnsboolean

    true if the operation is an insert, merge, move, remove, or split operation.

transform

Transform a path by an operation.

Parameters

Collapse all

    The path to transform.

    The operation to apply.

    Options for transforming a path.

OptionsPathTransformOptions

Collapse all

    The affinity of the transform.

ReturnsPath | null

    The transformed path, or null if the path was deleted.

ancestors

Get a list of ancestor paths for a given path.

Parameters

Collapse all

    The path to get ancestors for.

    Options for ancestor retrieval.

OptionsPathAncestorsOptions

Collapse all

    If true, returns paths in reverse (deepest to shallowest).

ReturnsPath[]

    An array of paths sorted from shallowest to deepest ancestor (unless reversed).

child

Get a path to a child at the given index.

Parameters

Collapse all

    The parent path.

    The child index.

ReturnsPath

    The path to the child node.

common

Get the common ancestor path of two paths.

Parameters

Collapse all

    The first path.

    The second path.

ReturnsPath

    The common ancestor path.

compare

Compare a path to another, returning an integer indicating whether the path was before, at, or after the other.

Parameters

Collapse all

    The first path to compare.

    The second path to compare.

Returns-1 | 0 | 1

    -1 if before, 0 if at the same location, 1 if after.

endsAfter

Check if a path ends after one of the indexes in another.

Parameters

Collapse all

    The path to check.

    The path to compare against.

Returnsboolean

    true if path ends after another.

endsAt

Check if a path ends at one of the indexes in another.

Parameters

Collapse all

    The path to check.

    The path to compare against.

Returnsboolean

    true if path ends at the same index as another.

endsBefore

Check if a path ends before one of the indexes in another.

Parameters

Collapse all

    The path to check.

    The path to compare against.

Returnsboolean

    true if path ends before another.

equals

Check if a path is exactly equal to another.

Parameters

Collapse all

    The first path.

    The second path.

Returnsboolean

    true if the paths are exactly equal.

firstChild

Get a path to the first child of a path.

Parameters

Collapse all

    The parent path.

ReturnsPath

    The path to the first child node.

hasPrevious

Check if the path of a previous sibling node exists.

Parameters

Collapse all

    The path to check.

Returnsboolean

    true if a previous sibling exists.

isAfter

Check if a path is after another.

Parameters

Collapse all

    The path to check.

    The path to compare against.

Returnsboolean

    true if the first path is after the second.

isAncestor

Check if a path is an ancestor of another.

Parameters

Collapse all

    The potential ancestor path.

    The potential descendant path.

Returnsboolean

    true if path is an ancestor of another.

isBefore

Check if a path is before another.

Parameters

Collapse all

    The path to check.

    The path to compare against.

Returnsboolean

    true if the first path is before the second.

isChild

Check if a path is a child of another.

Parameters

Collapse all

    The potential child path.

    The potential parent path.

Returnsboolean

    true if path is a child of another.

isCommon

Check if a path is equal to or an ancestor of another.

Parameters

Collapse all

    The path to check.

    The path to compare against.

Returnsboolean

    true if path is equal to or an ancestor of another.

isDescendant

Check if a path is a descendant of another.

Parameters

Collapse all

    The potential descendant path.

    The potential ancestor path.

Returnsboolean

    true if path is a descendant of another.

isParent

Check if a path is the parent of another.

Parameters

Collapse all

    The potential parent path.

    The potential child path.

Returnsboolean

    true if path is the parent of another.

isPath

Check if a value implements the Path interface.

Parameters

Collapse all

    The value to check.

Returnsboolean

    true if the value is a path.

isSibling

Check if a path is a sibling of another.

Parameters

Collapse all

    The path to check.

    The path to compare against.

Returnsboolean

    true if the paths share the same parent.

lastIndex

Get the last index of a path.

Parameters

Collapse all

    The path to check.

Returnsnumber

    The last index, or -1 if the path is empty.

levels

Get a list of paths at every level down to a path.

Parameters

Collapse all

    The path to get levels for.

    Options for levels retrieval.

OptionsPathLevelsOptions

Collapse all

    If true, returns paths in reverse (deepest to shallowest).

ReturnsPath[]

    An array of paths including the path itself and all its ancestors.

next

Get the path to the next sibling node.

Parameters

Collapse all

    The current path.

ReturnsPath

    The path to the next sibling.

parent

Get the path to the parent node.

Parameters

Collapse all

    The current path.

ReturnsPath

    The path to the parent node.

previous

Get the path to the previous sibling node.

Parameters

Collapse all

    The current path.

ReturnsPath | undefined

    The path to the previous sibling, or undefined if there is none.

relative

Get a path relative to an ancestor.

Parameters

Collapse all

    The path to make relative.

    The ancestor path.

ReturnsPath

    The relative path.

Types

Path

An array of numbers representing the indexes to traverse to reach a specific node in the document tree.