cornfield 0.52.1 → 0.54.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/mentions.js CHANGED
@@ -237,3 +237,26 @@ export function threadOfPull(body) {
237
237
  const m = /(?:^|[\s(])(?:thread\s*:|(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)(?:\s*:)?)\s+#([1-9]\d{0,8})\b/i.exec(prose);
238
238
  return m ? Number(m[1]) : null;
239
239
  }
240
+
241
+ /**
242
+ * Every issue a pull request's text says it closes, as GitHub and Forgejo read it: `Closes #n`, and the other keywords both forges
243
+ * honour (close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved; any case; an optional colon), each number once, in
244
+ * the order written. Not in code (a fenced block or an inline span) and not in an HTML comment (a pull request template's
245
+ * `<!-- Fixes #123 -->`), which neither forge reads. An issue in another repo (`owner/name#n`) is not this repo's; with `repo`
246
+ * ("owner/name"), the same repo written out in full is. (`threadOfPull` is the first of these, or a `Thread: #n`; the work graph
247
+ * draws every one, server/work-graph.js.)
248
+ * @param {string} body
249
+ * @param {string | null} [repo] this repo, "owner/name"
250
+ * @returns {number[]}
251
+ */
252
+ export function closesOf(body, repo = null) {
253
+ const prose = scan(String(body ?? '')).prose.replace(/<!--[\s\S]*?(?:-->|$)/g, (c) => c.replace(/[^\n]/g, ' '));
254
+ const self = typeof repo === 'string' ? repo.toLowerCase() : null;
255
+ const out = [];
256
+ for (const m of prose.matchAll(/(?:^|[\s(])(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)(?:\s*:)?\s+([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)?#([1-9]\d{0,8})\b/gi)) {
257
+ if (m[1] && m[1].toLowerCase() !== self) continue;
258
+ const n = Number(m[2]);
259
+ if (!out.includes(n)) out.push(n);
260
+ }
261
+ return out;
262
+ }
package/core/strings.js CHANGED
@@ -123,6 +123,8 @@ export const STRINGS = Object.freeze({
123
123
  needsScope: 'This needs a corn-scope around it, with a corn-map in it',
124
124
  needsMap: 'This needs a corn-map in the same corn-scope',
125
125
  waitingForMap: 'Waiting for the map',
126
+ // The review's sections as tags (corn-proposal, corn-changes, corn-decision): a scope holds one of each
127
+ secondSection: 'This scope already has one of these',
126
128
  });
127
129
 
128
130
  /** The longest a value may be, in characters */
@@ -185,4 +185,6 @@
185
185
  /* The title of a panel: the Work panel, the node panel, the proposal bar, a detail in the Work panel and a dialog are one style. A node's name is long and
186
186
  often a path, so it wraps (overflow-wrap) in this size rather than being set larger than the panel's own words. */
187
187
  .hx-drawer-title { font-size: var(--corn-text-lg); font-weight: 700; line-height: 1.25; letter-spacing: normal; }
188
- .hx-drawer-head { min-height: var(--corn-panel-head-height); }
188
+ /* The head never shrinks: the body is a flex column that scrolls, and a short box (a panel in a host's 200px place, a short window) would squash the head to its
189
+ min-height, laying a title that wraps, or a kicker that does ("Added by" a proposal), over the line under it */
190
+ .hx-drawer-head { min-height: var(--corn-panel-head-height); flex-shrink: 0; }
@@ -136,6 +136,8 @@ export const newReasons = (reasons, answered) => reasons.filter((r) => !answered
136
136
  * cornfield server to send a review to (pieces/review.js with no `base`). Cornfield's own page always names its proposal, so it never says this.
137
137
  */
138
138
  export const NOTHING_TO_DECIDE = 'Shown to read only: there is no cornfield server here to send an approval or a send back to.';
139
+ /** What the foot says for a proposal with no name in a scope that has a server (`<corn-decision>`): it is shown, but nothing can be decided on it */
140
+ export const NAMELESS_PROPOSAL = 'Shown to read only: this proposal has no name, so there is nothing to send an approval or a send back about.';
139
141
 
140
142
  /**
141
143
  * The line above Approve and what a press of it does, from the facts and the page's own state.
@@ -81,17 +81,19 @@ export function visibleMapRect(inst) {
81
81
  if (isPhone(inst)) covers.bottom = measureCovered(inst) + 8;
82
82
  else if (canvas && typeof canvas.getBoundingClientRect === 'function') {
83
83
  const c = canvas.getBoundingClientRect();
84
- const bar = inst.el('proposal-bar');
85
- if (shown(bar)) covers.top = Math.max(0, bar.getBoundingClientRect().bottom - c.top) + 8;
84
+ // What lies over the map in this instance's own layout (cornfield's page, a review) answers for itself: the proposal bar, the review column and the scenario
85
+ // player each say where their edge is, the node panel its width. In a scope the pieces sit beside the map, not over it, and none answers
86
+ const bar = inst.ask('proposal:covers');
87
+ if (bar) covers.top = Math.max(0, bar.bottom - c.top) + 8;
86
88
  const panel = inst.ask('panel:covers'); // the node panel, when it slides over the map: its width, not its box (it slides in)
87
89
  if (panel && panel.right) covers.right = panel.right;
88
90
  const forge = inst.el('forge-panel');
89
91
  if (shown(forge) && forge.classList.contains('forge-open')) covers.left = forge.offsetWidth;
90
92
  // the review column (review-column.js) is docked on the left under the bar: its right edge is what it covers, past the Work panel's when both are open
91
- const column = inst.el('review-column');
92
- if (shown(column)) covers.left = Math.max(covers.left, Math.max(0, column.getBoundingClientRect().right - c.left) + 8);
93
- const player = inst.root ? inst.root.querySelector('.hx-player') : null;
94
- if (shown(player)) covers.bottom = Math.max(0, c.bottom - player.getBoundingClientRect().top) + 8;
93
+ const column = inst.ask('changes:covers');
94
+ if (column) covers.left = Math.max(covers.left, Math.max(0, column.right - c.left) + 8);
95
+ const player = inst.ask('player:covers');
96
+ if (player) covers.bottom = Math.max(0, c.bottom - player.top) + 8;
95
97
  }
96
98
  return freeRect(state.width || 0, state.height || 0, covers);
97
99
  }
@@ -97,8 +97,11 @@ export function demoScenario(nodes, edges) {
97
97
  * @param {ReturnType<import('../instance.js').createInstance>} inst
98
98
  * @param {ReturnType<typeof import('./piece.js').scopeOf>} scope the piece's own end: every listener, observer and the frame client go with it
99
99
  * @param {ReturnType<typeof import('./checks.js').createChecks>} checks
100
+ * @param {{ seat?: Element, hear?: EventTarget }} [where] where the piece that owns the player has put it, when that is not the page's or the review's layout (`<corn-changes>`):
101
+ * `seat` is the element the bar goes in (it is a part of that piece, not a sheet or a bar over the map), `hear` the root whose keys are the player's (Space, the arrows, Escape).
102
+ * Without it the bar lies over the map's bottom, or is a sheet in the dock (the dock's owner seats it: `player:seat`), and the instance's root hears
100
103
  */
101
- export function createScenarioPlayer(inst, scope, checks) {
104
+ export function createScenarioPlayer(inst, scope, checks, where = {}) {
102
105
  const { state } = inst;
103
106
  let player = null;
104
107
  let bar = null;
@@ -121,7 +124,8 @@ export function createScenarioPlayer(inst, scope, checks) {
121
124
  let barOffs = [];
122
125
  const notify = (snap) => { for (const fn of [...listeners]) fn(snap); inst.emit('scenario:player', snap); };
123
126
 
124
- const stage = () => (state.canvas ? state.canvas.parentElement : null);
127
+ const stage = () => (where.seat || (state.canvas ? state.canvas.parentElement : null));
128
+ const hear = where.hear || inst.root;
125
129
  const render = () => inst.map.render();
126
130
 
127
131
  // ---------------------------------------------------------------------------
@@ -353,12 +357,13 @@ export function createScenarioPlayer(inst, scope, checks) {
353
357
  menu.addEventListener('change', onSpeed);
354
358
  barOffs.push(() => { here.removeEventListener('click', onBarClick); menu.removeEventListener('change', onSpeed); });
355
359
  // 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
356
- const dock = inst.el('sheet-dock');
357
- const drawer = inst.el('spec-drawer');
358
- if (dock && drawer && drawer.parentElement === dock) dock.insertBefore(bar, drawer);
359
- else (dock || area).appendChild(bar);
360
- registerSheet(inst, 'player', bar);
361
- collapseAllSheets(inst);
360
+ if (where.seat) area.appendChild(bar); // a part of the piece's own box: no sheet, nothing over the map
361
+ else {
362
+ // On a phone the bar is a sheet in the dock, above the node panel; the dock's owner seats it (engine/sheets.js), else it lies over the map's bottom
363
+ if (inst.ask('player:seat', bar) !== true) area.appendChild(bar);
364
+ registerSheet(inst, 'player', bar);
365
+ collapseAllSheets(inst);
366
+ }
362
367
  // 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
363
368
  const RO = inst.win && inst.win.ResizeObserver;
364
369
  if (typeof RO === 'function') {
@@ -439,10 +444,11 @@ export function createScenarioPlayer(inst, scope, checks) {
439
444
  // ---------------------------------------------------------------------------
440
445
  /** A menu or dialog that has its own Escape: the layers menu, the toolbar's ⋯ menu, a dialog */
441
446
  function otherPopupOpen() {
442
- return !!inst.root.querySelector('#legend-dropdown:not([hidden]), #proposal-more-menu:not([hidden]), [data-corn="dialog-scrim"]:not([hidden]), .hx-mockup-dialog');
447
+ if (inst.ask('popup:open') === true) return true; // the Layers menu, the bar's ⋯ menu: whoever owns one says so
448
+ return !!inst.root.querySelector('[data-corn="dialog-scrim"]:not([hidden]), .hx-mockup-dialog');
443
449
  }
444
450
 
445
- scope.listen(inst.root, 'keydown', (e) => {
451
+ scope.listen(hear, 'keydown', (e) => {
446
452
  if (e.key === 'Escape' && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey) {
447
453
  if (player && !typingIn(e.target) && !otherPopupOpen()) { e.preventDefault(); stop(); return; } // Escape closes the scenario; focus goes back to Play
448
454
  }
@@ -454,7 +460,7 @@ export function createScenarioPlayer(inst, scope, checks) {
454
460
  act(action);
455
461
  });
456
462
  // Some browsers press a focused button on the key's release, so a space the player took must not reach it
457
- scope.listen(inst.root, 'keyup', (e) => {
463
+ scope.listen(hear, 'keyup', (e) => {
458
464
  if (player && (e.key === ' ' || e.code === 'Space') && !typingIn(e.target)) e.preventDefault();
459
465
  });
460
466
  // A sheet that opened or closed changes what the map shows: keep the step in view
@@ -360,6 +360,14 @@ export function initSheets(inst) {
360
360
  }
361
361
  if (!S.documentWired) {
362
362
  S.documentWired = true;
363
+ // The scenario player's bar is a sheet in the dock, above the node panel's drawer (the dock's own children): the dock's owner seats it
364
+ inst.on('player:seat', (bar) => {
365
+ const dock = S.dock;
366
+ if (!dock || !dock.isConnected) return undefined;
367
+ const drawer = [...dock.children].find((child) => child.classList.contains('hx-drawer'));
368
+ if (drawer) dock.insertBefore(bar, drawer); else dock.appendChild(bar);
369
+ return true;
370
+ });
363
371
  for (const type of ['pointerdown', 'touchstart', 'mousedown']) inst.listen(inst.root, type, (e) => onMapDown(inst, e), { passive: true, capture: true });
364
372
  inst.listen(inst.root, 'keydown', (e) => onEscape(inst, e), true);
365
373
  onPhoneChange(inst, () => { collapseAllSheets(inst); measureCovered(inst); });
@@ -65,6 +65,8 @@
65
65
  * announce text what a screen reader is told (engine/keyboard.js `announce`; the piece that owns a live region writes it: `announce:write`)
66
66
  * root:changed (none) the primary root moved (`attach`) or a root joined or left (engine/roots.js): what listens on every root puts itself right
67
67
  * map:ready (none) the map piece is mounted and has its topology (pieces/map.js); map:gone: it ended. The pieces around it (pieces/around.js) mount and unmount with it
68
+ * map:topology (none) the map piece installed a base map (a topology the host handed in, or the server's); map:canvas: its canvas was replaced (another renderer). What holds a
69
+ * proposal over the map (pieces/scope-proposal.js) lays it over the new base, and binds the new canvas
68
70
  * search:status text what the search's own live region says (engine/search-status.js; pieces/search.js writes it)
69
71
  *
70
72
  * What a piece is asked to do (`emit`ted to it):
@@ -89,11 +91,17 @@
89
91
  * scenario:clear (none) (emit) a selection ends a playing scenario
90
92
  * proposal:effective proposal -> proposal the proposal the map is drawn from (the what-if editor's, with its edits in); proposal:before-close -> false keeps it open
91
93
  * proposal:specs-list (none) -> false there is no list of specs to open here (the review in another app): a bad link's ways leave the button out
94
+ * proposal:covers (none) -> { bottom }, changes:covers (none) -> { right }, player:covers (none) -> { top } where the proposal bar, the review column and the scenario player lie over the map, in
95
+ * client px (engine/map-rect.js): the map frames into what is left. A piece in a box of its own lies over nothing and answers none. popup:open (none) -> true:
96
+ * a menu that has its own Escape is open (the Layers menu, the bar's ⋯ menu: the player's Escape leaves it alone)
97
+ * proposal:seat-column { column, phone } -> true the bar seats the review column: under it, or in its body on a phone (pieces/proposal.js); proposal:bar-bottom (none) -> px,
98
+ * how far down the bar reaches, and proposal:bar-resize (emit): the bar's height changed, so the column starts under it again
99
+ * player:seat bar -> true the dock's owner (engine/sheets.js) seats the scenario player's bar as a sheet above the node panel's
92
100
  * threads:index nodeId -> { threads: thread[] | null, forge: string, start: true } | undefined the Work panel's list of the threads that mention a node, for the node panel's "Threads"; `threads` is null until the list was read; no answer: no Threads section
93
101
  * threads:ensure (none) (emit) the node panel was filled: the Work panel reads the threads list once; threads:changed: it was read, or the map changed, so the node panel draws "Threads" again
94
102
  * work:on (none) -> boolean whether the Work panel has started (a piece mounted after it asks rather than waits for `work:available`)
95
103
  * work:answer { run } (emit) "Answer" on the proposal bar's line: the Work panel opens on Runs at that run, its reply field focused
96
- * work:open-specs (none) -> true the Work panel's Specs tab opened for a bad link's way on; map:set { nodes, edges } -> true the page laid the map out from these
104
+ * work:open-specs (none) -> true the Work panel's Specs tab opened for a bad link's way on; map:set { nodes, edges } -> true the page (or the review, or a scope's map: pieces/map.js) laid the map out from these
97
105
  * changes:opened-line title -> string, changes:played-line -> string what the review column says of an opening, and how many scenarios were played
98
106
  * whatif:edits -> edits[], whatif:form -> { name } | null, whatif:describe -> string[] what the decision asks of the what-if editor
99
107
  *
@@ -11,7 +11,9 @@
11
11
  * root the shadow root of the tag
12
12
  * inst the scope's instance, or null: no scope around the tag, so a private instance with no map, which this says (`needsScope`)
13
13
  * options tokens (the default `--corn-*` CSS text), piece (the options the piece is mounted with), initial (its first `update`), noMap (the `strings` key said
14
- * while there is no map: `needsMap`, or the panel's own empty state), onSearch ({ query, current }, the instance's `search` event)
14
+ * while there is no map: `needsMap`, or the panel's own empty state), onSearch ({ query, current }, the instance's `search` event),
15
+ * exclusive (a name: the piece holds state of its own, so a scope holds one of it; see below), signIn ({ during: string[], clear: string }: the instance's
16
+ * `auth` events whose `during` is listed put the scope's sign-in card in this tag's own root, and the event `clear` takes it away)
15
17
  *
16
18
  * What it does so that three roots can share one instance:
17
19
  * - the root joins the instance (`joinRoot`, engine/roots.js): its keys and its focus are the instance's, so `/` pressed on the map reaches the search and a click in the
@@ -20,7 +22,10 @@
20
22
  * - the piece mounts when the instance has a map with nodes (`map:ready`, then the `scene` its data brings) and ends when it has none (`map:gone`): the
21
23
  * pieces read the map's camera, scene and visibility, so with none they say what they need in its place (`needsMap`), and while the map waits on its
22
24
  * server (loading, signed out, offline: the map's own card says which) that they wait for it (`waitingForMap`). Tags can come in any order;
23
- * - it has a live region of its own, said in only when no map has one (`announce:fallback`): a panel or a search beside no map still speaks.
25
+ * - it has a live region of its own, said in only when no map has one (`announce:fallback`): a panel or a search beside no map still speaks;
26
+ * - an `exclusive` piece (the proposal's bar, the change list with its player, the decision) is one per scope: each has a state of its own (a hold, a
27
+ * note, a playing scenario, a line that is said once), which two could not share. The first to join holds the name; a second says `secondSection` in its own
28
+ * place, tells the scope (`piece:refused`, which is `cornError` `second-section`), and takes over when the first leaves.
24
29
  * Nothing here reads the page: no `document`, no id of a neighbour. It never throws for a missing scope or map.
25
30
  */
26
31
 
@@ -46,11 +51,12 @@ function adoptTokens(root, css) {
46
51
  * @param {{ mount: Function }} piece
47
52
  * @param {ShadowRoot|Element} root
48
53
  * @param {ReturnType<typeof createInstance>|null} inst
49
- * @param {{ tokens?: string, piece?: object, initial?: object, noMap?: string, onSearch?: (d: { query: string, current: string | null }) => void }} [options]
54
+ * @param {{ tokens?: string, piece?: object, initial?: object, noMap?: string, onSearch?: (d: { query: string, current: string | null }) => void, exclusive?: string, signIn?: { during: string[], clear: string } }} [options]
50
55
  */
51
56
  export function mountAround(piece, root, inst, options = {}) {
52
57
  const ownsInstance = !inst;
53
58
  if (ownsInstance) inst = createInstance({ root });
59
+ const exclusive = typeof options.exclusive === 'string' ? options.exclusive : '';
54
60
  const info = scopeInfo(inst);
55
61
  const scope = scopeOf(inst);
56
62
  adoptTokens(root, options.tokens);
@@ -62,8 +68,14 @@ export function mountAround(piece, root, inst, options = {}) {
62
68
  scope.on('announce:fallback', (text) => { say(text); return true; });
63
69
  scope.own(() => region.remove());
64
70
 
71
+ /** Who holds each exclusive name in this instance (this call is the token) */
72
+ const holders = exclusive ? inst.slot('exclusive', () => new Map()) : null;
73
+ const token = {};
74
+ const second = () => !!holders && holders.has(exclusive) && holders.get(exclusive) !== token;
75
+ const takeName = () => { if (!holders) return true; if (second()) return false; holders.set(exclusive, token); return true; };
65
76
  let real = null;
66
77
  let note = [];
78
+ let told = false;
67
79
  let pending = { ...(options.initial || {}) };
68
80
  let ended = false;
69
81
 
@@ -73,13 +85,18 @@ export function mountAround(piece, root, inst, options = {}) {
73
85
  const hasMap = () => !!inst.map && inst.state.nodes.length > 0;
74
86
  const showNote = (gone = false) => {
75
87
  if (ended) return;
76
- const words = !info ? t(inst, 'needsScope') : options.noMap === 'nodePanelEmpty' ? t(inst, 'nodePanelEmpty') : inst.map && !gone ? t(inst, 'waitingForMap') : t(inst, 'needsMap');
88
+ const words = second() ? t(inst, 'secondSection') : !info ? t(inst, 'needsScope') : options.noMap === 'nodePanelEmpty' ? t(inst, 'nodePanelEmpty') : inst.map && !gone ? t(inst, 'waitingForMap') : t(inst, 'needsMap');
77
89
  if (note.length && note[0].textContent === words) return;
78
90
  dropNote();
79
91
  note = place(inst, root, `<p class="hx-needs" data-corn="empty">${escapeHtml(words)}</p>`, null, 'needs');
80
92
  };
81
93
  const mountReal = () => {
82
94
  if (real || ended) return;
95
+ if (!takeName()) {
96
+ showNote();
97
+ if (!told) { told = true; inst.emit('piece:refused', { piece: exclusive, reason: 'second-section', message: `A scope holds one ${exclusive}.` }); }
98
+ return;
99
+ }
83
100
  if (!hasMap()) { showNote(); return; }
84
101
  dropNote();
85
102
  real = piece.mount(root, inst, { ...(options.piece || {}), inline: true, phone: false });
@@ -88,9 +105,18 @@ export function mountAround(piece, root, inst, options = {}) {
88
105
  const unmountReal = () => { if (real) { real.destroy(); real = null; } };
89
106
 
90
107
  scope.on('map:ready', mountReal);
108
+ scope.on('exclusive:released', (d) => { if (d && d.name === exclusive) mountReal(); }); // the one that held the name left: this one may have it
91
109
  scope.on('scene', () => { if (!real) mountReal(); }); // the map's data came (its server answered, or the host handed it in)
92
110
  scope.on('map:gone', () => { unmountReal(); showNote(true); }); // (said while the map ends: the instance may still hold it)
93
111
  if (options.onSearch) scope.on('search', (d) => options.onSearch(d));
112
+ // A refusal for want of a sign-in, said where the person is working (the scope says it once to the host: `cornAuth`)
113
+ if (options.signIn && info && info.mountStatus) {
114
+ const [slot] = place(inst, root, '<div class="hx-signin-slot"></div>', null, 'signin');
115
+ const card = info.mountStatus(slot, inst, { follow: false });
116
+ scope.on('auth', ({ status, during }) => { if (options.signIn.during.includes(during)) card.show({ state: 'sign-in', status, signIn: info.signIn() }); });
117
+ scope.on(options.signIn.clear, () => card.clear());
118
+ scope.own(() => { card.destroy(); slot.remove(); });
119
+ }
94
120
  mountReal();
95
121
 
96
122
  return {
@@ -107,7 +133,10 @@ export function mountAround(piece, root, inst, options = {}) {
107
133
  ended = true;
108
134
  unmountReal();
109
135
  dropNote();
136
+ const held = holders && holders.get(exclusive) === token;
137
+ if (held) holders.delete(exclusive);
110
138
  scope.destroy();
139
+ if (held && !inst.ended) inst.emit('exclusive:released', { name: exclusive });
111
140
  if (ownsInstance) inst.destroy();
112
141
  },
113
142
  };
@@ -30,7 +30,10 @@
30
30
  *
31
31
  * @param {ParentNode} root where the column goes when `options.slots` names no place
32
32
  * @param {ReturnType<typeof import('../instance.js').createInstance>} inst the instance; its map must be made (engine/render.js)
33
- * @param {{ slots?: { column?: Node }, checker?: object | null }} [options] `checker`: a plugin's checker for the scenarios' permission checks (none: "Not checked")
33
+ * @param {{ slots?: { column?: Node }, checker?: object | null, inline?: boolean }} [options] `checker`: a plugin's checker for the scenarios' permission checks (none: "Not checked").
34
+ * `inline` is the piece in a box and a root of its own (`<corn-changes>`, pieces/around.js): the column fills the box (no panel docked beside the map, no phone sheet and no
35
+ * tabs: both lists, one under the other, scroll inside it), the player's bar is its last part, not a bar over the map's bottom, and its keys are this root's. What lies
36
+ * over the map is none of its business: it answers no `*:covers`, and chooses a step without closing a node panel
34
37
  * @returns {{ update: (props?: { checker?: object | null }) => void, destroy: () => void, playScenario: Function, stopScenario: Function, getPlayer: Function, elements: Element[] }}
35
38
  * `update({ checker })` hands over the checker; `update()` draws the lists again.
36
39
  */
@@ -55,13 +58,13 @@ const PLAYER_BESIDE_PANEL = 1360;
55
58
  const asList = (v) => (Array.isArray(v) ? v : []);
56
59
 
57
60
  /** The markup of the piece: the column. `column` is its one place; it keeps a place of its own for the decision's foot */
58
- export const markup = () => ({
61
+ export const markup = ({ inline = false } = {}) => ({
59
62
  column: '<aside id="review-column" class="hx-review-column glass" aria-label="Review" data-corn="review-column" hidden>'
60
63
  + '<div class="hx-rc-scroll">'
61
64
  + '<p id="proposal-summary" class="hx-proposal-summary" hidden></p>'
62
65
  + '<div id="review-lists" class="hx-rc-lists"></div>'
63
66
  + '</div>'
64
- + '<!--corn-piece:decision/foot-->'
67
+ + (inline ? '<div class="hx-player-seat"></div>' : '<!--corn-piece:decision/foot-->') // a box of its own has no foot: the decision is a tag of its own
65
68
  + '</aside>',
66
69
  });
67
70
 
@@ -77,7 +80,10 @@ function changeRowHtml(r) {
77
80
  export function mount(root, inst, options = {}) {
78
81
  const { state } = inst;
79
82
  const scope = scopeOf(inst);
80
- const made = place(inst, root, markup().column, options.slots, 'column');
83
+ const inline = !!options.inline;
84
+ /** Whether the layout is a phone's: the window's width on cornfield's page, the box's in a review. A box of its own never has the phone's sheets: its narrowness is the CSS's alone */
85
+ const phone = () => !inline && isPhone(inst);
86
+ const made = place(inst, root, markup({ inline }).column, options.slots, 'column');
81
87
  /** An element of this piece by id */
82
88
  const own = (id) => {
83
89
  for (const el of made) {
@@ -92,7 +98,7 @@ export function mount(root, inst, options = {}) {
92
98
  let gone = false;
93
99
 
94
100
  const checks = createChecks(inst, { checker: options.checker });
95
- const player = createScenarioPlayer(inst, scope, checks);
101
+ const player = createScenarioPlayer(inst, scope, checks, inline ? { seat: col.querySelector('.hx-player-seat'), hear: root } : {});
96
102
  scope.own(() => checks.close());
97
103
 
98
104
  /** 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 */
@@ -220,17 +226,17 @@ export function mount(root, inst, options = {}) {
220
226
  const rows = everyRow.filter((r) => r.mark !== 'edit');
221
227
  const mine = everyRow.filter((r) => r.mark === 'edit'); // "Your edits · 1": the first group, not the last row
222
228
  const list = model();
223
- const phone = isPhone(inst);
229
+ const narrow = phone();
224
230
  // the phone's tab: the reviewer's last choice, or Scenarios when there are any; a proposal with none opens on its changes
225
231
  if (ui.tabFor !== proposalKey()) { ui.tabFor = proposalKey(); ui.tabNow = list.total ? (ui.tab || 'scenarios') : 'changes'; }
226
232
  const tab = ui.tabNow || 'changes';
227
233
  const personas = state.nodes.some((n) => n.type === 'persona');
228
234
 
229
- const tabs = `<div class="hx-rc-tabs" role="tablist" aria-label="Review" data-corn="tabs"${phone ? '' : ' hidden'}>`
235
+ const tabs = `<div class="hx-rc-tabs" role="tablist" aria-label="Review" data-corn="tabs"${narrow ? '' : ' hidden'}>`
230
236
  + `<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(inst, 'changes'))} · ${rows.length}</button>`
231
237
  + `<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(inst, 'scenarios'))} · ${list.total}</button></div>`;
232
238
 
233
- 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"'}>`
239
+ const changes = `<section id="rc-changes" class="hx-rc-section" data-corn="proposal-changes"${narrow ? ` role="tabpanel" aria-labelledby="rc-tab-changes"${tab === 'changes' ? '' : ' hidden'}` : ' aria-labelledby="rc-changes-h"'}>`
234
240
  + `<h3 id="rc-changes-h" class="hx-rc-h" tabindex="-1">${countHeading(t(inst, 'changes'), rows.length)}</h3>`
235
241
  + (mine.length ? `<h4 class="hx-rc-sub">${countHeading(t(inst, 'yourEdits'), mine.length)}</h4><ul class="hx-change-list">${mine.map(changeRowHtml).join('')}</ul>` : '')
236
242
  + (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>')
@@ -243,7 +249,7 @@ export function mount(root, inst, options = {}) {
243
249
  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(inst, 'anyone'))}.</p>`;
244
250
  if (list.coverage) body += `<p class="hx-rc-coverage" data-corn="notice">${escHtml(t(inst, 'notInAnyScenario'))}: ${list.notInAny.map(escHtml).join(', ')}</p>`;
245
251
  }
246
- 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"'}>`
252
+ const scenarios = `<section id="rc-scenarios" class="hx-rc-section" data-corn="scenario-list"${narrow ? ` role="tabpanel" aria-labelledby="rc-tab-scenarios"${tab === 'scenarios' ? '' : ' hidden'}` : ' aria-labelledby="rc-scenarios-h"'}>`
247
253
  + `<h3 id="rc-scenarios-h" class="hx-rc-h" tabindex="-1">${countHeading(t(inst, 'personasAndScenarios'), list.total)}</h3><div class="hx-rc-sbody">${body}</div></section>`;
248
254
  return `${tabs}${changes}${scenarios}`;
249
255
  }
@@ -253,20 +259,15 @@ export function mount(root, inst, options = {}) {
253
259
  // ---------------------------------------------------------------------------
254
260
  /** Where the column goes: after the proposal bar in the dock from 768px, at the end of the sheet's body on a phone */
255
261
  function mountColumn() {
256
- const dock = inst.el('sheet-dock');
257
- const body = inst.el('proposal-body');
258
- if (isPhone(inst) && body) { if (col.parentElement !== body) body.appendChild(col); } else if (dock) {
259
- const bar = inst.el('proposal-bar');
260
- if (bar && col.parentElement !== dock) bar.after(col);
261
- }
262
+ if (!inline) inst.ask('proposal:seat-column', { column: col, phone: phone() }); // the bar seats it (pieces/proposal.js): nobody answering leaves it where it is
262
263
  return col;
263
264
  }
264
265
 
265
266
  /** 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 */
266
267
  function placeColumn() {
267
- const bar = inst.el('proposal-bar');
268
- if (!bar || isPhone(inst) || bar.hidden) return;
269
- col.style.setProperty('--hx-column-top', `${Math.round(bar.offsetTop + bar.offsetHeight + 8)}px`);
268
+ if (inline || phone()) return;
269
+ const bottom = inst.ask('proposal:bar-bottom');
270
+ if (typeof bottom === 'number') col.style.setProperty('--hx-column-top', `${bottom}px`);
270
271
  }
271
272
 
272
273
  /** Draws the column for the open proposal, or hides it when none is open */
@@ -288,7 +289,7 @@ export function mount(root, inst, options = {}) {
288
289
  function shareRoom() {
289
290
  const lists = own('review-lists');
290
291
  const sc = own('rc-scenarios');
291
- if (!lists || !sc || col.hidden || isPhone(inst)) return;
292
+ if (!lists || !sc || col.hidden || phone()) return;
292
293
  const h = lists.clientHeight;
293
294
  if (!h) return;
294
295
  const gap = parseFloat(inst.win.getComputedStyle(lists).rowGap) || 0;
@@ -356,10 +357,9 @@ export function mount(root, inst, options = {}) {
356
357
  function chooseStep(sc, index) {
357
358
  ui.open = sc.id;
358
359
  // 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
359
- const drawer = inst.el('spec-drawer');
360
360
  const stage = state.canvas && state.canvas.parentElement;
361
- if (!isPhone(inst) && drawer && drawer.classList.contains('drawer-open') && stage && stage.clientWidth < PLAYER_BESIDE_PANEL) clearSelection(inst, { source: 'api' });
362
- player.play(sc, { autoplay: false, step: index, focus: isPhone(inst) });
361
+ if (!inline && !phone() && inst.ask('panel:covers') && stage && stage.clientWidth < PLAYER_BESIDE_PANEL) clearSelection(inst, { source: 'api' }); // a slide-over node panel is open (it answers `panel:covers`)
362
+ player.play(sc, { autoplay: false, step: index, focus: phone() });
363
363
  repaint();
364
364
  }
365
365
 
@@ -375,7 +375,7 @@ export function mount(root, inst, options = {}) {
375
375
  /** The counts' parts open their section: the switch moves to it on a phone; from 768px it scrolls into view and takes the focus */
376
376
  function showSection(which) {
377
377
  if (!state.proposal) return;
378
- if (isPhone(inst)) { showTab(which); expandSheet(inst, 'proposal'); }
378
+ if (phone()) { showTab(which); expandSheet(inst, 'proposal'); }
379
379
  const section = own(which === 'scenarios' ? 'rc-scenarios' : 'rc-changes');
380
380
  const heading = own(which === 'scenarios' ? 'rc-scenarios-h' : 'rc-changes-h');
381
381
  if (section && typeof section.scrollIntoView === 'function') section.scrollIntoView({ block: 'start' });
@@ -426,7 +426,7 @@ export function mount(root, inst, options = {}) {
426
426
  function stepToFocus() {
427
427
  const at = ui.lastStep;
428
428
  if (!at) return null;
429
- if (isPhone(inst)) expandSheet(inst, 'proposal');
429
+ if (phone()) expandSheet(inst, 'proposal');
430
430
  const lists = own('review-lists');
431
431
  return lists ? lists.querySelector(`[data-action="scenario-step"][data-scenario-index="${at.index}"][data-step-index="${at.step}"]`) : null;
432
432
  }
@@ -451,9 +451,15 @@ export function mount(root, inst, options = {}) {
451
451
  scope.on('changes:show', (which) => showSection(which));
452
452
  const RO = inst.win && inst.win.ResizeObserver;
453
453
  const watch = (el, fn) => { if (el && typeof RO === 'function') { const ro = new RO(fn); ro.observe(el); scope.own(() => ro.disconnect()); } };
454
- watch(inst.el('proposal-bar'), () => placeColumn());
454
+ scope.on('proposal:bar-resize', () => placeColumn()); // the bar's height changed (the counts wrap, a line comes): the column starts under it
455
455
  watch(col, () => shareRoom()); // the window's height changed
456
- scope.own(onPhoneChange(inst, () => { if (state.proposal) renderColumn(); })); // the window's width, or the box's where the review has one (engine/sheets.js)
456
+ if (!inline) {
457
+ scope.own(onPhoneChange(inst, () => { if (state.proposal) renderColumn(); })); // the window's width, or the box's where the review has one (engine/sheets.js)
458
+ // What the column and the player cover of the map: the map frames a step into what is left (engine/map-rect.js)
459
+ const shown = (el) => !!el && !el.hidden && el.isConnected;
460
+ scope.on('changes:covers', () => (shown(col) ? { right: col.getBoundingClientRect().right } : undefined));
461
+ scope.on('player:covers', () => { const bar = player.bar(); return shown(bar) ? { top: bar.getBoundingClientRect().top } : undefined; });
462
+ }
457
463
 
458
464
  scope.own(() => {
459
465
  gone = true;
@@ -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 (isPhone(inst)) expandSheet(inst, 'proposal');
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 (isPhone(inst) && send && typeof send.scrollIntoView === 'function') send.scrollIntoView({ block: 'nearest' });
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 (isPhone(inst)) expandSheet(inst, 'proposal');
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 (isPhone(inst)) expandSheet(inst, 'proposal');
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(inst.root, 'keydown', (e) => {
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;
@@ -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);
@@ -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
  /**