react-native-tree-multi-select
Version:
A super-fast, customizable tree view component for React Native with multi-selection, checkboxes, and search filtering capabilities.
81 lines (80 loc) • 2.35 kB
JavaScript
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
}
}),
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
}
})
}));
typedStore().set(id, store);
}
return typedStore().get(id);
}
export function useTreeViewStore(id) {
return getTreeViewStore(id);
}
//# sourceMappingURL=treeView.store.js.map
;