import {getById, h, span, addClass, div} from '/common.module.js' import {DACTAL} from "/dactal.js" const enterEvent = new KeyboardEvent('keydown', { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true, cancelable: true }); let dactal export async function onLoad() { const input = getById("input") dactal = new DACTAL() const brp = await fetch("/brp.json") const cdata = await brp.json() dactal.data = { personen: cdata } input.onkeydown = async (e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault() let result = await dactal.query(input.value) const results = getById("results") results.replaceChildren(renderValue(result.slice(0, 100))) if (result.length > 100) { results.appendChild(div(span(`Not showing ${result.length - 100} more results.`))) } } } input.dispatchEvent(enterEvent) } function renderValue(obj) { if (Array.isArray(obj)) { return h("ol", ...obj.map((item) => h("li", renderValue(item))) ) } else if (typeof obj === "object") { return h("ul", ...Object.entries(obj).map(([name, item]) => addClass(h("li", addClass(span(name), "name"), span(" "), renderValue(item)), "dash"))) } else if (typeof obj === "boolean") { return addClass(span(obj), obj ? "json-true" : "json-false") } else if (typeof obj === "number") { return addClass(span(obj), "json-number") } else if (typeof obj === "string") { return span(obj) } }