página del paquete→ /design/components.html
pages/design/components.html
406 líneas, 24.9 KB. Abrir tal cual (en un proyecto hay otros archivos a su lado; aquí pueden faltar).
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- <!--
- ---
- type: Lens
- title: "Components"
- icon: "🧩"
- description: "The component catalog of the project's libraries: the chosen component on the stage; the right panel holds the components by level, its states and its settings."
- template: custom
- layout: catalog
- lensType: catalog
- search: true
- sources: ["/design/components.md", "/design/components/*.md", "/design/<library>/components/**"]
- generator: "shtuk run design-components sync"
- ---
- The component catalog of `design-lenses`, read from `lib/design/components.data.js` (`shtuk run design-components sync`).
- The right panel holds three sections: Components (the tree by level, built of the library's tree items), States (any state or data state, or all side by side) and Settings (every control).
- -->
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Components</title>
- <link rel="stylesheet" href="../lib/kit.css">
- <link rel="stylesheet" href="../lib/explore.css">
- <script src="../lib/data.js"></script>
- <script src="../lib/design/style.data.js"></script>
- <script src="../lib/design/components.data.js"></script>
- <script src="../lib/explore.js"></script>
- <script>
- // The chosen style's CSS goes in before the kit's CSS, as in the style specimen: the lens wears the chosen style.
- (function () {
- const S = window.SB_STYLE, kit = document.querySelector('link[href$="lib/kit.css"]');
- if (!S || !kit) return;
- const root = new URL("../", kit.href).href;
- for (const p of S.css || []) {
- const l = document.createElement("link");
- l.rel = "stylesheet"; l.href = root + p.replace(/^\//, ""); l.dataset.style = S.id;
- kit.before(l);
- }
- })();
- </script>
- <script src="../lib/kit.js"></script>
- <style>
- /* The catalog: the stage fills the page (the shell's layout-catalog); the component tree is a section of the right panel,
- built of the library's tree items. No cards, no frames: the component stands on the white page; regions are separated
- by spacing and one hairline. Contract names only. */
- .cc { --cc-fg: var(--foreground, #191919); --cc-mute: var(--muted-foreground, #6f6e69); --cc-line: var(--border, #e9e9e7);
- --cc-row: var(--sidebar-accent, #f1f1ef);
- min-height: 100%; color: var(--cc-fg); box-sizing: border-box; }
- .cc *, .cc *::before, .cc *::after { box-sizing: border-box; }
- /* The tree scrolls with the States and Settings in the panel body. */
- .cc-tree { display: flex; flex-direction: column; gap: 1px; margin: 0 -8px; }
- .cc-tree [hidden] { display: none; }
- .cc-override { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--primary); }
- .cc-stage { min-width: 0; padding: 48px 56px 96px; }
- .cc-comp { max-width: 960px; }
- .cc-comp h1 { margin: 0; font-size: 26px; line-height: 1.2; font-weight: 650; letter-spacing: -.015em; }
- .cc-desc { margin: 8px 0 0; max-width: 640px; color: var(--cc-mute); font-size: 14px; line-height: 1.5; }
- .cc-links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 12px; font-size: 13px; color: var(--cc-mute); }
- .cc-links a { color: inherit; text-decoration: none; cursor: pointer; }
- .cc-links a:hover { color: var(--cc-fg); text-decoration: underline; text-underline-offset: 3px; }
- .cc-links .rel button { all: unset; cursor: pointer; color: var(--cc-fg); }
- .cc-links .rel button:hover { text-decoration: underline; text-underline-offset: 3px; }
- .cc-view { margin-top: 32px; border-top: 1px solid var(--cc-line); padding-top: 8px; }
- .cc-view iframe { display: block; width: 100%; border: 0; height: 240px; background: transparent; color-scheme: normal; }
- .cc-none { color: var(--cc-mute); font-size: 13.5px; padding: 24px 0; }
- .cc-warn { color: var(--destructive, #e85339); font-size: 13.5px; padding: 24px; }
- /* All components: a gallery of tiles, a picture and the name under it */
- .cc-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 28px 24px; margin-top: 32px; }
- .cc-tile { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
- .cc-pic { height: 130px; overflow: hidden; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--cc-line); margin-bottom: 8px; display: flex; align-items: center; justify-content: center; }
- .cc-pic .cc-view { margin: 0; border: 0; padding: 0; width: 100%; }
- .cc-pic iframe { max-height: 130px; }
- .cc-tile:hover .cc-pic { background: var(--cc-row); }
- .cc-tile .t { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
- .cc-tile .l { font-size: 12.5px; color: var(--cc-mute); }
- .cc-tile:focus-visible { outline: 2px solid var(--ring, #e04a72); outline-offset: 4px; border-radius: 8px; }
- /* the States section of the right panel: a list of rows, the chosen one grey */
- .cc-states { display: flex; flex-direction: column; gap: 1px; margin: 0 -8px; }
- .cc-states .g { font-size: 12px; color: var(--cc-mute, #6f6e69); padding: 8px 8px 3px; }
- .cc-states .g:first-child { padding-top: 0; }
- .cc-states button { all: unset; display: flex; align-items: center; height: 28px; padding: 0 8px; border-radius: 6px; font-size: 13.5px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
- .cc-states button:hover, .cc-states button.on { background: var(--sidebar-accent, #f1f1ef); }
- .cc-states button.on { font-weight: 500; }
- .cc-plain-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
- .cc-plain-row select { width: 100%; }
- @media (max-width: 900px) { .cc-stage { padding: 32px 24px 80px; } }
- </style>
- <script>
- (function () {
- const { h } = Lens;
- const LEVELS = [["primitive", "Primitives"], ["composite", "Composites"], ["block", "Blocks"], ["shell", "Shell"], ["page", "Pages"]];
- const href = (p) => Lens.rootHref + String(p).replace(/^\//, "");
- const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
- const stateKeys = (comp) => {
- const keys = [...(comp.states || []), ...(comp.status || [])].filter((k, i, a) => a.indexOf(k) === i);
- for (const k of Object.keys((comp.html && comp.html.templates) || {})) if (!keys.includes(k)) keys.push(k);
- return keys;
- };
- /** The CSS a frame links: the chosen style's files, then the library's own (style files of any installed style are left out). */
- function frameCss(C, S, styleId) {
- const styles = (S && S.styles) || [];
- const chosen = styles.find((s) => s.id === styleId) || (S && S.id === styleId ? { css: S.css } : null);
- const isStyleFile = (p) => styles.some((s) => p.startsWith("/design/" + s.id + "/")) || (S && p.startsWith("/design/" + S.id + "/"));
- const own = (C.css || []).filter((p) => !isStyleFile(p));
- return chosen ? [...chosen.css, ...own] : C.css || [];
- }
- /** The document of a frame: the chosen state alone and large, or every state side by side with its name under it. */
- function frameDoc(comp, css, theme, state) {
- const T = (comp.html && comp.html.templates) || {};
- const thumb = state === "thumb";
- const keys = state === "all" ? stateKeys(comp) : [state in T ? state : stateKeys(comp)[0]];
- const one = keys.length === 1 && state !== "all";
- const cells = keys.map((k) => {
- const body = T[k] != null ? T[k] : '<span class="sb-missing">no template</span>';
- return '<figure class="sb-cell" data-key="' + esc(k) + '"><div class="sb-stage">' + body + "</div>" + (one ? "" : "<figcaption>" + esc(k) + "</figcaption>") + "</figure>";
- }).join("");
- return '<!doctype html><html lang="en" data-theme="' + theme + '"' + (theme === "dark" ? ' class="dark"' : "") + '><head><meta charset="utf-8"><base href="' + esc(Lens.rootHref) + '">'
- + css.map((p) => '<link rel="stylesheet" href="' + esc(p.replace(/^\//, "")) + '">').join("")
- + "<style>html,body{margin:0;background:var(--background,#fff);color:var(--foreground,#191919);font-family:var(--font-sans,system-ui,sans-serif)}"
- + "body{padding:" + (thumb ? "20px" : one ? "56px 24px" : "28px 2px 8px") + "}" + (thumb ? "html,body{background:transparent}body{zoom:.8;pointer-events:none}" : "")
- + ".sb-cells{display:" + (one ? "flex;justify-content:center" : "grid;grid-template-columns:repeat(auto-fill,minmax(min(100%," + (comp.level === "primitive" ? "160px" : "300px") + "),1fr));gap:40px 48px;align-items:start") + "}"
- + ".sb-cell{margin:0;display:flex;flex-direction:column;gap:12px;min-width:0;max-width:100%}"
- + ".sb-stage{min-height:40px;display:flex;flex-direction:column;justify-content:center;" + (one ? "align-items:center;" : "align-items:stretch;") + "max-width:100%}"
- + ".sb-stage>*{max-width:100%}" + (comp.level === "primitive" ? ".sb-stage{align-items:flex-start}" : "") + (one ? ".sb-cells>.sb-cell{width:" + (comp.level === "primitive" ? "auto" : "min(100%,420px)") + "}" : "")
- + "figcaption{font:12px/1.2 var(--font-mono,ui-monospace,monospace);color:var(--muted-foreground,#6f6e69)}"
- + ".sb-missing{font-size:12px;color:var(--muted-foreground,#6f6e69)}</style></head><body><div class=\"sb-cells\">" + cells + "</div></body></html>";
- }
- /** A control value on a component root (build contract, section 4). */
- function applyControls(doc, comp, values) {
- if (!doc) return;
- const roots = [...doc.querySelectorAll(".sb-stage")].map((s) => s.querySelector('[data-slot="' + comp.id + '"]') || s.firstElementChild).filter(Boolean);
- for (const [k, c] of Object.entries(comp.controls || {})) {
- if (!(k in values)) continue;
- const v = values[k];
- for (const r of roots) {
- if (c.kind === "range") r.style.setProperty("--" + comp.id + "-" + k, v + (c.unit || ""));
- else if (c.kind === "bool") v === true || v === "true" ? r.setAttribute("data-" + k, "") : r.removeAttribute("data-" + k);
- else r.setAttribute("data-" + k, String(v));
- }
- }
- }
- Lens.templates.custom = function (cfg) {
- const ui = Lens.page(Object.assign({ layout: "catalog" }, cfg));
- const C = window.SB_COMPONENTS, S = window.SB_STYLE;
- if (!C) {
- ui.main.append(h("p", { class: "cc-warn" }, "There is no component data. Build it from the project root: shtuk run design-components sync"));
- return;
- }
- const comps = C.components || [];
- const byId = Object.fromEntries(comps.map((c) => [c.id, c]));
- const provenance = (c) => [...new Set([c.html, c.react].filter((impl) => impl?.overrides)
- .map((impl) => "from " + impl.library + ", overrides " + impl.overrides))].join(" · ");
- const usedBy = (id) => comps.filter((c) => (c.uses || []).includes(id)).map((c) => c.id);
- const styleIds = ((S && S.styles) || []).map((s) => s.id);
- const defStyle = (S && S.id) || C.style || styleIds[0] || "";
- if (defStyle && !styleIds.includes(defStyle)) styleIds.unshift(defStyle);
- const pageTheme = () => (document.documentElement.dataset.theme === "dark" ? "dark" : "light");
- const look = { style: defStyle, values: {} };
- const params = new URLSearchParams(location.search);
- let current = null, state = params.get("state") || "all", settings = null;
- const frames = []; // {comp, iframe, state}
- // ---------- the frame of one component ----------
- function mountFrame(comp, holder, st) {
- if (!comp.html) { holder.append(h("p", { class: "cc-none" }, "No HTML templates: " + (comp.react ? "React only (" + comp.react.source + ")." : "not implemented yet."))); return; }
- const f = h("iframe", { title: comp.title, sandbox: "allow-same-origin", loading: "lazy" });
- const rec = { comp, iframe: f, state: st };
- const size = (d) => { f.style.height = Math.max(64, Math.ceil(d.documentElement.getBoundingClientRect().height)) + "px"; };
- const fit = () => {
- try {
- const d = f.contentDocument;
- if (!d || !d.body) return;
- if (comp.id === current) applyControls(d, comp, look.values);
- size(d);
- if (!f._ro && f.contentWindow.ResizeObserver) { f._ro = new f.contentWindow.ResizeObserver(() => size(d)); f._ro.observe(d.body); }
- } catch { f.style.height = "240px"; }
- };
- f.addEventListener("load", () => { f._ro = null; fit(); setTimeout(fit, 150); });
- f.srcdoc = frameDoc(comp, frameCss(C, S, look.style), pageTheme(), st);
- holder.append(h("div", { class: "cc-view" }, f));
- frames.push(rec);
- }
- const pageLink = (p) => (Lens.rec(p) ? h("a", { onclick: (e) => { e.preventDefault(); Lens.open(p); } }, "Page") : h("a", { href: href(p), title: p }, "Page"));
- const relList = (label, ids) => ids.length ? h("span", { class: "rel" }, label + " ",
- ids.map((x, i) => [i ? ", " : "", byId[x] ? h("button", { type: "button", onclick: () => select(x) }, byId[x].title) : x])) : null;
- function compView(comp, st) {
- const box = h("section", { class: "cc-comp", "data-id": comp.id },
- h("h1", {}, comp.title),
- comp.description ? h("p", { class: "cc-desc" }, comp.description) : null,
- h("div", { class: "cc-links" },
- provenance(comp) ? h("span", {}, provenance(comp)) : null,
- comp.page ? pageLink(comp.page) : null,
- comp.html && comp.html.source ? h("a", { href: href(comp.html.source), title: comp.html.source }, "HTML") : null,
- comp.html && comp.html.css ? h("a", { href: href(comp.html.css), title: comp.html.css }, "CSS") : null,
- comp.react && comp.react.source ? h("a", { href: href(comp.react.source), title: comp.react.source }, "React") : null,
- relList("Uses", comp.uses || []), relList("Used by", usedBy(comp.id))));
- mountFrame(comp, box, st);
- return box;
- }
- /** All components: a gallery, each in its first state with its name under it; a click opens it. */
- function overview() {
- const grid = h("div", { class: "cc-gallery" });
- for (const c of comps) {
- const cell = h("button", { type: "button", class: "cc-tile", title: c.description || c.title, onclick: () => select(c.id) });
- const pic = h("div", { class: "cc-pic" });
- cell.append(pic, h("span", { class: "t" }, c.title), h("span", { class: "l" }, (LEVELS.find(([x]) => x === c.level) || [c.level, c.level])[1]));
- mountFrame(c, pic, "thumb");
- grid.append(cell);
- }
- return grid;
- }
- // ---------- layout: the stage fills the page; the tree is the first section of the right panel ----------
- const stage = h("div", { class: "cc-stage", "data-slot": "layout-catalog-stage" });
- ui.main.append(h("div", { class: "cc" }, stage));
- // The tree is the library's tree items: "All components", then the levels as rows that fold, their components under them.
- const CHEV = '<svg viewBox="0 0 16 16"><path d="m6 4 4 4-4 4"/></svg>';
- const tree = h("div", { class: "cc-tree", role: "tree", "data-slot": "layout-catalog-tree", "aria-label": "Components by level" });
- const treeBody = ui.section("Components", tree);
- if (treeBody.setAnswer) treeBody.setAnswer(String(comps.length));
- const treeItem = (label, count, depth, expanded, source) => h("div", { "data-slot": "tree-item", class: "tree-item", role: "treeitem", "aria-level": String(depth + 1),
- "aria-selected": "false", tabindex: "-1", title: source ? label + " · " + source : label, "--tree-item-depth": String(depth), ...(expanded != null ? { "aria-expanded": String(expanded) } : {}) },
- h("span", { "data-slot": "tree-item-toggle", class: "tree-item-toggle", "aria-hidden": "true", ...(expanded != null ? { html: CHEV } : {}) }),
- h("span", { "data-slot": "tree-item-label", class: "tree-item-label" }, label),
- source ? h("span", { class: "cc-override", role: "img", "aria-label": source }) : null,
- h("span", { "data-slot": "tree-item-count", class: "tree-item-count" }, String(count)));
- const items = {}, lvRows = {};
- let query = "", openLevel = null;
- const matches = (c, q) => (c.title + " " + c.id + " " + (c.description || "")).toLowerCase().includes(q);
- function paintTree() {
- for (const L of Object.values(lvRows)) {
- const hits = L.ids.filter((id) => !query || matches(byId[id], query));
- const isOpen = query ? hits.length > 0 : openLevel === L.lv;
- L.row.hidden = !!query && !hits.length;
- L.row.setAttribute("aria-expanded", String(isOpen));
- L.row.querySelector(".tree-item-count").textContent = String(hits.length);
- for (const id of L.ids) items[id].hidden = !(isOpen && hits.includes(id));
- }
- const tab = tree.querySelector('.tree-item[tabindex="0"]');
- if (!tab || tab.hidden) {
- if (tab) tab.setAttribute("tabindex", "-1");
- (tree.querySelector('.tree-item[aria-selected="true"]:not([hidden])') || allItem).setAttribute("tabindex", "0");
- }
- }
- const toggleLv = (lv, v = openLevel !== lv) => { if (!query) { openLevel = v ? lv : null; paintTree(); } };
- const allItem = treeItem("All components", comps.length, 0, null);
- allItem._act = () => select("");
- tree.append(allItem);
- const levels = LEVELS.concat([...new Set(comps.map((c) => c.level))].filter((l) => !LEVELS.some(([x]) => x === l)).map((l) => [l, l]));
- for (const [lv, title] of levels) {
- const list = comps.filter((c) => c.level === lv);
- if (!list.length) continue;
- const row = treeItem(title, list.length, 0, false);
- row._lv = lv; row._act = () => toggleLv(lv);
- lvRows[lv] = { lv, row, ids: list.map((c) => c.id) };
- tree.append(row);
- for (const c of list) {
- const it = (items[c.id] = treeItem(c.title, stateKeys(c).length, 1, null, provenance(c)));
- it.hidden = true; it._parent = row; it._act = () => select(c.id);
- tree.append(it);
- }
- }
- tree.addEventListener("click", (e) => { const r = e.target.closest(".tree-item"); if (r && r._act) r._act(); });
- tree.addEventListener("focusin", (e) => { const r = e.target.closest(".tree-item"); if (!r) return; tree.querySelectorAll('.tree-item[tabindex="0"]').forEach((x) => x.setAttribute("tabindex", "-1")); r.setAttribute("tabindex", "0"); });
- tree.addEventListener("keydown", (e) => {
- const r = e.target.closest(".tree-item");
- if (!r) return;
- const vis = [...tree.querySelectorAll(".tree-item")].filter((x) => !x.hidden), i = vis.indexOf(r);
- const go = (j) => { const t = vis[Math.max(0, Math.min(vis.length - 1, j))]; if (t) { e.preventDefault(); t.focus(); } };
- if (e.key === "ArrowDown") go(i + 1);
- else if (e.key === "ArrowUp") go(i - 1);
- else if (e.key === "Home") go(0);
- else if (e.key === "End") go(vis.length - 1);
- else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (r._act) r._act(); }
- else if (e.key === "ArrowRight" && r._lv && r.getAttribute("aria-expanded") === "false") { e.preventDefault(); toggleLv(r._lv, true); }
- else if (e.key === "ArrowLeft") {
- if (r._lv && r.getAttribute("aria-expanded") === "true") { e.preventDefault(); toggleLv(r._lv, false); }
- else if (r._parent) { e.preventDefault(); r._parent.focus(); }
- }
- });
- // ---------- the right panel: States, then Settings ----------
- const statesBody = ui.section("States");
- function drawStates() {
- const c = byId[current];
- statesBody.replaceChildren();
- if (statesBody.setAnswer) statesBody.setAnswer(c ? String(stateKeys(c).length) : "");
- const sec = statesBody.card || statesBody.closest("[data-slot=panel-section], .lx-sec");
- if (sec) sec.hidden = !c;
- if (!c) return;
- const row = (k, label) => h("button", { type: "button", class: state === k ? "on" : "", onclick: () => setState(k) }, label || k);
- const inter = (c.states || []).filter((k) => stateKeys(c).includes(k));
- const data = stateKeys(c).filter((k) => !inter.includes(k));
- statesBody.append(h("div", { class: "cc-states" }, row("all", "All, side by side"),
- inter.length ? [h("div", { class: "g" }, "Interaction"), inter.map((k) => row(k))] : null,
- data.length ? [h("div", { class: "g" }, "Data"), data.map((k) => row(k))] : null));
- }
- function setState(k) {
- state = k;
- const u = new URL(location.href);
- if (k === "all") u.searchParams.delete("state"); else u.searchParams.set("state", k);
- history.replaceState(null, "", u);
- drawStates();
- render();
- }
- let settingsHost = null;
- function openSettings(comp) {
- if (settings && settings.destroy) settings.destroy();
- if (settingsHost) { (settingsHost.card || settingsHost.closest("[data-slot=panel-section], .lx-sec") || settingsHost).remove(); settingsHost = null; }
- settings = null;
- look.values = {};
- const controls = Object.assign({}, (comp && comp.controls) || {});
- if (styleIds.length > 1) controls["preview-style"] = { kind: "select", options: styleIds, default: defStyle, label: "Style" };
- if (!comp || !Object.keys(controls).length) return;
- const opts = {
- title: "Settings",
- target: h("div", { hidden: true }),
- storageKey: "design-components:" + comp.id,
- sections: [{ title: "Settings", controls }],
- onChange: (values) => {
- look.values = values;
- const s = values["preview-style"] || defStyle;
- if (s !== look.style) { look.style = s; render(); return; }
- for (const r of frames) if (r.comp.id === comp.id) { try { applyControls(r.iframe.contentDocument, r.comp, values); } catch {} }
- },
- };
- if (ui.settings) { settings = ui.settings(opts); return; }
- // An older kit: the explore kit's panel stands in a bare block of the right panel, its title the section's.
- if (window.Explore && !window.Explore.standIn) {
- settingsHost = ui.section();
- settings = window.Explore.panel(Object.assign({}, opts, { sections: [{ title: "", controls }], container: settingsHost }));
- return;
- }
- settingsHost = ui.section("Settings");
- // No explore kit: plain selects with the same values.
- const vals = {};
- for (const [k, c] of Object.entries(controls)) {
- const o = (c.options || []).map((x) => (Array.isArray(x) ? x : [x, x]));
- vals[k] = c.default != null ? c.default : o.length ? o[0][0] : "";
- const inp = c.kind === "range" ? h("input", { type: "range", min: c.min, max: c.max, step: c.step || 1, value: vals[k] })
- : c.kind === "bool" ? h("input", { type: "checkbox", checked: !!vals[k] })
- : h("select", {}, o.map(([v, t]) => h("option", { value: v, selected: v === vals[k] }, t)));
- inp.addEventListener("input", () => { vals[k] = c.kind === "bool" ? inp.checked : inp.value; opts.onChange(Object.assign({}, vals)); });
- settingsHost.append(h("label", { class: "cc-plain-row" }, h("span", {}, c.label || k), inp));
- }
- opts.onChange(Object.assign({}, vals));
- }
- function render() {
- frames.length = 0;
- stage.replaceChildren();
- const c = byId[current];
- if (!c) {
- stage.append(comps.length ? h("div", { class: "cc-comp" }, h("h1", {}, "All components"),
- h("p", { class: "cc-desc" }, comps.length + " components by level; open one to see its states and settings."), overview())
- : h("p", { class: "cc-none" }, "No components in the data."));
- return;
- }
- stage.append(compView(c, state === "all" || stateKeys(c).includes(state) ? state : "all"));
- }
- function select(id) {
- if (id && !byId[id]) return;
- // the chosen component's level opens; the chosen row is the tree's one tab stop
- openLevel = id ? byId[id].level : null;
- allItem.setAttribute("aria-selected", String(!id));
- for (const [k, b] of Object.entries(items)) b.setAttribute("aria-selected", String(k === id));
- tree.querySelectorAll('.tree-item[tabindex="0"]').forEach((x) => x.setAttribute("tabindex", "-1"));
- (id ? items[id] : allItem).setAttribute("tabindex", "0");
- paintTree();
- const u = new URL(location.href);
- // Another component: the old one's control values and state leave the link (a shared link keeps them on the first open).
- if (current !== null && u.searchParams.get("component") !== id) {
- for (const k of [...u.searchParams.keys()]) if (!["component", "skin", "theme"].includes(k)) u.searchParams.delete(k);
- state = "all";
- }
- if (id) u.searchParams.set("component", id); else u.searchParams.delete("component");
- history.replaceState(null, "", u);
- current = id;
- if (byId[id] && state !== "all" && !stateKeys(byId[id]).includes(state)) state = "all";
- drawStates();
- openSettings(byId[id]);
- render();
- stage.scrollTop = 0;
- }
- Lens.on("search", (q) => {
- query = q || "";
- if (!query) openLevel = byId[current]?.level ?? null;
- paintTree();
- });
- // The frames follow the page's theme.
- new MutationObserver(() => render()).observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
- const want = params.get("component");
- select(byId[want] ? want : want === "" || params.get("view") === "all" ? "" : comps[0] ? comps[0].id : "");
- };
- })();
- </script>
- </head>
- <body><p class="lx-missing">The lens "Components". There is no data yet: build it from the project root with <code>shtuk run lenses build</code> and <code>shtuk run design-components sync</code>.</p></body>
- </html>