Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/shared/src/dom.js
iris 3be4ec069c frontend: one time wording for the swarm UI and the dashboard, and no HTML strings in the dashboard's busy buttons
fmtAgo, fmtUntil and durationLabel move to @hive/shared/time.js. The swarm UI's util.ts is deleted and its importers (RelativeTime, ReviewRuns, BuildsPage) read the shared module directly. The dashboard's own copies are gone: its fmtAgeSecs (a third phrasing, used for two status lines) becomes the shared fmtAgo, and the dashboard util.js lost fmtAgo, fmtElapsed, epochSec and truncate, which nothing called. asyncBtn and the bulk action buttons mark themselves busy with markBusy: a spinner node before the label and aria-busy, in place of replacing the button's innerHTML with a string (and the label, so the button changed width and lost its name). The el() helper loses its html attribute.
2026-11-20 17:02:32 +01:00

23 lines
1 KiB
JavaScript

// Tiny DOM-builder helper shared by the dashboard and the per-agent UI. There
// is no `html` attribute on purpose: content is built from nodes and text, so a
// string from the API can never become markup.
//
// `el(tag, attrs, ...children)` creates an element, applying `attrs` as
// either the `class` special case or plain attributes, and
// appending `children` (strings become text nodes, `null`/`undefined`
// entries are skipped so callers can inline conditional children).
// `tag` can be any custom element's tag name too (e.g. `el('hive-btn',
// { variant: 'danger' }, 'label')`) — `document.createElement` upgrades
// it automatically if the tag is already registered.
export const el = (tag, attrs = {}, ...children) => {
const e = document.createElement(tag);
for (const [k, v] of Object.entries(attrs)) {
if (k === "class") e.className = v;
else e.setAttribute(k, v);
}
for (const c of children) {
if (c == null) continue;
e.append(c.nodeType ? c : document.createTextNode(c));
}
return e;
};