Last active
December 31, 2020 18:36
-
-
Save lexoyo/b67b9ed9918145f476e9021a2c120130 to your computer and use it in GitHub Desktop.
tree component for silex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildTree(element, elements = silex.getElements(), _id) { | |
if(!element) { | |
console.error('element is undefined', _id) | |
silex.updateElements(silex.getElements().filter(el => el.id !== _id)) | |
return [] | |
} | |
const children = (element.children || []) | |
.map(id => buildTree(silex.getElementById(id), elements, id)) | |
const root = document.createElement('details') | |
root.setAttribute('data-id', element.id) | |
const summary = document.createElement('summary') | |
summary.innerHTML = element.tagName+'.'+(element.classList || []).join('.') | |
root.append(summary, ...children) | |
return root | |
} | |
console.log(silex.getBody()) | |
buildTree(silex.getBody()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment