@intentius/behold 0.29.41 → 0.29.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +32 -0
- package/dist/cli.js +111 -20
- package/package.json +1 -1
- package/web/carve-narration.js +32 -6
- package/web/carve-narration.test.js +31 -1
- package/web/dots.js +10 -10
- package/web/event-help-modal.js +1 -1
- package/web/index.html +192 -127
- package/web/kiosk-carve.js +26 -20
- package/web/kiosk-event-help-ui.js +1 -1
- package/web/kiosk-link.js +68 -0
- package/web/kiosk-link.test.js +69 -0
- package/web/kiosk-metrics.js +2 -2
- package/web/kiosk-trace.js +1 -1
- package/web/kiosk.html +186 -135
- package/web/kiosk.js +44 -1
- package/web/motion.js +42 -0
- package/web/motion.test.js +64 -0
- package/web/terralith.html +2 -2
- package/web/theme.js +99 -26
- package/web/theme.test.js +70 -6
- package/web/tooltip.js +212 -0
- package/web/tooltip.test.js +193 -0
- package/web/trunk-lane.js +160 -8
- package/web/trunk-lane.test.js +108 -1
package/web/tooltip.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// behold#725: one small tooltip for the page, in place of the browser's own
|
|
2
|
+
// for an SVG <title>. The browser's shows only under a resting mouse; this one
|
|
3
|
+
// also opens when a badge takes keyboard focus, closes on Escape, and is
|
|
4
|
+
// position: fixed, so a scrolling pane can't clip it. Screen readers get it
|
|
5
|
+
// through aria-describedby on the element it describes.
|
|
6
|
+
//
|
|
7
|
+
// The graph's marks keep their <title> elements as app.js draws them, so an
|
|
8
|
+
// exported SVG still carries every tooltip's words. While a mark is hovered or
|
|
9
|
+
// focused, its <title> is emptied (the browser then has nothing to show) and
|
|
10
|
+
// its words go into the shared tooltip; they go back when the pointer or the
|
|
11
|
+
// focus leaves. An HTML element can ask for the tooltip with data-tip.
|
|
12
|
+
|
|
13
|
+
export const TIP_ID = "b-tip";
|
|
14
|
+
/** The room between the tooltip and what it describes, and between it and the window's edge, in px. */
|
|
15
|
+
export const TIP_GAP = 8;
|
|
16
|
+
export const TIP_MARGIN = 8;
|
|
17
|
+
/** How long a pointer rests before the tooltip opens; focus opens it at once. */
|
|
18
|
+
export const HOVER_MS = 250;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Where the tooltip goes: centred under its target, above it when there is no
|
|
22
|
+
* room below, and kept inside the window's sides.
|
|
23
|
+
* `target` is a client rect, `size` the tooltip's, `view` the window's.
|
|
24
|
+
*/
|
|
25
|
+
export function placeTip(target, size, view, { gap = TIP_GAP, margin = TIP_MARGIN } = {}) {
|
|
26
|
+
const below = target.bottom + gap;
|
|
27
|
+
const above = target.top - gap - size.height;
|
|
28
|
+
const fitsBelow = below + size.height <= view.height - margin;
|
|
29
|
+
const side = fitsBelow || above < margin ? "below" : "above";
|
|
30
|
+
const top = side === "below" ? below : above;
|
|
31
|
+
const centred = (target.left + target.right) / 2 - size.width / 2;
|
|
32
|
+
const left = Math.max(margin, Math.min(centred, view.width - margin - size.width));
|
|
33
|
+
return { left: Math.round(left), top: Math.round(Math.max(margin, top)), side };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** An id list (aria-describedby) with `id` in it once. */
|
|
37
|
+
export function addId(list, id) {
|
|
38
|
+
const ids = String(list || "").split(/\s+/).filter(Boolean);
|
|
39
|
+
return ids.includes(id) ? ids.join(" ") : [...ids, id].join(" ");
|
|
40
|
+
}
|
|
41
|
+
/** An id list without `id`. */
|
|
42
|
+
export function dropId(list, id) {
|
|
43
|
+
return String(list || "").split(/\s+/).filter((x) => x && x !== id).join(" ");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const tagOf = (node) => String((node && (node.localName || node.tagName || node.nodeName)) || "").toLowerCase();
|
|
47
|
+
|
|
48
|
+
/** The <title> an SVG element carries as its own child, or null. */
|
|
49
|
+
export function ownTitle(node) {
|
|
50
|
+
for (const c of (node && node.children) || []) if (tagOf(c) === "title") return c;
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether an SVG element with a <title> is a badge, a mark drawn on a card or
|
|
56
|
+
* a box, which the keyboard should reach. The card itself, an edge and the
|
|
57
|
+
* drawing as a whole are not: the card has its own click, and a tab stop on
|
|
58
|
+
* every edge would bury the badges.
|
|
59
|
+
*/
|
|
60
|
+
export function isBadge(node) {
|
|
61
|
+
if (!node || !node.getAttribute) return false;
|
|
62
|
+
if (tagOf(node) === "svg") return false;
|
|
63
|
+
return !node.hasAttribute("data-node-id") && !node.hasAttribute("data-edge-from") && !node.hasAttribute("data-edge-via");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The element under `node` (or `node` itself) whose words a tooltip shows: the
|
|
68
|
+
* nearest with data-tip, or with a <title> child that has words. `current` is
|
|
69
|
+
* the element whose <title> is emptied while it is shown, so it still counts.
|
|
70
|
+
*/
|
|
71
|
+
export function tipHost(node, current = null) {
|
|
72
|
+
for (let n = node; n && n.nodeType === 1; n = n.parentNode) {
|
|
73
|
+
if (n === current) return n;
|
|
74
|
+
if (n.hasAttribute && n.hasAttribute("data-tip") && n.getAttribute("data-tip")) return n;
|
|
75
|
+
const t = ownTitle(n);
|
|
76
|
+
if (t && (t.textContent || "").trim()) return n;
|
|
77
|
+
if (tagOf(n) === "body") break;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Give every badge under `root` that has a <title> a tab stop. Returns how many it gave one. */
|
|
83
|
+
export function reachBadges(root) {
|
|
84
|
+
let n = 0;
|
|
85
|
+
if (!root || !root.querySelectorAll) return 0;
|
|
86
|
+
for (const t of root.querySelectorAll("svg title")) {
|
|
87
|
+
const host = t.parentNode;
|
|
88
|
+
if (!isBadge(host) || host.hasAttribute("tabindex") || !(t.textContent || "").trim()) continue;
|
|
89
|
+
host.setAttribute("tabindex", "0");
|
|
90
|
+
n++;
|
|
91
|
+
}
|
|
92
|
+
return n;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Wire the tooltip into `doc`. `scope` names the part of the page whose SVG
|
|
97
|
+
* badges get tab stops as they are drawn. A kiosk frame (the root's .bare) has
|
|
98
|
+
* its own popover and nothing to focus, so it gets neither.
|
|
99
|
+
*/
|
|
100
|
+
export function installTooltips(doc = typeof document !== "undefined" ? document : null, { scope = "#graph", setTimer = setTimeout, clearTimer = clearTimeout } = {}) {
|
|
101
|
+
if (!doc || !doc.documentElement || !doc.body) return () => {};
|
|
102
|
+
const off = () => doc.documentElement.classList && doc.documentElement.classList.contains("bare");
|
|
103
|
+
const win = doc.defaultView || (typeof window !== "undefined" ? window : null);
|
|
104
|
+
let tip = null;
|
|
105
|
+
let current = null; // { host, title, text, timer }
|
|
106
|
+
|
|
107
|
+
const ensureTip = () => {
|
|
108
|
+
if (tip) return tip;
|
|
109
|
+
tip = doc.getElementById(TIP_ID) || doc.createElement("div");
|
|
110
|
+
tip.id = TIP_ID;
|
|
111
|
+
tip.setAttribute("role", "tooltip");
|
|
112
|
+
tip.hidden = true;
|
|
113
|
+
if (!tip.parentNode) doc.body.appendChild(tip);
|
|
114
|
+
return tip;
|
|
115
|
+
};
|
|
116
|
+
const show = () => {
|
|
117
|
+
if (!current) return;
|
|
118
|
+
const t = ensureTip();
|
|
119
|
+
t.textContent = current.text;
|
|
120
|
+
t.hidden = false;
|
|
121
|
+
const r = current.host.getBoundingClientRect();
|
|
122
|
+
const s = t.getBoundingClientRect();
|
|
123
|
+
const view = { width: (win && win.innerWidth) || doc.documentElement.clientWidth, height: (win && win.innerHeight) || doc.documentElement.clientHeight };
|
|
124
|
+
const at = placeTip(r, { width: s.width, height: s.height }, view);
|
|
125
|
+
t.style.left = `${at.left}px`;
|
|
126
|
+
t.style.top = `${at.top}px`;
|
|
127
|
+
t.setAttribute("data-side", at.side);
|
|
128
|
+
current.host.setAttribute("aria-describedby", addId(current.host.getAttribute("aria-describedby"), TIP_ID));
|
|
129
|
+
};
|
|
130
|
+
const hideBubble = () => {
|
|
131
|
+
if (current && current.timer) { clearTimer(current.timer); current.timer = null; }
|
|
132
|
+
if (tip) tip.hidden = true;
|
|
133
|
+
};
|
|
134
|
+
const leave = () => {
|
|
135
|
+
if (!current) return;
|
|
136
|
+
hideBubble();
|
|
137
|
+
const { host, title, text } = current;
|
|
138
|
+
// Put the words back, unless app.js wrote new ones while they were out.
|
|
139
|
+
if (title && !(title.textContent || "").trim()) title.textContent = text;
|
|
140
|
+
const ids = dropId(host.getAttribute("aria-describedby"), TIP_ID);
|
|
141
|
+
if (ids) host.setAttribute("aria-describedby", ids);
|
|
142
|
+
else host.removeAttribute("aria-describedby");
|
|
143
|
+
current = null;
|
|
144
|
+
};
|
|
145
|
+
const enter = (host, delay) => {
|
|
146
|
+
if (current && current.host === host) return;
|
|
147
|
+
leave();
|
|
148
|
+
const title = host.hasAttribute("data-tip") ? null : ownTitle(host);
|
|
149
|
+
const text = title ? (title.textContent || "").trim() : host.getAttribute("data-tip");
|
|
150
|
+
if (!text) return;
|
|
151
|
+
// Emptied now, before the browser's own tooltip can rise.
|
|
152
|
+
if (title) title.textContent = "";
|
|
153
|
+
current = { host, title, text, timer: null };
|
|
154
|
+
if (delay > 0) current.timer = setTimer(show, delay);
|
|
155
|
+
else show();
|
|
156
|
+
};
|
|
157
|
+
const inside = (outer, node) => { for (let n = node; n; n = n.parentNode) if (n === outer) return true; return false; };
|
|
158
|
+
|
|
159
|
+
const onOver = (e) => {
|
|
160
|
+
if (off()) return;
|
|
161
|
+
const host = tipHost(e.target, current && current.host);
|
|
162
|
+
if (host) enter(host, HOVER_MS);
|
|
163
|
+
else if (current && !inside(current.host, e.target)) leave();
|
|
164
|
+
};
|
|
165
|
+
const onOut = (e) => { if (current && !inside(current.host, e.relatedTarget)) leave(); };
|
|
166
|
+
const onFocusIn = (e) => {
|
|
167
|
+
if (off()) return;
|
|
168
|
+
const host = tipHost(e.target, current && current.host);
|
|
169
|
+
if (host !== e.target) return;
|
|
170
|
+
// A click focuses a badge too; only the keyboard's focus opens the tooltip.
|
|
171
|
+
try { if (host.matches && !host.matches(":focus-visible")) return; } catch { /* an engine without :focus-visible opens it */ }
|
|
172
|
+
enter(host, 0);
|
|
173
|
+
};
|
|
174
|
+
const onFocusOut = () => leave();
|
|
175
|
+
const onKey = (e) => { if (e.key === "Escape" && current) hideBubble(); };
|
|
176
|
+
// A pan, a zoom or a scroll moves the target out from under a fixed tooltip.
|
|
177
|
+
const onMove = () => hideBubble();
|
|
178
|
+
|
|
179
|
+
doc.addEventListener("pointerover", onOver);
|
|
180
|
+
doc.addEventListener("pointerout", onOut);
|
|
181
|
+
doc.addEventListener("focusin", onFocusIn);
|
|
182
|
+
doc.addEventListener("focusout", onFocusOut);
|
|
183
|
+
doc.addEventListener("keydown", onKey);
|
|
184
|
+
doc.addEventListener("pointerdown", onMove, true);
|
|
185
|
+
doc.addEventListener("wheel", onMove, { capture: true, passive: true });
|
|
186
|
+
doc.addEventListener("scroll", onMove, true);
|
|
187
|
+
|
|
188
|
+
// Tab stops for the badges, as each frame is drawn.
|
|
189
|
+
let observer = null;
|
|
190
|
+
const area = doc.querySelector(scope);
|
|
191
|
+
const MO = win && win.MutationObserver;
|
|
192
|
+
if (area && MO) {
|
|
193
|
+
let queued = false;
|
|
194
|
+
const pass = () => { queued = false; if (!off()) reachBadges(area); };
|
|
195
|
+
observer = new MO(() => { if (!queued) { queued = true; Promise.resolve().then(pass); } });
|
|
196
|
+
observer.observe(area, { childList: true, subtree: true });
|
|
197
|
+
pass();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return () => {
|
|
201
|
+
leave();
|
|
202
|
+
if (observer) observer.disconnect();
|
|
203
|
+
doc.removeEventListener("pointerover", onOver);
|
|
204
|
+
doc.removeEventListener("pointerout", onOut);
|
|
205
|
+
doc.removeEventListener("focusin", onFocusIn);
|
|
206
|
+
doc.removeEventListener("focusout", onFocusOut);
|
|
207
|
+
doc.removeEventListener("keydown", onKey);
|
|
208
|
+
doc.removeEventListener("pointerdown", onMove, true);
|
|
209
|
+
doc.removeEventListener("wheel", onMove, { capture: true });
|
|
210
|
+
doc.removeEventListener("scroll", onMove, true);
|
|
211
|
+
};
|
|
212
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { HOVER_MS, TIP_ID, addId, dropId, installTooltips, isBadge, ownTitle, placeTip, reachBadges, tipHost } from "./tooltip.js";
|
|
3
|
+
|
|
4
|
+
// behold#725: a stand-in DOM, enough for the tooltip: elements with
|
|
5
|
+
// attributes, children, text and a rect, and a document with listeners.
|
|
6
|
+
class El {
|
|
7
|
+
constructor(tag, attrs = {}, kids = []) {
|
|
8
|
+
this.nodeType = 1;
|
|
9
|
+
this.localName = tag;
|
|
10
|
+
this.attrs = new Map(Object.entries(attrs));
|
|
11
|
+
this.children = [];
|
|
12
|
+
this.parentNode = null;
|
|
13
|
+
this._text = "";
|
|
14
|
+
this.hidden = false;
|
|
15
|
+
this.style = {};
|
|
16
|
+
this.rect = { left: 100, top: 100, right: 140, bottom: 120, width: 40, height: 20 };
|
|
17
|
+
this.focusVisible = true;
|
|
18
|
+
for (const k of kids) this.appendChild(typeof k === "string" ? Object.assign(new El("#text"), { _text: k }) : k);
|
|
19
|
+
}
|
|
20
|
+
get id() { return this.getAttribute("id") || ""; }
|
|
21
|
+
set id(v) { this.setAttribute("id", v); }
|
|
22
|
+
getAttribute(k) { return this.attrs.has(k) ? this.attrs.get(k) : null; }
|
|
23
|
+
setAttribute(k, v) { this.attrs.set(k, String(v)); }
|
|
24
|
+
hasAttribute(k) { return this.attrs.has(k); }
|
|
25
|
+
removeAttribute(k) { this.attrs.delete(k); }
|
|
26
|
+
appendChild(c) { c.parentNode = this; this.children.push(c); return c; }
|
|
27
|
+
get textContent() { return this.localName === "#text" ? this._text : this._text + this.children.map((c) => c.textContent).join(""); }
|
|
28
|
+
set textContent(v) { this.children = []; this._text = String(v); }
|
|
29
|
+
getBoundingClientRect() { return this.rect; }
|
|
30
|
+
matches(q) { return q === ":focus-visible" ? this.focusVisible : false; }
|
|
31
|
+
*walk() { for (const c of this.children) { yield c; yield* c.walk(); } }
|
|
32
|
+
querySelectorAll(q) {
|
|
33
|
+
if (q !== "svg title") return [];
|
|
34
|
+
const out = [];
|
|
35
|
+
for (const n of this.walk()) {
|
|
36
|
+
if (n.localName !== "title") continue;
|
|
37
|
+
for (let p = n.parentNode; p; p = p.parentNode) if (p.localName === "svg") { out.push(n); break; }
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const fakeDoc = (body, { bare = false } = {}) => {
|
|
43
|
+
const listeners = new Map();
|
|
44
|
+
const html = new El("html", {}, [body]);
|
|
45
|
+
html.classList = { contains: (c) => c === "bare" && bare };
|
|
46
|
+
html.clientWidth = 800;
|
|
47
|
+
html.clientHeight = 600;
|
|
48
|
+
const doc = {
|
|
49
|
+
documentElement: html,
|
|
50
|
+
body,
|
|
51
|
+
defaultView: { innerWidth: 800, innerHeight: 600 },
|
|
52
|
+
createElement: (tag) => new El(tag),
|
|
53
|
+
getElementById: (id) => [...html.walk()].find((n) => n.getAttribute && n.getAttribute("id") === id) || null,
|
|
54
|
+
querySelector: () => null,
|
|
55
|
+
addEventListener: (type, fn) => listeners.set(type, fn),
|
|
56
|
+
removeEventListener: (type) => listeners.delete(type),
|
|
57
|
+
fire: (type, e) => listeners.get(type) && listeners.get(type)(e),
|
|
58
|
+
};
|
|
59
|
+
html.parentNode = null;
|
|
60
|
+
return doc;
|
|
61
|
+
};
|
|
62
|
+
const graph = () => {
|
|
63
|
+
const badgeTitle = new El("title", {}, ["wave 2 · waiting\n(from terragucci's reports, not live)"]);
|
|
64
|
+
const badgeRect = new El("rect");
|
|
65
|
+
const badge = new El("g", { "data-tg-root": "badge" }, [badgeTitle, badgeRect]);
|
|
66
|
+
const cardTitle = new El("title", {}, ["still reading this member"]);
|
|
67
|
+
const card = new El("g", { "data-node-id": "a/b" }, [cardTitle, new El("rect"), badge]);
|
|
68
|
+
const edge = new El("g", { "data-edge-from": "a/b" }, [new El("title", {}, ["data dependency"])]);
|
|
69
|
+
const svg = new El("svg", {}, [card, edge]);
|
|
70
|
+
const body = new El("body", {}, [svg]);
|
|
71
|
+
return { body, svg, card, cardTitle, badge, badgeTitle, badgeRect, edge };
|
|
72
|
+
};
|
|
73
|
+
const timers = () => {
|
|
74
|
+
const queue = [];
|
|
75
|
+
return { setTimer: (fn, ms) => { queue.push({ fn, ms }); return queue.length; }, clearTimer: (i) => { if (queue[i - 1]) queue[i - 1].fn = () => {}; }, run: () => queue.splice(0).forEach((t) => t.fn()), queue };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
describe("placeTip (behold#725)", () => {
|
|
79
|
+
const view = { width: 800, height: 600 };
|
|
80
|
+
it("centres the tooltip under its target", () => {
|
|
81
|
+
expect(placeTip({ left: 100, right: 140, top: 100, bottom: 120 }, { width: 60, height: 30 }, view)).toEqual({ left: 90, top: 128, side: "below" });
|
|
82
|
+
});
|
|
83
|
+
it("goes above when there is no room below", () => {
|
|
84
|
+
expect(placeTip({ left: 100, right: 140, top: 560, bottom: 580 }, { width: 60, height: 30 }, view)).toEqual({ left: 90, top: 522, side: "above" });
|
|
85
|
+
});
|
|
86
|
+
it("stays inside the window's sides", () => {
|
|
87
|
+
expect(placeTip({ left: 0, right: 10, top: 10, bottom: 20 }, { width: 200, height: 30 }, view).left).toBe(8);
|
|
88
|
+
expect(placeTip({ left: 790, right: 800, top: 10, bottom: 20 }, { width: 200, height: 30 }, view).left).toBe(592);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("the id list (behold#725)", () => {
|
|
93
|
+
it("adds the tooltip's id once and takes it out again, keeping the others", () => {
|
|
94
|
+
expect(addId("", TIP_ID)).toBe(TIP_ID);
|
|
95
|
+
expect(addId(`x ${TIP_ID}`, TIP_ID)).toBe(`x ${TIP_ID}`);
|
|
96
|
+
expect(addId("x", TIP_ID)).toBe(`x ${TIP_ID}`);
|
|
97
|
+
expect(dropId(`x ${TIP_ID}`, TIP_ID)).toBe("x");
|
|
98
|
+
expect(dropId(null, TIP_ID)).toBe("");
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("the graph's badges (behold#725)", () => {
|
|
103
|
+
it("finds a mark's own <title> and the element whose words a tooltip shows", () => {
|
|
104
|
+
const g = graph();
|
|
105
|
+
expect(ownTitle(g.badge)).toBe(g.badgeTitle);
|
|
106
|
+
expect(tipHost(g.badgeRect)).toBe(g.badge);
|
|
107
|
+
expect(tipHost(g.card.children[1])).toBe(g.card);
|
|
108
|
+
expect(tipHost(g.svg)).toBe(null);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("counts a mark on a card as a badge, and the card, an edge and the drawing as not", () => {
|
|
112
|
+
const g = graph();
|
|
113
|
+
expect(isBadge(g.badge)).toBe(true);
|
|
114
|
+
expect(isBadge(g.card)).toBe(false);
|
|
115
|
+
expect(isBadge(g.edge)).toBe(false);
|
|
116
|
+
expect(isBadge(g.svg)).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("gives each badge with words a tab stop, once", () => {
|
|
120
|
+
const g = graph();
|
|
121
|
+
expect(reachBadges(g.body)).toBe(1);
|
|
122
|
+
expect(g.badge.getAttribute("tabindex")).toBe("0");
|
|
123
|
+
expect(g.card.hasAttribute("tabindex")).toBe(false);
|
|
124
|
+
expect(reachBadges(g.body)).toBe(0);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("installTooltips (behold#725)", () => {
|
|
129
|
+
it("opens on a resting pointer with the <title>'s words, which leave the <title> while it shows and come back after", () => {
|
|
130
|
+
const g = graph();
|
|
131
|
+
const doc = fakeDoc(g.body);
|
|
132
|
+
const t = timers();
|
|
133
|
+
installTooltips(doc, t);
|
|
134
|
+
doc.fire("pointerover", { target: g.badgeRect });
|
|
135
|
+
// Emptied at once, so the browser's own tooltip has nothing to show.
|
|
136
|
+
expect(g.badgeTitle.textContent).toBe("");
|
|
137
|
+
expect(t.queue[0].ms).toBe(HOVER_MS);
|
|
138
|
+
t.run();
|
|
139
|
+
const tip = doc.getElementById(TIP_ID);
|
|
140
|
+
expect(tip.getAttribute("role")).toBe("tooltip");
|
|
141
|
+
expect(tip.hidden).toBe(false);
|
|
142
|
+
expect(tip.textContent).toContain("wave 2 · waiting");
|
|
143
|
+
expect(g.badge.getAttribute("aria-describedby")).toBe(TIP_ID);
|
|
144
|
+
doc.fire("pointerout", { target: g.badgeRect, relatedTarget: g.svg });
|
|
145
|
+
expect(tip.hidden).toBe(true);
|
|
146
|
+
expect(g.badgeTitle.textContent).toContain("wave 2 · waiting");
|
|
147
|
+
expect(g.badge.hasAttribute("aria-describedby")).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("opens at once on keyboard focus, closes on Escape, and keeps the <title> empty until the focus leaves", () => {
|
|
151
|
+
const g = graph();
|
|
152
|
+
const doc = fakeDoc(g.body);
|
|
153
|
+
const t = timers();
|
|
154
|
+
installTooltips(doc, t);
|
|
155
|
+
doc.fire("focusin", { target: g.badge });
|
|
156
|
+
const tip = doc.getElementById(TIP_ID);
|
|
157
|
+
expect(tip.hidden).toBe(false);
|
|
158
|
+
doc.fire("keydown", { key: "Escape" });
|
|
159
|
+
expect(tip.hidden).toBe(true);
|
|
160
|
+
expect(g.badgeTitle.textContent).toBe("");
|
|
161
|
+
doc.fire("focusout", { target: g.badge });
|
|
162
|
+
expect(g.badgeTitle.textContent).toContain("wave 2 · waiting");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("stays shut on a click's focus", () => {
|
|
166
|
+
const g = graph();
|
|
167
|
+
g.badge.focusVisible = false;
|
|
168
|
+
const doc = fakeDoc(g.body);
|
|
169
|
+
installTooltips(doc, timers());
|
|
170
|
+
doc.fire("focusin", { target: g.badge });
|
|
171
|
+
expect(doc.getElementById(TIP_ID)).toBe(null);
|
|
172
|
+
expect(g.badgeTitle.textContent).toContain("wave 2");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("is placed fixed under its target", () => {
|
|
176
|
+
const g = graph();
|
|
177
|
+
const doc = fakeDoc(g.body);
|
|
178
|
+
installTooltips(doc, timers());
|
|
179
|
+
doc.fire("focusin", { target: g.badge });
|
|
180
|
+
const tip = doc.getElementById(TIP_ID);
|
|
181
|
+
expect(tip.style.top).toBe("128px");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("does nothing in a kiosk frame, which has its own popover", () => {
|
|
185
|
+
const g = graph();
|
|
186
|
+
const doc = fakeDoc(g.body, { bare: true });
|
|
187
|
+
const t = timers();
|
|
188
|
+
installTooltips(doc, t);
|
|
189
|
+
doc.fire("pointerover", { target: g.badgeRect });
|
|
190
|
+
expect(t.queue.length).toBe(0);
|
|
191
|
+
expect(g.badgeTitle.textContent).toContain("wave 2");
|
|
192
|
+
});
|
|
193
|
+
});
|
package/web/trunk-lane.js
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
// the promotion order chant declares: what the environment runs, and the
|
|
5
5
|
// gates waiting there, each with the approve button the gate strip uses
|
|
6
6
|
// (approveAffordance, #690), and the change set it binds as the link that
|
|
7
|
-
// draws it on the graph (#681).
|
|
7
|
+
// draws it on the graph (#681). Between the two, the releases cut from those
|
|
8
|
+
// commits (#692): each with its cut, a config-only mark, a revoked mark with
|
|
9
|
+
// the rollback line, where it runs and waits, and the environment it is
|
|
10
|
+
// promoted to next. Nothing here is behold's own state.
|
|
8
11
|
|
|
9
12
|
import { ago, clock } from "./terragucci.js";
|
|
10
13
|
import { approveAffordance, HOST_APPROVES, overrideCard } from "./workspace-gates.js";
|
|
@@ -60,6 +63,8 @@ export function commitRow(c, now = new Date()) {
|
|
|
60
63
|
const facts = [];
|
|
61
64
|
const work = workWords(c.work);
|
|
62
65
|
if (c.revoked) facts.push({ text: `revoked: ${c.revoked.phase || "a phase"} failed`, title: "" });
|
|
66
|
+
// #692: the releases cut from it.
|
|
67
|
+
if (c.cuts && c.cuts.length) facts.push({ text: `cut as ${c.cuts.map((x) => x.label || short(x.releaseDigest)).join(", ")}`, title: c.cuts.map((x) => `release ${x.releaseDigest} of ${x.member}`).join("\n") });
|
|
63
68
|
if (work) facts.push(work);
|
|
64
69
|
if (c.ignored && c.ignored.length) facts.push({ text: `${plural(c.ignored.length, "ci tag")} not counted`, title: c.ignored.map((t) => `${t.tag} (${t.status}): ${t.reason}`).join("\n") });
|
|
65
70
|
return {
|
|
@@ -78,21 +83,100 @@ export function commitRow(c, now = new Date()) {
|
|
|
78
83
|
export function runsLines(e, now = new Date()) {
|
|
79
84
|
const lines = [];
|
|
80
85
|
for (const r of e.releases || []) {
|
|
86
|
+
const rollback = r.rollback || [];
|
|
81
87
|
lines.push({
|
|
82
|
-
text: `runs ${r.label || short(r.releaseDigest)}, cut from ${sha7(r.commit)}${r.listed ? "" : " (older than the trunk list)"} · ${r.components.join(", ")}`,
|
|
83
|
-
title: [
|
|
88
|
+
text: `runs ${r.label || short(r.releaseDigest)}, cut from ${sha7(r.commit)}${r.listed ? "" : " (older than the trunk list)"} · ${r.components.join(", ")}${rollback.length ? " · revoked" : ""}`,
|
|
89
|
+
title: [
|
|
90
|
+
`release ${r.releaseDigest} of ${r.member}`,
|
|
91
|
+
r.cutBy ? `cut by ${r.cutBy}${r.cutAt ? ` ${clock(r.cutAt, now)}` : ""}` : "",
|
|
92
|
+
r.approver ? `deploy approved by ${r.approver}` : "",
|
|
93
|
+
...rollback.map((l) => `roll back: ${l}`),
|
|
94
|
+
]
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.join("\n"),
|
|
97
|
+
...(rollback.length ? { revoked: true } : {}),
|
|
84
98
|
});
|
|
85
99
|
}
|
|
86
100
|
for (const d of e.deploys || []) {
|
|
101
|
+
const from = d.release ? `release ${d.release.label || short(d.release.releaseDigest)}, ` : "";
|
|
87
102
|
lines.push({
|
|
88
|
-
text: `runs ${d.component} ${short(d.digest)} from ${sha7(d.gitSha)}${d.listed ? "" : " (older than the trunk list)"}`,
|
|
89
|
-
title: `deploy record of ${d.member}, run ${d.runId}, by ${d.actor} ${ago(d.timestamp, now)}${d.approver ? `, approved by ${d.approver}` : ""}`,
|
|
103
|
+
text: `runs ${d.component} ${short(d.digest)} from ${from}${sha7(d.gitSha)}${d.listed ? "" : " (older than the trunk list)"}${d.rollback ? " · revoked" : ""}`,
|
|
104
|
+
title: `deploy record of ${d.member}, run ${d.runId}, by ${d.actor} ${ago(d.timestamp, now)}${d.approver ? `, approved by ${d.approver}` : ""}${d.rollback ? `\nroll back: ${d.rollback}` : ""}`,
|
|
105
|
+
...(d.rollback ? { revoked: true } : {}),
|
|
90
106
|
});
|
|
91
107
|
}
|
|
92
108
|
if (!lines.length) lines.push({ text: "no deploy record", title: "chant has no deploy record for this environment, so behold does not say what runs here." });
|
|
93
109
|
return lines;
|
|
94
110
|
}
|
|
95
111
|
|
|
112
|
+
/** A release's name: its label, else its digest, short. */
|
|
113
|
+
const releaseName = (r) => (r ? r.label || short(r.releaseDigest) : "");
|
|
114
|
+
|
|
115
|
+
/** A cut's signature in words, from chant's own check of it (chant#4031). */
|
|
116
|
+
export function signatureWords(sig) {
|
|
117
|
+
if (!sig) return null;
|
|
118
|
+
if (sig.status === "verified") return { text: "signed", title: sig.reason || "chant verified the cut's signature." };
|
|
119
|
+
if (sig.status === "unsigned") return { text: "unsigned", title: sig.reason || "The cut carries no signature." };
|
|
120
|
+
return { text: "signature does not count", title: sig.reason || "" };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The note under the releases heading when the project's chant is below the column's floor. */
|
|
124
|
+
export function releaseColumnNote(a) {
|
|
125
|
+
if (!a || !a.releaseColumn || a.releaseColumn.full) return null;
|
|
126
|
+
return `chant ${a.chant || "(unknown version)"} does not say which releases are revoked; chant ${a.releaseColumn.floor} and newer does.`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* One release in the column (#692): its name and marks, its cut, where it is
|
|
131
|
+
* and where it goes next, and, when revoked, what failed and the line that
|
|
132
|
+
* rolls it back.
|
|
133
|
+
*/
|
|
134
|
+
export function releaseRow(r, now = new Date()) {
|
|
135
|
+
const marks = [];
|
|
136
|
+
if (r.configOnly) marks.push({ text: "config-only", cls: "lane-config-only", title: `The same artifact digests as ${releaseName(r.previous)}: only configuration changed.` });
|
|
137
|
+
if (r.revoked) marks.push({ text: "revoked", cls: "lane-revoked", title: `${r.revoked.tag}${r.revoked.tagged ? `, tagged ${clock(r.revoked.tagged, now)}` : ""}. chant promotes no revoked release and counts no approval of it.` });
|
|
138
|
+
const facts = [];
|
|
139
|
+
if (r.cut) {
|
|
140
|
+
facts.push({ text: `cut by ${r.cut.by} ${ago(r.cut.at, now)}`, title: clock(r.cut.at, now) });
|
|
141
|
+
const sig = signatureWords(r.cut.signature);
|
|
142
|
+
if (sig) facts.push(sig);
|
|
143
|
+
} else facts.push({ text: "no cut recorded", title: "chant stores the release, but no cut names it." });
|
|
144
|
+
if (r.artifacts === 0) facts.push({ text: "no artifact digests", title: "The member builds no image or asset, so no release of it is config-only." });
|
|
145
|
+
|
|
146
|
+
const where = [];
|
|
147
|
+
for (const x of r.runs) where.push({ text: `runs in ${x.env}`, title: x.components.join(", ") });
|
|
148
|
+
for (const w of r.waits) where.push(w.state === "superseded" ? { text: `gate in ${w.env} superseded`, title: `${w.gate}: its release is revoked, so no approval of it counts.` } : { text: `waits in ${w.env}`, title: `at gate ${w.gate}` });
|
|
149
|
+
if (r.next && !r.waits.some((w) => w.env === r.next)) where.push({ text: `next: ${r.next}`, title: "The next environment in the promotion order chant declares." });
|
|
150
|
+
if (!r.runs.length && !r.waits.length && !r.next) where.push({ text: "runs nowhere", title: "" });
|
|
151
|
+
|
|
152
|
+
const revoked = r.revoked
|
|
153
|
+
? {
|
|
154
|
+
text: `revoked: ${r.revoked.phase || "a required phase"} failed`,
|
|
155
|
+
run: r.revoked.run && r.revoked.run.url ? { text: r.revoked.run.name, href: r.revoked.run.url, title: r.revoked.run.conclusion ? `${r.revoked.run.name}: ${r.revoked.run.conclusion}` : r.revoked.run.name } : null,
|
|
156
|
+
rollback: r.revoked.rollback.map((l) => `roll back: ${l}`),
|
|
157
|
+
}
|
|
158
|
+
: null;
|
|
159
|
+
return {
|
|
160
|
+
key: r.releaseDigest,
|
|
161
|
+
head: `${releaseName(r)} · ${r.member}`,
|
|
162
|
+
cutFrom: `cut from ${sha7(r.commit)}${r.listed ? "" : " (older than the trunk list)"}`,
|
|
163
|
+
title: `release ${r.releaseDigest}\ncommit ${r.commit}${r.previous ? `\nprevious release ${releaseName(r.previous)}` : ""}`,
|
|
164
|
+
marks,
|
|
165
|
+
facts,
|
|
166
|
+
where,
|
|
167
|
+
revoked,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** A release gate chant reads as superseded, as a line in its environment. */
|
|
172
|
+
export function supersededLine(g, a) {
|
|
173
|
+
const r = ((a && a.releases) || []).find((x) => x.releaseDigest === g.releaseDigest);
|
|
174
|
+
return {
|
|
175
|
+
text: `${g.key} superseded: release ${r ? releaseName(r) : short(g.releaseDigest)} is revoked (${g.revoked.phase || "a required phase"} failed)`,
|
|
176
|
+
title: `${g.revoked.tag}\nchant approve refuses this gate, and chant promotes no revoked release.${g.runId ? `\nrun ${g.runId}` : ""}`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
96
180
|
/** One waiting gate as a card, with the gate strip's approve button (or the note in its place). */
|
|
97
181
|
export function laneGateCard(g, answer, { embed = false } = {}) {
|
|
98
182
|
if (g.override) {
|
|
@@ -122,7 +206,7 @@ export function laneGateCard(g, answer, { embed = false } = {}) {
|
|
|
122
206
|
/** The whole lane as words: the legend, the commits, and a lane per environment. Pure. */
|
|
123
207
|
export function laneView(a, now = new Date(), opts = {}) {
|
|
124
208
|
const legend = laneLegend(a, now);
|
|
125
|
-
if (!a || a.error || a.refusal) return { legend, notes: [], commits: [], environments: [] };
|
|
209
|
+
if (!a || a.error || a.refusal) return { legend, notes: [], commits: [], releases: null, environments: [] };
|
|
126
210
|
const notes = [];
|
|
127
211
|
if (a.order === "env" && a.environments.length) notes.push(`no member declares a promotion order, so this is ${a.environments[0].env} alone`);
|
|
128
212
|
for (const r of a.releaseRefusals || []) notes.push(`releases of ${r.member} not read: ${r.refusal.error}`);
|
|
@@ -131,11 +215,20 @@ export function laneView(a, now = new Date(), opts = {}) {
|
|
|
131
215
|
notes,
|
|
132
216
|
commits: (a.commits || []).map((c) => commitRow(c, now)),
|
|
133
217
|
empty: a.trunk && !(a.commits || []).length ? `no commits ${a.trunk.since ? `after ${sha7(a.trunk.since)}` : `within ${a.trunk.window}`}` : null,
|
|
218
|
+
// #692: null when the answer has no column (an older behold's export).
|
|
219
|
+
releases: a.releases
|
|
220
|
+
? {
|
|
221
|
+
note: releaseColumnNote(a),
|
|
222
|
+
empty: !a.releases.length ? "no release cut yet" : null,
|
|
223
|
+
rows: a.releases.map((r) => releaseRow(r, now)),
|
|
224
|
+
}
|
|
225
|
+
: null,
|
|
134
226
|
environments: (a.environments || []).map((e) => ({
|
|
135
227
|
env: e.env,
|
|
136
228
|
heading: e.canary ? `${e.env} (canary)` : e.env,
|
|
137
229
|
refusal: e.refusal ? `not read: ${e.refusal.error}` : null,
|
|
138
230
|
runs: e.refusal ? [] : runsLines(e, now),
|
|
231
|
+
superseded: (e.superseded || []).map((g) => supersededLine(g, a)),
|
|
139
232
|
gates: (e.waiting || []).filter((g) => g.state === "pending" || g.override).map((g) => laneGateCard(g, a, opts)),
|
|
140
233
|
})),
|
|
141
234
|
};
|
|
@@ -160,7 +253,7 @@ export function renderTrunkLane(host, a, now, ui) {
|
|
|
160
253
|
};
|
|
161
254
|
line(v.legend.tone === "refusal" ? "tg-refusal" : "tg-legend", v.legend.text, v.legend.title);
|
|
162
255
|
for (const n of v.notes) line("tg-legend", n);
|
|
163
|
-
if (!v.commits.length && !v.environments.length) return;
|
|
256
|
+
if (!v.commits.length && !v.environments.length && !(v.releases && v.releases.rows.length)) return;
|
|
164
257
|
|
|
165
258
|
const h = document.createElement("h3");
|
|
166
259
|
h.textContent = "trunk";
|
|
@@ -203,12 +296,71 @@ export function renderTrunkLane(host, a, now, ui) {
|
|
|
203
296
|
host.appendChild(row);
|
|
204
297
|
}
|
|
205
298
|
|
|
299
|
+
// #692: the release column, between the commits and the gates.
|
|
300
|
+
if (v.releases) {
|
|
301
|
+
const rh = document.createElement("h3");
|
|
302
|
+
rh.textContent = "releases";
|
|
303
|
+
host.appendChild(rh);
|
|
304
|
+
if (v.releases.note) line("tg-legend", v.releases.note);
|
|
305
|
+
if (v.releases.empty) line("tg-legend", v.releases.empty);
|
|
306
|
+
for (const r of v.releases.rows) {
|
|
307
|
+
const row = document.createElement("div");
|
|
308
|
+
row.className = "lane-release";
|
|
309
|
+
row.dataset.release = r.key;
|
|
310
|
+
row.title = r.title;
|
|
311
|
+
const head = document.createElement("div");
|
|
312
|
+
const name = document.createElement("span");
|
|
313
|
+
name.className = "lane-sha";
|
|
314
|
+
name.textContent = r.head;
|
|
315
|
+
head.append(name, document.createTextNode(` · ${r.cutFrom}`));
|
|
316
|
+
for (const m of r.marks) {
|
|
317
|
+
const mark = document.createElement("span");
|
|
318
|
+
mark.className = m.cls;
|
|
319
|
+
mark.textContent = ` · ${m.text}`;
|
|
320
|
+
mark.title = m.title;
|
|
321
|
+
head.appendChild(mark);
|
|
322
|
+
}
|
|
323
|
+
row.appendChild(head);
|
|
324
|
+
const parts = (cls, items) => {
|
|
325
|
+
const d = document.createElement("div");
|
|
326
|
+
d.className = cls;
|
|
327
|
+
items.forEach((f, i) => {
|
|
328
|
+
const sp = document.createElement("span");
|
|
329
|
+
sp.textContent = `${i ? " · " : ""}${f.text}`;
|
|
330
|
+
if (f.title) sp.title = f.title;
|
|
331
|
+
d.appendChild(sp);
|
|
332
|
+
});
|
|
333
|
+
row.appendChild(d);
|
|
334
|
+
return d;
|
|
335
|
+
};
|
|
336
|
+
parts("lane-facts", r.facts);
|
|
337
|
+
if (r.where.length) parts("lane-where", r.where);
|
|
338
|
+
if (r.revoked) {
|
|
339
|
+
const rv = parts("lane-revoked-why", [{ text: r.revoked.text }]);
|
|
340
|
+
if (r.revoked.run) {
|
|
341
|
+
rv.appendChild(document.createTextNode(" in "));
|
|
342
|
+
const a = ui && ui.link ? ui.link(r.revoked.run.text, r.revoked.run.href) : document.createTextNode(r.revoked.run.text);
|
|
343
|
+
if (a.title !== undefined) a.title = r.revoked.run.title;
|
|
344
|
+
rv.appendChild(a);
|
|
345
|
+
}
|
|
346
|
+
for (const l of r.revoked.rollback) {
|
|
347
|
+
const cmd = document.createElement("div");
|
|
348
|
+
cmd.className = "lane-rollback";
|
|
349
|
+
cmd.textContent = l;
|
|
350
|
+
row.appendChild(cmd);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
host.appendChild(row);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
206
357
|
for (const e of v.environments) {
|
|
207
358
|
const eh = document.createElement("h3");
|
|
208
359
|
eh.textContent = e.heading;
|
|
209
360
|
host.appendChild(eh);
|
|
210
361
|
if (e.refusal) line("tg-refusal", e.refusal);
|
|
211
|
-
for (const r of e.runs) line("lane-runs", r.text, r.title);
|
|
362
|
+
for (const r of e.runs) line(r.revoked ? "lane-runs lane-runs-revoked" : "lane-runs", r.text, r.title);
|
|
363
|
+
for (const g of e.superseded) line("lane-superseded", g.text, g.title);
|
|
212
364
|
for (const g of e.gates) {
|
|
213
365
|
const box = document.createElement("div");
|
|
214
366
|
box.className = "ws-gate";
|