Files
dawnline/web/src/admin/e.ts
T
Aemeath a3910f8b97
Build packages / Version (push) Waiting to run
Dawnline 0.1.0: AmneziaWG access server for OpenWrt
LuCI admin (people, devices, limits, disguise, health, updates, backups)
and a personal self-service portal, built as ipk (OpenWrt 24.10) and apk
(OpenWrt 25.12) with the OpenWrt SDK. Successor of openwrt-liminal.

- install.sh: checks the router, installs AmneziaWG for its firmware,
  then the release package verified against sha256sums.txt
- CI: Prettier, types, tests, committed bundles, ShellCheck, ucode checks;
  tagged releases build both packages and publish them
- Web bundles minified with esbuild (JS and CSS)
- README with framed screenshots
2026-10-15 03:29:30 +03:00

21 lines
1.1 KiB
TypeScript

// LuCI's global E() appends array children only one level deep and
// stringifies nested arrays ("[object HTMLDivElement]"). This wrapper
// flattens children recursively and drops empty values, so components can
// compose freely. Modules import it and thereby shadow the global.
import type { Child } from './luci.d';
function flatten(c: Child, out: (Node | string)[]): (Node | string)[] {
if (c == null || c === false || c === '') return out;
if (Array.isArray(c)) c.forEach((x) => flatten(x, out));
else out.push(c instanceof Node ? c : String(c));
return out;
}
export function E(tag: string, attrs?: Record<string, unknown> | Child, children?: Child): HTMLElement {
const luciE = (window as unknown as { E: (t: string, a: Record<string, unknown>, c: Child) => HTMLElement }).E;
const isAttrs = attrs != null && typeof attrs === 'object' && !Array.isArray(attrs) && !(attrs instanceof Node);
if (!isAttrs && children === undefined) return luciE(tag, {}, flatten(attrs as Child, []));
return luciE(tag, (isAttrs ? attrs : {}) as Record<string, unknown>, flatten(children, []));
}