The first E2E run of 085 to 099 failed 69 tests and errored 2; every spec is green again when run alone, and a full rerun left only a Firefox swipe flake. That flake was a real defect: fadeSwap() ran a page-wide View Transition, and captured content takes no pointer hits, so a click or swipe during any list fade was lost. fadeTransition(run, box) now names only the swapped box (view-transition-name list-swap, the root none), so everything outside it stays hit-testable; screen changes stay page-wide. test_hub_motion_e2e proves a hit outside the box during a real fadeSwap; it fails with the scoping removed. The swipe spec passed 3 of 3 runs. Code: the Filter menu opens leftwards instead of past the viewport; kanban lines measure beating cards at rest; a 409 toast names the row's title; viewstore keeps the board legend; a closing context menu drops its focus; the first closed-cards poll only takes a baseline (081 cadence); the Match tile keeps the deck height; a swipe never starts a native link drag; the heartbeat glow survives reduced motion; the Resources toolbar fits 390 px; the Send button keeps 44 px. Specs: elements fading out (086) and the new Claude dialogs section (094) are expected; probes skip the docked bubble's own avatar (098); no assertion was loosened. MEDUSA: 5 false positives accepted on the operator's word (MM-SCAN-058 regex PLA in errors=replace, WM-SCAN-354 regex ELS in else ... code, EXA007 toolbar line moved). 🎯 Fix: 94 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 90 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
292 lines
12 KiB
JavaScript
292 lines
12 KiB
JavaScript
const ctxMenu = {node: null, back: null, checks: []};
|
|
const CTX_FIELDS = ["INPUT", "TEXTAREA", "SELECT"];
|
|
const CTX_ITEMS = '[role="menuitem"], [role="menuitemcheckbox"]';
|
|
const CTX_MATCH = ".graph.match, .match-hidden";
|
|
const CTX_GAP = 8;
|
|
const CTX_MODIFIERS = ["Shift", "Control", "Alt", "Meta"];
|
|
const CTX_OPENS = {task: "Open task", message: "Open message", artifact: "Open artifact"};
|
|
const ctxAttr = (...names) => (node) => names.map((name) => node.getAttribute(name)).find(Boolean) || null;
|
|
const ctxField = (node) => Boolean(node.isContentEditable) || CTX_FIELDS.includes(node.tagName);
|
|
const ctxInside = (node) => Boolean(ctxMenu.node) && ctxMenu.node.contains(node);
|
|
const ctxCopyItem = (label, text) => ({label, hint: text, run: () => ctxCopy(text)});
|
|
|
|
function ctxAgentOf(node) {
|
|
const raw = ctxAttr("data-agent", "data-face", "data-name", "data-session")(node);
|
|
return raw && raw !== HUMAN ? agentKey(raw) : null;
|
|
}
|
|
|
|
function ctxPinOf(node) {
|
|
return node.matches(Panels.HOSTS) ? Panels.targetOf(node) : null;
|
|
}
|
|
|
|
const ctxPinEntry = (target) => (target.id && !target.refused ? Panels.lookup(target.kind, target.id, target.view) : null);
|
|
const ctxEntryOf = (ref) => state.inbox.find((entry) => keyOf(entry) === ref) || null;
|
|
const ctxArtifactOf = (id) => (tree.model ? tree.model.byId.get(id) || null : null);
|
|
|
|
function ctxTaskItems(node, id) {
|
|
const known = state.tasks.some((row) => row.task === id);
|
|
return [...(known ? [{label: "Open task", hint: id, run: () => taskSheet(id)}] : []), ctxCopyItem("Copy task id", id)];
|
|
}
|
|
|
|
function ctxAgentItems(node, key) {
|
|
return [ctxCopyItem("Copy name", nameOf(key))];
|
|
}
|
|
|
|
function ctxBranchItems(node, name) {
|
|
const ref = `branch:${node.getAttribute("data-repo")}\u0000${name}`;
|
|
const open = ctxArtifactOf(ref) ? [{label: "Open branch", hint: name, run: () => artSelect(ref)}] : [];
|
|
return [...open, ctxCopyItem("Copy branch name", name), {label: "Explain", hint: "what each mark of a branch means", run: () => openSheet("Explain", glossarySections(), false)}];
|
|
}
|
|
|
|
function ctxPathItems(node, path) {
|
|
return [...feedbackItems(node), ...(path === "-" ? [] : [ctxCopyItem("Copy path", path)])];
|
|
}
|
|
|
|
function ctxEntryItems(node, ref) {
|
|
const item = ctxEntryOf(ref);
|
|
return item ? [{label: "Open entry", hint: item.title, run: () => openItem(item)}, ctxCopyItem("Copy id", item.id)] : [];
|
|
}
|
|
|
|
function ctxPickItems(node, id) {
|
|
const found = ctxArtifactOf(id);
|
|
if (found) {
|
|
return [{label: "Open artifact", hint: found.label, run: () => artSelect(id)}];
|
|
}
|
|
const sub = state.graph.nodes.find((entry) => entry.id === id && entry.kind === "subagent");
|
|
return sub ? [{label: "Open parent agent", hint: labelOf(sub.parent), run: () => select(id)}] : [];
|
|
}
|
|
|
|
function ctxPickTitle(id) {
|
|
const found = ctxArtifactOf(id) || state.graph.nodes.find((entry) => entry.id === id);
|
|
return found ? found.label : id;
|
|
}
|
|
|
|
function ctxPinItems(node, target) {
|
|
if (target.refused) {
|
|
return [{label: "Pin to Home", hint: `not possible, ${target.refused}`, run: () => toast("Not pinned", [`Pin to Home is not possible: ${target.refused}.`], false)}];
|
|
}
|
|
const entry = ctxPinEntry(target);
|
|
if (!entry) {
|
|
return [];
|
|
}
|
|
const opens = Object.hasOwn(CTX_OPENS, target.kind) ? [{label: CTX_OPENS[target.kind], hint: entry.title, run: () => HOME_OPENERS[target.kind](Panels.raw(target.id), target.id)}] : [];
|
|
const pinned = Panels.has(homePins(), target.kind, target.id);
|
|
return [...opens, {label: pinned ? "Unpin from Home" : "Pin to Home", hint: entry.title, run: () => homePress(target.kind, target.id, entry.title, target.view)}];
|
|
}
|
|
|
|
function ctxTileItems(node, key) {
|
|
const hint = `${node.querySelector(".home-title").textContent}: zoom its content`;
|
|
return [
|
|
{label: "Zoom in", hint: `${hint} (+)`, run: () => homeZoomBy(key, 1)},
|
|
{label: "Zoom out", hint: `${hint} (-)`, run: () => homeZoomBy(key, -1)},
|
|
{label: `Reset zoom (${homeZoom(key)} %)`, hint: `${hint} (0)`, run: () => homeZoomBy(key, 0)},
|
|
];
|
|
}
|
|
|
|
const CTX_KINDS = [
|
|
{kind: "task", id: ctxAttr("data-task"), title: (id) => `Task ${id}`, items: ctxTaskItems},
|
|
{kind: "agent", id: ctxAgentOf, title: (key) => nameOf(key), items: ctxAgentItems},
|
|
{kind: "branch", id: ctxAttr("data-branch"), title: (name) => `Branch ${name}`, items: ctxBranchItems},
|
|
{kind: "path", id: ctxAttr("data-path"), title: (path) => path, items: ctxPathItems},
|
|
{kind: "entry", id: ctxAttr("data-ref"), title: (ref) => ctxEntryOf(ref).title, items: ctxEntryItems},
|
|
{kind: "rule", id: ctxAttr("data-rule", "data-entry"), title: (id) => `Rule ${id}`, items: (node, id) => [ctxCopyItem("Copy rule", id)]},
|
|
{kind: "pick", id: ctxAttr("data-pick"), title: ctxPickTitle, items: ctxPickItems},
|
|
{kind: "pin", id: ctxPinOf, title: (target) => (ctxPinEntry(target) || {title: "Home pin"}).title, items: ctxPinItems},
|
|
{kind: "tile", id: (node) => (node.matches(".home-tile[data-pin]") ? node.dataset.pin : null), title: (key) => `Tile ${key}`, items: ctxTileItems},
|
|
];
|
|
|
|
/**
|
|
* @param target - the element a right-click or the menu key hit.
|
|
* @returns [{kind, id, node, entry}]: per kind of CTX_KINDS the nearest marked element from target up, nearest first.
|
|
*/
|
|
function ctxFound(target) {
|
|
const found = [];
|
|
for (let node = target; node; node = node.parentElement) {
|
|
for (const entry of CTX_KINDS.filter((kind) => !found.some((seen) => seen.kind === kind.kind))) {
|
|
const id = entry.id(node);
|
|
if (id) {
|
|
found.push({kind: entry.kind, id, node, entry});
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
function ctxOwn(found, items) {
|
|
const groups = found.map((seen) => ({seen, items: items.filter((item) => item.scope === seen.kind && item.id === seen.id)})).filter((group) => group.items.length);
|
|
const flat = groups.flatMap((group) => group.items);
|
|
return {title: groups.length ? groups[0].seen.entry.title(groups[0].seen.id) : "", items: flat.filter((item, index) => flat.findIndex((other) => other.label === item.label) === index)};
|
|
}
|
|
|
|
/**
|
|
* @param target - the element the menu is for.
|
|
* @returns [{scope, title, items}]: the element's own items, inside Match its Show filter, then the current tab's,
|
|
* then the general ones; empty sections left out.
|
|
*/
|
|
function ctxSections(target) {
|
|
const found = ctxFound(target);
|
|
const provided = found.flatMap((seen) => seen.entry.items(seen.node, seen.id).map((item) => ({...item, scope: seen.kind, id: seen.id})));
|
|
const items = [...paletteItems(), ...provided];
|
|
const own = ctxOwn(found, items);
|
|
const tab = Nav.TABS.find(([id]) => id === Nav.tabOf(ui.screen));
|
|
return [
|
|
{scope: "element", title: own.title, items: own.items},
|
|
{scope: "match-show", title: "Show", items: target.closest(CTX_MATCH) ? matchShowItems() : []},
|
|
...(tab ? [{scope: tab[0], title: tab[1], items: items.filter((item) => item.scope === tab[0])}] : []),
|
|
{scope: "general", title: "General", items: items.filter((item) => item.scope === "general")},
|
|
].filter((section) => section.items.length);
|
|
}
|
|
|
|
async function ctxCopy(text) {
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
toast("Copied", [revealed(text)], true);
|
|
} catch {
|
|
toast("Not copied", ["The browser refused the clipboard."], false);
|
|
}
|
|
}
|
|
|
|
function ctxNode() {
|
|
if (!ctxMenu.node) {
|
|
ctxMenu.node = h("div", {class: "ctx-menu", role: "menu", "aria-label": "Context menu", tabindex: -1, hidden: true, on: {keydown: ctxKeys}});
|
|
document.body.append(ctxMenu.node);
|
|
}
|
|
return ctxMenu.node;
|
|
}
|
|
|
|
/**
|
|
* @param item - {label, hint, run, face}; with checked, a function telling whether it is ticked now, it is a
|
|
* checkbox whose click keeps the menu open.
|
|
* @returns the menu entry.
|
|
*/
|
|
function ctxItem(item) {
|
|
const check = typeof item.checked === "function";
|
|
const node = h("button", {type: "button", role: check ? "menuitemcheckbox" : "menuitem", tabindex: -1, class: "ctx-item", title: revealed(item.hint), ...(check ? {"aria-checked": String(item.checked())} : {}), on: {click: () => ctxRun(item)}}, check ? h("span", {class: "ctx-check", "aria-hidden": "true"}, icon("bi-check-lg")) : null,
|
|
item.face ? face(item.face, false) : null, h("span", {class: "ctx-label"}, revealed(item.label)), h("span", {class: "muted"}, revealed(item.hint)));
|
|
if (check) {
|
|
ctxMenu.checks.push([node, item]);
|
|
}
|
|
return node;
|
|
}
|
|
|
|
function ctxGroup(section, index) {
|
|
return [index ? h("div", {role: "separator", class: "ctx-rule"}) : null,
|
|
h("div", {role: "group", class: "ctx-group", "aria-label": revealed(section.title), "data-scope": section.scope}, h("div", {class: "ctx-head", "aria-hidden": "true"}, revealed(section.title)), section.items.map(ctxItem))];
|
|
}
|
|
|
|
function ctxPlace(node, at) {
|
|
node.style.left = "0px";
|
|
node.style.top = "0px";
|
|
const box = node.getBoundingClientRect();
|
|
const below = at.y + box.height + CTX_GAP <= window.innerHeight;
|
|
node.style.left = `${Math.max(CTX_GAP, Math.min(at.x, window.innerWidth - box.width - CTX_GAP))}px`;
|
|
node.style.top = `${Math.max(CTX_GAP, Math.min(below ? at.y : at.y - box.height, window.innerHeight - box.height - CTX_GAP))}px`;
|
|
}
|
|
|
|
/**
|
|
* @param sections - what ctxSections gives.
|
|
* @param at - {x, y}, the viewport point the menu opens at; it moves inside the viewport when it would run past it.
|
|
*/
|
|
function ctxShow(sections, at) {
|
|
const node = ctxNode();
|
|
ctxMenu.checks = [];
|
|
node.replaceChildren(...sections.flatMap(ctxGroup).filter(Boolean));
|
|
node.hidden = false;
|
|
ctxPlace(node, at);
|
|
const first = node.querySelector(CTX_ITEMS);
|
|
if (first) {
|
|
first.focus({preventScroll: true});
|
|
}
|
|
}
|
|
|
|
function ctxOpen(target, at) {
|
|
closeMenus(null);
|
|
ctxMenu.back = document.activeElement;
|
|
diffView.hit = target;
|
|
ctxShow(ctxSections(target), at);
|
|
}
|
|
|
|
function ctxClose(restore) {
|
|
if (!ctxMenu.node || ctxMenu.node.hidden) {
|
|
return;
|
|
}
|
|
const back = ctxMenu.back;
|
|
const node = ctxMenu.node;
|
|
Object.assign(ctxMenu, {back: null, node: null, checks: []});
|
|
node.classList.add("closing");
|
|
node.hidden = true;
|
|
vanish(node);
|
|
if (restore && back && back.isConnected && typeof back.focus === "function") {
|
|
back.focus({preventScroll: true});
|
|
}
|
|
if (node.contains(document.activeElement)) {
|
|
document.activeElement.blur();
|
|
}
|
|
}
|
|
|
|
function ctxRun(item) {
|
|
if (typeof item.checked === "function") {
|
|
item.run();
|
|
ctxMenu.checks.forEach(([node, check]) => node.setAttribute("aria-checked", String(check.checked())));
|
|
return;
|
|
}
|
|
ctxClose(true);
|
|
item.run();
|
|
}
|
|
|
|
/**
|
|
* @param keep - the menu a click landed in, as closeMenus gets it; the context menu stays open when it is that menu.
|
|
*/
|
|
function ctxDismiss(keep) {
|
|
if (ctxMenu.node && ctxMenu.node !== keep) {
|
|
ctxClose(ctxMenu.node.contains(document.activeElement));
|
|
}
|
|
}
|
|
|
|
function ctxKeys(event) {
|
|
if (event.currentTarget !== ctxMenu.node) {
|
|
return;
|
|
}
|
|
const items = [...ctxMenu.node.querySelectorAll(CTX_ITEMS)];
|
|
const at = items.indexOf(document.activeElement);
|
|
const moves = {ArrowDown: at + 1, ArrowUp: Math.max(at, 0) - 1, Home: 0, End: items.length - 1};
|
|
if (Object.hasOwn(moves, event.key)) {
|
|
items[(moves[event.key] + items.length) % items.length].focus();
|
|
} else if (event.key === "Enter" || event.key === " ") {
|
|
items[Math.max(at, 0)].click();
|
|
} else if (CTX_MODIFIERS.includes(event.key)) {
|
|
return;
|
|
} else {
|
|
ctxClose(true);
|
|
}
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
|
|
function ctxContextMenu(event) {
|
|
const target = event.target;
|
|
if (!(target instanceof Element) || event.defaultPrevented) {
|
|
return;
|
|
}
|
|
if (ctxInside(target)) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
if (event.shiftKey || ctxField(target)) {
|
|
return;
|
|
}
|
|
event.preventDefault();
|
|
ctxOpen(target, {x: event.clientX, y: event.clientY});
|
|
}
|
|
|
|
function ctxKeydown(event) {
|
|
const pressed = event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey);
|
|
const target = document.activeElement;
|
|
if (!pressed || event.ctrlKey || event.altKey || event.metaKey || !(target instanceof Element) || ctxField(target) || ctxInside(target)) {
|
|
return;
|
|
}
|
|
event.preventDefault();
|
|
const box = target.getBoundingClientRect();
|
|
ctxOpen(target, {x: box.left, y: box.bottom});
|
|
}
|