UNPKG

react-native-tree-multi-select

Version:

A super-fast, customizable tree view component for React Native with multi-selection, checkboxes, and search filtering capabilities.

117 lines (107 loc) 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInnerMostChildrenIdsInTree = getInnerMostChildrenIdsInTree; exports.selectAll = selectAll; exports.selectAllFiltered = selectAllFiltered; exports.unselectAll = unselectAll; exports.unselectAllFiltered = unselectAllFiltered; var _treeView = require("../store/treeView.store"); var _toggleCheckbox = require("./toggleCheckbox.helper"); /** * Selects all nodes that are currently visible due to the applied filter. * * If there is no search text, then it selects all nodes; otherwise, it selects all visible nodes. */ function selectAllFiltered(storeId) { const treeViewStore = (0, _treeView.getTreeViewStore)(storeId); const { searchText, innerMostChildrenIds } = treeViewStore.getState(); // If there's no search text, select all nodes if (!searchText) { selectAll(storeId); } else { // If there's search text, only select the visible nodes (0, _toggleCheckbox.toggleCheckboxes)(storeId, innerMostChildrenIds, true); } } ; /** * Unselects all nodes that are currently visible due to the applied filter. * * If there is no search text, then it unselects all nodes; otherwise, it unselects all visible nodes. */ function unselectAllFiltered(storeId) { const treeViewStore = (0, _treeView.getTreeViewStore)(storeId); const { searchText, innerMostChildrenIds } = treeViewStore.getState(); // If there's no search text, unselect all nodes if (!searchText) { unselectAll(storeId); } else { // If there's search text, only unselect the visible nodes (0, _toggleCheckbox.toggleCheckboxes)(storeId, innerMostChildrenIds, false); } } ; /** * Selects all nodes in the tree. * * This function selects all nodes by adding all node ids to the checked set and clearing the indeterminate set. */ function selectAll(storeId) { const treeViewStore = (0, _treeView.getTreeViewStore)(storeId); const { nodeMap, updateChecked, updateIndeterminate } = treeViewStore.getState(); // Create a new set containing the ids of all nodes const newChecked = new Set(nodeMap.keys()); // Update the state to mark all nodes as checked updateChecked(newChecked); updateIndeterminate(new Set()); } ; /** * Unselects all nodes in the tree. * * This function unselects all nodes by clearing both the checked and indeterminate sets. */ function unselectAll(storeId) { const treeViewStore = (0, _treeView.getTreeViewStore)(storeId); const { updateChecked, updateIndeterminate } = treeViewStore.getState(); // Update the state to mark all nodes as unchecked updateChecked(new Set()); updateIndeterminate(new Set()); } ; /** * Get the ids of the innermost children in the tree * * @param filteredTreeNodes - The filtered tree data * @returns - array of ids of the inner most children only */ function getInnerMostChildrenIdsInTree(filteredTreeNodes) { const allLeafIds = []; const getLeafNodes = _nodes => { for (let node of _nodes) { if (node.children) { getLeafNodes(node.children); } else { allLeafIds.push(node.id); } } }; getLeafNodes(filteredTreeNodes); return allLeafIds; } //# sourceMappingURL=selectAll.helper.js.map