/** * Tree node visibility states. */ declare const States: { readonly unselected: 0; readonly selected: 1; readonly mixed: 2; readonly disabled: 3; }; type StateValue = (typeof States)[keyof typeof States]; /** Icon index: 0 for shapes, 1 for edges */ type IconIndex = 0 | 1; /** * Represents a node in the tree structure. */ interface TreeNode { name: string; state: [StateValue, StateValue]; path: string; rendered: boolean; level: number; children?: Record; expanded?: boolean; } /** * Raw tree data input format. */ interface TreeData { [key: string]: [StateValue, StateValue] | TreeData; } /** * Options for configuring a TreeModel instance. */ interface TreeModelOptions { linkIcons?: boolean; onStateChange?: ((node: TreeNode, iconNumber: IconIndex) => void) | null; } /** * Manages tree data structure, traversal, and state for the TreeView. * Separates data/logic concerns from DOM rendering. */ declare class TreeModel { linkIcons: boolean; onStateChange: ((node: TreeNode, iconNumber: IconIndex) => void) | null; maxLevel: number; root: TreeNode | null; /** * Create a TreeModel instance. * @param treeData - The raw tree structure data. * @param options - Configuration options. */ constructor(treeData: TreeData, options?: TreeModelOptions); /** * Builds the internal tree structure from raw data. * @param data - Raw tree data. * @returns The root node of the built tree. */ private _buildTreeStructure; /** * Traverse the tree and call a callback for each node. * @param node - Starting node (usually root). * @param callback - Function to call for each node. */ traverse(node: TreeNode, callback: (node: TreeNode) => void): void; /** * Check if a node is a leaf (has no children). * @param node - The node to check. * @returns True if the node is a leaf. */ isLeaf(node: TreeNode): boolean; /** * Get the full path of a node (with leading slash). * @param node - The node. * @returns The full path (e.g., "/root/child"). */ getNodePath(node: TreeNode | null): string; /** * Find a node by its path. * @param path - Path string or array of path parts. * @returns The found node or null. */ findNodeByPath(path: string | string[]): TreeNode | null; /** * Get the parent node of a given node. * @param node - The child node. * @returns The parent node or null if node is root. */ getParent(node: TreeNode): TreeNode | null; /** * Get the state of a node by path. * @param path - The node path. * @returns The state array [icon0State, icon1State] or null. */ getState(path: string): [StateValue, StateValue] | null; /** * Get all leaf node states. * @returns Map of path -> state array. */ getStates(): Record; /** * Set the state of a node by path. * @param path - The node path. * @param state - The new state [icon0State, icon1State]. */ setState(path: string, state: [StateValue, StateValue]): void; /** * Set multiple node states at once. * @param states - Map of path -> state array. */ setStates(states: Record): void; /** * Toggle the state of a node's icon. * @param node - The node to toggle. * @param iconNumber - Which icon (0 or 1). * @param force - Force to specific state (true=selected, false=unselected, null=toggle). * @returns True if state was changed. */ toggleNodeState(node: TreeNode, iconNumber: IconIndex, force?: boolean | null): boolean; /** * Update parent states based on children states. * @param node - The node whose parents should be updated. * @param iconNumber - Which icon to update. */ private _updateParentStates; /** * Update children states to match parent state. * @param node - The parent node. * @param iconNumber - Which icon to update. */ private _updateChildrenStates; /** * Hide all nodes (set state to unselected). */ hideAll(): void; /** * Show all nodes (set state to selected). */ showAll(): void; /** * Show a specific node by path. * @param path - The node path. */ show(path: string): void; /** * Hide a specific node by path. * @param path - The node path. */ hide(path: string): void; /** * Set expanded state for all nodes up to a certain level. * @param level - The level to expand to (-1 for smart expand). */ setExpandedLevel(level: number): void; /** * Expand all nodes along a path. * @param path - The path to expand to. * @returns The final node in the path, or null if not found. */ expandPath(path: string): TreeNode | null; /** * Collapse a node by path. * @param path - The path to collapse. * @returns The collapsed node, or null if not found. */ collapsePath(path: string): TreeNode | null; /** * Dispose of resources. */ dispose(): void; } export { TreeModel, States }; export type { TreeNode, TreeData, StateValue, IconIndex };