// @ts-check
///
import { html, keyed } from 'dhtml'
import { createRoot } from 'dhtml/client'
/** @param {string} text */
function tableCell(text) {
function onClick(e) {
console.log('Clicked' + text)
e.stopPropagation()
}
return html`
${text} | `
}
/** @param {TableItemState} data */
function tableRow(data) {
return html`
${tableCell('#' + data.id)} ${data.props.map(c => tableCell(c))}
`
}
/** @param {TableState} data */
function table(data) {
return html`
${data.items.map(item => keyed(tableRow(item), item.id))}
`
}
/** @param {AnimBoxState} data */
function animBox(data) {
return html`
`
}
/** @param {AnimState} data */
function anim(data) {
return html`${data.items.map(item => keyed(animBox(item), item.id))}
`
}
/** @param {TreeNodeState} data */
function treeLeaf(data) {
return html`${data.id}`
}
/** @param {TreeNodeState} data */
function treeNode(data) {
return html`
${data.children.map(child => keyed(child.container ? treeNode(child) : treeLeaf(child), child.id))}
`
}
/** @param {TreeState} data */
function tree(data) {
return html`${treeNode(data.root)}
`
}
/** @param {AppState} data */
function main(data) {
let section
switch (data.location) {
case 'table':
section = table(data.table)
break
case 'anim':
section = anim(data.anim)
break
case 'tree':
section = tree(data.tree)
break
}
return html`${section}
`
}
const root = createRoot(document.body)
uibench.init('dhtml', 'HEAD')
uibench.run(
state => {
root.render(main(state))
},
samples => {
root.render(html`${JSON.stringify(samples, null, ' ')}`)
},
)