@popcorn245/cornfield 0.34.2 → 0.35.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.
@@ -74,9 +74,9 @@
74
74
  <div id="proposal-legend" class="hx-menu-section" hidden>
75
75
  <div class="hx-menu-title"><span>Proposal marks</span></div>
76
76
  <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--added"></span><span>Added: dashed ring</span></div>
77
- <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed"></span><span>Changed: amber ring</span></div>
78
- <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed"></span><span>Removed: red, faded, label struck through</span></div>
79
- <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit"></span><span>Your edit: violet</span></div>
77
+ <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed"></span><span>Changed: solid ring</span></div>
78
+ <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed"></span><span>Removed: faded ring, label struck through</span></div>
79
+ <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit"></span><span>Your edit: dotted ring</span></div>
80
80
  </div>
81
81
 
82
82
  <div class="hx-menu-section">
@@ -235,8 +235,10 @@
235
235
  </section>
236
236
 
237
237
  <!-- The Work panel (forge-panel.js): Specs, PRs, Issues, Threads, Runs and Deploys, in the order of the loop. A slide-over from the left on desktop, a bottom sheet on a phone; hidden and inert until the config names a forge. `forge-panel` on the inner box is the old name of the hook, kept for one release (docs/theming.md) -->
238
+ <p id="offline-banner" class="hx-offline" data-corn="notice" hidden></p>
238
239
  <aside id="forge-panel" class="hx-forge glass" aria-label="Work" inert hidden data-corn="work-panel">
239
240
  <div class="hx-forge-body" data-corn="forge-panel">
241
+ <div class="hx-forge-top" data-corn="work-top">
240
242
  <div class="hx-forge-head">
241
243
  <h2 id="forge-title" class="hx-drawer-title" tabindex="-1">Work</h2>
242
244
  <button type="button" class="hx-btn hx-btn--quiet" data-action="refresh-forge" title="Ask the forge again" data-corn-kind="quiet">Refresh</button>
@@ -250,6 +252,7 @@
250
252
  <button type="button" class="hx-forge-tab" data-forge-kind="work" aria-pressed="false" title="Agent runs, and the work grouped by issue and proposal with agent-made work marked" data-corn="tab"><span data-corn-string="tabRuns">Runs</span><span class="hx-forge-count" hidden></span></button>
251
253
  <button type="button" class="hx-forge-tab" data-forge-kind="deploys" aria-pressed="false" data-corn="tab"><span data-corn-string="tabDeploys">Deploys</span><span class="hx-forge-count" hidden></span></button>
252
254
  </div>
255
+ </div>
253
256
  <div id="forge-bar" class="hx-forge-bar">
254
257
  <p id="forge-status" class="hx-forge-status hx-faint"></p>
255
258
  <button type="button" id="forge-filter-chip" class="hx-forge-chip" data-action="toggle-filters" aria-expanded="false" aria-controls="forge-filter-box" hidden>Filter<span class="hx-forge-count" hidden></span></button>
@@ -350,6 +353,7 @@
350
353
  <a id="drawer-open-btn" class="hx-open" href="#" target="_blank" rel="noreferrer" hidden>Open route ↗</a>
351
354
  <button type="button" id="drawer-run-btn" class="hx-btn hx-foot-btn" data-action="start-run" data-corn-string="startRun" hidden>Start a run</button>
352
355
  <button type="button" class="hx-btn hx-btn--quiet hx-foot-btn" data-action="copy-spec" data-corn-string="copySpec">Copy Spec</button>
356
+ <p id="copy-spec-result" class="hx-forge-result" data-corn="result" hidden></p>
353
357
  </div>
354
358
  </aside>
355
359
  </div>
@@ -24,6 +24,7 @@ import { hooks } from './proposal.js';
24
24
  import { mockupsOf } from '../core/proposal.js';
25
25
  import { mockupsFor, mockupsSectionHtml, stateWords } from './mockups-model.js';
26
26
  import { cornState } from './corn-state.js';
27
+ import { focusableIn, trapTab } from './focusables.js';
27
28
 
28
29
  const $ = (id) => document.getElementById(id);
29
30
 
