import type { TreeNode, TreeChangeEvent, TreeValidationResult } from '../Tree.types'; import { type NodeState } from '../utils/treeOperations'; /** * Hook configuration options. * Internal to the Tree component — NOT exported from index.ts. */ export interface TreeOptions { /** Intercept check/uncheck — return false to cancel */ beforeCheck?: (node: TreeNode, nextChecked: boolean) => boolean; /** Callback after every successful state change */ onChange?: (event: TreeChangeEvent) => void; /** Default expand state for all branches */ defaultExpanded?: boolean; /** Specific node IDs to expand initially */ expandedIds?: string[]; /** Read-only mode — disables all toggle operations */ readOnly?: boolean; } /** * Return type of the useTree hook. * Internal to the Tree component — NOT exported from index.ts. */ export interface UseTreeReturn { /** Visible nodes array for rendering (respects expand/collapse) */ nodes: NodeState[]; /** Currently expanded branch IDs */ expandedIds: Set; /** Toggle a node's checked state with cascade + propagation */ toggle: (nodeId: string) => void; /** Expand a branch node */ expand: (nodeId: string) => void; /** Collapse a branch node */ collapse: (nodeId: string) => void; /** Expand all branch nodes */ expandAll: () => void; /** Collapse all branch nodes */ collapseAll: () => void; /** All nodes with current state (flat TreeNode[]) */ getAll: () => TreeNode[]; /** Only checked nodes (flat TreeNode[]) */ getChecked: () => TreeNode[]; /** Only disabled nodes (flat TreeNode[]) */ getDisabled: () => TreeNode[]; /** Nodes changed since initial mount (flat TreeNode[]) */ getModified: () => TreeNode[]; /** Run validation over all nodes */ validate: (fn: (node: TreeNode) => boolean) => TreeValidationResult; /** Ordered list of visible nodes as TreeNode[] (memoized) */ visibleNodes: TreeNode[]; /** Currently focused node ID for keyboard navigation */ focusedId: string | null; /** Set the focused node ID */ setFocusedId: (id: string) => void; } /** * Core hook for tree state management. * * Manages the "write path" of the tree: initializing state from nodes, * toggling checked states with cascade/propagation, respecting beforeCheck * validation, firing onChange, and managing expand/collapse state. * * All tree algorithms are delegated to `treeOperations.ts` pure functions. * This hook MUST NOT implement cascade/propagation logic directly. * * @param initialNodes - Array of root TreeNode objects * @param options - Optional configuration (beforeCheck, onChange, defaultExpanded, expandedIds, readOnly) * @returns UseTreeReturn with reactive state and action methods */ export declare function useTree(initialNodes: TreeNode[], options?: TreeOptions): UseTreeReturn; //# sourceMappingURL=useTree.d.ts.map