@popcorn245/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.
Files changed (42) hide show
  1. package/core/strings.js +14 -0
  2. package/explorer/check.js +7 -227
  3. package/explorer/connection.js +3 -3
  4. package/explorer/css/review.css +49 -0
  5. package/explorer/decision-model.js +6 -0
  6. package/explorer/engine/checks.js +252 -0
  7. package/explorer/engine/connection.js +36 -0
  8. package/explorer/engine/layers.js +1 -0
  9. package/explorer/engine/layout.js +8 -3
  10. package/explorer/engine/player.js +489 -0
  11. package/explorer/engine/proposal.js +373 -0
  12. package/explorer/engine/render.js +1 -0
  13. package/explorer/engine/sheets.js +40 -7
  14. package/explorer/engine/source.js +315 -0
  15. package/explorer/engine/theme-sheet.js +444 -0
  16. package/explorer/engine/topology.js +126 -0
  17. package/explorer/index.html +6 -59
  18. package/explorer/instance.js +87 -7
  19. package/explorer/page-address.js +59 -0
  20. package/explorer/page-pieces.js +33 -5
  21. package/explorer/page.js +20 -20
  22. package/explorer/panels.js +1 -3
  23. package/explorer/pieces/changes.js +495 -0
  24. package/explorer/pieces/decision.js +664 -0
  25. package/explorer/pieces/layers.js +4 -0
  26. package/explorer/pieces/map.js +117 -25
  27. package/explorer/pieces/node-panel.js +34 -1
  28. package/explorer/pieces/proposal.js +488 -0
  29. package/explorer/pieces/review.js +280 -0
  30. package/explorer/pieces/scope-link.js +50 -0
  31. package/explorer/pieces/scope.js +247 -0
  32. package/explorer/pieces/status.css +24 -0
  33. package/explorer/pieces/status.js +144 -0
  34. package/explorer/plugins.js +0 -10
  35. package/explorer/proposal.js +64 -697
  36. package/explorer/review-column.js +24 -439
  37. package/explorer/review.js +27 -673
  38. package/explorer/scenario-ui.js +32 -478
  39. package/explorer/sheets.js +8 -7
  40. package/explorer/view.js +12 -64
  41. package/explorer/waiting-line.js +7 -50
  42. package/package.json +1 -1
@@ -4,7 +4,8 @@
4
4
  * The engine as something a page can make more than one of (spec 0011 D2). `createInstance` returns the object that holds what
5
5
  * `state.js` held when the explorer was one program per document, and the things a piece of the explorer may reach:
6
6
  *
7
- * inst.root where the instance's elements are: a Document (cornfield's page), or an element or shadow root (a component)
7
+ * inst.root where the instance's elements are: a Document (cornfield's page), or an element or shadow root (a component); `attach(root)` moves it
8
+ * to the shadow root of the one piece that draws the map when the instance belongs to a scope (pieces/scope.js)
8
9
  * inst.state the explorer's state (instance-state.js): the topology, the layers, the camera, the selection, the view
9
10
  * inst.base the address of the cornfield server the instance talks to ('' = the page's own origin)
10
11
  * inst.fetch `fetch` bound to that base; inst.url(path) is a served path made absolute against it
@@ -15,6 +16,7 @@
15
16
  * handlers of `on(name, ...)`, else `undefined`. A piece that finds no answer does without (the Work panel is not part of every page)
16
17
  * inst.setSelection(node, edge, { source, quiet }) the one way the converted pieces change what is selected (explorer/engine/selection.js);
17
18
  * returns the change, whose `announce()` says it when `quiet` held it back (the caller touches the scene first)
19
+ * inst.offline() whether the browser has no network; inst.onNetwork(fn(offline)), inst.onWindowFocus(fn), inst.onPageHide(fn), inst.onHide(fn): the few window facts the review needs
18
20
  * inst.active() the element that has the focus inside the root's tree (a shadow root's own, not the host)
19
21
  * inst.el an element of the instance by id, found inside its root and never by document id
20
22
  * inst.listen a listener that `destroy()` removes; inst.own: any other clean-up `destroy()` runs; inst.release(fn): takes one back that its owner ran itself
@@ -35,9 +37,29 @@
35
37
  * layers (none) a layer went on or off, or the layers were set (engine/layers.js): live.js starts or stops the live layer, a search moves its matches
