@popcorn245/cornfield 0.51.8 → 0.52.1

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.
@@ -9,9 +9,6 @@
9
9
 
10
10
  import { t } from './strings.js';
11
11
 
12
- /** The two fields' status lines: the desktop box and the phone's bar */
13
- const IDS = ['search-status', 'mobile-search-status'];
14
-
15
12
  /** How long the typing must pause before what a search found is said: a live region that changed on every key would be read out on every key */
16
13
  export const NO_MATCH_DELAY_MS = 400;
17
14
 
@@ -24,12 +21,9 @@ const pendingOf = (inst) => inst.slot('search-status', () => {
24
21
  return m;
25
22
  });
26
23
 
27
- /** Writes `text` into the region(s) at once; '' clears them */
24
+ /** Says `text` in the region(s) at once, '' clears them: the search piece owns them and hears `search:status` (they may be in a root of their own) */
28
25
  function write(inst, text) {
29
- for (const id of IDS) {
30
- const el = inst.el(id);
31
- if (el) el.textContent = text;
32
- }
26
+ inst.emit('search:status', text);
33
27
  }
34
28
 
35
29
  /** Shows `text` by the search field(s) at once, ending any wait for what the typing found; '' clears it */
package/explorer/flows.js CHANGED
@@ -16,6 +16,7 @@
16
16
  import { pageInstance } from './state.js';
17
17
  import { FLOW_STYLES } from './flow-style.js';
18
18
  import * as F from './engine/flow-ui.js';
19
+ import { renderFlowLegend as drawFlowLegend } from './engine/flow-legend.js';
19
20
 
20
21
  export { FLOW_STYLES, flowStyleOf } from './flow-style.js';
21
22
 
@@ -30,5 +31,5 @@ export { buildDataFlow } from './flow-build.js';
30
31
  // ---------------------------------------------------------------------------
31
32
  // Legend and the panel's "Data flows" block (engine/flow-ui.js, on an instance)
32
33
  // ---------------------------------------------------------------------------
33
- export const renderFlowLegend = () => F.renderFlowLegend(pageInstance());
34
+ export const renderFlowLegend = () => drawFlowLegend(pageInstance(), pageInstance().el('flow-legend'));
34
35
  export const flowSummary = (node) => F.flowSummary(pageInstance(), node);
@@ -13,7 +13,8 @@
13
13
  */
14
14
 
15
15
  import { NODE_THEMES } from '../core/schema.js';
16
- import { parseColor } from './theme-model.js';
16
+ import { DARK_GROUND, LIGHT_GROUND, parseColor } from './theme-model.js';
17
+ import { over } from '../core/color.js';
17
18
 
18
19
  /** A node is at least this many px across (on screen) before its glyph is drawn: smaller, no glyph reads and the silhouette does the work */
19
20
  export const GLYPH_MIN_PX = 14;
@@ -48,14 +49,21 @@ const luminanceOf = ([r, g, b]) => {
48
49
  };
49
50
  const ratioOf = (a, b) => { const [hi, lo] = a > b ? [a, b] : [b, a]; return (hi + 0.05) / (lo + 0.05); };
50
51
 
