export type TreeItemKey = string | number; export interface TreeStateOptions { /** Items in the tree (controlled) */ items?: T[]; /** Default items in the tree (uncontrolled) */ defaultItems?: T[]; /** The currently selected keys in the tree (controlled). */ selectedKeys?: V[]; /** The default selected keys in the tree (uncontrolled). */ defaultSelectedKeys?: V[]; /** Handler that is called when the selection changes. */ onSelectedKeysChange?: (selection: V[]) => void; /** A function that returns a unique key for an item object. */ getKey: (item: T) => V; /** A function that returns the children for an item object. */ getChildren: (item: T) => T[]; } export interface TreeNode { /** A unique key for the tree node. */ key: V; /** The key of the parent node. */ parentKey?: V | null; /** The value object for the tree node. */ value: T; /** Children of the tree node. */ children: TreeNode[] | null; } export interface TreeState { /** The root nodes in the tree. */ nodes: TreeNode[]; /** The keys of the currently selected items in the tree. */ selectedKeys: V[]; /** Sets the selected keys. */ setSelectedKeys(selection: V[]): void; /** Gets a node from the tree by key. */ getItem(key: V): TreeNode | undefined; /** Gets the position of a node in the tree. */ getPosition(key: V): { parentKey: V | null; index: number; } | undefined; /** Appends items as children of a parent node. */ append(parentKey: V | null, items: T[]): TreeDataState; /** Replaces the children of a parent node with a new subtree. */ replace(parentKey: V | null, items: T[]): TreeDataState; /** Removes an item from the tree by its key. */ remove(...keys: V[]): TreeDataState | undefined; /** Moves an item within the tree. */ move(key: V, toParentKey: V | null, index: number): TreeDataState; /** Moves one or more items before a given key. */ moveBefore(key: V, keys: V[]): TreeDataState; /** Moves one or more items after a given key. */ moveAfter(key: V, keys: V[]): TreeDataState; /** Synchronizes the tree to the current items. */ externalSync(): TreeDataState; } export interface TreeDataState { nodes: TreeNode[]; nodeMap: Map>; } /** * Manages state for an immutable tree data structure, and provides convenience methods to update the data over time. */ export declare function useTreeState({ items: itemsProp, defaultItems: initialItemsProp, selectedKeys: selectedKeysProp, defaultSelectedKeys: defaultSelectedKeysProp, getKey, getChildren, onSelectedKeysChange: onChange, }: TreeStateOptions): TreeState; export declare const collectKeys: (nodes: TreeNode[]) => V[];