36
38
  * search { query, current } the search's query or its current match changed (pieces/search.js)
37
39
  * node:painted { node } the node panel was filled for this node (pieces/node-panel.js)
40
+ * proposal { change: 'opened' | 'view' | 'closed', slug, source, pinSource, view, proposal } the open proposal changed (engine/proposal.js; the page writes the address from it)
41
+ * proposal:draw { open } the bar and the review column draw again; proposal:bar { open }: they have, so what sits on the bar draws again
42
+ * proposal:mark { applied, effective, proposal } before the map is laid out (the what-if editor marks its edits)
43
+ * proposal:message { text, isError, ways } one line in the bar in place of a proposal; proposal:listing: the list the server gave was read
44
+ * proposal:pull-head sha the open proposal's PR was read; proposal:waiting { run, key }: a run waits on it (the bar's waiting line); proposal:waiting-reset
45
+ * scenario:player { id, index, total, done, playing, checks } | null the scenario player moved, or closed (engine/player.js)
46
+ * changes:paint (none) the review column's lists were drawn again; changes:peek text: its count line, for a phone's peek
47
+ * decision { outcome: 'approved' | 'notes', review, slug, source, open } the server took the review, after it answered (pieces/decision.js);
48
+ * `open`: false when another proposal was opened, or this one closed, while it was sent
49
+ * auth { status: 401 | 403, during: 'facts' | 'review' | 'send' | 'landing' } sign-in is needed: a read or the press was refused
50
+ * source { state, … } where a scope's or a map's load from a cornfield server is (engine/source.js lists the states: loading, ready, sign-in,
51
+ * not-allowed, offline, server, address, version); pieces/status.js shows it and pieces/scope.js turns it into `cornAuth` and `cornError`
52
+ * theme { state: 'loading' | 'ready' | 'failed' | 'none' } the server's theme sheet (engine/theme-sheet.js, with `use-theme`; 'none': taken back out): the map reads its tokens again
53
+ * scope:theme (none) the scope's `theme` (light, dark, auto) or the mode it follows changed: the map draws again (pieces/scope.js)
54
+ * piece:refused { piece, reason, message, host } a piece that cannot have this instance (a second map in a scope); the scope says it as `cornError`
55
+ * and tells `host` to ask again when the root is free
56
+ * attach:released (none) the piece that had the instance's root (`attach`) gave it back
38
57
  * announce text what a screen reader is told (engine/keyboard.js `announce`, which also writes it in the root's `#map-announcer`, if it has one)
39
58
  *
40
59
  * What a piece is asked to do (`emit`ted to it):
60
+ * node:show-edge { edge } show this edge in the panel (engine/proposal.js `showEdge`)
61
+ * changes:show 'changes' | 'scenarios' the review column shows that section; proposal:focus-title: the focus goes to the proposal's name
62
+ * whatif:clear (none) the edits went with a note; mockups:refresh: an approval covers the screens as they are now; whatif:edits-changed: the edits changed
41
63
  * node:show { node, frame } show this node in the panel (engine/selection.js `selectNode`, once the scene is up to date); node:close: close it;
42
64
  * node:focus: the focus goes into the open panel (Enter on the map)
43
65
  * layers:redraw (none) draw the Layers menu again (engine/layers.js: a layer, the nodes or a review changed)
@@ -51,6 +73,10 @@
51
73
  * (live.js does); live:hydrate (emit) el: its photos
52
74
  * forge:can-start (none) can a run be started from here? -> boolean; forge:start (emit) { slug, returnTo }: open the Start dialog
53
75
  * scenario:clear (none) (emit) a selection ends a playing scenario
76
+ * 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
77
+ * 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
78
+ * changes:opened-line title -> string, changes:played-line -> string what the review column says of an opening, and how many scenarios were played
79
+ * whatif:edits -> edits[], whatif:form -> { name } | null, whatif:describe -> string[] what the decision asks of the what-if editor
54
80
  *
55
81
  * What input.js asks of the page (requests, not news of a change; the page decides what each means):
56
82
  * select node a tap on a node; `background`: a tap on the bare map; `grab`: a hand took the camera
@@ -72,7 +98,8 @@ const ABSOLUTE = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
72
98
  * @param {Record<string, string>} [opts.strings] the host's own words
73
99
  * @param {object} [opts.state] a state object to adopt instead of a new one (state.js hands the page's to the page instance)
74
100
  */
75
- export function createInstance({ root = null, base = '', fetch: fetchOpt, strings = {}, state } = {}) {
101
+ export function createInstance({ root: rootOpt = null, base = '', fetch: fetchOpt, strings = {}, state } = {}) {
102
+ let root = rootOpt;
76
103
  const doc = root ? (root.nodeType === 9 ? /** @type {Document} */ (root) : root.ownerDocument) : null;
77
104
  const win = doc ? doc.defaultView : null;
78
105
  const events = new Map();
@@ -80,6 +107,8 @@ export function createInstance({ root = null, base = '', fetch: fetchOpt, string
80
107
  const slots = new Map();
81
108
  let destroyed = false;
82
109
  const fetchImpl = fetchOpt;
110
+ const initialRoot = root;
111
+ let attached = null;
83
112
 
84
113
  const on = (name, fn) => {
85
114
  let set = events.get(name);
@@ -88,11 +117,16 @@ export function createInstance({ root = null, base = '', fetch: fetchOpt, string
88
117
  return () => set.delete(fn);
89
118
  };
90
119
 
91
- /** A served path made absolute against the base; anything already absolute (or no base) is returned as it was */
120
+ /**
121
+ * A served path made absolute against the base; anything already absolute (or no base) is returned as it was. A base with a path
122
+ * (`https://example.com/cornfield`, a server behind a proxy's prefix) keeps it: `/topology.json` is `https://example.com/cornfield/topology.json`.
123
+ */
92
124
  const url = (path) => {
93
125
  const p = String(path);
94
126
  if (!base || ABSOLUTE.test(p)) return p;
95
- return new URL(p, base).href;
127
+ const at = new URL(base);
128
+ const prefix = at.pathname.replace(/\/+$/, '');
129
+ return new URL(prefix && p.startsWith('/') ? prefix + p : p, at).href;
96
130
  };
97
131
 
98
132
  /** The element whose computed style holds the tokens: the document's own for a page, else the root itself (a shadow root's host) */
@@ -187,11 +221,38 @@ export function createInstance({ root = null, base = '', fetch: fetchOpt, string
187
221
  // -- the instance's own elements ----------------------------------------------------------------------------------------------
188
222
  /** The element with this id inside the root, or null (ids are only unique inside one root) */
189
223
  el: (id) => (root ? root.querySelector(`[id="${String(id).replace(/["\\]/g, '\\$&')}"]`) : null),
224
+ /**
225
+ * Where the instance's elements are, once a piece has put them somewhere of its own: a scope (pieces/scope.js) makes the instance over its own
226
+ * element before any piece exists, and the one piece that draws the map attaches its shadow root, so `el`, `active` and the tokens are read
227
+ * there. One root at a time: a second attach throws (the engine holds one map per instance); the release gives back the root it had.
228
+ * @param {Document|Element|ShadowRoot} next
229
+ * @returns {() => void} release
230
+ */
231
+ attach(next) {
232
+ if (attached) throw new Error('This instance already has a map');
233
+ attached = next;
234
+ root = next;
235
+ inst.root = next;
236
+ const release = () => {
237
+ if (attached !== next) return;
238
+ attached = null;
239
+ root = initialRoot;
240
+ inst.root = initialRoot;
241
+ inst.release(release);
242
+ if (!destroyed) inst.emit('attach:released'); // a piece that was refused (a second map in a scope) may have it now
243
+ };
244
+ cleanups.push(release);
245
+ return release;
246
+ },
190
247
  /** The element with the focus in the root's own tree: a Document's or a shadow root's `activeElement`, or the document's when it is inside the root; else null */
191
248
  active: () => {
192
249
  if (!root || !doc) return null;
193
250
  if (root.nodeType !== 1) return root.activeElement || null; // a Document or a shadow root
194
- return doc.activeElement && root.contains(doc.activeElement) ? doc.activeElement : null;
251
+ // An element: the focus is asked of the tree it sits in, so an element inside a shadow root (the review piece's box in a shell's shadow root)
252
+ // finds its own focused element, where the document's would be the shadow root's host
253
+ const tree = typeof root.getRootNode === 'function' ? root.getRootNode() : doc;
254
+ const focused = tree && tree.activeElement !== undefined ? tree.activeElement : doc.activeElement;
255
+ return focused && root.contains(focused) ? focused : null;
195
256
  },
196
257
 
197
258
  // -- what the viewer prefers --------------------------------------------------------------------------------------------------
@@ -209,11 +270,28 @@ export function createInstance({ root = null, base = '', fetch: fetchOpt, string
209
270
  /** The device pixel ratio now */
210
271
  dpr: () => (win && win.devicePixelRatio) || 1,
211
272
  /** Whether the tab is hidden */
212
- hidden: () => !!(doc && doc.hidden),
273
+ hidden: () => !!(doc && (doc.hidden || doc.visibilityState === 'hidden')),
213
274
  /** Calls `fn` when the tab is shown again; the one document-level fact an instance needs. Removed by destroy(). */
214
275
  onShown(fn) {
215
276
  if (!doc) return () => {};
216
- return inst.listen(doc, 'visibilitychange', () => { if (!doc.hidden) fn(); });
277
+ return inst.listen(doc, 'visibilitychange', () => { if (!inst.hidden()) fn(); });
278
+ },
279
+ /** Whether the browser says it has no network (`navigator.onLine === false`) */
280
+ offline: () => !!(win && win.navigator && win.navigator.onLine === false),
281
+ /** Calls `fn(offline)` when the browser goes offline (true) or comes back (false). Removed by destroy(). */
282
+ onNetwork(fn) {
283
+ if (!win) return () => {};
284
+ const offs = [inst.listen(win, 'offline', () => fn(true)), inst.listen(win, 'online', () => fn(false))];
285
+ return () => offs.forEach((off) => off());
286
+ },
287
+ /** Calls `fn()` when the window gets the focus again. Removed by destroy(). */
288
+ onWindowFocus: (fn) => (win ? inst.listen(win, 'focus', () => fn()) : () => {}),
289
+ /** Calls `fn()` when the page is going away (a tab closed, a reload). Removed by destroy(). */
290
+ onPageHide: (fn) => (win ? inst.listen(win, 'pagehide', () => fn()) : () => {}),
291
+ /** Calls `fn()` when the tab is hidden. Removed by destroy(). */
292
+ onHide(fn) {
293
+ if (!doc) return () => {};
294
+ return inst.listen(doc, 'visibilitychange', () => { if (inst.hidden()) fn(); });
217
295
  },
218
296
  /** A small key-value store (the browser's localStorage, which may be blocked): what a viewer's own choices are kept in */
219
297
  store: {
@@ -248,6 +326,8 @@ export function createInstance({ root = null, base = '', fetch: fetchOpt, string
248
326
  if (!slots.has(key)) slots.set(key, make(inst));
249
327
  return slots.get(key);
250
328
  },
329
+ /** Whether `destroy()` has run: an answer that arrives after it (a fetch in flight) is not wanted */
330
+ get ended() { return destroyed; },
251
331
  /** Removes every listener, observer and timer the instance's modules set up and releases the renderer's GPU context. Safe to call twice. */
252
332
  destroy() {
253
333
  if (destroyed) return;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @module explorer/page-address
3
+ *
4
+ * The address bar, for cornfield's own page (spec 0011 D2): `?proposal=`, `?source=` and `?proposalView=` belong to the page shell, not to a piece. Reading
5
+ * them makes the same calls a host app would make (`openFromAddress`: open this proposal, in this view); writing them follows the instance, which says when a
6
+ * proposal opened, changed view or closed (`keepAddress`). Page code: it reads `location` and writes `history`. (test/explorer/instance-tripwires.test.js
7
+ * holds the pieces and the engine to not doing either.)
8
+ */
9
+
10
+ import { parseProposalQuery, malformedLinkWords, viewWords } from './proposal-model.js';
11
+ import { announce } from './engine/keyboard.js';
12
+ import { openProposal, setProposalView, setMessage, pinnedSource, titleOf } from './engine/proposal.js';
13
+ import { t } from './engine/strings.js';
14
+
15
+ /** `?proposal=` (and `source`, `proposalView`) follow the open proposal, without a new history entry; other parameters stay */
16
+ function syncAddress(inst) {
17
+ if (typeof history === 'undefined' || typeof location === 'undefined') return;
18
+ const { state } = inst;
19
+ try {
20
+ const params = new URLSearchParams(location.search);
21
+ ['proposal', 'source', 'proposalView'].forEach((k) => params.delete(k));
22
+ if (state.proposal && state.proposalSlug) {
23
+ params.set('proposal', state.proposalSlug);
24
+ if (pinnedSource(inst) && state.proposalSource) params.set('source', state.proposalSource);
25
+ if (state.proposalView !== 'diff') params.set('proposalView', state.proposalView);
26
+ }
27
+ const query = params.toString();
28
+ history.replaceState(null, '', `${location.pathname}${query ? `?${query}` : ''}${location.hash}`);
29
+ } catch { /* the address is a convenience */ }
30
+ }
31
+
32
+ /** The address follows the open proposal: written when the instance says one opened, changed view or closed. Once per instance; returns how to stop. */
33
+ export function keepAddress(inst) {
34
+ const mem = inst.slot('page-address', () => ({ off: null }));
35
+ if (mem.off) return mem.off;
36
+ const off = inst.on('proposal', () => syncAddress(inst));
37
+ mem.off = () => { off(); mem.off = null; };
38
+ return mem.off;
39
+ }
40
+
41
+ /**
42
+ * Opens what the address asks for, as a host would: a proposal by name (and the copy and the view), or a line that says the link is not a proposal's name.
43
+ * @returns {Promise<boolean>} whether a proposal from the address opened (false when it asked for none)
44
+ */
45
+ export async function openFromAddress(inst, search) {
46
+ const asked = parseProposalQuery(search);
47
+ if (!asked) {
48
+ // A link whose `proposal` is not a proposal's name: said plainly (the value as text, never markup or a link), with the Specs list
49
+ const bad = malformedLinkWords(search);
50
+ if (bad) setMessage(inst, bad, true, [{ label: t(inst, 'openSpecsList'), way: 'specs' }]);
51
+ return false;
52
+ }
53
+ const ok = await openProposal(inst, asked.slug, asked.source);
54
+ if (ok && asked.view) {
55
+ setProposalView(inst, asked.view, { quiet: true });
56
+ announce(inst, `${inst.ask('changes:opened-line', titleOf(inst.state)) || ''} ${viewWords(inst.state.proposalView)}.`);
57
+ }
58
+ return ok;
59
+ }
@@ -18,10 +18,14 @@ import { pageMap } from './render.js';
18
18
  import * as nodePanel from './pieces/node-panel.js';
19
19
  import * as layers from './pieces/layers.js';
20
20
  import * as search from './pieces/search.js';
21
+ import * as proposal from './pieces/proposal.js';
22
+ import * as changes from './pieces/changes.js';
23
+ import * as decision from './pieces/decision.js';
21
24
 
22
25
  /** The pieces of the page, in the order they are mounted (the node panel registers its sheet; search and the Layers menu follow the map) */
23
- const PIECES = { 'node-panel': nodePanel, layers, search };
26
+ const PIECES = { 'node-panel': nodePanel, layers, search, proposal, changes, decision }; // (the decision's place is inside the changes piece's column: it follows it)
24
27
  const mounted = new Map(); // name -> { handle, markers: Comment[] }
28
+ const optionsOf = new Map(); // name -> what the page tells a piece besides its places (a checker, a clock)
25
29
 
26
30
  /** The marker comments of a piece in the document: { slot: Comment } */
27
31
  function markersOf(doc, name) {
@@ -47,20 +51,44 @@ export function ensurePagePieces() {
47
51
  if (!doc) return {};
48
52
  for (const [name, piece] of Object.entries(PIECES)) {
49
53
  const have = mounted.get(name);
50
- if (have && have.markers.every((m) => m.isConnected)) continue;
54
+ if (have && (have.forced ? have.handle.elements.every((el) => el.isConnected) : have.markers.every((m) => m.isConnected))) continue;
51
55
  if (have) { have.handle.destroy(); mounted.delete(name); }
52
56
  const slots = markersOf(doc, name);
53
57
  const markers = Object.values(slots);
54
58
  if (!markers.length) continue;
55
59
  pageMap(); // the pieces follow the page's map: it is there before they are
56
- mounted.set(name, { handle: piece.mount(doc.body, inst, { slots }), markers });
60
+ mounted.set(name, { handle: piece.mount(doc.body, inst, { ...(optionsOf.get(name) || {}), slots }), markers });
57
61
  }
58
62
  return Object.fromEntries([...mounted].map(([name, { handle }]) => [name, handle]));
59
63
  }
60
64
 
61
- /** The page's mounted piece by name ('node-panel', 'layers', 'search'), or null */
62
- export function pagePiece(name) {
65
+ /**
66
+ * What the page tells a piece besides its places (`mount`'s options: the changes piece's checker, the decision's clock). A piece already mounted is
67
+ * ended and mounted again with them, at its places.
68
+ */
69
+ export function setPagePieceOptions(name, options) {
70
+ if (options === undefined) optionsOf.delete(name); else optionsOf.set(name, options);
71
+ const have = mounted.get(name);
72
+ if (have) { have.handle.destroy(); mounted.delete(name); }
73
+ ensurePagePieces();
74
+ }
75
+
76
+ /** Adds to what the page tells a piece without ending it: the piece hears it as `update(patch)` (and takes it when it is mounted next) */
77
+ export function mergePagePieceOptions(name, patch) {
78
+ optionsOf.set(name, { ...(optionsOf.get(name) || {}), ...patch });
79
+ const have = mounted.get(name);
80
+ if (have) have.handle.update(patch);
81
+ }
82
+
83
+ /** The page's mounted piece by name ('node-panel', 'layers', 'search', 'proposal', 'changes', 'decision'), or null; `anywhere`: mounted at the end of the body when the page has no place for it */
84
+ export function pagePiece(name, { anywhere = false } = {}) {
63
85
  ensurePagePieces();
86
+ // A caller that needs the piece whether or not the page has a place for it (a test drives the scenario player on a bare stage) has it at the end of the body
87
+ if (anywhere && !mounted.has(name) && PIECES[name] && pageInstance().doc) {
88
+ const inst = pageInstance();
89
+ pageMap();
90
+ mounted.set(name, { handle: PIECES[name].mount(inst.doc.body, inst, { ...(optionsOf.get(name) || {}), slots: {} }), markers: [], forced: true });
91
+ }
64
92
  const have = mounted.get(name);
65
93
  return have ? have.handle : null;
66
94
  }
package/explorer/page.js CHANGED
@@ -14,11 +14,13 @@
14
14
  * scene.js what is drawn (contract) renderer.js how it is drawn: renderer-webgl.js or renderer-canvas2d.js
15
15
  * pieces/ the node panel, the Layers menu and the search: pieces mounted where index.html has their places (page-pieces.js)
16
16
  * view.js loading and view switching input.js mouse and touch
17
- * proposal.js the proposal overlay (picker, Before / Diff / After); proposal-model.js its pure half
17
+ * pieces/proposal.js the proposal's bar (the picker, Before / Diff / After); engine/proposal.js opening one; proposal-model.js its pure half
18
+ * pieces/changes.js the review column and the scenario player (engine/player.js, engine/checks.js); pieces/decision.js Approve and Send back
19
+ * page-address.js ?proposal=, ?source= and ?proposalView= in the address bar
18
20
  * whatif.js what-if edits on an open proposal (add, remove, draw, steps, undo); whatif-model.js its pure half
19
- * review.js approve a proposal or send it back with a note and the edits; review-model.js its pure half
21
+ * review-model.js, decision-model.js the words and the choices of the decision (pure)
20
22
  * deep-link.js ?run=, ?issue= and ?proposal=…&start=1 land on a run, an issue and a Start dialog
21
- * scenario.js the player's pure core scenario-ui.js its bar, keys and camera
23
+ * scenario.js the player's pure core
22
24
  * bench.js /?bench=1 stopwatch and /?fixture=5k (the generated topology, from the server)
23
25
  * keyboard.js the map by keyboard and the screen reader's announcer; keyboard-model.js its pure half
24
26
  * live.js the live layer: the chip, polling, laying a live source's answer over the map; live-model.js its pure half
@@ -32,34 +34,32 @@ import { createMap } from './engine/render.js';
32
34
  import { rendererPreference } from './renderer.js';
33
35
  import { clearFreeformPositions, layoutOrbit, loadFreeformPositions } from './engine/layout.js';
34
36
  import { measureCovered } from './sheets.js';
35
- import { setProjectLayers } from './layers.js';
36
37
  import { closeDrawer } from './panels.js';
37
- import { ensurePagePieces, pieceSlots } from './page-pieces.js';
38
- import { initScenarioUi, maybeStartDemo, playOutage } from './scenario-ui.js';
38
+ import { ensurePagePieces, mergePagePieceOptions, pieceSlots } from './page-pieces.js';
39
+ import { maybeStartDemo, playOutage } from './scenario-ui.js';
39
40
  import { initSheets } from './sheets.js';
40
- import { initReviewColumn } from './review-column.js';
41
41
  import { loadTopology, setView, syncViewUi } from './view.js';
42
42
  import { mount as mountMap, KEYS_HELP_WITH_PANEL } from './pieces/map.js';
43
- import { initProposals } from './proposal.js';
43
+ import { keepAddress, openFromAddress } from './page-address.js';
44
+ import './proposal.js'; // the old names the modules not yet on an instance use (hooks)
45
+ import { initReview } from './review.js'; // what the decision asks of the what-if editor and the mockups
44
46
  import { followDeepLink } from './deep-link.js';
45
47
  import { initWhatIf } from './whatif.js';
46
- import { initReview } from './review.js';
47
48
  import { initMockups } from './mockups.js';
48
49
  import { benchMeta, measureParams, readoutLines, resultLine, runBench, showReadout } from './bench.js';
49
50
  import { initLive } from './live.js';
50
51
  import { initHouse } from './house.js';
51
52
  import { houseOffered } from './house-model.js';
52
- import { initChecks } from './check.js';
53
53
  import { initKeyboard } from './keyboard.js';
54
54
  import { initForgePanel } from './forge-panel.js';
55
55
  import { initReviewTokens } from './review-tokens.js';
56
- import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
56
+ import { loadSources, applyBranding } from './plugins.js';
57
+ import { applyConfig, fetchConfig } from './engine/source.js';
57
58
  import { initTheme, setThemeChoice } from './theme.js';
58
59
  import { initAccountMenu } from './account-menu.js';
59
60
  import { watchHeaderFit } from './header-fit.js';
60
61
  import { watchHint } from './hint.js';
61
62
  import { watchFocusRoom } from './focus-room.js';
62
- import { mapStyleOf } from './engine/map-style.js';
63
63
 
64
64
  /** The instance and its map: made by `startPage`, the one of this document */
65
65
  let inst;
@@ -169,7 +169,6 @@ async function runPageBench(frames, zoomFactor, sync) {
169
169
  export function startPage() {
170
170
  inst = startPageInstance({ root: document }); // the one instance of this document, the document its root; state.js hands the modules that are not yet on an instance its state
171
171
  map = createMap(inst, { measureCovered }); // the camera, the scene and the frame loop of this instance (engine/render.js)
172
- const mapStyle = mapStyleOf(inst);
173
172
  initTheme(); // light or dark, before the first scene is built (theme.js)
174
173
  // The map piece (pieces/map.js, also what <corn-map> mounts) makes the map's canvases, their keys' help and the announcer where index.html keeps
175
174
  // `<!--corn-piece:map/stage-->`. It watches the theme's tokens (the map reads --corn-map-* from the theme, and again when it changes), makes the
@@ -180,17 +179,17 @@ export function startPage() {
180
179
  renderer: rendererPreference(window.location.search) === 'canvas2d' ? 'canvas2d' : 'auto',
181
180
  });
182
181
  loadFreeformPositions(inst);
183
- ensurePagePieces(); // the node panel, the Layers menu and the search, mounted where index.html has their places (page-pieces.js)
182
+ ensurePagePieces(); // the node panel, the Layers menu, the search, the proposal's bar, the review column and the decision, mounted where index.html has their places (page-pieces.js)
183
+ keepAddress(inst); // ?proposal= follows the open proposal (page-address.js)
184
184
  initKeyboard(); // the map by keyboard (the panel's, the Layers menu's and the search's keys are their pieces') (engine/keyboard.js)
185
185
  initAccountMenu(); // the one menu at the right of the header (account-menu.js)
186
186
  initSheets();
187
- initScenarioUi();
188
- initReviewColumn(); // the review column: the changes, and the personas with their scenarios (review-column.js)
189
187
 
190
188
  map.resize();
191
189
  syncViewUi();
192
190
  // /?proposal=<slug> opens a proposal over the map, /?view=dataflow the data-flow preset: both have a link
193
- const configReady = loadClientConfig().then((config) => { applyBranding(document, config); watchHeaderFit(document); watchHint(document); watchFocusRoom(document); mapStyle.applyTheme(config.theme); setProjectLayers(config.layers); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
191
+ // The config is read and applied by engine/source.js, as a scope does it; a page opened without the server reads as no config
192
+ const configReady = fetchConfig(inst).catch(() => ({})).then((config) => { applyBranding(document, config); watchHeaderFit(document); watchHint(document); watchFocusRoom(document); applyConfig(inst, config); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
194
193
  loadTopology().then(async (ok) => {
195
194
  if (!ok) return;
196
195
  // The sources the repo's cornfield.config.js names (plugins.js): a live layer, a house, devices, a checker; each optional
@@ -200,14 +199,15 @@ export function startPage() {
200
199
  const forgeOn = initForgePanel(config); // issues and PRs: only when the config names a forge (forge-panel.js)
201
200
  initReviewTokens(config); // review tokens for the review API: only for somebody signed in (review-tokens.js)
202
201
  initWhatIf(); // before a proposal can open, so its edits come with it
203
- initReview(); // after it: the review controls sit under the edit controls on the bar
202
+ initReview(); // the decision follows the what-if editor's edits
204
203
  initMockups(); // a proposal's screens open from the node they name
205
- const proposalOpened = await initProposals();
204
+ // /?proposal=<slug> (&source=, &proposalView=) opens a proposal, as a host would ask for one (page-address.js)
205
+ const proposalOpened = await openFromAddress(inst, window.location.search);
206
206
  // The live layer (live.js): loads only once a live layer goes on in the Layers menu; with no source it stays off
207
207
  initLive({ source: liveSource, onSelectionGone: closeDrawer });
208
208
  // The House view (house.js): a source's floor renderer draws the plan under the map (plain room boxes without one); /?view=house opens it
209
209
  initHouse({ floor: floorRenderer, offered: houseOffered(houseSource, state.nodes) }); // no house source and no house in the map: no House button
210
- initChecks({ checker }); // scenarios ask the source's checker, when there is one (check.js)
210
+ mergePagePieceOptions('changes', { checker }); // scenarios ask the source's checker, when there is one (pieces/changes.js)
211
211
  if (new URLSearchParams(window.location.search).get("view") === "dataflow") setView("dataflow");
212
212
  // /?run=, /?issue= and /?proposal=…&start=1 land on a run, an issue's Start button and a proposal's Start dialog (deep-link.js)
213
213
  followDeepLink({ proposalOpened, forgeOn }).catch((err) => console.error('Following the link failed', err));
@@ -4,11 +4,10 @@
4
4
  * A bridge (spec 0011 D2 and D3, step 4): the node panel is now a piece (pieces/node-panel.js) and choosing a node is the instance's
5
5
  * (engine/selection.js). This file keeps the old names for the modules that are not yet on an instance (forge-panel.js, house.js, proposal.js,
6
6
  * review-column.js, page.js), bound to the page's instance, and answers for the unconverted neighbours the piece asks (the live layer's
7
- * block, the Start dialog, the end of a playing scenario). It goes when the last of those callers is converted.
7
+ * block, the Start dialog). It goes when the last of those callers is converted.
8
8
  */
9
9
 
10
10
  import { pageInstance } from './state.js';
11
- import { clearScenario } from './scenario-ui.js';
12
11
  import { liveSection, hydrateLivePhotos } from './live.js';
13
12
  import { canStartAgent, openProposalStart } from './forge-panel.js';
14
13
  import { selectNode as select, clearSelection } from './engine/selection.js';
@@ -19,7 +18,6 @@ export const LINES_CAP = CAP;
19
18
 
20
19
  // What the node panel asks of neighbours that are not on an instance yet, answered for the page's instance
21
20
  const page = pageInstance();
22
- page.on('scenario:clear', () => { clearScenario(); });
23
21
  page.on('live:section', (node) => liveSection(node));
24
22
  page.on('live:hydrate', (el) => { hydrateLivePhotos(el); });
25
23
  page.on('forge:can-start', () => canStartAgent());