cornfield 0.37.0 → 0.39.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/cli/cornfield.js +4 -1
- package/core/proposal.js +22 -0
- package/core/strings.js +24 -0
- package/explorer/check.js +14 -10
- package/explorer/corn-state.js +3 -1
- package/explorer/explorer.css +221 -30
- package/explorer/forge-panel.js +173 -14
- package/explorer/index.html +24 -9
- package/explorer/main.js +2 -0
- package/explorer/panels.js +2 -1
- package/explorer/proposal-model.js +18 -13
- package/explorer/proposal.js +22 -87
- package/explorer/review-column.js +430 -0
- package/explorer/review.js +8 -7
- package/explorer/runs-view.js +7 -4
- package/explorer/scenario-list-model.js +301 -0
- package/explorer/scenario-ui.js +139 -136
- package/explorer/sheet-model.js +67 -19
- package/explorer/sheets.js +144 -15
- package/explorer/waiting-line.js +57 -0
- package/explorer/waiting-model.js +287 -0
- package/explorer/waiting-view.js +37 -0
- package/package.json +1 -1
- package/server/forge-forgejo.js +1 -1
- package/server/forge-github.js +1 -1
- package/server/forge.js +1 -1
- package/server/proposal-pulls.js +93 -2
- package/server/proposals.js +4 -2
- package/server/reviews.js +5 -4
- package/server/submit-review.js +2 -1
package/explorer/scenario-ui.js
CHANGED
|
@@ -14,16 +14,15 @@
|
|
|
14
14
|
* scenario costs nothing, a hidden tab stops the loop, and under prefers-reduced-motion the steps
|
|
15
15
|
* still change but the packet does not travel and the camera jumps.
|
|
16
16
|
*
|
|
17
|
-
* The scenario list:
|
|
18
|
-
* is
|
|
19
|
-
* a row inside the proposal bar, and at the stage's corner when there is no bar.
|
|
17
|
+
* The scenario list is the review column's (review-column.js): this module plays what it hands over and tells it where the
|
|
18
|
+
* player is (`onPlayerChange`), so the list can follow.
|
|
20
19
|
*
|
|
21
20
|
* On a phone (sheets.js, TOPO-18) the bar is a bottom sheet in `#sheet-dock`: a peek (title, step
|
|
22
21
|
* counter and text) until expanded, and the camera follows a step into the part of the map the
|
|
23
22
|
* sheets leave free.
|
|
24
23
|
*/
|
|
25
24
|
|
|
26
|
-
import { state, touchScene
|
|
25
|
+
import { state, touchScene } from './state.js';
|
|
27
26
|
import { render, ensureFlowLoop, addFrameClient, isNodeVisible, getMinZoom } from './render.js';
|
|
28
27
|
import { flowReduceMotion } from './flows.js';
|
|
29
28
|
import { registerSheet, unregisterSheet, collapseAllSheets, visibleMapRect, onCoveredChange } from './sheets.js';
|
|
@@ -31,8 +30,12 @@ import { createPlayer, cameraFor, parseSpeed, SPEED_CHOICES, SPEED_KEY } from '.
|
|
|
31
30
|
import { edgeKey } from '../core/proposal.js';
|
|
32
31
|
import { checksVersion, closeChecks, decorateSnapshot, openChecks, paintChecks } from './check.js';
|
|
33
32
|
import { blastRadius, outageLayers, outageScenario } from './outage-model.js';
|
|
34
|
-
import { toggleLayer } from './layers.js';
|
|
33
|
+
import { toggleLayer, LAYER_DEFS } from './layers.js';
|
|
34
|
+
import { externalLayer } from './cloud-model.js';
|
|
35
35
|
import { announce } from './keyboard.js';
|
|
36
|
+
import { t } from './strings.js';
|
|
37
|
+
import { currentStepSentence } from './scenario-list-model.js';
|
|
38
|
+
import { personaFor, personaLabel } from './check-model.js';
|
|
36
39
|
|
|
37
40
|
/** A frame that arrives later than this (a tab that was hidden) counts as this long */
|
|
38
41
|
const MAX_FRAME_MS = 250;
|
|
@@ -43,7 +46,9 @@ let player = null;
|
|
|
43
46
|
let bar = null;
|
|
44
47
|
let signature = '';
|
|
45
48
|
let glide = null; // { to: {x, y, zoom}, last: nowMs|null }
|
|
46
|
-
let
|
|
49
|
+
let held = false; // the viewer took hold of the map since the step began: the camera is theirs until the next step
|
|
50
|
+
let framedFor = -1; // the player bar's height when the camera last followed the step
|
|
51
|
+
let barWatch = null; // a ResizeObserver on the bar: when it grows (a check's line arrives), the step is followed again
|
|
47
52
|
|
|
48
53
|
const $stage = () => (state.canvas ? state.canvas.parentElement : null);
|
|
49
54
|
|
|
@@ -54,39 +59,40 @@ const $stage = () => (state.canvas ? state.canvas.parentElement : null);
|
|
|
54
59
|
/**
|
|
55
60
|
* Plays a scenario on the map, replacing any that is playing.
|
|
56
61
|
* @param {import('./scenario.js').Scenario} scenario
|
|
57
|
-
* @param {{ autoplay?: boolean, stepMs?: number | 'manual' }} [opts] `autoplay` false opens it paused on the first step;
|
|
58
|
-
* `stepMs` is a speed for this scenario in place of the viewer's saved one
|
|
62
|
+
* @param {{ autoplay?: boolean, stepMs?: number | 'manual', step?: number, focus?: boolean }} [opts] `autoplay` false opens it paused on the first step;
|
|
63
|
+
* `step` opens it on that step (paused); `stepMs` is a speed for this scenario in place of the viewer's saved one;
|
|
64
|
+
* `focus` false leaves the keyboard focus where it is (the review column's step list keeps it)
|
|
59
65
|
* @returns {ReturnType<typeof createPlayer>} the player, for a caller that wants to drive it
|
|
60
66
|
*/
|
|
61
67
|
export function playScenario(scenario, opts = {}) {
|
|
62
68
|
const opener = openerOf();
|
|
63
|
-
const takeFocus = isKeyboardish(); // checked now:
|
|
64
|
-
clearScenario();
|
|
69
|
+
const takeFocus = isKeyboardish() && opts.focus !== false; // checked now: whatever was pressed may go with the markup
|
|
70
|
+
clearScenario({ keepChecks: true });
|
|
65
71
|
returnTo = opener;
|
|
66
72
|
const speed = opts.stepMs ?? readSpeed();
|
|
67
73
|
player = createPlayer(scenario, { stepMs: speed, maxFrameMs: MAX_FRAME_MS });
|
|
74
|
+
if (Number.isFinite(opts.step) && opts.step > 0) player.goTo(opts.step);
|
|
68
75
|
showBar(speed);
|
|
69
|
-
openChecks(scenario, () => { sync(); render(); }); // PHY-10: one batch of permission checks for the scenario (check.js)
|
|
76
|
+
openChecks(scenario, () => { sync(); render(); }); // PHY-10: one batch of permission checks for the scenario (check.js); the same scenario already open in the list keeps its answers
|
|
70
77
|
showOutageLayers(scenario);
|
|
71
|
-
|
|
78
|
+
showStepLayers(scenario);
|
|
79
|
+
if (opts.autoplay !== false && !(opts.step > 0)) player.play();
|
|
72
80
|
sync(true);
|
|
73
81
|
render();
|
|
74
82
|
ensureFlowLoop();
|
|
75
|
-
// Whatever started it
|
|
76
|
-
if (
|
|
83
|
+
// Whatever started it may be gone: focus goes to the player's play and pause button, the first control of what opened
|
|
84
|
+
if (takeFocus && bar) {
|
|
77
85
|
const toggle = bar.querySelector('[data-action=scenario-toggle]');
|
|
78
86
|
if (toggle && !toggle.disabled) toggle.focus(); else bar.querySelector('[data-action=scenario-next]')?.focus();
|
|
79
87
|
}
|
|
80
88
|
return player;
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
/** What had the focus when a scenario started, to give it back when the scenario closes
|
|
91
|
+
/** What had the focus when a scenario started, to give it back when the scenario closes (a control of another panel, say) */
|
|
84
92
|
let returnTo = null;
|
|
85
93
|
function openerOf() {
|
|
86
94
|
const active = document.activeElement;
|
|
87
|
-
|
|
88
|
-
if (active && active !== document.body && (active === play || active.closest?.('#proposal-scenarios'))) return play;
|
|
89
|
-
if (active && active !== document.body && !active.closest?.('.hx-player') && active !== state.canvas) return active;
|
|
95
|
+
if (active && active !== document.body && !active.closest?.('.hx-player') && !active.closest?.('#review-column') && active !== state.canvas) return active;
|
|
90
96
|
return null;
|
|
91
97
|
}
|
|
92
98
|
|
|
@@ -96,7 +102,19 @@ function isKeyboardish() {
|
|
|
96
102
|
return !!active && active !== document.body && !typingIn(active);
|
|
97
103
|
}
|
|
98
104
|
|
|
99
|
-
/**
|
|
105
|
+
/** Who knows where the focus goes when the player closes: the review column's step list (review-column.js) gives the step the player was on */
|
|
106
|
+
let closeFocus = null;
|
|
107
|
+
export function setCloseFocus(fn) { closeFocus = typeof fn === 'function' ? fn : null; }
|
|
108
|
+
|
|
109
|
+
/** Who is told when the player moves: `fn(snapshot)` on each change of step, play state or answer, and `fn(null)` when it closes */
|
|
110
|
+
const playerListeners = new Set();
|
|
111
|
+
export function onPlayerChange(fn) {
|
|
112
|
+
playerListeners.add(fn);
|
|
113
|
+
return () => playerListeners.delete(fn);
|
|
114
|
+
}
|
|
115
|
+
const notify = (snap) => { for (const fn of playerListeners) fn(snap); };
|
|
116
|
+
|
|
117
|
+
/** Closing the player by the viewer's own act: the focus goes back to the step it was on in the list, else to what started it, else to the map */
|
|
100
118
|
function giveFocusBack() {
|
|
101
119
|
const to = returnTo;
|
|
102
120
|
returnTo = null;
|
|
@@ -105,7 +123,7 @@ function giveFocusBack() {
|
|
|
105
123
|
el.focus();
|
|
106
124
|
return document.activeElement === el; // a control the stylesheet hides takes no focus
|
|
107
125
|
};
|
|
108
|
-
if (took(
|
|
126
|
+
if (took(closeFocus && closeFocus()) || took(to)) return;
|
|
109
127
|
took(state.canvas);
|
|
110
128
|
}
|
|
111
129
|
|
|
@@ -119,6 +137,40 @@ function showOutageLayers(scenario) {
|
|
|
119
137
|
.forEach((key) => { if (state.activeLayers[key] === false) toggleLayer(key); });
|
|
120
138
|
}
|
|
121
139
|
|
|
140
|
+
/**
|
|
141
|
+
* The Layers keys that hide a node, or [] when no layer does (#212). Only what Layers decides: the Flow and House views and
|
|
142
|
+
* Before or After draw their own sets, and a layer would not change them.
|
|
143
|
+
*/
|
|
144
|
+
export function layersHiding(node) {
|
|
145
|
+
if (!node || state.view === 'dataflow' || state.view === 'house') return [];
|
|
146
|
+
const on = (key) => state.activeLayers[key] !== false;
|
|
147
|
+
const t = node.type;
|
|
148
|
+
if (t === 'root') return [];
|
|
149
|
+
if (t === 'core') return [...(on('core') ? [] : ['core']), ...(state.activeLayers.pkg || state.activeLayers.atom ? [] : ['pkg'])];
|
|
150
|
+
if (t === 'store') return ['flow', 'store'].filter((k) => !on(k));
|
|
151
|
+
if (t === 'rom') return ['rom', 'flow'].filter((k) => !on(k));
|
|
152
|
+
if (t === 'floor' || t === 'room') return on('house') ? [] : ['house'];
|
|
153
|
+
const key = t === 'external' ? externalLayer(node) : t;
|
|
154
|
+
return on(key) ? [] : [key];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The nodes a scenario's steps name: a node step's node, both ends of an edge step */
|
|
158
|
+
const stepNodeIds = (scenario) => (Array.isArray(scenario?.steps) ? scenario.steps : []).flatMap((st) => (st?.edge ? [st.edge.from, st.edge.to] : st && st.node !== undefined ? [st.node] : []));
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A step on a layer that is off cannot be followed: the camera has nothing to go to (#212). Playing a scenario turns on the layers
|
|
162
|
+
* its steps are drawn on, as an outage turns on what it hits, and says which.
|
|
163
|
+
*/
|
|
164
|
+
function showStepLayers(scenario) {
|
|
165
|
+
const byId = new Map(state.nodes.map((n) => [n.id, n]));
|
|
166
|
+
const keys = [];
|
|
167
|
+
for (const id of stepNodeIds(scenario)) for (const key of layersHiding(byId.get(id))) if (!keys.includes(key)) keys.push(key);
|
|
168
|
+
if (!keys.length) return;
|
|
169
|
+
for (const key of keys) { if (key === 'pkg') state.activeLayers.pkg = false; toggleLayer(key); }
|
|
170
|
+
const names = keys.map((key) => (LAYER_DEFS.find((l) => l.key === key) || { label: key }).label);
|
|
171
|
+
announce(`Turned on ${names.length > 1 ? `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}` : names[0]} to show this scenario's steps.`);
|
|
172
|
+
}
|
|
173
|
+
|
|
122
174
|
/** The cloud panel's Play button (CLOUD-07): plays "X is down" for a cloud node, generated from the map (outage-model.js) */
|
|
123
175
|
export function playOutage(id) {
|
|
124
176
|
const node = state.nodes.find((n) => n.id === id);
|
|
@@ -129,25 +181,32 @@ export function playOutage(id) {
|
|
|
129
181
|
/** The player of the scenario on the map, or null */
|
|
130
182
|
export const getPlayer = () => player;
|
|
131
183
|
|
|
132
|
-
/** Ends the scenario without touching the picture: for callers that rebuild it themselves (selecting a node, switching view) */
|
|
133
|
-
export function clearScenario() {
|
|
184
|
+
/** Ends the scenario without touching the picture: for callers that rebuild it themselves (selecting a node, switching view). `keepChecks` while another scenario is about to start */
|
|
185
|
+
export function clearScenario({ keepChecks = false, closing = false } = {}) {
|
|
186
|
+
const had = !!player || !!state.scenario;
|
|
134
187
|
player = null;
|
|
135
188
|
glide = null;
|
|
136
189
|
signature = '';
|
|
137
190
|
state.scenario = null;
|
|
138
|
-
closeChecks();
|
|
191
|
+
if (!keepChecks) closeChecks();
|
|
192
|
+
if (barWatch) { barWatch.disconnect(); barWatch = null; }
|
|
139
193
|
if (bar) { unregisterSheet('player'); bar.remove(); bar = null; }
|
|
140
|
-
|
|
194
|
+
if (had && (!keepChecks || closing)) notify(null);
|
|
141
195
|
}
|
|
142
196
|
|
|
197
|
+
/** Who keeps a closed scenario's checks: the review column, while its steps are open in the list (their verdicts stay there) */
|
|
198
|
+
let keepChecksOnClose = null;
|
|
199
|
+
export function setKeepChecksOnClose(fn) { keepChecksOnClose = typeof fn === 'function' ? fn : null; }
|
|
200
|
+
|
|
143
201
|
/** Ends the scenario and redraws the map without it */
|
|
144
202
|
export function stopScenario() {
|
|
145
203
|
if (!player && !state.scenario) return;
|
|
146
|
-
const hadFocus = !!bar && bar.contains(document.activeElement);
|
|
147
|
-
|
|
204
|
+
const hadFocus = (!!bar && bar.contains(document.activeElement)) || !!document.activeElement?.closest?.('#review-column'); // in the player, or in the list that follows it
|
|
205
|
+
const keep = !!player && !!keepChecksOnClose && keepChecksOnClose(player.scenario().id); // the list still shows its steps: their verdicts stay
|
|
206
|
+
clearScenario({ keepChecks: keep, closing: true });
|
|
148
207
|
touchScene();
|
|
149
208
|
render();
|
|
150
|
-
if (hadFocus || document.activeElement === document.body) giveFocusBack(); // focus was in the player, which is gone
|
|
209
|
+
if (hadFocus || document.activeElement === document.body) giveFocusBack(); // focus was in the player, which is gone: it goes to the step the player was on
|
|
151
210
|
else returnTo = null;
|
|
152
211
|
}
|
|
153
212
|
|
|
@@ -162,9 +221,10 @@ function sync(force = false) {
|
|
|
162
221
|
const stepChanged = force || next.split('|')[0] !== signature.split('|')[0];
|
|
163
222
|
signature = next;
|
|
164
223
|
touchScene();
|
|
165
|
-
if (stepChanged) followStep(snap);
|
|
224
|
+
if (stepChanged) { held = false; followStep(snap); }
|
|
166
225
|
}
|
|
167
226
|
updateBar(snap);
|
|
227
|
+
if (changed) notify({ id: snap.id, index: snap.index, total: snap.total, done: snap.done, playing: snap.playing, checks: checksVersion() });
|
|
168
228
|
return changed;
|
|
169
229
|
}
|
|
170
230
|
|
|
@@ -176,6 +236,7 @@ function followStep(snap) {
|
|
|
176
236
|
state.nodes.forEach((n) => { if (isNodeVisible(n)) visible.set(n.id, n); });
|
|
177
237
|
// The step must be in the part of the map nothing covers: not under the proposal bar, the node panel, the player or (on a phone) the sheets
|
|
178
238
|
const rect = visibleMapRect();
|
|
239
|
+
framedFor = bar ? bar.offsetHeight : 0;
|
|
179
240
|
const target = cameraFor({ node: snap.current.node, edge: snap.current.edge, at: snap.current.at, text: snap.current.text }, state.camera, rect, visible, 60, getMinZoom());
|
|
180
241
|
if (!target) return;
|
|
181
242
|
if (flowReduceMotion) { Object.assign(state.camera, target); glide = null; render(); return; } // reduced motion: jump, do not fly
|
|
@@ -222,19 +283,27 @@ function showBar(speed) {
|
|
|
222
283
|
bar.dataset.corn = 'scenario-player';
|
|
223
284
|
bar.setAttribute('role', 'region');
|
|
224
285
|
bar.setAttribute('aria-label', 'Scenario player');
|
|
286
|
+
// One bar (spec 0006 D6): Previous, Pause or Play, Next; "2 of 4 · As Adult · the step's text · Allowed"; the speed and Close.
|
|
287
|
+
// The scenario's name is the title (heard, and shown on a phone's open sheet); the list beside the map has it open and the step marked.
|
|
225
288
|
bar.innerHTML = `
|
|
226
|
-
<
|
|
227
|
-
|
|
289
|
+
<span class="hx-player-title hx-sr-only"></span>
|
|
290
|
+
<div class="hx-player-controls" role="group">
|
|
291
|
+
<button data-corn-kind="secondary" type="button" class="hx-btn hx-player-prev" data-action="scenario-prev" data-peek-ok><span class="hx-player-label"></span></button>
|
|
292
|
+
<button type="button" class="hx-btn hx-btn--active hx-player-toggle" data-action="scenario-toggle" data-peek-ok data-corn-kind="primary"><span class="hx-player-label"></span></button>
|
|
293
|
+
<button data-corn-kind="secondary" type="button" class="hx-btn hx-player-next" data-action="scenario-next" data-peek-ok><span class="hx-player-label"></span></button>
|
|
294
|
+
<button data-corn-kind="secondary" type="button" class="hx-btn hx-player-next-scenario" data-action="scenario-next-scenario" data-peek-ok hidden></button>
|
|
295
|
+
</div>
|
|
296
|
+
<p class="hx-player-text"><span class="hx-player-count" data-corn="count"></span><span class="hx-player-sep" aria-hidden="true"> · </span><span class="hx-player-who"></span><span class="hx-player-step"></span></p>
|
|
297
|
+
<span class="hx-player-says hx-sr-only" role="status" aria-live="polite"></span>
|
|
298
|
+
<div class="hx-player-side">
|
|
228
299
|
<select data-corn="control" class="hx-player-speed" data-action="scenario-speed" aria-label="Time for each step" title="Time for each step">${SPEED_CHOICES.map((c) => `<option value="${c.value}">${c.label}</option>`).join('')}</select>
|
|
229
300
|
<button type="button" class="hx-close" data-action="scenario-close" aria-label="Close the scenario" data-corn-kind="icon">✕</button>
|
|
230
301
|
</div>
|
|
231
|
-
<p class="hx-player-text" aria-live="polite"><span class="hx-player-count" data-corn="count"></span> · <span class="hx-player-step"></span></p>
|
|
232
|
-
<div class="hx-player-controls">
|
|
233
|
-
<button data-corn-kind="secondary" type="button" class="hx-btn" data-action="scenario-prev" data-peek-ok>◀ Previous</button>
|
|
234
|
-
<button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle" data-peek-ok data-corn-kind="primary"></button>
|
|
235
|
-
<button data-corn-kind="secondary" type="button" class="hx-btn" data-action="scenario-next" data-peek-ok>Next ▶</button>
|
|
236
|
-
</div>
|
|
237
302
|
<div class="hx-player-track" data-corn="scenario-track" aria-hidden="true"><span class="hx-player-fill" data-corn="scenario-fill"></span></div>`;
|
|
303
|
+
bar.querySelector('.hx-player-controls').setAttribute('aria-label', t('steps'));
|
|
304
|
+
bar.querySelector('.hx-player-prev .hx-player-label').textContent = t('previousStep');
|
|
305
|
+
bar.querySelector('.hx-player-next .hx-player-label').textContent = t('nextStep');
|
|
306
|
+
bar.querySelector('.hx-player-next-scenario').textContent = t('nextScenario');
|
|
238
307
|
bar.addEventListener('click', (e) => {
|
|
239
308
|
const button = e.target.closest('[data-action]');
|
|
240
309
|
if (button) act(button.dataset.action);
|
|
@@ -242,15 +311,24 @@ function showBar(speed) {
|
|
|
242
311
|
const menu = bar.querySelector('.hx-player-speed');
|
|
243
312
|
menu.value = String(speed);
|
|
244
313
|
menu.addEventListener('change', (e) => chooseSpeed(e.target.value));
|
|
245
|
-
// On a phone the bar is a sheet in the dock, above the node panel; it opens as a peek and the others fold, so the map shows
|
|
314
|
+
// On a phone the bar is a sheet in the dock, above the node panel; it opens as a peek (one row) and the others fold, so the map shows
|
|
246
315
|
const dock = document.getElementById('sheet-dock');
|
|
247
316
|
const drawer = document.getElementById('spec-drawer');
|
|
248
317
|
if (dock && drawer && drawer.parentElement === dock) dock.insertBefore(bar, drawer);
|
|
249
318
|
else (dock || stage).appendChild(bar);
|
|
250
319
|
registerSheet('player', bar);
|
|
251
320
|
collapseAllSheets();
|
|
321
|
+
// The bar grows once it has more to say (a step's check, its As row): the step it framed would now be under it, so it is followed again
|
|
322
|
+
if (typeof ResizeObserver === 'function') {
|
|
323
|
+
barWatch = new ResizeObserver(() => { if (bar && player && state.scenario && !held && bar.offsetHeight !== framedFor) followStep(player.snapshot()); });
|
|
324
|
+
barWatch.observe(bar);
|
|
325
|
+
}
|
|
252
326
|
}
|
|
253
327
|
|
|
328
|
+
/** Who knows the scenario after this one, in the order the list reads (review-column.js): `fn(scenarioId)` gives the scenario or null */
|
|
329
|
+
let nextScenarioOf = null;
|
|
330
|
+
export function setNextScenario(fn) { nextScenarioOf = typeof fn === 'function' ? fn : null; }
|
|
331
|
+
|
|
254
332
|
// The viewer's speed: a setting of theirs, kept for the next scenario and the next visit
|
|
255
333
|
function readSpeed() {
|
|
256
334
|
try { return parseSpeed(window.localStorage.getItem(SPEED_KEY)); } catch { return parseSpeed(null); }
|
|
@@ -270,6 +348,12 @@ function chooseSpeed(value) {
|
|
|
270
348
|
function act(action) {
|
|
271
349
|
if (!player) return;
|
|
272
350
|
if (action === 'scenario-close') return stopScenario();
|
|
351
|
+
if (action === 'scenario-next-scenario') {
|
|
352
|
+
// the end of a scenario: nothing advances by itself; this is the reviewer's choice, and it starts the next one in the list's order
|
|
353
|
+
const next = nextScenarioOf ? nextScenarioOf(player.scenario().id) : null;
|
|
354
|
+
if (next) playScenario(next);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
273
357
|
if (action === 'scenario-toggle') {
|
|
274
358
|
const s = player.snapshot();
|
|
275
359
|
if (s.playing) player.pause(); else player.play();
|
|
@@ -289,14 +373,27 @@ function updateBar(snap) {
|
|
|
289
373
|
// this runs every frame: a live region is written only when its words change, so a step is said once, not once a frame
|
|
290
374
|
const put = (cls, text) => { const el = q(cls); if (el.textContent !== text) el.textContent = text; };
|
|
291
375
|
put('.hx-player-title', snap.title);
|
|
376
|
+
bar.setAttribute('aria-label', `Scenario player: ${snap.title}`);
|
|
292
377
|
put('.hx-player-count', `${Math.min(snap.index + 1, Math.max(snap.total, 1))} of ${snap.total}`);
|
|
293
|
-
|
|
378
|
+
const actor = snap.current.actor ? personaLabel(personaFor(state.nodes, snap.current.actor)) || snap.current.actor : '';
|
|
379
|
+
put('.hx-player-who', actor && !snap.done ? `As ${actor} · ` : '');
|
|
380
|
+
put('.hx-player-step', snap.done ? 'Played to the end' : snap.current.text);
|
|
381
|
+
bar.dataset.done = String(!!snap.done);
|
|
294
382
|
const toggle = q('[data-action=scenario-toggle]');
|
|
295
|
-
|
|
383
|
+
const label = snap.playing ? t('pause') : snap.done ? t('playAgain') : t('play');
|
|
384
|
+
put('[data-action=scenario-toggle] .hx-player-label', label);
|
|
385
|
+
toggle.dataset.state = snap.playing ? 'playing' : snap.done ? 'done' : 'paused';
|
|
296
386
|
toggle.disabled = snap.total === 0 || snap.manual;
|
|
297
387
|
toggle.title = snap.manual ? 'The time for each step is Manual: use Next' : '';
|
|
298
388
|
q('[data-action=scenario-prev]').disabled = snap.index === 0 && !snap.done;
|
|
299
|
-
q('[data-action=scenario-next]')
|
|
389
|
+
const next = q('[data-action=scenario-next]');
|
|
390
|
+
next.disabled = snap.done || snap.total === 0;
|
|
391
|
+
// at the end: Play again and Next scenario (the next one in the list's order); nothing carries on by itself
|
|
392
|
+
const following = snap.done && nextScenarioOf ? nextScenarioOf(snap.id) : null;
|
|
393
|
+
q('[data-action=scenario-next-scenario]').hidden = !following;
|
|
394
|
+
next.hidden = !!following;
|
|
395
|
+
// the one polite line: a step as the list says it ("Step 2 of 3, as Adult: checkout page, Added. You pay. Allowed.")
|
|
396
|
+
put('.hx-player-says', snap.done ? `${snap.title}: played to the end.` : currentStepSentence({ snap, nodes: state.nodes, edges: state.edges, words: { notChecked: t('notChecked') } }));
|
|
300
397
|
const fill = snap.total ? Math.round(((snap.done ? snap.total : snap.index + snap.progress) / snap.total) * 1000) / 10 : 0;
|
|
301
398
|
if (fill !== lastFill) { lastFill = fill; q('.hx-player-fill').style.width = `${fill}%`; }
|
|
302
399
|
paintChecks(bar, snap);
|
|
@@ -314,9 +411,9 @@ function typingIn(target) {
|
|
|
314
411
|
function onKeydown(e) {
|
|
315
412
|
if (e.key === 'Escape' && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
316
413
|
if (player && !typingIn(e.target) && !otherPopupOpen()) { e.preventDefault(); stopScenario(); return; } // Escape closes the scenario; focus goes back to Play
|
|
317
|
-
if (!player && list && !list.hidden && list.contains(document.activeElement)) { e.preventDefault(); closeList(true); return; }
|
|
318
414
|
}
|
|
319
415
|
if (!player || e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || typingIn(e.target)) return;
|
|
416
|
+
if ((e.key === ' ' || e.code === 'Space') && e.target.closest?.('#review-column')) return; // Space on a step or a row presses it
|
|
320
417
|
const action = e.key === ' ' || e.code === 'Space' ? 'scenario-toggle' : e.key === 'ArrowLeft' ? 'scenario-prev' : e.key === 'ArrowRight' ? 'scenario-next' : null;
|
|
321
418
|
if (!action) return;
|
|
322
419
|
e.preventDefault(); // space on a focused button would press it as well
|
|
@@ -333,98 +430,6 @@ function onKeyup(e) {
|
|
|
333
430
|
if (player && (e.key === ' ' || e.code === 'Space') && !typingIn(e.target)) e.preventDefault();
|
|
334
431
|
}
|
|
335
432
|
|
|
336
|
-
// ---------------------------------------------------------------------------
|
|
337
|
-
// The scenario list
|
|
338
|
-
// ---------------------------------------------------------------------------
|
|
339
|
-
/** The open proposal's scenarios, with the maintainer's what-if edits in (`state.effectiveProposal`) when there are any */
|
|
340
|
-
const proposalScenarios = () => {
|
|
341
|
-
const p = state.effectiveProposal || state.proposal;
|
|
342
|
-
return p && Array.isArray(p.scenarios) ? p.scenarios : [];
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Where the list goes: a row of the open proposal's bar, under its title row, so the list
|
|
347
|
-
* opens in the bar's own flow and the bar grows to hold it (as a second box at the stage's corner
|
|
348
|
-
* it opened underneath the bar and was covered). Without a bar it is a box at the stage's corner.
|
|
349
|
-
*/
|
|
350
|
-
function mountList() {
|
|
351
|
-
const body = document.getElementById('proposal-body');
|
|
352
|
-
const stage = $stage();
|
|
353
|
-
if (!body) {
|
|
354
|
-
if (stage && list.parentElement !== stage) stage.appendChild(list);
|
|
355
|
-
} else if (list.parentElement !== body) {
|
|
356
|
-
const summary = document.getElementById('proposal-summary');
|
|
357
|
-
if (summary && summary.parentElement === body) body.insertBefore(list, summary);
|
|
358
|
-
else body.appendChild(list);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
const wiredPlay = new WeakSet();
|
|
363
|
-
|
|
364
|
-
/** The toolbar's Play button: shown while the open proposal has scenarios and none plays; with one it plays it, with several it opens the list */
|
|
365
|
-
function paintPlay(show) {
|
|
366
|
-
const btn = document.getElementById('proposal-play');
|
|
367
|
-
if (!btn) return;
|
|
368
|
-
btn.hidden = !show;
|
|
369
|
-
// with one scenario Play plays it, so it expands nothing
|
|
370
|
-
if (proposalScenarios().length > 1) btn.setAttribute('aria-expanded', String(!!list && !list.hidden)); else btn.removeAttribute('aria-expanded');
|
|
371
|
-
if (wiredPlay.has(btn)) return;
|
|
372
|
-
wiredPlay.add(btn);
|
|
373
|
-
btn.addEventListener('click', () => {
|
|
374
|
-
const scenarios = proposalScenarios();
|
|
375
|
-
if (scenarios.length === 1) playScenario(scenarios[0]);
|
|
376
|
-
else if (list) {
|
|
377
|
-
if (list.hidden) { list.hidden = false; btn.setAttribute('aria-expanded', 'true'); list.querySelector('button')?.focus(); } // the first row of what opened
|
|
378
|
-
else closeList(false);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/** Folds the scenario list back onto Play; `refocus` gives Play the focus (Escape from inside the list) */
|
|
384
|
-
function closeList(refocus) {
|
|
385
|
-
if (list) list.hidden = true;
|
|
386
|
-
const btn = document.getElementById('proposal-play');
|
|
387
|
-
if (!btn) return;
|
|
388
|
-
btn.setAttribute('aria-expanded', 'false');
|
|
389
|
-
if (refocus) btn.focus();
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/** Shows or hides the Play button and its list to match the open proposal's scenarios (and hides them while one plays: the player is the control then) */
|
|
393
|
-
export function refreshList() {
|
|
394
|
-
const stage = $stage();
|
|
395
|
-
const scenarios = proposalScenarios();
|
|
396
|
-
const show = !!stage && scenarios.length > 0 && !player;
|
|
397
|
-
if (!show) { if (list) { list.remove(); list = null; } paintPlay(false); return; }
|
|
398
|
-
const key = scenarios.map((s) => `${s.id}\u0000${s.title}\u0000${(s.steps || []).length}`).join('\u0001');
|
|
399
|
-
if (list && list.dataset.key === key) { mountList(); paintPlay(true); return; }
|
|
400
|
-
const wasOpen = !!list && !list.hidden;
|
|
401
|
-
if (list) list.remove();
|
|
402
|
-
list = document.createElement('div');
|
|
403
|
-
list.id = 'proposal-scenarios';
|
|
404
|
-
list.className = 'hx-scenarios glass';
|
|
405
|
-
list.dataset.corn = 'scenario-list';
|
|
406
|
-
list.dataset.key = key;
|
|
407
|
-
list.hidden = !!document.getElementById('proposal-play') && (!wasOpen || scenarios.length < 2); // behind Play when the toolbar has one
|
|
408
|
-
scenarios.forEach((s) => {
|
|
409
|
-
const button = document.createElement('button');
|
|
410
|
-
button.type = 'button';
|
|
411
|
-
button.className = 'hx-scenarios-item';
|
|
412
|
-
button.dataset.corn = 'row';
|
|
413
|
-
button.dataset.scenario = s.id;
|
|
414
|
-
const steps = (s.steps || []).length;
|
|
415
|
-
button.textContent = `${s.title} · ${steps} ${steps === 1 ? 'step' : 'steps'}`;
|
|
416
|
-
list.appendChild(button);
|
|
417
|
-
});
|
|
418
|
-
list.addEventListener('click', (e) => {
|
|
419
|
-
const button = e.target.closest('[data-scenario]');
|
|
420
|
-
if (!button) return;
|
|
421
|
-
const scenario = proposalScenarios().find((s) => s.id === button.dataset.scenario);
|
|
422
|
-
if (scenario) playScenario(scenario);
|
|
423
|
-
});
|
|
424
|
-
mountList();
|
|
425
|
-
paintPlay(true);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
433
|
// ---------------------------------------------------------------------------
|
|
429
434
|
// /?scenario-demo=1: a small scenario over real nodes, for looking at the player before a proposal exists
|
|
430
435
|
// ---------------------------------------------------------------------------
|
|
@@ -474,10 +479,8 @@ export function initScenarioUi() {
|
|
|
474
479
|
wired = true;
|
|
475
480
|
document.addEventListener('keydown', onKeydown);
|
|
476
481
|
document.addEventListener('keyup', onKeyup);
|
|
477
|
-
onSceneTouch(refreshList);
|
|
478
482
|
// A sheet that opened or closed changes what the map shows: keep the step in view
|
|
479
483
|
onCoveredChange(() => { if (player && state.scenario) followStep(player.snapshot()); });
|
|
480
484
|
// Taking hold of the map (a drag, the wheel, a pinch) ends the camera's glide: the camera is theirs
|
|
481
|
-
for (const type of ['pointerdown', 'wheel', 'touchstart', 'mousedown']) document.addEventListener(type, (e) => { if (e.target === state.canvas) glide = null; }, { passive: true, capture: true });
|
|
482
|
-
refreshList();
|
|
485
|
+
for (const type of ['pointerdown', 'wheel', 'touchstart', 'mousedown']) document.addEventListener(type, (e) => { if (e.target === state.canvas) { glide = null; held = true; } }, { passive: true, capture: true });
|
|
483
486
|
}
|
package/explorer/sheet-model.js
CHANGED
|
@@ -1,47 +1,95 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/sheet-model
|
|
3
3
|
*
|
|
4
|
-
* The state machine of the phone's bottom sheets (TOPO-18), with no DOM: which sheets exist,
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The state machine of the phone's bottom sheets (TOPO-18, spec 0010 D7), with no DOM: which sheets exist, which are open, and which one is
|
|
5
|
+
* expanded. sheets.js puts this on the page.
|
|
6
|
+
*
|
|
7
|
+
* - Every sheet starts as a **peek** (a handle and a line or two). At most one is **expanded**; expanding one folds the sheets of the *other*
|
|
8
|
+
* group to a **stub** (one 44px row with a title and a badge). Tapping a stub expands it, and the one that was expanded becomes the stub.
|
|
9
|
+
* - **At most two sheets are open**: the *review* (the proposal bar, or the scenario player) and one *other* (Work, or the node panel).
|
|
10
|
+
* Opening Work displaces the node panel, and the reverse (`show` says which sheets it displaced); the node stays selected.
|
|
11
|
+
* - **The map keeps at least 35% of the screen** in every state (`sheetCap`): an expanded sheet's height is capped to leave it.
|
|
7
12
|
*/
|
|
8
13
|
|
|
14
|
+
/** The map keeps at least this share of the screen's height (spec 0010 D7) */
|
|
15
|
+
export const MAP_FLOOR = 0.35;
|
|
16
|
+
/** The height of a stub, in px: a row a thumb can hit */
|
|
17
|
+
export const STUB_PX = 44;
|
|
18
|
+
|
|
19
|
+
/** The groups: the sheets of the review, and the one other sheet (open one at a time) */
|
|
20
|
+
export const SHEET_GROUPS = Object.freeze({ proposal: 'review', player: 'review', forge: 'other', drawer: 'other' });
|
|
21
|
+
/** Groups that hold one open sheet at most: opening one displaces the other */
|
|
22
|
+
const EXCLUSIVE = new Set(['other']);
|
|
23
|
+
|
|
24
|
+
/** The tallest an expanded sheet may be, in px, for a screen `viewportPx` tall with `stubs` stubs under or over it: the rest is the map's 35% */
|
|
25
|
+
export const sheetCap = (viewportPx, stubs = 0) => Math.max(0, Math.floor(viewportPx - Math.ceil(viewportPx * MAP_FLOOR) - stubs * STUB_PX));
|
|
26
|
+
|
|
27
|
+
/** The map's smallest share of the screen, in px, for a screen `viewportPx` tall */
|
|
28
|
+
export const mapFloorPx = (viewportPx) => Math.ceil(viewportPx * MAP_FLOOR);
|
|
29
|
+
|
|
9
30
|
/**
|
|
31
|
+
* @param {Record<string, string>} [groups] the group of each sheet id (a sheet not named is its own group)
|
|
10
32
|
* @returns {{
|
|
11
33
|
* add(id: string): void, remove(id: string): void, has(id: string): boolean,
|
|
34
|
+
* show(id: string): string[], hide(id: string): void, isShown(id: string): boolean, shown(): string[],
|
|
12
35
|
* expand(id: string): boolean, collapse(id: string): boolean, collapseAll(): boolean, toggle(id: string): boolean,
|
|
13
|
-
* isExpanded(id: string): boolean, expanded(): string|null, ids(): string[],
|
|
14
|
-
* }} every change method answers whether anything changed
|
|
36
|
+
* isExpanded(id: string): boolean, expanded(): string|null, stateOf(id: string): 'expanded'|'peek'|'stub'|'hidden'|undefined, stubs(): number, ids(): string[],
|
|
37
|
+
* }} every change method answers whether anything changed (`show`: the ids it displaced)
|
|
15
38
|
*/
|
|
16
|
-
export function createSheetModel() {
|
|
39
|
+
export function createSheetModel(groups = SHEET_GROUPS) {
|
|
17
40
|
const known = new Set();
|
|
18
|
-
|
|
41
|
+
const open = new Set(); // the sheets that are open (a sheet is open from `add` until `hide`)
|
|
42
|
+
let expandedId = null;
|
|
43
|
+
const groupOf = (id) => groups[id] || id;
|
|
19
44
|
return {
|
|
20
|
-
add: (id) => { known.add(id); },
|
|
21
|
-
remove: (id) => { known.delete(id); if (
|
|
45
|
+
add: (id) => { known.add(id); open.add(id); },
|
|
46
|
+
remove: (id) => { known.delete(id); open.delete(id); if (expandedId === id) expandedId = null; },
|
|
22
47
|
has: (id) => known.has(id),
|
|
48
|
+
/** Opens a sheet. In an exclusive group the other open sheet is displaced (closed): its id is returned */
|
|
49
|
+
show(id) {
|
|
50
|
+
if (!known.has(id)) return [];
|
|
51
|
+
open.add(id);
|
|
52
|
+
if (!EXCLUSIVE.has(groupOf(id))) return [];
|
|
53
|
+
const gone = [...open].filter((o) => o !== id && groupOf(o) === groupOf(id));
|
|
54
|
+
for (const g of gone) { open.delete(g); if (expandedId === g) expandedId = null; }
|
|
55
|
+
return gone;
|
|
56
|
+
},
|
|
57
|
+
hide(id) { open.delete(id); if (expandedId === id) expandedId = null; },
|
|
58
|
+
isShown: (id) => open.has(id),
|
|
59
|
+
shown: () => [...open],
|
|
23
60
|
expand(id) {
|
|
24
|
-
if (!known.has(id) || open === id) return false;
|
|
25
|
-
|
|
61
|
+
if (!known.has(id) || !open.has(id) || expandedId === id) return false;
|
|
62
|
+
expandedId = id;
|
|
26
63
|
return true;
|
|
27
64
|
},
|
|
28
65
|
collapse(id) {
|
|
29
|
-
if (
|
|
30
|
-
|
|
66
|
+
if (expandedId !== id) return false;
|
|
67
|
+
expandedId = null;
|
|
31
68
|
return true;
|
|
32
69
|
},
|
|
33
70
|
collapseAll() {
|
|
34
|
-
if (
|
|
35
|
-
|
|
71
|
+
if (expandedId === null) return false;
|
|
72
|
+
expandedId = null;
|
|
36
73
|
return true;
|
|
37
74
|
},
|
|
38
75
|
toggle(id) {
|
|
39
|
-
if (!known.has(id)) return false;
|
|
40
|
-
|
|
76
|
+
if (!known.has(id) || !open.has(id)) return false;
|
|
77
|
+
expandedId = expandedId === id ? null : id;
|
|
41
78
|
return true;
|
|
42
79
|
},
|
|
43
|
-
isExpanded: (id) =>
|
|
44
|
-
expanded: () =>
|
|
80
|
+
isExpanded: (id) => expandedId === id,
|
|
81
|
+
expanded: () => expandedId,
|
|
82
|
+
/** `stub` for an open sheet of the other group while one is expanded; `peek` otherwise; undefined for a sheet that is not known */
|
|
83
|
+
stateOf(id) {
|
|
84
|
+
if (!known.has(id)) return undefined;
|
|
85
|
+
if (!open.has(id)) return 'hidden';
|
|
86
|
+
if (expandedId === id) return 'expanded';
|
|
87
|
+
return expandedId !== null && groupOf(expandedId) !== groupOf(id) ? 'stub' : 'peek';
|
|
88
|
+
},
|
|
89
|
+
/** How many stubs there are now */
|
|
90
|
+
stubs() {
|
|
91
|
+
return [...open].filter((id) => expandedId !== null && id !== expandedId && groupOf(id) !== groupOf(expandedId)).length;
|
|
92
|
+
},
|
|
45
93
|
ids: () => [...known],
|
|
46
94
|
};
|
|
47
95
|
}
|