@popcorn245/cornfield 0.34.1 → 0.34.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/contrast.js +62 -0
- package/core/proposal.js +10 -3
- package/core/strings.js +1 -0
- package/explorer/camera.js +106 -0
- package/explorer/check.js +6 -1
- package/explorer/diff-marks.js +35 -0
- package/explorer/explorer.css +60 -5
- package/explorer/focusables.js +35 -0
- package/explorer/forge-panel.js +5 -15
- package/explorer/index.html +5 -3
- package/explorer/mockups.js +3 -9
- package/explorer/plugins.js +11 -2
- package/explorer/proposal-model.js +138 -3
- package/explorer/proposal.js +167 -21
- package/explorer/renderer-canvas2d.js +23 -5
- package/explorer/review-model.js +8 -3
- package/explorer/review-tokens.js +2 -7
- package/explorer/review.js +24 -7
- package/explorer/scenario-ui.js +78 -15
- package/explorer/scenario.js +16 -24
- package/explorer/scene.js +8 -7
- package/explorer/sheets.js +26 -0
- package/explorer/theme-model.js +13 -6
- package/explorer/tokens.css +10 -10
- package/explorer/whatif.js +10 -3
- package/package.json +1 -1
- package/server/proposals.js +1 -1
|
@@ -101,11 +101,12 @@ export function touchedIds(nodes, edges) {
|
|
|
101
101
|
// ---------------------------------------------------------------------------
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
-
* "
|
|
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 =
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -234,6 +258,117 @@ export function specRowHtml(entry, { current = null } = {}) {
|
|
|
234
258
|
+ `${entry.summary ? `<span class="hx-forge-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-forge-meta hx-forge-facts">${meta}</span></button></li>`;
|
|
235
259
|
}
|
|
236
260
|
|
|
261
|
+
// ---------------------------------------------------------------------------
|
|
262
|
+
// Which copy is open: the chip on the bar, and a link that finds nothing
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
|
|
265
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The checks on a PR's head in words, for the bar's source chip: "no checks", "1 check running", "2 checks failed, 1 check running",
|
|
269
|
+
* "all 3 checks passed". Failed first, then cancelled, then the ones still going.
|
|
270
|
+
* @param {{ state: string }[]} checks
|
|
271
|
+
*/
|
|
272
|
+
export function checksLine(checks) {
|
|
273
|
+
if (!Array.isArray(checks) || checks.length === 0) return 'no checks';
|
|
274
|
+
const n = (states) => checks.filter((c) => states.includes(c.state)).length;
|
|
275
|
+
const failed = n(['failure']);
|
|
276
|
+
const cancelled = n(['cancelled']);
|
|
277
|
+
const waiting = n(['running', 'queued']);
|
|
278
|
+
const parts = [];
|
|
279
|
+
if (failed) parts.push(`${plural(failed, 'check')} failed`);
|
|
280
|
+
if (cancelled) parts.push(`${plural(cancelled, 'check')} cancelled`);
|
|
281
|
+
if (waiting) parts.push(`${plural(waiting, 'check')} running`);
|
|
282
|
+
if (parts.length) return parts.join(', ');
|
|
283
|
+
return checks.length === 1 ? '1 check passed' : `all ${checks.length} checks passed`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** `pull/<n>` to n, or null (the same shape the server reads, server/proposal-pulls.js) */
|
|
287
|
+
export function pullNumberOf(source) {
|
|
288
|
+
const m = typeof source === 'string' ? /^pull\/([1-9]\d{0,8})$/.exec(source) : null;
|
|
289
|
+
return m ? Number(m[1]) : null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Where a source is, in words: "PR #21", "the checkout", "worktree <name>" */
|
|
293
|
+
export function sourceWhere(source) {
|
|
294
|
+
const n = pullNumberOf(source);
|
|
295
|
+
if (n) return `PR #${n}`;
|
|
296
|
+
if (!source || source === 'checkout') return 'the checkout';
|
|
297
|
+
return `worktree ${source}`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* What the bar's source chip says of the copy under review. A spec PR's copy: "PR #24 · draft · 1 check running" (the state and the checks
|
|
302
|
+
* are left out until known: `pull` is the listing's entry, `checks` the PR's checks, or null when they could not be read). A copy in the checkout
|
|
303
|
+
* or a worktree: "Local draft · in the checkout". `href` is the PR's address when it has one (the caller checks the scheme). `state` is the
|
|
304
|
+
* public `data-corn-state` of the copy (docs/theming.md): the PR's `open`, `draft`, `merged` or `closed`, and `draft` for a local copy (a
|
|
305
|
+
* branch with no pull request yet is `draft`); '' while the PR is not known yet.
|
|
306
|
+
* @param {string|null} source `pull/<n>`, `checkout` or a worktree's name
|
|
307
|
+
* @param {{ draft?: boolean, url?: string, state?: string }|null} [pull]
|
|
308
|
+
* @param {{ state: string }[]|null} [checks]
|
|
309
|
+
* @returns {{ text: string, href: string|null, state: ''|'open'|'draft'|'merged'|'closed', label: string }}
|
|
310
|
+
*/
|
|
311
|
+
export function sourceChip(source, pull = null, checks = null) {
|
|
312
|
+
const n = pullNumberOf(source);
|
|
313
|
+
if (!n) {
|
|
314
|
+
const where = !source || source === 'checkout' ? 'in the checkout' : `in worktree ${source}`;
|
|
315
|
+
return { text: `Local draft \u00b7 ${where}`, href: null, state: 'draft', label: `This is a local draft, ${where}, not a pull request` };
|
|
316
|
+
}
|
|
317
|
+
const parts = [`PR #${n}`];
|
|
318
|
+
const state = !pull ? '' : pull.state === 'merged' || pull.state === 'closed' ? pull.state : typeof pull.draft === 'boolean' ? (pull.draft ? 'draft' : 'open') : '';
|
|
319
|
+
if (state) parts.push(state);
|
|
320
|
+
if (Array.isArray(checks)) parts.push(checksLine(checks));
|
|
321
|
+
return {
|
|
322
|
+
text: parts.join(' \u00b7 '),
|
|
323
|
+
href: pull && typeof pull.url === 'string' ? pull.url : null,
|
|
324
|
+
state,
|
|
325
|
+
label: `Reviewing spec pull request: ${parts.join(', ')}`,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* What to say when a link names a proposal the server does not have: what was not found, said plainly. The place is named only when it is
|
|
331
|
+
* one: a PR number, the checkout, or a worktree the listing has (`sources`); anything else the link says is not repeated back.
|
|
332
|
+
* @param {string} slug (it passed the slug pattern)
|
|
333
|
+
* @param {string|null} source
|
|
334
|
+
* @param {Set<string>|null} [sources] the sources the listing knows, when it has been read
|
|
335
|
+
*/
|
|
336
|
+
export function notFoundWords(slug, source, sources = null) {
|
|
337
|
+
if (!source) return `There is no proposal called ${slug}.`;
|
|
338
|
+
if (pullNumberOf(source) || source === 'checkout' || (sources && sources.has(source) && SLUG.test(source))) return `There is no proposal called ${slug} in ${sourceWhere(source)}.`;
|
|
339
|
+
return `There is no proposal called ${slug}. This link's source is not a PR, the checkout or a worktree.`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* What to say when `?proposal=` holds something that is not a proposal's name (a typo, a cut-off link), or null when it is a name or absent.
|
|
344
|
+
* The value is shown as text, cut to 60 characters; the caller sets it with `textContent`.
|
|
345
|
+
* @param {string} search `location.search`
|
|
346
|
+
* @returns {string|null}
|
|
347
|
+
*/
|
|
348
|
+
export function malformedLinkWords(search) {
|
|
349
|
+
const params = new URLSearchParams(search || '');
|
|
350
|
+
if (!params.has('proposal')) return null;
|
|
351
|
+
const raw = params.get('proposal') || '';
|
|
352
|
+
if (SLUG.test(raw)) return null;
|
|
353
|
+
const shown = raw.length > 60 ? `${raw.slice(0, 59)}\u2026` : raw;
|
|
354
|
+
return shown.trim() ? `This link does not name a proposal: \u201c${shown}\u201d is not a proposal's name.` : 'This link does not name a proposal.';
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* The ways on from a link that found nothing: the same slug under another source, from the listing (a spec PR's copy before a local one),
|
|
359
|
+
* each as `{ slug, source, label }`. The Specs list is offered by the caller, always.
|
|
360
|
+
* @param {{ slug: string, source: string, error?: string, pull?: object }[]|null} listing
|
|
361
|
+
* @param {string} slug
|
|
362
|
+
* @param {string|null} source the one that was asked for (left out)
|
|
363
|
+
*/
|
|
364
|
+
export function otherCopies(listing, slug, source) {
|
|
365
|
+
if (!Array.isArray(listing)) return [];
|
|
366
|
+
return listing
|
|
367
|
+
.filter((e) => e && e.slug === slug && e.source !== source && !e.error)
|
|
368
|
+
.sort((a, b) => (pullNumberOf(b.source) ? 1 : 0) - (pullNumberOf(a.source) ? 1 : 0))
|
|
369
|
+
.map((e) => ({ slug: e.slug, source: e.source, label: pullNumberOf(e.source) ? `Open the copy in PR #${pullNumberOf(e.source)}${e.pull && e.pull.draft ? ' (draft)' : ''}` : `Open the copy ${e.source === 'checkout' ? 'in the checkout' : `in worktree ${e.source}`}` }));
|
|
370
|
+
}
|
|
371
|
+
|
|
237
372
|
// ---------------------------------------------------------------------------
|
|
238
373
|
// Where an added node sits
|
|
239
374
|
// ---------------------------------------------------------------------------
|
package/explorer/proposal.js
CHANGED
|
@@ -19,18 +19,21 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import { state, touchScene, viewEdges, nameOf, escHtml } from './state.js';
|
|
22
|
-
import { render, getScene, fitGraphToViewport, fitPadding, isNodeVisible, ensureFlowLoop, screenToWorld } from './render.js';
|
|
22
|
+
import { render, getScene, fitGraphToViewport, fitPadding, isNodeVisible, ensureFlowLoop, screenToWorld, getMinZoom } from './render.js';
|
|
23
|
+
import { frameNodes, largestGroup, READ_ZOOM, FRAME_ZOOM_MIN } from './camera.js';
|
|
23
24
|
import { setMap } from './view.js';
|
|
24
25
|
import { closeDrawer, selectNode } from './panels.js';
|
|
25
26
|
import { edgePoint, looksFor } from './scene.js';
|
|
26
27
|
import { onThemeChange } from './theme.js';
|
|
27
28
|
import { looksWith, onMapStyleChange } from './map-style.js';
|
|
28
29
|
import {
|
|
29
|
-
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
|
+
sourceChip, pullNumberOf, notFoundWords, otherCopies, malformedLinkWords,
|
|
30
32
|
} from './proposal-model.js';
|
|
31
33
|
import { applyProposal, edgeKey, proposalProblems, summarize } from '../core/proposal.js';
|
|
32
34
|
import { reviewWords } from './review-model.js';
|
|
33
|
-
import { collapseSheet } from './sheets.js';
|
|
35
|
+
import { collapseSheet, visibleMapRect, isPhone } from './sheets.js';
|
|
36
|
+
import { announce } from './keyboard.js';
|
|
34
37
|
import { t } from './strings.js';
|
|
35
38
|
|
|
36
39
|
const $ = (id) => document.getElementById(id);
|
|
@@ -42,8 +45,9 @@ const $ = (id) => document.getElementById(id);
|
|
|
42
45
|
* - `beforeClose()` returns false to keep the proposal open (it is asking whether to keep the edits)
|
|
43
46
|
* - `closed()` the proposal was closed
|
|
44
47
|
* - `bar(open)` the bar was drawn: redraw the editing controls
|
|
48
|
+
* - `openSpecs()` the Work panel's Specs tab, for a bad link's way on (forge-panel.js sets it; without it the header's Proposals menu opens)
|
|
45
49
|
*/
|
|
46
|
-
export const hooks = { effective: null, mark: null, beforeClose: null, closed: null, bar: null };
|
|
50
|
+
export const hooks = { effective: null, mark: null, beforeClose: null, closed: null, bar: null, openSpecs: null };
|
|
47
51
|
|
|
48
52
|
/** Whether the open proposal's source goes in the address (see `showProposal`) */
|
|
49
53
|
let pinnedSource = false;
|
|
@@ -97,24 +101,40 @@ export async function loadProposalList() {
|
|
|
97
101
|
* @returns {Promise<boolean>} whether it opened
|
|
98
102
|
*/
|
|
99
103
|
export async function openProposal(slug, source = null) {
|
|
104
|
+
const token = ++openToken;
|
|
100
105
|
setMessage(`Opening ${slug} …`);
|
|
101
106
|
try {
|
|
102
107
|
const res = await fetch(`/proposals/${encodeURIComponent(slug)}.json${source ? `?source=${encodeURIComponent(source)}` : ''}`, { cache: 'no-store' });
|
|
103
108
|
if (!res.ok) {
|
|
104
109
|
let why = '';
|
|
105
110
|
try { why = (await res.json()).error || ''; } catch { /* no body */ }
|
|
106
|
-
|
|
111
|
+
const err = new Error(res.status === 404 ? notFoundWords(slug, source) : why || `The server answered ${res.status}.`);
|
|
112
|
+
err.notFound = res.status === 404;
|
|
113
|
+
throw err;
|
|
107
114
|
}
|
|
108
115
|
const found = res.headers.get('X-Proposal-Source');
|
|
109
116
|
showProposal(await res.json(), { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true });
|
|
117
|
+
// said once, here: a proposal opens on a person's asking, never on a background refresh
|
|
118
|
+
announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView));
|
|
110
119
|
return true;
|
|
111
120
|
} catch (err) {
|
|
112
121
|
console.error('Opening the proposal failed', err);
|
|
113
|
-
|
|
122
|
+
// Said plainly, with the ways on: the Specs list, and the same name under another source when the list has one
|
|
123
|
+
setMessage(err.message || String(err), true, err.notFound ? [specsWay()] : []);
|
|
124
|
+
if (err.notFound && token === openToken) {
|
|
125
|
+
await loadProposalList();
|
|
126
|
+
const sources = new Set((Array.isArray(listing) ? listing : []).map((e) => e && e.source));
|
|
127
|
+
if (token === openToken) setMessage(notFoundWords(slug, source, sources), true, [...otherCopies(listing, slug, source).map((c) => ({ label: c.label, way: 'open', slug: c.slug, source: c.source })), specsWay()]);
|
|
128
|
+
}
|
|
114
129
|
return false;
|
|
115
130
|
}
|
|
116
131
|
}
|
|
117
132
|
|
|
133
|
+
/** The way on every bad link offers: the list of specs */
|
|
134
|
+
const specsWay = () => ({ label: t('openSpecsList'), way: 'specs' });
|
|
135
|
+
/** Which `openProposal` is the latest, so a slow answer never writes over a newer one */
|
|
136
|
+
let openToken = 0;
|
|
137
|
+
|
|
118
138
|
/**
|
|
119
139
|
* Puts a parsed proposal on the map. The map's nodes and edges become `applyProposal(base, proposal)`.
|
|
120
140
|
* @param {object} proposal
|
|
@@ -155,10 +175,10 @@ export function rebuildProposalMap(effective = hooks.effective ? hooks.effective
|
|
|
155
175
|
applied = { nodes: state.baseNodes.map((n) => ({ ...n, mark: 'none' })), edges: state.baseEdges.map((e) => ({ ...e, mark: 'none' })) };
|
|
156
176
|
}
|
|
157
177
|
swapMap(applied.nodes, applied.edges);
|
|
178
|
+
renderBar(); // first: the fit below leaves out what the bar covers, so the bar must be laid out
|
|
158
179
|
if (fit) fitToChange();
|
|
159
180
|
render();
|
|
160
181
|
ensureFlowLoop();
|
|
161
|
-
renderBar();
|
|
162
182
|
}
|
|
163
183
|
|
|
164
184
|
/** Closes the proposal: the plain map comes back, as it was, and the address loses `?proposal=` */
|
|
@@ -179,7 +199,7 @@ export function closeProposal() {
|
|
|
179
199
|
}
|
|
180
200
|
|
|
181
201
|
/** Switches between Before, Diff and After; no node moves. Entering Diff fits the camera to the change. */
|
|
182
|
-
export function setProposalView(view) {
|
|
202
|
+
export function setProposalView(view, { quiet = false } = {}) {
|
|
183
203
|
if (!state.proposal || !PROPOSAL_VIEWS.includes(view) || state.proposalView === view) return;
|
|
184
204
|
state.proposalView = view;
|
|
185
205
|
touchScene();
|
|
@@ -188,6 +208,7 @@ export function setProposalView(view) {
|
|
|
188
208
|
render();
|
|
189
209
|
renderBar();
|
|
190
210
|
syncAddress();
|
|
211
|
+
if (!quiet) announce(viewWords(view));
|
|
191
212
|
}
|
|
192
213
|
|
|
193
214
|
/** Hands the map new nodes and edges, keeping the selection on the same node */
|
|
@@ -203,9 +224,23 @@ function swapMap(nodes, edges) {
|
|
|
203
224
|
touchScene();
|
|
204
225
|
}
|
|
205
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Frames what the proposal changes (nodes added, changed or removed, and both ends of a changed edge; not what they connect to) in the part of the
|
|
229
|
+
* map nothing covers (the bar, the node panel, a phone's sheets), at a zoom up to 1 so their labels read. Only what is drawn counts: a change on a
|
|
230
|
+
* layer that is off is not framed (the map would centre on ground the viewer cannot see). When the change is wider than FRAME_ZOOM_MIN shows,
|
|
231
|
+
* the biggest part of it that fits there is framed, not the whole at a zoom where it is a speck (the change list reaches the rest). A proposal that changes nothing drawn shows the whole map.
|
|
232
|
+
*/
|
|
206
233
|
function fitToChange() {
|
|
207
|
-
const {
|
|
208
|
-
|
|
234
|
+
const { touched } = touchedIds(state.nodes, viewEdges());
|
|
235
|
+
const items = state.nodes.filter((n) => touched.has(n.id) && isNodeVisible(n));
|
|
236
|
+
const rect = visibleMapRect();
|
|
237
|
+
const opts = { padding: fitPadding(), maxZoom: 1, minZoom: getMinZoom() };
|
|
238
|
+
// The whole change when it fits at FRAME_ZOOM_MIN or closer; else the biggest part of it that does (camera.js)
|
|
239
|
+
const group = largestGroup(items, rect, { ...opts, minZoom: Math.max(opts.minZoom, FRAME_ZOOM_MIN) });
|
|
240
|
+
const cam = items.length ? frameNodes(group, rect, opts) : null;
|
|
241
|
+
if (!cam) { fitGraphToViewport(fitPadding()); return; }
|
|
242
|
+
Object.assign(state.camera, cam);
|
|
243
|
+
render();
|
|
209
244
|
}
|
|
210
245
|
|
|
211
246
|
/** `?proposal=` (and `source`, `proposalView`) follow the open proposal, without a new history entry; other parameters stay */
|
|
@@ -228,8 +263,8 @@ function syncAddress() {
|
|
|
228
263
|
// The bar: title, counts chip, Before / Diff / After, problems, Close
|
|
229
264
|
// ---------------------------------------------------------------------------
|
|
230
265
|
|
|
231
|
-
/** One line in the bar instead of a proposal: while one opens, or why it did not */
|
|
232
|
-
function setMessage(text, isError = false) {
|
|
266
|
+
/** One line in the bar instead of a proposal: while one opens, or why it did not (with `ways`, the buttons that go on from there) */
|
|
267
|
+
function setMessage(text, isError = false, ways = []) {
|
|
233
268
|
const bar = $('proposal-bar');
|
|
234
269
|
if (!bar) return;
|
|
235
270
|
bar.hidden = false;
|
|
@@ -238,6 +273,52 @@ function setMessage(text, isError = false) {
|
|
|
238
273
|
const msg = $('proposal-message');
|
|
239
274
|
msg.hidden = false;
|
|
240
275
|
msg.textContent = text;
|
|
276
|
+
const box = $('proposal-ways');
|
|
277
|
+
if (!box) return;
|
|
278
|
+
box.hidden = ways.length === 0;
|
|
279
|
+
box.innerHTML = ways.map((w) => `<button type="button" class="hx-btn" data-action="proposal-way" data-way="${escHtml(w.way)}"${w.slug ? ` data-slug="${escHtml(w.slug)}"` : ''}${w.source ? ` data-source="${escHtml(w.source)}"` : ''} data-peek-ok data-corn-kind="quiet">${escHtml(w.label)}</button>`).join('');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
// Which copy is open: the chip after the title
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
|
|
286
|
+
/** The spec PRs read for the chip, by number: `{ pull, checks }` of `GET /api/forge/pulls/<n>`; kept, so a proposal opened again shows it at once and then asks again */
|
|
287
|
+
const pullInfo = new Map();
|
|
288
|
+
/** The proposal the PR was last asked for (`source/slug`): asked again when another opens, not each time the bar is drawn */
|
|
289
|
+
let pullAskedFor = null;
|
|
290
|
+
|
|
291
|
+
const safeHref = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
|
|
292
|
+
|
|
293
|
+
/** The chip says which copy is under review: a PR (number, draft or open, the checks in words) linking to it, or a local draft and where. It only tells. */
|
|
294
|
+
function paintSource() {
|
|
295
|
+
const chip = $('proposal-source');
|
|
296
|
+
if (!chip) return;
|
|
297
|
+
const source = state.proposal ? state.proposalSource : null;
|
|
298
|
+
chip.hidden = !source;
|
|
299
|
+
if (!source) return;
|
|
300
|
+
const n = pullNumberOf(source);
|
|
301
|
+
const known = n ? pullInfo.get(n) : null;
|
|
302
|
+
const entry = n && Array.isArray(listing) ? listing.find((e) => e.slug === state.proposalSlug && e.source === source) : null;
|
|
303
|
+
const words = sourceChip(source, (known && known.pull) || (entry && entry.pull) || null, known ? known.checks : null);
|
|
304
|
+
chip.textContent = words.text;
|
|
305
|
+
if (words.state) chip.dataset.cornState = words.state; else delete chip.dataset.cornState;
|
|
306
|
+
const href = safeHref(words.href);
|
|
307
|
+
if (href) { chip.setAttribute('href', href); chip.setAttribute('target', '_blank'); chip.setAttribute('rel', 'noreferrer'); chip.title = 'Open this pull request'; } else {
|
|
308
|
+
chip.removeAttribute('href'); chip.removeAttribute('target'); chip.removeAttribute('rel'); chip.title = words.label;
|
|
309
|
+
}
|
|
310
|
+
const key = `${source}/${state.proposalSlug}`;
|
|
311
|
+
if (n && pullAskedFor !== key) { pullAskedFor = key; loadPullInfo(n); }
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Reads the PR's state and checks once for this opening of the bar (the server keeps its own short cache); a forge that cannot say leaves the chip as it is */
|
|
315
|
+
async function loadPullInfo(n) {
|
|
316
|
+
try {
|
|
317
|
+
const res = await fetch(`/api/forge/pulls/${n}`);
|
|
318
|
+
const body = res.ok ? await res.json() : null;
|
|
319
|
+
if (body && body.ok !== false && body.pull) pullInfo.set(n, { pull: body.pull, checks: Array.isArray(body.checks) ? body.checks : null });
|
|
320
|
+
} catch { /* no forge, or not signed in: the chip keeps what it has */ }
|
|
321
|
+
if (state.proposal && pullNumberOf(state.proposalSource) === n) paintSource();
|
|
241
322
|
}
|
|
242
323
|
|
|
243
324
|
/** The problems a proposal has, as the bar lists them (at most `max`, then "and N more") */
|
|
@@ -264,6 +345,7 @@ export function renderBar() {
|
|
|
264
345
|
$('proposal-body').hidden = false;
|
|
265
346
|
const p = state.proposal;
|
|
266
347
|
$('proposal-title').textContent = (p && typeof p.title === 'string' && p.title) || state.proposalSlug || 'Proposal';
|
|
348
|
+
paintSource();
|
|
267
349
|
const summary = $('proposal-summary');
|
|
268
350
|
summary.textContent = (p && typeof p.summary === 'string' && p.summary) || '';
|
|
269
351
|
const title = $('proposal-title');
|
|
@@ -311,26 +393,33 @@ function renderChanges() {
|
|
|
311
393
|
list.innerHTML = rows.join('') || '<p class="hx-faint">This proposal changes nothing on the map.</p>';
|
|
312
394
|
}
|
|
313
395
|
|
|
314
|
-
function toggleChanges() {
|
|
396
|
+
function toggleChanges(refocus = false) {
|
|
315
397
|
const list = $('proposal-changes');
|
|
316
398
|
if (!list) return;
|
|
317
399
|
list.hidden = !list.hidden;
|
|
318
400
|
$('proposal-summary').hidden = list.hidden || !$('proposal-summary').textContent;
|
|
319
401
|
$('proposal-chip').setAttribute('aria-expanded', String(!list.hidden));
|
|
402
|
+
// The list sits after the toolbar's buttons in the page, so focus goes into it when it opens (its first row), and back to the chip when it closes by Escape
|
|
403
|
+
if (!list.hidden) { if (!isPhone()) list.querySelector('button')?.focus(); } else if (refocus) $('proposal-chip').focus();
|
|
320
404
|
}
|
|
321
405
|
|
|
322
|
-
/**
|
|
406
|
+
/**
|
|
407
|
+
* Picks a row of the changes list: select it, centre it in the part of the map the open list, the node panel and (on a phone) the sheets leave free,
|
|
408
|
+
* at a zoom where its label reads, and make sure the current view shows it
|
|
409
|
+
*/
|
|
323
410
|
function focusChange(kind, key) {
|
|
324
411
|
const item = kind === 'edge' ? state.edges.find((e) => edgeKey(e) === key) : state.nodes.find((n) => n.id === key);
|
|
325
412
|
if (!item) return;
|
|
326
413
|
const ends = (kind === 'edge' ? [state.nodes.find((n) => n.id === item.from), state.nodes.find((n) => n.id === item.to)] : [item]).filter(Boolean);
|
|
327
414
|
if (!ends.length) return;
|
|
328
|
-
if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff'); // Before or After hides what it removes or adds
|
|
329
|
-
const at = { x: ends.reduce((s, n) => s + n.x, 0) / ends.length, y: ends.reduce((s, n) => s + n.y, 0) / ends.length };
|
|
330
|
-
state.camera.x = state.width / 2 - at.x * state.camera.zoom;
|
|
331
|
-
state.camera.y = state.height / 2 - at.y * state.camera.zoom;
|
|
415
|
+
if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff', { quiet: true }); // Before or After hides what it removes or adds
|
|
332
416
|
if (kind === 'edge') showEdgePanel(item);
|
|
333
417
|
else selectNode(item);
|
|
418
|
+
// The panel is open now, so what it covers is known
|
|
419
|
+
const cam = frameNodes(ends, visibleMapRect(), { padding: fitPadding(), maxZoom: Math.max(READ_ZOOM, state.camera.zoom), minZoom: getMinZoom() });
|
|
420
|
+
if (cam) Object.assign(state.camera, cam);
|
|
421
|
+
render();
|
|
422
|
+
announce(jumpWords(MARK_WORDS[item.mark] || item.mark, kind === 'edge' ? `${nameOf(item.from)} to ${nameOf(item.to)}` : item.label));
|
|
334
423
|
}
|
|
335
424
|
|
|
336
425
|
// ---------------------------------------------------------------------------
|
|
@@ -532,6 +621,7 @@ const ACTIONS = {
|
|
|
532
621
|
'toggle-proposal-mode': () => toggleMode(),
|
|
533
622
|
'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
|
|
534
623
|
'toggle-proposal-changes': () => toggleChanges(),
|
|
624
|
+
'proposal-way': (el) => (el.dataset.way === 'open' ? openProposal(el.dataset.slug, el.dataset.source || null) : openSpecs()),
|
|
535
625
|
'proposal-focus': (el) => focusChange(el.dataset.kind, el.dataset.key),
|
|
536
626
|
};
|
|
537
627
|
|
|
@@ -543,12 +633,63 @@ function onClick(e) {
|
|
|
543
633
|
if (moreOpen() && !(target && target.dataset.action === 'toggle-proposal-more')) closeMore(!!(target && target.closest('#proposal-more-menu')));
|
|
544
634
|
// Any click outside the picker closes it
|
|
545
635
|
const wrap = $('proposal-wrap');
|
|
546
|
-
if (menuOpen() && wrap && !wrap.contains(e.target)) closeMenu();
|
|
636
|
+
if (menuOpen() && wrap && !wrap.contains(e.target) && !(target && target.dataset.action === 'proposal-way')) closeMenu(); // (a bad link's Specs list opens it from outside)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/** A bad link's way on: the Work panel's Specs tab when there is one, else the header's Proposals menu */
|
|
640
|
+
function openSpecs() {
|
|
641
|
+
if (hooks.openSpecs) { hooks.openSpecs(); return; }
|
|
642
|
+
if (!menuOpen()) toggleMenu();
|
|
547
643
|
}
|
|
548
644
|
|
|
549
645
|
function onKey(e) {
|
|
550
646
|
if (e.key === 'Escape' && menuOpen()) closeMenu();
|
|
551
647
|
onMoreKey(e);
|
|
648
|
+
// Escape inside the list of changes folds it back onto its chip
|
|
649
|
+
const list = $('proposal-changes');
|
|
650
|
+
if (e.key === 'Escape' && !e.defaultPrevented && list && !list.hidden && list.contains(document.activeElement)) { e.preventDefault(); toggleChanges(true); }
|
|
651
|
+
if (e.key === 'Tab' && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey) tabThroughList(e);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/** The lists the toolbar opens, each after the button that opens it: the changes (the counts) and the scenarios (Play) */
|
|
655
|
+
const OPENERS = [['proposal-chip', 'proposal-changes'], ['proposal-play', 'proposal-scenarios']];
|
|
656
|
+
const TABBABLE = 'button, a[href], input, select, textarea, summary, [tabindex]';
|
|
657
|
+
const canTab = (el) => el.tabIndex >= 0 && !el.disabled && !el.closest('[hidden]') && (typeof el.checkVisibility !== 'function' || el.checkVisibility());
|
|
658
|
+
const tabbables = (root) => [...root.querySelectorAll(TABBABLE)].filter(canTab);
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* An open list sits in the page under the whole toolbar, so Tab would reach it only after Approve and ⋯ (WCAG 2.4.3). The bar's Tab order is
|
|
662
|
+
* the page's with each open list moved to right after the button that opened it: Tab goes from the button into the list, from its last row on
|
|
663
|
+
* to the toolbar's next control, and Shift+Tab the same way back. Where that order and the page's agree, the browser moves the focus itself.
|
|
664
|
+
*/
|
|
665
|
+
function tabThroughList(e) {
|
|
666
|
+
const bar = $('proposal-bar');
|
|
667
|
+
if (!bar || bar.hidden) return;
|
|
668
|
+
const open = OPENERS.map(([b, l]) => [$(b), $(l)]).filter(([btn, list]) => btn && list && !list.hidden && bar.contains(list) && canTab(btn));
|
|
669
|
+
if (!open.length) return;
|
|
670
|
+
const all = tabbables(bar);
|
|
671
|
+
let order = all.filter((el) => !open.some(([, list]) => list.contains(el)));
|
|
672
|
+
for (const [btn, list] of open) {
|
|
673
|
+
const at = order.indexOf(btn);
|
|
674
|
+
if (at >= 0) order = [...order.slice(0, at + 1), ...all.filter((el) => list.contains(el)), ...order.slice(at + 1)];
|
|
675
|
+
}
|
|
676
|
+
const active = document.activeElement;
|
|
677
|
+
let to = null;
|
|
678
|
+
if (active && bar.contains(active)) {
|
|
679
|
+
const i = order.indexOf(active);
|
|
680
|
+
if (i < 0) return;
|
|
681
|
+
const next = order[i + (e.shiftKey ? -1 : 1)];
|
|
682
|
+
const natural = all[all.indexOf(active) + (e.shiftKey ? -1 : 1)];
|
|
683
|
+
if (next === natural) return;
|
|
684
|
+
if (next) to = next;
|
|
685
|
+
else if (!e.shiftKey) to = tabbables(document).find((el) => !bar.contains(el) && (bar.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING)) || null; // out of the bar, past the list's rows
|
|
686
|
+
} else if (e.shiftKey && active) {
|
|
687
|
+
// Coming back into the bar from after it: its last control in this order, not the last row of a list
|
|
688
|
+
const page = tabbables(document);
|
|
689
|
+
const prev = page[page.indexOf(active) - 1];
|
|
690
|
+
if (prev && bar.contains(prev) && prev !== order[order.length - 1]) to = order[order.length - 1];
|
|
691
|
+
}
|
|
692
|
+
if (to) { e.preventDefault(); to.focus(); }
|
|
552
693
|
}
|
|
553
694
|
|
|
554
695
|
/** The marks' colours for the legend and the panel (the --hx-mark-* variables), the same the map draws on this ground */
|
|
@@ -580,9 +721,14 @@ export async function initProposals() {
|
|
|
580
721
|
renderBar();
|
|
581
722
|
|
|
582
723
|
const asked = parseProposalQuery(location.search);
|
|
583
|
-
if (!asked)
|
|
724
|
+
if (!asked) {
|
|
725
|
+
// A link whose `proposal` is not a proposal's name: said plainly (the value as text, never markup or a link), with the Specs list
|
|
726
|
+
const bad = malformedLinkWords(location.search);
|
|
727
|
+
if (bad) setMessage(bad, true, [specsWay()]);
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
584
730
|
const ok = await openProposal(asked.slug, asked.source);
|
|
585
|
-
if (ok && asked.view) setProposalView(asked.view);
|
|
731
|
+
if (ok && asked.view) { setProposalView(asked.view, { quiet: true }); announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView)); }
|
|
586
732
|
return ok;
|
|
587
733
|
}
|
|
588
734
|
|
|
@@ -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
|
|
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
|
-
|
|
161
|
-
circle(ctx, node.x, node.y,
|
|
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
|
-
|
|
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
|
package/explorer/review-model.js
CHANGED
|
@@ -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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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
|
/**
|