--- title: Tree Nodes sidebar_position: 1 --- import { ApiLink, PackageLink } from "@site/src/components/shortLinks"; A [SharedTree](./index.mdx)'s data is organized into a tree of nodes. See [node types](./node-types.mdx) 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: ```typescript 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 the of a node. Many editing operations require a specific status. - `New` — created but not yet inserted into the tree - `InDocument` — parented under the root field - `Removed` — not under the root field, but can be added back - `Deleted` — removed and cannot be added back - `Tree.schema` — Returns the for a node; useful when the node's type isn't statically known. - `Tree.shortId` — Returns the identifier for a node defined with a `SchemaFactory.identifier` field — useful for cross-referencing nodes by stable ID rather than position. - `Tree.on` — Subscribes to change events on a node. See [Events](./events.mdx) for details. - `Tree.is` — Narrows a node's type to a specific -derived class. Use when the node's type is unknown: ```typescript if (Tree.is(myNode, Note)) { // myNode is typed as Note here } ```