cornfield 0.40.0 → 0.42.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/contrast.js +1 -0
- package/core/map-tokens.js +3 -2
- package/core/strings.js +9 -0
- package/explorer/camera.js +1 -1
- package/explorer/cluster.js +26 -0
- package/explorer/decision-model.js +231 -0
- package/explorer/explorer.css +81 -6
- package/explorer/fly.js +48 -0
- package/explorer/forge-panel.js +28 -5
- package/explorer/index.html +18 -2
- 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/proposal-model.js +24 -0
- package/explorer/proposal.js +13 -6
- package/explorer/render.js +19 -1
- package/explorer/review-column.js +22 -4
- package/explorer/review.js +413 -44
- package/explorer/runs-model.js +1 -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 +8 -0
- package/explorer/tokens.css +2 -0
- package/explorer/whatif.js +84 -7
- package/package.json +1 -1
- package/server/decision.js +117 -0
- package/server/proposal-pulls.js +1 -1
- package/server/proposals.js +58 -9
- package/server/server.js +19 -2
- package/server/submit-review.js +52 -7
package/explorer/runs-model.js
CHANGED
|
@@ -214,7 +214,7 @@ export function totalsLines(totals) {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
/** "20 s", "5 min", "2 h": how long ago, short enough for a line */
|
|
217
|
-
function agoShort(ms) {
|
|
217
|
+
export function agoShort(ms) {
|
|
218
218
|
const s = Math.max(0, Math.round(ms / 1000));
|
|
219
219
|
if (s < 60) return `${s} s`;
|
|
220
220
|
if (s < 3600) return `${Math.floor(s / 60)} min`;
|
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
|
}
|