Kundenansicht neu P1: h(), api() mit ApiFehler und Quelltext-Regel
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
46edb7c418
commit
6f0808647f
4 files changed
+140
No files matched your search
@@ -0,0 +1,28 @@
|
||||
/* Kundenansicht neu: Elemente bauen, ohne dass Kundentext je als HTML gelesen wird.
|
||||
Texte werden Textknoten, nie innerHTML. Das Modul liest `document` erst beim Aufruf und ist in Node importierbar. */
|
||||
|
||||
/** Element bauen. attrs.class setzt die Klasse, attrs.on = { click: fn } hängt Ereignisse an, true setzt ein Attribut ohne Wert,
|
||||
* false/null/undefined lassen es weg. Kinder werden flach gelegt, Strings und Zahlen werden Textknoten. */
|
||||
export function h(tag, attrs = {}, ...kinder) {
|
||||
const el = document.createElement(tag)
|
||||
for (const [name, wert] of Object.entries(attrs || {})) {
|
||||
if (wert === undefined || wert === null || wert === false) continue
|
||||
if (name === 'class') el.className = wert
|
||||
else if (name === 'on') for (const [typ, fn] of Object.entries(wert)) el.addEventListener(typ, fn)
|
||||
else el.setAttribute(name, wert === true ? '' : String(wert))
|
||||
}
|
||||
for (const kind of kinder.flat(Infinity)) if (kind !== undefined && kind !== null && kind !== false) el.append(typeof kind === 'number' ? String(kind) : kind)
|
||||
return el
|
||||
}
|
||||
|
||||
/** Alle Kinder entfernen. */
|
||||
export function leeren(el) {
|
||||
el.replaceChildren()
|
||||
return el
|
||||
}
|
||||
|
||||
/** Text setzen (nie HTML); null und undefined werden zum leeren Text. */
|
||||
export function text(el, wert) {
|
||||
el.textContent = String(wert ?? '')
|
||||
return el
|
||||
}
|
||||
Reference in new issue
Block a user