@popcorn245/cornfield 0.46.1 → 0.47.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/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 +98 -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 +552 -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-build.js +88 -0
- package/explorer/flow-style.js +28 -0
- package/explorer/flows.js +11 -132
- package/explorer/fly.js +11 -43
- package/explorer/hint.js +15 -88
- package/explorer/index.html +40 -82
- package/explorer/input.js +197 -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 +66 -0
- package/explorer/page.js +223 -0
- package/explorer/panels.js +29 -409
- package/explorer/pieces/adopt-tokens.js +38 -0
- package/explorer/pieces/layers.js +325 -0
- package/explorer/pieces/map-stage.css +14 -0
- package/explorer/pieces/map.js +332 -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 +12 -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/explorer/sheets.js
CHANGED
|
@@ -1,386 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/sheets
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
7
|
-
*
|
|
8
|
-
* screen (60% for the node panel) with its own scroll. A tap or a swipe on the handle expands or collapses it; a tap
|
|
9
|
-
* on the map collapses it. At most one is expanded at a time (sheet-model.js). Spec 0010 D7: the Work panel is a sheet too, with the review
|
|
10
|
-
* (the proposal bar or the scenario player) and one other sheet at most (opening Work displaces the node panel and the reverse); while one is
|
|
11
|
-
* expanded the sheet of the other group folds to a **stub** (one 44px row: its title and its badge; a tap swaps them), and an expanded sheet is
|
|
12
|
-
* capped so the map keeps 35% of the screen (`--hx-sheet-cap`, sheet-model.js `sheetCap`). Escape folds an expanded sheet, then closes.
|
|
13
|
-
*
|
|
14
|
-
* The sheets cover the bottom of the map, so the map must not fit or follow a step into that part:
|
|
15
|
-
* `measureCovered()` is the height the dock covers (0 on a desktop), kept in `state.coveredBottom`
|
|
16
|
-
* and in `--hx-covered` on the stage; render.js's fit and the scenario camera read it.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { state } from './state.js';
|
|
20
|
-
import { createSheetModel, sheetCap } from './sheet-model.js';
|
|
21
|
-
import { freeRect } from './camera.js';
|
|
22
|
-
|
|
23
|
-
/** The width below which the sheets apply (matches the CSS) */
|
|
24
|
-
export const PHONE_QUERY = '(max-width: 767px)';
|
|
25
|
-
/** A drag on the handle longer than this (px) is a swipe, not a tap */
|
|
26
|
-
const SWIPE_PX = 20;
|
|
27
|
-
|
|
28
|
-
const model = createSheetModel();
|
|
29
|
-
const elements = new Map(); // id -> the sheet's element
|
|
30
|
-
const options = new Map(); // id -> { stub?: () => { title: string, badge?: string, label?: string }, away?: () => void } what the sheet's owner gave it
|
|
31
|
-
const wiredAs = new WeakMap(); // a sheet's element, and its handle -> the id their listeners were bound for
|
|
32
|
-
const away = new Set(); // sheets displaced by the other of their group: open on the page, hidden until opened again
|
|
33
|
-
const listeners = new Set();
|
|
34
|
-
let dock = null;
|
|
35
|
-
let lastCovered = 0;
|
|
36
|
-
let observers = [];
|
|
37
|
-
|
|
38
|
-
export const isPhone = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(PHONE_QUERY).matches;
|
|
39
|
-
|
|
40
|
-
const $ = (id) => document.getElementById(id);
|
|
41
|
-
const stageOf = () => (dock && dock.parentElement) || (state.canvas ? state.canvas.parentElement : null);
|
|
42
|
-
|
|
43
|
-
/** 'expanded', 'stub' or 'peek' for a registered sheet (a sheet that is not open is a peek, as it is when it opens); undefined for one that is not registered */
|
|
44
|
-
export const sheetState = (id) => { const st = model.stateOf(id); return st === 'hidden' ? 'peek' : st; };
|
|
45
|
-
/** The id of the expanded sheet, or null */
|
|
46
|
-
export const expandedSheet = () => model.expanded();
|
|
47
|
-
|
|
48
|
-
/** Calls `fn` when the height the sheets cover, or which sheet is expanded, changes. Returns how to stop. */
|
|
49
|
-
export function onCoveredChange(fn) {
|
|
50
|
-
listeners.add(fn);
|
|
51
|
-
return () => listeners.delete(fn);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Puts the model on the page: each sheet's attribute and handle, the stage's `data-sheet-open`, the covered height */
|
|
55
|
-
function apply() {
|
|
56
|
-
syncShown();
|
|
57
|
-
for (const [id, el] of elements) {
|
|
58
|
-
const expanded = model.isExpanded(id);
|
|
59
|
-
const st = model.stateOf(id);
|
|
60
|
-
el.dataset.sheetState = st === 'hidden' ? 'peek' : st;
|
|
61
|
-
const handle = [...el.children].find((c) => c.classList.contains('hx-sheet-handle'));
|
|
62
|
-
if (handle) {
|
|
63
|
-
handle.setAttribute('aria-expanded', String(expanded));
|
|
64
|
-
handle.setAttribute('aria-label', expanded ? 'Collapse this panel' : 'Expand this panel');
|
|
65
|
-
}
|
|
66
|
-
paintStub(id, el, st === 'stub');
|
|
67
|
-
}
|
|
68
|
-
const stage = stageOf();
|
|
69
|
-
if (stage) stage.dataset.sheetOpen = model.expanded() || '';
|
|
70
|
-
// The expanded sheet is capped so the map keeps 35% of the screen: what is left under the stub, if there is one
|
|
71
|
-
if (dock && isPhone() && typeof window !== 'undefined') dock.style.setProperty('--hx-sheet-cap', `${sheetCap(window.innerHeight || 0, model.stubs())}px`);
|
|
72
|
-
markLast();
|
|
73
|
-
measureCovered();
|
|
74
|
-
listeners.forEach((fn) => fn());
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Whether a sheet's element is open on the page (the proposal bar is shown, the Work panel and the node panel carry their open class) */
|
|
78
|
-
function isOpenOnPage(id, el) {
|
|
79
|
-
if (id === 'forge') return el.classList.contains('forge-open');
|
|
80
|
-
if (id === 'drawer') return el.classList.contains('drawer-open');
|
|
81
|
-
return !el.hidden && el.isConnected;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Brings the model's open sheets in line with the page. A sheet that has just opened beside another of its group displaces it (Work and the node
|
|
86
|
-
* panel take turns): the displaced one is `away` (hidden on a phone, its selection kept) and its owner is told. A sheet that is closed on the page
|
|
87
|
-
* is hidden in the model and is no longer away.
|
|
88
|
-
*/
|
|
89
|
-
function syncShown() {
|
|
90
|
-
if (!isPhone()) { // the sheets are panels from 768px: nothing is displaced and nothing is a stub
|
|
91
|
-
away.clear();
|
|
92
|
-
for (const el of elements.values()) el.removeAttribute('data-sheet-away');
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
for (const [id, el] of elements) {
|
|
96
|
-
const open = isOpenOnPage(id, el) && !away.has(id);
|
|
97
|
-
if (!open && !isOpenOnPage(id, el)) away.delete(id);
|
|
98
|
-
if (open && !model.isShown(id)) {
|
|
99
|
-
for (const gone of model.show(id)) displace(gone);
|
|
100
|
-
} else if (!open && model.isShown(id)) model.hide(id);
|
|
101
|
-
}
|
|
102
|
-
for (const [id, el] of elements) {
|
|
103
|
-
const gone = away.has(id);
|
|
104
|
-
const was = el.hasAttribute('data-sheet-away');
|
|
105
|
-
el.toggleAttribute('data-sheet-away', gone);
|
|
106
|
-
if (gone && !el.inert) el.inert = true; // out of reach of Tab while it is away
|
|
107
|
-
else if (!gone && was && isOpenOnPage(id, el)) el.inert = false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** A sheet displaced by the other of its group: hidden, not closed (the node stays selected); Work is closed by its own code */
|
|
112
|
-
function displace(id) {
|
|
113
|
-
const el = elements.get(id);
|
|
114
|
-
if (!el) return;
|
|
115
|
-
away.add(id);
|
|
116
|
-
const on = options.get(id);
|
|
117
|
-
if (on && on.away) on.away();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** The stub's row: made on first use, shown only in the stub state, with the title and the badge the sheet's owner says */
|
|
121
|
-
function paintStub(id, el, on) {
|
|
122
|
-
let stub = [...el.children].find((c) => c.classList.contains('hx-sheet-stub'));
|
|
123
|
-
if (!stub) {
|
|
124
|
-
if (!on) return;
|
|
125
|
-
stub = document.createElement('button');
|
|
126
|
-
stub.type = 'button';
|
|
127
|
-
stub.className = 'hx-sheet-stub';
|
|
128
|
-
stub.dataset.corn = 'sheet-stub';
|
|
129
|
-
stub.addEventListener('click', (e) => { e.stopPropagation(); e.preventDefault(); expandSheet(id); const h = [...el.children].find((c) => c.classList.contains('hx-sheet-handle')); if (h && isPhone()) h.focus(); });
|
|
130
|
-
el.append(stub);
|
|
131
|
-
}
|
|
132
|
-
stub.hidden = !on;
|
|
133
|
-
if (!on) return;
|
|
134
|
-
const opt = options.get(id);
|
|
135
|
-
const said = (opt && opt.stub ? opt.stub() : null) || { title: el.getAttribute('aria-label') || id };
|
|
136
|
-
const title = String(said.title || '');
|
|
137
|
-
const badge = said.badge ? String(said.badge) : '';
|
|
138
|
-
const key = `${title}\u0000${badge}\u0000${said.label || ''}`;
|
|
139
|
-
if (stub.dataset.key === key) return;
|
|
140
|
-
stub.dataset.key = key;
|
|
141
|
-
stub.replaceChildren();
|
|
142
|
-
const t = document.createElement('span');
|
|
143
|
-
t.className = 'hx-sheet-stub-title';
|
|
144
|
-
t.textContent = title;
|
|
145
|
-
stub.append(t);
|
|
146
|
-
if (badge) {
|
|
147
|
-
const b = document.createElement('span');
|
|
148
|
-
b.className = 'hx-waiting-badge';
|
|
149
|
-
b.dataset.corn = 'waiting-badge';
|
|
150
|
-
b.setAttribute('aria-hidden', 'true');
|
|
151
|
-
b.textContent = badge;
|
|
152
|
-
stub.append(b);
|
|
153
|
-
}
|
|
154
|
-
stub.setAttribute('aria-label', said.label || (badge ? `${title}, ${badge}` : title));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** Says a stub's words may have changed (the number waiting, a proposal's title): drawn again, if it is showing */
|
|
158
|
-
export function refreshStubs() {
|
|
159
|
-
for (const [id, el] of elements) if (model.stateOf(id) === 'stub') paintStub(id, el, true);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Opens a sheet's place in the dock without expanding it (Work opens as a peek, a node panel opens as a peek): the other sheet of its group is
|
|
164
|
-
* displaced, and this one is no longer away. Called by what opens a sheet (the node panel's code); the Work panel's open class is seen too.
|
|
165
|
-
*/
|
|
166
|
-
export function showSheet(id) {
|
|
167
|
-
if (!elements.has(id)) return;
|
|
168
|
-
away.delete(id);
|
|
169
|
-
apply();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** The lowest visible sheet gets `data-sheet-last`: it carries the bottom safe-area inset */
|
|
173
|
-
function markLast() {
|
|
174
|
-
if (!dock) return;
|
|
175
|
-
let last = null;
|
|
176
|
-
for (const child of dock.children) {
|
|
177
|
-
child.removeAttribute('data-sheet-last');
|
|
178
|
-
const closed = (child.classList.contains('hx-drawer') && !child.classList.contains('drawer-open')) || (child.classList.contains('hx-forge') && !child.classList.contains('forge-open'));
|
|
179
|
-
if (!child.hidden && !closed) last = child;
|
|
180
|
-
}
|
|
181
|
-
if (last) last.setAttribute('data-sheet-last', '');
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* The height of the map the sheets hide, in px: the dock's height on a phone, 0 anywhere else.
|
|
186
|
-
* Also written to `state.coveredBottom` and to `--hx-covered` on the stage. Without a dock on the
|
|
187
|
-
* page it returns what `state.coveredBottom` holds.
|
|
188
|
-
*/
|
|
189
|
-
export function measureCovered() {
|
|
190
|
-
if (!dock || !dock.isConnected) return state.coveredBottom || 0;
|
|
191
|
-
const covered = isPhone() ? Math.round(dock.offsetHeight || 0) : 0;
|
|
192
|
-
state.coveredBottom = covered;
|
|
193
|
-
const stage = stageOf();
|
|
194
|
-
if (stage) stage.style.setProperty('--hx-covered', `${covered}px`);
|
|
195
|
-
if (covered !== lastCovered) {
|
|
196
|
-
lastCovered = covered;
|
|
197
|
-
listeners.forEach((fn) => fn());
|
|
198
|
-
}
|
|
199
|
-
return covered;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* The part of the map nothing covers, in the canvas's own CSS px: what the camera should frame a node into.
|
|
204
|
-
* On a phone the dock's sheets cover the bottom; from 768px the proposal bar covers the top (and the change list it grows to hold),
|
|
205
|
-
* the node panel the right, the Work panel and the review column the left and the scenario player the bottom. Without a layout (no page) it is the whole canvas.
|
|
206
|
-
* @returns {{ x: number, y: number, width: number, height: number }}
|
|
4
|
+
* A bridge (spec 0011 D2, step 4): the phone's bottom sheets now live in engine/sheets.js, one set per instance (the node panel registers its
|
|
5
|
+
* own, pieces/node-panel.js). This file keeps the old names for the modules that are not yet on an instance (the proposal bar, the review
|
|
6
|
+
* column, the Work panel, the scenario player, deep links, the House), bound to the page's instance, and registers the proposal bar's sheet,
|
|
7
|
+
* which is not a piece yet. It goes when the last of them is converted.
|
|
207
8
|
*/
|
|
208
|
-
export function visibleMapRect() {
|
|
209
|
-
const covers = { top: 0, bottom: 0, left: 0, right: 0 };
|
|
210
|
-
const canvas = state.canvas;
|
|
211
|
-
const shown = (el) => !!el && !el.hidden && el.isConnected;
|
|
212
|
-
if (isPhone()) covers.bottom = measureCovered() + 8;
|
|
213
|
-
else if (canvas && typeof canvas.getBoundingClientRect === 'function') {
|
|
214
|
-
const c = canvas.getBoundingClientRect();
|
|
215
|
-
const bar = $('proposal-bar');
|
|
216
|
-
if (shown(bar)) covers.top = Math.max(0, bar.getBoundingClientRect().bottom - c.top) + 8;
|
|
217
|
-
const drawer = $('spec-drawer');
|
|
218
|
-
if (shown(drawer) && drawer.classList.contains('drawer-open')) covers.right = drawer.offsetWidth; // its width, not its box: it slides in
|
|
219
|
-
const forge = $('forge-panel');
|
|
220
|
-
if (shown(forge) && forge.classList.contains('forge-open')) covers.left = forge.offsetWidth;
|
|
221
|
-
// the review column (review-column.js) is docked on the left under the bar: its right edge is what it covers, past the Work panel's when both are open
|
|
222
|
-
const column = $('review-column');
|
|
223
|
-
if (shown(column)) covers.left = Math.max(covers.left, Math.max(0, column.getBoundingClientRect().right - c.left) + 8);
|
|
224
|
-
const player = document.querySelector('.hx-player');
|
|
225
|
-
if (shown(player)) covers.bottom = Math.max(0, c.bottom - player.getBoundingClientRect().top) + 8;
|
|
226
|
-
}
|
|
227
|
-
return freeRect(state.width || 0, state.height || 0, covers);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// ---------------------------------------------------------------------------
|
|
231
|
-
// Registering and changing sheets
|
|
232
|
-
// ---------------------------------------------------------------------------
|
|
233
|
-
|
|
234
|
-
/** Makes `el` a sheet called `id` (a peek until expanded) and gives it a handle if it has none */
|
|
235
|
-
export function registerSheet(id, el, opts = {}) {
|
|
236
|
-
if (!el) return;
|
|
237
|
-
unregisterSheet(id, false);
|
|
238
|
-
model.add(id);
|
|
239
|
-
elements.set(id, el);
|
|
240
|
-
options.set(id, opts);
|
|
241
|
-
el.classList.add('hx-sheet');
|
|
242
|
-
let handle = [...el.children].find((c) => c.classList.contains('hx-sheet-handle'));
|
|
243
|
-
if (!handle) {
|
|
244
|
-
handle = document.createElement('button');
|
|
245
|
-
handle.type = 'button';
|
|
246
|
-
handle.className = 'hx-sheet-handle';
|
|
247
|
-
handle.dataset.corn = 'sheet-handle';
|
|
248
|
-
handle.innerHTML = '<span data-corn="sheet-grip"></span>';
|
|
249
|
-
el.prepend(handle);
|
|
250
|
-
}
|
|
251
|
-
if (wiredAs.get(handle) !== id) { wiredAs.set(handle, id); bindHandle(id, handle); } // registered again (a re-init): one listener, or a tap toggles twice
|
|
252
|
-
if (wiredAs.get(el) !== id) { wiredAs.set(el, id); el.addEventListener('click', (e) => peekClick(id, e), true); }
|
|
253
|
-
apply();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** Forgets a sheet (the player closing); `redraw` false while it is only being replaced */
|
|
257
|
-
export function unregisterSheet(id, redraw = true) {
|
|
258
|
-
if (!model.has(id)) return;
|
|
259
|
-
model.remove(id);
|
|
260
|
-
elements.delete(id);
|
|
261
|
-
options.delete(id);
|
|
262
|
-
away.delete(id);
|
|
263
|
-
if (redraw) apply();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export function expandSheet(id) { syncShown(); if (model.expand(id)) apply(); } // what is open on the page is known first (a bar shown a moment ago)
|
|
267
|
-
export function collapseSheet(id) { if (model.collapse(id)) apply(); }
|
|
268
|
-
export function collapseAllSheets() { if (model.collapseAll()) apply(); }
|
|
269
|
-
export function toggleSheet(id) { syncShown(); if (model.toggle(id)) apply(); } // the same: a bar shown since the last change is open
|
|
270
|
-
|
|
271
|
-
// ---------------------------------------------------------------------------
|
|
272
|
-
// Taps and swipes
|
|
273
|
-
// ---------------------------------------------------------------------------
|
|
274
|
-
|
|
275
|
-
/** The handle: a tap toggles, a swipe up expands, a swipe down collapses */
|
|
276
|
-
function bindHandle(id, handle) {
|
|
277
|
-
let startY = null;
|
|
278
|
-
let swiped = false;
|
|
279
|
-
handle.addEventListener('pointerdown', (e) => {
|
|
280
|
-
startY = e.clientY;
|
|
281
|
-
swiped = false;
|
|
282
|
-
if (handle.setPointerCapture && e.pointerId !== undefined) { try { handle.setPointerCapture(e.pointerId); } catch { /* a synthetic event has no pointer to capture */ } }
|
|
283
|
-
});
|
|
284
|
-
const end = (e) => {
|
|
285
|
-
if (startY === null) return;
|
|
286
|
-
const dy = e.clientY - startY;
|
|
287
|
-
startY = null;
|
|
288
|
-
if (Math.abs(dy) < SWIPE_PX) return;
|
|
289
|
-
swiped = true;
|
|
290
|
-
if (dy < 0) expandSheet(id); else collapseSheet(id);
|
|
291
|
-
};
|
|
292
|
-
handle.addEventListener('pointerup', end);
|
|
293
|
-
handle.addEventListener('pointercancel', () => { startY = null; });
|
|
294
|
-
handle.addEventListener('click', (e) => {
|
|
295
|
-
e.stopPropagation(); // not a tap on the sheet itself (peekClick)
|
|
296
|
-
if (swiped) { swiped = false; return; }
|
|
297
|
-
toggleSheet(id);
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/** A peek sheet expands on a tap anywhere on it, except on its Close button (which still closes) */
|
|
302
|
-
function peekClick(id, e) {
|
|
303
|
-
if (!isPhone() || model.isExpanded(id)) return;
|
|
304
|
-
const target = e.target;
|
|
305
|
-
if (target.closest && target.closest('.hx-sheet-handle, .hx-sheet-stub')) return; // the handle's own listener, and the stub's (it swaps, and takes the focus to the handle)
|
|
306
|
-
if (target.closest && target.closest('select, input, textarea, [data-peek-ok]')) return; // the speed menu, and the proposal's Send back, Approve and mode switcher, work from the peek
|
|
307
|
-
const action = target.closest && target.closest('[data-action]');
|
|
308
|
-
if (action && /close/.test(action.dataset.action)) return;
|
|
309
|
-
e.preventDefault();
|
|
310
|
-
e.stopPropagation();
|
|
311
|
-
expandSheet(id);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/** A touch or click on the map collapses the expanded sheet */
|
|
315
|
-
function onMapDown(e) {
|
|
316
|
-
if (e.target === state.canvas && isPhone()) collapseAllSheets();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/** Escape in an expanded sheet folds it to a peek; Escape in a peek is the sheet's own (it closes it): "folds, then closes" (spec 0010 D7) */
|
|
320
|
-
function onEscape(e) {
|
|
321
|
-
if (e.key !== 'Escape' || e.defaultPrevented || !isPhone()) return;
|
|
322
|
-
const id = model.expanded();
|
|
323
|
-
const el = id && elements.get(id);
|
|
324
|
-
if (!el || !el.contains(e.target)) return;
|
|
325
|
-
if (e.target.closest && e.target.closest('select, input, textarea')) return; // a field's own Escape first
|
|
326
|
-
e.preventDefault();
|
|
327
|
-
e.stopPropagation();
|
|
328
|
-
collapseSheet(id);
|
|
329
|
-
const handle = [...el.children].find((c) => c.classList.contains('hx-sheet-handle'));
|
|
330
|
-
if (handle) handle.focus();
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/** The dim layer behind an expanded node panel: a tap there collapses the panel to its peek (it no longer closes it) */
|
|
334
|
-
function onBackdrop(e) {
|
|
335
|
-
if (!isPhone()) return;
|
|
336
|
-
e.stopPropagation();
|
|
337
|
-
collapseAllSheets();
|
|
338
|
-
}
|
|
339
9
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
10
|
+
import { pageInstance } from './state.js';
|
|
11
|
+
import { ensurePagePieces } from './page-pieces.js';
|
|
12
|
+
import * as S from './engine/sheets.js';
|
|
13
|
+
|
|
14
|
+
export { PHONE_QUERY } from './engine/sheets.js';
|
|
15
|
+
|
|
16
|
+
const page = () => pageInstance();
|
|
17
|
+
export const isPhone = () => S.isPhone(page());
|
|
18
|
+
export const sheetState = (id) => S.sheetState(page(), id);
|
|
19
|
+
export const expandedSheet = () => S.expandedSheet(page());
|
|
20
|
+
export const onCoveredChange = (fn) => S.onCoveredChange(page(), fn);
|
|
21
|
+
export const refreshStubs = () => S.refreshStubs(page());
|
|
22
|
+
export const showSheet = (id) => S.showSheet(page(), id);
|
|
23
|
+
export const measureCovered = () => S.measureCovered(page());
|
|
24
|
+
export const visibleMapRect = () => S.visibleMapRect(page());
|
|
25
|
+
export const registerSheet = (id, el, opts) => S.registerSheet(page(), id, el, opts);
|
|
26
|
+
export const unregisterSheet = (id, redraw) => S.unregisterSheet(page(), id, redraw);
|
|
27
|
+
export const expandSheet = (id) => S.expandSheet(page(), id);
|
|
28
|
+
export const collapseSheet = (id) => S.collapseSheet(page(), id);
|
|
29
|
+
export const collapseAllSheets = () => S.collapseAllSheets(page());
|
|
30
|
+
export const toggleSheet = (id) => S.toggleSheet(page(), id);
|
|
31
|
+
|
|
32
|
+
/** Watches the page's dock and registers the proposal bar's sheet (the node panel registers its own as it mounts) */
|
|
345
33
|
export function initSheets() {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
if
|
|
349
|
-
|
|
350
|
-
observers.forEach((o) => o.disconnect());
|
|
351
|
-
observers = [];
|
|
352
|
-
model.ids().forEach((id) => model.remove(id));
|
|
353
|
-
elements.clear();
|
|
354
|
-
options.clear();
|
|
355
|
-
away.clear();
|
|
356
|
-
lastCovered = 0;
|
|
357
|
-
dock = found;
|
|
358
|
-
}
|
|
359
|
-
registerSheet('proposal', $('proposal-bar'), { stub: () => ({ title: ($('proposal-title') && $('proposal-title').textContent) || 'Proposal' }) });
|
|
360
|
-
registerSheet('drawer', $('spec-drawer'), { stub: () => ({ title: ($('drawer-title') && $('drawer-title').textContent) || 'Node' }) });
|
|
361
|
-
if (wiredDock !== dock) {
|
|
362
|
-
wiredDock = dock;
|
|
363
|
-
const backdrop = $('drawer-backdrop');
|
|
364
|
-
if (backdrop) backdrop.addEventListener('click', onBackdrop, true);
|
|
365
|
-
if (typeof MutationObserver === 'function') {
|
|
366
|
-
const mo = new MutationObserver(() => { markLast(); measureCovered(); });
|
|
367
|
-
mo.observe(dock, { childList: true, subtree: true, attributes: true, attributeFilter: ['hidden', 'class'] });
|
|
368
|
-
observers.push(mo);
|
|
369
|
-
}
|
|
370
|
-
if (typeof ResizeObserver === 'function') {
|
|
371
|
-
const ro = new ResizeObserver(() => measureCovered());
|
|
372
|
-
ro.observe(dock);
|
|
373
|
-
observers.push(ro);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (!documentWired) {
|
|
377
|
-
documentWired = true;
|
|
378
|
-
for (const type of ['pointerdown', 'touchstart', 'mousedown']) document.addEventListener(type, onMapDown, { passive: true, capture: true });
|
|
379
|
-
document.addEventListener('keydown', onEscape, true);
|
|
380
|
-
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
|
|
381
|
-
const mq = window.matchMedia(PHONE_QUERY);
|
|
382
|
-
if (mq && mq.addEventListener) mq.addEventListener('change', () => { collapseAllSheets(); measureCovered(); });
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
apply();
|
|
34
|
+
const inst = page();
|
|
35
|
+
S.initSheets(inst);
|
|
36
|
+
ensurePagePieces(); // the node panel's sheet, if the page has its place
|
|
37
|
+
S.registerSheet(inst, 'proposal', inst.el('proposal-bar'), { stub: () => ({ title: (inst.el('proposal-title') && inst.el('proposal-title').textContent) || 'Proposal' }) });
|
|
386
38
|
}
|
package/explorer/state.js
CHANGED
|
@@ -1,191 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/state
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The hand-over from the one shared state to instances (spec 0011 D2). The explorer used to be one program per document with one shared,
|
|
5
|
+
* mutable `state`; it now runs as an instance (instance.js), and cornfield's page makes exactly one (page.js). The modules that are on an
|
|
6
|
+
* instance take it as an argument and import nothing from here. The ones that are not yet keep importing this file and work as they did:
|
|
7
|
+
*
|
|
8
|
+
* `state` the page instance's state object (the same object: `pageInstance().state === state`)
|
|
9
|
+
* `touchScene`, `onSceneTouch`, `viewEdges`, `nodeById`, `nameOf` the page instance's, under their old names
|
|
10
|
+
* `pageInstance()` the page's instance, for a module that is being converted (or a bridge, explorer/render.js, map-style.js, layout.js);
|
|
11
|
+
* `startPageInstance()` is page.js's one call that claims it
|
|
12
|
+
*
|
|
13
|
+
* To convert a module: take `inst` as an argument (or from the piece that mounts it), read `inst.state`, call `inst.touchScene()`, find elements
|
|
14
|
+
* with `inst.el(id)`, listen with `inst.listen(root, ...)`, and drop the import of this file; add it to the converted list of
|
|
15
|
+
* test/explorer/instance-tripwires.test.js. When no module imports a bridge or this file any more, delete them.
|
|
7
16
|
*/
|
|
8
17
|
|
|
9
|
-
// The one escaper: the server serves this file (core/text.js), beside the explorer's own
|
|
10
18
|
import { escapeHtml } from '../core/text.js';
|
|
19
|
+
import { createInstance } from './instance.js';
|
|
20
|
+
import { createState } from './instance-state.js';
|
|
21
|
+
import { pageStrings } from './strings.js';
|
|
11
22
|
|
|
12
|
-
/** The
|
|
13
|
-
export const state =
|
|
14
|
-
canvas: /** @type {HTMLCanvasElement|null} */ (null),
|
|
15
|
-
ctx: /** @type {CanvasRenderingContext2D|null} */ (null),
|
|
16
|
-
/** The transparent canvas stacked over `canvas` that draws every label (labels.js); null = no labels */
|
|
17
|
-
labelCanvas: /** @type {HTMLCanvasElement|null} */ (null),
|
|
18
|
-
width: 0,
|
|
19
|
-
height: 0,
|
|
20
|
-
/** Height (px) of the bottom of the map the phone's sheets cover (sheets.js); 0 on a desktop. The fit and the scenario camera leave it out. */
|
|
21
|
-
coveredBottom: 0,
|
|
22
|
-
|
|
23
|
-
/** topology.json: every node has x/y assigned by layout.js (the file stores no positions) */
|
|
24
|
-
nodes: [],
|
|
25
|
-
edges: [],
|
|
26
|
-
|
|
27
|
-
/** 'orbit' (the whole map), 'dataflow' (the preset: browser -> servers -> API -> tables -> services -> outside) or 'house' (the House preset, PHY-11) */
|
|
28
|
-
view: 'orbit',
|
|
29
|
-
/** What the data-flow preset shows, built by flows.js buildDataFlow() when the topology loads */
|
|
30
|
-
flow: null,
|
|
31
|
-
/** The orbital rings layout.js drew the positions on */
|
|
32
|
-
rings: { rings: [], clusters: [] },
|
|
33
|
-
|
|
34
|
-
/** 'dark' or 'light': the ground the map is drawn for (theme.js keeps it, from the system and the toggle); a change must `touchScene()` */
|
|
35
|
-
theme: 'dark',
|
|
36
|
-
|
|
37
|
-
camera: { x: 0, y: 0, zoom: 1 },
|
|
38
|
-
selectedNode: null,
|
|
39
|
-
/** The node panel's "Include its children's lines" switch (spec 0008 D5): off, a selection lights one hop; on, the children's neighbours too. Kept across selections */
|
|
40
|
-
throughChildren: false,
|
|
41
|
-
/** The edge kind the panel chose to light alone (selection-model.js), or null for every kind; a new selection clears it */
|
|
42
|
-
selectedKind: null,
|
|
43
|
-
/** The config's `forge` (`{ type, url, repo, baseBranch? }`), or null: where a node's file is opened (file-url.js) */
|
|
44
|
-
forge: null,
|
|
45
|
-
searchQuery: '',
|
|
46
|
-
/** The id of the search match the stepping is on (search.js), or null: the map draws its halo and places its label first of the matches */
|
|
47
|
-
searchCurrent: null,
|
|
48
|
-
/** The id of the node the pointer is on (input.js): a node with no label is named by a chip while it is */
|
|
49
|
-
hoverNodeId: null,
|
|
50
|
-
|
|
51
|
-
isFreeform: false,
|
|
52
|
-
freeformPositions: {},
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Layer key -> on. The infra layer is its own view, so it starts off, and so do the physical world's
|
|
56
|
-
* (spec 0029): machines, containers, devices, the house and people. Turning one of the live ones on
|
|
57
|
-
* (live-model.js LIVE_LAYERS) is what first loads the live layer.
|
|
58
|
-
*/
|
|
59
|
-
activeLayers: {
|
|
60
|
-
app: true, pkg: true, page: true, atom: true, molecule: true, token: true, tool: true,
|
|
61
|
-
flow: true, table: true, rom: true, service: true, cloud: true, web: true, stack: false,
|
|
62
|
-
machine: false, container: false, device: false, house: false, persona: false,
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The project's own layers (spec 0009): `{ key, label, desc?, match }` in `add` order, as the config sent them (core/layers.js); a node is
|
|
67
|
-
* in the first one whose match it meets (explorer/layer-model.js). `layerOrder` is the config's `order`; `layerDefaults` what each layer is
|
|
68
|
-
* when the viewer has not touched it (layers.js `setProjectLayers`). Empty with no `layers` in the config: the menu is then the starting set.
|
|
69
|
-
*/
|
|
70
|
-
projectLayers: [],
|
|
71
|
-
layerOrder: [],
|
|
72
|
-
layerDefaults: {},
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The review of the open proposal, which narrows the map to the change (issue #232; explorer/layer-model.js `layersOf`): null with no proposal open,
|
|
76
|
-
* else `{ whole, manual, step, rev }`. `whole`: "Show the whole map" is on, the map is as Diff always was. `manual`: layers the reviewer turned on or
|
|
77
|
-
* off by hand in this review, `step`: the ones a playing scenario turned on (both `{ key: boolean }`). `rev` moves with each change.
|
|
78
|
-
* None of it is the viewer's: `activeLayers` and the saved choices (layers.js) are never written while it is set.
|
|
79
|
-
*/
|
|
80
|
-
review: null,
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The map as the last `setMap` (view.js) was handed it, before the live layer is laid in: the base
|
|
84
|
-
* copies, or a proposal applied over them. `nodes` and `edges` are these plus the live ones.
|
|
85
|
-
*/
|
|
86
|
-
mapNodes: [],
|
|
87
|
-
mapEdges: [],
|
|
23
|
+
/** The page's state: one object, made at import time so a module that reads it while it loads finds it filled */
|
|
24
|
+
export const state = createState();
|
|
88
25
|
|
|
89
|
-
|
|
90
|
-
* The live layer (live.js, spec 0029 section 4), in memory only and never stored anywhere: the
|
|
91
|
-
* runner's snapshot `{ status, answer, error, lastOkAt }` and what merging it found: `counts`
|
|
92
|
-
* (persona id -> accounts), `other` (accounts no persona counts), `linked` (node id -> its
|
|
93
|
-
* inventory item). null until a live layer is first turned on.
|
|
94
|
-
*/
|
|
95
|
-
live: null,
|
|
26
|
+
let page = null;
|
|
96
27
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
baseNodes: [],
|
|
110
|
-
baseEdges: [],
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The proposal open on the map (proposal.js, spec 0012 B2): the parsed file or null. While it is
|
|
114
|
-
* set, `nodes` and `edges` are `applyProposal(base, proposal)`: each carries `mark` (and `before`,
|
|
115
|
-
* `why` when changed or removed). `proposalView` is what scene.js shows of that: 'before' | 'diff' |
|
|
116
|
-
* 'after'. `proposalSource` is where it was found ('checkout' or a worktree name), `proposalSlug` its
|
|
117
|
-
* file name without `.json`, `proposalErrors` what `validateProposal` found against the base.
|
|
118
|
-
*/
|
|
119
|
-
proposal: null,
|
|
120
|
-
proposalView: 'diff',
|
|
121
|
-
proposalSource: null,
|
|
122
|
-
/** The open proposal's file as the server sent it, its SHA-256 (X-Proposal-Sha256), or null: a review names it, so a push since is refused (spec 0007) */
|
|
123
|
-
proposalSha256: null,
|
|
124
|
-
proposalSlug: null,
|
|
125
|
-
proposalErrors: [],
|
|
126
|
-
/** Where each of the open proposal's mockups stands with the review, by position: 'approved' | 'changed' | 'unreviewed' | 'missing' (mockups.js; none read yet is empty) */
|
|
127
|
-
mockupStates: {},
|
|
128
|
-
/**
|
|
129
|
-
* The proposal the map is drawn from: `proposal` with what-if edits folded in (whatif.js, TOPO-11), or `proposal` itself
|
|
130
|
-
* when there are none; null with no proposal open. `proposal` is never changed: it is the robot's file.
|
|
131
|
-
*/
|
|
132
|
-
effectiveProposal: null,
|
|
133
|
-
/** The maintainer's what-if edits to the open proposal, and what Undo took back (whatif-model.js): `{ edits, undone }` */
|
|
134
|
-
whatIf: { edits: [], undone: [] },
|
|
135
|
-
/** The My edits toggle is off: the map is drawn from the proposal as written, the edits are kept and still go with a review (whatif.js, spec 0007 D5) */
|
|
136
|
-
whatIfOff: false,
|
|
137
|
-
/** A marked edge picked on the map (nodes are `selectedNode`): the panel shows it, the scene does not change */
|
|
138
|
-
selectedEdge: null,
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The scenario being played on the map: the player's snapshot (scenario.js `ScenarioSnapshot`:
|
|
142
|
-
* index, playing, done, visited, current, progress ...) or null. The ROM simulation's walk is one.
|
|
143
|
-
* scenario-ui.js owns it; scene.js lights it, and an outage's `down` its blast radius (outage-model.js).
|
|
144
|
-
*/
|
|
145
|
-
scenario: null,
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* What the selected pull request lights (forge-panel.js, forge-panel-model.js `litFor`): `{ changed, failing }`, sets of
|
|
149
|
-
* node ids (the nodes its files are; the nodes of the tests a failing check names), or null with none selected.
|
|
150
|
-
*/
|
|
151
|
-
forgeLit: null,
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* The runs on the map (explorer/runs-map.js): `{ flight: Map<nodeId, runId[]>, collide: Map<nodeId, runId[]>, runs }` for the open runs'
|
|
155
|
-
* nodes, or null when there are none. The map's marks over the nodes are drawn from it.
|
|
156
|
-
*/
|
|
157
|
-
runsMap: null,
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Which threads mention which nodes (forge-panel.js, docs/threads.md), for a node's panel: `{ for(nodeId) -> thread[] | null,
|
|
161
|
-
* ensure(), open(number) }`, or null when threads are off or there is no forge. `for` answers null until the list has been
|
|
162
|
-
* read; `ensure` reads it (once) and repaints the panel's "Threads"; `open` shows a thread in the issues and PRs panel.
|
|
163
|
-
*/
|
|
164
|
-
threadIndex: null,
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Changes whenever anything the scene is built from changes (scene.js). render.js rebuilds the
|
|
168
|
-
* scene only when this moved: never for a camera change or a packet frame.
|
|
169
|
-
*/
|
|
170
|
-
sceneVersion: 0,
|
|
171
|
-
};
|
|
28
|
+
/**
|
|
29
|
+
* The page's instance. It is made the first time anything asks, because modules that are not yet converted register with it while they load
|
|
30
|
+
* (layers.js follows the map's style), before page.js has run. A test that drives one module on its own gets the same plain instance over the
|
|
31
|
+
* global document, if there is one, holding the same `state`.
|
|
32
|
+
*/
|
|
33
|
+
export function pageInstance() {
|
|
34
|
+
if (!page) {
|
|
35
|
+
page = createInstance({ state, root: typeof document !== 'undefined' ? document : null });
|
|
36
|
+
page.strings = pageStrings; // the page's words are the bridge's (strings.js), one object for the modules on an instance and the ones not yet
|
|
37
|
+
}
|
|
38
|
+
return page;
|
|
39
|
+
}
|
|
172
40
|
|
|
173
41
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* later a proposal. Not for the camera, and not for time.
|
|
42
|
+
* Called once by page.js: the instance of this document. There is only ever one (`pageInstance()` above), made with the defaults cornfield's page
|
|
43
|
+
* wants (its own origin, the global fetch, no strings of a host's); this hands it over, and does not make a second.
|
|
177
44
|
*/
|
|
178
|
-
export function
|
|
179
|
-
|
|
180
|
-
|
|
45
|
+
export function startPageInstance({ root }) {
|
|
46
|
+
const inst = pageInstance();
|
|
47
|
+
if (root !== inst.root) throw new Error('The page instance is over the document it was first asked for');
|
|
48
|
+
return inst;
|
|
181
49
|
}
|
|
182
50
|
|
|
183
|
-
const
|
|
51
|
+
export const touchScene = () => pageInstance().touchScene();
|
|
184
52
|
/** Calls `fn` after every touchScene(): for UI that follows what the scene is built from (the scenario list follows `state.proposal`). Returns how to stop. */
|
|
185
|
-
export
|
|
186
|
-
sceneListeners.add(fn);
|
|
187
|
-
return () => sceneListeners.delete(fn);
|
|
188
|
-
}
|
|
53
|
+
export const onSceneTouch = (fn) => pageInstance().onSceneTouch(fn);
|
|
189
54
|
|
|
190
55
|
/** The edges the current view draws and the selection walks */
|
|
191
56
|
export function viewEdges() {
|