51
- /** The ink that reads on a fill: white or dark, whichever has the higher contrast (the glyph is at least 3:1 on every fill of the default palette: a test holds it) */
52
- export function inkFor(fill) {
53
- const lum = luminanceOf(parseColor(fill));
52
+ /** The ink that reads on a fill (seen over `ground`, when the fill is translucent): white or dark, whichever has the higher contrast (the glyph is at least 3:1 on every fill of the default palette: a test holds it) */
53
+ export function inkFor(fill, ground = DARK_GROUND) {
54
+ let rgba = parseColor(fill);
55
+ // A translucent fill is seen over the map's ground (a node is drawn translucent, renderer-canvas2d.js), so the ink is chosen against that.
56
+ // The ground is opaque: a translucent one is taken over black, as a canvas with nothing under it shows
57
+ if (rgba[3] < 1) rgba = over(rgba, over(parseColor(ground), [0, 0, 0, 1]));
58
+ const lum = luminanceOf(rgba);
54
59
  return ratioOf(1, lum) >= ratioOf(luminanceOf(parseColor(INK_DARK)), lum) ? INK_LIGHT : INK_DARK;
55
60
  }
56
61
 
57
- /** The ink a node's glyph is drawn in: the theme's (`--corn-map-glyph`, in the style's `values`), else the one that reads on its fill */
58
- export const glyphInk = (node, style) => (style && style.values && style.values['--corn-map-glyph']) || inkFor(node.color);
62
+ /** The ground a node is seen over: the theme's (`--corn-ground`, the style's `ground`), else the light or the dark one */
63
+ const groundOf = (style, theme) => (style && style.ground) || (theme === 'light' ? LIGHT_GROUND : DARK_GROUND);
64
+
65
+ /** The ink a node's glyph is drawn in: the theme's (`--corn-map-glyph`, in the style's `values`), else the one that reads on its fill (over the ground, when it is translucent) */
66
+ export const glyphInk = (node, style, theme = 'dark') => (style && style.values && style.values['--corn-map-glyph']) || inkFor(node.color, groundOf(style, theme));
59
67
 
60
68
  /** Whether a node's glyph is drawn at this zoom: it has one, no icon or letters replace it, and it is wide enough on screen */
61
69
  export const showsGlyph = (node, zoom) => !!node.glyph && !node.icon && !node.letters && node.r * 2 * zoom >= GLYPH_MIN_PX;
@@ -18,7 +18,9 @@
18
18
  * returns the change, whose `announce()` says it when `quiet` held it back (the caller touches the scene first)
19
19
  * inst.offline() whether the browser has no network; inst.onNetwork(fn(offline)), inst.onWindowFocus(fn), inst.onPageHide(fn), inst.onPageShow(fn), inst.onResize(fn), inst.onHide(fn): the few window facts the review needs;
20
20
  * inst.onPageFocus(fn(event)): a focus anywhere in the page, outside the root too (a modal dialog's trap in a host's page)
21
- * inst.active() the element that has the focus inside the root's tree (a shadow root's own, not the host)
21
+ * inst.active() the element that has the focus inside the root's tree (a shadow root's own, not the host), or inside any root that joined
22
+ * inst.extraRoots the other roots that belong to the instance (a leaf piece's own shadow root, in a scope), joined by engine/roots.js `joinRoot`: `active` looks in them too.
23
+ * `inst.el` still looks in the primary root only: a piece owns its elements, and a neighbour reaches it by an event or an `ask`
22
24
  * inst.el an element of the instance by id, found inside its root and never by document id
23
25
  * 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
24
26
  * inst.slot what a module keeps for this instance (its map style), made on first use
@@ -60,7 +62,10 @@
60
62
  * work:available { on } the Work panel started (a forge in the config and somebody signed in), or ended: the account menu's Proposals entry is only for a cornfield without it
61
63
  * runs:map { active } runs are on the map, or none is (pieces/work.js, runs-map.js): the Layers menu shows its legend while there are
62
64
  * thread:open { number } a thread listed in the node panel was chosen; thread:start { node }: "Start a thread about this" (pieces/node-panel.js; the Work panel opens the thread, or its New idea form)
63
- * 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)
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
+ * 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
+ * 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
+ * search:status text what the search's own live region says (engine/search-status.js; pieces/search.js writes it)
64
69
  *
65
70
  * What a piece is asked to do (`emit`ted to it):
66
71
  * node:show-edge { edge } show this edge in the panel (engine/proposal.js `showEdge`)
@@ -73,6 +78,9 @@
73
78
  * view view the view changed ('orbit', 'dataflow', 'house'): the Layers chip dims while the data-flow view is on (view.js on the page)
74
79
  *
75
80
  * What a piece asks of a neighbour that may not be there (`ask`: the first answer that is not `undefined`; nobody answering is a no):
