@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.
Files changed (43) hide show
  1. package/core/release-notes.js +2 -2
  2. package/explorer/css/changes.css +3 -7
  3. package/explorer/css/header.css +15 -0
  4. package/explorer/css/layers.css +11 -2
  5. package/explorer/css/map.css +27 -0
  6. package/explorer/css/node-panel.css +45 -0
  7. package/explorer/css/page.css +2 -7
  8. package/explorer/css/proposal.css +2 -3
  9. package/explorer/css/work.css +7 -7
  10. package/explorer/engine/hint.js +7 -7
  11. package/explorer/engine/keyboard.js +5 -4
  12. package/explorer/engine/map-rect.js +2 -2
  13. package/explorer/engine/render.js +2 -1
  14. package/explorer/forge-panel-model.js +24 -0
  15. package/explorer/history-model.js +93 -12
  16. package/explorer/history-replay.js +318 -0
  17. package/explorer/history.js +40 -9
  18. package/explorer/index.html +7 -1
  19. package/explorer/instance-state.js +1 -0
  20. package/explorer/page.js +3 -0
  21. package/explorer/panel-model.js +103 -0
  22. package/explorer/panel-sections.js +140 -0
  23. package/explorer/pieces/layers.js +27 -6
  24. package/explorer/pieces/node-panel.js +80 -1
  25. package/explorer/pieces/search.js +22 -9
  26. package/explorer/pieces/work-deploys.js +13 -13
  27. package/explorer/pieces/work-issues.js +10 -5
  28. package/explorer/pieces/work-list.js +72 -9
  29. package/explorer/pieces/work-paint.js +45 -10
  30. package/explorer/pieces/work-prs.js +46 -34
  31. package/explorer/pieces/work-runs.js +17 -5
  32. package/explorer/pieces/work-specs.js +24 -4
  33. package/explorer/pieces/work-threads.js +59 -15
  34. package/explorer/pieces/work.js +6 -3
  35. package/explorer/proposal-model.js +3 -6
  36. package/explorer/runs-view.js +42 -8
  37. package/explorer/scene.js +35 -1
  38. package/explorer/work-model.js +266 -55
  39. package/explorer/work-view.css +9 -16
  40. package/explorer/work-view.js +107 -34
  41. package/package.json +1 -1
  42. package/server/server.js +1 -1
  43. package/server/work-graph.js +5 -5
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @module explorer/panel-sections
3
+ *
4
+ * The node panel's sections and its ⋯ menu on an instance (spec 0015 D4): a section's title opens and closes it, and which are open is remembered per kind
5
+ * of node in the browser (`localStorage`, every read and write in a try: a private window, or storage turned off, only means nothing is remembered);
6
+ * the ⋯ of the action bar shows the rest of the actions, Escape closes it with the focus back on ⋯. The markup is panel-model.js's.
7
+ *
8
+ * applySections(inst, root, kind) puts what was remembered for `kind` on every section under `root` (after it is drawn)
9
+ * onSectionsClick(inst, e, kind) a click in the panel: a section's title, a count that opens its rows, ⋯, an action in the menu; true when it was one of the first three
10
+ * onSectionsKey(e) Escape in an open menu closes it; true when it did
11
+ * menuOpen(root), reopenMenu(root) whether the ⋯ menu under `root` is open, and opening it again after the bar was drawn anew
12
+ */
13
+
14
+ import { SECTIONS_KEY, isOpen, readPrefs, withOpen } from './panel-model.js';
15
+
16
+ const storeOf = (inst) => {
17
+ try { return inst && inst.win && inst.win.localStorage ? inst.win.localStorage : null; } catch { return null; }
18
+ };
19
+
20
+ /** What the browser remembers of the sections (nothing, when it cannot say) */
21
+ export function loadPrefs(inst) {
22
+ try {
23
+ const store = storeOf(inst);
24
+ return readPrefs(store ? store.getItem(SECTIONS_KEY) : '');
25
+ } catch {
26
+ return {};
27
+ }
28
+ }
29
+
30
+ function savePrefs(inst, prefs) {
31
+ try {
32
+ const store = storeOf(inst);
33
+ if (store) store.setItem(SECTIONS_KEY, JSON.stringify(prefs));
34
+ } catch { /* nothing is remembered: the section is open or closed for now */ }
35
+ }
36
+
37
+ const bodyOf = (toggle) => {
38
+ const block = toggle.closest('[data-sec]');
39
+ return block ? [...block.children].find((c) => c.classList && c.classList.contains('hx-sec-body')) || null : null;
40
+ };
41
+
42
+ function setSection(toggle, open) {
43
+ toggle.setAttribute('aria-expanded', String(open));
44
+ const body = bodyOf(toggle);
45
+ if (body) body.hidden = !open;
46
+ }
47
+
48
+ /** Each section under `root` as `kind`'s were left (else as it was drawn: closed unless it holds the action) */
49
+ export function applySections(inst, root, kind) {
50
+ if (!root || !kind || typeof root.querySelectorAll !== 'function') return;
51
+ const prefs = loadPrefs(inst);
52
+ for (const toggle of root.querySelectorAll('[data-sec-toggle]')) setSection(toggle, isOpen(prefs, kind, toggle.dataset.secToggle, toggle.dataset.secDefault === 'true'));
53
+ }
54
+
55
+ function setMenu(toggle, open, { focus = false } = {}) {
56
+ const box = toggle.closest('.hx-actions-more');
57
+ const menu = box && box.querySelector('[data-more-menu]');
58
+ if (!menu) return;
59
+ toggle.setAttribute('aria-expanded', String(open));
60
+ menu.hidden = !open;
61
+ if (open && focus) {
62
+ const first = [...menu.querySelectorAll('button, a[href]')].find((el) => !el.hidden && !el.disabled);
63
+ if (first) first.focus();
64
+ }
65
+ }
66
+
67
+ /** Closes every open ⋯ menu under `root` */
68
+ function closeMenus(root, except = null) {
69
+ for (const t of root.querySelectorAll('[data-more-toggle][aria-expanded="true"]')) if (t !== except) setMenu(t, false);
70
+ }
71
+
72
+ /** Whether a ⋯ menu under `root` is open */
73
+ export const menuOpen = (root) => !!(root && root.querySelector('[data-more-toggle][aria-expanded="true"]'));
74
+
75
+ /** Opens the ⋯ menu under `root` again (its bar was drawn anew while it was open) */
76
+ export function reopenMenu(root) {
77
+ const toggle = root && root.querySelector('[data-more-toggle]');
78
+ if (toggle) setMenu(toggle, true);
79
+ }
80
+
81
+ /**
82
+ * A click in the panel. A section's title opens or closes it and the browser remembers it for `kind`; ⋯ opens or closes its menu (the focus goes to the first action in it);
83
+ * an action in the menu closes the menu once its own click is heard (it is the same button it always was); a click anywhere else closes an open menu.
84
+ * @returns {boolean} whether it was a section's title or ⋯ (nothing else need hear it)
85
+ */
86
+ export function onSectionsClick(inst, e, kind) {
87
+ const t = e.target && e.target.closest ? e.target : null;
88
+ if (!t) return false;
89
+ const root = e.currentTarget && e.currentTarget.querySelectorAll ? e.currentTarget : t.ownerDocument;
90
+ const toggle = t.closest('[data-sec-toggle]');
91
+ if (toggle) {
92
+ const open = toggle.getAttribute('aria-expanded') !== 'true';
93
+ setSection(toggle, open);
94
+ if (kind) savePrefs(inst, withOpen(loadPrefs(inst), kind, toggle.dataset.secToggle, open));
95
+ return true;
96
+ }
97
+ // A count that opens its rows (a group of Connected, History's specs and issues): the list after it
98
+ const sub = t.closest('[data-sub-toggle]');
99
+ if (sub) {
100
+ const open = sub.getAttribute('aria-expanded') !== 'true';
101
+ sub.setAttribute('aria-expanded', String(open));
102
+ const list = sub.nextElementSibling;
103
+ if (list) list.hidden = !open;
104
+ return true;
105
+ }
106
+ const more = t.closest('[data-more-toggle]');
107
+ if (more) {
108
+ const open = more.getAttribute('aria-expanded') !== 'true';
109
+ closeMenus(root, more);
110
+ setMenu(more, open, { focus: open });
111
+ return true;
112
+ }
113
+ const inMenu = t.closest('[data-more-menu]');
114
+ if (inMenu) {
115
+ const box = inMenu.closest('.hx-actions-more');
116
+ const back = box && box.querySelector('[data-more-toggle]');
117
+ // after the action's own listeners (they are on the panel's root, which hears it later): the menu goes, the focus is not left on a hidden button
118
+ setTimeout(() => {
119
+ if (!back || !back.isConnected) return;
120
+ const had = inMenu.contains(back.ownerDocument.activeElement);
121
+ setMenu(back, false);
122
+ if (had) back.focus();
123
+ }, 0);
124
+ return false;
125
+ }
126
+ closeMenus(root);
127
+ return false;
128
+ }
129
+
130
+ /** Escape in an open ⋯ menu (or on ⋯ while it is open) closes it, with the focus back on ⋯; the panel's own Escape does not follow */
131
+ export function onSectionsKey(e) {
132
+ if (e.key !== 'Escape' || e.defaultPrevented || !e.target || !e.target.closest) return false;
133
+ const box = e.target.closest('.hx-actions-more');
134
+ const toggle = box && box.querySelector('[data-more-toggle]');
135
+ if (!toggle || toggle.getAttribute('aria-expanded') !== 'true') return false;
136
+ e.preventDefault();
137
+ setMenu(toggle, false);
138
+ toggle.focus();
139
+ return true;
140
+ }
@@ -2,7 +2,9 @@
2
2
  * @module explorer/pieces/layers
