Files
skills/orchestrator/templates/page-legend.js
T
Kevin Veen-BirkenbachandClaude Opus 5.5 94bf0b418a feat(orchestrator): legend toggle per panel and Home tile (017)
Every view panel and Home tile that holds a legend gets an info button beside its star that hides or shows the legend. The pick is kept in the view store under legend.views per panel and legend.tiles per pin key; the store validates both maps and drops the state of a tile whose pin left Home. Unit tests for the store, E2E in Chromium and Firefox at 1920, 1366 and 390.

🎯 Fix: 94 %
💥 Break: 4 %
💸 Tokens: 100 %
⏱️ Velocity: 100 %
🛡️ Security: 100 %
🏆 Score: 90
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 14:13:29 +00:00

86 lines
3.1 KiB
JavaScript

const LEGEND_PARTS = ".legend, .res-legend, .home-metric > .legend-chips";
const LEGEND_PATHS = {view: "legend.views", tile: "legend.tiles"};
const legendView = {buttons: new WeakMap()};
const legendShown = (path, key) => ViewStore.get(path)[key] !== false;
function legendToggle(path, key) {
const show = !legendShown(path, key);
ViewStore.update(path, (flags) => {
const next = {...flags};
delete next[key];
return show ? next : {...next, [key]: false};
});
}
function legendButton(path, key) {
const button = iconBtn("bi-info-circle", "Legend", "btn small ghost legend-toggle", (event) => {
event.stopPropagation();
legendToggle(path, key);
});
button.dataset.legendKey = key;
button.addEventListener("pointerdown", (event) => event.stopPropagation());
return button;
}
function paintLegend(owner, button, shown) {
const state = shown ? "shown" : "hidden";
if (owner.dataset.legend !== state) {
owner.dataset.legend = state;
}
if (button.getAttribute("aria-pressed") !== String(shown)) {
button.setAttribute("aria-pressed", String(shown));
button.title = `Legend: ${shown ? "shown, press to hide it" : "hidden, press to show it"}`;
}
}
/**
* @param owner - a panel of a view or a Home tile.
* @param path - the view-store key of its kind, legend.views or legend.tiles.
* @param key - its panel id or pin key there.
* @param place - (button) => void putting the button in its spot, or null when the owner holds no legend.
*/
function legendFor(owner, path, key, place) {
const made = legendView.buttons.get(owner);
if (!place) {
if (made) {
made.remove();
legendView.buttons.delete(owner);
}
if (owner.dataset.legend) {
delete owner.dataset.legend;
}
return;
}
const button = made && made.dataset.legendKey === key ? made : legendButton(path, key);
legendView.buttons.set(owner, button);
place(button);
paintLegend(owner, button, legendShown(path, key));
}
const ownOf = (host, selector) => [...host.querySelectorAll(selector)].find((node) => node.closest(Panels.HOSTS) === host) || null;
function markLegends() {
for (const host of document.querySelectorAll("#main [data-panel]")) {
if (host.closest(".home-tile")) {
continue;
}
const star = ownOf(host, ".star");
legendFor(host, LEGEND_PATHS.view, host.dataset.panel, star && ownOf(host, LEGEND_PARTS) ? (button) => star.nextElementSibling !== button && star.after(button) : null);
}
for (const tile of document.querySelectorAll(".home-tile[data-pin]")) {
const open = tile.querySelector(".home-open");
legendFor(tile, LEGEND_PATHS.tile, tile.dataset.pin, tile.querySelector(`.home-body :is(${LEGEND_PARTS})`) ? (button) => open.previousElementSibling !== button && open.before(button) : null);
}
}
function legendBoot() {
new MutationObserver(markLegends).observe(document.body, {childList: true, subtree: true});
ViewStore.on("legend", () => {
markLegends();
drawHome();
drawResources();
});
markLegends();
}