@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
package/explorer/capped.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module explorer/capped
|
|
3
3
|
*
|
|
4
4
|
* A long list in the node panel shows its first few items and a quiet "and 15 more" button that opens the rest in place
|
|
5
|
-
* (a disclosure: `aria-expanded`). `toggleCapped` is the click handler
|
|
5
|
+
* (a disclosure: `aria-expanded`). `toggleCapped` is the click handler the node panel (pieces/node-panel.js) binds once on its list.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/** Items shown before the rest folds away */
|
|
@@ -25,7 +25,8 @@ export function capped(items, cap = CAP) {
|
|
|
25
25
|
export function toggleCapped(target) {
|
|
26
26
|
const button = target.closest && target.closest('[data-more]');
|
|
27
27
|
if (!button) return false;
|
|
28
|
-
const
|
|
28
|
+
const before = button.previousElementSibling; // the folded list is the button's own neighbour, so the id is only a label and two roots may count alike
|
|
29
|
+
const list = before && before.id === button.dataset.more ? before : null;
|
|
29
30
|
const open = button.getAttribute('aria-expanded') !== 'true';
|
|
30
31
|
if (list) list.hidden = !open;
|
|
31
32
|
button.setAttribute('aria-expanded', String(open));
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/engine/feedback
|
|
3
|
+
*
|
|
4
|
+
* One way to say what an action came to: **where the person is looking** (by the control they used) and **to a screen reader** (the live
|
|
5
|
+
* region), together. A result is kept under its key (a run's id) until the next action on that key, so a card that is drawn again shows
|
|
6
|
+
* it again; a result that has no next action to end it (Copy spec) goes after `RESULT_MS`, which is never less than five seconds.
|
|
7
|
+
* The results are the instance's own. explorer/feedback.js keeps the old names for the page's instance.
|
|
8
|
+
*
|
|
9
|
+
* sayResult(inst, key, words, ok) keep the result for `key` and announce it
|
|
10
|
+
* resultOf(inst, key) { text, ok } or null
|
|
11
|
+
* clearResult(inst, key) the next action on `key` begins: the old result goes
|
|
12
|
+
* showResultIn(inst, el, key) paints the result of `key` into a result element (`data-corn="result"`), hidden when there is none
|
|
13
|
+
*/
|
|
14
|
+
import { announce } from './keyboard.js';
|
|
15
|
+
|
|
16
|
+
/** How long a result with no next action to end it stays (ms): at least five seconds */
|
|
17
|
+
export const RESULT_MS = 6000;
|
|
18
|
+
|
|
19
|
+
const resultsOf = (inst) => inst.slot('feedback', () => new Map());
|
|
20
|
+
|
|
21
|
+
/** Keeps the result of an action under `key` and announces it through the live region */
|
|
22
|
+
export function sayResult(inst, key, text, ok = true) {
|
|
23
|
+
resultsOf(inst).set(key, { text, ok });
|
|
24
|
+
announce(inst, text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The result kept under `key`, or null */
|
|
28
|
+
export function resultOf(inst, key) {
|
|
29
|
+
return resultsOf(inst).get(key) || null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The next action on `key` begins: its old result goes */
|
|
33
|
+
export function clearResult(inst, key) {
|
|
34
|
+
resultsOf(inst).delete(key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Paints the result of `key` into `el` (a result element), hidden when there is none */
|
|
38
|
+
export function showResultIn(inst, el, key) {
|
|
39
|
+
if (!el) return;
|
|
40
|
+
const r = resultsOf(inst).get(key);
|
|
41
|
+
el.hidden = !r;
|
|
42
|
+
el.textContent = r ? r.text : '';
|
|
43
|
+
if (r) el.dataset.cornState = r.ok ? 'success' : 'failure'; else delete el.dataset.cornState;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** For tests: forget every result */
|
|
47
|
+
export function resetFeedback(inst) {
|
|
48
|
+
resultsOf(inst).clear();
|
|
49
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/engine/flow-ui
|
|
3
|
+
*
|
|
4
|
+
* Data flow in the Layers menu and the node panel, on an instance: the legend of the flow lines and the "Sends to / Gets from" block of a node's
|
|
5
|
+
* panel. How a flow edge is styled is flow-style.js; the data-flow preset is flows.js `buildDataFlow` (a pure function of nodes and edges).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
9
|
+
import { themed } from '../theme-model.js';
|
|
10
|
+
import { capped } from '../capped.js';
|
|
11
|
+
import { layersOf } from '../layer-model.js';
|
|
12
|
+
import { FLOW_STYLES } from '../flow-style.js';
|
|
13
|
+
|
|
14
|
+
export function renderFlowLegend(inst) {
|
|
15
|
+
const el = inst.el('flow-legend');
|
|
16
|
+
if (!el) return;
|
|
17
|
+
const { state } = inst;
|
|
18
|
+
const activeLayers = layersOf(state);
|
|
19
|
+
if (activeLayers.flow === false && activeLayers.table === false) { el.innerHTML = ''; el.hidden = true; return; }
|
|
20
|
+
el.hidden = false;
|
|
21
|
+
const row = (swatch, text) => `<div class="hx-legend-row"><span class="hx-legend-swatch">${swatch}</span><span>${text}</span></div>`;
|
|
22
|
+
el.innerHTML = `
|
|
23
|
+
<div class="hx-menu-section" data-corn="menu-section" part="menu-section">
|
|
24
|
+
<div class="hx-menu-title" data-corn="menu-title" part="menu-title">
|
|
25
|
+
<span>Data Flow</span>
|
|
26
|
+
</div>
|
|
27
|
+
${Object.values(FLOW_STYLES).map((s) => row(`<span data-corn="swatch" part="swatch" class="hx-swatch-line" style="background:${themed(s.color, state.theme)}"></span>`, s.label)).join('')}
|
|
28
|
+
</div>`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function flowSummary(inst, node) {
|
|
32
|
+
const { state } = inst;
|
|
33
|
+
const nameOf = (id) => (state.nodes.find((n) => n.id === id) || { label: id }).label;
|
|
34
|
+
const flows = state.edges.filter((e) => e.kind === 'flow' && (e.from === node.id || e.to === node.id));
|
|
35
|
+
const fact = (key, list, out) => (list.length
|
|
36
|
+
? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">${key}</div><div class="hx-fact-v">${capped(list.map((e) => `<div class="hx-line"><span><span class="hx-name">${escHtml(nameOf(out ? e.to : e.from))}</span> · ${escHtml(e.label)}${e.status === 'live' ? '' : ' <span class="hx-warn">(proposed)</span>'}</span></div>`))}</div></div>`
|
|
37
|
+
: '');
|
|
38
|
+
return fact('Sends to', flows.filter((e) => e.from === node.id), true) + fact('Gets from', flows.filter((e) => e.to === node.id && e.from !== node.id), false);
|
|
39
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/engine/fly
|
|
3
|
+
*
|
|
4
|
+
* The camera flying to a place, on an instance: a short glide to `{ x, y, zoom }`, as the scenario player's steps do, so a match chosen in a
|
|
5
|
+
* search is not a jump the eye has to find again. Under reduced motion the camera jumps. A new flight replaces the one in the air, and a
|
|
6
|
+
* hand on the map (a pan, a wheel) is not fought: `stopFlight(inst)` ends it (the page calls it when the pointer takes the camera, on `grab`).
|
|
7
|
+
* It is a frame client of the instance's map loop, so it asks for frames only while it flies. explorer/fly.js keeps the old names for the page.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** How quickly the camera closes on the target: the time constant of the glide (ms) */
|
|
11
|
+
export const FLY_MS = 120;
|
|
12
|
+
|
|
13
|
+
/** The flight of one instance: made on first use, joined to the map's frame loop */
|
|
14
|
+
function flightOf(inst) {
|
|
15
|
+
return inst.slot('fly', () => {
|
|
16
|
+
const f = { glide: null }; // { to: {x, y, zoom}, last: nowMs|null }
|
|
17
|
+
f.tick = (now) => {
|
|
18
|
+
if (!f.glide) return;
|
|
19
|
+
const dt = f.glide.last === null ? 16 : Math.min(now - f.glide.last, 100);
|
|
20
|
+
f.glide.last = now;
|
|
21
|
+
const k = 1 - Math.exp(-dt / FLY_MS);
|
|
22
|
+
const cam = inst.state.camera;
|
|
23
|
+
cam.x += (f.glide.to.x - cam.x) * k;
|
|
24
|
+
cam.y += (f.glide.to.y - cam.y) * k;
|
|
25
|
+
cam.zoom += (f.glide.to.zoom - cam.zoom) * k;
|
|
26
|
+
if (Math.abs(f.glide.to.x - cam.x) < 0.5 && Math.abs(f.glide.to.y - cam.y) < 0.5 && Math.abs(f.glide.to.zoom - cam.zoom) < 0.002) {
|
|
27
|
+
Object.assign(cam, f.glide.to);
|
|
28
|
+
f.glide = null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
f.off = inst.map ? inst.map.addFrameClient({ wants: () => !!f.glide, tick: f.tick }) : null;
|
|
32
|
+
if (f.off) inst.own(f.off);
|
|
33
|
+
return f;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Flies the camera to `target` (jumps there when motion is reduced) */
|
|
38
|
+
export function flyTo(inst, target) {
|
|
39
|
+
if (!target) return;
|
|
40
|
+
const f = flightOf(inst);
|
|
41
|
+
const { state } = inst;
|
|
42
|
+
if (inst.reducedMotion || !state.width) { Object.assign(state.camera, target); f.glide = null; inst.map.render(); return; }
|
|
43
|
+
f.glide = { to: { ...target }, last: null };
|
|
44
|
+
inst.map.ensureFlowLoop();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Ends a flight where it is */
|
|
48
|
+
export function stopFlight(inst) { flightOf(inst).glide = null; }
|
|
49
|
+
|
|
50
|
+
/** Whether the camera is in the air */
|
|
51
|
+
export const flying = (inst) => !!flightOf(inst).glide;
|
|
52
|
+
|
|
53
|
+
/** One frame of the glide (exported so a test can be the loop) */
|
|
54
|
+
export function tickFlight(inst, now) { flightOf(inst).tick(now); }
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/engine/hint
|
|
3
|
+
*
|
|
4
|
+
* The hint at the map's corner ("Click a node for what it is"; CF review F56), on an instance. Three rules:
|
|
5
|
+
* - its words follow the pointer: `hintInspect` / `hintDrag` for a mouse or a trackpad, `hintInspectTouch` / `hintDragTouch` where the
|
|
6
|
+
* main pointer is coarse (a finger). A repo that sets only `hintInspect` (or `hintDrag`) gets its words on both;
|
|
7
|
+
* - it goes once the person has selected a node, for the rest of the session (sessionStorage; the Flow view's own description stays,
|
|
8
|
+
* since it says what Flow is, not how to use the map);
|
|
9
|
+
* - it is never shown over an open proposal, a node panel, the Work panel or a sheet.
|
|
10
|
+
* The icon is `[data-corn="hint-icon"]`, so a theme can restyle or replace it. explorer/hint.js keeps the old names for the page's instance.
|
|
11
|
+
*/
|
|
12
|
+
import { isOverridden, t } from './strings.js';
|
|
13
|
+
|
|
14
|
+
export const HINT_STORAGE_KEY = 'cornfield:hint-done';
|
|
15
|
+
|
|
16
|
+
/** Whether the main pointer is a finger (`(pointer: coarse)`) */
|
|
17
|
+
export function coarsePointer(win) {
|
|
18
|
+
try { return !!(win && win.matchMedia && win.matchMedia('(pointer: coarse)').matches); } catch { return false; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The words by the pointer: the Touch ones on a finger, unless the repo set only the plain key (then its words serve both) */
|
|
22
|
+
export function hintWords(plain, touch, coarse) {
|
|
23
|
+
return coarse && (touch.set || !plain.set) ? touch.text : plain.text;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The hint for the view in force */
|
|
27
|
+
export function hintText(inst, coarse = coarsePointer(inst.win)) {
|
|
28
|
+
const { state } = inst;
|
|
29
|
+
if (state.view === 'dataflow') return t(inst, 'hintDataFlow');
|
|
30
|
+
return state.isFreeform
|
|
31
|
+
? hintWords({ text: t(inst, 'hintDrag'), set: isOverridden(inst, 'hintDrag') }, { text: t(inst, 'hintDragTouch'), set: isOverridden(inst, 'hintDragTouch') }, coarse)
|
|
32
|
+
: hintWords({ text: t(inst, 'hintInspect'), set: isOverridden(inst, 'hintInspect') }, { text: t(inst, 'hintInspectTouch'), set: isOverridden(inst, 'hintInspectTouch') }, coarse);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const sessionOf = (inst) => { try { return inst.win ? inst.win.sessionStorage : null; } catch { return null; } };
|
|
36
|
+
/** Whether a node was selected in this session, for this instance */
|
|
37
|
+
const memory = (inst) => inst.slot('hint', () => {
|
|
38
|
+
const m = { dismissed: false };
|
|
39
|
+
try { const store = sessionOf(inst); m.dismissed = !!store && store.getItem(HINT_STORAGE_KEY) === '1'; } catch { m.dismissed = false; }
|
|
40
|
+
return m;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** Remembers that a node was selected: the hint is not shown again this session */
|
|
44
|
+
export function dismissHint(inst) {
|
|
45
|
+
const m = memory(inst);
|
|
46
|
+
if (m.dismissed) return;
|
|
47
|
+
m.dismissed = true;
|
|
48
|
+
try { const store = sessionOf(inst); if (store) store.setItem(HINT_STORAGE_KEY, '1'); } catch { /* storage blocked: it holds for this page load */ }
|
|
49
|
+
syncHint(inst);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** For tests: the hint is new again */
|
|
53
|
+
export function resetHint(inst) {
|
|
54
|
+
memory(inst).dismissed = false;
|
|
55
|
+
try { const store = sessionOf(inst); if (store) store.removeItem(HINT_STORAGE_KEY); } catch { /* none */ }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** What covers the map: an open proposal, the node panel, the Work panel, a sheet of the dock */
|
|
59
|
+
export function mapCovered(inst) {
|
|
60
|
+
const open = (id) => inst.el(id);
|
|
61
|
+
const bar = open('proposal-bar');
|
|
62
|
+
if (bar && !bar.hidden) return true;
|
|
63
|
+
const drawer = open('spec-drawer');
|
|
64
|
+
if (drawer && drawer.classList.contains('drawer-open')) return true;
|
|
65
|
+
const work = open('forge-panel');
|
|
66
|
+
if (work && work.classList.contains('forge-open')) return true;
|
|
67
|
+
return !!(inst.root && inst.root.querySelector('[data-corn="scenario-player"]')); // a scenario is playing (a sheet on a phone)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Words, and whether it shows, for the state of the page now */
|
|
71
|
+
export function syncHint(inst) {
|
|
72
|
+
const text = inst.el('instruction-badge-text');
|
|
73
|
+
const words = hintText(inst);
|
|
74
|
+
if (text && text.textContent !== words) text.textContent = words;
|
|
75
|
+
const hint = text && text.closest('[data-corn="hint"]');
|
|
76
|
+
if (!hint) return;
|
|
77
|
+
const hide = mapCovered(inst) || (memory(inst).dismissed && inst.state.view !== 'dataflow');
|
|
78
|
+
if (hint.hidden !== hide) hint.hidden = hide;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Keeps the hint right as panels open and close, and as the pointer kind changes. Returns how to stop; the instance's end stops it too. */
|
|
82
|
+
export function watchHint(inst) {
|
|
83
|
+
const win = inst.win;
|
|
84
|
+
const stops = [];
|
|
85
|
+
const stage = (inst.root && inst.root.querySelector('[data-corn="stage"]')) || (inst.doc && inst.doc.body);
|
|
86
|
+
if (win && win.MutationObserver && stage) {
|
|
87
|
+
const mo = new win.MutationObserver(() => syncHint(inst));
|
|
88
|
+
mo.observe(stage, { attributes: true, attributeFilter: ['class', 'hidden', 'inert'], childList: true, subtree: true });
|
|
89
|
+
stops.push(() => mo.disconnect());
|
|
90
|
+
}
|
|
91
|
+
const media = win && win.matchMedia ? win.matchMedia('(pointer: coarse)') : null;
|
|
92
|
+
if (media && media.addEventListener) stops.push(inst.listen(media, 'change', () => syncHint(inst)));
|
|
93
|
+
syncHint(inst);
|
|
94
|
+
const stop = () => stops.forEach((fn) => fn());
|
|
95
|
+
inst.own(stop);
|
|
96
|
+
return stop;
|
|
97
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/engine/keyboard
|
|
3
|
+
*
|
|
4
|
+
* The map by keyboard, and what a screen reader hears (MAP-02), on an instance. keyboard-model.js decides what a key means and the words;
|
|
5
|
+
* this module does it:
|
|
6
|
+
*
|
|
7
|
+
* - the map canvas is focusable (`tabindex="0"`, `role="application"`, its keys in `#map-keys-help`): the arrow keys pan, + and - zoom about
|
|
8
|
+
* the middle, 0 fits, N and P (or ] and [) step through the visible nodes in reading order and select each, centred, Home and End the first
|
|
9
|
+
* and the last, Enter goes into the panel, Escape closes it, and in Freeform Alt+arrow moves the selected node. The keys are the canvas's:
|
|
10
|
+
* they act only while the canvas has the focus, so another instance on the page is not moved;
|
|
11
|
+
* - `#map-announcer` (a polite live region) says where the keyboard landed: the node, its type, its connections, its place; the zoom; a
|
|
12
|
+
* search's hit. `announce(inst, text)` also tells the instance (`announce`), for a host that keeps its live region elsewhere;
|
|
13
|
+
* - with a search on, N and P step through its matches: the search piece answers `search:active` and `search:step` (pieces/search.js).
|
|
14
|
+
*
|
|
15
|
+
* The keys of the node panel (Escape inside it), of the Layers menu (Escape) and of the search (`/`) belong to those pieces. A shortcut acts
|
|
16
|
+
* only while the focus is inside the instance's root; on the page the root is the document. explorer/keyboard.js keeps the old names for the page.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { zoomAbout } from '../camera.js';
|
|
20
|
+
import { selectNode, clearSelection } from './selection.js';
|
|
21
|
+
import { saveFreeformPositions } from './layout.js';
|
|
22
|
+
import * as K from '../keyboard-model.js';
|
|
23
|
+
import { frameSelection, litNodes } from '../selection-view.js';
|
|
24
|
+
|
|
25
|
+
/** Tells a screen reader `text` (politely: after what it is reading). The same words twice are said twice. */
|
|
26
|
+
export function announce(inst, text) {
|
|
27
|
+
const mem = inst.slot('announce', () => {
|
|
28
|
+
const m = { timer: null };
|
|
29
|
+
inst.own(() => clearTimeout(m.timer));
|
|
30
|
+
return m;
|
|
31
|
+
});
|
|
32
|
+
inst.emit('announce', text);
|
|
33
|
+
const el = inst.el('map-announcer');
|
|
34
|
+
if (!el) return;
|
|
35
|
+
el.textContent = '';
|
|
36
|
+
clearTimeout(mem.timer);
|
|
37
|
+
// a fresh text node a moment later is what makes a live region speak again
|
|
38
|
+
mem.timer = setTimeout(() => { el.textContent = text; }, 30);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The visible nodes, in the order the keys step through them */
|
|
42
|
+
const stepOrder = (inst) => K.readingOrder(inst.state.nodes.filter((n) => inst.map.isNodeVisible(n)));
|
|
43
|
+
|
|
44
|
+
/** The camera that puts `node` in the middle of the part of the map not under the panels or a phone's sheets, at `zoom` (the current one by default) */
|
|
45
|
+
export function centreTarget(inst, node, zoom = inst.state.camera.zoom) {
|
|
46
|
+
const { width, height } = inst.state;
|
|
47
|
+
const visibleHeight = Math.max(160, height - (inst.state.coveredBottom || 0));
|
|
48
|
+
const panel = inst.el('spec-drawer');
|
|
49
|
+
const visibleWidth = width >= 768 && panel && panel.classList.contains('drawer-open') ? Math.max(160, width - (panel.offsetWidth || 480)) : width;
|
|
50
|
+
// The issues and PRs panel slides in from the left (forge-panel.js)
|
|
51
|
+
const forge = inst.el('forge-panel');
|
|
52
|
+
const left = width >= 768 && forge && forge.classList.contains('forge-open') ? Math.min(forge.offsetWidth || 400, visibleWidth - 160) : 0;
|
|
53
|
+
return { x: left + (visibleWidth - left) / 2 - node.x * zoom, y: visibleHeight / 2 - node.y * zoom, zoom };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Moves the camera so `node` is in the middle of the part of the map not under the panels or a phone's sheets */
|
|
57
|
+
export function centreOn(inst, node) {
|
|
58
|
+
Object.assign(inst.state.camera, centreTarget(inst, node));
|
|
59
|
+
inst.map.render();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function land(inst, node, order) {
|
|
63
|
+
if (!node) { announce(inst, 'No nodes are shown. Turn a layer on in the Layers menu.'); return; }
|
|
64
|
+
selectNode(inst, node, { frame: true, source: 'keyboard' }); // the keyboard's selection frames the node and what it lights (spec 0008 D6)
|
|
65
|
+
announce(inst, K.describeNode(node, order.length, order.indexOf(node)));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** "Frame them" and the `F` key: the camera goes to the selected node and what it lights, and a screen reader is told how many that is */
|
|
69
|
+
export function frameThem(inst) {
|
|
70
|
+
const { state } = inst;
|
|
71
|
+
if (!state.selectedNode) return;
|
|
72
|
+
const target = frameSelection(inst);
|
|
73
|
+
if (!target) return;
|
|
74
|
+
const connected = Math.max(0, litNodes(inst).length - 1);
|
|
75
|
+
announce(inst, target.framed ? `Framed ${state.selectedNode.label} and ${connected} connected` : `${state.selectedNode.label} centred: ${connected} connected, too spread out to frame together`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function moveSelected(inst, dx, dy) {
|
|
79
|
+
const { state } = inst;
|
|
80
|
+
const node = state.selectedNode;
|
|
81
|
+
if (!node) return;
|
|
82
|
+
node.x += dx;
|
|
83
|
+
node.y += dy;
|
|
84
|
+
state.freeformPositions[node.id] = { x: node.x, y: node.y };
|
|
85
|
+
inst.touchScene();
|
|
86
|
+
saveFreeformPositions(inst);
|
|
87
|
+
inst.map.render();
|
|
88
|
+
announce(inst, `Moved ${node.label}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function onMapKey(inst, e) {
|
|
92
|
+
const { state, map } = inst;
|
|
93
|
+
if (e.target !== state.canvas || e.defaultPrevented) return;
|
|
94
|
+
const action = K.mapKeyAction(e.key, {
|
|
95
|
+
shift: e.shiftKey, alt: e.altKey, ctrl: e.ctrlKey, meta: e.metaKey,
|
|
96
|
+
scenario: !!state.scenario, freeform: state.isFreeform && state.view === 'orbit', selected: !!state.selectedNode,
|
|
97
|
+
});
|
|
98
|
+
if (!action) return;
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
const { camera, width, height } = state;
|
|
101
|
+
switch (action.type) {
|
|
102
|
+
case 'pan':
|
|
103
|
+
camera.x += action.dx;
|
|
104
|
+
camera.y += action.dy;
|
|
105
|
+
map.render();
|
|
106
|
+
break;
|
|
107
|
+
case 'zoom':
|
|
108
|
+
Object.assign(camera, zoomAbout(camera, action.factor, width / 2, height / 2, map.getMinZoom()));
|
|
109
|
+
map.render();
|
|
110
|
+
announce(inst, K.zoomWords(camera.zoom));
|
|
111
|
+
break;
|
|
112
|
+
case 'fit':
|
|
113
|
+
map.fitGraphToViewport(map.fitPadding());
|
|
114
|
+
announce(inst, `The whole map. ${K.zoomWords(camera.zoom)}`);
|
|
115
|
+
break;
|
|
116
|
+
case 'step': {
|
|
117
|
+
if (inst.ask('search:active') && inst.ask('search:step', action.by)) break; // with a search on, N and P walk its matches (pieces/search.js)
|
|
118
|
+
const order = stepOrder(inst);
|
|
119
|
+
land(inst, K.stepFrom(order, state.selectedNode && state.selectedNode.id, action.by), order);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'first': case 'last': {
|
|
123
|
+
const order = stepOrder(inst);
|
|
124
|
+
land(inst, action.type === 'first' ? order[0] : order[order.length - 1], order);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case 'frame':
|
|
128
|
+
frameThem(inst);
|
|
129
|
+
break;
|
|
130
|
+
case 'open':
|
|
131
|
+
inst.emit('node:focus'); // into the open panel: its title takes the focus, so a screen reader starts there and Tab goes on into it
|
|
132
|
+
break;
|
|
133
|
+
case 'close':
|
|
134
|
+
clearSelection(inst, { source: 'keyboard' });
|
|
135
|
+
announce(inst, 'Panel closed');
|
|
136
|
+
break;
|
|
137
|
+
case 'move':
|
|
138
|
+
moveSelected(inst, action.dx, action.dy);
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Wires the map's keys (once the canvas is on the state); a second call does nothing until `resetKeyboard` */
|
|
145
|
+
export function initKeyboard(inst) {
|
|
146
|
+
const mem = inst.slot('keyboard', () => ({ off: null }));
|
|
147
|
+
if (mem.off || !inst.state.canvas) return;
|
|
148
|
+
mem.off = inst.listen(inst.state.canvas, 'keydown', (e) => onMapKey(inst, e));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** For tests: wire again on a fresh page */
|
|
152
|
+
export function resetKeyboard(inst) {
|
|
153
|
+
const mem = inst.slot('keyboard', () => ({ off: null }));
|
|
154
|
+
if (mem.off) mem.off();
|
|
155
|
+
mem.off = null;
|
|
156
|
+
}
|