cornfield 0.62.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 (42) 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 +0 -1
  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 +21 -11
  16. package/explorer/history-replay.js +13 -5
  17. package/explorer/history.js +16 -7
  18. package/explorer/index.html +6 -3
  19. package/explorer/page.js +1 -2
  20. package/explorer/panel-model.js +103 -0
  21. package/explorer/panel-sections.js +140 -0
  22. package/explorer/pieces/layers.js +27 -6
  23. package/explorer/pieces/node-panel.js +78 -1
  24. package/explorer/pieces/search.js +22 -9
  25. package/explorer/pieces/work-deploys.js +13 -13
  26. package/explorer/pieces/work-issues.js +10 -5
  27. package/explorer/pieces/work-list.js +72 -9
  28. package/explorer/pieces/work-paint.js +45 -10
  29. package/explorer/pieces/work-prs.js +46 -34
  30. package/explorer/pieces/work-runs.js +17 -5
  31. package/explorer/pieces/work-specs.js +24 -4
  32. package/explorer/pieces/work-threads.js +59 -15
  33. package/explorer/pieces/work.js +6 -3
  34. package/explorer/proposal-model.js +3 -6
  35. package/explorer/runs-view.js +42 -8
  36. package/explorer/scene.js +5 -1
  37. package/explorer/work-model.js +266 -55
  38. package/explorer/work-view.css +9 -16
  39. package/explorer/work-view.js +107 -34
  40. package/package.json +1 -1
  41. package/server/server.js +1 -1
  42. package/server/work-graph.js +5 -5
@@ -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');
@@ -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
  }
@@ -422,6 +431,7 @@ export function mount(root, inst, options = {}) {
422
431
  const els = [];
423
432
  for (let el = metaList.firstChild; el && el !== before; el = el.nextSibling) els.push(el);
424
433
  if (html) addParts(metaList);
434
+ for (const el of els) applySections(inst, el, kindShown());
425
435
  workShown = { node, html, els };
426
436
  }
427
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 */
@@ -435,8 +445,11 @@ export function mount(root, inst, options = {}) {
435
445
  }
436
446
 
437
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)
438
449
  function show(node, { frame = false } = {}) {
439
450
  if (!node || gone) return;
451
+ shownNode = node;
452
+ drawer.dataset.panelKind = panelKind(node);
440
453
  const title = own('drawer-title');
441
454
  title.textContent = node.tag ? `<${node.tag}>` : node.label;
442
455
  title.classList.toggle('hx-mono', node.type === 'page' || !!node.tag); // a route or a tag reads as code
@@ -497,6 +510,10 @@ export function mount(root, inst, options = {}) {
497
510
  openBtn.hidden = true;
498
511
  own('drawer-run-btn').hidden = true;
499
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);
500
517
 
501
518
  drawer.classList.add('drawer-open');
502
519
  drawer.inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
@@ -507,12 +524,47 @@ export function mount(root, inst, options = {}) {
507
524
  inst.emit('node:painted', { node });
508
525
  }
509
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
+
510
561
  /**
511
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`).
512
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.
513
564
  */
514
565
  function showEdge(edge) {
515
566
  if (!edge || gone) return;
567
+ shownNode = null;
516
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>` : '');
517
569
  const kind = edge.kind || (edge.dashed ? 'usage' : 'ownership');
518
570
  const facts = row('Kind', kind) + row('Flow', edge.flow) + row('Label', edge.label) + row('Reads', Array.isArray(edge.keys) ? edge.keys.join(', ') : '');
@@ -534,6 +586,9 @@ export function mount(root, inst, options = {}) {
534
586
  own('drawer-open-btn').hidden = true;
535
587
  own('drawer-file-btn').hidden = true;
536
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;
537
592
  drawer.classList.add('drawer-open');
538
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
539
594
  backdrop.hidden = false;
@@ -554,7 +609,20 @@ export function mount(root, inst, options = {}) {
554
609
  inst.map.render();
555
610
  }
556
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
+
557
621
  function close() {
622
+ shownNode = null;
623
+ backTo = null;
624
+ const btn = own('drawer-back');
625
+ if (btn) btn.hidden = true;
558
626
  drawer.classList.remove('drawer-open');
559
627
  drawer.inert = true;
560
628
  backdrop.hidden = true;
@@ -576,8 +644,10 @@ export function mount(root, inst, options = {}) {
576
644
  'start-run': () => startRun(),
577
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)
578
646
  'frame-selection': () => frameThem(inst),
647
+ 'panel-back': () => { if (goBack()) scope.timeout(focusTitle, 0); },
579
648
  };
580
649
  scope.listen(drawer, 'click', (e) => {
650
+ if (onSectionsClick(inst, e, kindShown())) return; // a section's title, a count that opens its rows, ⋯
581
651
  const target = e.target.closest && e.target.closest('[data-action]');
582
652
  if (!target) return;
583
653
  const shut = target.dataset.action === 'close-drawer';
@@ -607,9 +677,12 @@ export function mount(root, inst, options = {}) {
607
677
  }
608
678
  // Escape anywhere in the panel closes it, and the map has the focus again
609
679
  scope.listen(drawer, 'keydown', (e) => {
680
+ if (onSectionsKey(e)) return; // Escape in the open ⋯ menu closes the menu, not the panel
610
681
  if (e.key !== 'Escape' || e.defaultPrevented) return;
611
682
  if (e.target.closest && e.target.closest('select, input, textarea')) return; // a field's own Escape first
612
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; }
613
686
  const back = inst.ask('node:back');
614
687
  clearSelection(inst, { source: 'keyboard' });
615
688
  if (!(back && back()) && state.canvas) state.canvas.focus();
@@ -621,6 +694,10 @@ export function mount(root, inst, options = {}) {
621
694
  scope.on('panel:covers', () => (!inline && !gone && !drawer.hidden && drawer.classList.contains('drawer-open') ? { right: drawer.offsetWidth } : undefined));
622
695
  scope.on('node:show', ({ node, frame }) => show(node, { frame }));
623
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 }); });
624
701
  scope.on('node:show-edge', ({ edge }) => showEdge(edge));
625
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
626
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);