路径(Path)

Plate 中路径的 API 参考。

Path 是一个索引列表,用于描述节点在 Plate 节点树中的确切位置。虽然它们通常是相对于根 Editor 对象的,但也可以相对于任何 Node 对象。

type Path = number[];

PathApi

operationCanTransformPath

检查操作是否会影响路径(在规范化过程中用作脏路径更新的优化)。

Parameters

  • operation Operation<N>

    要检查的操作。

Returnsboolean

    如果操作是插入、合并、移动、删除或拆分操作,则返回 true

transform

通过操作转换路径。

Parameters

Collapse all
  • path Path

    要转换的路径。

  • operation Operation

    要应用的操作。

  • options optional PathTransformOptions

    路径转换的选项。

OptionsPathTransformOptions

Collapse all
  • affinity optional TextDirection | null

    转换的亲和性。

ReturnsPath | null

    转换后的路径,如果路径被删除则返回 null

ancestors

获取给定路径的所有祖先路径列表。

Parameters

Collapse all
  • path Path

    要获取祖先的路径。

  • options optional PathAncestorsOptions

    获取祖先的选项。

OptionsPathAncestorsOptions

Collapse all
  • reverse optional boolean

    如果为 true,则按反向顺序返回路径(从最深到最浅)。

ReturnsPath[]

    从最浅到最深的祖先路径数组(除非反向)。

child

获取指定索引的子节点路径。

Parameters

Collapse all
  • path Path

    父路径。

  • index number

    子节点索引。

ReturnsPath

    子节点的路径。

common

获取两个路径的共同祖先路径。

Parameters

Collapse all
  • path Path

    第一个路径。

  • another Path

    第二个路径。

ReturnsPath

    共同祖先路径。

compare

比较两个路径,返回一个整数表示路径是在另一个之前、相同还是之后。

Parameters

Collapse all
  • path Path

    要比较的第一个路径。

  • another Path

    要比较的第二个路径。

Returns-1 | 0 | 1

    如果在之前返回 -1,相同位置返回 0,之后返回 1

endsAfter

检查路径是否在另一个路径的某个索引之后结束。

Parameters

Collapse all
  • path Path

    要检查的路径。

  • another Path

    要比较的路径。

Returnsboolean

    如果 pathanother 之后结束返回 true

endsAt

检查路径是否在另一个路径的某个索引处结束。

Parameters

Collapse all
  • path Path

    要检查的路径。

  • another Path

    要比较的路径。

Returnsboolean

    如果 pathanother 相同索引处结束返回 true

endsBefore

检查路径是否在另一个路径的某个索引之前结束。

Parameters

Collapse all
  • path Path

    要检查的路径。

  • another Path

    要比较的路径。

Returnsboolean

    如果 pathanother 之前结束返回 true

equals

检查路径是否与另一个完全相等。

Parameters

Collapse all
  • path Path

    第一个路径。

  • another Path

    第二个路径。

Returnsboolean

    如果路径完全相等返回 true

firstChild

获取路径的第一个子节点路径。

Parameters

Collapse all
  • path Path

    父路径。

ReturnsPath

    第一个子节点的路径。

hasPrevious

检查前一个兄弟节点的路径是否存在。

Parameters

Collapse all
  • path Path

    要检查的路径。

Returnsboolean

    如果存在前一个兄弟节点返回 true

isAfter

检查路径是否在另一个之后。

Parameters

Collapse all
  • path Path

    要检查的路径。

  • another Path

    要比较的路径。

Returnsboolean

    如果第一个路径在第二个之后返回 true

isAncestor

检查路径是否是另一个的祖先。

Parameters

Collapse all
  • path Path

    可能的祖先路径。

  • another Path

    可能的子孙路径。

Returnsboolean

    如果 pathanother 的祖先返回 true

isBefore

检查路径是否在另一个之前。

Parameters

Collapse all
  • path Path

    要检查的路径。

  • another Path

    要比较的路径。

Returnsboolean

    如果第一个路径在第二个之前返回 true

isChild

检查路径是否是另一个的子路径。

Parameters

Collapse all
  • path Path

    可能的子路径。

  • another Path

    可能的父路径。

Returnsboolean

    如果 pathanother 的子路径返回 true

isCommon

检查路径是否等于或是另一个的祖先。

Parameters

Collapse all
  • path Path

    要检查的路径。

  • another Path

    要比较的路径。

Returnsboolean

    如果 path 等于或是 another 的祖先返回 true

isDescendant

检查路径是否是另一个的子孙。

Parameters

Collapse all
  • path Path

    可能的子孙路径。

  • another Path

    可能的祖先路径。

Returnsboolean

    如果 pathanother 的子孙返回 true

isParent

检查路径是否是另一个的父路径。

Parameters

Collapse all
  • path Path

    可能的父路径。

  • another Path

    可能的子路径。

Returnsboolean

    如果 pathanother 的父路径返回 true

isPath

检查值是否实现了 Path 接口。

Parameters

Collapse all
  • value any

    要检查的值。

Returnsboolean

    如果值是路径返回 true

isSibling

检查路径是否是另一个的兄弟路径。

Parameters

Collapse all
  • path Path

    要检查的路径。

  • another Path

    要比较的路径。

Returnsboolean

    如果路径共享同一个父路径返回 true

lastIndex

获取路径的最后一个索引。

Parameters

Collapse all
  • path Path

    要检查的路径。

Returnsnumber

    最后一个索引,如果路径为空则返回 -1。

levels

获取从路径到每个级别的路径列表。

Parameters

Collapse all
  • path Path

    要获取级别的路径。

  • options optional PathLevelsOptions

    获取级别的选项。

OptionsPathLevelsOptions

Collapse all
  • reverse optional boolean

    如果为 true,则按反向顺序返回路径(从最深到最浅)。

ReturnsPath[]

    包含路径本身及其所有祖先的路径数组。

next

获取下一个兄弟节点的路径。

Parameters

Collapse all
  • path Path

    当前路径。

ReturnsPath

    下一个兄弟节点的路径。

parent

获取父节点的路径。

Parameters

Collapse all
  • path Path

    当前路径。

ReturnsPath

    父节点的路径。

previous

获取前一个兄弟节点的路径。

Parameters

Collapse all
  • path Path

    当前路径。

ReturnsPath | undefined

    前一个兄弟节点的路径,如果没有则返回 undefined

relative

获取相对于祖先的路径。

Parameters

Collapse all
  • path Path

    要相对化的路径。

  • ancestor Path

    祖先路径。

ReturnsPath

    相对路径。

类型

Path

一个数字数组,表示遍历文档树以到达特定节点的索引。