@popcorn245/cornfield 0.61.0 → 0.63.0
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/core/release-notes.js +2 -2
- package/explorer/css/changes.css +3 -7
- package/explorer/css/header.css +15 -0
- package/explorer/css/layers.css +11 -2
- package/explorer/css/map.css +27 -0
- package/explorer/css/node-panel.css +45 -0
- package/explorer/css/page.css +2 -7
- package/explorer/css/proposal.css +2 -3
- package/explorer/css/work.css +7 -7
- package/explorer/engine/hint.js +7 -7
- package/explorer/engine/keyboard.js +5 -4
- package/explorer/engine/map-rect.js +2 -2
- package/explorer/engine/render.js +2 -1
- package/explorer/forge-panel-model.js +24 -0
- package/explorer/history-model.js +93 -12
- package/explorer/history-replay.js +318 -0
- package/explorer/history.js +40 -9
- package/explorer/index.html +7 -1
- package/explorer/instance-state.js +1 -0
- package/explorer/page.js +3 -0
- package/explorer/panel-model.js +103 -0
- package/explorer/panel-sections.js +140 -0
- package/explorer/pieces/layers.js +27 -6
- package/explorer/pieces/node-panel.js +80 -1
- package/explorer/pieces/search.js +22 -9
- package/explorer/pieces/work-deploys.js +13 -13
- package/explorer/pieces/work-issues.js +10 -5
- package/explorer/pieces/work-list.js +72 -9
- package/explorer/pieces/work-paint.js +45 -10
- package/explorer/pieces/work-prs.js +46 -34
- package/explorer/pieces/work-runs.js +17 -5
- package/explorer/pieces/work-specs.js +24 -4
- package/explorer/pieces/work-threads.js +59 -15
- package/explorer/pieces/work.js +6 -3
- package/explorer/proposal-model.js +3 -6
- package/explorer/runs-view.js +42 -8
- package/explorer/scene.js +35 -1
- package/explorer/work-model.js +266 -55
- package/explorer/work-view.css +9 -16
- package/explorer/work-view.js +107 -34
- package/package.json +1 -1
- package/server/server.js +1 -1
- package/server/work-graph.js +5 -5
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/history-replay
|
|
3
|
+
*
|
|
4
|
+
* Replay (spec 0014 D1): the map grows on a timeline, commit by commit, like cells in a dish. The layout is today's and never moves; at a commit
|
|
5
|
+
* the map holds only the nodes born by then and the lines between them (`state.replay`, which scene.js reads). A node being born buds out of its
|
|
6
|
+
* parent and settles into its place; the nodes a commit changed pulse once. Under reduced motion nothing buds or pulses: nodes simply appear,
|
|
7
|
+
* and a changed node wears a still ring for its step.
|
|
8
|
+
*
|
|
9
|
+
* The timeline is a strip along the bottom of the map: one mark per commit (its height how many nodes it touched, its colour its kind), the
|
|
10
|
+
* playhead, Play or Pause, a step back and forward, three speeds, Now (back to the map as it is), the commit at the playhead as a trail, and a
|
|
11
|
+
* count. The playhead is a range input, so the keyboard has it whole (arrows, Home, End, Page keys); a step says what was born and what changed.
|
|
12
|
+
*
|
|
13
|
+
* createReplay(inst, source) -> { start(at?), stop(), open(), repaint(), destroy() }
|
|
14
|
+
*
|
|
15
|
+
* `source` is history.js's: `{ ready(), history(), load(), links, specs() }`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { announce } from './engine/keyboard.js';
|
|
19
|
+
import { SPEEDS, commitKind, dayOf, parentsOf, replayCount, replayFrame, speedMs, stepWords, trailHtml } from './history-model.js';
|
|
20
|
+
import { escapeHtml as esc } from '../core/text.js';
|
|
21
|
+
import { redrawLayers } from './engine/layers.js';
|
|
22
|
+
|
|
23
|
+
/** How long a node takes to bud out of its parent (ms) */
|
|
24
|
+
export const BUD_MS = 520;
|
|
25
|
+
/** The tokens a mark is drawn in, by the commit's kind; a picked spec's commits get a dot in the last */
|
|
26
|
+
const MARK_TOKENS = { feat: '--corn-added', fix: '--corn-warn', docs: '--corn-accent', other: '--corn-text-3', spec: '--corn-history-week' };
|
|
27
|
+
const ease = (t) => 1 - (1 - t) ** 3;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {ReturnType<typeof import('./instance.js').createInstance>} inst
|
|
31
|
+
* @param {{ ready: () => boolean, history: () => object, load: () => Promise<void>, links: object | null, specs: () => Map<string, object> }} source
|
|
32
|
+
*/
|
|
33
|
+
export function createReplay(inst, source) {
|
|
34
|
+
const { state } = inst;
|
|
35
|
+
let strip = null;
|
|
36
|
+
let pulses = null;
|
|
37
|
+
let frame = null;
|
|
38
|
+
let parents = new Map();
|
|
39
|
+
let playing = false;
|
|
40
|
+
let speed = 1;
|
|
41
|
+
let acc = 0;
|
|
42
|
+
let last = null;
|
|
43
|
+
/** @type {Map<string, { x: number, y: number, start: number | null }>} the nodes budding, from where */
|
|
44
|
+
const buds = new Map();
|
|
45
|
+
let pulsedAt = -1;
|
|
46
|
+
let offFrames = null;
|
|
47
|
+
let offPaint = null;
|
|
48
|
+
|
|
49
|
+
const open = () => !!state.replay;
|
|
50
|
+
const byId = (id) => state.nodes.find((n) => n.id === id);
|
|
51
|
+
const labelOf = (id) => { const n = byId(id); return n ? String(n.label || n.id) : id; };
|
|
52
|
+
const stage = () => (state.canvas && state.canvas.parentElement) || null;
|
|
53
|
+
/** Replay's button, on the History row of the Layers menu (spec 0015 D6): it says pressed from `state.replay` each time the menu is drawn. Where the focus goes back when the
|
|
54
|
+
* timeline closes from inside: that button while the menu is open, else the menu's chip, else the map */
|
|
55
|
+
const returnFocus = () => {
|
|
56
|
+
const root = inst.root;
|
|
57
|
+
const find = (sel) => (root && root.querySelector ? root.querySelector(sel) : null);
|
|
58
|
+
const row = find('.hx-row-action[data-action="history-replay"]');
|
|
59
|
+
const to = row && !row.closest('[hidden]') ? row : find('[data-corn="layers-button"]') || state.canvas;
|
|
60
|
+
if (to && typeof to.focus === 'function') to.focus();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function wire() {
|
|
64
|
+
if (!inst.map) return;
|
|
65
|
+
if (!offFrames) offFrames = inst.map.addFrameClient({ wants: () => open() && (playing || buds.size > 0), tick });
|
|
66
|
+
if (!offPaint) offPaint = inst.map.onPaint((scene, camera) => placePulses(scene, camera));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Each frame: the playhead moves on while playing, and the buds grow */
|
|
70
|
+
function tick(now) {
|
|
71
|
+
if (!open()) return;
|
|
72
|
+
const dt = last === null ? 16 : Math.min(now - last, 250);
|
|
73
|
+
last = now;
|
|
74
|
+
if (playing) {
|
|
75
|
+
acc += dt;
|
|
76
|
+
const each = speedMs(frame.total, speed);
|
|
77
|
+
while (acc >= each && playing) {
|
|
78
|
+
acc -= each;
|
|
79
|
+
if (frame.at >= frame.total - 1) { setPlaying(false); announce(inst, `The end: ${replayCount(frame)}`); break; }
|
|
80
|
+
go(frame.at + 1, { bud: true });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (buds.size) {
|
|
84
|
+
const bud = new Map();
|
|
85
|
+
for (const [id, b] of buds) {
|
|
86
|
+
if (b.start === null) b.start = now;
|
|
87
|
+
const t = (now - b.start) / BUD_MS;
|
|
88
|
+
if (t >= 1) buds.delete(id); else bud.set(id, { x: b.x, y: b.y, t: ease(t) });
|
|
89
|
+
}
|
|
90
|
+
state.replay.bud = bud;
|
|
91
|
+
inst.touchScene();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Moves the playhead to a commit. `bud`: a step forward, so what was born there buds (a jump or a scrub just shows it). `say`: a screen reader hears the step.
|
|
97
|
+
*/
|
|
98
|
+
function go(at, { bud = false, say = false } = {}) {
|
|
99
|
+
const h = source.history();
|
|
100
|
+
frame = replayFrame(h, state.edges, at);
|
|
101
|
+
if (!bud || inst.reducedMotion) buds.clear();
|
|
102
|
+
else {
|
|
103
|
+
for (const id of frame.born) {
|
|
104
|
+
const p = byId(parents.get(id));
|
|
105
|
+
if (p && !frame.hidden.has(p.id)) buds.set(id, { x: p.x, y: p.y, start: null });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
state.replay = { at: frame.at, hidden: frame.hidden, bud: new Map([...buds].map(([id, b]) => [id, { x: b.x, y: b.y, t: 0 }])) };
|
|
109
|
+
state.historyAt = frame.at;
|
|
110
|
+
paintStrip();
|
|
111
|
+
inst.touchScene();
|
|
112
|
+
inst.emit('history:at');
|
|
113
|
+
if (inst.map) { inst.map.render(); inst.map.ensureFlowLoop(); }
|
|
114
|
+
if (say) announce(inst, stepWords(frame, { labelOf }));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function setPlaying(on) {
|
|
118
|
+
playing = !!on && !!frame && frame.at < frame.total - 1;
|
|
119
|
+
acc = 0;
|
|
120
|
+
last = null;
|
|
121
|
+
paintControls();
|
|
122
|
+
if (playing && inst.map) inst.map.ensureFlowLoop();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
// The strip
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
function buildStrip() {
|
|
129
|
+
const host = stage();
|
|
130
|
+
if (!host) return;
|
|
131
|
+
if (strip && strip.isConnected) return;
|
|
132
|
+
strip = inst.doc.createElement('div');
|
|
133
|
+
strip.className = 'hx-timeline glass';
|
|
134
|
+
strip.setAttribute('role', 'group');
|
|
135
|
+
strip.setAttribute('aria-label', 'Replay the map\'s history');
|
|
136
|
+
strip.innerHTML = `<div class="hx-timeline-bar">
|
|
137
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn" data-replay="back" aria-label="Step back a commit" title="Step back a commit">‹</button>
|
|
138
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn hx-timeline-play" data-replay="play" aria-label="Play">▶</button>
|
|
139
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn" data-replay="forward" aria-label="Step forward a commit" title="Step forward a commit">›</button>
|
|
140
|
+
<button type="button" data-corn-kind="icon" class="hx-timeline-btn hx-timeline-speed" data-replay="speed" aria-label="Speed 1×" title="Speed">1×</button>
|
|
141
|
+
<span class="hx-timeline-count hx-faint" aria-live="off"></span>
|
|
142
|
+
<button type="button" class="hx-btn hx-btn--quiet hx-textact" data-corn-kind="quiet" data-replay="now" title="Back to the map as it is now">Now</button>
|
|
143
|
+
</div>
|
|
144
|
+
<div class="hx-timeline-track">
|
|
145
|
+
<canvas class="hx-timeline-marks" aria-hidden="true"></canvas>
|
|
146
|
+
<input type="range" data-corn="control" class="hx-timeline-range" min="0" max="0" step="1" value="0" aria-label="Commit">
|
|
147
|
+
</div>
|
|
148
|
+
<div class="hx-timeline-line"></div>`;
|
|
149
|
+
strip.addEventListener('click', onClick);
|
|
150
|
+
const range = strip.querySelector('.hx-timeline-range');
|
|
151
|
+
range.addEventListener('input', () => { setPlaying(false); go(Number(range.value)); });
|
|
152
|
+
range.addEventListener('change', () => { if (frame) announce(inst, stepWords(frame, { labelOf })); });
|
|
153
|
+
host.append(strip);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function onClick(e) {
|
|
157
|
+
const b = e.target.closest('[data-replay]');
|
|
158
|
+
if (!b || !frame) return;
|
|
159
|
+
const what = b.getAttribute('data-replay');
|
|
160
|
+
if (what === 'play') setPlaying(!playing);
|
|
161
|
+
else if (what === 'back') { setPlaying(false); go(frame.at - 1, { say: true }); }
|
|
162
|
+
else if (what === 'forward') { setPlaying(false); go(frame.at + 1, { bud: true, say: true }); }
|
|
163
|
+
else if (what === 'speed') { speed = SPEEDS[(SPEEDS.indexOf(speed) + 1) % SPEEDS.length]; acc = 0; paintControls(); announce(inst, `Speed ${speed}×`); }
|
|
164
|
+
else if (what === 'now') stop();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function paintControls() {
|
|
168
|
+
if (!strip) return;
|
|
169
|
+
const play = strip.querySelector('[data-replay="play"]');
|
|
170
|
+
play.textContent = playing ? '❚❚' : '▶';
|
|
171
|
+
play.setAttribute('aria-label', playing ? 'Pause' : 'Play');
|
|
172
|
+
const sp = strip.querySelector('[data-replay="speed"]');
|
|
173
|
+
sp.textContent = `${speed}×`;
|
|
174
|
+
sp.setAttribute('aria-label', `Speed ${speed}×`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function paintStrip() {
|
|
178
|
+
if (!strip || !frame) return;
|
|
179
|
+
const c = frame.commit || {};
|
|
180
|
+
const range = strip.querySelector('.hx-timeline-range');
|
|
181
|
+
range.max = String(frame.total - 1);
|
|
182
|
+
range.value = String(frame.at);
|
|
183
|
+
range.setAttribute('aria-valuetext', `Commit ${frame.at + 1} of ${frame.total}, ${dayOf(c.date)}: ${c.subject || ''}`);
|
|
184
|
+
strip.querySelector('.hx-timeline-count').textContent = replayCount(frame);
|
|
185
|
+
strip.querySelector('[data-replay="back"]').disabled = frame.at <= 0;
|
|
186
|
+
strip.querySelector('[data-replay="forward"]').disabled = frame.at >= frame.total - 1;
|
|
187
|
+
strip.querySelector('.hx-timeline-line').innerHTML = `<span class="hx-faint">${esc(dayOf(c.date))}</span> <span class="hx-timeline-subject">${esc(c.subject || '')}</span> ${trailHtml(c, { links: source.links, specs: source.specs() })}`;
|
|
188
|
+
paintControls();
|
|
189
|
+
paintMarks();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The marks: one per commit, its height how many nodes it touched, its colour its kind; those after the playhead faint; a picked spec's commits dotted */
|
|
193
|
+
function paintMarks() {
|
|
194
|
+
const canvas = strip && strip.querySelector('.hx-timeline-marks');
|
|
195
|
+
if (!canvas || !frame) return;
|
|
196
|
+
const w = canvas.clientWidth || 0;
|
|
197
|
+
const hgt = canvas.clientHeight || 0;
|
|
198
|
+
let ctx = null;
|
|
199
|
+
try { ctx = w && hgt ? canvas.getContext('2d') : null; } catch { ctx = null; }
|
|
200
|
+
if (!ctx) return;
|
|
201
|
+
const ratio = (inst.doc.defaultView && inst.doc.defaultView.devicePixelRatio) || 1;
|
|
202
|
+
canvas.width = Math.round(w * ratio);
|
|
203
|
+
canvas.height = Math.round(hgt * ratio);
|
|
204
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
205
|
+
ctx.clearRect(0, 0, w, hgt);
|
|
206
|
+
const read = inst.tokenReader();
|
|
207
|
+
const colour = (k) => (read && read(MARK_TOKENS[k]).trim()) || 'gray';
|
|
208
|
+
const colours = Object.fromEntries(Object.keys(MARK_TOKENS).map((k) => [k, colour(k)]));
|
|
209
|
+
const commits = source.history().commits;
|
|
210
|
+
const n = commits.length;
|
|
211
|
+
const most = Math.max(1, ...commits.map((x) => (x.nodes ? x.nodes.length : 0)));
|
|
212
|
+
const pick = state.historyPick ? state.historyPick.spec : null;
|
|
213
|
+
const step = n > 1 ? (w - 4) / (n - 1) : 0;
|
|
214
|
+
const barW = Math.max(1, Math.min(4, step * 0.7));
|
|
215
|
+
for (let i = 0; i < n; i++) {
|
|
216
|
+
const x = 2 + i * step;
|
|
217
|
+
const k = commits[i].nodes ? commits[i].nodes.length : 0;
|
|
218
|
+
const h = Math.max(2, (hgt - 8) * Math.sqrt(k / most));
|
|
219
|
+
ctx.globalAlpha = i <= frame.at ? 1 : 0.3;
|
|
220
|
+
ctx.fillStyle = colours[commitKind(commits[i].subject)];
|
|
221
|
+
ctx.fillRect(x - barW / 2, hgt - h, barW, h);
|
|
222
|
+
if (pick && commits[i].specs && commits[i].specs.includes(pick)) {
|
|
223
|
+
ctx.globalAlpha = 1;
|
|
224
|
+
ctx.fillStyle = colours.spec;
|
|
225
|
+
ctx.beginPath();
|
|
226
|
+
ctx.arc(x, 3, 2.5, 0, Math.PI * 2);
|
|
227
|
+
ctx.fill();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
ctx.globalAlpha = 1;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
// The pulses: a ring on each node the commit at the playhead changed, once
|
|
235
|
+
// ---------------------------------------------------------------------------
|
|
236
|
+
function placePulses(scene, camera) {
|
|
237
|
+
if (!open() || !frame) { if (pulses) { pulses.remove(); pulses = null; } return; }
|
|
238
|
+
const host = stage();
|
|
239
|
+
if (!host) return;
|
|
240
|
+
if (!pulses || !pulses.isConnected) {
|
|
241
|
+
pulses = inst.doc.createElement('div');
|
|
242
|
+
pulses.className = 'hx-replay-pulses';
|
|
243
|
+
pulses.setAttribute('aria-hidden', 'true');
|
|
244
|
+
host.append(pulses);
|
|
245
|
+
pulsedAt = -1;
|
|
246
|
+
}
|
|
247
|
+
pulses.classList.toggle('is-static', !!inst.reducedMotion);
|
|
248
|
+
if (pulsedAt !== frame.at) { pulses.innerHTML = ''; pulsedAt = frame.at; }
|
|
249
|
+
const want = new Set(frame.changed);
|
|
250
|
+
const have = new Map([...pulses.children].map((el) => [el.dataset.node, el]));
|
|
251
|
+
for (const node of scene.nodes) {
|
|
252
|
+
if (!want.has(node.id)) continue;
|
|
253
|
+
let el = have.get(node.id);
|
|
254
|
+
if (!el) {
|
|
255
|
+
el = inst.doc.createElement('span');
|
|
256
|
+
el.className = 'hx-replay-pulse';
|
|
257
|
+
el.dataset.node = node.id;
|
|
258
|
+
if (frame.born.includes(node.id)) el.dataset.born = '';
|
|
259
|
+
pulses.append(el);
|
|
260
|
+
}
|
|
261
|
+
el.style.left = `${(node.x * camera.zoom + camera.x).toFixed(1)}px`;
|
|
262
|
+
el.style.top = `${(node.y * camera.zoom + camera.y).toFixed(1)}px`;
|
|
263
|
+
el.style.setProperty('--r', `${(Math.max(6, node.r * camera.zoom) + 4).toFixed(1)}px`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ---------------------------------------------------------------------------
|
|
268
|
+
// Opening and closing
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
async function start(at = 0) {
|
|
271
|
+
if (state.view !== 'orbit') return;
|
|
272
|
+
if (!source.ready()) {
|
|
273
|
+
announce(inst, 'Reading the history…');
|
|
274
|
+
await source.load();
|
|
275
|
+
if (!source.ready()) { announce(inst, 'The history could not be read, so there is nothing to replay.'); return; }
|
|
276
|
+
}
|
|
277
|
+
const h = source.history();
|
|
278
|
+
if (!h.commits.length) { announce(inst, 'The history has no commit to replay.'); return; }
|
|
279
|
+
parents = parentsOf(state.edges);
|
|
280
|
+
wire();
|
|
281
|
+
buildStrip();
|
|
282
|
+
go(at, { say: true });
|
|
283
|
+
redrawLayers(inst); // Replay says pressed
|
|
284
|
+
setPlaying(!inst.reducedMotion && at === 0);
|
|
285
|
+
if (strip) strip.querySelector(playing ? '[data-replay="play"]' : '.hx-timeline-range').focus();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function stop() {
|
|
289
|
+
if (!open()) return;
|
|
290
|
+
const had = strip && strip.contains(inst.active());
|
|
291
|
+
setPlaying(false);
|
|
292
|
+
buds.clear();
|
|
293
|
+
state.replay = null;
|
|
294
|
+
state.historyAt = null;
|
|
295
|
+
frame = null;
|
|
296
|
+
if (strip) { strip.remove(); strip = null; }
|
|
297
|
+
if (pulses) { pulses.remove(); pulses = null; }
|
|
298
|
+
redrawLayers(inst);
|
|
299
|
+
if (had) returnFocus();
|
|
300
|
+
inst.touchScene();
|
|
301
|
+
inst.emit('history:at');
|
|
302
|
+
if (inst.map) inst.map.render();
|
|
303
|
+
announce(inst, 'Back to the map as it is now');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return {
|
|
307
|
+
start,
|
|
308
|
+
stop,
|
|
309
|
+
open,
|
|
310
|
+
/** The strip again: a pick changed (its commits' dots), or the theme */
|
|
311
|
+
repaint: () => paintStrip(),
|
|
312
|
+
destroy() {
|
|
313
|
+
stop();
|
|
314
|
+
if (offFrames) { offFrames(); offFrames = null; }
|
|
315
|
+
if (offPaint) { offPaint(); offPaint = null; }
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
package/explorer/history.js
CHANGED
|
@@ -18,12 +18,16 @@
|
|
|
18
18
|
* history:all (none) (emit) the section lists every commit, not only the newest
|
|
19
19
|
* history:changed (none) (emitted) the read ended, or a pick changed: the open panel draws its History section again
|
|
20
20
|
* history:legend { active } (emitted) the History layer is drawn: the Layers menu shows its legend
|
|
21
|
+
* history:replay at? (emit) open Replay (history-replay.js) at a commit, or close it when it is open and no commit is named;
|
|
22
|
+
* the Layers menu's Replay (on the History row, spec 0015 D6) asks it, with the History layer turned on first
|
|
23
|
+
* history:at (none) (emitted) the timeline's commit moved (`state.historyAt`): the halos follow it
|
|
21
24
|
*/
|
|
22
25
|
|
|
23
26
|
import { credentialed } from './engine/connection.js';
|
|
24
27
|
import { announce } from './engine/keyboard.js';
|
|
25
|
-
import { onLayersChange, redrawLayers } from './engine/layers.js';
|
|
28
|
+
import { onLayersChange, redrawLayers, setLayer } from './engine/layers.js';
|
|
26
29
|
import { layerOn } from './layer-model.js';
|
|
30
|
+
import { createReplay } from './history-replay.js';
|
|
27
31
|
import { HISTORY_LAYER, MAX_HALOS, forgeLinks, haloWidth, heatOf, historyRowOf, historySectionHtml, specBarHtml, specFiles, specReach } from './history-model.js';
|
|
28
32
|
|
|
29
33
|
/** Where the server answers the history (server/server.js) */
|
|
@@ -37,10 +41,8 @@ export const HISTORY_PATH = '/api/history';
|
|
|
37
41
|
export function initHistory(inst, config) {
|
|
38
42
|
/** The dot of the Layers menu's row: this week's halo colour, as the theme has it */
|
|
39
43
|
const haloColor = () => {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const v = root && view && view.getComputedStyle ? view.getComputedStyle(root).getPropertyValue('--corn-history-week').trim() : '';
|
|
43
|
-
return v || 'currentColor';
|
|
44
|
+
const read = inst.tokenReader();
|
|
45
|
+
return (read && read('--corn-history-week').trim()) || 'currentColor';
|
|
44
46
|
};
|
|
45
47
|
const { state } = inst;
|
|
46
48
|
const on = !!(config && config.history === true);
|
|
@@ -138,8 +140,12 @@ export function initHistory(inst, config) {
|
|
|
138
140
|
if (inst.map) inst.map.render();
|
|
139
141
|
}
|
|
140
142
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
let reading = null;
|
|
144
|
+
function load() {
|
|
145
|
+
if (mem.status === 'idle') reading = read();
|
|
146
|
+
return reading || Promise.resolve();
|
|
147
|
+
}
|
|
148
|
+
async function read() {
|
|
143
149
|
mem.status = 'loading';
|
|
144
150
|
try {
|
|
145
151
|
const res = await credentialed(inst)(HISTORY_PATH);
|
|
@@ -172,9 +178,34 @@ export function initHistory(inst, config) {
|
|
|
172
178
|
inst.emit('history:changed');
|
|
173
179
|
}
|
|
174
180
|
|
|
181
|
+
const replay = mem.status === 'off' ? null : createReplay(inst, {
|
|
182
|
+
ready: () => mem.status === 'ready',
|
|
183
|
+
history: () => mem.history,
|
|
184
|
+
load,
|
|
185
|
+
links: mem.links,
|
|
186
|
+
specs: () => { if (!mem.specs) mem.specs = specFiles(state.nodes); return mem.specs; },
|
|
187
|
+
});
|
|
188
|
+
|
|
175
189
|
if (mem.status !== 'off') {
|
|
176
|
-
|
|
177
|
-
|
|
190
|
+
stops.push(inst.on('history:replay', (at) => {
|
|
191
|
+
if (Number.isInteger(at)) { if (replay.open()) replay.stop(); replay.start(at); return; }
|
|
192
|
+
if (replay.open()) replay.stop(); else replay.start(0);
|
|
193
|
+
}));
|
|
194
|
+
stops.push(inst.on('view', () => { if (state.view !== 'orbit' && replay.open()) replay.stop(); }));
|
|
195
|
+
stops.push(inst.on('history:changed', () => { if (replay.open()) replay.repaint(); }));
|
|
196
|
+
stops.push(() => replay.destroy());
|
|
197
|
+
// Replay on the Layers menu's History row (spec 0015 D6): pressed, it turns the History layer on and opens the timeline; pressed again, it closes it
|
|
198
|
+
// (page.js, which hears the click first, goes to the Map view from another)
|
|
199
|
+
if (inst.root && inst.root.addEventListener) {
|
|
200
|
+
stops.push(inst.listen(inst.root, 'click', (e) => {
|
|
201
|
+
const press = e.target && e.target.closest ? e.target.closest('.hx-row-action[data-action="history-replay"]') : null;
|
|
202
|
+
if (!press) return;
|
|
203
|
+
if (!replay.open()) setLayer(inst, HISTORY_LAYER, true, { viewer: true });
|
|
204
|
+
inst.emit('history:replay');
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
// The Layers menu's row under Overlays (engine/layers.js `layerRows`), in the colour of this week's halo, with Replay on it (spec 0015 D6)
|
|
208
|
+
state.historyRow = () => historyRowOf(mem.status, mem.status === 'ready' ? heatNow() : null, haloColor(), { replaying: replay.open() });
|
|
178
209
|
stops.push(onLayersChange(inst, layerChanged));
|
|
179
210
|
if (inst.map) stops.push(inst.map.onPaint((scene, camera) => syncHalos(scene, camera)));
|
|
180
211
|
stops.push(inst.on('history:at', () => { placed = ''; if (inst.map) inst.map.render(); redrawLayers(inst); }));
|
package/explorer/index.html
CHANGED
|
@@ -63,13 +63,18 @@
|
|
|
63
63
|
</button>
|
|
64
64
|
</div>
|
|
65
65
|
|
|
66
|
+
<!-- The controls of the view that is on (spec 0015 D5), then the Layers chip. In the Work view: Waiting on you (a toggle) and List, which explorer/work-view.js puts in the group;
|
|
67
|
+
the Map's Replay is on the History row of the Layers menu (D6). On a phone the two sit on the map's top-left row, the Layers chip first -->
|
|
68
|
+
<div class="hx-view-tools">
|
|
69
|
+
<div class="hx-view-controls" role="group" aria-label="Work view" data-corn="view-controls" hidden></div>
|
|
70
|
+
|
|
66
71
|
<!-- The Layers chip: how many of the layers are on; it opens the layers menu. On a phone it sits on the map, top left. It is a piece (explorer/pieces/layers.js): page.js mounts it here. Until then a stand-in (its markup without ids) holds its place, so the first paint has the chip and nothing moves when the piece comes; test/explorer/page-pieces.test.js keeps the two the same -->
|
|
67
72
|
<!--corn-placeholder:layers/menu-->
|
|
68
73
|
<div class="hx-menu-wrap hx-layers">
|
|
69
74
|
<button type="button" class="hx-layers-chip" data-action="toggle-layers-menu" aria-expanded="false" data-corn="layers-button" part="layers-button"><span data-corn-string="layers">Layers</span><span class="hx-layers-count" data-corn="count" part="count"></span></button>
|
|
70
75
|
<div class="hx-menu glass" hidden data-corn="layers-menu" part="layers-menu">
|
|
71
76
|
<div class="hx-menu-title hx-menu-head" data-corn="menu-title" part="menu-title">
|
|
72
|
-
<span>
|
|
77
|
+
<span>Layers</span>
|
|
73
78
|
<span class="hx-menu-links">
|
|
74
79
|
<button type="button" class="hx-textbtn hx-textbtn--accent" data-action="layers-all" data-corn="layers-all" part="layers-all" data-corn-kind="quiet" data-corn-string="layersAll">All</button>
|
|
75
80
|
<span class="hx-faint">•</span>
|
|
@@ -105,6 +110,7 @@
|
|
|
105
110
|
</div>
|
|
106
111
|
</div>
|
|
107
112
|
<!--corn-piece:layers/menu-->
|
|
113
|
+
</div>
|
|
108
114
|
|
|
109
115
|
<!-- The live layer's chip (explorer/live.js, spec 0029): shown once a live layer is on; a dot on a phone, its line on tap -->
|
|
110
116
|
<div id="live-wrap" class="hx-menu-wrap hx-live" data-tone="idle" hidden>
|
|
@@ -46,6 +46,7 @@ export function createState() {
|
|
|
46
46
|
/** The spec picked in a node's History (history.js, spec 0014 D3): `{ spec, nodes }`, the nodes its commits touched, lit while the rest dims; or null */
|
|
47
47
|
historyPick: null,
|
|
48
48
|
historyAt: null, // the timeline's commit (spec 0014 D1), an index into the history; null is the newest
|
|
49
|
+
replay: null, // Replay (history-replay.js, spec 0014 D1): { at, hidden: Set of the nodes not born yet, bud: Map of the nodes budding }
|
|
49
50
|
historyRow: null, // the History layer's row in the Layers menu (history.js), while the config has history on
|
|
50
51
|
/** The id of the search match the stepping is on (search.js), or null: the map draws its halo and places its label first of the matches */
|
|
51
52
|
searchCurrent: null,
|
package/explorer/page.js
CHANGED
|
@@ -116,6 +116,9 @@ const ACTIONS = {
|
|
|
116
116
|
setView(state.view === 'dataflow' ? 'orbit' : 'dataflow');
|
|
117
117
|
},
|
|
118
118
|
'play-outage': (el) => playOutage(el.dataset.id), // the cloud panel's Play button (spec 0031 section 8)
|
|
119
|
+
'history-replay': () => { // Replay (spec 0014 D1), on the Layers menu's History row (spec 0015 D6), runs on the Map view: from another view it goes there first (history.js, which hears the click after this, opens it)
|
|
120
|
+
if (state.view !== 'orbit') { closeDrawer(); setView('orbit'); }
|
|
121
|
+
},
|
|
119
122
|
'retry': () => loadTopology(),
|
|
120
123
|
'set-theme': (el) => setThemeChoice(el.dataset.choice),
|
|
121
124
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/panel-model
|
|
3
|
+
*
|
|
4
|
+
* The node panel's shape (spec 0015 D4), as strings and plain data: the action bar that leads it, the one "Next" line under the bar, the sections that
|
|
5
|
+
* fold behind their title and count, and what the browser remembers of which are open, per kind of node. Pure: no DOM, no storage of its own
|
|
6
|
+
* (explorer/panel-sections.js reads and writes the browser's and wires the clicks).
|
|
7
|
+
*
|
|
8
|
+
* actionBarHtml({ primary, others, next }) the bar: the one next action first, the next two beside it, the rest under ⋯
|
|
9
|
+
* nextHtml(words) "Then: approve, and Land it once docs finishes (1 check running)."
|
|
10
|
+
* sectionHtml({ key, title, count, note, body, open }) a section with its count, closed unless it holds the action
|
|
11
|
+
* groupLinks(links) a node's Connected rows grouped by relation, in the order first seen
|
|
12
|
+
* readPrefs(text), isOpen(prefs, kind, key, fallback), withOpen(prefs, kind, key, open) what is remembered
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { escapeHtml as esc } from '../core/text.js';
|
|
16
|
+
|
|
17
|
+
/** How many actions sit beside the primary one before the rest go under ⋯ */
|
|
18
|
+
export const BESIDE = 2;
|
|
19
|
+
|
|
20
|
+
/** The browser's key for which sections are open, per kind of node */
|
|
21
|
+
export const SECTIONS_KEY = 'cornfield.panel.sections';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The action bar: the primary action, the next ones beside it, the rest under ⋯ (a disclosure: a button that shows a group of buttons, reached with Tab, closed by Escape),
|
|
25
|
+
* then the Next line. Each action is the markup of a button or a link, as its part draws it today (its data attributes are what its click does). '' with nothing to show.
|
|
26
|
+
* @param {{ primary?: string, others?: string[], next?: string }} parts
|
|
27
|
+
*/
|
|
28
|
+
export function actionBarHtml({ primary = '', others = [], next = '' } = {}) {
|
|
29
|
+
const rest = others.filter(Boolean);
|
|
30
|
+
const first = primary || rest.shift() || '';
|
|
31
|
+
if (!first && !next) return '';
|
|
32
|
+
const beside = rest.slice(0, BESIDE);
|
|
33
|
+
const more = rest.slice(BESIDE);
|
|
34
|
+
const menu = more.length
|
|
35
|
+
? `<div class="hx-actions-more"><button type="button" class="hx-btn hx-btn--quiet hx-actions-more-btn" data-corn="more" data-corn-kind="quiet" data-more-toggle aria-expanded="false" aria-label="More actions" title="More actions">⋯</button><div class="hx-actions-menu glass" data-more-menu role="group" aria-label="More actions" hidden>${more.join('')}</div></div>`
|
|
36
|
+
: '';
|
|
37
|
+
const row = first ? `<div class="hx-actions-row">${first}${beside.join('')}${menu}</div>` : '';
|
|
38
|
+
return `<div class="hx-actions" data-corn="actions" role="group" aria-label="Actions">${row}${nextHtml(next)}</div>`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The one line under the bar that says what comes before an action can be taken; '' when nothing waits */
|
|
42
|
+
export const nextHtml = (words) => (words ? `<p class="hx-next">${esc(words)}</p>` : '');
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A section of the panel: its title and count on a button that opens and closes it (`aria-expanded`), its body under it. `open` is where it starts: closed unless it holds
|
|
46
|
+
* the action; the browser's memory of it, per kind of node, is put on it once it is drawn (panel-sections.js `applySections`).
|
|
47
|
+
* @param {{ key: string, title: string, count?: number | null, note?: string, body: string, open?: boolean, extra?: string }} s `note`: a few words after the count ("1 failed")
|
|
48
|
+
*/
|
|
49
|
+
export function sectionHtml({ key, title, count = null, note = '', body, open = false, extra = '' }) {
|
|
50
|
+
const n = Number.isInteger(count) ? ` <span class="hx-sec-count" data-corn="count">${count}</span>` : '';
|
|
51
|
+
const said = note ? ` <span class="hx-sec-note">· ${esc(note)}</span>` : '';
|
|
52
|
+
return `<div class="hx-sec-block hx-psec" data-corn="section" data-sec="${esc(key)}"${extra}>`
|
|
53
|
+
+ `<h3 class="hx-sec-title"><button type="button" class="hx-sec-toggle" data-corn-kind="quiet" data-sec-toggle="${esc(key)}" data-sec-default="${open}" aria-expanded="${open}"><span class="hx-sec-name">${esc(title)}</span>${n}${said}</button></h3>`
|
|
54
|
+
+ `<div class="hx-sec-body"${open ? '' : ' hidden'}>${body}</div></div>`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A node's connections grouped by relation, each group in the order its first row came: `[{ rel, rows }]`.
|
|
59
|
+
* @template {{ rel: string }} T
|
|
60
|
+
* @param {T[]} links
|
|
61
|
+
* @returns {{ rel: string, rows: T[] }[]}
|
|
62
|
+
*/
|
|
63
|
+
export function groupLinks(links) {
|
|
64
|
+
const groups = new Map();
|
|
65
|
+
for (const l of links || []) {
|
|
66
|
+
if (!groups.has(l.rel)) groups.set(l.rel, []);
|
|
67
|
+
groups.get(l.rel).push(l);
|
|
68
|
+
}
|
|
69
|
+
return [...groups].map(([rel, rows]) => ({ rel, rows }));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** "Discussed in", "Adds": a relation's words at the start of a row */
|
|
73
|
+
export const relTitle = (rel) => String(rel).charAt(0).toUpperCase() + String(rel).slice(1);
|
|
74
|
+
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// What the browser remembers: { [kind of node]: { [section]: open } }
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
/** What was stored, or nothing remembered (a broken or foreign value reads as nothing) */
|
|
80
|
+
export function readPrefs(text) {
|
|
81
|
+
if (typeof text !== 'string' || !text) return {};
|
|
82
|
+
try {
|
|
83
|
+
const v = JSON.parse(text);
|
|
84
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : {};
|
|
85
|
+
} catch {
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Whether a kind's section is open: what was remembered, else `fallback` */
|
|
91
|
+
export function isOpen(prefs, kind, key, fallback) {
|
|
92
|
+
const k = prefs && Object.hasOwn(prefs, kind) ? prefs[kind] : null;
|
|
93
|
+
return k && typeof k === 'object' && typeof k[key] === 'boolean' ? k[key] : !!fallback;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The prefs with one section of one kind remembered open or closed (a new object; the old is not changed) */
|
|
97
|
+
export function withOpen(prefs, kind, key, open) {
|
|
98
|
+
const was = prefs && Object.hasOwn(prefs, kind) && prefs[kind] && typeof prefs[kind] === 'object' ? prefs[kind] : {};
|
|
99
|
+
return { ...(prefs || {}), [kind]: { ...was, [key]: !!open } };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The kind of node a panel's memory is kept for: a piece of work's kind ("pull", "proposal"), else the node's type ("service") */
|
|
103
|
+
export const panelKind = (node) => (node && typeof node.work === 'string' && node.work ? node.work : node && typeof node.type === 'string' ? node.type : 'node');
|