API reference for paths in Plate.

A Path is a list of indexes that describe a node's exact position in a Plate 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

  • operation Operation<N>

    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
  • path Path

    The path to transform.

  • operation Operation

    The operation to apply.

  • options optional PathTransformOptions

    Options for transforming a path.

OptionsPathTransformOptions

Collapse all
  • affinity optional TextDirection | null

    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
  • path Path

    The path to get ancestors for.

  • options optional PathAncestorsOptions

    Options for ancestor retrieval.

OptionsPathAncestorsOptions

Collapse all
  • reverse optional boolean

    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
  • path Path

    The parent path.

  • index number

    The child index.

ReturnsPath

    The path to the child node.

common

Get the common ancestor path of two paths.

Parameters

Collapse all
  • path Path

    The first path.

  • another 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
  • path Path

    The first path to compare.

  • another Path

    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
  • path Path

    The path to check.

  • another Path

    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
  • path Path

    The path to check.

  • another Path

    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
  • path Path

    The path to check.

  • another Path

    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
  • path Path

    The first path.

  • another 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
  • path Path

    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
  • path Path

    The path to check.

Returnsboolean

    true if a previous sibling exists.

isAfter

Check if a path is after another.

Parameters

Collapse all
  • path Path

    The path to check.

  • another Path

    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
  • path Path

    The potential ancestor path.

  • another 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
  • path Path

    The path to check.

  • another Path

    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
  • path Path

    The potential child path.

  • another 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
  • path Path

    The path to check.

  • another Path

    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
  • path Path

    The potential descendant path.

  • another 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
  • path Path

    The potential parent path.

  • another 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
  • value any

    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
  • path Path

    The path to check.

  • another Path

    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
  • path Path

    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
  • path Path

    The path to get levels for.

  • options optional PathLevelsOptions

    Options for levels retrieval.

OptionsPathLevelsOptions

Collapse all
  • reverse optional boolean

    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
  • path Path

    The current path.

ReturnsPath

    The path to the next sibling.

parent

Get the path to the parent node.

Parameters

Collapse all
  • path Path

    The current path.

ReturnsPath

    The path to the parent node.

previous

Get the path to the previous sibling node.

Parameters

Collapse all
  • path Path

    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
  • path Path

    The path to make relative.

  • ancestor Path

    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.