This page is available as Markdown at /editor/reference/traversal.md. For the full documentation index, see /llms.txt, or the complete corpus at /llms-full.txt.
Traversal API overview
Traversal functions are pure functions that answer questions about the editor’s value tree, given a snapshot and a path. They provide a clean way to navigate and inspect the value tree without directly parsing the snapshot structure.
import * as traversal from '@portabletext/editor/traversal'TraversalSnapshots, paths, and how to find and walk nodes.
Lookups
Section titled “Lookups”Resolve a path to the node that lives there.
getNode- Get the node at a given pathhasNode- Check if a node exists at a given pathgetBlock- Get the node at a given path if it is a blockgetTextBlock- Get the text block node at a given pathgetSpan- Get the span node at a given pathgetAnnotation- Get the annotation at a given pathgetContainer- Get the registered editable container at a given path only, does not walk up to an enclosing containergetText- Get the concatenated text content of the node at a given path
Family walkers
Section titled “Family walkers”Move relative to a path.
getParent- Get the parent of a node at a given pathgetAncestor- Walk up from a path to find an ancestor that matches a predicategetAncestors- Get all ancestors of the node at a given path, from nearest to furthestgetChildren- Get the children of a node at a given pathgetContainerChildren- Resolve a container node’s editable child array (beta)getFirstChild- Get the first child of a node at a given pathgetLastChild- Get the last child of a node at a given pathgetSibling- Get a sibling of the node at a given pathgetEnclosingBlock- Walk up from a path to find the nearest enclosing blockgetLeaf- Walk from a path toward thestartorendedge and get the deepest leaf node reached
Narrowing predicates
Section titled “Narrowing predicates”isBlock- Determine if a node at the given path is a blockisInline- Determine if a node at the given path is inlineisObject- Check if a node is an object node (not a text block or span)isLeafObject- Check if a node is a leaf object: an object node that has no editable children
Path and point utilities
Section titled “Path and point utilities”pathContains- Returns true ifancestoris equal todescendant, or ifdescendantlives anywhere insideancestor’s subtreecomparePoints- Compares two points by document order, resolved at any depthrangeIntersects- Returns true if a range and a target path, point, or selection intersect
Schema resolution
Section titled “Schema resolution”getPathSubSchema- Return theSchemaview that applies at a given path; itsblockObjectsandinlineObjectsfields answer what can exist theregetUnionSchema- Return aSchemathat contains every named member reachable from a position where text is edited