43 lines
787 B
JavaScript
43 lines
787 B
JavaScript
/**
|
|
* @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;
|
|
}
|