81
+ * announce:write text -> true when a live region of a piece took it (the map's `#map-announcer`); announce:fallback text -> true: a piece that stands without a map has one
82
+ * panel:present (none) -> true: a node panel is part of this instance (the map says "Panel closed" and not "Selection cleared"); panel:covers (none) -> { right: px } the part of the map
83
+ * an open slide-over panel covers, else nothing; layers:present (none) -> true: a Layers menu is part of the instance
76
84
  * search:active (none) is a search with matches on? -> boolean (the map's N and P step through its matches then)
77
85
  * search:step by step to the next (+1) or previous (-1) match -> boolean, whether there was one
78
86
  * live:section node the live layer's block for the node panel -> HTML, put in the panel as it is: whoever answers escapes what it shows
@@ -120,6 +128,7 @@ export function createInstance({ root: rootOpt = null, base = '', fetch: fetchOp
120
128
  const fetchImpl = fetchOpt;
121
129
  const initialRoot = root;
122
130
  let attached = null;
131
+ const joined = new Set();
123
132
 
124
133
  const on = (name, fn) => {
125
134
  let set = events.get(name);
@@ -185,6 +194,24 @@ export function createInstance({ root: rootOpt = null, base = '', fetch: fetchOp
185
194
  Object.defineProperty(theState, 'selectedNode', { enumerable: true, configurable: true, get: () => selNode, set: (v) => { commit(v, selEdge, 'state', false); } });
186
195
  Object.defineProperty(theState, 'selectedEdge', { enumerable: true, configurable: true, get: () => selEdge, set: (v) => { commit(selNode, v, 'state', false); } });
187
196
 
197
+ /** The focused element of one tree: a Document's or a shadow root's `activeElement`; for an element, the tree it sits in, when the focus is inside it */
198
+ const activeIn = (r) => {
199
+ if (r.nodeType === 11) {
200
+ // A shadow root's own focus: asked of the root itself, which also answers inside a host's closed shadow root, where a walk from the document cannot
201
+ // look in. Where asking throws (happy-dom, while the focus is in another shadow root), it is found from the document down through the open roots
202
+ let own;
203
+ try { own = r.activeElement; } catch { own = undefined; }
204
+ if (own !== undefined) return own && own.getRootNode && own.getRootNode() === r ? own : null;
205
+ let el = doc.activeElement;
206
+ while (el && el.shadowRoot && el.shadowRoot.activeElement) el = el.shadowRoot.activeElement;
207
+ return el && el.getRootNode && el.getRootNode() === r ? el : null;
208
+ }
209
+ if (r.nodeType !== 1) return r.activeElement || null;
210
+ const tree = typeof r.getRootNode === 'function' ? r.getRootNode() : doc;
211
+ const focused = tree && tree.activeElement !== undefined ? tree.activeElement : doc.activeElement;
212
+ return focused && r.contains(focused) ? focused : null;
213
+ };
214
+
188
215
  const inst = {
189
216
  root,
190
217
  doc,
@@ -244,27 +271,29 @@ export function createInstance({ root: rootOpt = null, base = '', fetch: fetchOp
244
271
  attached = next;
245
272
  root = next;
246
273
  inst.root = next;
274
+ inst.emit('root:changed');
247
275
  const release = () => {
248
276
  if (attached !== next) return;
249
277
  attached = null;
250
278
  root = initialRoot;
251
279
  inst.root = initialRoot;
280
+ inst.emit('root:changed');
252
281
  inst.release(release);
253
282
  if (!destroyed) inst.emit('attach:released'); // a piece that was refused (a second map in a scope) may have it now
254
283
  };
255
284
  cleanups.push(release);
256
285
  return release;
257
286
  },
258
- /** 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 */
287
+ /** The element with the focus in the root's own tree, or in a root that joined: a Document's or a shadow root's `activeElement`, or the document's when it is inside the root; else null */
259
288
  active: () => {
260
- if (!root || !doc) return null;
261
- if (root.nodeType !== 1) return root.activeElement || null; // a Document or a shadow root
262
- // 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)
263
- // finds its own focused element, where the document's would be the shadow root's host
264
- const tree = typeof root.getRootNode === 'function' ? root.getRootNode() : doc;
265
- const focused = tree && tree.activeElement !== undefined ? tree.activeElement : doc.activeElement;
266
- return focused && root.contains(focused) ? focused : null;
289
+ if (!doc) return null;
290
+ for (const r of [root, ...joined]) {
291
+ const found = r && activeIn(r);
292
+ if (found) return found;
293
+ }
294
+ return null;
267
295
  },
296
+ extraRoots: joined,
268
297
 
269
298
  // -- what the viewer prefers --------------------------------------------------------------------------------------------------
270
299
  /** A reader of the computed custom properties at the root (`(name) => value`), or null where there is no page */
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @module explorer/pieces/around
3
+ *
4
+ * The pieces around the map (node panel, Layers menu, search) as a component mounts them (spec 0011 D4, D5, D7): each in a shadow root of its own, on the
5
+ * instance of the `<corn-scope>` it sits in, beside a `<corn-map>` that has a root of its own too. This is what a shell of those tags calls; cornfield's page
6
+ * and `<corn-review>` mount the same pieces themselves, in one root, and do not use it.
7
+ *
8
+ * const around = mountAround(piece, root, inst, options) -> { inst, update, destroy, focusField }
9
+ *
10
+ * piece the piece's module (`explorer/pieces/node-panel.js`, `layers.js`, `search.js`): its `mount(root, inst, options)`
11
+ * root the shadow root of the tag
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
+ * 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)
15
+ *
16
+ * What it does so that three roots can share one instance:
17
+ * - 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
18
+ * host's page outside the Layers menu closes it;
19
+ * - the server's theme is adopted into the root (`use-theme` on the scope), after the tag's own styles;
20
+ * - 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
+ * 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
+ * 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.
24
+ * Nothing here reads the page: no `document`, no id of a neighbour. It never throws for a missing scope or map.
25
+ */
26
+
27
+ import { createInstance } from '../instance.js';
28
+ import { scopeOf, place } from '../engine/piece.js';
29
+ import { joinRoot } from '../engine/roots.js';
30
+ import { speaker } from '../engine/keyboard.js';
31
+ import { t } from '../engine/strings.js';
32
+ import { escapeHtml } from '../../core/text.js';
33
+ import { adoptDefaultTokens } from './adopt-tokens.js';
34
+ import { scopeInfo } from './scope-link.js';
35
+
36
+ /** The document, and the shadow root the tag's host sits in if it is in one: where the default tokens go (as pieces/map.js does) */
37
+ function adoptTokens(root, css) {
38
+ const host = root.nodeType === 11 ? root.host : root;
39
+ const where = host && typeof host.getRootNode === 'function' ? host.getRootNode() : null;
40
+ if (!where || !css) return;
41
+ adoptDefaultTokens(where.nodeType === 9 ? where : where.ownerDocument, css);
42
+ if (where.nodeType === 11) adoptDefaultTokens(where, css);
43
+ }
44
+
45
+ /**
46
+ * @param {{ mount: Function }} piece
47
+ * @param {ShadowRoot|Element} root
48
+ * @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]
50
+ */
51
+ export function mountAround(piece, root, inst, options = {}) {
52
+ const ownsInstance = !inst;
53
+ if (ownsInstance) inst = createInstance({ root });
54
+ const info = scopeInfo(inst);
55
+ const scope = scopeOf(inst);
56
+ adoptTokens(root, options.tokens);
57
+ scope.own(joinRoot(inst, root));
58
+ if (info && info.serverTheme) scope.own(info.serverTheme.adopt(root));
59
+ // A live region for the words this piece says when no map is there to say them
60
+ const [region] = place(inst, root, '<p class="hx-sr-only" role="status" aria-live="polite"></p>', null, 'announcer');
61
+ const say = speaker(inst, region);
62
+ scope.on('announce:fallback', (text) => { say(text); return true; });
63
+ scope.own(() => region.remove());
64
+
65
+ let real = null;
66
+ let note = [];
67
+ let pending = { ...(options.initial || {}) };
68
+ let ended = false;
69
+
70
+ const dropNote = () => { for (const el of note) el.remove(); note = []; };
71
+ /** The map is there and has nodes: a map still loading, refused by its server (signed out, not a maintainer) or offline has none, and a search or a
72
+ * Layers menu over nothing would say "No match" or count layers of a map nobody can see. The map's own card says what is wrong, once */
73
+ const hasMap = () => !!inst.map && inst.state.nodes.length > 0;
74
+ const showNote = (gone = false) => {
75
+ 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');
77
+ if (note.length && note[0].textContent === words) return;
78
+ dropNote();
79
+ note = place(inst, root, `<p class="hx-needs" data-corn="empty">${escapeHtml(words)}</p>`, null, 'needs');
80
+ };
81
+ const mountReal = () => {
82
+ if (real || ended) return;
83
+ if (!hasMap()) { showNote(); return; }
84
+ dropNote();
85
+ real = piece.mount(root, inst, { ...(options.piece || {}), inline: true, phone: false });
86
+ if (Object.keys(pending).length) { real.update(pending); pending = {}; }
87
+ };
88
+ const unmountReal = () => { if (real) { real.destroy(); real = null; } };
89
+
90
+ scope.on('map:ready', mountReal);
91
+ scope.on('scene', () => { if (!real) mountReal(); }); // the map's data came (its server answered, or the host handed it in)
92
+ scope.on('map:gone', () => { unmountReal(); showNote(true); }); // (said while the map ends: the instance may still hold it)
93
+ if (options.onSearch) scope.on('search', (d) => options.onSearch(d));
94
+ mountReal();
95
+
96
+ return {
97
+ inst,
98
+ /** Takes the properties that changed; one that arrives before the piece is mounted is applied when it is */
99
+ update(next = {}) {
100
+ if (ended) return;
101
+ if (real) real.update(next); else Object.assign(pending, next);
102
+ },
103
+ /** The search's field takes the focus (nothing when the piece is not mounted, or is not a search) */
104
+ focusField() { if (real && typeof real.focusField === 'function') real.focusField(); },
105
+ destroy() {
106
+ if (ended) return;
107
+ ended = true;
108
+ unmountReal();
109
+ dropNote();
110
+ scope.destroy();
111
+ if (ownsInstance) inst.destroy();
112
+ },
113
+ };
114
+ }
@@ -28,13 +28,14 @@ import { kindLetters } from '../../core/layers.js';
28
28
  import { reviewHides, rowKeyOf, shownByProposal } from '../layer-model.js';
29
29
  import { layerShows } from '../scene.js';
30
30
  import { STROKE_TOKEN, kindToken, mapStyleOf } from '../engine/map-style.js';
31
- import { over, parseColor, contrast } from '../../core/color.js';
31
+ import { over, parseColor, contrast, toHex } from '../../core/color.js';
32
32
  import { DARK_GROUND, LIGHT_GROUND } from '../theme-model.js';
33
33
  import { t } from '../engine/strings.js';
34
- import { renderFlowLegend } from '../engine/flow-ui.js';
34
+ import { renderFlowLegend } from '../engine/flow-legend.js';
35
35
  import { isOn, keepLayersIn, layerRows, redrawing, setProjectLayers, swatch, toggleAllLayers, toggleLayer } from '../engine/layers.js';
36
36
  import { layerOn } from '../layer-model.js';
37
37
  import { scopeOf, place, addParts } from '../engine/piece.js';
38
+ import { listenRoots, onPageClick } from '../engine/roots.js';
38
39
 
39
40
  /** The markup of the piece: the chip and its menu (its one place is `menu`) */
40
41
  export const markup = () => ({
@@ -102,6 +103,15 @@ export function mount(root, inst, options = {}) {
102
103
  function setMenu(open) {
103
104
  menu.hidden = !open;
104
105
  btn.setAttribute('aria-expanded', String(open));
106
+ if (open && options.inline) alignMenu();
107
+ }
108
+ /** In a box of its own (`<corn-layers>`) the menu hangs from the chip's start; where that runs past the window's end (a chip at the right of a host's
109
+ * toolbar) and there is room the other way, it hangs from the chip's end instead (`hx-menu--end`) */
110
+ function alignMenu() {
111
+ menu.classList.remove('hx-menu--end');
112
+ const room = inst.win ? inst.win.innerWidth : 0;
113
+ const r = menu.getBoundingClientRect();
114
+ if (room && r.width && r.right > room && wrap.getBoundingClientRect().right - r.width >= 0) menu.classList.add('hx-menu--end');
105
115
  }
106
116
  const toggleMenu = (open) => setMenu(open === undefined ? menu.hidden : !!open);
107
117
  const closeMenu = () => setMenu(false);
@@ -118,9 +128,9 @@ export function mount(root, inst, options = {}) {
118
128
  const [r, g, b] = over(surface, over(ground, [0, 0, 0, 1]));
119
129
  return `rgb(${r}, ${g}, ${b})`;
120
130
  }
121
- /** The outline a dot or swatch gets when its fill is under 3:1 on the menu: the map's own outline colour when the theme sets one, else the CSS default (`.is-ringed`). The fill is never changed */
131
+ /** The outline a dot or swatch gets when its fill (as it shows over the menu) is under 3:1 on the menu: the map's own outline colour when the theme sets one, else the CSS default (`.is-ringed`). The fill is never changed */
122
132
  function ringOf(color, surface) {
123
- if (contrast(color, surface) >= 3) return null;
133
+ if (contrast(toHex(over(parseColor(color), parseColor(surface))), surface) >= 3) return null; // a translucent fill is seen over the menu, as the node is over the ground
124
134
  const stroke = style().values[STROKE_TOKEN];
125
135
  return { stroke: stroke ? swatch(stroke) : '' };
126
136
  }
@@ -129,7 +139,7 @@ export function mount(root, inst, options = {}) {
129
139
  const ring = ringOf(color, surface);
130
140
  const glow = on && state.theme !== 'light' ? (/^#[0-9a-f]{6}$/i.test(color) ? `0 0 8px ${color}90` : `0 0 8px color-mix(in srgb, ${color} 56%, transparent)`) : 'none';
131
141
  const css = `background-color: ${color}; box-shadow: ${glow}${ring && ring.stroke ? `; --hx-dot-ring: ${ring.stroke}` : ''}`;
132
- return `<span class="hx-dot${extra ? ' hx-kind-swatch' : ''}${ring ? ' is-ringed' : ''}" data-corn="swatch"${extra} style="${escHtml(css)}"></span>`;
142
+ return `<span class="hx-dot${extra ? ' hx-kind-swatch' : ''}${ring ? ' is-ringed' : ''}" data-corn="swatch"${extra} data-style="${escHtml(css)}"></span>`;
133
143
  }
134
144
 
135
145
  // -- the kinds of a row ---------------------------------------------------------------------------------------------------------
@@ -230,7 +240,7 @@ export function mount(root, inst, options = {}) {
230
240
  const again = [...container.querySelectorAll('[data-action]')].find((el) => el.getAttribute('data-action') === was.action && el.getAttribute('data-layer') === was.layer);
231
241
  if (again && typeof again.focus === 'function') again.focus({ preventScroll: true });
232
242
  }
233
- renderFlowLegend(inst);
243
+ renderFlowLegend(inst, own('flow-legend'));
234
244
  renderEdgeKey();
235
245
  renderCloudLegend();
236
246
  addParts(own('flow-legend'));
@@ -282,22 +292,26 @@ export function mount(root, inst, options = {}) {
282
292
  const action = ACTIONS[target.dataset.action];
283
293
  if (action) action(target);
284
294
  });
285
- // Any click outside the menu closes it; a click on one of its rows does not. Whether it was inside is read BEFORE the action, in the capture
286
- // phase: a row's action draws the rows again, the clicked node is then out of the page, and asking afterwards would take a click on a row for one outside
287
- let inside = false;
288
- scope.listen(inst.root, 'click', (e) => {
289
- const target = e.target;
290
- inside = !!target && wrap.contains(target);
291
- }, true);
292
- scope.listen(inst.root, 'click', () => { if (!menu.hidden && !inside) closeMenu(); });
293
- // Escape with the menu open closes it, and its chip has the focus again
294
- scope.listen(inst.root, 'keydown', (e) => {
295
+ // Any click outside the menu closes it; a click on one of its rows does not. Whether it was inside is known before the action (a row's action draws the
296
+ // rows again, the clicked node is then out of the page, and asking afterwards would take a click on a row for one outside): the menu's own element hears
297
+ // the click on its way in, and the page decides once the click has passed. The page's own path is not enough: in a host's closed shadow root the
298
+ // document's `composedPath()` stops at that root's host, so a click on a row would look like one outside
299
+ const inside = new WeakSet();
300
+ scope.listen(wrap, 'click', (e) => { inside.add(e); }, true);
301
+ scope.own(onPageClick(inst, (e) => {
302
+ if (menu.hidden || inside.has(e)) return;
303
+ const path = typeof e.composedPath === 'function' ? e.composedPath() : [e.target];
304
+ if (!path.includes(wrap)) closeMenu();
305
+ }, { capture: false }));
306
+ // Escape with the menu open closes it, and its chip has the focus again (a key in any root of the instance: the map's too)
307
+ scope.own(listenRoots(inst, 'keydown', (e) => {
295
308
  if (e.key !== 'Escape' || menu.hidden) return;
296
309
  closeMenu();
297
310
  btn.focus();
298
- });
311
+ }));
299
312
 
300
313
  // -- following the instance ------------------------------------------------------------------------------------------------------
314
+ scope.on('layers:present', () => true); // the map's keys know there is a menu to turn a layer on in
301
315
  scope.on('layers:redraw', renderLayerToggles);
302
316
  scope.on('theme', renderLayerToggles); // the dots and the legends are drawn in the theme's colours
303
317
  scope.on('view', syncView);
@@ -46,7 +46,7 @@ import { createInstance } from '../instance.js';
46
46
  import { createMap } from '../engine/render.js';
47
47
  import { mapStyleOf } from '../engine/map-style.js';
48
48
  import { layoutMap, setTopology as installTopology } from '../engine/topology.js';
49
- import { initKeyboard, resetKeyboard } from '../engine/keyboard.js';
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';
52
52
  import { scopeOf, place } from '../engine/piece.js';
@@ -90,6 +90,7 @@ function refused(root, inst, info) {
90
90
  return {
91
91
  inst,
92
92
  refused: true,
93
+ selection: () => null,
93
94
  update: none,
94
95
  fit: none,
95
96
  refresh: none,
@@ -139,6 +140,7 @@ function mountWithSource(root, options) {
139
140
  return {
140
141
  get inst() { return real ? real.inst : null; },
141
142
  get map() { return real ? real.map : null; },
143
+ selection() { return real ? real.selection() : null; },
142
144
  update(next = {}) { if (real) real.update(next); else Object.assign(pending, next); },
143
145
  fit() { if (real) real.fit(); },
144
146
  focusNode(id) { return real ? real.focusNode(id) : false; },
@@ -193,6 +195,9 @@ function mountOn(root, inst, options, privateScope) {
193
195
  const made = place(inst, root, slots ? html : `<div data-corn="map-stage">${html}</div>`, slots, 'stage');
194
196
  const find = (sel) => made.map((el) => (el.matches(sel) ? el : el.querySelector(sel))).find(Boolean);
195
197
  scope.own(() => { for (const el of [...made, state.canvas]) if (el) el.remove(); });
198
+ // The announcer is this piece's: what a screen reader is told (engine/keyboard.js `announce`) is written in it
199
+ const announcer = find('#map-announcer');
200
+ if (announcer) { const say = speaker(inst, announcer); scope.on('announce:write', (text) => { say(text); return true; }); }
196
201
  // What the person sees while the data loads and when it cannot be had (pieces/status.js): only a map that has a source
197
202
  const stage = made.find((el) => el.matches('[data-corn="map-stage"]')) || null;
198
203
  if (source && stage) {
@@ -400,10 +405,18 @@ function mountOn(root, inst, options, privateScope) {
400
405
  update(first);
401
406
  takeSource();
402
407
  refresh();
408
+ scope.own(() => inst.emit('map:gone')); // the pieces around the map (pieces/around.js) go back to waiting for one
409
+ inst.emit('map:ready'); // ... and the ones that waited for it mount
403
410
 
404
411
  return {
405
412
  inst,
406
413
  map,
414
+ /** What the instance has selected now, whoever chose it (a piece mounted late is handed it): `{ id, kind }`, or null */
415
+ selection() {
416
+ if (state.selectedNode) return { id: state.selectedNode.id, kind: 'node' };
417
+ if (state.selectedEdge) return { id: `${state.selectedEdge.from}->${state.selectedEdge.to}`, kind: 'edge' };
418
+ return null;
419
+ },
407
420
  update,
408
421
  destroy,
409
422
  /** The whole map in view */
@@ -17,7 +17,10 @@
17
17
  *
18
18
  * @param {ParentNode} root where the panel goes when `options.slots` names no place
19
19
  * @param {ReturnType<typeof import('../instance.js').createInstance>} inst the instance; its map must be made (engine/render.js)
20
- * @param {{ slots?: { drawer?: Node, backdrop?: Node } }} [options]
20
+ * `options.inline` is the panel in a box of its own (`<corn-node-panel>`): it fills the box its host gives it instead of sliding over the map, never becomes a phone's
21
+ * bottom sheet (no dock, no dim layer: the host's layout decides where it is), says what it needs while nothing is selected (`empty`), and covers nothing of the map.
22
+ *
23
+ * @param {{ slots?: { drawer?: Node, backdrop?: Node }, inline?: boolean }} [options]
21
24
  * @returns {{ update: (props?: { node?: object | null }) => void, destroy: () => void, show: Function, close: Function, repaintThreads: Function, copySpec: Function, startRun: Function, keepSelectedInView: Function, elements: Element[] }}
22
25
  * `update({ node })` shows that node (or closes the panel for `null`) without selecting it; `update()` paints the open panel again from the
23
26
  * instance's state (after the host changed the topology or the words).
@@ -290,9 +293,10 @@ export function mount(root, inst, options = {}) {
290
293
  const { state } = inst;
291
294
  const scope = scopeOf(inst);
292
295
  const sections = sectionsOf(inst);
296
+ const inline = options.inline === true;
293
297
  const made = [
294
298
  ...place(inst, root, markup().drawer, options.slots, 'drawer'),
295
- ...place(inst, root, markup().backdrop, options.slots, 'backdrop'),
299
+ ...(inline ? place(inst, root, `<p class="hx-panel-empty" data-corn="empty">${escHtml(t(inst, 'nodePanelEmpty'))}</p>`, null, 'empty') : place(inst, root, markup().backdrop, options.slots, 'backdrop')),
296
300
  ];
297
301
  /** An element of this piece by id (the piece's own, whatever else the root holds) */
298
302
  const own = (id) => {
@@ -305,7 +309,9 @@ export function mount(root, inst, options = {}) {
305
309
  };
306
310
  scope.keepParts(...made);
307
311
  const drawer = own('spec-drawer');
308
- const backdrop = own('drawer-backdrop');
312
+ const backdrop = inline ? { hidden: true } : own('drawer-backdrop'); // (a box of its own has no dim layer)
313
+ const empty = inline ? made.find((el) => el.matches('[data-corn="empty"]')) : null;
314
+ const setEmpty = (shown) => { if (empty) empty.hidden = !shown; };
309
315
  let gone = false;
310
316
 
311
317
  const litNow = () => activeSubgraph(state.selectedNode, inst.viewEdges(), { throughChildren: state.throughChildren, kind: state.selectedKind });
@@ -434,8 +440,9 @@ export function mount(root, inst, options = {}) {
434
440
  drawer.classList.add('drawer-open');
435
441
  drawer.inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
436
442
  backdrop.hidden = false;
437
- showSheet(inst, 'drawer'); // on a phone it takes Work's place (the node sheet and Work take turns), and comes back from away when its node is tapped again
438
- if (!frame) keepSelectedInView(); // with `frame`, the selection flies the camera to the node once this returns (engine/selection.js)
443
+ setEmpty(false);
444
+ if (!inline) showSheet(inst, 'drawer'); // on a phone it takes Work's place (the node sheet and Work take turns), and comes back from away when its node is tapped again
445
+ if (!frame && !inline) keepSelectedInView(); // with `frame`, the selection flies the camera to the node once this returns (engine/selection.js)
439
446
  inst.emit('node:painted', { node });
440
447
  }
441
448
 
@@ -469,6 +476,7 @@ export function mount(root, inst, options = {}) {
469
476
  drawer.classList.add('drawer-open');
470
477
  drawer.inert = false; // closed, the panel is inert (MAP-02): open for an edge, its links and its Close are reached as a node's are
471
478
  backdrop.hidden = false;
479
+ setEmpty(false);
472
480
  }
473
481
 
474
482
  /**
@@ -489,7 +497,8 @@ export function mount(root, inst, options = {}) {
489
497
  drawer.classList.remove('drawer-open');
490
498
  drawer.inert = true;
491
499
  backdrop.hidden = true;
492
- collapseSheet(inst, 'drawer'); // the next node opens as a peek on a phone
500
+ setEmpty(true);
501
+ if (!inline) collapseSheet(inst, 'drawer'); // the next node opens as a peek on a phone
493
502
  }
494
503
 
495
504
  /** Start a run: the Start dialog of the Work panel, on the proposal that is open */
@@ -525,10 +534,12 @@ export function mount(root, inst, options = {}) {
525
534
  // The threads that mention nodes changed (the list was read, or the map changed): the section is drawn again
526
535
  scope.on('threads:changed', () => repaintThreads());
527
536
  // The dim layer behind the panel: on a phone a tap there folds the panel to its peek; elsewhere it closes it
528
- scope.listen(backdrop, 'click', (e) => {
529
- if (isPhone(inst)) { onBackdrop(inst, e); return; }
530
- clearSelection(inst, { source: 'tap' });
531
- }, true);
537
+ if (!inline) {
538
+ scope.listen(backdrop, 'click', (e) => {
539
+ if (isPhone(inst)) { onBackdrop(inst, e); return; }
540
+ clearSelection(inst, { source: 'tap' });
541
+ }, true);
542
+ }
532
543
  // Escape anywhere in the panel closes it, and the map has the focus again
533
544
  scope.listen(drawer, 'keydown', (e) => {
534
545
  if (e.key !== 'Escape' || e.defaultPrevented) return;
@@ -539,6 +550,9 @@ export function mount(root, inst, options = {}) {
539
550
  announce(inst, 'Panel closed');
540
551
  });
541
552
 
553
+ scope.on('panel:present', () => true); // the map says "Panel closed", not "Selection cleared"
554
+ // A slide-over covers the right of the map by its width; a panel in a box of its own (`inline`) covers nothing
555
+ scope.on('panel:covers', () => (!inline && !gone && !drawer.hidden && drawer.classList.contains('drawer-open') ? { right: drawer.offsetWidth } : undefined));
542
556
  scope.on('node:show', ({ node, frame }) => show(node, { frame }));
543
557
  scope.on('node:close', close);
544
558
  scope.on('node:show-edge', ({ edge }) => showEdge(edge));
@@ -546,14 +560,18 @@ export function mount(root, inst, options = {}) {
546
560
  scope.on('node:focus', () => {
547
561
  const title = own('drawer-title');
548
562
  if (!title) return;
563
+ // A second panel in one scope (two tags, one maybe hidden by the host's layout) leaves the focus where the first that could take it put it
564
+ const now = inst.active();
565
+ if (inline && now && now !== title && typeof now.matches === 'function' && now.matches('[data-corn="node-title"]')) return;
549
566
  title.setAttribute('tabindex', '-1');
550
567
  title.focus();
551
568
  });
552
- scope.own(onCoveredChange(inst, () => keepSelectedInView()));
553
-
554
- initSheets(inst);
555
- registerSheet(inst, 'drawer', drawer, { stub: () => ({ title: (own('drawer-title') && own('drawer-title').textContent) || 'Node' }) });
556
- scope.own(() => unregisterSheet(inst, 'drawer'));
569
+ if (!inline) {
570
+ scope.own(onCoveredChange(inst, () => keepSelectedInView()));
571
+ initSheets(inst);
572
+ registerSheet(inst, 'drawer', drawer, { stub: () => ({ title: (own('drawer-title') && own('drawer-title').textContent) || 'Node' }) });
573
+ scope.own(() => unregisterSheet(inst, 'drawer'));
574
+ }
557
575
 
558
576
  // A node was selected before the panel came: it shows it
559
577
  if (state.selectedNode) show(state.selectedNode, { frame: false });