@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
34 lines (33 loc) • 1.21 kB
JavaScript
"use client";
//#region packages/@mantine/core/src/components/Tree/get-children-nodes-values/get-children-nodes-values.ts
function findTreeNode(value, data) {
for (const node of data) {
if (node.value === value) return node;
if (Array.isArray(node.children)) {
const childNode = findTreeNode(value, node.children);
if (childNode) return childNode;
}
}
return null;
}
function getChildrenNodesValues(value, data, acc = []) {
const node = findTreeNode(value, data);
if (!node) return acc;
if (!Array.isArray(node.children) || node.children.length === 0) return [node.value];
node.children.forEach((child) => {
if (Array.isArray(child.children) && child.children.length > 0) getChildrenNodesValues(child.value, data, acc);
else acc.push(child.value);
});
return acc;
}
function getAllChildrenNodes(data) {
return data.reduce((acc, node) => {
if (Array.isArray(node.children) && node.children.length > 0) acc.push(...getAllChildrenNodes(node.children));
else acc.push(node.value);
return acc;
}, []);
}
//#endregion
exports.getAllChildrenNodes = getAllChildrenNodes;
exports.getChildrenNodesValues = getChildrenNodesValues;
//# sourceMappingURL=get-children-nodes-values.cjs.map