3
3
  *
4
4
  * The Layers menu as a piece (spec 0011 D3): one toggle per kind of node (apps, pages, tables, services, ...) with its count, plus the legend
5
- * of what the lines mean. The data-flow preset ignores the toggles. What the layers are, which are on and what a review shows is the instance's
5
+ * of what the lines mean. The data-flow preset ignores the toggles. A row may carry a button of its own beside it (`action` on the row: the History
6
+ * row's Replay, spec 0015 D6), which this piece draws and closes the menu for; what it does is the page's (page.js hears its `data-action`). A legend
7
+ * (the Key, Agent runs, History, Cloud, Data Flow) shows only while its layer is on; the proposal marks' while a proposal is open. What the layers are, which are on and what a review shows is the instance's
6
8
  * (engine/layers.js); this is the chip, the menu and its rows.
7
9
  *
8
10
  * mount(root, inst, options) -> { update, destroy, ... }
@@ -43,7 +45,7 @@ export const markup = () => ({
43
45
  <button type="button" id="legend-toggle-btn" class="hx-layers-chip" data-action="toggle-layers-menu" aria-expanded="false" aria-controls="legend-dropdown" data-corn="layers-button"><span data-corn-string="layers">Layers</span><span id="layers-count" class="hx-layers-count" data-corn="count"></span></button>
44
46
  <div id="legend-dropdown" class="hx-menu glass" hidden data-corn="layers-menu">
45
47
  <div class="hx-menu-title hx-menu-head" data-corn="menu-title">
46
- <span>Section Toggles</span>
48
+ <span>Layers</span>
47
49
  <span class="hx-menu-links">
48
50
  <button type="button" class="hx-textbtn hx-textbtn--accent" data-action="layers-all" data-corn="layers-all" data-corn-kind="quiet" data-corn-string="layersAll">All</button>
49
51
  <span class="hx-faint">•</span>
@@ -81,6 +83,9 @@ export const markup = () => ({
81
83
  });
82
84
 
83
85
  /** "1 link", "3 in flight", else the number */
86
+ /** The runs' layer (runs-map.js `RUNS_LAYER`): named here, so the menu does not load the runs' marks */
87
+ const RUNS_LAYER = 'runs';
88
+
84
89
  const UNIT = Object.assign(Object.create(null), { flow: (n) => `${n} ${n === 1 ? 'link' : 'links'}`, runs: (n) => `${n} in flight` });
85
90
 
86
91
  /** Mounts the Layers menu; see the top of this file */
@@ -219,11 +224,12 @@ export function mount(root, inst, options = {}) {
219
224
 
220
225
  const row = (layer) => {
221
226
  const on = isOn(inst, layer.key);
227
+ const act = layer.action && typeof layer.action.name === 'string' ? layer.action : null;
222
228
  const shown = byProposal[layer.key] ? `<span class="hx-faint hx-layer-note" data-corn="layer-note">+${byProposal[layer.key]} shown by the proposal</span>` : '';
223
229
  // A row the review hid says so under its name (there is no room beside it): it can still be turned on, for the review
224
230
  const hid = !shown && counts[layer.key] && reviewHides(state, layer.key) ? `<span class="hx-faint hx-layer-note" data-corn="layer-note">${escHtml(t(inst, 'hiddenWhileReviewing'))}</span>` : '';
225
231
  const name = `<span class="hx-toggle-name">${escHtml(layer.label)}</span>`;
226
- return `
232
+ const toggle = `
227
233
  <button type="button" class="hx-toggle-row${on ? '' : ' is-off'}" data-action="toggle-layer" data-layer="${escHtml(layer.key)}" aria-pressed="${on}" title="${escHtml(layer.desc)}" data-corn="row">
228
234
  <span class="hx-toggle-label">
229
235
  ${dot(swatch(layer.color), on, surface)}
@@ -233,7 +239,10 @@ export function mount(root, inst, options = {}) {
233
239
  <span class="hx-count" data-corn="count">${layer.countText || (UNIT[layer.key] || String)(counts[layer.key] || 0)}</span>
234
240
  <span class="hx-tick">${on ? '✓' : '—'}</span>
235
241
  </span>
236
- </button>${kindsHtml(layer, kinds.get(layer.key), surface)}`;
242
+ </button>`;
243
+ // A row's own button (the History row's Replay) sits beside it, never in it: a button in a button is not one
244
+ const line = act ? `<div class="hx-toggle-line">${toggle}<button type="button" class="hx-row-action" data-action="${escHtml(act.name)}" data-corn-kind="secondary" aria-pressed="${act.pressed === true}" title="${escHtml(act.title || '')}">${escHtml(act.label)}</button></div>` : toggle;
245
+ return `${line}${kindsHtml(layer, kinds.get(layer.key), surface)}`;
237
246
  };
238
247
 
239
248
  // The focus stays where it was across the redraw: the same row or disclosure, found again by what it names
@@ -249,10 +258,20 @@ export function mount(root, inst, options = {}) {
249
258
  }
250
259
  renderFlowLegend(inst, own('flow-legend'));
251
260
  renderEdgeKey();
261
+ paintLegends(layers);
252
262
  renderCloudLegend();
253
263
  addParts(own('flow-legend'));
254
264
  }
255
265
 
266
+ /** The legends that follow a layer (spec 0015 D6): the Key while any layer is on (with none, no line is drawn), Agent runs while runs are on the map and their layer is on */
267
+ let runsActive = false;
268
+ function paintLegends(layers = layerRows(inst).layers) {
269
+ const key = own('edge-key');
270
+ if (key) key.hidden = !layers.some((l) => isOn(inst, l.key));
271
+ const runs = own('runs-legend');
272
+ if (runs) runs.hidden = !(runsActive && isOn(inst, RUNS_LAYER));
273
+ }
274
+
256
275
  /** The Key (spec 0008 D7): each kind of line as the map draws it (edge-key.js) */
257
276
  function renderEdgeKey() {
258
277
  const el = own('edge-key');
@@ -296,6 +315,8 @@ export function mount(root, inst, options = {}) {
296
315
  scope.listen(wrap, 'click', (e) => {
297
316
  const target = e.target.closest && e.target.closest('[data-action]');
298
317
  if (!target) return;
318
+ // A row's own button (Replay): the menu closes, the focus on its chip, and the page does the rest (it hears the click on the document)
319
+ if (target.classList.contains('hx-row-action')) { closeMenu(); btn.focus(); return; }
299
320
  const action = ACTIONS[target.dataset.action];
300
321
  if (action) action(target);
301
322
  });
@@ -323,8 +344,8 @@ export function mount(root, inst, options = {}) {
323
344
  scope.on('layers:redraw', renderLayerToggles);
324
345
  scope.on('theme', renderLayerToggles); // the dots and the legends are drawn in the theme's colours
325
346
  scope.on('view', syncView);
326
- scope.on('runs:map', ({ active }) => { const legend = own('runs-legend'); if (legend) legend.hidden = !active; });
327
- scope.on('history:legend', ({ active }) => { const legend = own('history-legend'); if (legend) legend.hidden = !active; }); // the History layer is drawn (history.js): what a halo's width and colour say // runs are on the map (the Work list): the legend says what each mark is
347
+ scope.on('runs:map', ({ active }) => { runsActive = !!active; paintLegends(); }); // runs are on the map (the Work list): the legend says what each mark is, while their layer is on
348
+ scope.on('history:legend', ({ active }) => { const legend = own('history-legend'); if (legend) legend.hidden = !active; }); // the History layer is drawn (history.js): what a halo's width and colour say
328
349
  // The marks legend is there while a proposal is open (the proposal's bar says so: engine/proposal.js)
329
350
  const showLegend = (open) => { const legend = own('proposal-legend'); if (legend) legend.hidden = !open; };
330
351
  scope.on('proposal:draw', ({ open }) => showLegend(open));
@@ -44,6 +44,8 @@ import { reach } from '../selection-view.js';
44
44
  import { announce, frameThem } from '../engine/keyboard.js';
45
45
  import { selectNode, clearSelection } from '../engine/selection.js';
46
46
  import { scopeOf, place, addParts } from '../engine/piece.js';
47
+ import { panelKind, sectionHtml } from '../panel-model.js';
48
+ import { applySections, onSectionsClick, onSectionsKey } from '../panel-sections.js';
47
49
 
48
50
  // ---------------------------------------------------------------------------
49
51
  // Small HTML pieces shared by the sections below
@@ -96,6 +98,8 @@ export const LINES_CAP = 12;
96
98
  export const markup = () => ({
97
99
  drawer: '<aside id="spec-drawer" class="hx-drawer glass" aria-label="Node details" inert data-corn="node-panel">'
98
100
  + '<div class="hx-drawer-body">'
101
+ // Back (spec 0015 D3): to the Work list this panel took the place of, or from a thread folded into a proposal to the proposal; hidden when there is nowhere to go back to
102
+ + '<button type="button" id="drawer-back" class="hx-forge-back hx-panel-back" data-action="panel-back" data-corn="back" hidden><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">Back</span></button>'
99
103
  + '<div class="hx-drawer-head">'
100
104
  + '<div class="hx-drawer-id">'
101
105
  + '<p class="hx-kicker"><span id="drawer-badge" data-corn="badge">Atom</span><span id="drawer-host" data-corn="node-host"></span><span id="drawer-diff" class="hx-diffpill" data-corn="diff-pill" hidden></span></p>'
@@ -265,7 +269,7 @@ function sectionsOf(inst) {
265
269
  const count = Number(th.comments) || 0;
266
270
  return `<li><button type="button" class="hx-row hx-thread-open" data-thread-open="${escHtml(th.number)}" data-corn="row" aria-label="Open thread #${escHtml(th.number)}, ${escHtml(th.title)}, ${count} ${count === 1 ? 'comment' : 'comments'}, in the issues and pull requests panel"><span class="hx-row-title">${escHtml(th.title)}</span><span class="hx-row-meta">#${escHtml(th.number)} · ${count}</span></button></li>`;
267
271
  });
268
- return `<div class="hx-sec-block" data-corn="section"><h3 class="hx-sec-title">Threads</h3><ul class="hx-rows">${rows.join('')}</ul>${start}</div>`;
272
+ return sectionHtml({ key: 'threads', title: 'Threads', count: threads.length, body: `<ul class="hx-rows">${rows.join('')}</ul>${start}` });
269
273
  }
270
274
 
271
275
  /** "In this proposal": the diff for a changed node as key/value rows (id, parent, edges +2; a change shows each field before and after) */
@@ -389,8 +393,12 @@ export function mount(root, inst, options = {}) {
389
393
  if (!box || !state.selectedNode) return;
390
394
  box.innerHTML = sections.threadsSection(state.selectedNode);
391
395
  addParts(box);
396
+ applySections(inst, box, kindShown());
392
397
  }
393
398
 
399
+ /** The kind of node the panel shows, whose sections' open and closed the browser remembers (spec 0015 D4) */
400
+ const kindShown = () => drawer.dataset.panelKind || '';
401
+
394
402
  /** Draws "History" again in the open panel (spec 0014 D2: the history was read, a spec was picked, or Show all); nothing else in the panel moves */
395
403
  function repaintHistory() {
396
404
  const box = own('drawer-history');
@@ -400,6 +408,7 @@ export function mount(root, inst, options = {}) {
400
408
  const key = active && box.contains(active) ? (active.dataset.historySpec ? `spec:${active.dataset.historySpec}` : active.hasAttribute('data-history-all') ? 'all' : '') : '';
401
409
  box.innerHTML = inst.ask('history:section', node) || '';
402
410
  addParts(box);
411
+ applySections(inst, box, kindShown());
403
412
  if (key.startsWith('spec:')) { const el = [...box.querySelectorAll('[data-history-spec]')].find((x) => `spec:${x.dataset.historySpec}` === key); if (el) el.focus(); }
404
413
  else if (key === 'all') { const first = box.querySelector('.hx-history-commit a'); if (first) first.focus(); }
405
414
  }
@@ -408,6 +417,8 @@ export function mount(root, inst, options = {}) {
408
417
  const spec = e.target.closest && e.target.closest('[data-history-spec]');
409
418
  if (spec) { inst.emit('history:pick', spec.dataset.historySpec); return true; }
410
419
  if (e.target.closest && e.target.closest('[data-history-all]')) { inst.emit('history:all'); return true; }
420
+ const at = e.target.closest && e.target.closest('[data-history-at]');
421
+ if (at) { inst.emit('history:replay', Number(at.dataset.historyAt)); return true; } // the timeline moves to the commit (spec 0014 D2)
411
422
  return false;
412
423
  }
413
424
 
@@ -420,6 +431,7 @@ export function mount(root, inst, options = {}) {
420
431
  const els = [];
421
432
  for (let el = metaList.firstChild; el && el !== before; el = el.nextSibling) els.push(el);
422
433
  if (html) addParts(metaList);
434
+ for (const el of els) applySections(inst, el, kindShown());
423
435
  workShown = { node, html, els };
424
436
  }
425
437
  /** The work changed (`work:changed`: the Work layer came on or went off, or a new answer): the open panel's section for it is drawn again, and nothing else in it moves */
@@ -433,8 +445,11 @@ export function mount(root, inst, options = {}) {
433
445
  }
434
446
 
435
447
  /** Fills the panel for a node and opens it. The selection itself is the instance's (engine/selection.js); this is what is shown for it. */
448
+ let shownNode = null; // what the panel shows, for `panel:return` (the Work list stepped in front of it, spec 0015 D3)
436
449
  function show(node, { frame = false } = {}) {
437
450
  if (!node || gone) return;
451
+ shownNode = node;
452
+ drawer.dataset.panelKind = panelKind(node);
438
453
  const title = own('drawer-title');
439
454
  title.textContent = node.tag ? `<${node.tag}>` : node.label;
440
455
  title.classList.toggle('hx-mono', node.type === 'page' || !!node.tag); // a route or a tag reads as code
@@ -495,6 +510,10 @@ export function mount(root, inst, options = {}) {
495
510
  openBtn.hidden = true;
496
511
  own('drawer-run-btn').hidden = true;
497
512
  } else putWork(node, work ? work.html : '');
513
+ applySections(inst, metaList, kindShown()); // each section as it was left for this kind of node (spec 0015 D4)
514
+ // The foot holds a node of code's actions; a piece of work's are its action bar, at the top
515
+ own('drawer-copy-btn').closest('.hx-drawer-foot').hidden = !!(work && work.replace);
516
+ setBack(node);
498
517
 
499
518
  drawer.classList.add('drawer-open');
500
519
  drawer.inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
@@ -505,12 +524,47 @@ export function mount(root, inst, options = {}) {
505
524
  inst.emit('node:painted', { node });
506
525
  }
507
526
 
527
+ /**
528
+ * Back, at the top of the panel (spec 0015 D3): from a thread folded into the selected proposal (spec 0015 D2), to the proposal; else, while the Work list is open on a desktop
529
+ * (it waits behind this panel: `panel:back`, answered by the Work list), to the list. Escape does the same. With nowhere to go back to it is hidden, and Escape closes the panel.
530
+ */
531
+ let backTo = null;
532
+ function setBack(node) {
533
+ const btn = own('drawer-back');
534
+ const sel = state.selectedNode;
535
+ const into = node && node.foldedInto && sel && sel !== node && sel.id === node.foldedInto ? sel : null;
536
+ const list = !into && node && !inline ? inst.ask('panel:back') : undefined;
537
+ backTo = into ? () => { show(into, { frame: false }); return true; } : typeof list === 'function' ? list : null;
538
+ if (!btn) return;
539
+ btn.hidden = !backTo;
540
+ const words = into ? `Back to ${into.label || into.id}` : 'Back to the list';
541
+ btn.querySelector('.hx-forge-back-text').textContent = words;
542
+ btn.setAttribute('aria-label', into ? words : 'Back to the Work list');
543
+ }
544
+ /** Goes back (the button, or Escape); false when there was nowhere to go */
545
+ function goBack() {
546
+ const go = backTo;
547
+ if (!go) return false;
548
+ backTo = null;
549
+ go();
550
+ return true;
551
+ }
552
+
553
+ /** The Work list took this panel's place (spec 0015 D3): the panel steps aside, the selection stays, Back on the list's row brings it again */
554
+ function stepAside() {
555
+ if (inline || gone || !drawer.classList.contains('drawer-open')) return;
556
+ drawer.classList.remove('drawer-open');
557
+ drawer.inert = true;
558
+ backdrop.hidden = true;
559
+ }
560
+
508
561
  /**
509
562
  * Fills the panel for an edge and opens it: what it is, and what the proposal says about it (the engine's `showEdge` selects it and says `node:show-edge`).
510
563
  * As ever, an edge alone gets no sheet on a phone (the panel is opened, not `showSheet`ed), and Escape on the map does not close it.
511
564
  */
512
565
  function showEdge(edge) {
513
566
  if (!edge || gone) return;
567
+ shownNode = null;
514
568
  const row = (label, value) => (value ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">${escHtml(label)}</div><div class="hx-fact-v">${escHtml(value)}</div></div>` : '');
515
569
  const kind = edge.kind || (edge.dashed ? 'usage' : 'ownership');
516
570
  const facts = row('Kind', kind) + row('Flow', edge.flow) + row('Label', edge.label) + row('Reads', Array.isArray(edge.keys) ? edge.keys.join(', ') : '');
@@ -532,6 +586,9 @@ export function mount(root, inst, options = {}) {
532
586
  own('drawer-open-btn').hidden = true;
533
587
  own('drawer-file-btn').hidden = true;
534
588
  own('drawer-run-btn').hidden = true;
589
+ own('drawer-copy-btn').closest('.hx-drawer-foot').hidden = false;
590
+ setBack(null);
591
+ delete drawer.dataset.panelKind;
535
592
  drawer.classList.add('drawer-open');
536
593
  drawer.inert = false; // closed, the panel is inert (MAP-02): open for an edge, its links and its Close are reached as a node's are
537
594
  backdrop.hidden = false;
@@ -552,7 +609,20 @@ export function mount(root, inst, options = {}) {
552
609
  inst.map.render();
553
610
  }
554
611
 
612
+ /** After Back to the proposal the button that was pressed is gone: the focus goes to the title, as Enter on the map puts it */
613
+ function focusTitle() {
614
+ const now = inst.active();
615
+ if (!drawer.classList.contains('drawer-open') || (now && now.isConnected && now !== inst.doc.body && drawer.contains(now))) return;
616
+ const title = own('drawer-title');
617
+ title.setAttribute('tabindex', '-1');
618
+ title.focus();
619
+ }
620
+
555
621
  function close() {
622
+ shownNode = null;
623
+ backTo = null;
624
+ const btn = own('drawer-back');
625
+ if (btn) btn.hidden = true;
556
626
  drawer.classList.remove('drawer-open');
557
627
  drawer.inert = true;
558
628
  backdrop.hidden = true;
@@ -574,8 +644,10 @@ export function mount(root, inst, options = {}) {
574
644
  'start-run': () => startRun(),
575
645
  'select-node': (el) => selectNode(inst, sections.nodeById(el.dataset.id), { frame: true, source: 'link' }), // a link or a list row: the camera follows (spec 0008 D6)
576
646
  'frame-selection': () => frameThem(inst),
647
+ 'panel-back': () => { if (goBack()) scope.timeout(focusTitle, 0); },
577
648
  };
578
649
  scope.listen(drawer, 'click', (e) => {
650
+ if (onSectionsClick(inst, e, kindShown())) return; // a section's title, a count that opens its rows, ⋯
579
651
  const target = e.target.closest && e.target.closest('[data-action]');
580
652
  if (!target) return;
581
653
  const shut = target.dataset.action === 'close-drawer';
@@ -605,9 +677,12 @@ export function mount(root, inst, options = {}) {
605
677
  }
606
678
  // Escape anywhere in the panel closes it, and the map has the focus again
607
679
  scope.listen(drawer, 'keydown', (e) => {
680
+ if (onSectionsKey(e)) return; // Escape in the open ⋯ menu closes the menu, not the panel
608
681
  if (e.key !== 'Escape' || e.defaultPrevented) return;
609
682
  if (e.target.closest && e.target.closest('select, input, textarea')) return; // a field's own Escape first
610
683
  e.preventDefault();
684
+ // Back first (spec 0015 D3): to the Work list this panel took the place of, or from a folded thread to its proposal
685
+ if (backTo) { goBack(); scope.timeout(focusTitle, 0); announce(inst, 'Back'); return; }
611
686
  const back = inst.ask('node:back');
612
687
  clearSelection(inst, { source: 'keyboard' });
613
688
  if (!(back && back()) && state.canvas) state.canvas.focus();
@@ -619,6 +694,10 @@ export function mount(root, inst, options = {}) {
619
694
  scope.on('panel:covers', () => (!inline && !gone && !drawer.hidden && drawer.classList.contains('drawer-open') ? { right: drawer.offsetWidth } : undefined));
620
695
  scope.on('node:show', ({ node, frame }) => show(node, { frame }));
621
696
  scope.on('node:close', close);
697
+ // The Work list opened on a desktop: it takes this panel's place, and the selection stays (spec 0015 D3; a phone's sheets take turns on their own)
698
+ scope.on('work:list', ({ open }) => { if (open && !inline && !isPhone(inst)) stepAside(); });
699
+ // ... and the list's row of what it shows brings it back in the list's place (the list goes behind it again)
700
+ scope.on('panel:return', () => { if (shownNode && !inline && !gone && !drawer.classList.contains('drawer-open')) show(shownNode, { frame: false }); });
622
701
  scope.on('node:show-edge', ({ edge }) => showEdge(edge));
623
702
  // Enter on the map goes into the open panel: its title takes the focus, so a screen reader starts there and Tab goes on into it
624
703
  scope.on('node:focus', () => {
@@ -8,6 +8,8 @@
8
8
  * what a layer that is off hides last, under "In layers that are off", and choosing one turns its layer on;
9
9
  * - stepping: Enter and Shift+Enter in the field, the arrow keys in the list, N and P on the map (engine/keyboard.js asks `search:active` and
10
10
  * `search:step`) and the field's ^ and v buttons. Each step selects the match and flies the camera to it, at zoom 1 or closer;
11
+ * a choice made in the field (Enter) or the list (a click, Enter on a row) closes the list, so it does not lie over the node panel (spec 0015 D7):
12
+ * typing again, the down arrow or the field taking the focus again opens it;
11
13
  * - on the map the matches keep their halo and win a label (scene.js, labels.js), the rest dims.
12
14
  *
13
15
  * The desktop field and the phone's bar are two inputs on one search: the query, the matches and the current match are shared, each
@@ -183,7 +185,7 @@ export function mount(root, inst, options = {}) {
183
185
  if (!list) continue;
184
186
  const input = own(field.input);
185
187
  const focused = inst.active();
186
- const open = !!result.query && keepOpen && (focused === input || list.contains(focused) || list.dataset.open === 'true');
188
+ const open = !!result.query && keepOpen && list.dataset.shut !== 'true' && (focused === input || list.contains(focused) || list.dataset.open === 'true');
187
189
  // A row that has the focus is repainted: the focus goes to the same row again, so a keyboard user keeps their place
188
190
  const held = list.contains(focused) ? focused : null;
189
191
  const heldId = held ? held.dataset.searchId || (held.hasAttribute('data-search-frame') ? '' : null) : null;
@@ -204,6 +206,14 @@ export function mount(root, inst, options = {}) {
204
206
  }
205
207
  }
206
208
 
209
+ /** The list of a field, closed until it is asked for again (a match was chosen: Enter, or a row): typing, the down arrow or the field's focus opens it */
210
+ function shutList(field) {
211
+ const list = listOf(field);
212
+ if (list) list.dataset.shut = 'true';
213
+ closeList(field);
214
+ }
215
+ const unshut = (field) => { const list = listOf(field); if (list) delete list.dataset.shut; };
216
+
207
217
  /** The list of a field, closed (Escape, or the focus left it) */
208
218
  function closeList(field) {
209
219
  const list = listOf(field);
@@ -308,10 +318,11 @@ export function mount(root, inst, options = {}) {
308
318
  if (!typed) return;
309
319
  const result = currentResult();
310
320
  if (!result.total) { announce(inst, `No node matches ${typed}`); return; }
321
+ shutList(field); // the choice is made: the list would lie over the node's panel
311
322
  stepMatch(e.shiftKey ? -1 : 1);
312
323
  } else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
313
324
  const list = listOf(field);
314
- if (!list || list.hidden) { if (e.key === 'ArrowDown' && state.searchQuery) { e.preventDefault(); list.dataset.open = 'true'; paintSearch(); } return; }
325
+ if (!list || list.hidden) { if (e.key === 'ArrowDown' && state.searchQuery) { e.preventDefault(); unshut(field); list.dataset.open = 'true'; paintSearch(); } return; }
315
326
  const rows = rowsOf(list);
316
327
  if (!rows.length) return;
317
328
  e.preventDefault();
@@ -347,14 +358,15 @@ export function mount(root, inst, options = {}) {
347
358
  const result = currentResult();
348
359
  const match = result.matches.find((m) => m.node.id === row.dataset.searchId);
349
360
  if (!match) return;
350
- chooseMatch(match);
351
- // On a phone the list would cover the match: it shuts, and the focus goes to the next-match button, which stays
361
+ // The list shuts (it would lie over the node's panel) and the focus goes back to the field; on a phone, to the next-match button, which stays
352
362
  const field = fields.find((f) => listOf(f) === e.currentTarget);
353
- if (field && field.input === 'mobile-node-search' && isPhone(inst)) {
354
- closeList(field);
363
+ if (field) {
364
+ shutList(field);
355
365
  const next = own(field.steps) && own(field.steps).querySelector('[data-action="search-next"]');
356
- if (next) next.focus();
366
+ const to = field.input === 'mobile-node-search' && isPhone(inst) ? next : own(field.input);
367
+ if (to) to.focus();
357
368
  }
369
+ chooseMatch(match);
358
370
  }
359
371
 
360
372
  /** The list closes when the focus leaves the field and its list (a click on the map, Tab away) */
@@ -364,6 +376,7 @@ export function mount(root, inst, options = {}) {
364
376
  if (next && box && box.contains(next)) return;
365
377
  if (!next && e.target && e.target.matches && e.target.matches('[data-corn="search-result"]')) return; // a row that left the DOM (the list repainted)
366
378
  closeList(field);
379
+ unshut(field); // coming back to the field opens the list again
367
380
  }
368
381
 
369
382
  /** Opens or shuts the phone's search bar (its icon in the header, Cancel); opened, it takes the query and the focus */
@@ -388,9 +401,9 @@ export function mount(root, inst, options = {}) {
388
401
  input.setAttribute('aria-autocomplete', 'none');
389
402
  input.setAttribute('aria-expanded', 'false');
390
403
  input.setAttribute('aria-controls', field.results);
391
- scope.listen(input, 'input', (e) => setQuery(e.target.value));
404
+ scope.listen(input, 'input', (e) => { unshut(field); setQuery(e.target.value); });
392
405
  scope.listen(input, 'keydown', (e) => onFieldKey(e, field));
393
- scope.listen(input, 'focus', () => { const list = listOf(field); if (list && state.searchQuery) { list.dataset.open = 'true'; paintSearch(); } });
406
+ scope.listen(input, 'focus', () => { const list = listOf(field); if (list && state.searchQuery && list.dataset.shut !== 'true') { list.dataset.open = 'true'; paintSearch(); } });
394
407
  const box = input.closest('[data-corn="search"], [data-corn="mobile-search"]');
395
408
  if (box) scope.listen(box, 'focusout', (e) => onFocusOut(e, field));
396
409
  const list = listOf(field);
@@ -10,6 +10,7 @@ import { nodesForRestarts, deployWords, deployMeta, listUrl } from '../forge-pan
10
10
  import { cornStateAttr, stateIconHtml } from '../corn-state.js';
11
11
  import { escapeHtml as escHtml } from '../../core/text.js';
12
12
  import { plural, safeUrl } from './work-common.js';
13
+ import { sectionHtml } from '../panel-model.js';
13
14
 
14
15
  export function install(ctx) {
15
16
  const { ui, m, fn, state } = ctx;
@@ -71,24 +72,23 @@ export function install(ctx) {
71
72
  }
72
73
 
73
74
  /** The deploy in the node panel: what it was, its logs on the forge, and the nodes it restarted (each a button that selects it on the map) */
74
- function deployDetailHtml() {
75
- if (ui.detailError && !ui.deployItem) return `<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>`;
75
+ function deployParts() {
76
+ if (ui.detailError && !ui.deployItem) return { notes: `<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>` };
76
77
  const d = ui.deployItem;
77
- if (!d) return '<p class="hx-faint">Loading what it restarted …</p>';
78
+ if (!d) return { notes: '<p class="hx-faint">Loading what it restarted …</p>' };
78
79
  const lit = ui.litDeploy;
79
80
  const url = safeUrl(d.url);
80
- const head = `<p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, m.now()))}</p>
81
- ${url ? `<div class="hx-forge-cta"><a data-corn="open-link" data-corn-kind="secondary" class="hx-btn hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open the logs on ${escHtml(fn.forgeName())} ↗</a></div>` : ''}`;
81
+ // Its logs are its one action (spec 0015 D4); its state and when are the panel's head, its run's words a line under the bar
82
+ const logs = url ? `<a data-corn="open-link" data-corn-kind="primary" class="hx-btn hx-btn--primary hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open the logs on ${escHtml(fn.forgeName())} ↗</a>` : '';
83
+ const head = `<p class="hx-forge-meta">${escHtml(deployMeta(d, m.now()))}</p>`; // its state is the panel's one pill
82
84
  const stale = ui.lists.deploys && ui.lists.deploys.stale;
83
- let body;
85
+ const notes = `${head}${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}`;
84
86
  if (!d.restarts.length) {
85
- body = '<p class="hx-forge-notice" data-corn="notice">No node is mapped to this deploy. Say what it restarts under <code class="hx-code">deploys.restarts</code> in cornfield.config.js (docs/deploys.md).</p>';
86
- } else {
87
- const rows = lit.nodes.map((n) => `<li class="hx-forge-file" data-corn="file"><button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button> <span class="hx-faint">${escHtml(n.type)}</span></li>`).join('');
88
- const missing = lit.missing.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.missing.join(', '))} ${lit.missing.length === 1 ? 'is' : 'are'} named in the config but not on the map.</p>` : '';
89
- body = `<h3 class="hx-forge-sub">${escHtml(`Restarted: ${plural(lit.nodes.length, 'node')} on the map`)}</h3>${rows ? `<ul class="hx-forge-files">${rows}</ul>` : ''}${missing}`;
87
+ return { primary: logs, notes: `${notes}<p class="hx-forge-notice" data-corn="notice">No node is mapped to this deploy. Say what it restarts under <code class="hx-code">deploys.restarts</code> in cornfield.config.js (docs/deploys.md).</p>`, sections: [] };
90
88
  }
91
- return `${head}${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}${body}`;
89
+ const rows = lit.nodes.map((n) => `<li class="hx-forge-file" data-corn="file"><button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button> <span class="hx-faint">${escHtml(n.type)}</span></li>`).join('');
90
+ const missing = lit.missing.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.missing.join(', '))} ${lit.missing.length === 1 ? 'is' : 'are'} named in the config but not on the map.</p>` : '';
91
+ return { primary: logs, notes, sections: [sectionHtml({ key: 'restarted', title: 'Restarted', count: lit.nodes.length, body: `${rows ? `<ul class="hx-forge-files">${rows}</ul>` : `<p class="hx-faint">${escHtml(plural(0, 'node'))} on the map.</p>`}${missing}` })] };
92
92
  }
93
93
 
94
94
  /** What a screen reader hears when a deploy is selected */
@@ -101,5 +101,5 @@ export function install(ctx) {
101
101
  }
102
102
 
103
103
  // what other parts put in the panel gets its parts (a hook is a part of the same name)
104
- Object.assign(fn, { selectDeploy, showDeploy, clearDeploy, restartWords, deployHtml: (...a) => withParts(deployHtml(...a)), deployDetailHtml: (...a) => withParts(deployDetailHtml(...a)), deploySelectionWords });
104
+ Object.assign(fn, { selectDeploy, showDeploy, clearDeploy, restartWords, deployHtml: (...a) => withParts(deployHtml(...a)), deployParts, deploySelectionWords });
105
105
  }
@@ -8,20 +8,25 @@
8
8
 
9
9
  import { escapeHtml as escHtml } from '../../core/text.js';
10
10
  import { issueUrl, listUrl, listKeyOf, specBlock } from '../forge-panel-model.js';
11
+ import { safeUrl } from './work-common.js';
12
+ import { withParts } from '../engine/piece.js';
11
13
 
12
14
  export function install(ctx) {
13
15
  const { ui, fn } = ctx;
14
16
  const { t } = ctx.h;
15
17
 
16
18
  /** An issue's actions in the node panel: Start a spec (step 1 of the pipeline) and Start an agent, each opening its confirm step; a closed issue has none */
17
- function issueActionsHtml(item) {
19
+ // (spec 0015 D4: Start an agent is the primary action of an open issue, Start a spec and Open on the forge beside it; a closed one has only its link, and the Next line says why)
20
+ function issueParts(item) {
18
21
  const n = item.number;
19
- if (!item.open) return `<p class="hx-faint">${escHtml(specBlock({ state: 'closed' }))}</p>`;
22
+ const url = safeUrl(item.url);
23
+ const out = url ? withParts(`<a class="hx-btn hx-btn--quiet hx-foot-btn" data-corn-kind="quiet" data-corn="open-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on the forge ↗</a>`) : '';
24
+ if (!item.open) return { primary: '', others: [out], next: specBlock({ state: 'closed' }) };
20
25
  const spec = specBlock({ state: 'open' }) === null
21
26
  ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-spec="${n}" aria-label="Start a spec for issue ${n}"${ui.busy ? ' aria-disabled="true"' : ''}>Start a spec …</button>`
22
27
  : '';
23
- const agent = `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-agent="issue:${n}" aria-label="${escHtml(t('startAgent'))} on issue ${n}">${escHtml(t('startAgent'))} …</button>`;
24
- return `<div class="hx-forge-cta">${agent}${spec}</div>`;
28
+ const agent = `<button data-corn-kind="approve" type="button" class="hx-btn hx-btn--approve hx-forge-act hx-forge-startspec" data-forge-agent="issue:${n}" aria-label="${escHtml(t('startAgent'))} on issue ${n}">${escHtml(t('startAgent'))} …</button>`;
29
+ return { primary: agent, others: [spec, out] };
25
30
  }
26
31
 
27
32
  /**
@@ -42,5 +47,5 @@ export function install(ctx) {
42
47
  return null;
43
48
  }
44
49
 
45
- Object.assign(fn, { issueActionsHtml, oldIssue });
50
+ Object.assign(fn, { issueParts, oldIssue });
46
51
  }