cornfield 0.48.0 → 0.50.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.
- package/core/strings.js +14 -0
- package/explorer/check.js +7 -227
- package/explorer/connection.js +3 -3
- package/explorer/css/review.css +49 -0
- package/explorer/decision-model.js +6 -0
- package/explorer/engine/checks.js +252 -0
- package/explorer/engine/connection.js +36 -0
- package/explorer/engine/layers.js +1 -0
- package/explorer/engine/layout.js +8 -3
- package/explorer/engine/player.js +489 -0
- package/explorer/engine/proposal.js +373 -0
- package/explorer/engine/render.js +1 -0
- package/explorer/engine/sheets.js +40 -7
- package/explorer/engine/source.js +315 -0
- package/explorer/engine/theme-sheet.js +444 -0
- package/explorer/engine/topology.js +126 -0
- package/explorer/index.html +6 -59
- package/explorer/instance.js +87 -7
- package/explorer/page-address.js +59 -0
- package/explorer/page-pieces.js +33 -5
- package/explorer/page.js +20 -20
- package/explorer/panels.js +1 -3
- package/explorer/pieces/changes.js +495 -0
- package/explorer/pieces/decision.js +664 -0
- package/explorer/pieces/layers.js +4 -0
- package/explorer/pieces/map.js +117 -25
- package/explorer/pieces/node-panel.js +34 -1
- package/explorer/pieces/proposal.js +488 -0
- package/explorer/pieces/review.js +280 -0
- package/explorer/pieces/scope-link.js +50 -0
- package/explorer/pieces/scope.js +247 -0
- package/explorer/pieces/status.css +24 -0
- package/explorer/pieces/status.js +144 -0
- package/explorer/plugins.js +0 -10
- package/explorer/proposal.js +64 -697
- package/explorer/review-column.js +24 -439
- package/explorer/review.js +27 -673
- package/explorer/scenario-ui.js +32 -478
- package/explorer/sheets.js +8 -7
- package/explorer/view.js +12 -64
- package/explorer/waiting-line.js +7 -50
- package/package.json +1 -1
package/explorer/proposal.js
CHANGED
|
@@ -1,714 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/proposal
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
7
|
-
* to the plain map, plus the legend rows and picking a marked edge. What the three views show is
|
|
8
|
-
* decided by scene.js (buildScene); where an added node sits by view.js; the pure parts (the chip's
|
|
9
|
-
* words, the address, the panel rows) are in proposal-model.js and tested without a page.
|
|
4
|
+
* A bridge (spec 0011 D2 and D3, step 5): opening a proposal is the instance's (engine/proposal.js) and the proposal's bar is a piece
|
|
5
|
+
* (pieces/proposal.js). This file keeps the old names for the modules that are not yet on an instance (whatif.js, forge-panel.js, mockups.js, tests),
|
|
6
|
+
* bound to the page's instance and to the pieces the page mounts. It goes when the last of those callers is converted.
|
|
10
7
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* state.nodes / state.edges the base (copied) or `applyProposal(base, proposal)`
|
|
14
|
-
* state.proposalView 'before' | 'diff' | 'after'
|
|
8
|
+
* The `hooks` object is the old chain a module assigned to, each overwriting or wrapping the last. It is kept as accessors that register the function
|
|
9
|
+
* as a listener of the instance (one registration per hook: assigning again takes the last one back), so a chain that wraps `hooks.bar` still works:
|
|
15
10
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
11
|
+
* hooks.effective -> ask proposal:effective hooks.mark -> event proposal:mark hooks.beforeClose -> ask proposal:before-close
|
|
12
|
+
* hooks.closed -> event proposal {closed} hooks.bar -> event proposal:bar hooks.openSpecs -> ask work:open-specs
|
|
13
|
+
* hooks.reviewed -> event decision
|
|
19
14
|
*/
|
|
20
15
|
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
import { t } from './strings.js';
|
|
41
|
-
import { markStateAttr } from './corn-state.js';
|
|
42
|
-
import { isOffline } from './connection.js';
|
|
43
|
-
|
|
44
|
-
const $ = (id) => document.getElementById(id);
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* What-if editing (whatif.js, TOPO-11) plugs into the overlay here, so this file never imports it:
|
|
48
|
-
* - `effective(proposal)` the proposal the map is drawn from: `proposal` with the maintainer's edits in (called when one opens, and on a plain rebuild)
|
|
49
|
-
* - `mark(applied, effective, proposal)` puts the `edit` mark on what the edits added or removed, before the map is laid out
|
|
50
|
-
* - `beforeClose()` returns false to keep the proposal open (it is asking whether to keep the edits)
|
|
51
|
-
* - `closed()` the proposal was closed
|
|
52
|
-
* - `bar(open)` the bar was drawn: redraw the editing controls
|
|
53
|
-
* - `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)
|
|
54
|
-
* - `reviewed()` a review was posted (Approve or Send back): what waits on the maintainer is read again (forge-panel.js sets it)
|
|
55
|
-
*/
|
|
56
|
-
export const hooks = { effective: null, mark: null, beforeClose: null, closed: null, bar: null, openSpecs: null, reviewed: null };
|
|
57
|
-
|
|
58
|
-
/** Whether the open proposal's source goes in the address (see `showProposal`) */
|
|
59
|
-
let pinnedSource = false;
|
|
60
|
-
|
|
61
|
-
/** What the server listed last: `[{ slug, title, summary, spec, source, counts, errors, review, error? }]`, or null before the first answer */
|
|
62
|
-
let listing = null;
|
|
63
|
-
let listingProblem = null;
|
|
64
|
-
/** Why the server left the open spec PRs out of the last listing (the forge could not be asked), or null */
|
|
65
|
-
let forgeProblem = null;
|
|
66
|
-
/** When the listing was last read (ms), and who wants to hear of a new one (the Work panel's Specs tab, forge-panel.js) */
|
|
67
|
-
let listingAt = 0;
|
|
68
|
-
const listingWatchers = new Set();
|
|
69
|
-
|
|
70
|
-
/** What the server listed last, for the Work panel's Specs tab: the entries (null before the first answer), why the list could not be read, why the spec PRs are missing, and when */
|
|
71
|
-
export const proposalListing = () => ({ entries: listing, problem: listingProblem, forgeProblem, at: listingAt });
|
|
72
|
-
/** Calls `fn` each time the list is read again; returns the way to stop */
|
|
73
|
-
export function onProposalListing(fn) {
|
|
74
|
-
listingWatchers.add(fn);
|
|
75
|
-
return () => listingWatchers.delete(fn);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// ---------------------------------------------------------------------------
|
|
79
|
-
// Loading and closing
|
|
80
|
-
// ---------------------------------------------------------------------------
|
|
81
|
-
|
|
82
|
-
/** Asks the server for the proposals it can serve */
|
|
83
|
-
export async function loadProposalList() {
|
|
84
|
-
try {
|
|
85
|
-
let res;
|
|
86
|
-
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.'); }
|
|
87
|
-
if (!res.ok) throw new Error(`The server could not list them (error ${res.status}).`);
|
|
88
|
-
let body;
|
|
89
|
-
try { body = await res.json(); } catch { throw new Error('cornfield sent a list this page could not read.'); }
|
|
90
|
-
if (!Array.isArray(body)) throw new Error('cornfield sent something that is not a list of proposals.');
|
|
91
|
-
listing = body;
|
|
92
|
-
listingProblem = null;
|
|
93
|
-
const said = res.headers.get('X-Proposals-Forge-Error');
|
|
94
|
-
forgeProblem = said ? decodeURIComponent(said) : null;
|
|
95
|
-
} catch (err) {
|
|
96
|
-
listing = null;
|
|
97
|
-
forgeProblem = null;
|
|
98
|
-
listingProblem = err.message || 'cornfield did not answer.'; // always a plain sentence made above, never a parser's or a runtime's own words
|
|
99
|
-
}
|
|
100
|
-
listingAt = Date.now();
|
|
101
|
-
renderMenu();
|
|
102
|
-
for (const fn of listingWatchers) fn();
|
|
103
|
-
return listing;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Opens a proposal by name: fetches it from the server and shows it. `source` is where the server found it
|
|
108
|
-
* (`checkout` or a worktree's name); without one the server answers with the first it lists.
|
|
109
|
-
* @returns {Promise<boolean>} whether it opened
|
|
110
|
-
*/
|
|
111
|
-
export async function openProposal(slug, source = null) {
|
|
112
|
-
const token = ++openToken;
|
|
113
|
-
setMessage(`Opening ${slug} …`);
|
|
114
|
-
try {
|
|
115
|
-
let res;
|
|
116
|
-
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.`); }
|
|
117
|
-
if (!res.ok) {
|
|
118
|
-
let why = '';
|
|
119
|
-
try { why = (await res.json()).error || ''; } catch { /* no body */ }
|
|
120
|
-
const err = new Error(res.status === 404 ? notFoundWords(slug, source) : `${slug} could not be opened: ${why || `the server had a problem (error ${res.status}).`}`);
|
|
121
|
-
err.notFound = res.status === 404;
|
|
122
|
-
throw err;
|
|
123
|
-
}
|
|
124
|
-
const found = res.headers.get('X-Proposal-Source');
|
|
125
|
-
let item;
|
|
126
|
-
try { item = await res.json(); } catch { throw new Error(`${slug} could not be opened: cornfield sent a file this page could not read.`); }
|
|
127
|
-
const sha256 = res.headers.get('X-Proposal-Sha256'); // the version on screen: a review names it, so a push since is refused, not approved unseen
|
|
128
|
-
showProposal(item, { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true, sha256 });
|
|
129
|
-
// said once, here: a proposal opens on a person's asking, never on a background refresh
|
|
130
|
-
announce([reviewOpenedLine($('proposal-title').textContent), reviewLayersLine()].filter(Boolean).join(' ')); // and, once, which layers the review hid
|
|
131
|
-
return true;
|
|
132
|
-
} catch (err) {
|
|
133
|
-
console.error('Opening the proposal failed', err);
|
|
134
|
-
// Said plainly, with the ways on: the Specs list, and the same name under another source when the list has one
|
|
135
|
-
// (a failure that is not "no such proposal" can be asked for again, or let go of: Retry and Close)
|
|
136
|
-
setMessage(err.message || `${slug} could not be opened.`, true, err.notFound ? [specsWay()] : [{ label: 'Retry', way: 'retry', slug, source }, { label: 'Close', way: 'close' }]);
|
|
137
|
-
if (err.notFound && token === openToken) {
|
|
138
|
-
await loadProposalList();
|
|
139
|
-
const sources = new Set((Array.isArray(listing) ? listing : []).map((e) => e && e.source));
|
|
140
|
-
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()]);
|
|
141
|
-
}
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** The way on every bad link offers: the list of specs */
|
|
147
|
-
const specsWay = () => ({ label: t('openSpecsList'), way: 'specs' });
|
|
148
|
-
/** Which `openProposal` is the latest, so a slow answer never writes over a newer one */
|
|
149
|
-
let openToken = 0;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Puts a parsed proposal on the map. The map's nodes and edges become `applyProposal(base, proposal)`.
|
|
153
|
-
* @param {object} proposal
|
|
154
|
-
* @param {{slug?: string|null, source?: string|null, pinSource?: boolean, view?: 'before'|'diff'|'after', fit?: boolean, sha256?: string|null}} [opts]
|
|
155
|
-
* `sha256`: the file's SHA-256 as the server sent it (X-Proposal-Sha256): a review names it (spec 0007)
|
|
156
|
-
* `fit`: fit the camera to what the proposal touches and what it connects to (default true).
|
|
157
|
-
* `pinSource`: put `&source=` in the address (it was asked for by name; otherwise `/?proposal=<slug>` finds the same one)
|
|
158
|
-
*/
|
|
159
|
-
export function showProposal(proposal, { slug = null, source = null, pinSource = false, view, fit = true, sha256 = null } = {}) {
|
|
160
|
-
state.proposal = proposal;
|
|
161
|
-
beginReview(); // the map narrows to the change: a review of its own, the viewer's layers untouched (layers.js, layer-model.js)
|
|
162
|
-
state.proposalSlug = slug;
|
|
163
|
-
state.proposalSource = source;
|
|
164
|
-
state.proposalSha256 = typeof sha256 === 'string' && /^[0-9a-f]{64}$/.test(sha256) ? sha256 : null;
|
|
165
|
-
pinnedSource = pinSource;
|
|
166
|
-
if (view) state.proposalView = view;
|
|
167
|
-
else if (!PROPOSAL_VIEWS.includes(state.proposalView)) state.proposalView = 'diff';
|
|
168
|
-
rebuildProposalMap(hooks.effective ? hooks.effective(proposal) : proposal, { fit });
|
|
169
|
-
syncAddress();
|
|
170
|
-
closeMenu();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Redraws the map from `proposal` laid over the base, and the bar from `state.proposal`. Call it
|
|
175
|
-
* after anything the map is built from changes. `effective` is the proposal to apply: `state.proposal`,
|
|
176
|
-
* or an edited copy of it (what-if edits, TOPO-11).
|
|
177
|
-
* @param {object} [effective]
|
|
178
|
-
* @param {{fit?: boolean}} [opts]
|
|
179
|
-
*/
|
|
180
|
-
export function rebuildProposalMap(effective = hooks.effective ? hooks.effective(state.proposal) : state.proposal, { fit = false } = {}) {
|
|
181
|
-
const base = { nodes: state.baseNodes, edges: state.baseEdges };
|
|
182
|
-
let applied;
|
|
183
|
-
state.effectiveProposal = effective;
|
|
184
|
-
try {
|
|
185
|
-
state.proposalErrors = proposalProblems(base, effective).errors;
|
|
186
|
-
applied = applyProposal(base, effective);
|
|
187
|
-
if (hooks.mark) hooks.mark(applied, effective, state.proposal);
|
|
188
|
-
} catch (err) {
|
|
189
|
-
// A file so malformed that it cannot be read at all: the plain map, and the reason
|
|
190
|
-
state.proposalErrors = [{ path: '', message: `This proposal could not be read: ${err.message}` }];
|
|
191
|
-
applied = { nodes: state.baseNodes.map((n) => ({ ...n, mark: 'none' })), edges: state.baseEdges.map((e) => ({ ...e, mark: 'none' })) };
|
|
192
|
-
}
|
|
193
|
-
swapMap(applied.nodes, applied.edges);
|
|
194
|
-
renderBar(); // first: the fit below leaves out what the bar covers, so the bar must be laid out
|
|
195
|
-
renderLayerToggles(); // the menu follows the layers the change touches
|
|
196
|
-
if (fit) fitToChange();
|
|
197
|
-
render();
|
|
198
|
-
ensureFlowLoop();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/** Closes the proposal: the plain map comes back, as it was, and the address loses `?proposal=` */
|
|
202
|
-
export function closeProposal() {
|
|
203
|
-
if (hooks.beforeClose && hooks.beforeClose() === false) return;
|
|
204
|
-
state.proposal = null;
|
|
205
|
-
state.effectiveProposal = null;
|
|
206
|
-
state.proposalSlug = null;
|
|
207
|
-
state.proposalSource = null;
|
|
208
|
-
state.proposalSha256 = null;
|
|
209
|
-
state.proposalErrors = [];
|
|
210
|
-
endReview(); // the viewer's own layers are what is drawn again, exactly as they were
|
|
211
|
-
swapMap(state.baseNodes.map((n) => ({ ...n })), state.baseEdges);
|
|
212
|
-
fitGraphToViewport(fitPadding());
|
|
213
|
-
render();
|
|
214
|
-
ensureFlowLoop();
|
|
215
|
-
renderBar();
|
|
216
|
-
syncAddress();
|
|
217
|
-
if (hooks.closed) hooks.closed();
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Switches between Before, Diff and After; no node moves. Entering Diff fits the camera to the change. */
|
|
221
|
-
export function setProposalView(view, { quiet = false } = {}) {
|
|
222
|
-
if (!state.proposal || !PROPOSAL_VIEWS.includes(view) || state.proposalView === view) return;
|
|
223
|
-
state.proposalView = view;
|
|
224
|
-
touchScene();
|
|
225
|
-
if (state.selectedNode && !isNodeVisible(state.selectedNode)) closeDrawer(); // it is not in this view
|
|
226
|
-
if (view === 'diff') fitToChange();
|
|
227
|
-
render();
|
|
228
|
-
renderBar();
|
|
229
|
-
syncAddress();
|
|
230
|
-
if (!quiet) announce(viewWords(view));
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** Hands the map new nodes and edges, keeping the selection on the same node */
|
|
234
|
-
function swapMap(nodes, edges) {
|
|
235
|
-
const selected = state.selectedNode ? state.selectedNode.id : null;
|
|
236
|
-
setMap(nodes, edges);
|
|
237
|
-
state.selectedEdge = null;
|
|
238
|
-
if (selected) {
|
|
239
|
-
const again = state.nodes.find((n) => n.id === selected);
|
|
240
|
-
if (again) state.selectedNode = again;
|
|
241
|
-
else closeDrawer();
|
|
242
|
-
}
|
|
243
|
-
touchScene();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 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
|
|
248
|
-
* map nothing covers (the bar, the review column, 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
|
|
249
|
-
* 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,
|
|
250
|
-
* 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.
|
|
251
|
-
*/
|
|
252
|
-
function fitToChange() {
|
|
253
|
-
const { touched } = touchedIds(state.nodes, viewEdges());
|
|
254
|
-
const items = state.nodes.filter((n) => touched.has(n.id) && isNodeVisible(n));
|
|
255
|
-
const rect = visibleMapRect();
|
|
256
|
-
const opts = { padding: fitPadding(), maxZoom: 1, minZoom: getMinZoom() };
|
|
257
|
-
// The whole change when it fits at FRAME_ZOOM_MIN or closer; else the biggest part of it that does (camera.js)
|
|
258
|
-
const group = largestGroup(items, rect, { ...opts, minZoom: Math.max(opts.minZoom, FRAME_ZOOM_MIN) });
|
|
259
|
-
const cam = items.length ? frameNodes(group, rect, opts) : null;
|
|
260
|
-
if (!cam) { fitGraphToViewport(fitPadding()); return; }
|
|
261
|
-
Object.assign(state.camera, cam);
|
|
262
|
-
render();
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/** `?proposal=` (and `source`, `proposalView`) follow the open proposal, without a new history entry; other parameters stay */
|
|
266
|
-
function syncAddress() {
|
|
267
|
-
if (typeof history === 'undefined' || typeof location === 'undefined') return;
|
|
268
|
-
try {
|
|
269
|
-
const params = new URLSearchParams(location.search);
|
|
270
|
-
['proposal', 'source', 'proposalView'].forEach((k) => params.delete(k));
|
|
271
|
-
if (state.proposal && state.proposalSlug) {
|
|
272
|
-
params.set('proposal', state.proposalSlug);
|
|
273
|
-
if (pinnedSource && state.proposalSource) params.set('source', state.proposalSource);
|
|
274
|
-
if (state.proposalView !== 'diff') params.set('proposalView', state.proposalView);
|
|
275
|
-
}
|
|
276
|
-
const query = params.toString();
|
|
277
|
-
history.replaceState(null, '', `${location.pathname}${query ? `?${query}` : ''}${location.hash}`);
|
|
278
|
-
} catch { /* the address is a convenience */ }
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// ---------------------------------------------------------------------------
|
|
282
|
-
// The bar: title, counts chip, Before / Diff / After, problems, Close
|
|
283
|
-
// ---------------------------------------------------------------------------
|
|
284
|
-
|
|
285
|
-
/** 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) */
|
|
286
|
-
function setMessage(text, isError = false, ways = []) {
|
|
287
|
-
const bar = $('proposal-bar');
|
|
288
|
-
if (!bar) return;
|
|
289
|
-
bar.hidden = false;
|
|
290
|
-
bar.classList.toggle('is-error', isError);
|
|
291
|
-
$('proposal-body').hidden = true;
|
|
292
|
-
const msg = $('proposal-message');
|
|
293
|
-
msg.hidden = false;
|
|
294
|
-
msg.textContent = text;
|
|
295
|
-
const box = $('proposal-ways');
|
|
296
|
-
if (!box) return;
|
|
297
|
-
box.hidden = ways.length === 0;
|
|
298
|
-
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('');
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// ---------------------------------------------------------------------------
|
|
302
|
-
// Which copy is open: the chip after the title
|
|
303
|
-
// ---------------------------------------------------------------------------
|
|
304
|
-
|
|
305
|
-
/** 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 */
|
|
306
|
-
const pullInfo = new Map();
|
|
307
|
-
/** The proposal the PR was last asked for (`source/slug`): asked again when another opens, not each time the bar is drawn */
|
|
308
|
-
let pullAskedFor = null;
|
|
309
|
-
|
|
310
|
-
const safeHref = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
|
|
311
|
-
|
|
312
|
-
/** 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. */
|
|
313
|
-
function paintSource() {
|
|
314
|
-
const chip = $('proposal-source');
|
|
315
|
-
if (!chip) return;
|
|
316
|
-
const source = state.proposal ? state.proposalSource : null;
|
|
317
|
-
chip.hidden = !source;
|
|
318
|
-
if (!source) return;
|
|
319
|
-
const n = pullNumberOf(source);
|
|
320
|
-
const known = n ? pullInfo.get(n) : null;
|
|
321
|
-
const entry = n && Array.isArray(listing) ? listing.find((e) => e.slug === state.proposalSlug && e.source === source) : null;
|
|
322
|
-
const words = sourceChip(source, (known && known.pull) || (entry && entry.pull) || null, known ? known.checks : null);
|
|
323
|
-
chip.textContent = words.text;
|
|
324
|
-
if (words.state) chip.dataset.cornState = words.state; else delete chip.dataset.cornState;
|
|
325
|
-
const href = safeHref(words.href);
|
|
326
|
-
if (href) { chip.setAttribute('href', href); chip.setAttribute('target', '_blank'); chip.setAttribute('rel', 'noreferrer'); chip.title = 'Open this pull request'; } else {
|
|
327
|
-
chip.removeAttribute('href'); chip.removeAttribute('target'); chip.removeAttribute('rel'); chip.title = words.label;
|
|
328
|
-
}
|
|
329
|
-
const key = `${source}/${state.proposalSlug}`;
|
|
330
|
-
if (n && pullAskedFor !== key) { pullAskedFor = key; loadPullInfo(n); }
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/** 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 */
|
|
334
|
-
async function loadPullInfo(n) {
|
|
335
|
-
try {
|
|
336
|
-
const res = await fetch(`/api/forge/pulls/${n}`);
|
|
337
|
-
const body = res.ok ? await res.json() : null;
|
|
338
|
-
if (body && body.ok !== false && body.pull) pullInfo.set(n, { pull: body.pull, checks: Array.isArray(body.checks) ? body.checks : null });
|
|
339
|
-
if (body && body.pull && pullNumberOf(state.proposalSource) === n) setPullHead(body.pull.head && typeof body.pull.head.sha === 'string' ? body.pull.head.sha : ''); // what was seen is kept per PR head
|
|
340
|
-
} catch { /* no forge, or not signed in: the chip keeps what it has */ }
|
|
341
|
-
if (state.proposal && pullNumberOf(state.proposalSource) === n) paintSource();
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/** The problems a proposal has, as the bar lists them (at most `max`, then "and N more") */
|
|
345
|
-
export function problemsHtml(errors, max = 8) {
|
|
346
|
-
const shown = errors.slice(0, max).map((e) => `<li>${e.path ? `<code class="hx-code">${escHtml(e.path)}</code> ` : ''}${escHtml(e.message)}</li>`);
|
|
347
|
-
if (errors.length > max) shown.push(`<li class="hx-faint">and ${errors.length - max} more</li>`);
|
|
348
|
-
return shown.join('');
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const asList = (v) => (Array.isArray(v) ? v : []);
|
|
352
|
-
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
353
|
-
|
|
354
|
-
export function renderBar() {
|
|
355
|
-
const bar = $('proposal-bar');
|
|
356
|
-
if (!bar) return;
|
|
357
|
-
const open = !!state.proposal;
|
|
358
|
-
bar.hidden = !open;
|
|
359
|
-
const legend = $('proposal-legend');
|
|
360
|
-
if (legend) legend.hidden = !open;
|
|
361
|
-
if (!open) { closeMore(); toggleMode(false); collapseSheet('proposal'); renderReviewColumn(); if (hooks.bar) hooks.bar(false); return; }
|
|
362
|
-
|
|
363
|
-
bar.classList.remove('is-error');
|
|
364
|
-
$('proposal-message').hidden = true;
|
|
365
|
-
$('proposal-body').hidden = false;
|
|
366
|
-
const p = state.proposal;
|
|
367
|
-
$('proposal-title').textContent = (p && typeof p.title === 'string' && p.title) || state.proposalSlug || 'Proposal';
|
|
368
|
-
paintSource();
|
|
369
|
-
const summary = $('proposal-summary');
|
|
370
|
-
summary.textContent = (p && typeof p.summary === 'string' && p.summary) || '';
|
|
371
|
-
summary.hidden = !summary.textContent;
|
|
372
|
-
$('proposal-title').title = summary.textContent; // the bar stays one row: the summary is also the title's tooltip, and leads the review column
|
|
373
|
-
|
|
374
|
-
const counts = summarize(p);
|
|
375
|
-
const chip = $('proposal-chip');
|
|
376
|
-
// The counts name their lists: the changes part shows the Changes section, "5 scenarios" the Scenarios section (the review column, review-column.js)
|
|
377
|
-
const parts = barCounts(counts);
|
|
378
|
-
chip.innerHTML = parts.map((c) => {
|
|
379
|
-
const dot = c.mark ? `<span class="hx-mark-dot hx-mark-dot--${c.mark}" data-corn="mark-dot"${markStateAttr(c.mark)} aria-hidden="true"></span>` : '';
|
|
380
|
-
if (!c.mark && /scenarios?$/.test(c.text)) return `<button type="button" class="hx-proposal-count" data-action="review-show-scenarios" data-corn-kind="quiet" title="Show the personas and their scenarios">${escHtml(c.text)}</button>`;
|
|
381
|
-
return `<button type="button" class="hx-proposal-count" data-action="review-show-changes" data-corn-kind="quiet" title="Show the list of changes">${dot}${escHtml(c.text)}</button>`;
|
|
382
|
-
}).join('<span class="hx-proposal-sep" aria-hidden="true"> · </span>');
|
|
383
|
-
// The reviewer's own edits are a part of their own, never added to the proposal's numbers (spec 0007 D5)
|
|
384
|
-
const yours = yoursText(state.whatIf && state.whatIf.edits, !!state.whatIfOff);
|
|
385
|
-
if (yours) chip.insertAdjacentHTML('beforeend', `<span class="hx-proposal-sep" aria-hidden="true"> · </span><span class="hx-proposal-count hx-proposal-yours"><span class="hx-mark-dot hx-mark-dot--edit" data-corn="mark-dot" data-corn-state="edit" aria-hidden="true"></span>${escHtml(yours)}</span>`);
|
|
386
|
-
$('proposal-mode').textContent = t(state.proposalView);
|
|
387
|
-
|
|
388
|
-
for (const btn of bar.querySelectorAll('[data-action="proposal-view"]')) {
|
|
389
|
-
const on = btn.dataset.view === state.proposalView;
|
|
390
|
-
btn.setAttribute('aria-pressed', String(on));
|
|
391
|
-
btn.classList.toggle('is-on', on);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const whole = $('proposal-whole'); // the switch is the review's: off at every opening, kept across Before, Diff and After
|
|
395
|
-
if (whole) { // the pressed look is the one the bar's other chosen buttons have (it holds on hover)
|
|
396
|
-
const on = !!(state.review && state.review.whole);
|
|
397
|
-
whole.setAttribute('aria-pressed', String(on));
|
|
398
|
-
whole.title = t('showWholeMap'); // the words are short ("Whole map"); the tooltip says it in full, as its name does
|
|
399
|
-
whole.classList.toggle('hx-btn--active', on);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const errors = state.proposalErrors || [];
|
|
403
|
-
const box = $('proposal-errors');
|
|
404
|
-
box.hidden = errors.length === 0;
|
|
405
|
-
if (errors.length) {
|
|
406
|
-
$('proposal-errors-count').textContent = `${plural(errors.length, 'problem')} in this proposal`;
|
|
407
|
-
$('proposal-errors-list').innerHTML = problemsHtml(errors);
|
|
408
|
-
}
|
|
409
|
-
renderReviewColumn();
|
|
410
|
-
if (hooks.bar) hooks.bar(true);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Picks a row of the changes list: select it, centre it in the part of the map the review column, the node panel and (on a phone) the sheets leave free,
|
|
415
|
-
* at a zoom where its label reads, and make sure the current view shows it
|
|
416
|
-
*/
|
|
417
|
-
export function focusChange(kind, key, { select = true } = {}) {
|
|
418
|
-
const item = kind === 'edge' ? state.edges.find((e) => edgeKey(e) === key) : state.nodes.find((n) => n.id === key);
|
|
419
|
-
if (!item) return;
|
|
420
|
-
const ends = (kind === 'edge' ? [state.nodes.find((n) => n.id === item.from), state.nodes.find((n) => n.id === item.to)] : [item]).filter(Boolean);
|
|
421
|
-
if (!ends.length) return;
|
|
422
|
-
if (state.proposalView !== 'diff' && ends.some((n) => !isNodeVisible(n))) setProposalView('diff', { quiet: true }); // Before or After hides what it removes or adds
|
|
423
|
-
if (select) { if (kind === 'edge') showEdgePanel(item); else selectNode(item); }
|
|
424
|
-
// The panel is open now, so what it covers is known
|
|
425
|
-
const cam = frameNodes(ends, visibleMapRect(), { padding: fitPadding(), maxZoom: Math.max(READ_ZOOM, state.camera.zoom), minZoom: getMinZoom() });
|
|
426
|
-
if (cam) Object.assign(state.camera, cam);
|
|
427
|
-
render();
|
|
428
|
-
announce(jumpWords(MARK_WORDS[item.mark] || item.mark, kind === 'edge' ? `${nameOf(item.from)} to ${nameOf(item.to)}` : item.label));
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// ---------------------------------------------------------------------------
|
|
432
|
-
// The ⋯ menu (a menu button) and the phone's Before / Diff / After switcher
|
|
433
|
-
// ---------------------------------------------------------------------------
|
|
434
|
-
|
|
435
|
-
const moreItems = () => [...document.querySelectorAll('#proposal-more-menu [role="menuitem"]')];
|
|
436
|
-
|
|
437
|
-
function moreOpen() {
|
|
438
|
-
const menu = $('proposal-more-menu');
|
|
439
|
-
return !!menu && !menu.hidden;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/** Closes the ⋯ menu; `refocus` puts focus back on its button (Escape, or a choice made) */
|
|
443
|
-
function closeMore(refocus = false) {
|
|
444
|
-
const menu = $('proposal-more-menu');
|
|
445
|
-
const btn = $('proposal-more');
|
|
446
|
-
if (menu) menu.hidden = true;
|
|
447
|
-
if (btn) { btn.setAttribute('aria-expanded', 'false'); if (refocus) btn.focus(); }
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function openMore(which = 'first') {
|
|
451
|
-
const menu = $('proposal-more-menu');
|
|
452
|
-
if (!menu) return;
|
|
453
|
-
menu.hidden = false;
|
|
454
|
-
$('proposal-more').setAttribute('aria-expanded', 'true');
|
|
455
|
-
const items = moreItems();
|
|
456
|
-
(which === 'last' ? items[items.length - 1] : items[0])?.focus();
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/** On a phone the mode button shows the compare switcher under the counts; from 768px the switcher is always there */
|
|
460
|
-
function toggleMode(force) {
|
|
461
|
-
const bar = $('proposal-bar');
|
|
462
|
-
const on = typeof force === 'boolean' ? force : bar.dataset.modeOpen !== 'true';
|
|
463
|
-
bar.dataset.modeOpen = String(on);
|
|
464
|
-
$('proposal-mode').setAttribute('aria-expanded', String(on));
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function onMoreKey(e) {
|
|
468
|
-
const btn = $('proposal-more');
|
|
469
|
-
if (e.target === btn && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) { e.preventDefault(); openMore(e.key === 'ArrowUp' ? 'last' : 'first'); return; }
|
|
470
|
-
if (!moreOpen()) return;
|
|
471
|
-
if (e.key === 'Escape') { e.preventDefault(); closeMore(true); return; }
|
|
472
|
-
if (e.key === 'Tab') { closeMore(); return; }
|
|
473
|
-
const items = moreItems();
|
|
474
|
-
const at = items.indexOf(document.activeElement);
|
|
475
|
-
if (at < 0) return;
|
|
476
|
-
const next = { ArrowDown: (at + 1) % items.length, ArrowUp: (at - 1 + items.length) % items.length, Home: 0, End: items.length - 1 }[e.key];
|
|
477
|
-
if (next === undefined) return;
|
|
478
|
-
e.preventDefault();
|
|
479
|
-
items[next].focus();
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// ---------------------------------------------------------------------------
|
|
483
|
-
// The picker
|
|
484
|
-
// ---------------------------------------------------------------------------
|
|
485
|
-
|
|
486
|
-
function menuOpen() {
|
|
487
|
-
const menu = $('proposal-menu');
|
|
488
|
-
return !!menu && !menu.hidden;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
function closeMenu() {
|
|
492
|
-
const menu = $('proposal-menu');
|
|
493
|
-
if (menu) menu.hidden = true;
|
|
494
|
-
const btn = $('proposal-btn');
|
|
495
|
-
if (btn) btn.setAttribute('aria-expanded', 'false');
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
async function toggleMenu() {
|
|
499
|
-
const menu = $('proposal-menu');
|
|
500
|
-
if (!menu) return;
|
|
501
|
-
if (menuOpen()) return closeMenu();
|
|
502
|
-
menu.hidden = false;
|
|
503
|
-
$('proposal-btn').setAttribute('aria-expanded', 'true');
|
|
504
|
-
if (!listing) renderMenu(true);
|
|
505
|
-
await loadProposalList(); // always ask again: worktrees come and go
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function where(entry) {
|
|
509
|
-
if (entry.pull) return `Spec PR #${entry.pull.number}${entry.pull.draft ? ' (draft)' : ''}${entry.pull.author ? ` by ${entry.pull.author}` : ''}`;
|
|
510
|
-
return entry.source === 'checkout' ? 'In the checkout' : `In worktree ${entry.source}`;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
/** One row of the picker */
|
|
514
|
-
export function proposalRowHtml(entry, current) {
|
|
515
|
-
const mine = current && current.slug === entry.slug && current.source === entry.source;
|
|
516
|
-
const head = `<span class="hx-proposal-title">${escHtml(entry.title || entry.slug)}</span>`;
|
|
517
|
-
const meta = [`<span class="hx-proposal-where">${escHtml(where(entry))}</span>`];
|
|
518
|
-
if (entry.spec) meta.push(`<span>spec ${escHtml(entry.spec)}</span>`);
|
|
519
|
-
if (entry.error) {
|
|
520
|
-
return `<div class="hx-proposal-item is-broken" data-corn="row">${head}<span class="hx-proposal-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-proposal-meta">${meta.join('')}</span></div>`;
|
|
521
|
-
}
|
|
522
|
-
if (entry.counts) meta.push(`<span>${escHtml(chipText(entry.counts))}</span>`);
|
|
523
|
-
const reviewed = reviewWords(entry.review, Date.now()); // "Approved 3 minutes ago", from the listing
|
|
524
|
-
if (reviewed) meta.push(`<span class="hx-proposal-reviewed">${escHtml(reviewed)}</span>`);
|
|
525
|
-
if (entry.errors) meta.push(`<span class="hx-warn">${escHtml(plural(entry.errors, 'problem'))}</span>`);
|
|
526
|
-
return `<button type="button" class="hx-proposal-item${mine ? ' is-current' : ''}" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}" data-corn="row">${head}${entry.summary ? `<span class="hx-proposal-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-proposal-meta">${meta.join('')}</span></button>`;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
function renderMenu(loading = false) {
|
|
530
|
-
const menu = $('proposal-menu');
|
|
531
|
-
if (!menu) return;
|
|
532
|
-
const current = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
|
|
533
|
-
let body;
|
|
534
|
-
if (loading && !listing) body = '<p class="hx-faint hx-proposal-empty">Looking for proposals …</p>';
|
|
535
|
-
else if (listingProblem) body = `<p class="hx-error-text hx-proposal-empty">The list could not be loaded: ${escHtml(listingProblem)}</p>`;
|
|
536
|
-
else if (!listing || listing.length === 0) body = '<p class="hx-faint hx-proposal-empty">No proposals</p>';
|
|
537
|
-
else body = `<div class="hx-proposal-list" role="list">${listing.map((e) => `<div role="listitem">${proposalRowHtml(e, current)}</div>`).join('')}</div>`;
|
|
538
|
-
const forge = forgeProblem && !listingProblem ? `<p class="hx-error-text hx-proposal-empty">The spec PRs could not be listed: ${escHtml(forgeProblem)}</p>` : '';
|
|
539
|
-
menu.innerHTML = `<div class="hx-menu-title hx-menu-head" data-corn="menu-title"><span>${escHtml(t('proposals'))}</span></div>${forge}${body}`;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
// ---------------------------------------------------------------------------
|
|
543
|
-
// Picking an edge, and its panel
|
|
544
|
-
// ---------------------------------------------------------------------------
|
|
545
|
-
|
|
546
|
-
/** The kind a scene edge reports for an applied one (an ownership link has none) */
|
|
547
|
-
const kindOf = (e) => e.kind || (e.dashed ? 'usage' : 'ownership');
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* The marked edge under a point of the map, or null: the nearest one within `tolerance` world units,
|
|
551
|
-
* measured along the drawn curve. Only the edges of the current scene, so a hidden one is never hit.
|
|
552
|
-
* @param {number} x world
|
|
553
|
-
* @param {number} y world
|
|
554
|
-
* @param {number} tolerance world units
|
|
555
|
-
*/
|
|
556
|
-
export function markedEdgeAt(x, y, tolerance) {
|
|
557
|
-
let best = null;
|
|
558
|
-
let bestDistance = tolerance;
|
|
559
|
-
for (const edge of getScene().edges) {
|
|
560
|
-
if (edge.mark === 'none') continue;
|
|
561
|
-
for (let k = 0; k <= 1; k += 1 / 20) {
|
|
562
|
-
const p = edgePoint(edge, k);
|
|
563
|
-
const d = Math.hypot(p.x - x, p.y - y);
|
|
564
|
-
if (d <= bestDistance) { best = edge; bestDistance = d; }
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
if (!best) return null;
|
|
568
|
-
return viewEdges().find((e) => e.from === best.from && e.to === best.to && kindOf(e) === best.kind) || null;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/** Fills the side panel for an edge: what it is, and what the proposal says about it */
|
|
572
|
-
export function showEdgePanel(edge) {
|
|
573
|
-
closeDrawer(); // clears a node selection and any panel still loading
|
|
574
|
-
state.selectedEdge = edge;
|
|
575
|
-
const row = (label, value) => (value ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">${escHtml(label)}</div><div class="hx-fact-v">${escHtml(value)}</div></div>` : '');
|
|
576
|
-
const facts = row('Kind', kindOf(edge)) + row('Flow', edge.flow) + row('Label', edge.label) + row('Reads', Array.isArray(edge.keys) ? edge.keys.join(', ') : '');
|
|
577
|
-
|
|
578
|
-
$('drawer-title').textContent = `${nameOf(edge.from)} → ${nameOf(edge.to)}`;
|
|
579
|
-
$('drawer-title').classList.remove('hx-mono');
|
|
580
|
-
$('drawer-badge').textContent = 'Edge';
|
|
581
|
-
$('drawer-host').textContent = '';
|
|
582
|
-
$('drawer-diff').hidden = true;
|
|
583
|
-
$('drawer-description').textContent = '';
|
|
584
|
-
$('drawer-description').hidden = true;
|
|
585
|
-
$('drawer-meta-list').innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
|
|
586
|
-
<div class="hx-facts">
|
|
587
|
-
<div class="hx-fact" data-corn="section"><div class="hx-fact-k">From</div><div class="hx-fact-v"><button data-corn="node-link" type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.from)}">${escHtml(nameOf(edge.from))}</button></div></div>
|
|
588
|
-
<div class="hx-fact" data-corn="section"><div class="hx-fact-k">To</div><div class="hx-fact-v"><button data-corn="node-link" type="button" class="hx-linkbtn" data-action="select-node" data-id="${escHtml(edge.to)}">${escHtml(nameOf(edge.to))}</button></div></div>
|
|
589
|
-
</div>${proposalPanelHtml(edge)}`;
|
|
590
|
-
$('drawer-open-btn').hidden = true;
|
|
591
|
-
$('drawer-file-btn').hidden = true;
|
|
592
|
-
$('drawer-run-btn').hidden = true;
|
|
593
|
-
$('spec-drawer').classList.add('drawer-open');
|
|
594
|
-
$('spec-drawer').inert = false; // closed, the panel is inert (MAP-02): open for an edge, its links and its Close are reached as a node's are
|
|
595
|
-
$('drawer-backdrop').hidden = false;
|
|
596
|
-
touchScene();
|
|
597
|
-
render();
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/** A click on the canvas that picks no node but lands on a marked edge opens that edge */
|
|
601
|
-
function bindEdgePicking() {
|
|
602
|
-
const canvas = state.canvas;
|
|
603
|
-
if (!canvas) return;
|
|
604
|
-
let down = null;
|
|
605
|
-
canvas.addEventListener('mousedown', (e) => { down = { x: e.clientX, y: e.clientY }; });
|
|
606
|
-
canvas.addEventListener('click', (e) => {
|
|
607
|
-
if (!state.proposal || state.proposalView === 'before') return; // Before has no marked edges
|
|
608
|
-
if (down && Math.hypot(e.clientX - down.x, e.clientY - down.y) > 5) return; // a drag
|
|
609
|
-
const rect = canvas.getBoundingClientRect();
|
|
610
|
-
const p = screenToWorld(e.clientX - rect.left, e.clientY - rect.top);
|
|
611
|
-
const zoom = state.camera.zoom;
|
|
612
|
-
const onNode = state.nodes.some((n) => isNodeVisible(n) && Math.hypot(n.x - p.x, n.y - p.y) <= n.r + 6 / zoom);
|
|
613
|
-
if (onNode) return; // a node: the map's own selection handles it
|
|
614
|
-
const edge = markedEdgeAt(p.x, p.y, 8 / zoom);
|
|
615
|
-
if (edge) showEdgePanel(edge);
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
// ---------------------------------------------------------------------------
|
|
620
|
-
// Wiring
|
|
621
|
-
// ---------------------------------------------------------------------------
|
|
622
|
-
|
|
623
|
-
const ACTIONS = {
|
|
624
|
-
'toggle-proposals-menu': () => toggleMenu(),
|
|
625
|
-
'open-proposal': (el) => openProposal(el.dataset.slug, el.dataset.source || null),
|
|
626
|
-
'close-proposal': () => closeProposal(),
|
|
627
|
-
'proposal-whole': () => { setWholeMap(!(state.review && state.review.whole)); renderBar(); }, // "Show the whole map": announced by layers.js, the focus stays on the switch
|
|
628
|
-
'proposal-view': (el) => { setProposalView(el.dataset.view); toggleMode(false); },
|
|
629
|
-
'toggle-proposal-mode': () => toggleMode(),
|
|
630
|
-
'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
|
|
631
|
-
'review-show-changes': () => showSection('changes'),
|
|
632
|
-
'review-show-scenarios': () => showSection('scenarios'),
|
|
633
|
-
'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()),
|
|
634
|
-
'proposal-focus': (el) => focusChange(el.dataset.kind, el.dataset.key),
|
|
16
|
+
import { pageInstance } from './state.js';
|
|
17
|
+
import { pageMap } from './render.js';
|
|
18
|
+
import { ensurePagePieces, pagePiece } from './page-pieces.js';
|
|
19
|
+
import * as E from './engine/proposal.js';
|
|
20
|
+
import { problemsHtml as problems, proposalRowHtml as row } from './pieces/proposal.js';
|
|
21
|
+
import { openFromAddress, keepAddress } from './page-address.js';
|
|
22
|
+
|
|
23
|
+
/** The page's instance, with its map and its pieces there */
|
|
24
|
+
const page = () => { pageMap(); ensurePagePieces(); return pageInstance(); };
|
|
25
|
+
|
|
26
|
+
// The old hooks: each is a function a module assigned, registered as a listener of the page instance
|
|
27
|
+
const ADAPT = {
|
|
28
|
+
effective: (fn) => ['proposal:effective', (proposal) => fn(proposal)],
|
|
29
|
+
mark: (fn) => ['proposal:mark', ({ applied, effective, proposal }) => { fn(applied, effective, proposal); }],
|
|
30
|
+
beforeClose: (fn) => ['proposal:before-close', () => fn()],
|
|
31
|
+
closed: (fn) => ['proposal', ({ change }) => { if (change === 'closed') fn(); }],
|
|
32
|
+
bar: (fn) => ['proposal:bar', ({ open }) => { fn(open); }],
|
|
33
|
+
openSpecs: (fn) => ['work:open-specs', () => { fn(); return true; }],
|
|
34
|
+
reviewed: (fn) => ['decision', ({ open }) => { if (open !== false) fn(); }], // as before: not when another proposal was opened while it was sent
|
|
635
35
|
};
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
const opened = await openProposal(slug, source);
|
|
651
|
-
const to = opened ? $('proposal-title') : document.querySelector('#proposal-ways [data-way="retry"]');
|
|
652
|
-
if (!to) return;
|
|
653
|
-
if (opened) to.tabIndex = -1;
|
|
654
|
-
to.focus();
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/** Close, after a proposal failed to open: the bar goes, and the focus goes to the map, never the page */
|
|
658
|
-
function closeAfterFailure() {
|
|
659
|
-
closeProposal();
|
|
660
|
-
const map = $('graph-canvas');
|
|
661
|
-
if (map) map.focus();
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
/** A bad link's way on: the Work panel's Specs tab when there is one, else the header's Proposals menu */
|
|
665
|
-
function openSpecs() {
|
|
666
|
-
if (hooks.openSpecs) { hooks.openSpecs(); return; }
|
|
667
|
-
if (!menuOpen()) toggleMenu();
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function onKey(e) {
|
|
671
|
-
if (e.key === 'Escape' && menuOpen()) closeMenu();
|
|
672
|
-
onMoreKey(e);
|
|
36
|
+
const kept = {};
|
|
37
|
+
const stops = {};
|
|
38
|
+
export const hooks = {};
|
|
39
|
+
for (const name of Object.keys(ADAPT)) {
|
|
40
|
+
kept[name] = null;
|
|
41
|
+
Object.defineProperty(hooks, name, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: () => kept[name],
|
|
44
|
+
set(fn) {
|
|
45
|
+
if (stops[name]) { stops[name](); stops[name] = null; }
|
|
46
|
+
kept[name] = typeof fn === 'function' ? fn : null;
|
|
47
|
+
if (kept[name]) { const [event, listener] = ADAPT[name](kept[name]); stops[name] = pageInstance().on(event, listener); }
|
|
48
|
+
},
|
|
49
|
+
});
|
|
673
50
|
}
|
|
674
51
|
|
|
675
|
-
/**
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
52
|
+
/** What the server listed last, for the Work panel's Specs tab: the entries (null before the first answer), why the list could not be read, why the spec PRs are missing, and when */
|
|
53
|
+
export const proposalListing = () => E.proposalListing(pageInstance());
|
|
54
|
+
/** Calls `fn` each time the list is read again; returns the way to stop */
|
|
55
|
+
export const onProposalListing = (fn) => E.onProposalListing(pageInstance(), fn);
|
|
56
|
+
export const loadProposalList = () => E.loadProposalList(page());
|
|
57
|
+
export const openProposal = (slug, source = null) => E.openProposal(page(), slug, source);
|
|
58
|
+
export const showProposal = (proposal, opts) => E.showProposal(page(), proposal, opts);
|
|
59
|
+
export const rebuildProposalMap = (effective, opts) => E.rebuildProposalMap(page(), effective, opts);
|
|
60
|
+
export const closeProposal = () => E.closeProposal(page());
|
|
61
|
+
export const setProposalView = (view, opts) => E.setProposalView(page(), view, opts);
|
|
62
|
+
export const focusChange = (kind, key, opts) => E.focusChange(page(), kind, key, opts);
|
|
63
|
+
export const markedEdgeAt = (x, y, tolerance) => E.markedEdgeAt(page(), x, y, tolerance);
|
|
64
|
+
export const showEdgePanel = (edge) => E.showEdge(page(), edge);
|
|
65
|
+
export const renderBar = () => E.drawBar(page());
|
|
66
|
+
export const problemsHtml = problems;
|
|
67
|
+
export const proposalRowHtml = row;
|
|
683
68
|
|
|
684
69
|
/**
|
|
685
|
-
* Starts the overlay: the
|
|
686
|
-
* edge, and `/?proposal=<slug>` (and `&source=`, `&proposalView=`) when the address asks for one.
|
|
687
|
-
* Call once the map has loaded (the proposal is laid over it).
|
|
70
|
+
* Starts the overlay on the page: the pieces are mounted, and `/?proposal=<slug>` (and `&source=`, `&proposalView=`) opens one, as page.js does.
|
|
688
71
|
* @returns {Promise<boolean>} whether a proposal from the address opened (false when it asked for none)
|
|
689
72
|
*/
|
|
690
73
|
export async function initProposals() {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
// Once, however many times this runs
|
|
696
|
-
document.removeEventListener('click', onClick);
|
|
697
|
-
document.removeEventListener('keydown', onKey);
|
|
698
|
-
document.addEventListener('click', onClick);
|
|
699
|
-
document.addEventListener('keydown', onKey);
|
|
700
|
-
bindEdgePicking();
|
|
701
|
-
renderBar();
|
|
702
|
-
|
|
703
|
-
const asked = parseProposalQuery(location.search);
|
|
704
|
-
if (!asked) {
|
|
705
|
-
// 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
|
|
706
|
-
const bad = malformedLinkWords(location.search);
|
|
707
|
-
if (bad) setMessage(bad, true, [specsWay()]);
|
|
708
|
-
return false;
|
|
709
|
-
}
|
|
710
|
-
const ok = await openProposal(asked.slug, asked.source);
|
|
711
|
-
if (ok && asked.view) { setProposalView(asked.view, { quiet: true }); announce(`${reviewOpenedLine($('proposal-title').textContent)} ${viewWords(state.proposalView)}.`); }
|
|
712
|
-
return ok;
|
|
74
|
+
const inst = page();
|
|
75
|
+
keepAddress(inst);
|
|
76
|
+
E.drawBar(inst);
|
|
77
|
+
return openFromAddress(inst, typeof location === 'undefined' ? '' : location.search);
|
|
713
78
|
}
|
|
714
79
|
|
|
80
|
+
/** The bar piece the page mounted, or null */
|
|
81
|
+
export const proposalPiece = () => pagePiece('proposal');
|