Path API
16 min
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 type path = number\[] static methods docid\ srvjhmht4fihlhwgdbeihretrieval methods docid\ srvjhmht4fihlhwgdbeihcheck methods docid\ srvjhmht4fihlhwgdbeihtransform method docid\ srvjhmht4fihlhwgdbeih static methods retrieval methods path ancestors(path path, options { reverse? boolean } = {}) => path\[] get a list of ancestor paths for a given path the paths are sorted from deepest to shallowest ancestor however, if the reverse true option is passed, they are reversed path common(path path, another path) => path get the common ancestor path of two paths path compare(path path, another path) => 1 | 0 | 1 compare a path to another, returning an integer indicating whether the path was before, at, or after the other note two paths of unequal length can still receive a 0 result if one is directly above or below the other if you want exact matching, use \[\[path equals]] instead path levels(path path, options?) => path\[] get a list of paths at every level down to a path note this is the same as path ancestors , but includes the path itself the paths are sorted from shallowest to deepest however, if the reverse true option is passed, they are reversed options {reverse? boolean} path next(path path) => path given a path, gets the path to the next sibling node the method does not ensure that the returned path is valid in the document path parent(path path) => path given a path, return a new path referring to the parent node above it if the path argument is equal to \[] , throws an error path previous(path path) => path given a path, get the path to the previous sibling node the method will throw an error if there are no previous siblings (e g if the path is currently \[1, 0] , the previous path would be \[1, 1] which is illegal and will throw an error) path relative(path path, ancestor path) => path given two paths, one that is an ancestor to the other, returns the relative path from the ancestor argument to the path argument if the ancestor path is not actually an ancestor or equal to the path argument, throws an error check methods check some attribute of a path always returns a boolean path endsafter(path path, another path) => boolean check if a path ends after one of the indexes in another path endsat(path path, another path) => boolean check if a path ends at one of the indexes in another path endsbefore(path path, another path) => boolean check if a path ends before one of the indexes in another path equals(path path, another path) => boolean check if a path is exactly equal to another path hasprevious(path path) => boolean check if the path of previous sibling node exists path isafter(path path, another path) => boolean check if a path is after another path isancestor(path path, another path) => boolean check if a path is an ancestor of another path isbefore(path path, another path) => boolean check if a path is before another path ischild(path path, another path) => boolean check if a path is a child of another path iscommon(path path, another path) => boolean check if a path is equal to or an ancestor of another path isdescendant(path path, another path) => boolean check if a path is a descendant of another path isparent(path path, another path) => boolean check if a path is the parent of another path ispath(value any) => value is path check is a value implements the path interface path issibling(path path, another path) => boolean check if a path is a sibling of another transform method path transform(path path, operation operation, options?) => path | null transform a path by an operation options { affinity? 'forward' | 'backward' | null }