@@ -79,8 +80,6 @@ export async function refreshMockups() {
79
80
  // The window
80
81
  // ---------------------------------------------------------------------------
81
82
 
82
- const FOCUSABLE = 'button, [href], iframe, [tabindex]:not([tabindex="-1"])';
83
-
84
83
  /** Shuts the window and gives the focus back to the button that opened it */
85
84
  export function closeMockup() {
86
85
  if (!dialog) return;
@@ -99,13 +98,8 @@ function onKey(e) {
99
98
  e.stopPropagation();
100
99
  closeMockup();
101
100
  } else if (e.key === 'Tab') {
102
- const stops = [...dialog.querySelectorAll(FOCUSABLE)];
103
- const at = stops.indexOf(document.activeElement);
104
- const next = e.shiftKey ? (at <= 0 ? stops.length - 1 : at - 1) : (at < 0 || at === stops.length - 1 ? 0 : at + 1);
105
- if (stops.length) {
106
- e.preventDefault();
107
- stops[next].focus();
108
- }
101
+ // the frame is a stop too, though it holds the focus rather than a tabindex
102
+ if (focusableIn(dialog).length) trapTab(e, dialog);
109
103
  }
110
104
  }
111
105
 
@@ -20,6 +20,7 @@ import { t } from './strings.js';
20
20
  import { fileUrl } from './file-url.js';
21
21
  import { capped, toggleCapped } from './capped.js';
22
22
  import { canStartAgent, openProposalStart } from './forge-panel.js';
23
+ import { sayResult, clearResult, showResultIn, RESULT_MS } from './feedback.js';
23
24
 
24
25
  const $ = (id) => document.getElementById(id);
25
26
 
@@ -311,15 +312,20 @@ export function closeDrawer() {
311
312
  render();
312
313
  }
313
314
 
314
- /** Copies the selected node as JSON; the button says so for a moment */
315
+ let copyTimer = 0;
316
+ /** Copies the selected node as JSON; the result is said under the button and to a screen reader, and stays a few seconds */
315
317
  export async function copySpec(button) {
316
318
  if (!state.selectedNode) return;
317
319
  const text = JSON.stringify({ node: state.selectedNode }, null, 2);
320
+ clearTimeout(copyTimer);
321
+ clearResult('copy-spec');
322
+ const where = $('copy-spec-result');
318
323
  try {
319
324
  await navigator.clipboard.writeText(text);
320
- button.textContent = 'Copied ✓';
325
+ sayResult('copy-spec', `Copied the spec of ${state.selectedNode.label || state.selectedNode.id} to the clipboard.`, true);
321
326
  } catch {
322
- button.textContent = 'Copy blocked';
327
+ sayResult('copy-spec', 'The browser did not allow copying, so nothing was copied. Allow clipboard access for this page, then press Copy Spec again.', false);
323
328
  }
324
- setTimeout(() => { button.textContent = t('copySpec'); }, 1500);
329
+ showResultIn(where, 'copy-spec');
330
+ copyTimer = setTimeout(() => { clearResult('copy-spec'); showResultIn(where, 'copy-spec'); }, RESULT_MS);
325
331
  }
@@ -48,14 +48,22 @@ function brandImage(doc, src, kind, alt = '') {
48
48
  return img;
49
49
  }
50
50
 
51
+ /** The brand button's name starts with what it shows (the title, or the wordmark's alt), so "click Big map" works (WCAG 2.5.3) */
52
+ function nameBrandButton(doc) {
53
+ const button = doc.getElementById('cf-brand');
54
+ const text = doc.getElementById('cf-title');
55
+ if (!button || !text) return;
56
+ const img = text.querySelector && text.querySelector('img');
57
+ const shown = (text.textContent || '').trim() || (img && img.getAttribute('alt')) || '';
58
+ if (shown) button.setAttribute('aria-label', `${shown}: reset the view`);
59
+ }
60
+
51
61
  /**
52
62
  * The repo's brand in the header (docs/config.md#brand): the logo takes the brand mark's place and the wordmark the title text, inside
53
63
  * the same button, so its accessible name stays. The header text stays the repo's own title; `appName` replaces "cornfield" where
54
64
  * cornfield names itself: the button's accessible name and the page's heading (the tab title and the manifest are the server's).
55
65
  */
56
66
  function applyBrand(doc, brand, title) {
57
- const button = doc.getElementById('cf-brand');
58
- if (button && brand.appName) button.setAttribute('aria-label', `${brand.appName}: reset the view`);
59
67
  const text = doc.getElementById('cf-title');
60
68
  if (brand.logo && typeof doc.createElement === 'function') {
61
69
  const mark = doc.getElementById('cf-mark');
@@ -105,6 +113,7 @@ export function applyBranding(doc, config) {
105
113
  const heading = doc.getElementById('cf-heading');
106
114
  if (heading && config.title) heading.textContent = `${config.title}: the map`;
107
115
  if (config.brand) applyBrand(doc, config.brand, config.title);
116
+ nameBrandButton(doc);
108
117
  initThemePicker(doc, config.theme);
109
118
  paintAccount(doc, config);
110
119
  }
@@ -101,11 +101,12 @@ export function touchedIds(nodes, edges) {
101
101
  // ---------------------------------------------------------------------------
102
102
 
103
103
  /**
104
- * "3 added · 1 changed · 1 removed": zero counts are left out; nothing at all reads "No changes".
104
+ * "4 nodes, 2 edges added · 1 node changed" (the bar's words, without the scenarios), or "3 added · 1 changed" for counts
105
+ * without the split: zero counts are left out; nothing at all reads "No changes".
105
106
  * @param {{added?:number, changed?:number, removed?:number}} counts `summarize(proposal)`
106
107
  */
107
108
  export function chipText(counts) {
108
- const parts = MARKS.filter((m) => (counts?.[m] || 0) > 0).map((m) => `${counts[m]} ${m}`);
109
+ const parts = barCounts({ ...counts, scenarios: 0 }).filter((c) => c.mark).map((c) => c.text.replace(/^\+/, ''));
109
110
  return parts.length ? parts.join(' · ') : 'No changes';
110
111
  }
111
112
 
@@ -117,11 +118,34 @@ export function chipText(counts) {
117
118
  */
118
119
  export function barCounts(counts) {
119
120
  const n = (k) => counts?.[k] || 0;
120
- const parts = MARKS.filter((m) => n(m) > 0).map((m) => ({ mark: m, text: `${m === 'added' ? '+' : ''}${n(m)} ${m}` }));
121
+ // with the split (`summarize` gives it) the chip says what it counts: "4 nodes, 2 edges added"; without, the bare number
122
+ const unit = (k, word) => `${k} ${word}${k === 1 ? '' : 's'}`;
123
+ const what = (m) => {
124
+ const ns = counts?.nodes?.[m] || 0;
125
+ const es = counts?.edges?.[m] || 0;
126
+ if (!counts?.nodes || ns + es !== n(m)) return `${m === 'added' ? '+' : ''}${n(m)} ${m}`;
127
+ return `${[ns && unit(ns, 'node'), es && unit(es, 'edge')].filter(Boolean).join(', ')} ${m}`;
128
+ };
129
+ const parts = MARKS.filter((m) => n(m) > 0).map((m) => ({ mark: m, text: what(m) }));
121
130
  if (n('scenarios') > 0) parts.push({ mark: null, text: `${n('scenarios')} ${n('scenarios') === 1 ? 'scenario' : 'scenarios'}` });
122
131
  return parts.length ? parts : [{ mark: null, text: 'No changes' }];
123
132
  }
124
133
 
134
+ /** What a screen reader hears when a view is picked: "Diff view" */
135
+ export const viewWords = (view) => `${view === 'before' ? 'Before' : view === 'after' ? 'After' : 'Diff'} view`;
136
+
137
+ /**
138
+ * What it hears when a proposal has loaded: its title and counts, and the view it is in
139
+ * ("Proposal Alerts: 4 nodes and 2 edges added, 1 node changed, 3 scenarios. Diff view.": in speech a comma would split a part in two).
140
+ * @param {string} title
141
+ * @param {object} counts `summarize(proposal)`
142
+ * @param {'before'|'diff'|'after'} view
143
+ */
144
+ export const openedWords = (title, counts, view) => `Proposal ${title}: ${barCounts(counts).map((c) => c.text.replace(/^\+/, '').replace(', ', ' and ')).join(', ')}. ${viewWords(view)}.`;
145
+
146
+ /** What a click on a change row did: the node (or edge) the camera went to, and what the proposal does to it */
147
+ export const jumpWords = (markWord, name) => `${name}, ${String(markWord).toLowerCase()}. The map is on it.`;
148
+
125
149
  const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
126
150
 
127
151
  /**
@@ -199,10 +223,39 @@ export function proposalPanelHtml(item) {
199
223
  /** What a listing entry's state pill says: its spec PR's state, or "Local" for a proposal that is only in a checkout or a worktree */
200
224
  export const specState = (entry) => (entry.pull ? (entry.pull.draft ? 'Draft' : 'Open') : 'Local');
201
225
 
202
- /** Where a listing entry is, as a line of meta: "PR #11", or the checkout or worktree it is in */
226
+ /** Where a listing entry is, as a line of meta: "PR #11", or the checkout or worktree it is in; a proposal that is also somewhere else says so ("PR #11, and a copy in the checkout") */
203
227
  export function specWhere(entry) {
204
- if (entry.pull) return `PR #${entry.pull.number}`;
205
- return entry.source === 'checkout' ? 'in the checkout' : `in worktree ${entry.source}`;
228
+ const place = (source) => (source === 'checkout' ? 'the checkout' : `worktree ${source}`);
229
+ const copies = Array.isArray(entry.also) ? entry.also : [];
230
+ if (entry.pull) return `PR #${entry.pull.number}${copies.length ? `, and a copy in ${copies.map(place).join(' and ')}` : ''}`;
231
+ return `in ${place(entry.source)}${copies.length ? `, and in ${copies.map(place).join(' and ')}` : ''}`;
232
+ }
233
+
234
+ /**
235
+ * One row for each proposal. A proposal that is a draft in a checkout or a worktree and also on a spec PR is listed twice by the server (the two
236
+ * are different sources); here it is one row, the PR's (the one that can be reviewed), which says there is a local copy too (`also`: the sources
237
+ * of the copies). Local copies only (a checkout and a worktree) are one row as well. An entry that could not be read is never hidden behind
238
+ * another: its row stays and says why. Spec PRs come first (open, then draft), then local drafts; within each, the listing's order.
239
+ * @template T
240
+ * @param {T[]} entries the server's listing
241
+ * @returns {T[]}
242
+ */
243
+ export function mergeSpecs(entries) {
244
+ const groups = new Map();
245
+ for (const entry of entries || []) groups.set(entry.slug, [...(groups.get(entry.slug) || []), entry]);
246
+ const out = [];
247
+ for (const group of groups.values()) {
248
+ const read = group.filter((e) => !e.error);
249
+ const prs = read.filter((e) => e.pull);
250
+ const locals = read.filter((e) => !e.pull);
251
+ const also = (list) => (list.length ? { also: list.map((e) => e.source) } : {});
252
+ if (prs.length) out.push({ ...prs[0], ...also(locals) }, ...prs.slice(1));
253
+ else if (locals.length) out.push({ ...locals[0], ...also(locals.slice(1)) });
254
+ out.push(...group.filter((e) => e.error)); // a copy that could not be read keeps its own row, with why
255
+ }
256
+ // The ones a maintainer can review come first: open spec PRs, then draft ones, then the drafts in a checkout (in the listing's order within each)
257
+ const rank = (e) => (e.pull ? (e.pull.draft ? 1 : 0) : 2);
258
+ return out.map((e, i) => [e, i]).sort((a, b) => rank(a[0]) - rank(b[0]) || a[1] - b[1]).map(([e]) => e);
206
259
  }
207
260
 
208
261
  /**
@@ -217,7 +270,7 @@ export function specRowHtml(entry, { current = null } = {}) {
217
270
  return `<li class="hx-forge-item"><div class="hx-forge-row hx-forge-spec" data-corn="row">${head}<span class="hx-forge-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-forge-meta">${escHtml(specWhere(entry))}</span></div></li>`;
218
271
  }
219
272
  const state = specState(entry);
220
- const tone = state === 'Local' ? '' : ` data-corn-state="${state === 'Draft' ? 'draft' : 'open'}"`;
273
+ const tone = ` data-corn-state="${state === 'Open' ? 'open' : 'draft'}"`; // a proposal only in a checkout is a draft too, as a branch with no pull request is
221
274
  const c = entry.counts || {};
222
275
  const meta = [
223
276
  entry.spec ? `<span>spec ${escHtml(entry.spec)}</span>` : '',
@@ -228,7 +281,7 @@ export function specRowHtml(entry, { current = null } = {}) {
228
281
  c.scenarios ? `<span>${c.scenarios} ${c.scenarios === 1 ? 'scenario' : 'scenarios'}</span>` : '',
229
282
  entry.errors ? `<span class="hx-warn">${entry.errors} ${entry.errors === 1 ? 'problem' : 'problems'}</span>` : '',
230
283
  ].filter(Boolean).join('');
231
- const mine = !!current && current.slug === entry.slug && current.source === entry.source;
284
+ const mine = !!current && current.slug === entry.slug && (current.source === entry.source || (Array.isArray(entry.also) && entry.also.includes(current.source)));
232
285
  return `<li class="hx-forge-item"><button type="button" class="hx-forge-row hx-forge-spec" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}" aria-pressed="${mine}" data-corn="row">`
233
286
  + `<span class="hx-forge-line">${head}<span class="hx-forge-state hx-forge-state--${state === 'Draft' ? 'draft' : state === 'Open' ? 'open' : 'neutral'}" data-corn="state-pill"${tone}>${state}</span></span>`
234
287
  + `${entry.summary ? `<span class="hx-forge-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-forge-meta hx-forge-facts">${meta}</span></button></li>`;
@@ -27,13 +27,15 @@ import { edgePoint, looksFor } from './scene.js';
27
27
  import { onThemeChange } from './theme.js';
28
28
  import { looksWith, onMapStyleChange } from './map-style.js';
29
29
  import {
30
- PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds,
30
+ PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds, viewWords, openedWords, jumpWords,
31
31
  sourceChip, pullNumberOf, notFoundWords, otherCopies, malformedLinkWords,
32
32
  } from './proposal-model.js';
33
33
  import { applyProposal, edgeKey, proposalProblems, summarize } from '../core/proposal.js';
34
34
  import { reviewWords } from './review-model.js';
35
35
  import { collapseSheet, visibleMapRect, isPhone } from './sheets.js';
36
+ import { announce } from './keyboard.js';
36
37
  import { t } from './strings.js';
38
+ import { isOffline } from './connection.js';
37
39
 
38
40
  const $ = (id) => document.getElementById(id);
39
41
 
@@ -75,10 +77,12 @@ export function onProposalListing(fn) {
75
77
  /** Asks the server for the proposals it can serve */
76
78
  export async function loadProposalList() {
77
79
  try {
78
- const res = await fetch('/proposals', { cache: 'no-store' });
79
- if (!res.ok) throw new Error(`GET /proposals answered ${res.status}`);
80
- const body = await res.json();
81
- if (!Array.isArray(body)) throw new Error('GET /proposals did not answer with a list');
80
+ let res;
81
+ try { res = await fetch('/proposals', { cache: 'no-store' }); } catch { throw new Error(isOffline() ? 'You are offline.' : 'cornfield could not be reached. Check that it is still running.'); }
82
+ if (!res.ok) throw new Error(`The server could not list them (error ${res.status}).`);
83
+ let body;
84
+ try { body = await res.json(); } catch { throw new Error('cornfield sent a list this page could not read.'); }
85
+ if (!Array.isArray(body)) throw new Error('cornfield sent something that is not a list of proposals.');
82
86
  listing = body;
83
87
  listingProblem = null;
84
88
  const said = res.headers.get('X-Proposals-Forge-Error');
@@ -86,7 +90,7 @@ export async function loadProposalList() {
86
90
  } catch (err) {
87
91
  listing = null;
88
92
  forgeProblem = null;
89
- listingProblem = err.message || String(err);
93
+ listingProblem = err.message || 'cornfield did not answer.'; // always a plain sentence made above, never a parser's or a runtime's own words
90
94
  }
91
95
  listingAt = Date.now();
92
96
  renderMenu();
@@ -103,21 +107,27 @@ export async function openProposal(slug, source = null) {
103
107
  const token = ++openToken;
104
108
  setMessage(`Opening ${slug} …`);
105
109
  try {
106
- const res = await fetch(`/proposals/${encodeURIComponent(slug)}.json${source ? `?source=${encodeURIComponent(source)}` : ''}`, { cache: 'no-store' });
110
+ let res;
111
+ try { res = await fetch(`/proposals/${encodeURIComponent(slug)}.json${source ? `?source=${encodeURIComponent(source)}` : ''}`, { cache: 'no-store' }); } catch { throw new Error(isOffline() ? `${slug} could not be opened: you are offline.` : `${slug} could not be opened: cornfield could not be reached.`); }
107
112
  if (!res.ok) {
108
113
  let why = '';
109
114
  try { why = (await res.json()).error || ''; } catch { /* no body */ }
110
- const err = new Error(res.status === 404 ? notFoundWords(slug, source) : why || `The server answered ${res.status}.`);
115
+ const err = new Error(res.status === 404 ? notFoundWords(slug, source) : `${slug} could not be opened: ${why || `the server had a problem (error ${res.status}).`}`);
111
116
  err.notFound = res.status === 404;
112
117
  throw err;
113
118
  }
114
119
  const found = res.headers.get('X-Proposal-Source');
115
- showProposal(await res.json(), { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true });
120
+ let item;
121
+ try { item = await res.json(); } catch { throw new Error(`${slug} could not be opened: cornfield sent a file this page could not read.`); }
122
+ showProposal(item, { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true });
123
+ // said once, here: a proposal opens on a person's asking, never on a background refresh
124
+ announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView));
116
125
  return true;
117
126
  } catch (err) {
118
127
  console.error('Opening the proposal failed', err);
119
128
  // Said plainly, with the ways on: the Specs list, and the same name under another source when the list has one
120
- setMessage(err.message || String(err), true, err.notFound ? [specsWay()] : []);
129
+ // (a failure that is not "no such proposal" can be asked for again, or let go of: Retry and Close)
130
+ setMessage(err.message || `${slug} could not be opened.`, true, err.notFound ? [specsWay()] : [{ label: 'Retry', way: 'retry', slug, source }, { label: 'Close', way: 'close' }]);
121
131
  if (err.notFound && token === openToken) {
122
132
  await loadProposalList();
123
133
  const sources = new Set((Array.isArray(listing) ? listing : []).map((e) => e && e.source));
@@ -196,7 +206,7 @@ export function closeProposal() {
196
206
  }
197
207
 
198
208
  /** Switches between Before, Diff and After; no node moves. Entering Diff fits the camera to the change. */
199
- export function setProposalView(view) {
209
+ export function setProposalView(view, { quiet = false } = {}) {
200
210
  if (!state.proposal || !PROPOSAL_VIEWS.includes(view) || state.proposalView === view) return;
201
211
  state.proposalView = view;
202
212
  touchScene();
@@ -205,6 +215,7 @@ export function setProposalView(view) {
205
215
  render();
206
216
  renderBar();
207
217
  syncAddress();
218
+ if (!quiet) announce(viewWords(view));
208
219
  }
209
220
 
210
221
  /** Hands the map new nodes and edges, keeping the selection on the same node */
@@ -408,13 +419,14 @@ function focusChange(kind, key) {
408
419
  if (!item) return;
409
420
  const ends = (kind === 'edge' ? [state.nodes.find((n) => n.id === item.from), state.nodes.find((n) => n.id === item.to)] : [item]).filter(Boolean);
410
421
  if (!ends.length) return;
411
- if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff'); // Before or After hides what it removes or adds
422
+ if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff', { quiet: true }); // Before or After hides what it removes or adds
412
423
  if (kind === 'edge') showEdgePanel(item);
413
424
  else selectNode(item);
414
425
  // The panel is open now, so what it covers is known
415
426
  const cam = frameNodes(ends, visibleMapRect(), { padding: fitPadding(), maxZoom: Math.max(READ_ZOOM, state.camera.zoom), minZoom: getMinZoom() });
416
427
  if (cam) Object.assign(state.camera, cam);
417
428
  render();
429
+ announce(jumpWords(MARK_WORDS[item.mark] || item.mark, kind === 'edge' ? `${nameOf(item.from)} to ${nameOf(item.to)}` : item.label));
418
430
  }
419
431
 
420
432
  // ---------------------------------------------------------------------------
@@ -616,7 +628,7 @@ const ACTIONS = {
616
628
  'toggle-proposal-mode': () => toggleMode(),
617
629
  'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
618
630
  'toggle-proposal-changes': () => toggleChanges(),
619
- 'proposal-way': (el) => (el.dataset.way === 'open' ? openProposal(el.dataset.slug, el.dataset.source || null) : openSpecs()),
631
+ 'proposal-way': (el) => (el.dataset.way === 'open' ? openProposal(el.dataset.slug, el.dataset.source || null) : el.dataset.way === 'retry' ? retryOpen(el.dataset.slug, el.dataset.source || null) : el.dataset.way === 'close' ? closeAfterFailure() : openSpecs()),
620
632
  'proposal-focus': (el) => focusChange(el.dataset.kind, el.dataset.key),
621
633
  };
622
634
 
@@ -631,6 +643,22 @@ function onClick(e) {
631
643
  if (menuOpen() && wrap && !wrap.contains(e.target) && !(target && target.dataset.action === 'proposal-way')) closeMenu(); // (a bad link's Specs list opens it from outside)
632
644
  }
633
645
 
646
+ /** Retry, after a proposal failed to open: the bar is drawn anew either way, so the focus goes somewhere stated, the proposal's name once it opened or the new Retry if it failed again */
647
+ async function retryOpen(slug, source) {
648
+ const opened = await openProposal(slug, source);
649
+ const to = opened ? $('proposal-title') : document.querySelector('#proposal-ways [data-way="retry"]');
650
+ if (!to) return;
651
+ if (opened) to.tabIndex = -1;
652
+ to.focus();
653
+ }
654
+
655
+ /** Close, after a proposal failed to open: the bar goes, and the focus goes to the map, never the page */
656
+ function closeAfterFailure() {
657
+ closeProposal();
658
+ const map = $('graph-canvas');
659
+ if (map) map.focus();
660
+ }
661
+
634
662
  /** A bad link's way on: the Work panel's Specs tab when there is one, else the header's Proposals menu */
635
663
  function openSpecs() {
636
664
  if (hooks.openSpecs) { hooks.openSpecs(); return; }
@@ -723,7 +751,7 @@ export async function initProposals() {
723
751
  return false;
724
752
  }
725
753
  const ok = await openProposal(asked.slug, asked.source);
726
- if (ok && asked.view) setProposalView(asked.view);
754
+ if (ok && asked.view) { setProposalView(asked.view, { quiet: true }); announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView)); }
727
755
  return ok;
728
756
  }
729
757
 
@@ -8,7 +8,7 @@
8
8
  * labels are the label layer's (labels.js), one transparent canvas over the map for either renderer.
9
9
  */
10
10
 
11
- import { CORE_RATIO, ARROW, MARK_MIN_PX, looksFor, packetPoint } from './scene.js';
11
+ import { CORE_RATIO, ARROW, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint } from './scene.js';
12
12
  import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
13
13
 
14
14
  const TAU = Math.PI * 2;
@@ -88,6 +88,18 @@ function drawEdge(ctx, edge, timeMs, zoom, withPacket = true) {
88
88
  ctx.stroke();
89
89
  ctx.setLineDash([]);
90
90
 
91
+ // A removed edge is struck across at its midpoint, as the WebGL tips pass draws it
92
+ if (edge.mark === 'removed') {
93
+ const mid = edgePoint(edge, 0.5);
94
+ const len = Math.hypot(edge.x2 - edge.x1, edge.y2 - edge.y1);
95
+ const [dx, dy] = len > 0 ? [(edge.x2 - edge.x1) / len, (edge.y2 - edge.y1) / len] : [1, 0];
96
+ ctx.beginPath();
97
+ ctx.moveTo(mid.x - dy * EDGE_STRIKE.halfLength, mid.y + dx * EDGE_STRIKE.halfLength);
98
+ ctx.lineTo(mid.x + dy * EDGE_STRIKE.halfLength, mid.y - dx * EDGE_STRIKE.halfLength);
99
+ ctx.lineWidth = Math.max(EDGE_STRIKE.width, 1.5 / zoom);
100
+ ctx.stroke();
101
+ }
102
+
91
103
  // Arrowhead along the curve's end tangent
92
104
  if (edge.arrow) {
93
105
  const { cx, cy } = edge.curve || { cx: edge.x1, cy: edge.y1 };
@@ -154,17 +166,23 @@ function drawNode(ctx, node, zoom, looks, style) {
154
166
  ctx.stroke();
155
167
  }
156
168
 
157
- // A proposal's mark: a ring just outside the node, dashed for an addition (drawn a little stronger than the node, so a faded removal is still plain)
169
+ // A proposal's mark: a ring just outside the node in the mark's own dash, at the node's alpha (a removed node's ring is as faded
170
+ // as the node, as the WebGL shader draws it and as the contrast check measures it), and for removed a strike through the node
158
171
  const mark = looks.mark[node.mark];
159
172
  if (mark) {
160
- ctx.globalAlpha = Math.min(1, node.alpha * 1.8);
161
- circle(ctx, node.x, node.y, node.r + Math.max(mark.ringR, MARK_MIN_PX.gap / zoom));
173
+ const rr = node.r + Math.max(mark.ringR, MARK_MIN_PX.gap / zoom);
174
+ circle(ctx, node.x, node.y, rr);
162
175
  ctx.strokeStyle = mark.color;
163
176
  ctx.lineWidth = Math.max(mark.ringWidth, MARK_MIN_PX.ring / zoom);
164
177
  ctx.setLineDash(mark.ringDash || []);
165
178
  ctx.stroke();
166
179
  ctx.setLineDash([]);
167
- ctx.globalAlpha = node.alpha;
180
+ if (node.mark === 'removed') {
181
+ ctx.beginPath();
182
+ ctx.moveTo(node.x - rr, node.y);
183
+ ctx.lineTo(node.x + rr, node.y);
184
+ ctx.stroke();
185
+ }
168
186
  }
169
187
 
170
188
  // The node circle, glowing, with a white core dot
@@ -46,9 +46,14 @@ const VERDICT_WORDS = { approved: 'Approved', notes: 'Sent back' };
46
46
  * @param {number} nowMs
47
47
  */
48
48
  export function reviewWords(review, nowMs) {
49
- if (!review || !VERDICT_WORDS[review.verdict]) return '';
50
- const when = relativeTime(review.at, nowMs);
51
- return when ? `${VERDICT_WORDS[review.verdict]} ${when}` : VERDICT_WORDS[review.verdict];
49
+ const { verdict, when } = reviewParts(review, nowMs);
50
+ return when ? `${verdict} ${when}` : verdict;
51
+ }
52
+
53
+ /** The same line in two parts, `{ verdict: 'Approved', when: '3 minutes ago' }`: the bar says the verdict (a live region) and shows the time beside it */
54
+ export function reviewParts(review, nowMs) {
55
+ if (!review || !VERDICT_WORDS[review.verdict]) return { verdict: '', when: '' };
56
+ return { verdict: VERDICT_WORDS[review.verdict], when: relativeTime(review.at, nowMs) || '' };
52
57
  }
53
58
 
54
59
  /** Why a proposal cannot be sent back yet: it needs a note. Null when it can be. */
@@ -20,6 +20,7 @@
20
20
 
21
21
  import { escHtml } from './state.js';
22
22
  import { announce } from './keyboard.js';
23
+ import { trapTab } from './focusables.js';
23
24
  import { tokensUrl, introWords, DEFAULT_DAYS, MAX_DAYS, makeRequest, revokeUrl, tokenLine, errorWords } from './review-tokens-model.js';
24
25
 
25
26
  const $ = (id) => document.getElementById(id);
@@ -178,13 +179,7 @@ function onClick(e) {
178
179
  function onKey(e) {
179
180
  e.stopPropagation();
180
181
  if (e.key === 'Escape') { e.preventDefault(); closeTokens(); return; }
181
- if (e.key !== 'Tab') return;
182
- const items = [...dialog().querySelectorAll('button:not([disabled]), input:not([disabled])')].filter((el) => !el.closest('[hidden]'));
183
- if (!items.length) { e.preventDefault(); return; }
184
- const at = items.indexOf(document.activeElement);
185
- const next = e.shiftKey ? (at <= 0 ? items.length - 1 : at - 1) : (at === -1 || at === items.length - 1 ? 0 : at + 1);
186
- e.preventDefault();
187
- items[next].focus();
182
+ trapTab(e, dialog());
188
183
  }
189
184
 
190
185
  /**