cornfield 0.48.0 → 0.49.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/engine/checks.js +252 -0
- package/explorer/engine/connection.js +36 -0
- package/explorer/engine/layers.js +1 -0
- package/explorer/engine/player.js +489 -0
- package/explorer/engine/proposal.js +373 -0
- package/explorer/engine/render.js +1 -0
- package/explorer/engine/source.js +315 -0
- package/explorer/engine/theme-sheet.js +444 -0
- package/explorer/index.html +6 -59
- package/explorer/instance.js +82 -6
- 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 +502 -0
- package/explorer/pieces/decision.js +657 -0
- package/explorer/pieces/layers.js +4 -0
- package/explorer/pieces/map.js +113 -2
- package/explorer/pieces/node-panel.js +34 -1
- package/explorer/pieces/proposal.js +488 -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 +6 -5
- package/explorer/waiting-line.js +7 -50
- package/package.json +1 -1
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/proposal
|
|
3
|
+
*
|
|
4
|
+
* The proposal's bar as a piece (spec 0011 D3, D4: `corn-proposal`): the open proposal's title and the copy under review, the counts, Before / Diff /
|
|
5
|
+
* After, Whole map, the ⋯ menu with Close, the problems the proposal has, the one line that says why a proposal did not open, and the waiting line
|
|
6
|
+
* (a run waits on the proposal). And, where the host has a place for it, the Proposals menu that lists what the server finds.
|
|
7
|
+
*
|
|
8
|
+
* mount(root, inst, options) -> { update, destroy, ... }
|
|
9
|
+
*
|
|
10
|
+
* The piece makes its own markup (`markup()`: `bar` and `menu`) and puts it in `root`, or before the nodes `options.slots` names. Opening a proposal is
|
|
11
|
+
* the instance's (engine/proposal.js); this piece shows it, and its buttons ask the engine: Before, Diff, After, Whole map, Close, a row of the menu.
|
|
12
|
+
* It reads no address and writes none. What it tells and asks of its neighbours is listed at the top of engine/proposal.js.
|
|
13
|
+
*
|
|
14
|
+
* @param {ParentNode} root where the elements go when `options.slots` names no place
|
|
15
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst the instance; its map must be made (engine/render.js)
|
|
16
|
+
* @param {{ slots?: { bar?: Node, menu?: Node }, edit?: boolean }} [options] `edit: false` leaves out the what-if editor's two buttons (My edits, Edit):
|
|
17
|
+
* a host without the editor has nothing to put behind them
|
|
18
|
+
* @returns {{ update: (props?: { proposal?: string | object | null, source?: string | null, view?: string, slug?: string | null, sha256?: string | null }) => Promise<boolean> | void, destroy: () => void, elements: Element[], renderBar: Function, paintWaitingLine: Function, toggleMenu: Function, closeMenu: Function }}
|
|
19
|
+
* `update({ proposal })` opens a proposal: a slug (fetched through `inst.fetch`, with `source` to name the copy), or the proposal itself (nothing is fetched:
|
|
20
|
+
* `slug`, `source` and `sha256` name it); `null` closes it. `update({ view })` switches Before, Diff or After. `update()` draws the bar again.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
24
|
+
import { summarize } from '../../core/proposal.js';
|
|
25
|
+
import { PROPOSAL_VIEWS, chipText, barCounts, proposalPanelHtml, yoursText, sourceChip, pullNumberOf, malformedLinkWords } from '../proposal-model.js';
|
|
26
|
+
import { reviewWords } from '../review-model.js';
|
|
27
|
+
import { waitingLineWords } from '../waiting-model.js';
|
|
28
|
+
import { markStateAttr } from '../corn-state.js';
|
|
29
|
+
import { looksWith, mapStyleOf } from '../engine/map-style.js';
|
|
30
|
+
import { looksFor } from '../scene.js';
|
|
31
|
+
import { registerSheet, unregisterSheet, initSheets, collapseSheet } from '../engine/sheets.js';
|
|
32
|
+
import { setWholeMap } from '../engine/layers.js';
|
|
33
|
+
import { announce } from '../engine/keyboard.js';
|
|
34
|
+
import { t } from '../engine/strings.js';
|
|
35
|
+
import { credentialed } from '../engine/connection.js';
|
|
36
|
+
import { scopeOf, place, addParts } from '../engine/piece.js';
|
|
37
|
+
import {
|
|
38
|
+
openProposal, showProposal, closeProposal, setProposalView, drawBar, loadProposalList, proposalListing, setMessage, messageOf, bindEdgePicking, pinnedSource,
|
|
39
|
+
} from '../engine/proposal.js';
|
|
40
|
+
|
|
41
|
+
/** The markup of the piece: the bar (a sheet in the dock on a phone), and the Proposals menu the account menu holds. `bar` and `menu` are the two places */
|
|
42
|
+
export const markup = ({ edit = true } = {}) => ({
|
|
43
|
+
bar: '<section id="proposal-bar" class="hx-proposal-bar glass" aria-label="Open proposal" hidden data-corn="proposal-bar">'
|
|
44
|
+
+ '<p id="proposal-message" class="hx-proposal-message" data-corn="message" role="status" hidden></p>'
|
|
45
|
+
+ '<div id="proposal-ways" class="hx-proposal-ways" role="group" aria-label="Ways on" data-corn="proposal-ways" hidden></div>'
|
|
46
|
+
+ '<div id="proposal-body">'
|
|
47
|
+
+ '<div class="hx-proposal-head" data-corn="proposal-head" role="group" aria-label="Proposal actions">'
|
|
48
|
+
+ '<h2 id="proposal-title" class="hx-proposal-name" data-corn="proposal-title"></h2>'
|
|
49
|
+
+ '<a id="proposal-source" class="hx-proposal-source" data-corn="proposal-source" hidden></a>'
|
|
50
|
+
+ '<div class="hx-proposal-counts">'
|
|
51
|
+
+ '<div id="proposal-chip" class="hx-proposal-chip" data-corn="proposal-counts"></div>'
|
|
52
|
+
+ '<p id="proposal-peek" class="hx-proposal-peek"></p>'
|
|
53
|
+
+ '<button type="button" id="proposal-mode" class="hx-proposal-mode" data-corn="proposal-mode" data-action="toggle-proposal-mode" data-peek-ok aria-expanded="false" aria-controls="proposal-seg" title="Before, Diff or After"></button>'
|
|
54
|
+
+ '</div>'
|
|
55
|
+
+ '<div id="proposal-seg" class="hx-seg" data-corn="compare" role="group" aria-label="Compare">'
|
|
56
|
+
+ '<button data-corn="compare-option" type="button" class="hx-seg-btn" data-action="proposal-view" data-view="before" aria-pressed="false" data-corn-string="before">Before</button>'
|
|
57
|
+
+ '<button data-corn="compare-option" type="button" class="hx-seg-btn" data-action="proposal-view" data-view="diff" aria-pressed="true" data-corn-string="diff">Diff</button>'
|
|
58
|
+
+ '<button data-corn="compare-option" type="button" class="hx-seg-btn" data-action="proposal-view" data-view="after" aria-pressed="false" data-corn-string="after">After</button>'
|
|
59
|
+
+ '</div>'
|
|
60
|
+
+ '<div class="hx-proposal-tools">'
|
|
61
|
+
// The review narrows the map to the change; this puts the whole map back, as Diff always was (engine/layers.js setWholeMap). Off at every opening.
|
|
62
|
+
// Its words are "Whole map", which read right pressed or not; its name and tooltip are the full "Show the whole map". On a desk it sits beside
|
|
63
|
+
// the title, so the bar keeps its rows (css/proposal.css)
|
|
64
|
+
+ '<button data-corn="whole-map" data-corn-kind="secondary" type="button" id="proposal-whole" class="hx-btn" data-action="proposal-whole" aria-pressed="false" aria-label="Show the whole map" title="Show the whole map" data-peek-ok data-corn-string="wholeMap" data-corn-string-aria-label="showWholeMap">Whole map</button>'
|
|
65
|
+
// The what-if editor's two buttons (whatif.js): My edits is shown only while there are edits
|
|
66
|
+
+ (edit ? '<button data-corn-kind="secondary" type="button" id="proposal-myedits" class="hx-btn" aria-pressed="true" data-peek-ok data-corn-string="myEdits" hidden>My edits</button>'
|
|
67
|
+
+ '<button data-corn-kind="secondary" type="button" id="proposal-edit" class="hx-btn" aria-expanded="false" aria-controls="whatif" title="Try a change: add a node or an edge, reword a scenario">Edit</button>' : '')
|
|
68
|
+
+ '</div>'
|
|
69
|
+
+ '<div class="hx-proposal-more">'
|
|
70
|
+
+ '<button type="button" id="proposal-more" class="hx-btn hx-btn--icon" data-action="toggle-proposal-more" aria-haspopup="menu" aria-expanded="false" aria-controls="proposal-more-menu" aria-label="More" data-corn-kind="icon"><svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><circle cx="3" cy="8" r="1.5"/><circle cx="8" cy="8" r="1.5"/><circle cx="13" cy="8" r="1.5"/></svg></button>'
|
|
71
|
+
+ '<div id="proposal-more-menu" class="hx-proposal-more-menu glass" data-corn="proposal-menu" role="menu" aria-label="More" hidden>'
|
|
72
|
+
+ '<button type="button" role="menuitem" class="hx-btn hx-btn--quiet" data-action="close-proposal" title="Close the proposal and go back to the map" data-corn-kind="quiet" data-corn-string="closeProposal">Close</button>'
|
|
73
|
+
+ '</div>'
|
|
74
|
+
+ '</div>'
|
|
75
|
+
+ '</div>'
|
|
76
|
+
+ '<details id="proposal-errors" class="hx-proposal-errors" data-corn="proposal-errors" hidden>'
|
|
77
|
+
+ '<summary data-corn="summary" id="proposal-errors-count"></summary>'
|
|
78
|
+
+ '<ul id="proposal-errors-list"></ul>'
|
|
79
|
+
+ '<p class="hx-faint">The map shows what it can.</p>'
|
|
80
|
+
+ '</details>'
|
|
81
|
+
+ '</div>'
|
|
82
|
+
+ '</section>',
|
|
83
|
+
menu: '<div id="proposal-wrap">'
|
|
84
|
+
+ '<button type="button" id="proposal-btn" class="hx-account-item" data-action="toggle-proposals-menu" aria-haspopup="true" aria-expanded="false" title="Open a proposal: what a change would add, change and remove" data-corn="proposals-button"><span data-corn-string="proposals">Proposals</span><span class="hx-faint" aria-hidden="true">▾</span></button>'
|
|
85
|
+
+ '<div id="proposal-menu" class="hx-menu hx-menu--proposals" hidden data-corn="proposals-menu"></div>'
|
|
86
|
+
+ '</div>',
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/** The problems a proposal has, as the bar lists them (at most `max`, then "and N more") */
|
|
90
|
+
export function problemsHtml(errors, max = 8) {
|
|
91
|
+
const shown = errors.slice(0, max).map((e) => `<li>${e.path ? `<code class="hx-code">${escHtml(e.path)}</code> ` : ''}${escHtml(e.message)}</li>`);
|
|
92
|
+
if (errors.length > max) shown.push(`<li class="hx-faint">and ${errors.length - max} more</li>`);
|
|
93
|
+
return shown.join('');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
97
|
+
const safeHref = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
|
|
98
|
+
|
|
99
|
+
/** Where a proposal in the picker is: "Spec PR #23 (draft) by someone", "In the checkout", "In worktree x" */
|
|
100
|
+
function where(entry) {
|
|
101
|
+
if (entry.pull) return `Spec PR #${entry.pull.number}${entry.pull.draft ? ' (draft)' : ''}${entry.pull.author ? ` by ${entry.pull.author}` : ''}`;
|
|
102
|
+
return entry.source === 'checkout' ? 'In the checkout' : `In worktree ${entry.source}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** One row of the picker */
|
|
106
|
+
export function proposalRowHtml(entry, current) {
|
|
107
|
+
const mine = current && current.slug === entry.slug && current.source === entry.source;
|
|
108
|
+
const head = `<span class="hx-proposal-title">${escHtml(entry.title || entry.slug)}</span>`;
|
|
109
|
+
const meta = [`<span class="hx-proposal-where">${escHtml(where(entry))}</span>`];
|
|
110
|
+
if (entry.spec) meta.push(`<span>spec ${escHtml(entry.spec)}</span>`);
|
|
111
|
+
if (entry.error) {
|
|
112
|
+
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>`;
|
|
113
|
+
}
|
|
114
|
+
if (entry.counts) meta.push(`<span>${escHtml(chipText(entry.counts))}</span>`);
|
|
115
|
+
const reviewed = reviewWords(entry.review, Date.now()); // "Approved 3 minutes ago", from the listing
|
|
116
|
+
if (reviewed) meta.push(`<span class="hx-proposal-reviewed">${escHtml(reviewed)}</span>`);
|
|
117
|
+
if (entry.errors) meta.push(`<span class="hx-warn">${escHtml(plural(entry.errors, 'problem'))}</span>`);
|
|
118
|
+
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>`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Mounts the proposal's bar; see the top of this file */
|
|
122
|
+
export function mount(root, inst, options = {}) {
|
|
123
|
+
const { state } = inst;
|
|
124
|
+
const scope = scopeOf(inst);
|
|
125
|
+
const html = markup({ edit: options.edit !== false });
|
|
126
|
+
const made = [
|
|
127
|
+
...place(inst, root, html.bar, options.slots, 'bar'),
|
|
128
|
+
...place(inst, root, html.menu, options.slots, 'menu'),
|
|
129
|
+
];
|
|
130
|
+
/** An element of this piece by id (the piece's own, whatever else the root holds) */
|
|
131
|
+
const own = (id) => {
|
|
132
|
+
for (const el of made) {
|
|
133
|
+
if (el.id === id) return el;
|
|
134
|
+
const found = el.querySelector(`[id="${id}"]`);
|
|
135
|
+
if (found) return found;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
};
|
|
139
|
+
scope.keepParts(...made);
|
|
140
|
+
const bar = own('proposal-bar');
|
|
141
|
+
/** The waiting line and the problems list are made later: their hooks get their parts too */
|
|
142
|
+
let waitingEl = null;
|
|
143
|
+
let waitingSaid = null;
|
|
144
|
+
let gone = false;
|
|
145
|
+
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
// One line in the bar instead of a proposal
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
function paintMessage({ text, isError, ways }) {
|
|
150
|
+
bar.hidden = false;
|
|
151
|
+
bar.classList.toggle('is-error', isError);
|
|
152
|
+
own('proposal-body').hidden = true;
|
|
153
|
+
const msg = own('proposal-message');
|
|
154
|
+
msg.hidden = false;
|
|
155
|
+
msg.textContent = text;
|
|
156
|
+
const box = own('proposal-ways');
|
|
157
|
+
box.hidden = ways.length === 0;
|
|
158
|
+
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('');
|
|
159
|
+
addParts(box);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
// Which copy is open: the chip after the title
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
/** 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 */
|
|
166
|
+
const pullInfo = inst.slot('proposal-pulls', () => new Map());
|
|
167
|
+
let pullAskedFor = null;
|
|
168
|
+
|
|
169
|
+
function paintSource() {
|
|
170
|
+
const chip = own('proposal-source');
|
|
171
|
+
const source = state.proposal ? state.proposalSource : null;
|
|
172
|
+
chip.hidden = !source;
|
|
173
|
+
if (!source) return;
|
|
174
|
+
const n = pullNumberOf(source);
|
|
175
|
+
const known = n ? pullInfo.get(n) : null;
|
|
176
|
+
const listing = proposalListing(inst).entries;
|
|
177
|
+
const entry = n && Array.isArray(listing) ? listing.find((e) => e.slug === state.proposalSlug && e.source === source) : null;
|
|
178
|
+
const words = sourceChip(source, (known && known.pull) || (entry && entry.pull) || null, known ? known.checks : null);
|
|
179
|
+
chip.textContent = words.text;
|
|
180
|
+
if (words.state) chip.dataset.cornState = words.state; else delete chip.dataset.cornState;
|
|
181
|
+
const href = safeHref(words.href);
|
|
182
|
+
if (href) { chip.setAttribute('href', href); chip.setAttribute('target', '_blank'); chip.setAttribute('rel', 'noreferrer'); chip.title = 'Open this pull request'; } else {
|
|
183
|
+
chip.removeAttribute('href'); chip.removeAttribute('target'); chip.removeAttribute('rel'); chip.title = words.label;
|
|
184
|
+
}
|
|
185
|
+
const key = `${source}/${state.proposalSlug}`;
|
|
186
|
+
if (n && pullAskedFor !== key) { pullAskedFor = key; loadPullInfo(n); }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 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 */
|
|
190
|
+
async function loadPullInfo(n) {
|
|
191
|
+
try {
|
|
192
|
+
const res = await credentialed(inst)(`/api/forge/pulls/${n}`);
|
|
193
|
+
const body = res.ok ? await res.json() : null;
|
|
194
|
+
if (gone) return;
|
|
195
|
+
if (body && body.ok !== false && body.pull) pullInfo.set(n, { pull: body.pull, checks: Array.isArray(body.checks) ? body.checks : null });
|
|
196
|
+
if (body && body.pull && pullNumberOf(state.proposalSource) === n) inst.emit('proposal:pull-head', body.pull.head && typeof body.pull.head.sha === 'string' ? body.pull.head.sha : ''); // what was seen is kept per PR head
|
|
197
|
+
} catch { /* no forge, or not signed in: the chip keeps what it has */ }
|
|
198
|
+
if (!gone && state.proposal && pullNumberOf(state.proposalSource) === n) paintSource();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// The bar: title, counts chip, Before / Diff / After, problems, Close
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
function renderBar({ open = !!state.proposal } = {}) {
|
|
205
|
+
bar.hidden = !open;
|
|
206
|
+
if (!open) { closeMore(); toggleMode(false); collapseSheet(inst, 'proposal'); return; }
|
|
207
|
+
|
|
208
|
+
bar.classList.remove('is-error');
|
|
209
|
+
own('proposal-message').hidden = true;
|
|
210
|
+
own('proposal-body').hidden = false;
|
|
211
|
+
const p = state.proposal;
|
|
212
|
+
const title = own('proposal-title');
|
|
213
|
+
title.textContent = (p && typeof p.title === 'string' && p.title) || state.proposalSlug || 'Proposal';
|
|
214
|
+
paintSource();
|
|
215
|
+
const summary = (p && typeof p.summary === 'string' && p.summary) || '';
|
|
216
|
+
title.title = summary; // the bar stays one row: the summary is also the title's tooltip, and leads the review column
|
|
217
|
+
|
|
218
|
+
const chip = own('proposal-chip');
|
|
219
|
+
// The counts name their lists: the changes part shows the Changes section, "5 scenarios" the Scenarios section (the review column, pieces/changes.js)
|
|
220
|
+
const parts = barCounts(summarize(p));
|
|
221
|
+
chip.innerHTML = parts.map((c) => {
|
|
222
|
+
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>` : '';
|
|
223
|
+
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>`;
|
|
224
|
+
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>`;
|
|
225
|
+
}).join('<span class="hx-proposal-sep" aria-hidden="true"> · </span>');
|
|
226
|
+
// The reviewer's own edits are a part of their own, never added to the proposal's numbers (spec 0007 D5)
|
|
227
|
+
const yours = yoursText(state.whatIf && state.whatIf.edits, !!state.whatIfOff);
|
|
228
|
+
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>`);
|
|
229
|
+
addParts(chip);
|
|
230
|
+
own('proposal-mode').textContent = t(inst, state.proposalView);
|
|
231
|
+
|
|
232
|
+
for (const btn of bar.querySelectorAll('[data-action="proposal-view"]')) {
|
|
233
|
+
const on = btn.dataset.view === state.proposalView;
|
|
234
|
+
btn.setAttribute('aria-pressed', String(on));
|
|
235
|
+
btn.classList.toggle('is-on', on);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const whole = own('proposal-whole'); // the switch is the review's: off at every opening, kept across Before, Diff and After
|
|
239
|
+
const on = !!(state.review && state.review.whole);
|
|
240
|
+
whole.setAttribute('aria-pressed', String(on));
|
|
241
|
+
whole.title = t(inst, 'showWholeMap'); // the words are short ("Whole map"); the tooltip says it in full, as its name does
|
|
242
|
+
whole.classList.toggle('hx-btn--active', on);
|
|
243
|
+
|
|
244
|
+
const errors = state.proposalErrors || [];
|
|
245
|
+
const box = own('proposal-errors');
|
|
246
|
+
box.hidden = errors.length === 0;
|
|
247
|
+
if (errors.length) {
|
|
248
|
+
own('proposal-errors-count').textContent = `${plural(errors.length, 'problem')} in this proposal`;
|
|
249
|
+
own('proposal-errors-list').innerHTML = problemsHtml(errors);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
// The waiting line: a run waits on the open proposal (spec 0010 D2)
|
|
255
|
+
// ---------------------------------------------------------------------------
|
|
256
|
+
/** The line is its own element, added after the bar's head once, so the bar's own markup is not touched; the runner's words are set as text, never as HTML */
|
|
257
|
+
function waitingLine() {
|
|
258
|
+
const body = own('proposal-body');
|
|
259
|
+
if (waitingEl && waitingEl.isConnected) return waitingEl;
|
|
260
|
+
waitingEl = inst.doc.createElement('p');
|
|
261
|
+
waitingEl.className = 'hx-waiting-line';
|
|
262
|
+
waitingEl.dataset.corn = 'waiting-line';
|
|
263
|
+
waitingEl.setAttribute('part', 'waiting-line');
|
|
264
|
+
waitingEl.dataset.cornState = 'waiting';
|
|
265
|
+
waitingEl.hidden = true;
|
|
266
|
+
waitingEl.innerHTML = '<span data-waiting-words></span> <button type="button" class="hx-btn hx-forge-act" data-waiting-answer data-peek-ok data-corn-kind="secondary"></button>';
|
|
267
|
+
const head = body.querySelector('.hx-proposal-head');
|
|
268
|
+
if (head) head.after(waitingEl); else body.append(waitingEl);
|
|
269
|
+
return waitingEl;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Shows the line for `run` (the run waiting on the open proposal), or hides it for null. The first time a run is shown for a proposal it is said
|
|
274
|
+
* through the live region once; a repaint of the same run says nothing.
|
|
275
|
+
*/
|
|
276
|
+
function paintWaitingLine(run, key) {
|
|
277
|
+
const el = waitingLine();
|
|
278
|
+
el.hidden = !run;
|
|
279
|
+
if (!run) { waitingSaid = null; return; }
|
|
280
|
+
const words = waitingLineWords(run);
|
|
281
|
+
el.querySelector('[data-waiting-words]').textContent = words;
|
|
282
|
+
const button = el.querySelector('[data-waiting-answer]');
|
|
283
|
+
button.textContent = t(inst, 'answer');
|
|
284
|
+
button.dataset.waitingAnswer = run.runId;
|
|
285
|
+
button.setAttribute('aria-label', `${t(inst, 'answer')}: ${words}`);
|
|
286
|
+
const said = `${key}|${run.runId}`;
|
|
287
|
+
if (waitingSaid !== said) { waitingSaid = said; announce(inst, words); }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ---------------------------------------------------------------------------
|
|
291
|
+
// The ⋯ menu (a menu button) and the phone's Before / Diff / After switcher
|
|
292
|
+
// ---------------------------------------------------------------------------
|
|
293
|
+
const moreItems = () => [...bar.querySelectorAll('#proposal-more-menu [role="menuitem"]')];
|
|
294
|
+
const moreOpen = () => { const menu = own('proposal-more-menu'); return !!menu && !menu.hidden; };
|
|
295
|
+
|
|
296
|
+
/** Closes the ⋯ menu; `refocus` puts focus back on its button (Escape, or a choice made) */
|
|
297
|
+
function closeMore(refocus = false) {
|
|
298
|
+
own('proposal-more-menu').hidden = true;
|
|
299
|
+
const btn = own('proposal-more');
|
|
300
|
+
btn.setAttribute('aria-expanded', 'false');
|
|
301
|
+
if (refocus) btn.focus();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function openMore(which = 'first') {
|
|
305
|
+
own('proposal-more-menu').hidden = false;
|
|
306
|
+
own('proposal-more').setAttribute('aria-expanded', 'true');
|
|
307
|
+
const items = moreItems();
|
|
308
|
+
(which === 'last' ? items[items.length - 1] : items[0])?.focus();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** On a phone the mode button shows the compare switcher under the counts; from 768px the switcher is always there */
|
|
312
|
+
function toggleMode(force) {
|
|
313
|
+
const on = typeof force === 'boolean' ? force : bar.dataset.modeOpen !== 'true';
|
|
314
|
+
bar.dataset.modeOpen = String(on);
|
|
315
|
+
own('proposal-mode').setAttribute('aria-expanded', String(on));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function onMoreKey(e) {
|
|
319
|
+
const btn = own('proposal-more');
|
|
320
|
+
if (e.target === btn && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) { e.preventDefault(); openMore(e.key === 'ArrowUp' ? 'last' : 'first'); return; }
|
|
321
|
+
if (!moreOpen()) return;
|
|
322
|
+
if (e.key === 'Escape') { e.preventDefault(); closeMore(true); return; }
|
|
323
|
+
if (e.key === 'Tab') { closeMore(); return; }
|
|
324
|
+
const items = moreItems();
|
|
325
|
+
const at = items.indexOf(inst.active());
|
|
326
|
+
if (at < 0) return;
|
|
327
|
+
const next = { ArrowDown: (at + 1) % items.length, ArrowUp: (at - 1 + items.length) % items.length, Home: 0, End: items.length - 1 }[e.key];
|
|
328
|
+
if (next === undefined) return;
|
|
329
|
+
e.preventDefault();
|
|
330
|
+
items[next].focus();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ---------------------------------------------------------------------------
|
|
334
|
+
// The picker
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
const menuOpen = () => { const menu = own('proposal-menu'); return !!menu && !menu.hidden; };
|
|
337
|
+
|
|
338
|
+
function closeMenu() {
|
|
339
|
+
own('proposal-menu').hidden = true;
|
|
340
|
+
own('proposal-btn').setAttribute('aria-expanded', 'false');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async function toggleMenu() {
|
|
344
|
+
const menu = own('proposal-menu');
|
|
345
|
+
if (menuOpen()) return closeMenu();
|
|
346
|
+
menu.hidden = false;
|
|
347
|
+
own('proposal-btn').setAttribute('aria-expanded', 'true');
|
|
348
|
+
if (!proposalListing(inst).entries) renderMenu(true);
|
|
349
|
+
await loadProposalList(inst); // always ask again: worktrees come and go
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function renderMenu(loading = false) {
|
|
353
|
+
const menu = own('proposal-menu');
|
|
354
|
+
const { entries: listing, problem: listingProblem, forgeProblem } = proposalListing(inst);
|
|
355
|
+
const current = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
|
|
356
|
+
let body;
|
|
357
|
+
if (loading && !listing) body = '<p class="hx-faint hx-proposal-empty">Looking for proposals …</p>';
|
|
358
|
+
else if (listingProblem) body = `<p class="hx-error-text hx-proposal-empty">The list could not be loaded: ${escHtml(listingProblem)}</p>`;
|
|
359
|
+
else if (!listing || listing.length === 0) body = '<p class="hx-faint hx-proposal-empty">No proposals</p>';
|
|
360
|
+
else body = `<div class="hx-proposal-list" role="list">${listing.map((e) => `<div role="listitem">${proposalRowHtml(e, current)}</div>`).join('')}</div>`;
|
|
361
|
+
const forge = forgeProblem && !listingProblem ? `<p class="hx-error-text hx-proposal-empty">The spec PRs could not be listed: ${escHtml(forgeProblem)}</p>` : '';
|
|
362
|
+
menu.innerHTML = `<div class="hx-menu-title hx-menu-head" data-corn="menu-title"><span>${escHtml(t(inst, 'proposals'))}</span></div>${forge}${body}`;
|
|
363
|
+
addParts(menu);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// ---------------------------------------------------------------------------
|
|
367
|
+
// What the buttons do
|
|
368
|
+
// ---------------------------------------------------------------------------
|
|
369
|
+
/** Retry, after a proposal failed to open: the bar is drawn anew either way, so the focus goes somewhere stated, the proposal's name once it opened or the new Retry if it failed again */
|
|
370
|
+
async function retryOpen(slug, source) {
|
|
371
|
+
const opened = await openProposal(inst, slug, source);
|
|
372
|
+
if (gone) return;
|
|
373
|
+
const to = opened ? own('proposal-title') : bar.querySelector('#proposal-ways [data-way="retry"]');
|
|
374
|
+
if (!to) return;
|
|
375
|
+
if (opened) to.tabIndex = -1;
|
|
376
|
+
to.focus();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Close, after a proposal failed to open: the bar goes, and the focus goes to the map, never the page */
|
|
380
|
+
function closeAfterFailure() {
|
|
381
|
+
closeProposal(inst);
|
|
382
|
+
if (state.canvas) state.canvas.focus();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** A bad link's way on: the Work panel's Specs tab when there is one, else the header's Proposals menu */
|
|
386
|
+
function openSpecs() {
|
|
387
|
+
if (inst.ask('work:open-specs') === true) return;
|
|
388
|
+
if (!menuOpen()) toggleMenu();
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const ACTIONS = {
|
|
392
|
+
'toggle-proposals-menu': () => toggleMenu(),
|
|
393
|
+
'open-proposal': (el) => openProposal(inst, el.dataset.slug, el.dataset.source || null),
|
|
394
|
+
'close-proposal': () => closeProposal(inst),
|
|
395
|
+
'proposal-whole': () => { setWholeMap(inst, !(state.review && state.review.whole)); drawBar(inst); }, // "Show the whole map": announced by engine/layers.js, the focus stays on the switch
|
|
396
|
+
'proposal-view': (el) => { setProposalView(inst, el.dataset.view); toggleMode(false); },
|
|
397
|
+
'toggle-proposal-mode': () => toggleMode(),
|
|
398
|
+
'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
|
|
399
|
+
'review-show-changes': () => inst.emit('changes:show', 'changes'),
|
|
400
|
+
'review-show-scenarios': () => inst.emit('changes:show', 'scenarios'),
|
|
401
|
+
'proposal-way': (el) => (el.dataset.way === 'open' ? openProposal(inst, 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()),
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// The root hears every control: the bar's, the menu's and a row of the Work panel's Specs list (`open-proposal`), as the document did
|
|
405
|
+
scope.listen(inst.root, 'click', (e) => {
|
|
406
|
+
const target = e.target.closest ? e.target.closest('[data-action]') : null;
|
|
407
|
+
const action = target && Object.hasOwn(ACTIONS, target.dataset.action) && ACTIONS[target.dataset.action];
|
|
408
|
+
if (action) action(target);
|
|
409
|
+
// A choice in the ⋯ menu closes it back onto its button (Close may stop at the what-if confirm); a click anywhere else just closes it
|
|
410
|
+
if (moreOpen() && !(target && target.dataset.action === 'toggle-proposal-more')) closeMore(!!(target && target.closest('#proposal-more-menu')));
|
|
411
|
+
// Any click outside the picker closes it
|
|
412
|
+
const wrap = own('proposal-wrap');
|
|
413
|
+
if (menuOpen() && wrap && !wrap.contains(e.target) && !(target && target.dataset.action === 'proposal-way')) closeMenu(); // (a bad link's Specs list opens it from outside)
|
|
414
|
+
});
|
|
415
|
+
scope.listen(inst.root, 'keydown', (e) => {
|
|
416
|
+
if (e.key === 'Escape' && menuOpen()) closeMenu();
|
|
417
|
+
onMoreKey(e);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
// ---------------------------------------------------------------------------
|
|
421
|
+
// The marks' colours for the legend and the panel (the --hx-mark-* variables), the same the map draws on this ground
|
|
422
|
+
// ---------------------------------------------------------------------------
|
|
423
|
+
function setMarkColours() {
|
|
424
|
+
const el = inst.tokenElement();
|
|
425
|
+
if (!el || !el.style) return;
|
|
426
|
+
const { mark: looks } = looksWith(looksFor(state.theme), mapStyleOf(inst).get()); // the theme's --corn-map-added|changed|removed|edit, when it sets them
|
|
427
|
+
for (const mark of Object.keys(looks)) el.style.setProperty(`--hx-mark-${mark}`, looks[mark].color);
|
|
428
|
+
}
|
|
429
|
+
setMarkColours();
|
|
430
|
+
scope.on('theme', setMarkColours);
|
|
431
|
+
scope.own(mapStyleOf(inst).onChange(() => setMarkColours())); // a theme stylesheet that finishes loading later
|
|
432
|
+
|
|
433
|
+
// ---------------------------------------------------------------------------
|
|
434
|
+
// Following the instance
|
|
435
|
+
// ---------------------------------------------------------------------------
|
|
436
|
+
scope.on('proposal:draw', ({ open }) => renderBar({ open }));
|
|
437
|
+
scope.on('changes:peek', (text) => { own('proposal-peek').textContent = text; }); // the review column's count line, for the phone's peek
|
|
438
|
+
scope.on('proposal:focus-title', () => { const title = own('proposal-title'); title.tabIndex = -1; title.focus(); }); // the decision hands the focus to the proposal's name
|
|
439
|
+
scope.on('proposal:message', (m) => paintMessage(m));
|
|
440
|
+
scope.on('proposal:listing', () => { renderMenu(); if (state.proposal) paintSource(); });
|
|
441
|
+
scope.on('proposal:waiting', ({ run, key }) => paintWaitingLine(run, key));
|
|
442
|
+
scope.on('proposal:waiting-reset', () => { waitingSaid = null; waitingEl = null; });
|
|
443
|
+
scope.on('proposal', ({ change }) => { if (change === 'opened') closeMenu(); });
|
|
444
|
+
scope.own(bindEdgePicking(inst, (target, type, fn) => scope.listen(target, type, fn)));
|
|
445
|
+
|
|
446
|
+
initSheets(inst);
|
|
447
|
+
registerSheet(inst, 'proposal', bar, { stub: () => ({ title: (own('proposal-title') && own('proposal-title').textContent) || 'Proposal' }) });
|
|
448
|
+
scope.own(() => unregisterSheet(inst, 'proposal'));
|
|
449
|
+
|
|
450
|
+
scope.own(() => {
|
|
451
|
+
gone = true;
|
|
452
|
+
made.forEach((el) => el.remove());
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
renderBar();
|
|
456
|
+
const said = messageOf(inst);
|
|
457
|
+
if (said && !state.proposal) paintMessage(said);
|
|
458
|
+
|
|
459
|
+
return {
|
|
460
|
+
elements: made,
|
|
461
|
+
renderBar: () => drawBar(inst),
|
|
462
|
+
paintWaitingLine,
|
|
463
|
+
toggleMenu,
|
|
464
|
+
closeMenu,
|
|
465
|
+
setMessage: (text, isError, ways) => setMessage(inst, text, isError, ways),
|
|
466
|
+
/** A link whose `proposal` is not a proposal's name: said plainly, with the Specs list (the page calls this for `?proposal=` it cannot read) */
|
|
467
|
+
sayBadLink: (search) => { const bad = malformedLinkWords(search); if (bad) setMessage(inst, bad, true, [{ label: t(inst, 'openSpecsList'), way: 'specs' }]); return !!bad; },
|
|
468
|
+
update(props) {
|
|
469
|
+
if (!props || !('proposal' in props || 'view' in props)) { drawBar(inst); return undefined; }
|
|
470
|
+
let result;
|
|
471
|
+
if ('proposal' in props) {
|
|
472
|
+
const p = props.proposal;
|
|
473
|
+
if (p === null) closeProposal(inst);
|
|
474
|
+
else if (typeof p === 'string') {
|
|
475
|
+
const same = state.proposal && state.proposalSlug === p && (props.source || null) === (state.proposalSource || null) && !!state.proposal;
|
|
476
|
+
result = same ? Promise.resolve(true) : openProposal(inst, p, props.source || null);
|
|
477
|
+
} else if (p && typeof p === 'object') {
|
|
478
|
+
showProposal(inst, p, { slug: props.slug || null, source: props.source || null, pinSource: !!props.source, view: PROPOSAL_VIEWS.includes(props.view) ? props.view : 'diff', sha256: props.sha256 || null });
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if ('view' in props && PROPOSAL_VIEWS.includes(props.view) && !(typeof props.proposal === 'string' && result)) setProposalView(inst, props.view, { quiet: true });
|
|
482
|
+
else if ('view' in props && result) result = result.then((ok) => { if (ok && PROPOSAL_VIEWS.includes(props.view)) setProposalView(inst, props.view, { quiet: true }); return ok; });
|
|
483
|
+
return result;
|
|
484
|
+
},
|
|
485
|
+
pinnedSource: () => pinnedSource(inst),
|
|
486
|
+
destroy: () => scope.destroy(),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/scope-link
|
|
3
|
+
*
|
|
4
|
+
* The part of the scope protocol (pieces/scope.js) a piece needs, and nothing of the scope itself: how a piece asks for the scope around it
|
|
5
|
+
* (`joinScope`), the two event names, and what a scope's instance tells its pieces (`scopeInfo`). A map that never meets a scope or a `src` loads
|
|
6
|
+
* only this; the loading, the states, the server's theme (pieces/scope.js, engine/source.js, pieces/status.js, engine/theme-sheet.js) come with
|
|
7
|
+
* `<corn-scope>`, or the first time a map has a `src` (pieces/map.js imports them then, as a chunk of the package's own).
|
|
8
|
+
*
|
|
9
|
+
* const join = joinScope(el, onChange) -> { inst, scope, leave } (a piece's shell calls it for the scope around it, if any)
|
|
10
|
+
* scopeInfo(inst) -> { theme, serverTheme, host, source, mountStatus } for a scope's instance, else null
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const REQUEST = 'corn-scope-request';
|
|
14
|
+
export const CHANGED = 'corn-scope-changed';
|
|
15
|
+
|
|
16
|
+
/** What a piece may ask a scope for, per instance: set when a scope makes the instance */
|
|
17
|
+
export const infoOf = (inst) => inst.slot('scope', () => ({ theme: 'auto', serverTheme: null, host: null, source: null, mountStatus: null }));
|
|
18
|
+
/**
|
|
19
|
+
* The scope's side of an instance, or null for a private one: its `theme`, its server theme (to adopt into a root), its element, its source (the
|
|
20
|
+
* load: engine/source.js) and how a piece shows the load's states (pieces/status.js `mount`)
|
|
21
|
+
*/
|
|
22
|
+
export const scopeInfo = (inst) => {
|
|
23
|
+
const info = infoOf(inst);
|
|
24
|
+
return info.host ? info : null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A piece's side: asks for the scope around `el`. `onChange` runs when the answer may be different (a new instance, a scope gone or come): the
|
|
29
|
+
* shell leaves, ends its piece and joins again. `inst` is null when no scope answered (the piece makes a private instance); `leave` is idempotent.
|
|
30
|
+
* @param {Element} el
|
|
31
|
+
* @param {() => void} onChange
|
|
32
|
+
* @returns {{ inst: ReturnType<typeof import('../instance.js').createInstance> | null, scope: object | null, leave: () => void }}
|
|
33
|
+
*/
|
|
34
|
+
export function joinScope(el, onChange) {
|
|
35
|
+
let handle = null;
|
|
36
|
+
el.dispatchEvent(new CustomEvent(REQUEST, { bubbles: true, composed: true, detail: { el, claim: (h) => { handle = h; } } }));
|
|
37
|
+
const changed = () => onChange();
|
|
38
|
+
el.addEventListener(CHANGED, changed);
|
|
39
|
+
let left = false;
|
|
40
|
+
return {
|
|
41
|
+
inst: handle ? handle.inst : null,
|
|
42
|
+
scope: handle ? handle.scope : null,
|
|
43
|
+
leave() {
|
|
44
|
+
if (left) return;
|
|
45
|
+
left = true;
|
|
46
|
+
el.removeEventListener(CHANGED, changed);
|
|
47
|
+
if (handle) handle.release();
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|