UNPKG

react-native-tree-multi-select

Version:

Super-fast, customizable tree view component for React Native with drag-and-drop reordering, multi-selection, and search filtering.

45 lines 2.29 kB
import type { TreeNode } from "../types/treeView.types"; import type { DropPosition } from "../types/dragDrop.types"; /** * Move a node within a tree structure. Returns a new tree (no mutation). * * @param data - The current tree data * @param draggedNodeId - The ID of the node to move * @param targetNodeId - The ID of the target node * @param position - Where to place relative to target: "above", "below", or "inside" * @returns New tree data with the node moved, or the original data if the move is invalid */ export declare function moveTreeNode<ID>(data: TreeNode<ID>[], draggedNodeId: ID, targetNodeId: ID, position: DropPosition): TreeNode<ID>[]; /** * Commit the result of a `moveTreeNode` to the store: swap in the new tree, * rebuild the node maps, recalculate parent checked/indeterminate states, and * expand whatever is needed to make the moved node visible ("inside" drops * expand the target; ancestors of the moved node are always expanded). * * Shared by the interactive drag commit (useDragDrop.handleDragEnd) and the * programmatic `TreeViewRef.moveNode` so the two paths cannot drift. */ export declare function applyMoveToStore<ID>(storeId: string, newData: TreeNode<ID>[], movedNodeId: ID, targetNodeId: ID, position: DropPosition): void; /** * Locate a node within a tree, returning its parent id (null at root) and its * index within that parent's children (or the root array). Returns null if the * node is not found. Iterative (stack-based) DFS. * * Used to build the lightweight `MoveResult` delta (previous/new parent + index) * without exposing a full tree copy. */ export declare function findNodePosition<ID>(data: TreeNode<ID>[], nodeId: ID): { parentId: ID | null; index: number; } | null; /** * `findNodePosition` for a node that is still in the store's CURRENT tree: * uses the already-built childToParentMap/nodeMap for O(depth + siblings) * instead of a full-tree DFS. Only valid while the maps match `data` (i.e. * before the move mutates the tree). */ export declare function findNodePositionFromMaps<ID>(data: TreeNode<ID>[], nodeMap: Map<ID, TreeNode<ID>>, childToParentMap: Map<ID, ID>, nodeId: ID): { parentId: ID | null; index: number; } | null; //# sourceMappingURL=moveTreeNode.helper.d.ts.map