Skip to content

Instantly share code, notes, and snippets.

@lexoyo
Last active December 31, 2020 18:36
Show Gist options
  • Save lexoyo/b67b9ed9918145f476e9021a2c120130 to your computer and use it in GitHub Desktop.
Save lexoyo/b67b9ed9918145f476e9021a2c120130 to your computer and use it in GitHub Desktop.
tree component for silex
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