@popcorn245/cornfield 0.52.0 → 0.53.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 +2 -0
- package/explorer/css/node-panel.css +3 -1
- package/explorer/decision-model.js +2 -0
- package/explorer/engine/map-rect.js +8 -6
- package/explorer/engine/map-style.js +12 -6
- package/explorer/engine/player.js +17 -11
- package/explorer/engine/sheets.js +8 -0
- package/explorer/glyphs.js +14 -6
- package/explorer/instance.js +9 -1
- package/explorer/pieces/around.js +33 -4
- package/explorer/pieces/changes.js +32 -26
- package/explorer/pieces/decision.js +15 -8
- package/explorer/pieces/layers.js +4 -3
- package/explorer/pieces/map.js +6 -1
- package/explorer/pieces/proposal.js +41 -14
- package/explorer/pieces/scope-link.js +2 -2
- package/explorer/pieces/scope-proposal.js +158 -0
- package/explorer/pieces/scope.js +64 -1
- package/explorer/renderer-canvas2d.js +46 -12
- package/explorer/renderer-webgl.js +3 -1
- package/explorer/shaders.js +17 -6
- package/package.json +1 -1
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
*
|
|
43
43
|
* @param {ParentNode} root where the foot goes when `options.slots` names no place
|
|
44
44
|
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst the instance
|
|
45
|
-
* @param {{ slots?: { foot?: Node }, now?: () => number }} [options] `now`: the clock the times shown are read from (a test winds it)
|
|
45
|
+
* @param {{ slots?: { foot?: Node }, now?: () => number, unnamed?: string, inline?: boolean }} [options] `now`: the clock the times shown are read from (a test winds it).
|
|
46
|
+
* `inline` is the piece in a box and a root of its own (`<corn-decision>`, pieces/around.js): no phone sheet to open for the note, and the Escape that takes a
|
|
47
|
+
* question back or ends a hold is heard in this root, where the focus is
|
|
46
48
|
* @returns {{ update: (props?: object) => void, destroy: () => void, sendReview: Function, loadFacts: Function, elements: Element[] }}
|
|
47
49
|
* `update()` reads the proposal that is open again (the host changed it); nothing else is taken
|
|
48
50
|
*/
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
import { expandSheet, isPhone } from '../engine/sheets.js';
|
|
51
53
|
import { reviewParts, sendBackProblem, reviewBody, editsHint, isReviewable } from '../review-model.js';
|
|
52
54
|
import {
|
|
53
|
-
HOLD_MS, decide, askReasons, askWords, newReasons, sendBackLine, sendBackDecision, refusalWords, holdWords, holdStartWords, holdCancelledWords, editsSentWords,
|
|
55
|
+
HOLD_MS, NAMELESS_PROPOSAL, decide, askReasons, askWords, newReasons, sendBackLine, sendBackDecision, refusalWords, holdWords, holdStartWords, holdCancelledWords, editsSentWords,
|
|
54
56
|
} from '../decision-model.js';
|
|
55
57
|
import { pullNumberOf } from '../proposal-model.js';
|
|
56
58
|
import { announce } from '../engine/keyboard.js';
|
|
@@ -101,8 +103,12 @@ export function mount(root, inst, options = {}) {
|
|
|
101
103
|
const { state } = inst;
|
|
102
104
|
const scope = scopeOf(inst);
|
|
103
105
|
const now = typeof options.now === 'function' ? options.now : () => Date.now();
|
|
106
|
+
const inline = !!options.inline;
|
|
107
|
+
const phone = () => !inline && isPhone(inst);
|
|
108
|
+
/** What hears the Escape and the held key's repeats: the instance's root, or the box's own root */
|
|
109
|
+
const hear = inline ? root : inst.root;
|
|
104
110
|
/** What the foot says in place of its buttons for a proposal with no name, which nothing can be decided on (the review piece's, with no server); none: the page's */
|
|
105
|
-
const unnamed = typeof options.unnamed === 'string' && options.unnamed ? options.unnamed : '';
|
|
111
|
+
const unnamed = typeof options.unnamed === 'string' && options.unnamed ? options.unnamed : inline ? NAMELESS_PROPOSAL : '';
|
|
106
112
|
const get = credentialed(inst);
|
|
107
113
|
const made = place(inst, root, markup().foot, options.slots, 'foot');
|
|
108
114
|
scope.keepParts(...made);
|
|
@@ -260,11 +266,11 @@ export function mount(root, inst, options = {}) {
|
|
|
260
266
|
ui.noting = true;
|
|
261
267
|
ui.message = '';
|
|
262
268
|
paint();
|
|
263
|
-
if (
|
|
269
|
+
if (phone()) expandSheet(inst, 'proposal');
|
|
264
270
|
q('#review-note').focus();
|
|
265
271
|
// On a phone the keyboard is about to take half the screen: the note and the button that sends it stay in view above it
|
|
266
272
|
const send = button('notes');
|
|
267
|
-
if (
|
|
273
|
+
if (phone() && send && typeof send.scrollIntoView === 'function') send.scrollIntoView({ block: 'nearest' });
|
|
268
274
|
}
|
|
269
275
|
|
|
270
276
|
/** Cancel: the field closes, what was typed goes, and focus goes back to Send back */
|
|
@@ -283,6 +289,7 @@ export function mount(root, inst, options = {}) {
|
|
|
283
289
|
function onBar({ open }) {
|
|
284
290
|
const key = open ? keyOf() : null;
|
|
285
291
|
rootEl.hidden = !(key || (open && unnamed));
|
|
292
|
+
if (inline) foot.hidden = !open; // in a box of its own there is no column to hide with no proposal open: the foot is the box
|
|
286
293
|
if (key === ui.key) { paint(); return; }
|
|
287
294
|
if (ui.hold) stopHold(open ? 'other' : 'closed', { quiet: false });
|
|
288
295
|
ui.key = key;
|
|
@@ -421,7 +428,7 @@ export function mount(root, inst, options = {}) {
|
|
|
421
428
|
ui.message = problem;
|
|
422
429
|
ui.noting = true; // the refusal is about the note: show it
|
|
423
430
|
paint();
|
|
424
|
-
if (
|
|
431
|
+
if (phone()) expandSheet(inst, 'proposal');
|
|
425
432
|
q('#review-note').focus();
|
|
426
433
|
return;
|
|
427
434
|
}
|
|
@@ -544,7 +551,7 @@ export function mount(root, inst, options = {}) {
|
|
|
544
551
|
ui.message = problem;
|
|
545
552
|
ui.noting = true; // the refusal is about the note: show it
|
|
546
553
|
paint();
|
|
547
|
-
if (
|
|
554
|
+
if (phone()) expandSheet(inst, 'proposal');
|
|
548
555
|
noteEl.focus();
|
|
549
556
|
return false;
|
|
550
557
|
}
|
|
@@ -624,7 +631,7 @@ export function mount(root, inst, options = {}) {
|
|
|
624
631
|
});
|
|
625
632
|
scope.listen(rootEl, 'keydown', (e) => { if (e.key === 'Escape' && ui.noting && !ui.asking && !ui.hold) { e.stopPropagation(); closeNote(); } });
|
|
626
633
|
// Escape takes an open question back, or ends a hold, before anything else on the page hears it; a held key's repeats do nothing here
|
|
627
|
-
scope.listen(
|
|
634
|
+
scope.listen(hear, 'keydown', (e) => {
|
|
628
635
|
// A key held down repeats: its repeats are not more decisions (Enter held on Approve would answer its own question, then undo the hold)
|
|
629
636
|
if (e.repeat && (e.key === 'Enter' || e.key === ' ') && e.target && e.target.closest && e.target.closest('#review-decision [data-review], #review-decision [data-review-undo]')) { e.preventDefault(); e.stopPropagation(); return; }
|
|
630
637
|
if (e.key !== 'Escape' || !ui.key) return;
|
|
@@ -28,7 +28,7 @@ import { kindLetters } from '../../core/layers.js';
|
|
|
28
28
|
import { reviewHides, rowKeyOf, shownByProposal } from '../layer-model.js';
|
|
29
29
|
import { layerShows } from '../scene.js';
|
|
30
30
|
import { STROKE_TOKEN, kindToken, mapStyleOf } from '../engine/map-style.js';
|
|
31
|
-
import { over, parseColor, contrast } from '../../core/color.js';
|
|
31
|
+
import { over, parseColor, contrast, toHex } from '../../core/color.js';
|
|
32
32
|
import { DARK_GROUND, LIGHT_GROUND } from '../theme-model.js';
|
|
33
33
|
import { t } from '../engine/strings.js';
|
|
34
34
|
import { renderFlowLegend } from '../engine/flow-legend.js';
|
|
@@ -128,9 +128,9 @@ export function mount(root, inst, options = {}) {
|
|
|
128
128
|
const [r, g, b] = over(surface, over(ground, [0, 0, 0, 1]));
|
|
129
129
|
return `rgb(${r}, ${g}, ${b})`;
|
|
130
130
|
}
|
|
131
|
-
/** The outline a dot or swatch gets when its fill is under 3:1 on the menu: the map's own outline colour when the theme sets one, else the CSS default (`.is-ringed`). The fill is never changed */
|
|
131
|
+
/** The outline a dot or swatch gets when its fill (as it shows over the menu) is under 3:1 on the menu: the map's own outline colour when the theme sets one, else the CSS default (`.is-ringed`). The fill is never changed */
|
|
132
132
|
function ringOf(color, surface) {
|
|
133
|
-
if (contrast(color, surface) >= 3) return null;
|
|
133
|
+
if (contrast(toHex(over(parseColor(color), parseColor(surface))), surface) >= 3) return null; // a translucent fill is seen over the menu, as the node is over the ground
|
|
134
134
|
const stroke = style().values[STROKE_TOKEN];
|
|
135
135
|
return { stroke: stroke ? swatch(stroke) : '' };
|
|
136
136
|
}
|
|
@@ -312,6 +312,7 @@ export function mount(root, inst, options = {}) {
|
|
|
312
312
|
|
|
313
313
|
// -- following the instance ------------------------------------------------------------------------------------------------------
|
|
314
314
|
scope.on('layers:present', () => true); // the map's keys know there is a menu to turn a layer on in
|
|
315
|
+
scope.on('popup:open', () => (!menu.hidden ? true : undefined)); // the scenario player's Escape leaves a menu that has its own
|
|
315
316
|
scope.on('layers:redraw', renderLayerToggles);
|
|
316
317
|
scope.on('theme', renderLayerToggles); // the dots and the legends are drawn in the theme's colours
|
|
317
318
|
scope.on('view', syncView);
|
package/explorer/pieces/map.js
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
import { createInstance } from '../instance.js';
|
|
46
46
|
import { createMap } from '../engine/render.js';
|
|
47
47
|
import { mapStyleOf } from '../engine/map-style.js';
|
|
48
|
-
import { layoutMap, setTopology as installTopology } from '../engine/topology.js';
|
|
48
|
+
import { layoutMap, setMap, setTopology as installTopology } from '../engine/topology.js';
|
|
49
49
|
import { initKeyboard, resetKeyboard, speaker } from '../engine/keyboard.js';
|
|
50
50
|
import { selectNode, clearSelection } from '../engine/selection.js';
|
|
51
51
|
import { stopFlight } from '../engine/fly.js';
|
|
@@ -181,6 +181,9 @@ function mountOn(root, inst, options, privateScope) {
|
|
|
181
181
|
const scope = scopeOf(inst);
|
|
182
182
|
scope.own(releaseRoot);
|
|
183
183
|
if (privateScope) scope.own(() => privateScope.destroy());
|
|
184
|
+
// In a scope, a proposal the scope holds (pieces/scope-proposal.js) is laid out on this map's own layout: nodes that were there keep their place (the review
|
|
185
|
+
// and cornfield's page answer for their own maps)
|
|
186
|
+
if (info) scope.on('map:set', ({ nodes, edges }) => { setMap(inst, nodes, edges); return true; });
|
|
184
187
|
const rendererOf = (v) => (v === 'canvas2d' ? 'canvas2d' : 'auto');
|
|
185
188
|
const themeOf = (v) => (v === 'light' || v === 'dark' ? v : 'auto');
|
|
186
189
|
const current = { renderer: rendererOf(options.renderer), theme: themeOf(options.theme), topology: undefined };
|
|
@@ -329,6 +332,7 @@ function mountOn(root, inst, options, privateScope) {
|
|
|
329
332
|
if (asked) selectNode(inst, asked, { source: 'api' });
|
|
330
333
|
map.render();
|
|
331
334
|
map.ensureFlowLoop();
|
|
335
|
+
inst.emit('map:topology'); // a proposal held over the map (pieces/scope-proposal.js) is laid over the new base
|
|
332
336
|
}
|
|
333
337
|
|
|
334
338
|
function setView(view) {
|
|
@@ -355,6 +359,7 @@ function mountOn(root, inst, options, privateScope) {
|
|
|
355
359
|
installRenderer();
|
|
356
360
|
map.resize();
|
|
357
361
|
if (hadFocus) next.focus();
|
|
362
|
+
inst.emit('map:canvas'); // a click on an edge is heard on the new canvas (pieces/scope-proposal.js)
|
|
358
363
|
}
|
|
359
364
|
|
|
360
365
|
/**
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @param {ParentNode} root where the elements go when `options.slots` names no place
|
|
15
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
|
|
16
|
+
* @param {{ slots?: { bar?: Node, menu?: Node }, edit?: boolean, inline?: 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. `inline` is the piece in a box of its own, in a root of its own (`<corn-proposal>`, pieces/around.js): the
|
|
18
|
+
* bar is a block that fills the box, not a panel over the map: no phone sheet, no Proposals menu, no what-if buttons, its keys and clicks are its own root's, and the picking of an
|
|
19
|
+
* edge on the map is the scope's (pieces/scope-proposal.js), whose proposal this is
|
|
18
20
|
* @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
21
|
* `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
22
|
* `slug`, `source` and `sha256` name it); `null` closes it. `update({ view })` switches Before, Diff or After. `update()` draws the bar again.
|
|
@@ -122,11 +124,14 @@ export function proposalRowHtml(entry, current) {
|
|
|
122
124
|
export function mount(root, inst, options = {}) {
|
|
123
125
|
const { state } = inst;
|
|
124
126
|
const scope = scopeOf(inst);
|
|
125
|
-
const
|
|
127
|
+
const inline = !!options.inline;
|
|
128
|
+
const html = markup({ edit: options.edit !== false && !inline });
|
|
126
129
|
const made = [
|
|
127
130
|
...place(inst, root, html.bar, options.slots, 'bar'),
|
|
128
|
-
...place(inst, root, html.menu, options.slots, 'menu'),
|
|
131
|
+
...(inline ? [] : place(inst, root, html.menu, options.slots, 'menu')),
|
|
129
132
|
];
|
|
133
|
+
/** What hears the clicks and keys of this piece: the instance's root, which holds the Work panel's Specs list too (cornfield's page), or the box's own root */
|
|
134
|
+
const hear = inline ? root : inst.root;
|
|
130
135
|
/** An element of this piece by id (the piece's own, whatever else the root holds) */
|
|
131
136
|
const own = (id) => {
|
|
132
137
|
for (const el of made) {
|
|
@@ -203,7 +208,7 @@ export function mount(root, inst, options = {}) {
|
|
|
203
208
|
// ---------------------------------------------------------------------------
|
|
204
209
|
function renderBar({ open = !!state.proposal } = {}) {
|
|
205
210
|
bar.hidden = !open;
|
|
206
|
-
if (!open) { closeMore(); toggleMode(false); collapseSheet(inst, 'proposal'); return; }
|
|
211
|
+
if (!open) { closeMore(); toggleMode(false); if (!inline) collapseSheet(inst, 'proposal'); return; }
|
|
207
212
|
|
|
208
213
|
bar.classList.remove('is-error');
|
|
209
214
|
own('proposal-message').hidden = true;
|
|
@@ -336,12 +341,15 @@ export function mount(root, inst, options = {}) {
|
|
|
336
341
|
const menuOpen = () => { const menu = own('proposal-menu'); return !!menu && !menu.hidden; };
|
|
337
342
|
|
|
338
343
|
function closeMenu() {
|
|
339
|
-
own('proposal-menu')
|
|
344
|
+
const menu = own('proposal-menu');
|
|
345
|
+
if (!menu) return; // a bar in a box of its own has no Proposals menu
|
|
346
|
+
menu.hidden = true;
|
|
340
347
|
own('proposal-btn').setAttribute('aria-expanded', 'false');
|
|
341
348
|
}
|
|
342
349
|
|
|
343
350
|
async function toggleMenu() {
|
|
344
351
|
const menu = own('proposal-menu');
|
|
352
|
+
if (!menu) return undefined;
|
|
345
353
|
if (menuOpen()) return closeMenu();
|
|
346
354
|
menu.hidden = false;
|
|
347
355
|
own('proposal-btn').setAttribute('aria-expanded', 'true');
|
|
@@ -351,6 +359,7 @@ export function mount(root, inst, options = {}) {
|
|
|
351
359
|
|
|
352
360
|
function renderMenu(loading = false) {
|
|
353
361
|
const menu = own('proposal-menu');
|
|
362
|
+
if (!menu) return;
|
|
354
363
|
const { entries: listing, problem: listingProblem, forgeProblem } = proposalListing(inst);
|
|
355
364
|
const current = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
|
|
356
365
|
let body;
|
|
@@ -391,7 +400,7 @@ export function mount(root, inst, options = {}) {
|
|
|
391
400
|
const ACTIONS = {
|
|
392
401
|
'toggle-proposals-menu': () => toggleMenu(),
|
|
393
402
|
'open-proposal': (el) => openProposal(inst, el.dataset.slug, el.dataset.source || null),
|
|
394
|
-
'close-proposal': () => closeProposal(inst),
|
|
403
|
+
'close-proposal': () => { closeProposal(inst); if (inline && state.canvas) state.canvas.focus(); }, // the bar is gone with the proposal: the focus goes to the map, never to the page
|
|
395
404
|
'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
405
|
'proposal-view': (el) => { setProposalView(inst, el.dataset.view); toggleMode(false); },
|
|
397
406
|
'toggle-proposal-mode': () => toggleMode(),
|
|
@@ -402,7 +411,7 @@ export function mount(root, inst, options = {}) {
|
|
|
402
411
|
};
|
|
403
412
|
|
|
404
413
|
// 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(
|
|
414
|
+
scope.listen(hear, 'click', (e) => {
|
|
406
415
|
const target = e.target.closest ? e.target.closest('[data-action]') : null;
|
|
407
416
|
const action = target && Object.hasOwn(ACTIONS, target.dataset.action) && ACTIONS[target.dataset.action];
|
|
408
417
|
if (action) action(target);
|
|
@@ -412,6 +421,10 @@ export function mount(root, inst, options = {}) {
|
|
|
412
421
|
const wrap = own('proposal-wrap');
|
|
413
422
|
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
423
|
});
|
|
424
|
+
// In a box of its own the root hears only the bar's clicks: a click anywhere else in the page (the map, the host's own page, another section) closes the ⋯ menu
|
|
425
|
+
// too, as it does on cornfield's page. The open menu holds the focus (on an item), and such a click takes it out of the bar: the menu closes when the focus
|
|
426
|
+
// leaves the bar (to nothing, or to anything outside it), which holds in a host's closed shadow root too and needs no listener on the page
|
|
427
|
+
if (inline) scope.listen(bar, 'focusout', (e) => { if (moreOpen() && !(e.relatedTarget && bar.contains(e.relatedTarget))) closeMore(); });
|
|
415
428
|
// Answer, on the bar's line (a run waits on this proposal): the Work panel opens on that run with its reply field focused (work:answer)
|
|
416
429
|
scope.listen(bar, 'click', (e) => {
|
|
417
430
|
const go = e.target.closest && e.target.closest('[data-waiting-answer]');
|
|
@@ -421,7 +434,7 @@ export function mount(root, inst, options = {}) {
|
|
|
421
434
|
const proposalsEntry = (workOn) => { const wrap = own('proposal-wrap'); if (wrap) wrap.hidden = !!workOn; };
|
|
422
435
|
scope.on('work:available', ({ on }) => proposalsEntry(on));
|
|
423
436
|
if (inst.ask('work:on')) proposalsEntry(true); // the Work panel started before this piece was mounted: it said so to nobody
|
|
424
|
-
scope.listen(
|
|
437
|
+
scope.listen(hear, 'keydown', (e) => {
|
|
425
438
|
if (e.key === 'Escape' && menuOpen()) closeMenu();
|
|
426
439
|
onMoreKey(e);
|
|
427
440
|
});
|
|
@@ -450,11 +463,25 @@ export function mount(root, inst, options = {}) {
|
|
|
450
463
|
scope.on('proposal:waiting', ({ run, key }) => paintWaitingLine(run, key));
|
|
451
464
|
scope.on('proposal:waiting-reset', () => { waitingSaid = null; waitingEl = null; });
|
|
452
465
|
scope.on('proposal', ({ change }) => { if (change === 'opened') closeMenu(); });
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
466
|
+
if (!inline) {
|
|
467
|
+
scope.own(bindEdgePicking(inst, (target, type, fn) => scope.listen(target, type, fn)));
|
|
468
|
+
initSheets(inst);
|
|
469
|
+
registerSheet(inst, 'proposal', bar, { stub: () => ({ title: (own('proposal-title') && own('proposal-title').textContent) || 'Proposal' }) });
|
|
470
|
+
scope.own(() => unregisterSheet(inst, 'proposal'));
|
|
471
|
+
// What the bar answers its neighbours in a box of one root: the part of the map it covers (the map frames into what is left), where the review column
|
|
472
|
+
// goes (under it, or in its body on a phone), and how far down it reaches (the column starts there)
|
|
473
|
+
scope.on('proposal:covers', () => (bar.hidden || !bar.isConnected ? undefined : { bottom: bar.getBoundingClientRect().bottom }));
|
|
474
|
+
scope.on('proposal:bar-bottom', () => (bar.hidden ? undefined : Math.round(bar.offsetTop + bar.offsetHeight + 8)));
|
|
475
|
+
scope.on('proposal:seat-column', ({ column, phone }) => {
|
|
476
|
+
const body = own('proposal-body');
|
|
477
|
+
if (phone && body) { if (column.parentElement !== body) body.appendChild(column); return true; }
|
|
478
|
+
if (bar.parentElement && column.parentElement !== bar.parentElement) bar.after(column);
|
|
479
|
+
return true;
|
|
480
|
+
});
|
|
481
|
+
const RO = inst.win && inst.win.ResizeObserver;
|
|
482
|
+
if (typeof RO === 'function') { const ro = new RO(() => inst.emit('proposal:bar-resize')); ro.observe(bar); scope.own(() => ro.disconnect()); }
|
|
483
|
+
}
|
|
484
|
+
scope.on('popup:open', () => (moreOpen() ? true : undefined)); // the player's Escape leaves a menu that has its own
|
|
458
485
|
|
|
459
486
|
scope.own(() => {
|
|
460
487
|
gone = true;
|
|
@@ -7,14 +7,14 @@
|
|
|
7
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
8
|
*
|
|
9
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
|
|
10
|
+
* scopeInfo(inst) -> { theme, serverTheme, host, source, mountStatus, signIn } for a scope's instance, else null (`signIn()`: the server's sign-in, back to the page)
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
export const REQUEST = 'corn-scope-request';
|
|
14
14
|
export const CHANGED = 'corn-scope-changed';
|
|
15
15
|
|
|
16
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 }));
|
|
17
|
+
export const infoOf = (inst) => inst.slot('scope', () => ({ theme: 'auto', serverTheme: null, host: null, source: null, mountStatus: null, signIn: () => '' }));
|
|
18
18
|
/**
|
|
19
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
20
|
* load: engine/source.js) and how a piece shows the load's states (pieces/status.js `mount`)
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/scope-proposal
|
|
3
|
+
*
|
|
4
|
+
* The proposal a `<corn-scope>` holds for every piece in it (spec 0011 D4, D5, D6): the sketch puts `proposal` (and `source` and `view`) on the scope, so
|
|
5
|
+
* the review's sections (`<corn-proposal>`, `<corn-changes>`, `<corn-decision>`) and the map beside them follow one proposal. This is the same opening
|
|
6
|
+
* `corn-review` does in its one root (pieces/review.js `applyProposal`), on the scope's instance and with no piece of its own: it asks the engine
|
|
7
|
+
* (engine/proposal.js: `GET /proposals/<name>.json` through `credentialed`, so the session goes only to the server's own origin), and the pieces that
|
|
8
|
+
* are there draw what the instance says (`proposal:draw`, `proposal:bar`). It is a chunk of its own, loaded the first time a scope has a proposal:
|
|
9
|
+
* a scope or a map that never has one does not carry it.
|
|
10
|
+
*
|
|
11
|
+
* const held = holdProposal(inst, options) -> { update, sync, destroy }
|
|
12
|
+
*
|
|
13
|
+
* Options (and what `update(next)` takes, only the keys present):
|
|
14
|
+
* proposal a name (read from the server), the proposal object (shown for reading: a decision needs the name), or null: closes it. Held while
|
|
15
|
+
* there is no map with nodes to lay it over, and opened when there is (a map that comes later, or is put back: `map:ready`, `map:topology`)
|
|
16
|
+
* source which copy of it: `checkout`, `pull/31`, a worktree; none: the server answers with the first it lists
|
|
17
|
+
* view `before`, `diff` or `after`
|
|
18
|
+
* blocked the scope's `src` is not an address: a name is asked of nobody (the scope says so)
|
|
19
|
+
* pageUrl () => the page's address, for the sign-in's way back
|
|
20
|
+
* onNavigate ({ proposal, source, view, change }) the open proposal or its view changed: what cornfield's own page puts in its address bar (the host decides what
|
|
21
|
+
* to do with it); `change`: 'opened' | 'view' | 'closed'. Said once, whoever changed it: a host's property, a button on the bar, a way on from a bad link
|
|
22
|
+
* onDecision ({ outcome, proposal, source, open, review }) the server took a review; once, after its answer, whichever `<corn-decision>` was pressed
|
|
23
|
+
* onAuth ({ status, signIn, during }) a read or a press was refused for want of a sign-in (`during`: 'proposal', 'facts', 'review', 'send', 'landing')
|
|
24
|
+
* onError ({ kind: 'proposal', message }) the proposal asked for did not open
|
|
25
|
+
*
|
|
26
|
+
* What it does for the pieces besides opening: it answers `proposal:specs-list` (there is no list of specs to open in another app's page), and it hears a click on an edge of the map (engine/proposal.js
|
|
27
|
+
* `bindEdgePicking`, on the map's canvas) so that a marked edge opens in the node panel whether or not a `<corn-proposal>` is there. It reads no address and
|
|
28
|
+
* writes none.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { openProposal, showProposal, closeProposal, setProposalView, rebuildProposalMap, bindEdgePicking, setMessage } from '../engine/proposal.js';
|
|
32
|
+
import { scopeOf } from '../engine/piece.js';
|
|
33
|
+
import { signInUrl } from '../engine/source-address.js';
|
|
34
|
+
import { PROPOSAL_VIEWS, isProposalName, notANameWords } from '../proposal-model.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst the scope's instance
|
|
38
|
+
* @param {object} [options] see the top of this file
|
|
39
|
+
*/
|
|
40
|
+
export function holdProposal(inst, options = {}) {
|
|
41
|
+
const { state } = inst;
|
|
42
|
+
const scope = scopeOf(inst);
|
|
43
|
+
let ended = false;
|
|
44
|
+
/** What the host asked for; `shown` is the key of the proposal this has opened (or is opening), so a repeat of the same ask opens nothing again */
|
|
45
|
+
const current = { proposal: null, source: null, view: null, shown: null };
|
|
46
|
+
const hasMap = () => !!inst.map && state.nodes.length > 0;
|
|
47
|
+
const blocked = !!options.blocked;
|
|
48
|
+
/** No server to ask (no `src`): a name is never asked of the page's own origin in its place, as the review's is not */
|
|
49
|
+
const serverless = () => !inst.base;
|
|
50
|
+
|
|
51
|
+
/** Opens, shows or closes what the host asked for, once there is a map to lay it over */
|
|
52
|
+
function sync() {
|
|
53
|
+
if (ended) return undefined;
|
|
54
|
+
const wanted = current.proposal;
|
|
55
|
+
if (wanted === null || wanted === undefined || wanted === '') {
|
|
56
|
+
current.shown = null;
|
|
57
|
+
if (state.proposal && inst.map) closeProposal(inst);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (!hasMap()) return undefined; // a proposal is laid over a map: it opens when there is one
|
|
61
|
+
const view = current.view;
|
|
62
|
+
if (typeof wanted === 'string' && blocked) return undefined; // there is no server to ask (the scope says why)
|
|
63
|
+
if (typeof wanted === 'string' && serverless()) {
|
|
64
|
+
const key = `${wanted}\u0000${current.source || ''}`;
|
|
65
|
+
if (current.shown === key) return undefined;
|
|
66
|
+
current.shown = key;
|
|
67
|
+
const message = isProposalName(wanted) ? `${wanted} cannot be opened here: there is no cornfield server to read it from (the scope has no src).` : notANameWords(wanted);
|
|
68
|
+
setMessage(inst, message, true, []);
|
|
69
|
+
inst.emit('proposal:failed', { slug: wanted, source: current.source, status: 0, notFound: false, message });
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
if (typeof wanted === 'string') {
|
|
73
|
+
// The proposal that is open already, asked for again by its name (a host that heard `cornNavigate` and set what it said): nothing opens again
|
|
74
|
+
if (state.proposal && state.proposalSlug === wanted && (!current.source || current.source === state.proposalSource)) {
|
|
75
|
+
current.shown = `${wanted}\u0000${current.source || ''}`;
|
|
76
|
+
if (PROPOSAL_VIEWS.includes(view) && state.proposalView !== view) setProposalView(inst, view, { quiet: true });
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const key = `${wanted}\u0000${current.source || ''}`;
|
|
80
|
+
if (current.shown === key) return undefined; // asked already: open, opening, or said why not
|
|
81
|
+
current.shown = key;
|
|
82
|
+
return openProposal(inst, wanted, current.source).then((ok) => {
|
|
83
|
+
if (ok && !ended && current.shown === key && PROPOSAL_VIEWS.includes(view) && state.proposalView !== view) setProposalView(inst, view, { quiet: true });
|
|
84
|
+
return ok;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (current.shown === wanted && state.proposal) return undefined;
|
|
88
|
+
current.shown = wanted;
|
|
89
|
+
const source = current.source || null;
|
|
90
|
+
showProposal(inst, wanted, { slug: null, source, pinSource: !!source, view: PROPOSAL_VIEWS.includes(view) ? view : 'diff', sha256: null });
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// -- what the pieces need of whoever holds the proposal -------------------------------------------------------------------------------
|
|
95
|
+
// (`map:set`, laying the proposal's nodes out beside the map's, is the scope's map's own answer: pieces/map.js)
|
|
96
|
+
scope.on('proposal:specs-list', () => false);
|
|
97
|
+
|
|
98
|
+
// -- the map comes, changes its data, or is put back ------------------------------------------------------------------------------------
|
|
99
|
+
let stopEdges = () => {};
|
|
100
|
+
const bindEdges = () => {
|
|
101
|
+
stopEdges();
|
|
102
|
+
stopEdges = inst.map && state.canvas ? bindEdgePicking(inst, (target, type, fn) => scope.listen(target, type, fn)) : () => {};
|
|
103
|
+
};
|
|
104
|
+
scope.own(() => stopEdges());
|
|
105
|
+
scope.on('map:ready', () => { bindEdges(); sync(); });
|
|
106
|
+
scope.on('map:canvas', bindEdges);
|
|
107
|
+
scope.on('map:gone', () => { stopEdges(); stopEdges = () => {}; });
|
|
108
|
+
scope.on('map:topology', () => {
|
|
109
|
+
// A new base map: an open proposal is laid over it again, as the review does; a proposal still waiting for a map opens
|
|
110
|
+
if (state.proposal && inst.map) rebuildProposalMap(inst, undefined, { fit: true });
|
|
111
|
+
sync();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// -- what a host hears --------------------------------------------------------------------------------------------------------------------
|
|
115
|
+
scope.on('proposal', ({ change, slug, source, pinSource, view }) => {
|
|
116
|
+
// The reviewer's own act (the bar's Close or View, a way on from a bad link) is the host's property too: asked for again it opens nothing
|
|
117
|
+
if (change === 'closed') { current.proposal = null; current.shown = null; } else if (change === 'opened' && slug) {
|
|
118
|
+
current.proposal = slug;
|
|
119
|
+
if (pinSource) current.source = source;
|
|
120
|
+
current.shown = `${slug}\u0000${current.source || ''}`;
|
|
121
|
+
}
|
|
122
|
+
if (view) current.view = view;
|
|
123
|
+
if (options.onNavigate) options.onNavigate({ proposal: slug, source: pinSource ? source : null, view: change === 'closed' ? null : view, change });
|
|
124
|
+
});
|
|
125
|
+
const signInOf = () => (inst.base ? signInUrl(inst.base, typeof options.pageUrl === 'function' ? options.pageUrl() : '') : '');
|
|
126
|
+
/** The facts are read again every half minute: a sign-in that is still needed is said once, not every time (a press, or a decision taken, is said each time) */
|
|
127
|
+
let factsRefused = '';
|
|
128
|
+
scope.on('auth', ({ status, during }) => {
|
|
129
|
+
if (during === 'facts') { if (factsRefused === `${status}`) return; factsRefused = `${status}`; } else factsRefused = '';
|
|
130
|
+
if (options.onAuth) options.onAuth({ status, signIn: signInOf(), during });
|
|
131
|
+
});
|
|
132
|
+
scope.on('decision', ({ outcome, review, slug, source, open }) => {
|
|
133
|
+
factsRefused = '';
|
|
134
|
+
if (options.onDecision) options.onDecision({ outcome, proposal: slug, source, open, review });
|
|
135
|
+
});
|
|
136
|
+
scope.on('proposal:failed', ({ message }) => { if (options.onError) options.onError({ kind: 'proposal', message }); });
|
|
137
|
+
|
|
138
|
+
const held = {
|
|
139
|
+
/** Takes the keys that changed; returns a promise of whether the proposal opened, when a name was fetched */
|
|
140
|
+
update(next = {}) {
|
|
141
|
+
if (ended) return undefined;
|
|
142
|
+
let asked = false;
|
|
143
|
+
if ('source' in next && (next.source || null) !== current.source) { current.source = next.source || null; asked = true; }
|
|
144
|
+
if ('proposal' in next && (next.proposal ?? null) !== current.proposal) { current.proposal = next.proposal ?? null; current.shown = null; asked = true; }
|
|
145
|
+
if ('view' in next && PROPOSAL_VIEWS.includes(next.view) && next.view !== current.view) {
|
|
146
|
+
current.view = next.view;
|
|
147
|
+
if (state.proposal && !asked) setProposalView(inst, next.view, { quiet: true }); // a reviewer's own choice is the same value: nothing changes
|
|
148
|
+
}
|
|
149
|
+
return asked ? sync() : undefined;
|
|
150
|
+
},
|
|
151
|
+
sync,
|
|
152
|
+
destroy() { if (ended) return; ended = true; scope.destroy(); },
|
|
153
|
+
};
|
|
154
|
+
held.update({ proposal: options.proposal, source: options.source, view: options.view });
|
|
155
|
+
bindEdges();
|
|
156
|
+
sync();
|
|
157
|
+
return held;
|
|
158
|
+
}
|
package/explorer/pieces/scope.js
CHANGED
|
@@ -25,6 +25,12 @@
|
|
|
25
25
|
* A second map in a scope is refused (the engine holds one map per instance); when the map that has the scope leaves, the first refused map that
|
|
26
26
|
* is still in the page is told to ask again, and takes it.
|
|
27
27
|
*
|
|
28
|
+
* THE PROPOSAL. A scope with a `proposal` (a name, or the object) holds it for every piece in it, with `source` and `view` (pieces/scope-proposal.js, a chunk of its own,
|
|
29
|
+
* loaded the first time a scope has one): the map narrows to it, `<corn-proposal>`, `<corn-changes>` and `<corn-decision>` show and decide it. What the reviewer
|
|
30
|
+
* does (the bar's Close and Before, Diff or After, a way on from a bad link) is the instance's, and it is told to the host once as `onNavigate`; a decision as
|
|
31
|
+
* `onDecision`; a refused read or press as `onAuth` with `during`. The scope, not one of the sections, says them: the proposal is the scope's, whatever number of
|
|
32
|
+
* sections (none, or two) are in it, and it is the one place `cornAuth` and `cornError` already come from.
|
|
33
|
+
*
|
|
28
34
|
* It reads no `location`: the page's address is a function the shell passes in (`pageUrl`), used for the sign-in's way back and to name the
|
|
29
35
|
* origin a "not listed" message asks the server to list. It never navigates the window.
|
|
30
36
|
*/
|
|
@@ -32,6 +38,7 @@
|
|
|
32
38
|
import { createInstance } from '../instance.js';
|
|
33
39
|
import { adoptDefaultTokens } from './adopt-tokens.js';
|
|
34
40
|
import { parseSource } from '../engine/source.js';
|
|
41
|
+
import { signInUrl } from '../engine/source-address.js';
|
|
35
42
|
import { connectServer } from '../engine/server-load.js';
|
|
36
43
|
import { keepLayersIn } from '../engine/layers.js';
|
|
37
44
|
import { mount as mountStatus } from './status.js';
|
|
@@ -55,9 +62,15 @@ const THEMES = ['light', 'dark', 'auto'];
|
|
|
55
62
|
* @param {(detail: { status: number, signIn: string }) => void} [options.onAuth] the server wants a sign-in
|
|
56
63
|
* @param {(detail: { kind: 'not-listed' | 'offline' | 'server' | 'address' | 'version' | 'theme' | 'second-map', message?: string }) => void} [options.onError]
|
|
57
64
|
* @param {() => void} [options.onReady] the scope has its data (loaded, or handed in)
|
|
65
|
+
* @param {string | object | null} [options.proposal] @param {string | null} [options.source] @param {'before'|'diff'|'after'|null} [options.view] the proposal the scope holds
|
|
66
|
+
* @param {(detail: { proposal: string | null, source: string | null, view: 'before' | 'diff' | 'after' | null, change: 'opened' | 'view' | 'closed' }) => void} [options.onNavigate] the open proposal or its view changed
|
|
67
|
+
* @param {(detail: { outcome: 'approved' | 'notes', proposal: string | null, source: string | null, open: boolean, review: any }) => void} [options.onDecision] the server took a review
|
|
58
68
|
*/
|
|
59
69
|
export function mountScope(host, options = {}) {
|
|
60
|
-
const props = {
|
|
70
|
+
const props = {
|
|
71
|
+
src: options.src, theme: options.theme, useTheme: !!options.useTheme, topology: options.topology, config: options.config, strings: options.strings,
|
|
72
|
+
proposal: options.proposal ?? null, source: options.source ?? null, view: options.view ?? null,
|
|
73
|
+
};
|
|
61
74
|
const pageUrl = options.pageUrl || (() => '');
|
|
62
75
|
/** The pieces that took this scope's answer, by their element: what is told when the instance changes */
|
|
63
76
|
const handles = new Set();
|
|
@@ -68,6 +81,9 @@ export function mountScope(host, options = {}) {
|
|
|
68
81
|
let serverLink = null;
|
|
69
82
|
let readyFired = false;
|
|
70
83
|
let ended = false;
|
|
84
|
+
/** The proposal the instance holds (pieces/scope-proposal.js), once there is one to hold; null before that, and for an instance that has none */
|
|
85
|
+
let held = null;
|
|
86
|
+
let holdLoading = false;
|
|
71
87
|
|
|
72
88
|
// -- the answer to a piece ---------------------------------------------------------------------------------------------------------------
|
|
73
89
|
const answer = (event) => {
|
|
@@ -123,6 +139,7 @@ export function mountScope(host, options = {}) {
|
|
|
123
139
|
source = link.source;
|
|
124
140
|
info.source = source;
|
|
125
141
|
info.mountStatus = mountStatus;
|
|
142
|
+
info.signIn = () => (mine.base ? signInUrl(mine.base, pageUrl()) : ''); // the server's sign-in, back to this page: a section that is refused shows the card with it
|
|
126
143
|
readyFired = false;
|
|
127
144
|
// A second map waits: when the one that has the instance's root gives it back, the first that waits and is still in the page asks again
|
|
128
145
|
// (after the leaving map has finished ending, so the two never hold the instance's state at once)
|
|
@@ -143,6 +160,48 @@ export function mountScope(host, options = {}) {
|
|
|
143
160
|
if (parsed && !parsed.ok) source.say({ state: 'address', problem: parsed.problem });
|
|
144
161
|
source.provide({ topology: props.topology || undefined, config: props.config || undefined, strings: props.strings || undefined });
|
|
145
162
|
if (parsed && parsed.ok) source.load();
|
|
163
|
+
held = null;
|
|
164
|
+
holdLoading = false;
|
|
165
|
+
holdProposal();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The proposal's keys a host changed, handed over together once its script has run: a host sets `source` and then `proposal` (or `proposal` and then `view`)
|
|
170
|
+
* one after the other, and each alone would open the wrong thing first (the old proposal under the new source: a read of a copy that does not exist, a
|
|
171
|
+
* `cornError` for it, and a line in the bar)
|
|
172
|
+
*/
|
|
173
|
+
let asking = null;
|
|
174
|
+
function askHeld(asked) {
|
|
175
|
+
if (asking) { Object.assign(asking, asked); return; }
|
|
176
|
+
asking = { ...asked };
|
|
177
|
+
queueMicrotask(() => {
|
|
178
|
+
const keys = asking;
|
|
179
|
+
asking = null;
|
|
180
|
+
if (ended) return;
|
|
181
|
+
if (held) held.update(keys); else holdProposal();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Makes the instance hold the proposal when the scope has one (the first time: the chunk is loaded); a scope with none loads nothing */
|
|
186
|
+
function holdProposal() {
|
|
187
|
+
if (ended || held || holdLoading || props.proposal === null || props.proposal === undefined || props.proposal === '') return;
|
|
188
|
+
holdLoading = true;
|
|
189
|
+
const mine = inst;
|
|
190
|
+
const blocked = props.src !== undefined && props.src !== null && props.src !== '' && !parseSource(props.src).ok;
|
|
191
|
+
import('./scope-proposal.js').then(({ holdProposal: hold }) => {
|
|
192
|
+
holdLoading = false;
|
|
193
|
+
if (ended || inst !== mine || held) return;
|
|
194
|
+
held = hold(mine, {
|
|
195
|
+
proposal: props.proposal, source: props.source, view: props.view, blocked, pageUrl,
|
|
196
|
+
onNavigate: (detail) => { if (options.onNavigate) options.onNavigate(detail); },
|
|
197
|
+
onDecision: (detail) => { if (options.onDecision) options.onDecision(detail); },
|
|
198
|
+
onAuth: (detail) => { if (options.onAuth) options.onAuth(detail); },
|
|
199
|
+
onError: (detail) => { if (options.onError) options.onError(detail); },
|
|
200
|
+
});
|
|
201
|
+
}, (err) => {
|
|
202
|
+
holdLoading = false;
|
|
203
|
+
if (!ended && options.onError) options.onError({ kind: 'offline', message: `the scope's proposal loader did not load: ${err && err.message ? err.message : err}` });
|
|
204
|
+
});
|
|
146
205
|
}
|
|
147
206
|
|
|
148
207
|
function release() {
|
|
@@ -181,6 +240,10 @@ export function mountScope(host, options = {}) {
|
|
|
181
240
|
const hand = {};
|
|
182
241
|
for (const key of ['topology', 'config', 'strings']) if (key in next && next[key] !== props[key]) { props[key] = next[key]; hand[key] = next[key] === undefined ? null : next[key]; }
|
|
183
242
|
if (Object.keys(hand).length) source.provide(hand);
|
|
243
|
+
// The proposal: the keys that changed go to what holds it (loaded now, if this is the scope's first)
|
|
244
|
+
const asked = {};
|
|
245
|
+
for (const key of ['proposal', 'source', 'view']) if (key in next && (next[key] ?? null) !== props[key]) { props[key] = next[key] ?? null; asked[key] = props[key]; }
|
|
246
|
+
if (Object.keys(asked).length) askHeld(asked);
|
|
184
247
|
},
|
|
185
248
|
destroy() {
|
|
186
249
|
if (ended) return;
|