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.

112 lines (110 loc) 3.37 kB
"use strict"; import { create } from "zustand"; // Map to store individual tree view stores by id const treeViewStores = new Map(); // a function that returns a strongly typed version of `treeViewStores` const typedStore = () => treeViewStores; export function getTreeViewStore(id) { if (!typedStore().has(id)) { const store = create(set => ({ checked: new Set(), updateChecked: checked => set({ checked }), indeterminate: new Set(), updateIndeterminate: indeterminate => set({ indeterminate }), expanded: new Set(), updateExpanded: expanded => set({ expanded }), initialTreeViewData: [], updateInitialTreeViewData: initialTreeViewData => set({ initialTreeViewData }), nodeMap: new Map(), updateNodeMap: nodeMap => set({ nodeMap }), childToParentMap: new Map(), updateChildToParentMap: childToParentMap => set({ childToParentMap }), searchText: "", updateSearchText: searchText => set({ searchText }), searchKeys: [""], updateSearchKeys: searchKeys => set({ searchKeys }), innerMostChildrenIds: [], updateInnerMostChildrenIds: innerMostChildrenIds => set({ innerMostChildrenIds }), selectionPropagation: { toChildren: true, toParents: true }, setSelectionPropagation: selectionPropagation => set({ selectionPropagation: { // Default selection propagation for parent and children to true if not specified toChildren: selectionPropagation.toChildren ?? true, toParents: selectionPropagation.toParents ?? true } }), draggedNodeId: null, updateDraggedNodeId: draggedNodeId => set({ draggedNodeId }), invalidDragTargetIds: new Set(), updateInvalidDragTargetIds: invalidDragTargetIds => set({ invalidDragTargetIds }), dropTargetNodeId: null, dropPosition: null, dropLevel: null, updateDropTarget: (nodeId, position, level) => set({ dropTargetNodeId: nodeId, dropPosition: position, dropLevel: level ?? null }), cleanUpTreeViewStore: () => set({ checked: new Set(), indeterminate: new Set(), expanded: new Set(), initialTreeViewData: [], nodeMap: new Map(), childToParentMap: new Map(), searchText: "", searchKeys: [""], innerMostChildrenIds: [], selectionPropagation: { toChildren: true, toParents: true }, draggedNodeId: null, invalidDragTargetIds: new Set(), dropTargetNodeId: null, dropPosition: null, dropLevel: null }) })); typedStore().set(id, store); } return typedStore().get(id); } export function deleteTreeViewStore(id) { treeViewStores.delete(id); } /** * Returns the per-instance bound Zustand store for the given id. The returned * store is itself callable as a hook with a selector - e.g. * `useTreeViewStore(id)(useShallow(state => ...))` - which is why it keeps the * `use` prefix. Internal helper; not part of the public API. */ export function useTreeViewStore(id) { return getTreeViewStore(id); } //# sourceMappingURL=treeView.store.js.map