cornfield 0.46.1 → 0.46.2
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/explorer/capped.js +3 -2
- package/explorer/engine/feedback.js +49 -0
- package/explorer/engine/flow-ui.js +39 -0
- package/explorer/engine/fly.js +54 -0
- package/explorer/engine/hint.js +97 -0
- package/explorer/engine/keyboard.js +156 -0
- package/explorer/engine/layers.js +280 -0
- package/explorer/engine/layout.js +378 -0
- package/explorer/engine/map-style.js +547 -0
- package/explorer/engine/piece.js +142 -0
- package/explorer/engine/render.js +331 -0
- package/explorer/engine/search-status.js +59 -0
- package/explorer/engine/selection.js +42 -0
- package/explorer/engine/sheets.js +417 -0
- package/explorer/engine/strings.js +63 -0
- package/explorer/feedback.js +11 -45
- package/explorer/flow-style.js +28 -0
- package/explorer/flows.js +10 -51
- package/explorer/fly.js +11 -43
- package/explorer/hint.js +15 -88
- package/explorer/index.html +38 -75
- package/explorer/input.js +190 -177
- package/explorer/instance-state.js +172 -0
- package/explorer/instance.js +267 -0
- package/explorer/keyboard.js +14 -206
- package/explorer/labels.js +3 -3
- package/explorer/layers.js +34 -445
- package/explorer/layout.js +14 -372
- package/explorer/main.js +4 -226
- package/explorer/map-style.js +27 -525
- package/explorer/mockups-model.js +3 -3
- package/explorer/page-pieces.js +61 -0
- package/explorer/page.js +232 -0
- package/explorer/panels.js +29 -409
- package/explorer/pieces/layers.js +325 -0
- package/explorer/pieces/node-panel.js +536 -0
- package/explorer/pieces/search.js +454 -0
- package/explorer/proposal-model.js +1 -1
- package/explorer/proposal.js +1 -0
- package/explorer/render.js +37 -267
- package/explorer/renderer-canvas2d.js +4 -4
- package/explorer/renderer-webgl.js +21 -8
- package/explorer/renderer.js +11 -9
- package/explorer/scene.js +3 -2
- package/explorer/search-status.js +8 -47
- package/explorer/search.js +26 -324
- package/explorer/selection-view.js +17 -19
- package/explorer/sheets.js +31 -379
- package/explorer/state.js +38 -173
- package/explorer/strings.js +17 -60
- package/explorer/view.js +4 -5
- package/package.json +1 -1
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/layers
|
|
3
|
+
*
|
|
4
|
+
* The Layers menu as a piece (spec 0011 D3): one toggle per kind of node (apps, pages, tables, services, ...) with its count, plus the legend
|
|
5
|
+
* of what the lines mean. The data-flow preset ignores the toggles. What the layers are, which are on and what a review shows is the instance's
|
|
6
|
+
* (engine/layers.js); this is the chip, the menu and its rows.
|
|
7
|
+
*
|
|
8
|
+
* mount(root, inst, options) -> { update, destroy, ... }
|
|
9
|
+
*
|
|
10
|
+
* The piece makes its own markup (`markup()`) and puts it in `root`, or before the node `options.slots.menu`. It draws itself again on
|
|
11
|
+
* `layers:redraw` (a layer, the nodes or a review changed: engine/layers.js), on `theme` (the host says light or dark changed), and when the
|
|
12
|
+
* map's own style changes; it follows `view` (the chip dims while the data-flow view is on). Its buttons are its own: the chip, All, None, a
|
|
13
|
+
* row, a row's kinds. A click anywhere in the root outside the menu closes it, and Escape inside the root closes it with the focus back on the
|
|
14
|
+
* chip. `options.storageKey` is where the viewer's choices are kept in their browser (`cornfield:layers` by default, `null` for nowhere).
|
|
15
|
+
* `destroy()` takes back every listener and removes the elements.
|
|
16
|
+
*
|
|
17
|
+
* @param {ParentNode} root where the menu goes when `options.slots` names no place
|
|
18
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst the instance; its map must be made (engine/render.js)
|
|
19
|
+
* @param {{ slots?: { menu?: Node }, storageKey?: string | null }} [options]
|
|
20
|
+
* @returns {{ update: (props?: { layers?: unknown }) => void, destroy: () => void, elements: Element[], renderToggles: () => void, renderEdgeKey: () => void, renderCloudLegend: () => void, toggleMenu: (open?: boolean) => void, closeMenu: () => void, toggleKinds: (key: string) => void }}
|
|
21
|
+
* `update({ layers })` takes the project's layers (the config's `layers`) and draws; `update()` draws again
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
25
|
+
import { WHEN_STYLES } from '../cloud-model.js';
|
|
26
|
+
import { edgeKeyHtml, keySwatch } from '../edge-key.js';
|
|
27
|
+
import { kindLetters } from '../../core/layers.js';
|
|
28
|
+
import { reviewHides, rowKeyOf, shownByProposal } from '../layer-model.js';
|
|
29
|
+
import { layerShows } from '../scene.js';
|
|
30
|
+
import { STROKE_TOKEN, kindToken, mapStyleOf } from '../engine/map-style.js';
|
|
31
|
+
import { over, parseColor, contrast } from '../../core/color.js';
|
|
32
|
+
import { DARK_GROUND, LIGHT_GROUND } from '../theme-model.js';
|
|
33
|
+
import { t } from '../engine/strings.js';
|
|
34
|
+
import { renderFlowLegend } from '../engine/flow-ui.js';
|
|
35
|
+
import { isOn, keepLayersIn, layerRows, redrawing, setProjectLayers, swatch, toggleAllLayers, toggleLayer } from '../engine/layers.js';
|
|
36
|
+
import { layerOn } from '../layer-model.js';
|
|
37
|
+
import { scopeOf, place, addParts } from '../engine/piece.js';
|
|
38
|
+
|
|
39
|
+
/** The markup of the piece: the chip and its menu (its one place is `menu`) */
|
|
40
|
+
export const markup = () => ({
|
|
41
|
+
menu: `<div class="hx-menu-wrap hx-layers">
|
|
42
|
+
<button type="button" id="legend-toggle-btn" class="hx-layers-chip" data-action="toggle-layers-menu" aria-expanded="false" aria-controls="legend-dropdown" data-corn="layers-button"><span data-corn-string="layers">Layers</span><span id="layers-count" class="hx-layers-count" data-corn="count"></span></button>
|
|
43
|
+
<div id="legend-dropdown" class="hx-menu glass" hidden data-corn="layers-menu">
|
|
44
|
+
<div class="hx-menu-title hx-menu-head" data-corn="menu-title">
|
|
45
|
+
<span>Section Toggles</span>
|
|
46
|
+
<span class="hx-menu-links">
|
|
47
|
+
<button type="button" class="hx-textbtn hx-textbtn--accent" data-action="layers-all" data-corn="layers-all" data-corn-kind="quiet" data-corn-string="layersAll">All</button>
|
|
48
|
+
<span class="hx-faint">•</span>
|
|
49
|
+
<button type="button" class="hx-textbtn" data-action="layers-none" data-corn="layers-none" data-corn-kind="quiet" data-corn-string="layersNone">None</button>
|
|
50
|
+
</span>
|
|
51
|
+
</div>
|
|
52
|
+
<div class="hx-menu-body">
|
|
53
|
+
<p id="layers-preset-note" class="hx-note" data-corn="notice" hidden>The data-flow view shows its own tiers and ignores these toggles. Switch it off to use them.</p>
|
|
54
|
+
<div id="layer-toggles-container" class="hx-toggles"></div>
|
|
55
|
+
<div id="flow-legend" hidden></div>
|
|
56
|
+
<div id="edge-key" class="hx-menu-section" data-corn="legend-key"></div>
|
|
57
|
+
<div id="cloud-legend" class="hx-menu-section" data-corn="menu-section" hidden></div>
|
|
58
|
+
<div id="runs-legend" class="hx-menu-section" data-corn="menu-section" hidden>
|
|
59
|
+
<div class="hx-menu-title" data-corn="menu-title"><span>Agent runs</span></div>
|
|
60
|
+
<div class="hx-legend-row"><span class="hx-run-swatch hx-run-swatch--flight" aria-hidden="true"></span><span>In flight: a pulsing ring (still under reduced motion)</span></div>
|
|
61
|
+
<div class="hx-legend-row"><span class="hx-run-swatch hx-run-swatch--collision" aria-hidden="true"></span><span>Collision: dashed ring, ⚠ and the words, where two open runs change one node</span></div>
|
|
62
|
+
</div>
|
|
63
|
+
<div id="proposal-legend" class="hx-menu-section" data-corn="menu-section" hidden>
|
|
64
|
+
<div class="hx-menu-title" data-corn="menu-title"><span>Proposal marks</span></div>
|
|
65
|
+
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--added" data-corn="mark-dot" data-corn-state="added"></span><span>Added: dashed ring</span></div>
|
|
66
|
+
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed"></span><span>Changed: solid ring</span></div>
|
|
67
|
+
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed" data-corn="mark-dot" data-corn-state="removed"></span><span>Removed: faded ring, label struck through</span></div>
|
|
68
|
+
<div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit" data-corn="mark-dot" data-corn-state="edit"></span><span>Your edit: dotted ring, long-dashed line</span></div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</div>`,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/** "1 link", "3 in flight", else the number */
|
|
76
|
+
const UNIT = Object.assign(Object.create(null), { flow: (n) => `${n} ${n === 1 ? 'link' : 'links'}`, runs: (n) => `${n} in flight` });
|
|
77
|
+
|
|
78
|
+
/** Mounts the Layers menu; see the top of this file */
|
|
79
|
+
export function mount(root, inst, options = {}) {
|
|
80
|
+
const { state } = inst;
|
|
81
|
+
const scope = scopeOf(inst);
|
|
82
|
+
const made = place(inst, root, markup().menu, options.slots, 'menu');
|
|
83
|
+
/** An element of this piece by id */
|
|
84
|
+
const own = (id) => {
|
|
85
|
+
for (const el of made) {
|
|
86
|
+
if (el.id === id) return el;
|
|
87
|
+
const found = el.querySelector(`[id="${id}"]`);
|
|
88
|
+
if (found) return found;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
scope.keepParts(...made);
|
|
93
|
+
const wrap = made[0];
|
|
94
|
+
const menu = own('legend-dropdown');
|
|
95
|
+
const btn = own('legend-toggle-btn');
|
|
96
|
+
/** The rows whose kinds are open ("5 kinds"), by key: kept across redraws */
|
|
97
|
+
const openKinds = new Set();
|
|
98
|
+
const style = () => mapStyleOf(inst).get();
|
|
99
|
+
if ('storageKey' in options) keepLayersIn(inst, options.storageKey);
|
|
100
|
+
|
|
101
|
+
// -- the menu open or shut, and its chip saying which (aria-expanded) -----------------------------------------------------------
|
|
102
|
+
function setMenu(open) {
|
|
103
|
+
menu.hidden = !open;
|
|
104
|
+
btn.setAttribute('aria-expanded', String(open));
|
|
105
|
+
}
|
|
106
|
+
const toggleMenu = (open) => setMenu(open === undefined ? menu.hidden : !!open);
|
|
107
|
+
const closeMenu = () => setMenu(false);
|
|
108
|
+
|
|
109
|
+
// -- the dots ------------------------------------------------------------------------------------------------------------------
|
|
110
|
+
/** The ground of the menu: its surface laid over the page, as `--corn-surface-1` and `--corn-ground` say, else the theme's own ground */
|
|
111
|
+
function menuSurface() {
|
|
112
|
+
const fallback = state.theme === 'light' ? LIGHT_GROUND : DARK_GROUND;
|
|
113
|
+
const read = inst.tokenReader();
|
|
114
|
+
if (!read) return fallback;
|
|
115
|
+
const ground = parseColor(read('--corn-ground'));
|
|
116
|
+
const surface = parseColor(read('--corn-surface-1'));
|
|
117
|
+
if (!ground[3] || !surface[3]) return fallback;
|
|
118
|
+
const [r, g, b] = over(surface, over(ground, [0, 0, 0, 1]));
|
|
119
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
120
|
+
}
|
|
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 */
|
|
122
|
+
function ringOf(color, surface) {
|
|
123
|
+
if (contrast(color, surface) >= 3) return null;
|
|
124
|
+
const stroke = style().values[STROKE_TOKEN];
|
|
125
|
+
return { stroke: stroke ? swatch(stroke) : '' };
|
|
126
|
+
}
|
|
127
|
+
/** A swatch of `color` on this menu: the fill, a soft glow on a dark ground, and the outline when it is needed. `extra` is more attributes (a kind's is `aria-hidden`) */
|
|
128
|
+
function dot(color, on, surface, extra = '') {
|
|
129
|
+
const ring = ringOf(color, surface);
|
|
130
|
+
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
|
+
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>`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// -- the kinds of a row ---------------------------------------------------------------------------------------------------------
|
|
136
|
+
/** The finer kinds of each row: `{ key: [{ kind, letters, n }] }`, by name, from the nodes the row holds (an outside node's kind is its layer, not a finer one) */
|
|
137
|
+
function kindsByRow(rowOf) {
|
|
138
|
+
const letters = kindLetters(state.nodes);
|
|
139
|
+
const rows = new Map();
|
|
140
|
+
state.nodes.forEach((n) => {
|
|
141
|
+
if (typeof n.kind !== 'string' || !n.kind || n.type === 'external') return;
|
|
142
|
+
const key = rowOf(n);
|
|
143
|
+
if (!key) return;
|
|
144
|
+
if (!rows.has(key)) rows.set(key, new Map());
|
|
145
|
+
const id = `${n.type}\u0000${n.kind}`;
|
|
146
|
+
const entry = rows.get(key).get(id) || { type: n.type, kind: n.kind, letters: letters.get(n.type).get(n.kind), n: 0 };
|
|
147
|
+
entry.n++;
|
|
148
|
+
rows.get(key).set(id, entry);
|
|
149
|
+
});
|
|
150
|
+
return new Map([...rows].map(([k, m]) => [k, [...m.values()].sort((a, b) => a.kind.localeCompare(b.kind))]));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The swatch of a kind: the theme's `--corn-map-kind-<type>-<kind>`, as the map draws that kind, or nothing when the token is unset (the node then has its type's colour, which is the row's dot). Decoration: the letters and the name say which kind it is */
|
|
154
|
+
function kindSwatch(k, surface, pad) {
|
|
155
|
+
const fill = style().values[kindToken(k.type, k.kind)];
|
|
156
|
+
if (!fill) return pad ? '<span class="hx-dot hx-kind-swatch is-blank" aria-hidden="true"></span>' : ''; // nothing to see, but the letters of the rows stay in line
|
|
157
|
+
return dot(swatch(fill), true, surface, ' aria-hidden="true"');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** What a viewer sees as "kinds" for a row: the disclosure button and, when open, the key rows. A key is a key, not a toggle (spec 0009 D5) */
|
|
161
|
+
function kindsHtml(layer, kinds, surface) {
|
|
162
|
+
if (!kinds || !kinds.length) return '';
|
|
163
|
+
const open = openKinds.has(layer.key);
|
|
164
|
+
const id = `layer-kinds-${layer.key}`;
|
|
165
|
+
const words = `${kinds.length} ${kinds.length === 1 ? 'kind' : 'kinds'}`;
|
|
166
|
+
const padded = kinds.some((k) => style().values[kindToken(k.type, k.kind)]);
|
|
167
|
+
const list = open ? `<ul class="hx-kind-keys" id="${escHtml(id)}">${kinds.map((k) => `<li class="hx-kind-key" data-corn="kind-key">${kindSwatch(k, surface, padded)}<span class="hx-kind-letter" aria-hidden="true">${escHtml(k.letters)}</span><span class="hx-kind-name">${escHtml(k.kind)}</span><span class="hx-count" data-corn="count">${k.n}</span></li>`).join('')}</ul>` : '';
|
|
168
|
+
return `<div class="hx-kinds"><button type="button" class="hx-textbtn hx-kinds-btn" data-action="toggle-layer-kinds" data-layer="${escHtml(layer.key)}" aria-expanded="${open}" aria-controls="${escHtml(id)}" data-corn="layer-kinds" data-corn-kind="quiet">${open ? '▾' : '▸'} ${escHtml(words)}</button>${list}</div>`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// -- the rows ------------------------------------------------------------------------------------------------------------------
|
|
172
|
+
/** The chip says how many layers are on: " · 13 of 20". An overlay (Runs in flight) is not a layer: it is not counted */
|
|
173
|
+
function paintCount() {
|
|
174
|
+
const el = own('layers-count');
|
|
175
|
+
if (!el) return;
|
|
176
|
+
const { layers } = layerRows(inst);
|
|
177
|
+
const on = layers.filter((l) => isOn(inst, l.key)).length;
|
|
178
|
+
el.textContent = ` · ${on} of ${layers.length}`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function renderLayerToggles() {
|
|
182
|
+
paintCount();
|
|
183
|
+
const container = own('layer-toggles-container');
|
|
184
|
+
if (!container) return;
|
|
185
|
+
|
|
186
|
+
// Nodes by row. Data Flow has no nodes of its own: it counts its links, and says so; Runs in flight counts runs
|
|
187
|
+
const rowOf = (n) => rowKeyOf(state, n);
|
|
188
|
+
// Keyed by layer key: a project's key may be any word, "constructor" too, so these have no prototype to read through
|
|
189
|
+
const counts = Object.create(null);
|
|
190
|
+
const byProposal = Object.create(null);
|
|
191
|
+
state.nodes.forEach((n) => {
|
|
192
|
+
const key = rowOf(n);
|
|
193
|
+
if (!key) return;
|
|
194
|
+
counts[key] = (counts[key] || 0) + 1;
|
|
195
|
+
if (!layerShows(state, n) && shownByProposal(state, n)) byProposal[key] = (byProposal[key] || 0) + 1;
|
|
196
|
+
});
|
|
197
|
+
counts.flow = state.edges.filter((e) => e.kind === 'flow').length;
|
|
198
|
+
counts.runs = state.runsMap ? state.runsMap.flight.size : 0;
|
|
199
|
+
const kinds = kindsByRow(rowOf);
|
|
200
|
+
const { layers, overlays } = layerRows(inst);
|
|
201
|
+
const surface = menuSurface();
|
|
202
|
+
|
|
203
|
+
const row = (layer) => {
|
|
204
|
+
const on = isOn(inst, layer.key);
|
|
205
|
+
const shown = byProposal[layer.key] ? `<span class="hx-faint hx-layer-note" data-corn="layer-note">+${byProposal[layer.key]} shown by the proposal</span>` : '';
|
|
206
|
+
// A row the review hid says so under its name (there is no room beside it): it can still be turned on, for the review
|
|
207
|
+
const hid = !shown && counts[layer.key] && reviewHides(state, layer.key) ? `<span class="hx-faint hx-layer-note" data-corn="layer-note">${escHtml(t(inst, 'hiddenWhileReviewing'))}</span>` : '';
|
|
208
|
+
const name = `<span class="hx-toggle-name">${escHtml(layer.label)}</span>`;
|
|
209
|
+
return `
|
|
210
|
+
<button type="button" class="hx-toggle-row${on ? '' : ' is-off'}" data-action="toggle-layer" data-layer="${escHtml(layer.key)}" aria-pressed="${on}" title="${escHtml(layer.desc)}" data-corn="row">
|
|
211
|
+
<span class="hx-toggle-label">
|
|
212
|
+
${dot(swatch(layer.color), on, surface)}
|
|
213
|
+
${hid ? `<span class="hx-toggle-text">${name}${hid}</span>` : name}${layer.live ? '<span class="hx-live-tag" data-corn="live-tag">live</span>' : ''}
|
|
214
|
+
</span>
|
|
215
|
+
<span class="hx-toggle-meta">${shown}
|
|
216
|
+
<span class="hx-count" data-corn="count">${(UNIT[layer.key] || String)(counts[layer.key] || 0)}</span>
|
|
217
|
+
<span class="hx-tick">${on ? '✓' : '—'}</span>
|
|
218
|
+
</span>
|
|
219
|
+
</button>${kindsHtml(layer, kinds.get(layer.key), surface)}`;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// The focus stays where it was across the redraw: the same row or disclosure, found again by what it names
|
|
223
|
+
const focused = inst.active();
|
|
224
|
+
const active = focused && container.contains(focused) ? focused : null;
|
|
225
|
+
const was = active ? { action: active.getAttribute('data-action'), layer: active.getAttribute('data-layer') } : null;
|
|
226
|
+
container.innerHTML = layers.map(row).join('')
|
|
227
|
+
+ (overlays.length ? `<div class="hx-menu-title hx-overlays" data-corn="overlays"><span>${escHtml(t(inst, 'overlays'))}</span></div>${overlays.map(row).join('')}` : '');
|
|
228
|
+
addParts(container);
|
|
229
|
+
if (was) {
|
|
230
|
+
const again = [...container.querySelectorAll('[data-action]')].find((el) => el.getAttribute('data-action') === was.action && el.getAttribute('data-layer') === was.layer);
|
|
231
|
+
if (again && typeof again.focus === 'function') again.focus({ preventScroll: true });
|
|
232
|
+
}
|
|
233
|
+
renderFlowLegend(inst);
|
|
234
|
+
renderEdgeKey();
|
|
235
|
+
renderCloudLegend();
|
|
236
|
+
addParts(own('flow-legend'));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The Key (spec 0008 D7): each kind of line as the map draws it (edge-key.js) */
|
|
240
|
+
function renderEdgeKey() {
|
|
241
|
+
const el = own('edge-key');
|
|
242
|
+
if (el) { el.innerHTML = edgeKeyHtml(); addParts(el); }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** What a call into a cloud node looks like for its `when` (spec 0031 section 6), while the Cloud layer is on */
|
|
246
|
+
function renderCloudLegend() {
|
|
247
|
+
const el = own('cloud-legend');
|
|
248
|
+
if (!el) return;
|
|
249
|
+
if (!layerOn(state, 'cloud')) { el.innerHTML = ''; el.hidden = true; return; }
|
|
250
|
+
el.hidden = false;
|
|
251
|
+
el.innerHTML = `
|
|
252
|
+
<div class="hx-menu-title" data-corn="menu-title"><span>Cloud: when an outage bites</span></div>
|
|
253
|
+
${Object.entries(WHEN_STYLES).map(([when, s]) => `<div class="hx-legend-row"><span class="hx-legend-swatch hx-legend-swatch--wide hx-swatch-when--${when}">${keySwatch({ end: 'triangle', ticks: s.ticks })}</span><span>${s.legend}</span></div>`).join('')}
|
|
254
|
+
<div class="hx-legend-row"><span class="hx-legend-swatch"></span><span class="hx-faint"><span class="hx-cloud-browser">(browser)</span> the visitor's browser makes the call, not our server</span></div>`;
|
|
255
|
+
addParts(el);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Opens or closes the kinds of one row ("5 kinds"); the focus stays on its button */
|
|
259
|
+
function toggleKinds(key) {
|
|
260
|
+
if (openKinds.has(key)) openKinds.delete(key); else openKinds.add(key);
|
|
261
|
+
renderLayerToggles();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The chip dims and the note shows while the data-flow view is on (it has its own tiers and ignores the toggles) */
|
|
265
|
+
function syncView() {
|
|
266
|
+
const preset = state.view === 'dataflow';
|
|
267
|
+
btn.classList.toggle('hx-layers-chip--dim', preset);
|
|
268
|
+
own('layers-preset-note').hidden = !preset;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// -- the piece's own buttons, and the clicks and keys around the menu ------------------------------------------------------------
|
|
272
|
+
const ACTIONS = {
|
|
273
|
+
'toggle-layers-menu': () => toggleMenu(),
|
|
274
|
+
'layers-all': () => toggleAllLayers(inst, true, { viewer: true }),
|
|
275
|
+
'layers-none': () => toggleAllLayers(inst, false, { viewer: true }),
|
|
276
|
+
'toggle-layer': (el) => toggleLayer(inst, el.dataset.layer, { viewer: true }),
|
|
277
|
+
'toggle-layer-kinds': (el) => toggleKinds(el.dataset.layer),
|
|
278
|
+
};
|
|
279
|
+
scope.listen(wrap, 'click', (e) => {
|
|
280
|
+
const target = e.target.closest && e.target.closest('[data-action]');
|
|
281
|
+
if (!target) return;
|
|
282
|
+
const action = ACTIONS[target.dataset.action];
|
|
283
|
+
if (action) action(target);
|
|
284
|
+
});
|
|
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
|
+
if (e.key !== 'Escape' || menu.hidden) return;
|
|
296
|
+
closeMenu();
|
|
297
|
+
btn.focus();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// -- following the instance ------------------------------------------------------------------------------------------------------
|
|
301
|
+
scope.on('layers:redraw', renderLayerToggles);
|
|
302
|
+
scope.on('theme', renderLayerToggles); // the dots and the legends are drawn in the theme's colours
|
|
303
|
+
scope.on('view', syncView);
|
|
304
|
+
// ... and when the map's own tokens change (a named theme, its stylesheet arriving, light and dark): the same signal the map is drawn again on
|
|
305
|
+
scope.own(mapStyleOf(inst).onChange(() => { if (!redrawing(inst)) renderLayerToggles(); }));
|
|
306
|
+
scope.own(() => made.forEach((el) => el.remove()));
|
|
307
|
+
|
|
308
|
+
syncView();
|
|
309
|
+
renderLayerToggles();
|
|
310
|
+
|
|
311
|
+
return {
|
|
312
|
+
elements: made,
|
|
313
|
+
renderToggles: renderLayerToggles,
|
|
314
|
+
renderEdgeKey,
|
|
315
|
+
renderCloudLegend,
|
|
316
|
+
toggleMenu,
|
|
317
|
+
closeMenu,
|
|
318
|
+
toggleKinds,
|
|
319
|
+
update(props) {
|
|
320
|
+
if (props && 'layers' in props) setProjectLayers(inst, props.layers);
|
|
321
|
+
else renderLayerToggles();
|
|
322
|
+
},
|
|
323
|
+
destroy: () => scope.destroy(),
|
|
324
|
+
};
|
|
325
|
+
}
|