cornfield 0.48.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/strings.js +14 -0
- package/explorer/check.js +7 -227
- package/explorer/connection.js +3 -3
- package/explorer/css/review.css +49 -0
- package/explorer/decision-model.js +6 -0
- package/explorer/engine/checks.js +252 -0
- package/explorer/engine/connection.js +36 -0
- package/explorer/engine/layers.js +1 -0
- package/explorer/engine/layout.js +8 -3
- package/explorer/engine/player.js +489 -0
- package/explorer/engine/proposal.js +373 -0
- package/explorer/engine/render.js +1 -0
- package/explorer/engine/sheets.js +40 -7
- package/explorer/engine/source.js +315 -0
- package/explorer/engine/theme-sheet.js +444 -0
- package/explorer/engine/topology.js +126 -0
- package/explorer/index.html +6 -59
- package/explorer/instance.js +87 -7
- package/explorer/page-address.js +59 -0
- package/explorer/page-pieces.js +33 -5
- package/explorer/page.js +20 -20
- package/explorer/panels.js +1 -3
- package/explorer/pieces/changes.js +495 -0
- package/explorer/pieces/decision.js +664 -0
- package/explorer/pieces/layers.js +4 -0
- package/explorer/pieces/map.js +117 -25
- package/explorer/pieces/node-panel.js +34 -1
- package/explorer/pieces/proposal.js +488 -0
- package/explorer/pieces/review.js +280 -0
- package/explorer/pieces/scope-link.js +50 -0
- package/explorer/pieces/scope.js +247 -0
- package/explorer/pieces/status.css +24 -0
- package/explorer/pieces/status.js +144 -0
- package/explorer/plugins.js +0 -10
- package/explorer/proposal.js +64 -697
- package/explorer/review-column.js +24 -439
- package/explorer/review.js +27 -673
- package/explorer/scenario-ui.js +32 -478
- package/explorer/sheets.js +8 -7
- package/explorer/view.js +12 -64
- package/explorer/waiting-line.js +7 -50
- package/package.json +1 -1
|
@@ -1,448 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/review-column
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* sheet's body, with a two-part switch at its top (Changes | Scenarios). Its foot, `#review-decision`, is the decision: Send back and
|
|
8
|
-
* Approve (review.js) and, in spec 0007, the line that says what Approve does. Nothing about the decision is decided here.
|
|
9
|
-
*
|
|
10
|
-
* Changes · 6 one row for each marked node and edge: a button that selects it and frames it (proposal.js `proposal-focus`)
|
|
11
|
-
* Personas and scenarios · 3 an h4 for each persona, then its scenarios; a scenario is a disclosure
|
|
12
|
-
* Adult · 1 scenario
|
|
13
|
-
* ▾ An adult pays for the basket its steps as a numbered list: who acts, the node, its mark, the text, the verdict
|
|
14
|
-
* Not in any scenario: Child the personas on the map that act in no scenario of this proposal
|
|
15
|
-
*
|
|
16
|
-
* Choosing a step opens the player (scenario-ui.js) paused on it, and the camera goes to the step's node in the part of the map the
|
|
17
|
-
* column leaves free (sheets.js `visibleMapRect`). The list follows the player: its current step is `aria-current="step"`.
|
|
18
|
-
* Focus never falls to the page: a repaint puts it back on the same control, and closing the player gives it to the step it was on.
|
|
19
|
-
*
|
|
20
|
-
* The lists are drawn from `scenario-list-model.js` (pure, tested in Node). Every word a project's files supplied (persona labels,
|
|
21
|
-
* scenario titles, step text) is escaped on the way in; an id that reaches an element id or a `data-*` value is made safe first.
|
|
22
|
-
* What was seen (a tick per scenario) is kept in the browser's storage, per proposal and PR head: information only, never in the review.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { state, escHtml } from './state.js';
|
|
26
|
-
import { t } from './strings.js';
|
|
27
|
-
import { markStateAttr } from './corn-state.js';
|
|
28
|
-
import { isPhone, expandSheet, PHONE_QUERY } from './sheets.js';
|
|
29
|
-
import { pullNumberOf } from './proposal-model.js';
|
|
30
|
-
import { closeDrawer } from './panels.js';
|
|
31
|
-
import { onLayersChange } from './layers.js';
|
|
32
|
-
import { playScenario, getPlayer, onPlayerChange, setCloseFocus, setNextScenario, setKeepChecksOnClose, layersHiding } from './scenario-ui.js';
|
|
33
|
-
import { openChecks, closeChecks, scenarioVerdicts, checkedScenarioId } from './check.js';
|
|
34
|
-
import { buildScenarioList, changeRows, stepSentence, reviewCounts, reviewOpenedWords, seenKey, readSeen, writeSeen } from './scenario-list-model.js';
|
|
35
|
-
|
|
36
|
-
const $ = (id) => document.getElementById(id);
|
|
37
|
-
const TAB_KEY = 'cornfield.reviewTab';
|
|
38
|
-
/** The narrowest map area that holds the column (400px), the player bar and the node panel (480px) side by side */
|
|
39
|
-
const PLAYER_BESIDE_PANEL = 1360;
|
|
40
|
-
|
|
41
|
-
/** What the column shows apart from the proposal: the scenario whose steps are open, the phone's tab, the PR head the record is keyed by */
|
|
42
|
-
const ui = { checks: 0, open: null, tab: null, tabNow: null, tabFor: '', openFor: '', head: '', headFor: '', current: null, lastStep: null, seen: { played: [], read: [] }, seenFor: '', pending: [] };
|
|
43
|
-
let wiredRoot = null;
|
|
44
|
-
|
|
45
|
-
const asList = (v) => (Array.isArray(v) ? v : []);
|
|
46
|
-
const storage = () => { try { return window.localStorage; } catch { return null; } };
|
|
47
|
-
|
|
48
|
-
// ---------------------------------------------------------------------------
|
|
49
|
-
// What is shown, from the open proposal
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
|
|
52
|
-
/** The open proposal's scenarios, with the maintainer's what-if edits in */
|
|
53
|
-
const scenariosNow = () => {
|
|
54
|
-
const p = state.effectiveProposal || state.proposal;
|
|
55
|
-
return p && Array.isArray(p.scenarios) ? p.scenarios : [];
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/** The open proposal, as the record and the phone's tab know it: its source and its name */
|
|
59
|
-
const proposalKey = () => `${state.proposalSource || ''}/${state.proposalSlug || ''}`;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The browser key the open proposal's record is kept under, or null while it cannot be known: a PR's copy is kept per PR head,
|
|
63
|
-
* and until the PR has been read its head is not known (what is seen meanwhile is held in memory, then kept under the head)
|
|
4
|
+
* A bridge (spec 0011 D2 and D3, step 5): the review column is now a piece (pieces/changes.js). This file keeps the old names for the modules that are
|
|
5
|
+
* not yet on an instance (forge-panel.js, tests), bound to the page's instance and to the piece the page mounts. It goes when the last of those callers
|
|
6
|
+
* is converted.
|
|
64
7
|
*/
|
|
65
|
-
function recordKey() {
|
|
66
|
-
if (pullNumberOf(state.proposalSource)) return ui.headFor === proposalKey() && ui.head ? seenKey(state.proposalSource, state.proposalSlug, ui.head) : null;
|
|
67
|
-
return seenKey(state.proposalSource, state.proposalSlug, '');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** The record of what this browser saw, read again when the proposal (or its PR head) is another */
|
|
71
|
-
function refreshSeen() {
|
|
72
|
-
const key = recordKey();
|
|
73
|
-
const id = key || `pending:${proposalKey()}`;
|
|
74
|
-
if (ui.seenFor === id) return;
|
|
75
|
-
const was = ui.seenFor;
|
|
76
|
-
ui.seenFor = id;
|
|
77
|
-
if (!key) { ui.seen = { played: [], read: [] }; ui.pending = []; return; }
|
|
78
|
-
ui.seen = readSeen(storage(), key);
|
|
79
|
-
// what was seen of this proposal before its PR head was known is kept under the head now
|
|
80
|
-
if (was === `pending:${proposalKey()}`) for (const [scenario, how] of ui.pending) ui.seen = writeSeen(storage(), key, scenario, how);
|
|
81
|
-
ui.pending = [];
|
|
82
|
-
}
|
|
83
8
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
refreshSeen();
|
|
87
|
-
if (ui.seenFor.startsWith('pending:')) {
|
|
88
|
-
ui.pending.push([String(scenarioId), how]);
|
|
89
|
-
ui.seen = writeSeen(null, '', scenarioId, how, ui.seen);
|
|
90
|
-
} else ui.seen = writeSeen(storage(), ui.seenFor, scenarioId, how);
|
|
91
|
-
}
|
|
9
|
+
import { pageInstance } from './state.js';
|
|
10
|
+
import { pagePiece, setPagePieceOptions } from './page-pieces.js';
|
|
92
11
|
|
|
93
|
-
|
|
94
|
-
export function setPullHead(sha) {
|
|
95
|
-
const head = typeof sha === 'string' ? sha : '';
|
|
96
|
-
if (head === ui.head && ui.headFor === proposalKey()) return;
|
|
97
|
-
ui.head = head;
|
|
98
|
-
ui.headFor = proposalKey();
|
|
99
|
-
if (state.proposal) repaint();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function model() {
|
|
103
|
-
refreshSeen();
|
|
104
|
-
const verdicts = new Map();
|
|
105
|
-
const id = checkedScenarioId();
|
|
106
|
-
if (id !== null) verdicts.set(id, scenarioVerdicts());
|
|
107
|
-
const proposal = state.effectiveProposal || state.proposal;
|
|
108
|
-
const words = { notChecked: t('notChecked') };
|
|
109
|
-
const byId = new Map(state.nodes.map((n) => [n.id, n]));
|
|
110
|
-
const hidden = (id) => byId.has(id) && layersHiding(byId.get(id)).length > 0;
|
|
111
|
-
return buildScenarioList({ scenarios: scenariosNow(), nodes: state.nodes, edges: state.edges, proposal, verdicts, seen: ui.seen, words, hidden });
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** The proposal's own changes: the reviewer's what-if edits are a group of their own (spec 0007 D5), never counted into them */
|
|
115
|
-
const theirRows = (proposal) => changeRows(state.nodes, state.edges, proposal).filter((r) => r.mark !== 'edit');
|
|
12
|
+
const piece = () => pagePiece('changes');
|
|
116
13
|
|
|
14
|
+
/** Mounts the column where the page has its place (page.js does; a second call does nothing) */
|
|
15
|
+
export function initReviewColumn() { piece(); }
|
|
16
|
+
/** Draws the column for the open proposal, or hides it when none is open */
|
|
17
|
+
export function renderReviewColumn() { const p = piece(); if (p) p.renderColumn(); }
|
|
18
|
+
export function shareRoom() { const p = piece(); if (p) p.shareRoom(); }
|
|
19
|
+
/** The PR head the record is keyed by */
|
|
20
|
+
export function setPullHead(sha) { const p = piece(); if (p) p.setPullHead(sha); }
|
|
21
|
+
/** The counts' parts open their section */
|
|
22
|
+
export function showSection(which) { pageInstance().emit('changes:show', which); }
|
|
117
23
|
/** What opening a proposal says: "Opened Checkout: 6 changes, 3 scenarios for 2 personas." */
|
|
118
|
-
export function reviewOpenedLine(title) {
|
|
119
|
-
const proposal = state.effectiveProposal || state.proposal;
|
|
120
|
-
return reviewOpenedWords(title, theirRows(proposal).length, model());
|
|
121
|
-
}
|
|
122
|
-
|
|
24
|
+
export function reviewOpenedLine(title) { const p = piece(); return p ? p.openedLine(title) : ''; }
|
|
123
25
|
/** The phone's peek line: "6 changes · 3 scenarios for 2 personas" */
|
|
124
|
-
export function reviewPeekLine() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
/** "Changes · 6": a dot for the eye and a comma for a screen reader, so the heading reads "Changes, 6" */
|
|
134
|
-
const countHeading = (label, n) => `${escHtml(label)}<span aria-hidden="true"> · </span><span class="hx-sr-only">, </span><span data-corn="count">${n}</span>`;
|
|
135
|
-
|
|
136
|
-
function changeRowHtml(r) {
|
|
137
|
-
const label = `${r.word} ${r.name}, ${r.type}`;
|
|
138
|
-
return `<li><button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="${r.kind}" data-key="${escHtml(r.key)}" data-focus-key="ch:${escHtml(r.kind)}:${escHtml(r.key)}" data-corn="row" aria-label="${escHtml(label)}"><span class="hx-mark-dot hx-mark-dot--${r.mark}" data-corn="mark-dot"${markStateAttr(r.mark)} aria-hidden="true"></span><span class="hx-change-what">${escHtml(r.word)}</span><span class="hx-name">${escHtml(r.name)}</span><span class="hx-faint">${escHtml(r.type)}</span></button></li>`;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function stepHtml(sc, step, group, total) {
|
|
142
|
-
const current = ui.current && ui.current.index === sc.index && ui.current.step === step.index && ui.current.id === sc.id;
|
|
143
|
-
const pill = step.verdict ? `<span class="hx-step-verdict" data-corn="state-pill" data-tone="${escHtml(step.verdict.tone)}"${step.verdict.state ? ` data-corn-state="${step.verdict.state}"` : ''}>${escHtml(step.verdict.words)}</span>` : '';
|
|
144
|
-
const mark = step.mark ? `<span class="hx-step-mark"><span class="hx-mark-dot hx-mark-dot--${step.mark}" data-corn="mark-dot"${markStateAttr(step.mark)} aria-hidden="true"></span>${escHtml(step.markWord)}</span>` : '';
|
|
145
|
-
const who = step.actorLabel ? `<span class="hx-step-who">As ${escHtml(step.actorLabel)}</span>` : '';
|
|
146
|
-
return `<li><button type="button" class="hx-step" data-corn="step" data-action="scenario-step" data-scenario-index="${sc.index}" data-step-index="${step.index}" data-focus-key="st:${group.key}:${sc.key}:${step.index}" aria-label="${escHtml(stepSentence(step, total))}"${current ? ' aria-current="step"' : ''}>`
|
|
147
|
-
+ `<span class="hx-step-n" aria-hidden="true">${step.number}</span><span class="hx-step-body"><span class="hx-step-line">${who}<span class="hx-step-where">${escHtml(step.where)}</span>${mark}${step.layerOff ? '<span class="hx-step-off">Layer off: shown when played</span>' : ''}</span>`
|
|
148
|
-
+ `<span class="hx-step-text">${escHtml(step.text)}</span></span>${pill}</button></li>`;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function scenarioHtml(sc, group) {
|
|
152
|
-
const open = ui.open === sc.id;
|
|
153
|
-
const stepsId = `rc-steps-${group.key}-${sc.key}`;
|
|
154
|
-
const tick = sc.seen ? `<span class="hx-sc-seen" data-seen="${sc.seen}">${sc.seen === 'played' ? '✓ Played' : '✓ Read'}</span>` : '';
|
|
155
|
-
const done = sc.verdictSummary ? ` · ${escHtml(sc.verdictSummary)}` : '';
|
|
156
|
-
// its checks are asked when it is opened, but while another scenario plays the checks are that one's: say so rather than show steps with no verdict
|
|
157
|
-
const waits = open && playingOther(sc.id) && sc.steps.some((st) => st.actor) ? `<p class="hx-faint hx-rc-note hx-sc-waits" data-corn="notice">Not checked while another scenario plays. Close the player, or choose a step here to play this one.</p>` : '';
|
|
158
|
-
return `<li class="hx-sc" data-open="${open}"><button type="button" class="hx-sc-row" data-corn="row" data-action="scenario-open" data-scenario-index="${sc.index}" data-focus-key="sc:${group.key}:${sc.key}" aria-expanded="${open}" aria-controls="${stepsId}">`
|
|
159
|
-
+ `<span class="hx-sc-caret" aria-hidden="true">${open ? '▾' : '▸'}</span><span class="hx-sc-main"><span class="hx-sc-title">${escHtml(sc.title)}</span><span class="hx-sc-meta">${escHtml(sc.summary)}${done}</span></span>${tick}</button>${waits}`
|
|
160
|
-
+ `<ol class="hx-steps" id="${stepsId}" data-corn="step-list" aria-label="${escHtml(t('steps'))}: ${escHtml(sc.title)}"${open ? '' : ' hidden'}>${open ? sc.steps.map((s) => stepHtml(sc, s, group, sc.steps.length)).join('') : ''}</ol></li>`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function groupHtml(g) {
|
|
164
|
-
const n = g.scenarios.length;
|
|
165
|
-
const name = g.anyone ? t('anyone') : g.label;
|
|
166
|
-
const heading = `${escHtml(name)}<span aria-hidden="true"> · </span><span class="hx-sr-only">, </span>${n} ${n === 1 ? 'scenario' : 'scenarios'}`;
|
|
167
|
-
return `<div class="hx-persona" data-corn="persona-group" data-persona="${escHtml(g.key)}"><h4 class="hx-persona-name">${heading}</h4><ul class="hx-sc-list">${g.scenarios.map((sc) => scenarioHtml(sc, g)).join('')}</ul></div>`;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** Everything the two lists say, as markup (the foot is static in index.html) */
|
|
171
|
-
function listsHtml() {
|
|
172
|
-
const proposal = state.effectiveProposal || state.proposal;
|
|
173
|
-
const everyRow = changeRows(state.nodes, state.edges, proposal);
|
|
174
|
-
const rows = everyRow.filter((r) => r.mark !== 'edit');
|
|
175
|
-
const mine = everyRow.filter((r) => r.mark === 'edit'); // "Your edits · 1": the first group, not the last row
|
|
176
|
-
const list = model();
|
|
177
|
-
const phone = isPhone();
|
|
178
|
-
// the phone's tab: the reviewer's last choice, or Scenarios when there are any; a proposal with none opens on its changes
|
|
179
|
-
if (ui.tabFor !== proposalKey()) { ui.tabFor = proposalKey(); ui.tabNow = list.total ? (ui.tab || 'scenarios') : 'changes'; }
|
|
180
|
-
const tab = ui.tabNow || 'changes';
|
|
181
|
-
const personas = state.nodes.some((n) => n.type === 'persona');
|
|
182
|
-
|
|
183
|
-
const tabs = `<div class="hx-rc-tabs" role="tablist" aria-label="Review" data-corn="tabs"${phone ? '' : ' hidden'}>`
|
|
184
|
-
+ `<button type="button" role="tab" id="rc-tab-changes" class="hx-rc-tab" data-corn="tab" data-action="review-tab" data-tab="changes" aria-selected="${tab === 'changes'}" aria-controls="rc-changes" tabindex="${tab === 'changes' ? 0 : -1}">${escHtml(t('changes'))} · ${rows.length}</button>`
|
|
185
|
-
+ `<button type="button" role="tab" id="rc-tab-scenarios" class="hx-rc-tab" data-corn="tab" data-action="review-tab" data-tab="scenarios" aria-selected="${tab === 'scenarios'}" aria-controls="rc-scenarios" tabindex="${tab === 'scenarios' ? 0 : -1}">${escHtml(t('scenarios'))} · ${list.total}</button></div>`;
|
|
186
|
-
|
|
187
|
-
const changes = `<section id="rc-changes" class="hx-rc-section" data-corn="proposal-changes"${phone ? ` role="tabpanel" aria-labelledby="rc-tab-changes"${tab === 'changes' ? '' : ' hidden'}` : ' aria-labelledby="rc-changes-h"'}>`
|
|
188
|
-
+ `<h3 id="rc-changes-h" class="hx-rc-h" tabindex="-1">${countHeading(t('changes'), rows.length)}</h3>`
|
|
189
|
-
+ (mine.length ? `<h4 class="hx-rc-sub">${countHeading(t('yourEdits'), mine.length)}</h4><ul class="hx-change-list">${mine.map(changeRowHtml).join('')}</ul>` : '')
|
|
190
|
-
+ (rows.length ? `<ul class="hx-change-list">${rows.map(changeRowHtml).join('')}</ul>` : '<p class="hx-faint hx-rc-empty">This proposal changes nothing on the map.</p>')
|
|
191
|
-
+ '</section>';
|
|
192
|
-
|
|
193
|
-
let body;
|
|
194
|
-
if (!list.total) body = '<p class="hx-faint hx-rc-empty">This proposal has no scenarios: there is nothing to walk through, and its changes are all it shows.</p>';
|
|
195
|
-
else {
|
|
196
|
-
body = list.groups.map(groupHtml).join('');
|
|
197
|
-
if (!personas) body += `<p class="hx-faint hx-rc-note">This map has no personas (topology.personas.json), so every scenario is listed under ${escHtml(t('anyone'))}.</p>`;
|
|
198
|
-
if (list.coverage) body += `<p class="hx-rc-coverage" data-corn="notice">${escHtml(t('notInAnyScenario'))}: ${list.notInAny.map(escHtml).join(', ')}</p>`;
|
|
199
|
-
}
|
|
200
|
-
const scenarios = `<section id="rc-scenarios" class="hx-rc-section" data-corn="scenario-list"${phone ? ` role="tabpanel" aria-labelledby="rc-tab-scenarios"${tab === 'scenarios' ? '' : ' hidden'}` : ' aria-labelledby="rc-scenarios-h"'}>`
|
|
201
|
-
+ `<h3 id="rc-scenarios-h" class="hx-rc-h" tabindex="-1">${countHeading(t('personasAndScenarios'), list.total)}</h3><div class="hx-rc-sbody">${body}</div></section>`;
|
|
202
|
-
return `${tabs}${changes}${scenarios}`;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// ---------------------------------------------------------------------------
|
|
206
|
-
// Painting: focus and scroll survive it
|
|
207
|
-
// ---------------------------------------------------------------------------
|
|
208
|
-
|
|
209
|
-
/** Where the column goes: after the proposal bar in the dock from 768px, at the end of the sheet's body on a phone */
|
|
210
|
-
function mountColumn() {
|
|
211
|
-
const col = $('review-column');
|
|
212
|
-
if (!col) return null;
|
|
213
|
-
const dock = $('sheet-dock');
|
|
214
|
-
const body = $('proposal-body');
|
|
215
|
-
if (isPhone() && body) { if (col.parentElement !== body) body.appendChild(col); } else if (dock) {
|
|
216
|
-
const bar = $('proposal-bar');
|
|
217
|
-
if (bar && col.parentElement !== dock) bar.after(col);
|
|
218
|
-
}
|
|
219
|
-
return col;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/** The column starts under the bar, whatever height the bar has (the counts wrap, the edit controls open): from 768px; a phone's has no place of its own */
|
|
223
|
-
function placeColumn() {
|
|
224
|
-
const col = $('review-column');
|
|
225
|
-
const bar = $('proposal-bar');
|
|
226
|
-
if (!col || !bar || isPhone() || bar.hidden) return;
|
|
227
|
-
col.style.setProperty('--hx-column-top', `${Math.round(bar.offsetTop + bar.offsetHeight + 8)}px`);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/** Draws the column for the open proposal, or hides it when none is open */
|
|
231
|
-
export function renderReviewColumn() {
|
|
232
|
-
const col = mountColumn();
|
|
233
|
-
if (!col) return;
|
|
234
|
-
const open = !!state.proposal;
|
|
235
|
-
col.hidden = !open;
|
|
236
|
-
if (!open) { ui.open = null; ui.current = null; ui.lastStep = null; closeChecksIfIdle(); const lists = $('review-lists'); if (lists) lists.innerHTML = ''; return; }
|
|
237
|
-
wire(col);
|
|
238
|
-
repaint();
|
|
239
|
-
placeColumn();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* From 768px both lists share the column's height. The changes take what they need, up to 40% while the scenarios need the rest;
|
|
244
|
-
* when the scenarios are few, the changes take the room they leave (no gap under a short list while the changes scroll). Measured,
|
|
245
|
-
* because the split depends on how tall the scenario list is: the result is two CSS variables on the column.
|
|
246
|
-
*/
|
|
247
|
-
export function shareRoom() {
|
|
248
|
-
const col = $('review-column');
|
|
249
|
-
const lists = $('review-lists');
|
|
250
|
-
const sc = $('rc-scenarios');
|
|
251
|
-
if (!col || !lists || !sc || col.hidden || isPhone()) return;
|
|
252
|
-
const h = lists.clientHeight;
|
|
253
|
-
if (!h) return;
|
|
254
|
-
const gap = parseFloat(getComputedStyle(lists).rowGap) || 0;
|
|
255
|
-
const head = sc.querySelector('.hx-rc-h');
|
|
256
|
-
const body = sc.querySelector('.hx-rc-sbody');
|
|
257
|
-
const need = Math.ceil((head ? head.offsetHeight + (parseFloat(getComputedStyle(head).marginBottom) || 0) : 0) + (body ? body.scrollHeight : 0));
|
|
258
|
-
col.style.setProperty('--hx-scenarios-need', `${need}px`);
|
|
259
|
-
col.style.setProperty('--hx-changes-max', `${Math.floor(Math.max(0.4 * h, h - need - gap))}px`);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/** "2 of 3 scenarios played", or '': the decision line says it (spec 0007 D1; it used to sit under the scenario list) */
|
|
263
|
-
export function playedLine() {
|
|
264
|
-
return state.proposal ? model().playedLine : '';
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const paintWatchers = new Set();
|
|
268
|
-
/** `fn()` after the lists are drawn again: the decision line follows what was played */
|
|
269
|
-
export function onReviewColumnPaint(fn) {
|
|
270
|
-
paintWatchers.add(fn);
|
|
271
|
-
return () => paintWatchers.delete(fn);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function repaint() {
|
|
275
|
-
const lists = $('review-lists');
|
|
276
|
-
const col = $('review-column');
|
|
277
|
-
if (!lists || !col || !state.proposal) return;
|
|
278
|
-
// another proposal: nothing of the last one's list is open (two proposals may name a scenario alike)
|
|
279
|
-
if (ui.openFor !== proposalKey()) { ui.openFor = proposalKey(); if (!getPlayer()) { ui.open = null; ui.current = null; ui.lastStep = null; } }
|
|
280
|
-
// a scenario that is no longer in the proposal (a what-if edit deleted it) is not open any more
|
|
281
|
-
if (ui.open !== null && !scenariosNow().some((s) => s.id === ui.open)) ui.open = null;
|
|
282
|
-
// an edit to the open scenario (what-if) plans its checks again: the verdicts are of the steps it has now
|
|
283
|
-
const openScenario = ui.open !== null && !getPlayer() ? scenariosNow().find((s) => s.id === ui.open) : null;
|
|
284
|
-
if (openScenario && checkedScenarioId() === openScenario.id) openChecks(openScenario, () => repaint());
|
|
285
|
-
const active = document.activeElement;
|
|
286
|
-
const key = active && lists.contains(active) && active.getAttribute ? active.getAttribute('data-focus-key') : null;
|
|
287
|
-
const scroll = lists.scrollTop;
|
|
288
|
-
lists.innerHTML = listsHtml();
|
|
289
|
-
lists.scrollTop = scroll;
|
|
290
|
-
const peek = $('proposal-peek');
|
|
291
|
-
if (peek) peek.textContent = reviewPeekLine();
|
|
292
|
-
if (key) {
|
|
293
|
-
const again = [...lists.querySelectorAll('[data-focus-key]')].find((el) => el.getAttribute('data-focus-key') === key);
|
|
294
|
-
if (again) again.focus();
|
|
295
|
-
}
|
|
296
|
-
shareRoom();
|
|
297
|
-
for (const fn of paintWatchers) fn();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// ---------------------------------------------------------------------------
|
|
301
|
-
// Doing things
|
|
302
|
-
// ---------------------------------------------------------------------------
|
|
303
|
-
|
|
304
|
-
const scenarioAt = (el) => scenariosNow()[Number(el.dataset.scenarioIndex)] || null;
|
|
305
|
-
|
|
306
|
-
/** Whether a player plays a scenario other than the one a disclosure would check (the checks are the player's then) */
|
|
307
|
-
const playingOther = (id) => { const p = getPlayer(); return !!p && p.scenario().id !== id; };
|
|
308
|
-
|
|
309
|
-
function closeChecksIfIdle() { if (!getPlayer()) closeChecks(); }
|
|
310
|
-
|
|
311
|
-
/** A scenario's disclosure: opens its steps (asking its checks, once, as one batch) or folds them; one is open at a time */
|
|
312
|
-
function toggleScenario(sc) {
|
|
313
|
-
if (ui.open === sc.id) {
|
|
314
|
-
ui.open = null;
|
|
315
|
-
if (!getPlayer()) closeChecks();
|
|
316
|
-
} else {
|
|
317
|
-
ui.open = sc.id;
|
|
318
|
-
markSeen(sc.id, 'read');
|
|
319
|
-
if (!playingOther(sc.id)) openChecks(sc, () => repaint());
|
|
320
|
-
}
|
|
321
|
-
repaint();
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/** A step was chosen: the player opens paused on it, the list stays open and the focus stays on the step (on a phone the sheet folds, so the player takes it) */
|
|
325
|
-
function chooseStep(sc, index) {
|
|
326
|
-
ui.open = sc.id;
|
|
327
|
-
// Under 1360px the column, the node panel and the player bar do not fit side by side: the node panel closes, the player takes its room
|
|
328
|
-
const drawer = $('spec-drawer');
|
|
329
|
-
const stage = state.canvas && state.canvas.parentElement;
|
|
330
|
-
if (!isPhone() && drawer && drawer.classList.contains('drawer-open') && stage && stage.clientWidth < PLAYER_BESIDE_PANEL) closeDrawer();
|
|
331
|
-
playScenario(sc, { autoplay: false, step: index, focus: isPhone() });
|
|
332
|
-
repaint();
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function showTab(tab, { focus = false } = {}) {
|
|
336
|
-
ui.tab = tab;
|
|
337
|
-
ui.tabNow = tab;
|
|
338
|
-
ui.tabFor = proposalKey();
|
|
339
|
-
try { storage()?.setItem(TAB_KEY, tab); } catch { /* the choice is a convenience */ }
|
|
340
|
-
repaint();
|
|
341
|
-
if (focus) $(`rc-tab-${tab}`)?.focus();
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/** The counts' parts open their section: the switch moves to it on a phone; from 768px it scrolls into view and takes the focus */
|
|
345
|
-
export function showSection(which) {
|
|
346
|
-
if (!state.proposal) return;
|
|
347
|
-
if (isPhone()) { showTab(which); expandSheet('proposal'); }
|
|
348
|
-
const section = $(which === 'scenarios' ? 'rc-scenarios' : 'rc-changes');
|
|
349
|
-
const heading = $(which === 'scenarios' ? 'rc-scenarios-h' : 'rc-changes-h');
|
|
350
|
-
if (section && typeof section.scrollIntoView === 'function') section.scrollIntoView({ block: 'start' });
|
|
351
|
-
if (heading) heading.focus();
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function onClick(e) {
|
|
355
|
-
const el = e.target.closest ? e.target.closest('[data-action]') : null;
|
|
356
|
-
if (!el) return;
|
|
357
|
-
const action = el.dataset.action;
|
|
358
|
-
if (action === 'scenario-open') { const sc = scenarioAt(el); if (sc) toggleScenario(sc); } else if (action === 'scenario-step') { const sc = scenarioAt(el); if (sc) chooseStep(sc, Number(el.dataset.stepIndex)); } else if (action === 'review-tab') showTab(el.dataset.tab, { focus: false });
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/** Arrow keys move between the phone's two tabs */
|
|
362
|
-
function onKey(e) {
|
|
363
|
-
const tab = e.target.closest ? e.target.closest('[role="tab"]') : null;
|
|
364
|
-
if (!tab || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(e.key)) return;
|
|
365
|
-
e.preventDefault();
|
|
366
|
-
showTab(tab.dataset.tab === 'changes' ? 'scenarios' : 'changes', { focus: true });
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// ---------------------------------------------------------------------------
|
|
370
|
-
// The player and the list follow each other
|
|
371
|
-
// ---------------------------------------------------------------------------
|
|
372
|
-
|
|
373
|
-
/** Called with each change of the player: the step it is on (null when closed), whether it reached the end */
|
|
374
|
-
function onPlayer(snap) {
|
|
375
|
-
if (!snap) {
|
|
376
|
-
// closed: the list keeps the scenario open, without a current step, and its steps keep their verdicts (the checks are the list's again)
|
|
377
|
-
const sc = ui.open !== null && state.proposal && ui.openFor === proposalKey() ? scenariosNow().find((s) => s.id === ui.open) : null;
|
|
378
|
-
if (sc) openChecks(sc, () => repaint());
|
|
379
|
-
if (ui.current || sc) { ui.current = null; repaint(); }
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
const scenarios = scenariosNow();
|
|
383
|
-
const index = scenarios.findIndex((s) => s.id === snap.id);
|
|
384
|
-
const next = { id: snap.id, index, step: Math.min(snap.index, Math.max(snap.total - 1, 0)) };
|
|
385
|
-
ui.lastStep = next;
|
|
386
|
-
if (snap.done) {
|
|
387
|
-
refreshSeen();
|
|
388
|
-
if (!ui.seen.played.includes(snap.id)) markSeen(snap.id, 'played');
|
|
389
|
-
}
|
|
390
|
-
const same = ui.current && ui.current.id === next.id && ui.current.step === next.step;
|
|
391
|
-
ui.current = next;
|
|
392
|
-
if (ui.open !== snap.id) ui.open = snap.id; // playing a scenario opens its list
|
|
393
|
-
if (!same || snap.done || snap.checks !== ui.checks) { ui.checks = snap.checks; repaint(); }
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/** The step button the player was on, to give the focus back when it closes (a phone's sheet opens again first) */
|
|
397
|
-
function stepToFocus() {
|
|
398
|
-
const at = ui.lastStep;
|
|
399
|
-
if (!at) return null;
|
|
400
|
-
if (isPhone()) expandSheet('proposal');
|
|
401
|
-
const lists = $('review-lists');
|
|
402
|
-
return lists ? lists.querySelector(`[data-action="scenario-step"][data-scenario-index="${at.index}"][data-step-index="${at.step}"]`) : null;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/** The scenario after `id` in the order the list reads (the personas' order, each scenario once), or null at the end of the list */
|
|
406
|
-
function nextScenarioAfter(id) {
|
|
407
|
-
const order = [];
|
|
408
|
-
for (const g of model().groups) for (const sc of g.scenarios) if (!order.includes(sc.id)) order.push(sc.id);
|
|
409
|
-
const at = order.indexOf(id);
|
|
410
|
-
const next = at >= 0 ? order[at + 1] : undefined;
|
|
411
|
-
return next === undefined ? null : scenariosNow().find((s) => String(s.id) === next) || null;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function wire(col) {
|
|
415
|
-
if (wiredRoot === col) return;
|
|
416
|
-
wiredRoot = col;
|
|
417
|
-
col.addEventListener('click', onClick);
|
|
418
|
-
col.addEventListener('keydown', onKey);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
let started = false;
|
|
422
|
-
/** Wires the column to the player and the viewport (main.js calls this once, after the page's markup is there) */
|
|
423
|
-
export function initReviewColumn() {
|
|
424
|
-
if (started) return;
|
|
425
|
-
started = true;
|
|
426
|
-
try { const saved = storage()?.getItem(TAB_KEY); if (saved === 'changes' || saved === 'scenarios') ui.tab = saved; } catch { /* no remembered tab */ }
|
|
427
|
-
onPlayerChange(onPlayer);
|
|
428
|
-
onLayersChange(() => { if (state.proposal) repaint(); }); // a step's "Layer off" follows the Layers menu
|
|
429
|
-
const bar = $('proposal-bar');
|
|
430
|
-
if (bar && typeof ResizeObserver === 'function') new ResizeObserver(() => { placeColumn(); }).observe(bar);
|
|
431
|
-
const col = $('review-column');
|
|
432
|
-
if (col && typeof ResizeObserver === 'function') new ResizeObserver(() => shareRoom()).observe(col); // the window's height changed
|
|
433
|
-
setCloseFocus(stepToFocus);
|
|
434
|
-
setNextScenario(nextScenarioAfter);
|
|
435
|
-
setKeepChecksOnClose((id) => ui.open === id && !!state.proposal);
|
|
436
|
-
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
|
|
437
|
-
const mq = window.matchMedia(PHONE_QUERY);
|
|
438
|
-
if (mq && mq.addEventListener) mq.addEventListener('change', () => { if (state.proposal) renderReviewColumn(); });
|
|
439
|
-
}
|
|
440
|
-
renderReviewColumn();
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/** For tests: forget what the column remembered */
|
|
444
|
-
export function resetReviewColumnForTests() {
|
|
445
|
-
Object.assign(ui, { checks: 0, open: null, tab: null, tabNow: null, tabFor: '', openFor: '', head: '', headFor: '', current: null, lastStep: null, seen: { played: [], read: [] }, seenFor: '', pending: [] });
|
|
446
|
-
wiredRoot = null;
|
|
447
|
-
started = false;
|
|
448
|
-
}
|
|
26
|
+
export function reviewPeekLine() { const p = piece(); return p ? p.peekLine() : ''; }
|
|
27
|
+
/** "2 of 3 scenarios played", or '' */
|
|
28
|
+
export const playedLine = () => { const a = pageInstance().ask('changes:played-line'); return typeof a === 'string' ? a : ''; };
|
|
29
|
+
/** `fn()` after the lists are drawn again. Returns how to stop. */
|
|
30
|
+
export const onReviewColumnPaint = (fn) => pageInstance().on('changes:paint', fn);
|
|
31
|
+
|
|
32
|
+
/** For tests: forget what the column remembered (the piece is made again) */
|
|
33
|
+
export function resetReviewColumnForTests() { setPagePieceOptions('changes', undefined); }
|