cornfield 0.34.0 → 0.34.2
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/strings.js +2 -0
- package/explorer/camera.js +144 -5
- package/explorer/explorer.css +52 -3
- package/explorer/forge-panel.js +2 -1
- package/explorer/index.html +4 -0
- package/explorer/input.js +3 -3
- package/explorer/keyboard.js +2 -2
- package/explorer/layers.js +33 -9
- package/explorer/layout.js +113 -22
- package/explorer/main.js +4 -0
- package/explorer/panels.js +21 -2
- package/explorer/proposal-model.js +111 -0
- package/explorer/proposal.js +158 -17
- package/explorer/render.js +33 -5
- package/explorer/renderer-canvas2d.js +110 -18
- package/explorer/review.js +16 -3
- package/explorer/scenario-ui.js +71 -12
- package/explorer/scenario.js +16 -24
- package/explorer/scene.js +2 -2
- package/explorer/search-status.js +41 -0
- package/explorer/sheets.js +26 -0
- package/package.json +1 -1
- package/server/compress.js +135 -0
- package/server/proxy.js +2 -0
- package/server/server.js +2 -0
package/explorer/main.js
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { state, nodeById, touchScene } from './state.js';
|
|
27
|
+
import { updateSearchStatus } from './search-status.js';
|
|
27
28
|
import { render, resize, fitGraphToViewport, fitPadding, isNodeVisible, setRenderer, getRenderer, ensureFlowLoop, renderNow, holdFrames } from './render.js';
|
|
28
29
|
import { createRenderer } from './renderer.js';
|
|
29
30
|
import { clearFreeformPositions, layoutOrbit, loadFreeformPositions } from './layout.js';
|
|
@@ -95,6 +96,9 @@ function handleSearch(value) {
|
|
|
95
96
|
state.camera.x = state.width / 2 - found.x * state.camera.zoom;
|
|
96
97
|
state.camera.y = state.height / 2 - found.y * state.camera.zoom;
|
|
97
98
|
}
|
|
99
|
+
updateSearchStatus(state.searchQuery, !!found);
|
|
100
|
+
} else {
|
|
101
|
+
updateSearchStatus('', false);
|
|
98
102
|
}
|
|
99
103
|
render();
|
|
100
104
|
}
|
package/explorer/panels.js
CHANGED
|
@@ -12,7 +12,8 @@ import { flowSummary } from './flows.js';
|
|
|
12
12
|
import { clearScenario } from './scenario-ui.js';
|
|
13
13
|
import { kindOfMark, fieldRows, MARK_WORDS } from './proposal-model.js';
|
|
14
14
|
import { nodeMockupsHtml } from './mockups-model.js';
|
|
15
|
-
import { collapseSheet } from './sheets.js';
|
|
15
|
+
import { collapseSheet, isPhone, measureCovered, onCoveredChange } from './sheets.js';
|
|
16
|
+
import { panIntoView } from './camera.js';
|
|
16
17
|
import { liveSection, hydrateLivePhotos } from './live.js';
|
|
17
18
|
import { cloudPanelHtml } from './cloud-model.js';
|
|
18
19
|
import { t } from './strings.js';
|
|
@@ -94,7 +95,9 @@ function dataSummary(node) {
|
|
|
94
95
|
}
|
|
95
96
|
if (node.type === 'service') {
|
|
96
97
|
const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'imports' ? ` · ${escHtml(e.label)}` : ''}`;
|
|
97
|
-
|
|
98
|
+
// The summary is the first sentence of the description above: shown again only when the description does not hold it
|
|
99
|
+
const again = node.summary && !String(node.desc || '').includes(node.summary);
|
|
100
|
+
return section('Kind:', [line(`${code(node.kind)}${again ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
|
|
98
101
|
+ section('Started by:', [...(node.triggers || []).map((t) => line(escHtml(t))), ...edgesOf('triggers', 'to', node.id).map((e) => line(row(e, 'from')))])
|
|
99
102
|
+ section('Jobs:', (node.jobs || []).map((j) => line(`${code(j.name)} · cron ${code(j.cron)}`)))
|
|
100
103
|
+ section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(row(e, 'to'))))
|
|
@@ -272,8 +275,24 @@ export async function selectNode(node) {
|
|
|
272
275
|
$('spec-drawer').classList.add('drawer-open');
|
|
273
276
|
$('spec-drawer').inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
|
|
274
277
|
$('drawer-backdrop').hidden = false;
|
|
278
|
+
keepSelectedInView();
|
|
275
279
|
}
|
|
276
280
|
|
|
281
|
+
/**
|
|
282
|
+
* On a phone the node's sheet covers the bottom of the map (sheets.js): when the selected node is under it, or
|
|
283
|
+
* gets covered as the sheet expands, pan the map (never zoom it) so the node is in the part still showing (F32)
|
|
284
|
+
*/
|
|
285
|
+
export function keepSelectedInView() {
|
|
286
|
+
const node = state.selectedNode;
|
|
287
|
+
if (!node || !state.width || !isPhone()) return;
|
|
288
|
+
const covered = measureCovered();
|
|
289
|
+
const next = panIntoView(state.camera, node, { left: 0, top: 0, right: state.width, bottom: state.height - covered }, node.r * state.camera.zoom + 16);
|
|
290
|
+
if (!next) return;
|
|
291
|
+
Object.assign(state.camera, next);
|
|
292
|
+
render();
|
|
293
|
+
}
|
|
294
|
+
onCoveredChange(() => keepSelectedInView());
|
|
295
|
+
|
|
277
296
|
/** Start a run: the Start dialog of the Work panel, on the proposal that is open */
|
|
278
297
|
export function startRun() {
|
|
279
298
|
if (state.proposalSlug) openProposalStart(state.proposalSlug, '#drawer-run-btn');
|
|
@@ -234,6 +234,117 @@ export function specRowHtml(entry, { current = null } = {}) {
|
|
|
234
234
|
+ `${entry.summary ? `<span class="hx-forge-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-forge-meta hx-forge-facts">${meta}</span></button></li>`;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
// Which copy is open: the chip on the bar, and a link that finds nothing
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 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",
|
|
245
|
+
* "all 3 checks passed". Failed first, then cancelled, then the ones still going.
|
|
246
|
+
* @param {{ state: string }[]} checks
|
|
247
|
+
*/
|
|
248
|
+
export function checksLine(checks) {
|
|
249
|
+
if (!Array.isArray(checks) || checks.length === 0) return 'no checks';
|
|
250
|
+
const n = (states) => checks.filter((c) => states.includes(c.state)).length;
|
|
251
|
+
const failed = n(['failure']);
|
|
252
|
+
const cancelled = n(['cancelled']);
|
|
253
|
+
const waiting = n(['running', 'queued']);
|
|
254
|
+
const parts = [];
|
|
255
|
+
if (failed) parts.push(`${plural(failed, 'check')} failed`);
|
|
256
|
+
if (cancelled) parts.push(`${plural(cancelled, 'check')} cancelled`);
|
|
257
|
+
if (waiting) parts.push(`${plural(waiting, 'check')} running`);
|
|
258
|
+
if (parts.length) return parts.join(', ');
|
|
259
|
+
return checks.length === 1 ? '1 check passed' : `all ${checks.length} checks passed`;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** `pull/<n>` to n, or null (the same shape the server reads, server/proposal-pulls.js) */
|
|
263
|
+
export function pullNumberOf(source) {
|
|
264
|
+
const m = typeof source === 'string' ? /^pull\/([1-9]\d{0,8})$/.exec(source) : null;
|
|
265
|
+
return m ? Number(m[1]) : null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Where a source is, in words: "PR #21", "the checkout", "worktree <name>" */
|
|
269
|
+
export function sourceWhere(source) {
|
|
270
|
+
const n = pullNumberOf(source);
|
|
271
|
+
if (n) return `PR #${n}`;
|
|
272
|
+
if (!source || source === 'checkout') return 'the checkout';
|
|
273
|
+
return `worktree ${source}`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* 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
|
|
278
|
+
* 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
|
|
279
|
+
* 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
|
|
280
|
+
* 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
|
|
281
|
+
* branch with no pull request yet is `draft`); '' while the PR is not known yet.
|
|
282
|
+
* @param {string|null} source `pull/<n>`, `checkout` or a worktree's name
|
|
283
|
+
* @param {{ draft?: boolean, url?: string, state?: string }|null} [pull]
|
|
284
|
+
* @param {{ state: string }[]|null} [checks]
|
|
285
|
+
* @returns {{ text: string, href: string|null, state: ''|'open'|'draft'|'merged'|'closed', label: string }}
|
|
286
|
+
*/
|
|
287
|
+
export function sourceChip(source, pull = null, checks = null) {
|
|
288
|
+
const n = pullNumberOf(source);
|
|
289
|
+
if (!n) {
|
|
290
|
+
const where = !source || source === 'checkout' ? 'in the checkout' : `in worktree ${source}`;
|
|
291
|
+
return { text: `Local draft \u00b7 ${where}`, href: null, state: 'draft', label: `This is a local draft, ${where}, not a pull request` };
|
|
292
|
+
}
|
|
293
|
+
const parts = [`PR #${n}`];
|
|
294
|
+
const state = !pull ? '' : pull.state === 'merged' || pull.state === 'closed' ? pull.state : typeof pull.draft === 'boolean' ? (pull.draft ? 'draft' : 'open') : '';
|
|
295
|
+
if (state) parts.push(state);
|
|
296
|
+
if (Array.isArray(checks)) parts.push(checksLine(checks));
|
|
297
|
+
return {
|
|
298
|
+
text: parts.join(' \u00b7 '),
|
|
299
|
+
href: pull && typeof pull.url === 'string' ? pull.url : null,
|
|
300
|
+
state,
|
|
301
|
+
label: `Reviewing spec pull request: ${parts.join(', ')}`,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 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
|
|
307
|
+
* one: a PR number, the checkout, or a worktree the listing has (`sources`); anything else the link says is not repeated back.
|
|
308
|
+
* @param {string} slug (it passed the slug pattern)
|
|
309
|
+
* @param {string|null} source
|
|
310
|
+
* @param {Set<string>|null} [sources] the sources the listing knows, when it has been read
|
|
311
|
+
*/
|
|
312
|
+
export function notFoundWords(slug, source, sources = null) {
|
|
313
|
+
if (!source) return `There is no proposal called ${slug}.`;
|
|
314
|
+
if (pullNumberOf(source) || source === 'checkout' || (sources && sources.has(source) && SLUG.test(source))) return `There is no proposal called ${slug} in ${sourceWhere(source)}.`;
|
|
315
|
+
return `There is no proposal called ${slug}. This link's source is not a PR, the checkout or a worktree.`;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 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.
|
|
320
|
+
* The value is shown as text, cut to 60 characters; the caller sets it with `textContent`.
|
|
321
|
+
* @param {string} search `location.search`
|
|
322
|
+
* @returns {string|null}
|
|
323
|
+
*/
|
|
324
|
+
export function malformedLinkWords(search) {
|
|
325
|
+
const params = new URLSearchParams(search || '');
|
|
326
|
+
if (!params.has('proposal')) return null;
|
|
327
|
+
const raw = params.get('proposal') || '';
|
|
328
|
+
if (SLUG.test(raw)) return null;
|
|
329
|
+
const shown = raw.length > 60 ? `${raw.slice(0, 59)}\u2026` : raw;
|
|
330
|
+
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.';
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* 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),
|
|
335
|
+
* each as `{ slug, source, label }`. The Specs list is offered by the caller, always.
|
|
336
|
+
* @param {{ slug: string, source: string, error?: string, pull?: object }[]|null} listing
|
|
337
|
+
* @param {string} slug
|
|
338
|
+
* @param {string|null} source the one that was asked for (left out)
|
|
339
|
+
*/
|
|
340
|
+
export function otherCopies(listing, slug, source) {
|
|
341
|
+
if (!Array.isArray(listing)) return [];
|
|
342
|
+
return listing
|
|
343
|
+
.filter((e) => e && e.slug === slug && e.source !== source && !e.error)
|
|
344
|
+
.sort((a, b) => (pullNumberOf(b.source) ? 1 : 0) - (pullNumberOf(a.source) ? 1 : 0))
|
|
345
|
+
.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}`}` }));
|
|
346
|
+
}
|
|
347
|
+
|
|
237
348
|
// ---------------------------------------------------------------------------
|
|
238
349
|
// Where an added node sits
|
|
239
350
|
// ---------------------------------------------------------------------------
|
package/explorer/proposal.js
CHANGED
|
@@ -19,7 +19,8 @@
|
|
|
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';
|
|
@@ -27,10 +28,11 @@ import { onThemeChange } from './theme.js';
|
|
|
27
28
|
import { looksWith, onMapStyleChange } from './map-style.js';
|
|
28
29
|
import {
|
|
29
30
|
PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds,
|
|
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';
|
|
34
36
|
import { t } from './strings.js';
|
|
35
37
|
|
|
36
38
|
const $ = (id) => document.getElementById(id);
|
|
@@ -42,8 +44,9 @@ const $ = (id) => document.getElementById(id);
|
|
|
42
44
|
* - `beforeClose()` returns false to keep the proposal open (it is asking whether to keep the edits)
|
|
43
45
|
* - `closed()` the proposal was closed
|
|
44
46
|
* - `bar(open)` the bar was drawn: redraw the editing controls
|
|
47
|
+
* - `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
48
|
*/
|
|
46
|
-
export const hooks = { effective: null, mark: null, beforeClose: null, closed: null, bar: null };
|
|
49
|
+
export const hooks = { effective: null, mark: null, beforeClose: null, closed: null, bar: null, openSpecs: null };
|
|
47
50
|
|
|
48
51
|
/** Whether the open proposal's source goes in the address (see `showProposal`) */
|
|
49
52
|
let pinnedSource = false;
|
|
@@ -97,24 +100,38 @@ export async function loadProposalList() {
|
|
|
97
100
|
* @returns {Promise<boolean>} whether it opened
|
|
98
101
|
*/
|
|
99
102
|
export async function openProposal(slug, source = null) {
|
|
103
|
+
const token = ++openToken;
|
|
100
104
|
setMessage(`Opening ${slug} …`);
|
|
101
105
|
try {
|
|
102
106
|
const res = await fetch(`/proposals/${encodeURIComponent(slug)}.json${source ? `?source=${encodeURIComponent(source)}` : ''}`, { cache: 'no-store' });
|
|
103
107
|
if (!res.ok) {
|
|
104
108
|
let why = '';
|
|
105
109
|
try { why = (await res.json()).error || ''; } catch { /* no body */ }
|
|
106
|
-
|
|
110
|
+
const err = new Error(res.status === 404 ? notFoundWords(slug, source) : why || `The server answered ${res.status}.`);
|
|
111
|
+
err.notFound = res.status === 404;
|
|
112
|
+
throw err;
|
|
107
113
|
}
|
|
108
114
|
const found = res.headers.get('X-Proposal-Source');
|
|
109
115
|
showProposal(await res.json(), { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true });
|
|
110
116
|
return true;
|
|
111
117
|
} catch (err) {
|
|
112
118
|
console.error('Opening the proposal failed', err);
|
|
113
|
-
|
|
119
|
+
// 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()] : []);
|
|
121
|
+
if (err.notFound && token === openToken) {
|
|
122
|
+
await loadProposalList();
|
|
123
|
+
const sources = new Set((Array.isArray(listing) ? listing : []).map((e) => e && e.source));
|
|
124
|
+
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()]);
|
|
125
|
+
}
|
|
114
126
|
return false;
|
|
115
127
|
}
|
|
116
128
|
}
|
|
117
129
|
|
|
130
|
+
/** The way on every bad link offers: the list of specs */
|
|
131
|
+
const specsWay = () => ({ label: t('openSpecsList'), way: 'specs' });
|
|
132
|
+
/** Which `openProposal` is the latest, so a slow answer never writes over a newer one */
|
|
133
|
+
let openToken = 0;
|
|
134
|
+
|
|
118
135
|
/**
|
|
119
136
|
* Puts a parsed proposal on the map. The map's nodes and edges become `applyProposal(base, proposal)`.
|
|
120
137
|
* @param {object} proposal
|
|
@@ -155,10 +172,10 @@ export function rebuildProposalMap(effective = hooks.effective ? hooks.effective
|
|
|
155
172
|
applied = { nodes: state.baseNodes.map((n) => ({ ...n, mark: 'none' })), edges: state.baseEdges.map((e) => ({ ...e, mark: 'none' })) };
|
|
156
173
|
}
|
|
157
174
|
swapMap(applied.nodes, applied.edges);
|
|
175
|
+
renderBar(); // first: the fit below leaves out what the bar covers, so the bar must be laid out
|
|
158
176
|
if (fit) fitToChange();
|
|
159
177
|
render();
|
|
160
178
|
ensureFlowLoop();
|
|
161
|
-
renderBar();
|
|
162
179
|
}
|
|
163
180
|
|
|
164
181
|
/** Closes the proposal: the plain map comes back, as it was, and the address loses `?proposal=` */
|
|
@@ -203,9 +220,23 @@ function swapMap(nodes, edges) {
|
|
|
203
220
|
touchScene();
|
|
204
221
|
}
|
|
205
222
|
|
|
223
|
+
/**
|
|
224
|
+
* 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
|
|
225
|
+
* 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
|
|
226
|
+
* 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,
|
|
227
|
+
* 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.
|
|
228
|
+
*/
|
|
206
229
|
function fitToChange() {
|
|
207
|
-
const {
|
|
208
|
-
|
|
230
|
+
const { touched } = touchedIds(state.nodes, viewEdges());
|
|
231
|
+
const items = state.nodes.filter((n) => touched.has(n.id) && isNodeVisible(n));
|
|
232
|
+
const rect = visibleMapRect();
|
|
233
|
+
const opts = { padding: fitPadding(), maxZoom: 1, minZoom: getMinZoom() };
|
|
234
|
+
// The whole change when it fits at FRAME_ZOOM_MIN or closer; else the biggest part of it that does (camera.js)
|
|
235
|
+
const group = largestGroup(items, rect, { ...opts, minZoom: Math.max(opts.minZoom, FRAME_ZOOM_MIN) });
|
|
236
|
+
const cam = items.length ? frameNodes(group, rect, opts) : null;
|
|
237
|
+
if (!cam) { fitGraphToViewport(fitPadding()); return; }
|
|
238
|
+
Object.assign(state.camera, cam);
|
|
239
|
+
render();
|
|
209
240
|
}
|
|
210
241
|
|
|
211
242
|
/** `?proposal=` (and `source`, `proposalView`) follow the open proposal, without a new history entry; other parameters stay */
|
|
@@ -228,8 +259,8 @@ function syncAddress() {
|
|
|
228
259
|
// The bar: title, counts chip, Before / Diff / After, problems, Close
|
|
229
260
|
// ---------------------------------------------------------------------------
|
|
230
261
|
|
|
231
|
-
/** One line in the bar instead of a proposal: while one opens, or why it did not */
|
|
232
|
-
function setMessage(text, isError = false) {
|
|
262
|
+
/** 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) */
|
|
263
|
+
function setMessage(text, isError = false, ways = []) {
|
|
233
264
|
const bar = $('proposal-bar');
|
|
234
265
|
if (!bar) return;
|
|
235
266
|
bar.hidden = false;
|
|
@@ -238,6 +269,52 @@ function setMessage(text, isError = false) {
|
|
|
238
269
|
const msg = $('proposal-message');
|
|
239
270
|
msg.hidden = false;
|
|
240
271
|
msg.textContent = text;
|
|
272
|
+
const box = $('proposal-ways');
|
|
273
|
+
if (!box) return;
|
|
274
|
+
box.hidden = ways.length === 0;
|
|
275
|
+
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('');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ---------------------------------------------------------------------------
|
|
279
|
+
// Which copy is open: the chip after the title
|
|
280
|
+
// ---------------------------------------------------------------------------
|
|
281
|
+
|
|
282
|
+
/** 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 */
|
|
283
|
+
const pullInfo = new Map();
|
|
284
|
+
/** The proposal the PR was last asked for (`source/slug`): asked again when another opens, not each time the bar is drawn */
|
|
285
|
+
let pullAskedFor = null;
|
|
286
|
+
|
|
287
|
+
const safeHref = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
|
|
288
|
+
|
|
289
|
+
/** 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. */
|
|
290
|
+
function paintSource() {
|
|
291
|
+
const chip = $('proposal-source');
|
|
292
|
+
if (!chip) return;
|
|
293
|
+
const source = state.proposal ? state.proposalSource : null;
|
|
294
|
+
chip.hidden = !source;
|
|
295
|
+
if (!source) return;
|
|
296
|
+
const n = pullNumberOf(source);
|
|
297
|
+
const known = n ? pullInfo.get(n) : null;
|
|
298
|
+
const entry = n && Array.isArray(listing) ? listing.find((e) => e.slug === state.proposalSlug && e.source === source) : null;
|
|
299
|
+
const words = sourceChip(source, (known && known.pull) || (entry && entry.pull) || null, known ? known.checks : null);
|
|
300
|
+
chip.textContent = words.text;
|
|
301
|
+
if (words.state) chip.dataset.cornState = words.state; else delete chip.dataset.cornState;
|
|
302
|
+
const href = safeHref(words.href);
|
|
303
|
+
if (href) { chip.setAttribute('href', href); chip.setAttribute('target', '_blank'); chip.setAttribute('rel', 'noreferrer'); chip.title = 'Open this pull request'; } else {
|
|
304
|
+
chip.removeAttribute('href'); chip.removeAttribute('target'); chip.removeAttribute('rel'); chip.title = words.label;
|
|
305
|
+
}
|
|
306
|
+
const key = `${source}/${state.proposalSlug}`;
|
|
307
|
+
if (n && pullAskedFor !== key) { pullAskedFor = key; loadPullInfo(n); }
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** 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 */
|
|
311
|
+
async function loadPullInfo(n) {
|
|
312
|
+
try {
|
|
313
|
+
const res = await fetch(`/api/forge/pulls/${n}`);
|
|
314
|
+
const body = res.ok ? await res.json() : null;
|
|
315
|
+
if (body && body.ok !== false && body.pull) pullInfo.set(n, { pull: body.pull, checks: Array.isArray(body.checks) ? body.checks : null });
|
|
316
|
+
} catch { /* no forge, or not signed in: the chip keeps what it has */ }
|
|
317
|
+
if (state.proposal && pullNumberOf(state.proposalSource) === n) paintSource();
|
|
241
318
|
}
|
|
242
319
|
|
|
243
320
|
/** The problems a proposal has, as the bar lists them (at most `max`, then "and N more") */
|
|
@@ -264,6 +341,7 @@ export function renderBar() {
|
|
|
264
341
|
$('proposal-body').hidden = false;
|
|
265
342
|
const p = state.proposal;
|
|
266
343
|
$('proposal-title').textContent = (p && typeof p.title === 'string' && p.title) || state.proposalSlug || 'Proposal';
|
|
344
|
+
paintSource();
|
|
267
345
|
const summary = $('proposal-summary');
|
|
268
346
|
summary.textContent = (p && typeof p.summary === 'string' && p.summary) || '';
|
|
269
347
|
const title = $('proposal-title');
|
|
@@ -311,26 +389,32 @@ function renderChanges() {
|
|
|
311
389
|
list.innerHTML = rows.join('') || '<p class="hx-faint">This proposal changes nothing on the map.</p>';
|
|
312
390
|
}
|
|
313
391
|
|
|
314
|
-
function toggleChanges() {
|
|
392
|
+
function toggleChanges(refocus = false) {
|
|
315
393
|
const list = $('proposal-changes');
|
|
316
394
|
if (!list) return;
|
|
317
395
|
list.hidden = !list.hidden;
|
|
318
396
|
$('proposal-summary').hidden = list.hidden || !$('proposal-summary').textContent;
|
|
319
397
|
$('proposal-chip').setAttribute('aria-expanded', String(!list.hidden));
|
|
398
|
+
// 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
|
|
399
|
+
if (!list.hidden) { if (!isPhone()) list.querySelector('button')?.focus(); } else if (refocus) $('proposal-chip').focus();
|
|
320
400
|
}
|
|
321
401
|
|
|
322
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* 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,
|
|
404
|
+
* at a zoom where its label reads, and make sure the current view shows it
|
|
405
|
+
*/
|
|
323
406
|
function focusChange(kind, key) {
|
|
324
407
|
const item = kind === 'edge' ? state.edges.find((e) => edgeKey(e) === key) : state.nodes.find((n) => n.id === key);
|
|
325
408
|
if (!item) return;
|
|
326
409
|
const ends = (kind === 'edge' ? [state.nodes.find((n) => n.id === item.from), state.nodes.find((n) => n.id === item.to)] : [item]).filter(Boolean);
|
|
327
410
|
if (!ends.length) return;
|
|
328
411
|
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;
|
|
332
412
|
if (kind === 'edge') showEdgePanel(item);
|
|
333
413
|
else selectNode(item);
|
|
414
|
+
// The panel is open now, so what it covers is known
|
|
415
|
+
const cam = frameNodes(ends, visibleMapRect(), { padding: fitPadding(), maxZoom: Math.max(READ_ZOOM, state.camera.zoom), minZoom: getMinZoom() });
|
|
416
|
+
if (cam) Object.assign(state.camera, cam);
|
|
417
|
+
render();
|
|
334
418
|
}
|
|
335
419
|
|
|
336
420
|
// ---------------------------------------------------------------------------
|
|
@@ -532,6 +616,7 @@ const ACTIONS = {
|
|
|
532
616
|
'toggle-proposal-mode': () => toggleMode(),
|
|
533
617
|
'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
|
|
534
618
|
'toggle-proposal-changes': () => toggleChanges(),
|
|
619
|
+
'proposal-way': (el) => (el.dataset.way === 'open' ? openProposal(el.dataset.slug, el.dataset.source || null) : openSpecs()),
|
|
535
620
|
'proposal-focus': (el) => focusChange(el.dataset.kind, el.dataset.key),
|
|
536
621
|
};
|
|
537
622
|
|
|
@@ -543,12 +628,63 @@ function onClick(e) {
|
|
|
543
628
|
if (moreOpen() && !(target && target.dataset.action === 'toggle-proposal-more')) closeMore(!!(target && target.closest('#proposal-more-menu')));
|
|
544
629
|
// Any click outside the picker closes it
|
|
545
630
|
const wrap = $('proposal-wrap');
|
|
546
|
-
if (menuOpen() && wrap && !wrap.contains(e.target)) closeMenu();
|
|
631
|
+
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
|
+
}
|
|
633
|
+
|
|
634
|
+
/** A bad link's way on: the Work panel's Specs tab when there is one, else the header's Proposals menu */
|
|
635
|
+
function openSpecs() {
|
|
636
|
+
if (hooks.openSpecs) { hooks.openSpecs(); return; }
|
|
637
|
+
if (!menuOpen()) toggleMenu();
|
|
547
638
|
}
|
|
548
639
|
|
|
549
640
|
function onKey(e) {
|
|
550
641
|
if (e.key === 'Escape' && menuOpen()) closeMenu();
|
|
551
642
|
onMoreKey(e);
|
|
643
|
+
// Escape inside the list of changes folds it back onto its chip
|
|
644
|
+
const list = $('proposal-changes');
|
|
645
|
+
if (e.key === 'Escape' && !e.defaultPrevented && list && !list.hidden && list.contains(document.activeElement)) { e.preventDefault(); toggleChanges(true); }
|
|
646
|
+
if (e.key === 'Tab' && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey) tabThroughList(e);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** The lists the toolbar opens, each after the button that opens it: the changes (the counts) and the scenarios (Play) */
|
|
650
|
+
const OPENERS = [['proposal-chip', 'proposal-changes'], ['proposal-play', 'proposal-scenarios']];
|
|
651
|
+
const TABBABLE = 'button, a[href], input, select, textarea, summary, [tabindex]';
|
|
652
|
+
const canTab = (el) => el.tabIndex >= 0 && !el.disabled && !el.closest('[hidden]') && (typeof el.checkVisibility !== 'function' || el.checkVisibility());
|
|
653
|
+
const tabbables = (root) => [...root.querySelectorAll(TABBABLE)].filter(canTab);
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* 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
|
|
657
|
+
* 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
|
|
658
|
+
* 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.
|
|
659
|
+
*/
|
|
660
|
+
function tabThroughList(e) {
|
|
661
|
+
const bar = $('proposal-bar');
|
|
662
|
+
if (!bar || bar.hidden) return;
|
|
663
|
+
const open = OPENERS.map(([b, l]) => [$(b), $(l)]).filter(([btn, list]) => btn && list && !list.hidden && bar.contains(list) && canTab(btn));
|
|
664
|
+
if (!open.length) return;
|
|
665
|
+
const all = tabbables(bar);
|
|
666
|
+
let order = all.filter((el) => !open.some(([, list]) => list.contains(el)));
|
|
667
|
+
for (const [btn, list] of open) {
|
|
668
|
+
const at = order.indexOf(btn);
|
|
669
|
+
if (at >= 0) order = [...order.slice(0, at + 1), ...all.filter((el) => list.contains(el)), ...order.slice(at + 1)];
|
|
670
|
+
}
|
|
671
|
+
const active = document.activeElement;
|
|
672
|
+
let to = null;
|
|
673
|
+
if (active && bar.contains(active)) {
|
|
674
|
+
const i = order.indexOf(active);
|
|
675
|
+
if (i < 0) return;
|
|
676
|
+
const next = order[i + (e.shiftKey ? -1 : 1)];
|
|
677
|
+
const natural = all[all.indexOf(active) + (e.shiftKey ? -1 : 1)];
|
|
678
|
+
if (next === natural) return;
|
|
679
|
+
if (next) to = next;
|
|
680
|
+
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
|
|
681
|
+
} else if (e.shiftKey && active) {
|
|
682
|
+
// Coming back into the bar from after it: its last control in this order, not the last row of a list
|
|
683
|
+
const page = tabbables(document);
|
|
684
|
+
const prev = page[page.indexOf(active) - 1];
|
|
685
|
+
if (prev && bar.contains(prev) && prev !== order[order.length - 1]) to = order[order.length - 1];
|
|
686
|
+
}
|
|
687
|
+
if (to) { e.preventDefault(); to.focus(); }
|
|
552
688
|
}
|
|
553
689
|
|
|
554
690
|
/** The marks' colours for the legend and the panel (the --hx-mark-* variables), the same the map draws on this ground */
|
|
@@ -580,7 +716,12 @@ export async function initProposals() {
|
|
|
580
716
|
renderBar();
|
|
581
717
|
|
|
582
718
|
const asked = parseProposalQuery(location.search);
|
|
583
|
-
if (!asked)
|
|
719
|
+
if (!asked) {
|
|
720
|
+
// 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
|
|
721
|
+
const bad = malformedLinkWords(location.search);
|
|
722
|
+
if (bad) setMessage(bad, true, [specsWay()]);
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
584
725
|
const ok = await openProposal(asked.slug, asked.source);
|
|
585
726
|
if (ok && asked.view) setProposalView(asked.view);
|
|
586
727
|
return ok;
|
package/explorer/render.js
CHANGED
|
@@ -15,6 +15,7 @@ import { createSpatialCache } from './spatial.js';
|
|
|
15
15
|
import { createFrameScheduler, packetsOnScreen } from './frame.js';
|
|
16
16
|
import { createLabelLayer } from './labels.js';
|
|
17
17
|
import { measureCovered } from './sheets.js';
|
|
18
|
+
import { ZOOM_MIN, ZOOM_FLOOR } from './camera.js';
|
|
18
19
|
|
|
19
20
|
// ---------------------------------------------------------------------------
|
|
20
21
|
// Visibility and focus (decided in scene.js, kept here under their old names)
|
|
@@ -93,15 +94,15 @@ export function resize() {
|
|
|
93
94
|
render();
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
const { nodes, width, height
|
|
97
|
+
/** The box the fit shows (world px) and the zoom that makes it fill the screen, before any limit; null with nothing to show */
|
|
98
|
+
function fitTarget(padding, only = null) {
|
|
99
|
+
const { nodes, width, height } = state;
|
|
99
100
|
let visible = nodes.filter(isNodeVisible);
|
|
100
101
|
if (only) {
|
|
101
102
|
const part = visible.filter((n) => only.has(n.id));
|
|
102
103
|
if (part.length) visible = part;
|
|
103
104
|
}
|
|
104
|
-
if (visible.length === 0) return;
|
|
105
|
+
if (visible.length === 0) return null;
|
|
105
106
|
// The phone's sheets hide the bottom of the map (sheets.js): fit into the part they leave
|
|
106
107
|
const mapHeight = Math.max(160, height - measureCovered());
|
|
107
108
|
|
|
@@ -118,7 +119,34 @@ export function fitGraphToViewport(padding = 40, only = null) {
|
|
|
118
119
|
|
|
119
120
|
const availWidth = Math.max(160, width - padding * 2);
|
|
120
121
|
const availHeight = Math.max(160, mapHeight - padding * 2);
|
|
121
|
-
const
|
|
122
|
+
const raw = Math.min(availWidth / (maxX - minX), availHeight / (maxY - minY));
|
|
123
|
+
return { minX, maxX, minY, maxY, mapHeight, raw };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let minZoomKey = '';
|
|
127
|
+
let minZoomValue = ZOOM_MIN;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The lowest zoom for this map on this screen: low enough that Fit shows all of it (at most the default floor, so a small
|
|
131
|
+
* map keeps its limit). Hand zoom (wheel, pinch, keys) and Fit share it.
|
|
132
|
+
*/
|
|
133
|
+
export function getMinZoom() {
|
|
134
|
+
const key = `${state.sceneVersion}|${state.width}|${state.height}|${state.view}|${measureCovered()}`;
|
|
135
|
+
if (key !== minZoomKey) {
|
|
136
|
+
minZoomKey = key;
|
|
137
|
+
const t = fitTarget(fitPadding());
|
|
138
|
+
minZoomValue = t && t.raw > 0 && Number.isFinite(t.raw) ? Math.max(ZOOM_FLOOR, Math.min(ZOOM_MIN, t.raw)) : ZOOM_MIN;
|
|
139
|
+
}
|
|
140
|
+
return minZoomValue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Zoom and pan so every visible node (and its label) is on screen; `only` (a Set of ids) narrows it to those, when any are visible */
|
|
144
|
+
export function fitGraphToViewport(padding = 40, only = null) {
|
|
145
|
+
const { width, camera } = state;
|
|
146
|
+
const t = fitTarget(padding, only);
|
|
147
|
+
if (!t) return;
|
|
148
|
+
const { minX, maxX, minY, maxY, mapHeight } = t;
|
|
149
|
+
const targetZoom = Math.min(1.0, Math.max(ZOOM_FLOOR, t.raw));
|
|
122
150
|
|
|
123
151
|
camera.zoom = targetZoom;
|
|
124
152
|
camera.x = width / 2 - ((minX + maxX) / 2) * targetZoom;
|