@popcorn245/cornfield 0.46.0 → 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
- package/server/agent-api.js +13 -6
- package/server/agent-runs.js +2 -1
- package/server/auth.js +1 -1
- package/server/forge-actions.js +34 -24
- package/server/forge-routes.js +3 -3
- package/server/lander.js +3 -2
- package/server/proposals.js +11 -3
- package/server/review-api.js +13 -8
- package/server/server.js +5 -4
- package/server/throttle.js +27 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/search
|
|
3
|
+
*
|
|
4
|
+
* Search as a piece (spec 0011 D3; spec 0008 D3 and D4); search-model.js decides what is found and in what order, this shows it:
|
|
5
|
+
*
|
|
6
|
+
* - the count in the field ("33 matches", "3 of 33", "No match") and, under the field, a list of what was found: up to 50 rows,
|
|
7
|
+
* grouped by type (the Layers name, with a count) in rank order, each row the label and its parent's; "Frame all 33" first;
|
|
8
|
+
* what a layer that is off hides last, under "In layers that are off", and choosing one turns its layer on;
|
|
9
|
+
* - stepping: Enter and Shift+Enter in the field, the arrow keys in the list, N and P on the map (engine/keyboard.js asks `search:active` and
|
|
10
|
+
* `search:step`) and the field's ^ and v buttons. Each step selects the match and flies the camera to it, at zoom 1 or closer;
|
|
11
|
+
* - on the map the matches keep their halo and win a label (scene.js, labels.js), the rest dims.
|
|
12
|
+
*
|
|
13
|
+
* The desktop field and the phone's bar are two inputs on one search: the query, the matches and the current match are shared, each
|
|
14
|
+
* field has its own count, buttons and list. A polite live region says what changed (engine/search-status.js). Everything the user typed or
|
|
15
|
+
* the map holds goes into the markup as text.
|
|
16
|
+
*
|
|
17
|
+
* mount(root, inst, options) -> { update, destroy, ... }
|
|
18
|
+
*
|
|
19
|
+
* The piece makes its own markup (`markup()`: the field with its phone button, and the phone's bar) and puts it in `root`, or before the nodes
|
|
20
|
+
* `options.slots` names (`field`, `bar`). It tells the instance `search` ({ query, current }) when either changes, answers `search:active` and
|
|
21
|
+
* `search:step`, and follows `layers` (a layer going on or off moves matches between the list and "In layers that are off"). `/` goes to the
|
|
22
|
+
* field while the focus is inside the root and not in a field. `destroy()` takes back every listener and timer and removes the elements.
|
|
23
|
+
*
|
|
24
|
+
* @param {ParentNode} root where the search goes when `options.slots` names no place
|
|
25
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst the instance; its map must be made (engine/render.js)
|
|
26
|
+
* @param {{ slots?: { field?: Node, bar?: Node } }} [options]
|
|
27
|
+
* @returns {{ update: (props?: { query?: string }) => void, destroy: () => void, elements: Element[], setQuery: Function, stepMatch: Function, frameAll: Function, chooseMatch: Function, currentResult: Function, searchActive: Function, paintSearch: Function, toggleMobileSearch: Function, reset: Function }}
|
|
28
|
+
* `update({ query })` sets the search; `update()` paints the count and the list again
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
32
|
+
import { toggleLayer } from '../engine/layers.js';
|
|
33
|
+
import { selectNode } from '../engine/selection.js';
|
|
34
|
+
import { isPhone, visibleMapRect } from '../engine/sheets.js';
|
|
35
|
+
import { announce } from '../engine/keyboard.js';
|
|
36
|
+
import { flyTo } from '../engine/fly.js';
|
|
37
|
+
import { groupOf } from '../scene.js';
|
|
38
|
+
import { layerOn, projectLayerKey } from '../layer-model.js';
|
|
39
|
+
import { showSearchStatus, updateSearchStatus } from '../engine/search-status.js';
|
|
40
|
+
import { countText, moreLine, noMatchLine, searchNodes, stepIndex } from '../search-model.js';
|
|
41
|
+
import { scopeOf, place } from '../engine/piece.js';
|
|
42
|
+
|
|
43
|
+
/** The two fields: the desktop's and the phone's bar. Each has its input, count, list and the live region it shares with the other */
|
|
44
|
+
const FIELDS = [
|
|
45
|
+
{ input: 'node-search', count: 'search-count', results: 'search-results', steps: 'search-steps' },
|
|
46
|
+
{ input: 'mobile-node-search', count: 'mobile-search-count', results: 'mobile-search-results', steps: 'mobile-search-steps' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/** The zoom a chosen match is shown at, at least */
|
|
50
|
+
export const MATCH_ZOOM = 1;
|
|
51
|
+
|
|
52
|
+
const FRAME_STOP = Symbol('frame all');
|
|
53
|
+
|
|
54
|
+
/** The markup of the piece: the field with the button that opens the phone's bar (`field`), and the phone's bar (`bar`) */
|
|
55
|
+
export const markup = () => ({
|
|
56
|
+
field: `<button type="button" id="mobile-search-toggle" class="hx-hdr-icon hx-only-mobile" data-corn="mobile-search-button" data-action="toggle-mobile-search" aria-label="Open Search" title="Search nodes" data-corn-kind="icon">
|
|
57
|
+
<svg viewBox="0 0 16 16" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><circle cx="7" cy="7" r="4.5" /><path d="M10.5 10.5L14 14" /></svg>
|
|
58
|
+
</button>
|
|
59
|
+
|
|
60
|
+
<div class="hx-search" role="search" data-corn="search">
|
|
61
|
+
<svg class="hx-search-icon" viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><circle cx="7" cy="7" r="4.5" /><path d="M10.5 10.5L14 14" /></svg>
|
|
62
|
+
<input type="text" id="node-search" class="hx-search-input" placeholder="Search..." data-corn-string-placeholder="searchPlaceholder" aria-label="Search nodes" aria-keyshortcuts="/" data-corn="search-input" />
|
|
63
|
+
<kbd class="hx-kbd" data-corn="search-key" aria-hidden="true">/</kbd>
|
|
64
|
+
<span id="search-steps" class="hx-search-steps" data-corn="search-steps" hidden>
|
|
65
|
+
<span id="search-count" class="hx-search-count" data-corn="search-count" aria-hidden="true"></span>
|
|
66
|
+
<button type="button" class="hx-search-btn" data-action="search-prev" aria-label="Previous match" title="Previous match (Shift+Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 10.5L8 6l4.5 4.5" /></svg></button>
|
|
67
|
+
<button type="button" class="hx-search-btn" data-action="search-next" aria-label="Next match" title="Next match (Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 5.5L8 10l4.5-4.5" /></svg></button>
|
|
68
|
+
<button type="button" class="hx-search-btn" data-action="clear-search" aria-label="Clear search" title="Clear search (Escape)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" /></svg></button>
|
|
69
|
+
</span>
|
|
70
|
+
<div id="search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
|
|
71
|
+
<div id="search-results" class="hx-search-results" data-corn="search-results" hidden></div>
|
|
72
|
+
</div>`,
|
|
73
|
+
bar: `<div id="mobile-search-bar" class="hx-mobile-search glass-header" role="search" hidden data-corn="mobile-search">
|
|
74
|
+
<input type="text" id="mobile-node-search" class="hx-input hx-input--wide" placeholder="Search nodes, apps, components..." aria-label="Search nodes" data-corn="search-input" />
|
|
75
|
+
<button type="button" class="hx-textbtn" data-action="close-mobile-search" data-corn-kind="quiet">Cancel</button>
|
|
76
|
+
<span id="mobile-search-steps" class="hx-search-steps" data-corn="search-steps" hidden>
|
|
77
|
+
<span id="mobile-search-count" class="hx-search-count" data-corn="search-count" aria-hidden="true"></span>
|
|
78
|
+
<button type="button" class="hx-search-btn" data-action="search-prev" aria-label="Previous match" title="Previous match (Shift+Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 10.5L8 6l4.5 4.5" /></svg></button>
|
|
79
|
+
<button type="button" class="hx-search-btn" data-action="search-next" aria-label="Next match" title="Next match (Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 5.5L8 10l4.5-4.5" /></svg></button>
|
|
80
|
+
<button type="button" class="hx-search-btn" data-action="clear-search" aria-label="Clear search" title="Clear search (Escape)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" /></svg></button>
|
|
81
|
+
</span>
|
|
82
|
+
<div id="mobile-search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
|
|
83
|
+
<div id="mobile-search-results" class="hx-search-results" data-corn="search-results" hidden></div>
|
|
84
|
+
</div>`,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
function rowHtml(state, m, off, stop = false) {
|
|
88
|
+
const type = off ? ` · ${escHtml(m.group)}` : '';
|
|
89
|
+
const parent = m.parent ? escHtml(m.parent) : '';
|
|
90
|
+
const current = state.searchCurrent === m.node.id;
|
|
91
|
+
return `<button type="button" role="option" class="hx-search-row" data-corn="search-result" data-search-id="${escHtml(m.node.id)}" tabindex="${stop ? 0 : -1}" aria-selected="${current}"${current ? ' aria-current="true"' : ''}><span class="hx-search-row-label">${escHtml(m.node.label)}</span><span class="hx-search-row-parent">${parent}${type}</span></button>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The list's markup for a result: a listbox (the combobox's popup) of Frame all and the groups of rows, then the "and N more" line; or the
|
|
96
|
+
* no-match words alone. The focus moves into the listbox, from option to option (each row is a button with the option role).
|
|
97
|
+
* @param {{ searchCurrent: string | null }} state
|
|
98
|
+
* @param {ReturnType<typeof searchNodes>} result
|
|
99
|
+
* @param {string} [listId] the listbox's id
|
|
100
|
+
*/
|
|
101
|
+
export function resultsHtml(state, result, listId = 'search-listbox') {
|
|
102
|
+
if (!result.query) return '';
|
|
103
|
+
if (!result.total) return `<p class="hx-search-empty" data-corn="search-empty">${escHtml(noMatchLine(result.query))}</p>`;
|
|
104
|
+
// A roving tab stop: one option (the chosen match when it is listed, else the first) is in the tab order, so Tab reaches the list that scrolls
|
|
105
|
+
const listed = result.groups.flatMap((g) => g.rows);
|
|
106
|
+
const stop = listed.some((m) => m.node.id === state.searchCurrent) ? state.searchCurrent : result.onMap ? FRAME_STOP : listed[0].node.id;
|
|
107
|
+
const frame = result.onMap ? `<button type="button" role="option" aria-selected="false" class="hx-search-row hx-search-frame" data-corn="search-result" data-search-frame tabindex="${stop === FRAME_STOP ? 0 : -1}">Frame all ${result.onMap}</button>` : '';
|
|
108
|
+
const groups = result.groups.map((g) => `<div class="hx-search-group" role="group" aria-label="${escHtml(g.name)}, ${g.count}" data-corn="search-group"><div class="hx-search-group-title" aria-hidden="true">${escHtml(g.name)} <span class="hx-search-group-count">${g.count}</span></div>${g.rows.map((m) => rowHtml(state, m, g.off, m.node.id === stop)).join('')}</div>`).join('');
|
|
109
|
+
const more = result.more ? `<p class="hx-search-more">${escHtml(moreLine(result.more))}</p>` : '';
|
|
110
|
+
return `<div role="listbox" id="${escHtml(listId)}" aria-label="Search results">${frame}${groups}</div>${more}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const rowsOf = (list) => [...list.querySelectorAll('[data-corn="search-result"]')];
|
|
114
|
+
|
|
115
|
+
/** Whether the key went to something that takes typing */
|
|
116
|
+
const typing = (el) => !!el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName));
|
|
117
|
+
|
|
118
|
+
/** Mounts the search; see the top of this file */
|
|
119
|
+
export function mount(root, inst, options = {}) {
|
|
120
|
+
const { state } = inst;
|
|
121
|
+
const scope = scopeOf(inst);
|
|
122
|
+
const made = [
|
|
123
|
+
...place(inst, root, markup().field, options.slots, 'field'),
|
|
124
|
+
...place(inst, root, markup().bar, options.slots, 'bar'),
|
|
125
|
+
];
|
|
126
|
+
/** An element of this piece by id */
|
|
127
|
+
const own = (id) => {
|
|
128
|
+
for (const el of made) {
|
|
129
|
+
if (el.id === id) return el;
|
|
130
|
+
const found = el.querySelector(`[id="${id}"]`);
|
|
131
|
+
if (found) return found;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
};
|
|
135
|
+
scope.keepParts(...made);
|
|
136
|
+
let memo = null; // { key, nodes, result }
|
|
137
|
+
let chosen = 0;
|
|
138
|
+
|
|
139
|
+
/** The parent's label, for the row: the node the first ownership edge into it comes from */
|
|
140
|
+
function parentLabeller() {
|
|
141
|
+
const byId = new Map(state.nodes.map((n) => [n.id, n]));
|
|
142
|
+
const parentOf = new Map();
|
|
143
|
+
for (const e of state.edges) if (!e.kind && !e.dashed && !parentOf.has(e.to)) parentOf.set(e.to, e.from);
|
|
144
|
+
return (node) => { const p = byId.get(parentOf.get(node.id)); return p ? String(p.label || '') : ''; };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** What the current query finds (kept until the query, the nodes or the scene change) */
|
|
148
|
+
function currentResult() {
|
|
149
|
+
const key = `${state.searchQuery}|${state.sceneVersion}|${state.nodes.length}`;
|
|
150
|
+
if (memo && memo.key === key && memo.nodes === state.nodes) return memo.result;
|
|
151
|
+
const result = searchNodes(state.nodes, state.searchQuery, { visible: (n) => inst.map.isNodeVisible(n), parentLabel: parentLabeller() });
|
|
152
|
+
memo = { key, nodes: state.nodes, result };
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Whether a search is on and found something: N and P step through its matches then */
|
|
157
|
+
const searchActive = () => !!state.searchQuery && currentResult().total > 0;
|
|
158
|
+
|
|
159
|
+
// -- drawing the count and the list ---------------------------------------------------------------------------------------------
|
|
160
|
+
const listOf = (field) => own(field.results);
|
|
161
|
+
|
|
162
|
+
/** Paints the count, the step buttons and the list of both fields from the current result */
|
|
163
|
+
function paintSearch({ keepOpen = true } = {}) {
|
|
164
|
+
const result = currentResult();
|
|
165
|
+
const text = countText(result, state.searchCurrent);
|
|
166
|
+
for (const field of FIELDS) {
|
|
167
|
+
const count = own(field.count);
|
|
168
|
+
if (count) { count.textContent = text; count.dataset.empty = result.query && !result.total ? 'true' : 'false'; }
|
|
169
|
+
const steps = own(field.steps);
|
|
170
|
+
if (steps) {
|
|
171
|
+
steps.hidden = !result.query;
|
|
172
|
+
for (const b of steps.querySelectorAll('[data-action="search-prev"], [data-action="search-next"]')) b.disabled = !result.total; // nothing to step to
|
|
173
|
+
}
|
|
174
|
+
const list = listOf(field);
|
|
175
|
+
if (!list) continue;
|
|
176
|
+
const input = own(field.input);
|
|
177
|
+
const focused = inst.active();
|
|
178
|
+
const open = !!result.query && keepOpen && (focused === input || list.contains(focused) || list.dataset.open === 'true');
|
|
179
|
+
// A row that has the focus is repainted: the focus goes to the same row again, so a keyboard user keeps their place
|
|
180
|
+
const held = list.contains(focused) ? focused : null;
|
|
181
|
+
const heldId = held ? held.dataset.searchId || (held.hasAttribute('data-search-frame') ? '' : null) : null;
|
|
182
|
+
const listId = `${field.results}-listbox`;
|
|
183
|
+
list.innerHTML = open ? resultsHtml(state, result, listId) : '';
|
|
184
|
+
if (open) for (const x of list.querySelectorAll('[data-corn]:not([part])')) x.setAttribute('part', x.getAttribute('data-corn'));
|
|
185
|
+
if (held && open && heldId !== null) {
|
|
186
|
+
const again = rowsOf(list).find((r) => (heldId === '' ? r.hasAttribute('data-search-frame') : r.dataset.searchId === heldId));
|
|
187
|
+
if (again) again.focus();
|
|
188
|
+
}
|
|
189
|
+
list.hidden = !open;
|
|
190
|
+
list.dataset.open = open ? 'true' : 'false';
|
|
191
|
+
if (input) {
|
|
192
|
+
const options2 = open && result.total > 0; // the popup is the listbox: with no match there is none, only the words (and the live region says them)
|
|
193
|
+
input.setAttribute('aria-expanded', String(options2));
|
|
194
|
+
input.setAttribute('aria-controls', options2 ? listId : field.results);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The list of a field, closed (Escape, or the focus left it) */
|
|
200
|
+
function closeList(field) {
|
|
201
|
+
const list = listOf(field);
|
|
202
|
+
if (!list) return;
|
|
203
|
+
list.hidden = true;
|
|
204
|
+
list.dataset.open = 'false';
|
|
205
|
+
list.innerHTML = '';
|
|
206
|
+
const input = own(field.input);
|
|
207
|
+
if (input) input.setAttribute('aria-expanded', 'false');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// -- the query ------------------------------------------------------------------------------------------------------------------
|
|
211
|
+
/** What the live region says for a result, once the typing pauses: the count, or for none the no-match words (engine/search-status.js) */
|
|
212
|
+
function announceResult(result) {
|
|
213
|
+
updateSearchStatus(inst, result.query, result.total > 0, countText(result, state.searchCurrent)); // once the typing pauses, not on every key
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Sets the query (typed in either field, or cleared): the map redraws, the count and the list follow */
|
|
217
|
+
function setQuery(value) {
|
|
218
|
+
const query = String(value || '').trim();
|
|
219
|
+
const changed = query !== state.searchQuery;
|
|
220
|
+
state.searchQuery = query;
|
|
221
|
+
if (changed) state.searchCurrent = null; // a new question has no current answer yet
|
|
222
|
+
inst.touchScene();
|
|
223
|
+
for (const field of FIELDS) {
|
|
224
|
+
const input = own(field.input);
|
|
225
|
+
if (input && input.value !== value) input.value = value || '';
|
|
226
|
+
const list = listOf(field);
|
|
227
|
+
if (list && input && inst.active() === input) list.dataset.open = 'true';
|
|
228
|
+
}
|
|
229
|
+
paintSearch();
|
|
230
|
+
announceResult(currentResult());
|
|
231
|
+
inst.map.render();
|
|
232
|
+
if (changed) inst.emit('search', { query: state.searchQuery, current: state.searchCurrent });
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// -- choosing a match -----------------------------------------------------------------------------------------------------------
|
|
236
|
+
/** Turns on the layer that hides `node`, so it can be shown (the matches in layers that are off) */
|
|
237
|
+
function showLayerOf(node) {
|
|
238
|
+
// A project layer that takes the node decides alone (spec 0009); else its starting layer, and what that one needs on with it
|
|
239
|
+
const tries = [projectLayerKey(state, node), groupOf(node), node.type === 'store' || node.type === 'rom' ? 'flow' : null, node.type === 'core' ? 'pkg' : null, node.type === 'core' ? 'core' : null];
|
|
240
|
+
for (const key of tries) {
|
|
241
|
+
if (inst.map.isNodeVisible(node)) return;
|
|
242
|
+
if (key && !layerOn(state, key)) toggleLayer(inst, key);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The camera that puts `node` in the middle of the part of the map nothing covers (the panels, the proposal bar, the review column, a phone's sheets: engine/sheets.js) */
|
|
247
|
+
function matchTarget(node, zoom) {
|
|
248
|
+
const r = visibleMapRect(inst);
|
|
249
|
+
return { x: r.x + r.width / 2 - node.x * zoom, y: r.y + r.height / 2 - node.y * zoom, zoom };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Selects a match and flies the camera to it (zoom 1 or closer): what Enter, a row and N do */
|
|
253
|
+
async function chooseMatch(match, { say = true } = {}) {
|
|
254
|
+
const node = match.node;
|
|
255
|
+
const mine = ++chosen;
|
|
256
|
+
if (!inst.map.isNodeVisible(node)) showLayerOf(node);
|
|
257
|
+
state.searchCurrent = node.id;
|
|
258
|
+
inst.touchScene();
|
|
259
|
+
const result = currentResult();
|
|
260
|
+
const at = result.matches.findIndex((m) => m.node.id === node.id);
|
|
261
|
+
selectNode(inst, node, { source: 'search' });
|
|
262
|
+
if (mine !== chosen || state.searchCurrent !== node.id) return; // a later choice, or a new query, has taken over
|
|
263
|
+
flyTo(inst, matchTarget(node, Math.max(state.camera.zoom, MATCH_ZOOM)));
|
|
264
|
+
paintSearch();
|
|
265
|
+
inst.emit('search', { query: state.searchQuery, current: state.searchCurrent });
|
|
266
|
+
const words = `${at + 1} of ${result.total}: ${node.label}${match.parent ? `, in ${match.parent}` : ''}`;
|
|
267
|
+
showSearchStatus(inst, ''); // said once, by the map's announcer: two live regions with the same words are read out twice
|
|
268
|
+
if (say) announce(inst, words);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** The match `by` (+1, -1) from the current one: the first (or last) with none; false when there is nothing to step to */
|
|
272
|
+
function stepMatch(by) {
|
|
273
|
+
const result = currentResult();
|
|
274
|
+
if (!state.searchQuery || !result.total) return false;
|
|
275
|
+
const at = stepIndex(result.matches, state.searchCurrent, by);
|
|
276
|
+
if (at < 0) return false;
|
|
277
|
+
chooseMatch(result.matches[at]);
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Fits the camera to every match on the map ("Frame all") */
|
|
282
|
+
function frameAll() {
|
|
283
|
+
const result = currentResult();
|
|
284
|
+
const ids = new Set(result.matches.filter((m) => m.on).map((m) => m.node.id));
|
|
285
|
+
if (!ids.size) return;
|
|
286
|
+
inst.map.fitGraphToViewport(inst.map.fitPadding(), ids);
|
|
287
|
+
showSearchStatus(inst, '');
|
|
288
|
+
announce(inst, `Framed ${ids.size} ${ids.size === 1 ? 'match' : 'matches'}`);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// -- keys and clicks ------------------------------------------------------------------------------------------------------------
|
|
292
|
+
function onFieldKey(e, field) {
|
|
293
|
+
const input = e.currentTarget;
|
|
294
|
+
if (e.key === 'Enter') {
|
|
295
|
+
if (e.isComposing) return;
|
|
296
|
+
e.preventDefault();
|
|
297
|
+
const typed = input.value.trim();
|
|
298
|
+
if (typed !== state.searchQuery) setQuery(input.value);
|
|
299
|
+
if (!typed) return;
|
|
300
|
+
const result = currentResult();
|
|
301
|
+
if (!result.total) { announce(inst, `No node matches ${typed}`); return; }
|
|
302
|
+
stepMatch(e.shiftKey ? -1 : 1);
|
|
303
|
+
} else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
304
|
+
const list = listOf(field);
|
|
305
|
+
if (!list || list.hidden) { if (e.key === 'ArrowDown' && state.searchQuery) { e.preventDefault(); list.dataset.open = 'true'; paintSearch(); } return; }
|
|
306
|
+
const rows = rowsOf(list);
|
|
307
|
+
if (!rows.length) return;
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
(e.key === 'ArrowDown' ? rows[0] : rows[rows.length - 1]).focus();
|
|
310
|
+
} else if (e.key === 'Escape') {
|
|
311
|
+
const list = listOf(field);
|
|
312
|
+
if (list && !list.hidden) { e.preventDefault(); closeList(field); return; }
|
|
313
|
+
if (state.searchQuery) { e.preventDefault(); setQuery(''); announce(inst, 'Search cleared'); }
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function onListKey(e, field) {
|
|
318
|
+
const list = listOf(field);
|
|
319
|
+
const rows = rowsOf(list);
|
|
320
|
+
const at = rows.indexOf(inst.active());
|
|
321
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
322
|
+
e.preventDefault();
|
|
323
|
+
const next = at + (e.key === 'ArrowDown' ? 1 : -1);
|
|
324
|
+
if (next < 0) own(field.input).focus(); else rows[Math.min(rows.length - 1, next)].focus();
|
|
325
|
+
} else if (e.key === 'Home' || e.key === 'End') {
|
|
326
|
+
e.preventDefault();
|
|
327
|
+
rows[e.key === 'Home' ? 0 : rows.length - 1].focus();
|
|
328
|
+
} else if (e.key === 'Escape') {
|
|
329
|
+
e.preventDefault();
|
|
330
|
+
own(field.input).focus(); // back in the field, the list still there: a second Escape shuts it
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function onListClick(e) {
|
|
335
|
+
const row = e.target.closest && e.target.closest('[data-corn="search-result"]');
|
|
336
|
+
if (!row) return;
|
|
337
|
+
if (row.hasAttribute('data-search-frame')) { frameAll(); return; }
|
|
338
|
+
const result = currentResult();
|
|
339
|
+
const match = result.matches.find((m) => m.node.id === row.dataset.searchId);
|
|
340
|
+
if (!match) return;
|
|
341
|
+
chooseMatch(match);
|
|
342
|
+
// On a phone the list would cover the match: it shuts, and the focus goes to the next-match button, which stays
|
|
343
|
+
const field = FIELDS.find((f) => listOf(f) === e.currentTarget);
|
|
344
|
+
if (field && field.input === 'mobile-node-search' && isPhone(inst)) {
|
|
345
|
+
closeList(field);
|
|
346
|
+
const next = own(field.steps) && own(field.steps).querySelector('[data-action="search-next"]');
|
|
347
|
+
if (next) next.focus();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** The list closes when the focus leaves the field and its list (a click on the map, Tab away) */
|
|
352
|
+
function onFocusOut(e, field) {
|
|
353
|
+
const next = e.relatedTarget;
|
|
354
|
+
const box = own(field.input).closest('[data-corn="search"], [data-corn="mobile-search"]');
|
|
355
|
+
if (next && box && box.contains(next)) return;
|
|
356
|
+
if (!next && e.target && e.target.matches && e.target.matches('[data-corn="search-result"]')) return; // a row that left the DOM (the list repainted)
|
|
357
|
+
closeList(field);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Opens or shuts the phone's search bar (its icon in the header, Cancel); opened, it takes the query and the focus */
|
|
361
|
+
function toggleMobileSearch(open) {
|
|
362
|
+
const bar = own('mobile-search-bar');
|
|
363
|
+
const input = own('mobile-node-search');
|
|
364
|
+
const willOpen = open !== undefined ? open : bar.hidden;
|
|
365
|
+
bar.hidden = !willOpen;
|
|
366
|
+
if (willOpen) {
|
|
367
|
+
input.value = state.searchQuery;
|
|
368
|
+
scope.timeout(() => input.focus(), 60);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Both fields, their list, and the step and clear buttons
|
|
373
|
+
for (const field of FIELDS) {
|
|
374
|
+
const input = own(field.input);
|
|
375
|
+
// A combobox whose popup is a listbox: its options (Frame all, then the rows) in labelled groups, reached with the down arrow and
|
|
376
|
+
// walked with the arrows (the focus moves from option to option), so a screen reader hears each row and its group
|
|
377
|
+
input.setAttribute('role', 'combobox');
|
|
378
|
+
input.setAttribute('aria-haspopup', 'listbox');
|
|
379
|
+
input.setAttribute('aria-autocomplete', 'none');
|
|
380
|
+
input.setAttribute('aria-expanded', 'false');
|
|
381
|
+
input.setAttribute('aria-controls', field.results);
|
|
382
|
+
scope.listen(input, 'input', (e) => setQuery(e.target.value));
|
|
383
|
+
scope.listen(input, 'keydown', (e) => onFieldKey(e, field));
|
|
384
|
+
scope.listen(input, 'focus', () => { const list = listOf(field); if (list && state.searchQuery) { list.dataset.open = 'true'; paintSearch(); } });
|
|
385
|
+
const box = input.closest('[data-corn="search"], [data-corn="mobile-search"]');
|
|
386
|
+
if (box) scope.listen(box, 'focusout', (e) => onFocusOut(e, field));
|
|
387
|
+
const list = listOf(field);
|
|
388
|
+
if (list) {
|
|
389
|
+
// A press on a row keeps the focus where it is (some browsers do not focus a button they press): the field would lose it and shut the list before the click
|
|
390
|
+
scope.listen(list, 'mousedown', (e) => { if (e.target.closest && e.target.closest('[data-corn="search-result"]')) e.preventDefault(); });
|
|
391
|
+
scope.listen(list, 'click', onListClick);
|
|
392
|
+
scope.listen(list, 'keydown', (e) => onListKey(e, field));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// The piece's own buttons: the phone's search icon and Cancel, previous, next and clear
|
|
397
|
+
const ACTIONS = {
|
|
398
|
+
'toggle-mobile-search': () => toggleMobileSearch(),
|
|
399
|
+
'close-mobile-search': () => toggleMobileSearch(false),
|
|
400
|
+
'clear-search': () => { setQuery(''); const bar = own('mobile-search-bar'); (bar && !bar.hidden ? own('mobile-node-search') : own('node-search')).focus(); },
|
|
401
|
+
'search-prev': () => stepMatch(-1),
|
|
402
|
+
'search-next': () => stepMatch(1),
|
|
403
|
+
};
|
|
404
|
+
for (const el of made) {
|
|
405
|
+
scope.listen(el, 'click', (e) => {
|
|
406
|
+
const target = e.target.closest && e.target.closest('[data-action]');
|
|
407
|
+
if (!target || !el.contains(target)) return;
|
|
408
|
+
const action = ACTIONS[target.dataset.action];
|
|
409
|
+
if (action) action(target);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** `/` goes to the search box, or to the phone's search bar where the box is not shown (opening the bar if it is shut) */
|
|
414
|
+
function goToSearch() {
|
|
415
|
+
const input = own('node-search');
|
|
416
|
+
const shown = input && input.closest('.hx-search') && inst.win.getComputedStyle(input.closest('.hx-search')).display !== 'none';
|
|
417
|
+
if (shown) { input.focus(); input.select(); return; }
|
|
418
|
+
const bar = own('mobile-search-bar');
|
|
419
|
+
if (bar && !bar.hidden) { own('mobile-node-search').focus(); return; }
|
|
420
|
+
const open = own('mobile-search-toggle');
|
|
421
|
+
if (open) open.click();
|
|
422
|
+
}
|
|
423
|
+
scope.listen(inst.root, 'keydown', (e) => {
|
|
424
|
+
if (e.key === '/' && !e.ctrlKey && !e.metaKey && !e.altKey && !typing(e.target) && !inst.root.querySelector('[data-corn="dialog-scrim"]:not([hidden]), .hx-mockup-dialog')) {
|
|
425
|
+
e.preventDefault();
|
|
426
|
+
goToSearch();
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// What the neighbours ask of the search, and a layer going on or off moving matches between the list and "In layers that are off"
|
|
431
|
+
scope.on('search:active', () => searchActive());
|
|
432
|
+
scope.on('search:step', (by) => stepMatch(by));
|
|
433
|
+
scope.on('layers', () => { if (state.searchQuery) paintSearch(); });
|
|
434
|
+
scope.own(() => { chosen++; made.forEach((el) => el.remove()); });
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
elements: made,
|
|
438
|
+
setQuery,
|
|
439
|
+
stepMatch,
|
|
440
|
+
frameAll,
|
|
441
|
+
chooseMatch,
|
|
442
|
+
currentResult,
|
|
443
|
+
searchActive,
|
|
444
|
+
paintSearch,
|
|
445
|
+
toggleMobileSearch,
|
|
446
|
+
/** For tests: forget what was found */
|
|
447
|
+
reset() { memo = null; chosen++; state.searchQuery = ''; state.searchCurrent = null; },
|
|
448
|
+
update(props) {
|
|
449
|
+
if (props && 'query' in props) setQuery(props.query);
|
|
450
|
+
else paintSearch();
|
|
451
|
+
},
|
|
452
|
+
destroy: () => scope.destroy(),
|
|
453
|
+
};
|
|
454
|
+
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* Switching the view never moves a node: all three draw the same positions.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { escHtml } from '
|
|
21
|
+
import { escapeHtml as escHtml } from '../core/text.js';
|
|
22
22
|
import { markStateAttr, stateIconHtml } from './corn-state.js';
|
|
23
23
|
import { specStateOf, specStateWords, SPEC_STATE_WORDS, SPEC_STATE_CORN } from './waiting-model.js';
|
|
24
24
|
|
package/explorer/proposal.js
CHANGED
|
@@ -591,6 +591,7 @@ export function showEdgePanel(edge) {
|
|
|
591
591
|
$('drawer-file-btn').hidden = true;
|
|
592
592
|
$('drawer-run-btn').hidden = true;
|
|
593
593
|
$('spec-drawer').classList.add('drawer-open');
|
|
594
|
+
$('spec-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
|
|
594
595
|
$('drawer-backdrop').hidden = false;
|
|
595
596
|
touchScene();
|
|
596
597
|
render();
|