UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

30 lines (29 loc) 1.59 kB
"use client"; const require_get_children_nodes_values = require("../Tree/get-children-nodes-values/get-children-nodes-values.cjs"); const require_get_all_checked_nodes = require("../Tree/get-all-checked-nodes/get-all-checked-nodes.cjs"); const require_is_node_checked = require("../Tree/is-node-checked/is-node-checked.cjs"); //#region packages/@mantine/core/src/components/TreeSelect/get-checked-values-by-strategy.ts function expandToLeafChecked(value, data) { const leaves = /* @__PURE__ */ new Set(); for (const v of value) for (const leaf of require_get_children_nodes_values.getChildrenNodesValues(v, data)) leaves.add(leaf); return Array.from(leaves); } function getTopmostCheckedParents(data, checkedState) { const result = []; for (const node of data) if (require_is_node_checked.isNodeChecked(node.value, data, checkedState)) result.push(node.value); else if (Array.isArray(node.children) && node.children.length > 0) result.push(...getTopmostCheckedParents(node.children, checkedState)); return result; } function checkedToValue(checkedState, data, strategy) { if (checkedState.length === 0) return []; switch (strategy) { case "child": return checkedState; case "all": return require_get_all_checked_nodes.getAllCheckedNodes(data, checkedState).result.filter((n) => n.checked).map((n) => n.value); case "parent": return getTopmostCheckedParents(data, checkedState); default: return checkedState; } } //#endregion exports.checkedToValue = checkedToValue; exports.expandToLeafChecked = expandToLeafChecked; //# sourceMappingURL=get-checked-values-by-strategy.cjs.map