Core API
The core package provides tree operations and framework-agnostic utilities.
Tree Operations
Section titled “Tree Operations”createNode
Section titled “createNode”createNode(type: string, props: Record<string, any>): NodeCreate a new BetterTUI node.
appendChild
Section titled “appendChild”appendChild(parent: Node, child: Node): voidAdd a child node.
removeChild
Section titled “removeChild”removeChild(parent: Node, child: Node): voidRemove a child node.
insertBefore
Section titled “insertBefore”insertBefore(parent: Node, newChild: Node, referenceChild: Node): voidInsert a child before a reference node.
commitUpdate
Section titled “commitUpdate”commitUpdate(node: Node, updates: Record<string, any>): voidApply property updates to a node.
interface Node { id: string; type: string; props: Record<string, any>; children: Node[]; parent: Node | null;}RenderCommand
Section titled “RenderCommand”interface RenderCommand { type: 'create' | 'update' | 'delete'; nodeId: string; props?: Record<string, any>;}Utilities
Section titled “Utilities”diffTree
Section titled “diffTree”diffTree(oldTree: Node, newTree: Node): RenderCommand[]Compute the diff between two trees.
flattenTree
Section titled “flattenTree”flattenTree(root: Node): Node[]Flatten a tree into a list.
findNode
Section titled “findNode”findNode(root: Node, predicate: (node: Node) => boolean): Node | nullFind a node by predicate.