cornfield 0.40.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/map-tokens.js +3 -2
- package/explorer/camera.js +1 -1
- package/explorer/cluster.js +26 -0
- package/explorer/explorer.css +53 -5
- package/explorer/fly.js +48 -0
- package/explorer/index.html +14 -1
- package/explorer/input.js +16 -5
- package/explorer/keyboard.js +12 -22
- package/explorer/labels.js +239 -80
- package/explorer/layout.js +43 -15
- package/explorer/main.js +6 -25
- package/explorer/map-style.js +21 -8
- package/explorer/render.js +19 -1
- package/explorer/scene.js +28 -36
- package/explorer/search-model.js +156 -0
- package/explorer/search-status.js +24 -13
- package/explorer/search.js +335 -0
- package/explorer/state.js +4 -0
- package/explorer/tokens.css +2 -0
- package/package.json +1 -1
package/explorer/map-style.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* --corn-map-collision the collision mark of two runs on one node (a DOM mark: explorer.css reads it)
|
|
16
16
|
* --corn-map-font the font list of every label on the map (a list of families, `auto` for the map's own)
|
|
17
17
|
* --corn-map-edge-width the width of an ordinary line, in map px (`auto` keeps each line's own; the focus's and the marks' keep their proportion)
|
|
18
|
+
* --corn-map-label-min the smallest a label is drawn on screen, in px (11 by default; below 9px it is ignored; a hub's title is 2 more)
|
|
18
19
|
* --corn-map-glow the soft glow round nodes, lines and packets: a factor (`0` none, `1` as drawn, `auto` as drawn)
|
|
19
20
|
*
|
|
20
21
|
* `auto` (the default of every one of them but the width and the collision) means "keep what the map draws without a theme": the
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
|
|
35
36
|
import { NODE_THEMES } from '../core/schema.js';
|
|
36
37
|
import { parseColor } from './theme-model.js';
|
|
37
|
-
import { looksFor } from './scene.js';
|
|
38
|
+
import { LABEL_MIN_FLOOR, looksFor } from './scene.js';
|
|
38
39
|
import { iconKeyShape, iconKeysFor, mapGroupToken, mapKindToken } from '../core/layers.js';
|
|
39
40
|
|
|
40
41
|
/** The node kinds (topology types) and the groups (layers a node can belong to) the tokens exist for */
|
|
@@ -53,6 +54,9 @@ export const COLLISION_TOKEN = '--corn-map-collision';
|
|
|
53
54
|
export const FONT_TOKEN = '--corn-map-font';
|
|
54
55
|
export const EDGE_WIDTH_TOKEN = '--corn-map-edge-width';
|
|
55
56
|
export const GLOW_TOKEN = '--corn-map-glow';
|
|
57
|
+
export const LABEL_MIN_TOKEN = '--corn-map-label-min';
|
|
58
|
+
/** The largest label minimum a theme may ask for: bigger text would leave no room for another label */
|
|
59
|
+
export const MAX_LABEL_MIN = 24;
|
|
56
60
|
/** The width an ordinary line has with no theme (scene.js `flowEdge`): the `--corn-map-edge-width` scales every line by its ratio to this */
|
|
57
61
|
export const BASE_EDGE_WIDTH = 1.6;
|
|
58
62
|
/** The most a font list may hold: the families, and the characters */
|
|
@@ -87,7 +91,7 @@ export const MAP_COLOR_TOKENS = Object.freeze([
|
|
|
87
91
|
...MAP_STATES.map(stateToken),
|
|
88
92
|
]);
|
|
89
93
|
/** Every map token */
|
|
90
|
-
export const mapTokenNames = () => [...MAP_COLOR_TOKENS, STROKE_WIDTH_TOKEN, COLLISION_TOKEN, FONT_TOKEN, EDGE_WIDTH_TOKEN, GLOW_TOKEN];
|
|
94
|
+
export const mapTokenNames = () => [...MAP_COLOR_TOKENS, STROKE_WIDTH_TOKEN, COLLISION_TOKEN, FONT_TOKEN, EDGE_WIDTH_TOKEN, GLOW_TOKEN, LABEL_MIN_TOKEN];
|
|
91
95
|
|
|
92
96
|
// ---------------------------------------------------------------------------
|
|
93
97
|
// Reading a token
|
|
@@ -206,6 +210,12 @@ function pxOf(value, max) {
|
|
|
206
210
|
return Number.isFinite(n) && n > 0 && n <= max ? n : null;
|
|
207
211
|
}
|
|
208
212
|
|
|
213
|
+
/** The label minimum: a length in px from LABEL_MIN_FLOOR to MAX_LABEL_MIN, or null for `auto` and anything else (under the floor is ignored, so a theme cannot make labels unreadable) */
|
|
214
|
+
function labelMinOf(value) {
|
|
215
|
+
const n = pxOf(value, MAX_LABEL_MIN);
|
|
216
|
+
return n !== null && n >= LABEL_MIN_FLOOR ? n : null;
|
|
217
|
+
}
|
|
218
|
+
|
|
209
219
|
/** The glow factor: a number (`0` for none, `1` as drawn, up to MAX_GLOW; `0px` reads as 0), or null for `auto` and anything else */
|
|
210
220
|
function factorOf(value) {
|
|
211
221
|
const m = /^\s*(\d*\.?\d+)(px)?\s*$/i.exec(String(value ?? ''));
|
|
@@ -219,8 +229,8 @@ function factorOf(value) {
|
|
|
219
229
|
* The tokens as the page computes them.
|
|
220
230
|
* @param {(name: string) => string} read the value of a custom property
|
|
221
231
|
* @param {string[]} [extra] more colour tokens to read: those of the finer kinds and project layers on the map (`setMapSubjects`)
|
|
222
|
-
* @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null}}
|
|
223
|
-
* `values` holds only the tokens that are a colour (not `auto`); `font`, `edgeWidth` and `
|
|
232
|
+
* @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null, labelMin: number | null}}
|
|
233
|
+
* `values` holds only the tokens that are a colour (not `auto`); `font`, `edgeWidth`, `glow` and `labelMin` are null at `auto` or when the value is not one
|
|
224
234
|
*/
|
|
225
235
|
export function readMapTokens(read, extra = []) {
|
|
226
236
|
const values = {};
|
|
@@ -235,6 +245,7 @@ export function readMapTokens(read, extra = []) {
|
|
|
235
245
|
font: cssFontList(read(FONT_TOKEN)),
|
|
236
246
|
edgeWidth: pxOf(read(EDGE_WIDTH_TOKEN), MAX_EDGE_WIDTH),
|
|
237
247
|
glow: factorOf(read(GLOW_TOKEN)),
|
|
248
|
+
labelMin: labelMinOf(read(LABEL_MIN_TOKEN)),
|
|
238
249
|
};
|
|
239
250
|
}
|
|
240
251
|
|
|
@@ -303,12 +314,13 @@ export function createIconStore(urls, { load = loadImage, onChange = () => {}, w
|
|
|
303
314
|
* @property {string | null} font the label font list (`--corn-map-font`), null at `auto`
|
|
304
315
|
* @property {number | null} edgeWidth an ordinary line's width in px (`--corn-map-edge-width`), null at `auto`
|
|
305
316
|
* @property {number | null} glow the glow factor (`--corn-map-glow`), null at `auto`
|
|
317
|
+
* @property {number | null} labelMin the smallest label size in px (`--corn-map-label-min`), null at `auto` or under 9px
|
|
306
318
|
* @property {ReturnType<typeof createIconStore> | null} icons
|
|
307
319
|
* @property {boolean} pixelated sample icons without smoothing
|
|
308
320
|
* @property {boolean} plain nothing to apply: no colour set, no icon loaded (the scene is drawn as it is)
|
|
309
321
|
*/
|
|
310
322
|
|
|
311
|
-
const NO_TOKENS = { values: {}, strokeWidth: DEFAULT_STROKE_WIDTH, font: null, edgeWidth: null, glow: null };
|
|
323
|
+
const NO_TOKENS = { values: {}, strokeWidth: DEFAULT_STROKE_WIDTH, font: null, edgeWidth: null, glow: null, labelMin: null };
|
|
312
324
|
let tokens = NO_TOKENS;
|
|
313
325
|
let icons = null;
|
|
314
326
|
let pixelated = false;
|
|
@@ -317,8 +329,8 @@ let current = compose();
|
|
|
317
329
|
const listeners = new Set();
|
|
318
330
|
|
|
319
331
|
function compose() {
|
|
320
|
-
const plain = !Object.keys(tokens.values).length && !(icons && icons.anyReady()) && tokens.font === null && tokens.edgeWidth === null && tokens.glow === null;
|
|
321
|
-
return Object.freeze({ version, values: tokens.values, strokeWidth: tokens.strokeWidth, font: tokens.font, edgeWidth: tokens.edgeWidth, glow: tokens.glow, icons, pixelated, plain });
|
|
332
|
+
const plain = !Object.keys(tokens.values).length && !(icons && icons.anyReady()) && tokens.font === null && tokens.edgeWidth === null && tokens.glow === null && tokens.labelMin === null;
|
|
333
|
+
return Object.freeze({ version, values: tokens.values, strokeWidth: tokens.strokeWidth, font: tokens.font, edgeWidth: tokens.edgeWidth, glow: tokens.glow, labelMin: tokens.labelMin, icons, pixelated, plain });
|
|
322
334
|
}
|
|
323
335
|
|
|
324
336
|
function changed() {
|
|
@@ -359,7 +371,7 @@ export function onMapStyleChange(fn) {
|
|
|
359
371
|
export function refreshMapStyle(read = pageReader()) {
|
|
360
372
|
if (!read) return false;
|
|
361
373
|
const next = readMapTokens(read, subjectTokens);
|
|
362
|
-
const same = next.strokeWidth === tokens.strokeWidth && next.font === tokens.font && next.edgeWidth === tokens.edgeWidth && next.glow === tokens.glow
|
|
374
|
+
const same = next.strokeWidth === tokens.strokeWidth && next.font === tokens.font && next.edgeWidth === tokens.edgeWidth && next.glow === tokens.glow && next.labelMin === tokens.labelMin
|
|
363
375
|
&& Object.keys(next.values).length === Object.keys(tokens.values).length
|
|
364
376
|
&& Object.entries(next.values).every(([k, v]) => tokens.values[k] === v);
|
|
365
377
|
if (same) return false;
|
|
@@ -488,6 +500,7 @@ function compute(scene, style) {
|
|
|
488
500
|
});
|
|
489
501
|
const out = { ...scene, nodes, edges: scene.edges.map((e) => styleEdge(e, style, painted.edges)) };
|
|
490
502
|
if (style.font) out.labelFont = style.font; // every label's font list (labels.js reads `scene.labelFont`)
|
|
503
|
+
if (style.labelMin != null) out.labelMin = style.labelMin; // the smallest label on screen (labels.js reads `scene.labelMin`)
|
|
491
504
|
const halo = values[LABEL_HALO_TOKEN];
|
|
492
505
|
if (halo) { // the outline under the labels, at the widths it has (labels.js reads `scene.labelOutline` before the ground's own)
|
|
493
506
|
const { node, edge } = looksFor(scene.theme).labelOutline;
|
package/explorer/render.js
CHANGED
|
@@ -172,10 +172,28 @@ function paint() {
|
|
|
172
172
|
getRenderer().draw(scene, state.camera, performance.now());
|
|
173
173
|
// The labels repaint only when the camera, the scene or the size changed, never on a packet frame
|
|
174
174
|
const labels = getLabelLayer();
|
|
175
|
-
if (labels) labels.draw(scene, state.camera);
|
|
175
|
+
if (labels) labels.draw(scene, state.camera, { hover: state.hoverNodeId });
|
|
176
176
|
paintHooks.forEach((fn) => fn(scene, state.camera));
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
/** The node whose label is drawn under a screen point, or null (labels.js `hit`): a cluster's title frames the cluster */
|
|
180
|
+
export function labelNodeAt(x, y) {
|
|
181
|
+
const labels = getLabelLayer();
|
|
182
|
+
return labels ? labels.hit(x, y) : null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The node the pointer is on (or null): a node with no label is named by a chip over the map while it is. Only the label layer
|
|
187
|
+
* draws again (the map has nothing new to show), so moving across the map costs one small redraw per node entered.
|
|
188
|
+
*/
|
|
189
|
+
export function setHoverNode(id) {
|
|
190
|
+
const next = id || null;
|
|
191
|
+
if (state.hoverNodeId === next) return;
|
|
192
|
+
state.hoverNodeId = next;
|
|
193
|
+
const labels = getLabelLayer();
|
|
194
|
+
if (labels && state.canvas && state.width) labels.draw(getScene(), state.camera, { hover: next });
|
|
195
|
+
}
|
|
196
|
+
|
|
179
197
|
/** Things drawn over the map by the page itself (the runs' marks, explorer/runs-map.js): called after each draw with the scene and the camera */
|
|
180
198
|
const paintHooks = new Set();
|
|
181
199
|
export function onPaint(fn) {
|
package/explorer/scene.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* What changes the scene (and so what must call `touchScene()` in state.js): the topology, the
|
|
18
18
|
* layout, the layers, the selection, the search, the view, a playing scenario (the ROM simulation is one), a dragged node, a selected pull request.
|
|
19
19
|
* What does NOT: the camera (pan, zoom, fit) and time (packets). So the scene is built once per
|
|
20
|
-
* `state.sceneVersion` and drawn many times. The one camera-dependent decision,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* `state.sceneVersion` and drawn many times. The one camera-dependent decision, which labels fit
|
|
21
|
+
* and how big they are, is therefore not in the scene's nodes but in labels.js (`placeLabels(scene,
|
|
22
|
+
* zoom)`, which the label layer calls and caches by zoom).
|
|
23
23
|
*
|
|
24
24
|
* buildScene needs no text metrics (a label's size comes from rules, not from measuring it), so it
|
|
25
25
|
* takes no `measure` function; the one place that measures text is layout.js `labelWidth`, which
|
|
@@ -55,14 +55,16 @@
|
|
|
55
55
|
* @property {Halo} halo
|
|
56
56
|
* @property {Mark} mark
|
|
57
57
|
* @property {boolean} selected this is the selected node
|
|
58
|
-
* @property {boolean} match the search
|
|
58
|
+
* @property {boolean} match the search finds it (its label, id, file, type or kind: search-model.js)
|
|
59
|
+
* @property {boolean} current it is the search match the stepping is on (`state.searchCurrent`): its label is placed first of the matches
|
|
60
|
+
* @property {number} degree how many edges it has (the label placer's tie-break: more edges first)
|
|
59
61
|
* @property {boolean} connected inside the focus subgraph (always true when nothing is focused)
|
|
60
|
-
* @property {string} label the text, always set; whether it is drawn is
|
|
61
|
-
* @property {number} labelSize px
|
|
62
|
+
* @property {string} label the text, always set; whether it is drawn is labels.js's decision (`placeLabels`)
|
|
63
|
+
* @property {number} labelSize px in world units: 12 for `root`/`app`, else 11. On screen a label is never under LABEL_MIN_PX (a hub's, 2 more)
|
|
62
64
|
* @property {boolean} labelBold
|
|
63
65
|
* @property {number} labelAlpha = alpha
|
|
64
66
|
* @property {string} labelColor `#f8fafc`, or a dim white for a node outside the focus
|
|
65
|
-
* @property {boolean} labelKeep
|
|
67
|
+
* @property {boolean} labelKeep its label is asked for: a landmark type, the selection, a match, a marked node, or in the focus (and what a painter lights: an outage, a pull request)
|
|
66
68
|
* @property {boolean} labelStrike the label is struck through (a node a proposal removes, in the Diff view)
|
|
67
69
|
* @property {boolean} live the node came from the live layer (spec 0029: a floor, a room, a live device), not from topology.json
|
|
68
70
|
* @property {{x:number, y:number, w:number, h:number}|null} box a live room's box in the 800 x 600 floor viewBox (for the House view), else null
|
|
@@ -139,7 +141,7 @@
|
|
|
139
141
|
* @property {{nodes: Set<string>, edges: Set<string>}} painted the ids of the nodes and the keys of the edges a painter (an outage, a check's verdict, a pull request) gave a colour of its own: map-style.js leaves those alone
|
|
140
142
|
* @property {SceneDecor} decor
|
|
141
143
|
* @property {{node: {color: string, width: number}, edge: {color: string, width: number}}} [labelOutline] the outline under the labels when the theme sets one (map-style.js, `--corn-map-label-halo`); else `looksFor(theme).labelOutline`
|
|
142
|
-
* @property {boolean} preset the data-flow view
|
|
144
|
+
* @property {boolean} preset the data-flow view
|
|
143
145
|
* @property {'dark'|'light'} theme the ground it is drawn for (`state.theme`, theme.js): every colour in it already suits it; `looksFor(theme)` has the rest
|
|
144
146
|
* @property {number} version the `state.sceneVersion` it was built from
|
|
145
147
|
*
|
|
@@ -167,6 +169,7 @@ import { lettersOf, projectLayerKey, shownByProposal } from './layer-model.js';
|
|
|
167
169
|
import { outageFor, paintOutage } from './outage-model.js';
|
|
168
170
|
import { paintForge } from './forge-panel-model.js';
|
|
169
171
|
import { lightColor, lightenScene, parseColor } from './theme-model.js';
|
|
172
|
+
import { matchIds } from './search-model.js';
|
|
170
173
|
import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVED_ALPHA } from './diff-marks.js';
|
|
171
174
|
|
|
172
175
|
// ---------------------------------------------------------------------------
|
|
@@ -175,8 +178,13 @@ import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVE
|
|
|
175
178
|
export const LANDMARK_TYPES = ['root', 'app', 'pkg', 'tool', 'store', 'rom', 'floor']; // a floor (spec 0029) names its cluster of rooms like an app names its pages
|
|
176
179
|
export const FONT_NODE = '"Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif';
|
|
177
180
|
export const FONT_EDGE = '"Segoe UI", -apple-system, sans-serif';
|
|
178
|
-
/**
|
|
179
|
-
|
|
181
|
+
/**
|
|
182
|
+
* The smallest a label is ever drawn on screen (px), whatever the zoom (spec 0008 D2): a node's own, and a hub's (its cluster's title).
|
|
183
|
+
* A theme may raise the first with `--corn-map-label-min` (not below LABEL_MIN_FLOOR); a hub's is that plus 2.
|
|
184
|
+
*/
|
|
185
|
+
export const LABEL_MIN_PX = 11;
|
|
186
|
+
export const LABEL_MIN_FLOOR = 9;
|
|
187
|
+
export const HUB_LABEL_EXTRA_PX = 2;
|
|
180
188
|
/** The white dot in the middle of a node, as a fraction of its radius */
|
|
181
189
|
export const CORE_RATIO = 0.32;
|
|
182
190
|
export const CORE_COLOR = '#ffffff';
|
|
@@ -369,27 +377,6 @@ export function packetPoint(edge, timeMs) {
|
|
|
369
377
|
/** `#rgb`, `#rrggbb`, `rgb(...)` or `rgba(...)` → `[r, g, b, a]` (0..255, alpha 0..1); transparent for anything else (theme-model.js) */
|
|
370
378
|
export { parseColor };
|
|
371
379
|
|
|
372
|
-
// ---------------------------------------------------------------------------
|
|
373
|
-
// Labels: the one decision that depends on the camera
|
|
374
|
-
// ---------------------------------------------------------------------------
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* The label a node shows at `zoom`, or null. Zoomed out (below LABEL_ZOOM, outside the data-flow
|
|
378
|
-
* view) only landmarks and the focus keep a label, drawn larger so it stays readable on screen;
|
|
379
|
-
* the data-flow view is small enough to label everything, a little larger when zoomed out.
|
|
380
|
-
* @param {SceneNode} node
|
|
381
|
-
* @param {number} zoom
|
|
382
|
-
* @param {{preset:boolean}} scene
|
|
383
|
-
* @returns {{text:string, x:number, y:number, size:number, bold:boolean, color:string, alpha:number, strike:boolean}|null}
|
|
384
|
-
*/
|
|
385
|
-
export function labelAt(node, zoom, scene) {
|
|
386
|
-
const zoomedOut = !scene.preset && zoom < LABEL_ZOOM;
|
|
387
|
-
if (zoomedOut && !node.labelKeep) return null;
|
|
388
|
-
const boost = zoomedOut ? Math.min(2.2, 0.75 / zoom) : scene.preset ? Math.min(1.8, 0.8 / zoom) : 1;
|
|
389
|
-
const size = Math.round(node.labelSize * Math.max(1, boost));
|
|
390
|
-
return { text: node.label, x: node.x, y: node.y + node.r + size + 3, size, bold: node.labelBold, color: node.labelColor, alpha: node.labelAlpha, strike: node.labelStrike };
|
|
391
|
-
}
|
|
392
|
-
|
|
393
380
|
// ---------------------------------------------------------------------------
|
|
394
381
|
// Edges
|
|
395
382
|
// ---------------------------------------------------------------------------
|
|
@@ -550,11 +537,12 @@ function buildEdges(state, subgraph, reduceMotion) {
|
|
|
550
537
|
// Nodes
|
|
551
538
|
// ---------------------------------------------------------------------------
|
|
552
539
|
/** A node's group: its layer in the Layers menu (layers.js), one per kind but for the rooms and floors (House) and the outside nodes (Cloud, or the Public web) */
|
|
553
|
-
const groupOf = (node) => (node.type === 'floor' || node.type === 'room' ? 'house' : node.type === 'external' ? externalLayer(node) : node.type);
|
|
540
|
+
export const groupOf = (node) => (node.type === 'floor' || node.type === 'room' ? 'house' : node.type === 'external' ? externalLayer(node) : node.type);
|
|
554
541
|
|
|
555
542
|
function buildNodes(state, subgraph) {
|
|
556
543
|
const { nodes, selectedNode, searchQuery } = state;
|
|
557
|
-
const
|
|
544
|
+
const found = searchQuery ? matchIds(nodes, searchQuery) : null; // what the search finds: label, id, file, type, kind (search-model.js)
|
|
545
|
+
const searching = !!found && nodes.some((n) => found.has(n.id) && isNodeVisible(state, n)); // with no match on the map nothing dims: it would only be a blank map
|
|
558
546
|
const out = [];
|
|
559
547
|
const view = proposalView(state);
|
|
560
548
|
const focus = view === 'diff' ? touchedIds(nodes, viewEdgesOf(state)) : null;
|
|
@@ -563,7 +551,8 @@ function buildNodes(state, subgraph) {
|
|
|
563
551
|
if (!isNodeVisible(state, node)) return;
|
|
564
552
|
|
|
565
553
|
const shown = view === 'before' ? beforeOf(node) : node; // Before reads a changed node as it was
|
|
566
|
-
const match = !!
|
|
554
|
+
const match = !!found && found.has(node.id);
|
|
555
|
+
const current = match && state.searchCurrent === node.id;
|
|
567
556
|
const selected = !!selectedNode && selectedNode.id === node.id;
|
|
568
557
|
const connected = subgraph ? subgraph.connectedNodeIds.has(node.id) : true;
|
|
569
558
|
const child = subgraph && subgraph.childIds ? subgraph.childIds.has(node.id) : false;
|
|
@@ -571,7 +560,9 @@ function buildNodes(state, subgraph) {
|
|
|
571
560
|
const look = MARK[mark];
|
|
572
561
|
const gone = mark === 'edit' && node.editOp === 'removed'; // a node a what-if edit removes: violet ring, faded, label struck through
|
|
573
562
|
// deep dimming for what is not connected; a proposal's Diff view fades what it does not touch, less deeply, and a removed node is faded too
|
|
574
|
-
|
|
563
|
+
// A search's matches are what the reader asked for: a selection's focus does not dim them, so each keeps its label (spec 0008 D4)
|
|
564
|
+
let alpha = subgraph && !connected && !(searching && match) ? DIM_ALPHA : 1;
|
|
565
|
+
if (searching && !match && !selected && !(subgraph && connected)) alpha = DIM_ALPHA; // a search dims what it did not find, as a focus does
|
|
575
566
|
if (focus && !focus.touched.has(node.id)) alpha = Math.min(alpha, PROPOSAL_DIM_ALPHA);
|
|
576
567
|
if (look) alpha *= gone ? MARK.removed.alpha : look.alpha;
|
|
577
568
|
const big = shown.type === 'root' || shown.type === 'app';
|
|
@@ -589,7 +580,8 @@ function buildNodes(state, subgraph) {
|
|
|
589
580
|
glow: connected && alpha >= 0.5 ? (big ? 15 : 9) : 0,
|
|
590
581
|
halo: match ? 'match' : selected ? 'selected' : child ? 'child' : 'none',
|
|
591
582
|
mark,
|
|
592
|
-
selected, match, connected,
|
|
583
|
+
selected, match, current, connected,
|
|
584
|
+
degree: node.degree || 0,
|
|
593
585
|
label: shown.label,
|
|
594
586
|
labelSize: big ? 12 : 11,
|
|
595
587
|
labelBold: big,
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/search-model
|
|
3
|
+
*
|
|
4
|
+
* What a search finds, in what order, and how it reads (spec 0008 D3 and D4). Pure: no DOM, no state. Nodes in, matches out.
|
|
5
|
+
*
|
|
6
|
+
* - It reads a node's label, its id, its file path, its type (as a word: "service", and as its layer's name: "Services")
|
|
7
|
+
* and its finer kind ("webhook"). Case does not matter. Not descriptions: on a big map a common word in one would match
|
|
8
|
+
* hundreds of nodes and bury the one that was named.
|
|
9
|
+
* - It ranks: a label that starts with the term (0), then a word of the label that does (1), then the label containing it
|
|
10
|
+
* (2), then the id or the file (3), then the type or the kind (4). Within a rank, by label, then id: the order does not
|
|
11
|
+
* depend on the camera or on how the nodes happen to be listed.
|
|
12
|
+
* - It groups by type, under the layer's name with a count, groups in the order of their best match, and puts the matches
|
|
13
|
+
* in layers that are off last, under their own heading.
|
|
14
|
+
*
|
|
15
|
+
* Substring matching only: no fuzzy matching, so a reviewer can always see why a node matched.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** The heading of the matches in layers that are off */
|
|
19
|
+
export const OFF_GROUP = 'In layers that are off';
|
|
20
|
+
|
|
21
|
+
/** Rows the list shows before "and N more" */
|
|
22
|
+
export const MAX_ROWS = 50;
|
|
23
|
+
|
|
24
|
+
/** The ranks, best first */
|
|
25
|
+
export const RANK = Object.freeze({ labelStart: 0, wordStart: 1, label: 2, idOrFile: 3, typeOrKind: 4 });
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The layer's name for each node type, as the Layers menu says it (layers.js `LAYER_DEFS`; a test keeps the two together).
|
|
29
|
+
* A type not here is its own name with a capital.
|
|
30
|
+
*/
|
|
31
|
+
export const TYPE_NAMES = Object.freeze({
|
|
32
|
+
root: 'Root', app: 'Apps', pkg: 'Packages', page: 'Pages & Routes', atom: 'Atoms', molecule: 'Molecules', token: 'Design Tokens',
|
|
33
|
+
tool: 'Dev Tools', core: 'Core', store: 'Stores', table: 'Tables', rom: 'ROM', service: 'Services', external: 'Cloud', stack: 'Infra',
|
|
34
|
+
machine: 'Machines', container: 'Containers', device: 'Devices', floor: 'House', room: 'House', persona: 'People',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const capital = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : s);
|
|
38
|
+
|
|
39
|
+
/** The name of the group a node is listed under: its layer's name */
|
|
40
|
+
export const groupName = (node) => TYPE_NAMES[node.type] || capital(String(node.type || ''));
|
|
41
|
+
|
|
42
|
+
const lower = (s) => (typeof s === 'string' ? s.toLowerCase() : '');
|
|
43
|
+
const WORD_BREAK = /[^\p{L}\p{N}]+/u;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* How well `query` (trimmed) matches a node, as a RANK, or -1 for no match
|
|
47
|
+
* @param {{label?: string, id?: string, file?: string, type?: string, kind?: string}} node
|
|
48
|
+
* @param {string} query
|
|
49
|
+
*/
|
|
50
|
+
export function rankOf(node, query) {
|
|
51
|
+
const term = String(query || '').toLowerCase();
|
|
52
|
+
if (!term) return -1;
|
|
53
|
+
const label = lower(node.label);
|
|
54
|
+
if (label.startsWith(term)) return RANK.labelStart;
|
|
55
|
+
if (label.split(WORD_BREAK).some((w) => w && w.startsWith(term))) return RANK.wordStart;
|
|
56
|
+
if (label.includes(term)) return RANK.label;
|
|
57
|
+
if (lower(node.id).includes(term) || lower(node.file).includes(term)) return RANK.idOrFile;
|
|
58
|
+
if (lower(node.type).includes(term) || lower(groupName(node)).includes(term) || lower(node.kind).includes(term)) return RANK.typeOrKind;
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Every node the query finds, in the order the list shows them.
|
|
64
|
+
* @param {object[]} nodes the topology nodes
|
|
65
|
+
* @param {string} query as typed (it is trimmed, and case does not matter)
|
|
66
|
+
* @param {{visible?: (node: object) => boolean, parentLabel?: (node: object) => string}} [opts]
|
|
67
|
+
* `visible`: whether the node is drawn (its layer is on); the others come last. `parentLabel`: who the row names after its label.
|
|
68
|
+
* @returns {{
|
|
69
|
+
* query: string,
|
|
70
|
+
* matches: {node: object, rank: number, on: boolean, group: string, parent: string}[],
|
|
71
|
+
* groups: {name: string, off: boolean, count: number, rows: object[]}[],
|
|
72
|
+
* total: number, onMap: number, off: number,
|
|
73
|
+
* rows: number, more: number
|
|
74
|
+
* }}
|
|
75
|
+
* `matches` is every match in list order (the order Enter and N walk), `groups` the same in groups with at most MAX_ROWS rows
|
|
76
|
+
* in all, `more` how many are past that.
|
|
77
|
+
*/
|
|
78
|
+
export function searchNodes(nodes, query, opts = {}) {
|
|
79
|
+
const term = String(query || '').trim().toLowerCase();
|
|
80
|
+
const visible = opts.visible || (() => true);
|
|
81
|
+
const parentLabel = opts.parentLabel || (() => '');
|
|
82
|
+
const out = { query: String(query || '').trim(), matches: [], groups: [], total: 0, onMap: 0, off: 0, rows: 0, more: 0 };
|
|
83
|
+
if (!term) return out;
|
|
84
|
+
|
|
85
|
+
const found = [];
|
|
86
|
+
for (const node of nodes) {
|
|
87
|
+
const rank = rankOf(node, term);
|
|
88
|
+
if (rank < 0) continue;
|
|
89
|
+
found.push({ node, rank, on: !!visible(node), group: groupName(node), parent: parentLabel(node) });
|
|
90
|
+
}
|
|
91
|
+
const byRank = (a, b) => a.rank - b.rank || String(a.node.label).localeCompare(String(b.node.label)) || String(a.node.id).localeCompare(String(b.node.id));
|
|
92
|
+
found.sort(byRank);
|
|
93
|
+
|
|
94
|
+
// The groups: by type, in the order of each one's best match (then its name); what is on the map before what is off it
|
|
95
|
+
const lists = new Map();
|
|
96
|
+
for (const m of found) {
|
|
97
|
+
const key = m.on ? `on|${m.group}` : 'off'; // what a layer that is off hides is one group, whatever its types
|
|
98
|
+
if (!lists.has(key)) lists.set(key, { name: m.on ? m.group : OFF_GROUP, off: !m.on, rows: [] });
|
|
99
|
+
lists.get(key).rows.push(m);
|
|
100
|
+
}
|
|
101
|
+
const groups = [...lists.values()].sort((a, b) => Number(a.off) - Number(b.off) || a.rows[0].rank - b.rows[0].rank || a.name.localeCompare(b.name));
|
|
102
|
+
out.matches = groups.flatMap((g) => g.rows);
|
|
103
|
+
out.total = out.matches.length;
|
|
104
|
+
out.onMap = found.filter((m) => m.on).length;
|
|
105
|
+
out.off = out.total - out.onMap;
|
|
106
|
+
|
|
107
|
+
// The list: the first MAX_ROWS rows in that order, in their groups; the groups keep their full counts
|
|
108
|
+
let room = MAX_ROWS;
|
|
109
|
+
for (const g of groups) {
|
|
110
|
+
if (room <= 0) break;
|
|
111
|
+
out.groups.push({ name: g.name, off: g.off, count: g.rows.length, rows: g.rows.slice(0, room) });
|
|
112
|
+
room -= g.rows.length;
|
|
113
|
+
}
|
|
114
|
+
out.rows = Math.min(MAX_ROWS, out.total);
|
|
115
|
+
out.more = Math.max(0, out.total - MAX_ROWS);
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The ids a query matches (what the map halos): a Set, empty for no query */
|
|
120
|
+
export function matchIds(nodes, query) {
|
|
121
|
+
const term = String(query || '').trim().toLowerCase();
|
|
122
|
+
const ids = new Set();
|
|
123
|
+
if (!term) return ids;
|
|
124
|
+
for (const node of nodes) if (rankOf(node, term) >= 0) ids.add(node.id);
|
|
125
|
+
return ids;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The match `by` steps (+1 or -1) from the one with id `currentId`, wrapping round; the first (or, going back, the last) when
|
|
130
|
+
* there is no current one or it is not among them.
|
|
131
|
+
* @param {{node: {id: string}}[]} matches in list order
|
|
132
|
+
* @param {string|null|undefined} currentId
|
|
133
|
+
* @param {number} by
|
|
134
|
+
* @returns {number} an index into `matches`, -1 for none
|
|
135
|
+
*/
|
|
136
|
+
export function stepIndex(matches, currentId, by) {
|
|
137
|
+
if (!matches.length) return -1;
|
|
138
|
+
const at = matches.findIndex((m) => m.node.id === currentId);
|
|
139
|
+
if (at < 0) return by < 0 ? matches.length - 1 : 0;
|
|
140
|
+
return (at + (by < 0 ? -1 : 1) + matches.length) % matches.length;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** What the field's count says: "No match", "33 matches", or "3 of 33" once one is chosen; '' for no query */
|
|
144
|
+
export function countText(result, currentId) {
|
|
145
|
+
if (!result.query) return '';
|
|
146
|
+
if (!result.total) return 'No match';
|
|
147
|
+
const at = result.matches.findIndex((m) => m.node.id === currentId);
|
|
148
|
+
if (at >= 0) return `${at + 1} of ${result.total}`;
|
|
149
|
+
return result.total === 1 ? '1 match' : `${result.total} matches`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The list's words for a query that found nothing (the query goes in as text, never as HTML) */
|
|
153
|
+
export const noMatchLine = (query) => `No node matches “${query}”. Search reads names, files, types and kinds.`;
|
|
154
|
+
|
|
155
|
+
/** "and 12 more: type more to narrow" */
|
|
156
|
+
export const moreLine = (n) => `and ${n} more: type more to narrow`;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/search-status
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
* The words are the `searchNoMatch` string; the query
|
|
4
|
+
* The polite live region by each search field (F24): what a screen reader hears of a search. Once the typing pauses it says the count ("7 matches")
|
|
5
|
+
* or "No match for “xyz”" (search.js, spec 0008); a match chosen or "Framed 7 matches" is said by the map's announcer (keyboard.js), once. The region is out of
|
|
6
|
+
* sight: the count in the field and the list under it say it on the screen. The no-match words are the `searchNoMatch` string; the query
|
|
7
|
+
* goes in as text, never as HTML.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import { t } from './strings.js';
|
|
@@ -14,28 +15,38 @@ const IDS = ['search-status', 'mobile-search-status'];
|
|
|
14
15
|
/** "No match for “query”" */
|
|
15
16
|
export const noMatchText = (query) => `${t('searchNoMatch')} “${query}”`;
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
18
|
+
/** Writes `text` into the region(s) at once; '' clears them */
|
|
19
|
+
function write(text) {
|
|
19
20
|
for (const id of IDS) {
|
|
20
21
|
const el = document.getElementById(id);
|
|
21
22
|
if (el) el.textContent = text;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
/** How long the typing must pause before
|
|
26
|
+
/** 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 */
|
|
26
27
|
export const NO_MATCH_DELAY_MS = 400;
|
|
27
28
|
let pending = null;
|
|
28
29
|
|
|
30
|
+
/** Shows `text` by the search field(s) at once, ending any wait for what the typing found; '' clears it */
|
|
31
|
+
export function showSearchStatus(text) {
|
|
32
|
+
clearTimeout(pending);
|
|
33
|
+
pending = null;
|
|
34
|
+
write(text);
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
/**
|
|
30
|
-
* Sets the status for a search:
|
|
31
|
-
*
|
|
38
|
+
* Sets the status for a search as it is typed: cleared at once (an empty query clears it for good), then, once the typing pauses, the
|
|
39
|
+
* count (`count`, "7 matches") for a query that found something, or "No match for …" for one that found nothing; so a screen reader
|
|
40
|
+
* says it once per pause, not for every letter.
|
|
32
41
|
* @param {string} query the trimmed query
|
|
33
|
-
* @param {boolean} found whether a
|
|
42
|
+
* @param {boolean} found whether a node matched
|
|
43
|
+
* @param {string} [count] what to say when one did (nothing is said without it)
|
|
34
44
|
*/
|
|
35
|
-
export function updateSearchStatus(query, found) {
|
|
45
|
+
export function updateSearchStatus(query, found, count = '') {
|
|
36
46
|
clearTimeout(pending);
|
|
37
47
|
pending = null;
|
|
38
|
-
|
|
39
|
-
const text = noMatchText(query);
|
|
40
|
-
|
|
48
|
+
write('');
|
|
49
|
+
const text = !query ? '' : found ? count : noMatchText(query);
|
|
50
|
+
if (!text) return;
|
|
51
|
+
pending = setTimeout(() => { pending = null; write(text); }, NO_MATCH_DELAY_MS);
|
|
41
52
|
}
|