节点是 Plate 文档的基本构建块。它可以是编辑器根节点(最高层级)、Element 节点或 Text 节点(最低层级)。此 API 提供了与节点交互的工具,包括遍历、查询和提取数据。
type TNode = Editor | TElement | TText;
type Descendant = Element | Text
type Ancestor = Editor | Element
NodeAPI
ancestor
获取特定路径的节点,并断言它是祖先节点。
ancestors
返回特定路径上方所有祖先节点的生成器。
child
获取节点在特定索引的子节点。
children
遍历特定路径节点的子节点。
common
获取两个路径公共祖先节点的条目。
descendant
获取特定路径的节点,并断言它是后代节点。
descendants
返回根节点内所有后代节点条目的生成器。
elements
返回根节点内所有 Element 节点的生成器。
first
从路径获取根节点中的第一个节点条目。
firstChild
获取节点的第一个子节点条目。
firstText
获取节点的第一个 Text 节点条目。
fragment
获取根节点内范围所表示的切片片段。
get
获取特定路径引用的后代节点。
last
从路径获取根节点中的最后一个节点条目。
lastChild
获取节点的最后一个子节点条目。
leaf
获取特定路径的节点,并确保它是叶子 Text 节点。
levels
返回树分支中从特定路径开始的节点生成器。
nodes
返回根节点所有节点条目的生成器。
parent
获取特定路径节点的父节点。
texts
返回根节点中所有叶子 Text 节点的生成器。
extractProps
获取节点的属性。
has
检查特定路径是否存在后代节点。
hasSingleChild
检查节点是否只有一个子节点。
isAncestor
检查值是否实现了 Ancestor
接口。
isDescendant
检查值是否实现了 Descendant
接口。
isLastChild
检查节点是否是父节点的最后一个子节点。
isNode
检查值是否实现了 TNode
接口。
isNodeList
检查值是否是 Descendant
对象的列表。
matches
检查节点是否匹配一组属性。
string
获取节点内容的连接文本字符串。
类型
TNode
Node
是 TNode
的类型别名。
type TNode = Editor | TElement | TText;
NodeEntry
NodeEntry
对象在遍历 Plate 文档树中的节点时返回。它们由两个元素的数组组成:TNode
及其相对于文档中根节点的 Path
。
Descendant
Descendant
联合类型表示树中的后代节点。
type Descendant = TElement | TText;
Ancestor
Ancestor
联合类型表示树中的祖先节点。
type Ancestor = Editor | TElement;
NodeOf<N>
NodeIn<V>
TNodeMatch<N>
DescendantOf<N>
DescendantIn<V>
ChildOf<N>
AncestorOf<N>
AncestorIn<V>
AncestorEntry
祖先条目表示一个祖先节点(Editor 或 Element)及其路径。
DescendantEntry
后代条目表示一个后代节点(Element 或 Text)及其路径。
NodeChildEntry
节点子条目表示一个子节点及其相对于父节点的路径。
On This Page
NodeAPI
ancestor
ancestors
child
children
common
descendant
descendants
elements
first
firstChild
firstText
fragment
get
last
lastChild
leaf
levels
nodes
parent
texts
extractProps
has
hasSingleChild
isAncestor
isDescendant
isLastChild
isNode
isNodeList
matches
string
类型TNode
NodeEntry
Descendant
Ancestor
NodeOf<N>
NodeIn<V>
TNodeMatch<N>
DescendantOf<N>
DescendantIn<V>
ChildOf<N>
AncestorOf<N>
AncestorIn<V>
AncestorEntry
DescendantEntry
NodeChildEntry