Tree Nodes
A SharedTree's data is organized into a tree of nodes. See node types for details on the available node types.
Node Utilities
The Tree singleton provides utilities for inspecting and navigating nodes — methods that can't live on TreeNode directly due to the risk of name collisions with object-node fields.
The following covers commonly used ones; see the API documentation for the full list.
-
Tree.parent— Returns the parent node. Useful when you need to act on a node's container rather than the node itself — for example, to remove it:const parent = Tree.parent(note);
if (Tree.is(parent, Notes) || Tree.is(parent, Items)) {
const index = parent.indexOf(note);
parent.removeAt(index);
} -
Tree.contains— Returns whether a node is a descendant of another — for example, to confirm a node belongs to a particular section, or to guard against creating a cycle when moving a node. -
Tree.status— Returns theTreeStatusof a node. Many editing operations require a specific status.New— created but not yet inserted into the treeInDocument— parented under the root fieldRemoved— not under the root field, but can be added backDeleted— removed and cannot be added back
-
Tree.schema— Returns theTreeNodeSchemafor a node; useful when the node's type isn't statically known. -
Tree.shortId— Returns the identifier for a node defined with aSchemaFactory.identifierfield — useful for cross-referencing nodes by stable ID rather than position. -
Tree.on— Subscribes to change events on a node. See Events for details. -
Tree.is— Narrows a node's type to a specificSchemaFactory-derived class. Use when the node's type is unknown:if (Tree.is(myNode, Note)) {
// myNode is typed as Note here
}