Skip to content

Core API

The core package provides tree operations and framework-agnostic utilities.

createNode(type: string, props: Record<string, any>): Node

Create a new BetterTUI node.

appendChild(parent: Node, child: Node): void

Add a child node.

removeChild(parent: Node, child: Node): void

Remove a child node.

insertBefore(parent: Node, newChild: Node, referenceChild: Node): void

Insert a child before a reference node.

commitUpdate(node: Node, updates: Record<string, any>): void

Apply property updates to a node.

interface Node {
id: string;
type: string;
props: Record<string, any>;
children: Node[];
parent: Node | null;
}
interface RenderCommand {
type: 'create' | 'update' | 'delete';
nodeId: string;
props?: Record<string, any>;
}
diffTree(oldTree: Node, newTree: Node): RenderCommand[]

Compute the diff between two trees.

flattenTree(root: Node): Node[]

Flatten a tree into a list.

findNode(root: Node, predicate: (node: Node) => boolean): Node | null

Find a node by predicate.