Structured layers menu (WIP)
This commit is contained in:
42
js/utils/nodeUtils.js
Normal file
42
js/utils/nodeUtils.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @module
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Object[]} flatList
|
||||
* @param {Number} depth
|
||||
*/
|
||||
function traverse(node, flatList, depth = 1) {
|
||||
const normNode = {label: node.label};
|
||||
if (node.model) {
|
||||
normNode.model = node.model;
|
||||
}
|
||||
flatList.push({
|
||||
...normNode,
|
||||
depth
|
||||
});
|
||||
if (node.children) {
|
||||
depth++;
|
||||
for(let child of node.children) {
|
||||
traverse(child, flatList, depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a flat list of nodes from
|
||||
* the nested structure in config
|
||||
* @param {Array} nodes
|
||||
* @returns {Object[]} A flat list of nodes
|
||||
**/
|
||||
export function normalizeNodes (nodes) {
|
||||
let flatNodes = [];
|
||||
|
||||
for (let node of nodes) {
|
||||
traverse(node, flatNodes);
|
||||
}
|
||||
|
||||
return flatNodes;
|
||||
}
|
||||
Reference in New Issue
Block a user