@graview/pages 0.1.74 → 0.2.1
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/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +11 -1
- package/dist/context-menu.js.map +1 -1
- package/dist/face-controls.d.ts.map +1 -1
- package/dist/face-controls.js +17 -2
- package/dist/face-controls.js.map +1 -1
- package/dist/held-element.d.ts +12 -0
- package/dist/held-element.d.ts.map +1 -0
- package/dist/held-element.js +90 -0
- package/dist/held-element.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/one-place-city.d.ts +9 -0
- package/dist/one-place-city.d.ts.map +1 -0
- package/dist/one-place-city.js +1892 -0
- package/dist/one-place-city.js.map +1 -0
- package/dist/one-place-control.d.ts +37 -0
- package/dist/one-place-control.d.ts.map +1 -0
- package/dist/one-place-control.js +14 -0
- package/dist/one-place-control.js.map +1 -0
- package/dist/one-place-geometry.d.ts +297 -0
- package/dist/one-place-geometry.d.ts.map +1 -0
- package/dist/one-place-geometry.js +532 -0
- package/dist/one-place-geometry.js.map +1 -0
- package/dist/one-place-signs.d.ts +59 -0
- package/dist/one-place-signs.d.ts.map +1 -0
- package/dist/one-place-signs.js +358 -0
- package/dist/one-place-signs.js.map +1 -0
- package/dist/one-place.d.ts +87 -0
- package/dist/one-place.d.ts.map +1 -0
- package/dist/one-place.js +1325 -0
- package/dist/one-place.js.map +1 -0
- package/dist/page-context.d.ts +28 -0
- package/dist/page-context.d.ts.map +1 -1
- package/dist/page-context.js +3 -0
- package/dist/page-context.js.map +1 -1
- package/dist/page-problems.d.ts.map +1 -1
- package/dist/page-problems.js +18 -6
- package/dist/page-problems.js.map +1 -1
- package/dist/page-record.d.ts.map +1 -1
- package/dist/page-record.js +3 -1
- package/dist/page-record.js.map +1 -1
- package/dist/page-search.d.ts.map +1 -1
- package/dist/page-search.js +32 -4
- package/dist/page-search.js.map +1 -1
- package/dist/page-shell.d.ts.map +1 -1
- package/dist/page-shell.js +72 -11
- package/dist/page-shell.js.map +1 -1
- package/dist/page-typography.d.ts.map +1 -1
- package/dist/page-typography.js +3 -2
- package/dist/page-typography.js.map +1 -1
- package/dist/router.d.ts +2 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +69 -3
- package/dist/router.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,1325 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { LOCAL_LAYERS, OVERVIEW_PATH, ONE_FACE_LAYERS, counted, hueFor, labelOf } from "@graview/core";
|
|
3
|
+
import { RECORD_BOXES_ATTRIBUTE, RECORD_BOXES_MOVED, recordBoxesOf } from "@graview/core/record-boxes";
|
|
4
|
+
import { retryingImport } from "@graview/core/retry";
|
|
5
|
+
import { barPlaces, HOME_KEY, PastBar } from "@graview/primitives/pages";
|
|
6
|
+
import { lazyPart, useGraview, usePlayback } from "@graview/react/provider";
|
|
7
|
+
import { Suspense, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { useHref, useLocation, useNavigate } from "react-router";
|
|
9
|
+
import { recordFacts } from "./facts.js";
|
|
10
|
+
import { useStoreTick } from "./page-context.js";
|
|
11
|
+
import { pluralOf } from "./page-typography.js";
|
|
12
|
+
import { kindOfSlug, recordPath, pluralSlug } from "./registry.js";
|
|
13
|
+
import { OneFaceContext } from "./one-place-control.js";
|
|
14
|
+
import { HeldHere } from "./held-element.js";
|
|
15
|
+
import { BOARD_ASPECT, boardFaceWidth, frameSpacing, smallWindow, CITY, LEVEL_NAMES, nearestThatWay, PAGE, PANEL, panelBox, panelRange, panelStoreKey, PHONE } from "./one-place-geometry.js";
|
|
16
|
+
/**
|
|
17
|
+
* PAGES AND THE SCENE ARE ONE PLACE (Graview HQ feature:f-page-zooms-out-to-the-city).
|
|
18
|
+
*
|
|
19
|
+
* The routed page is read over the Scene's own city — the `Scene` of
|
|
20
|
+
* `@graview/react`, mounted underneath in the same provider the pages draw
|
|
21
|
+
* with — and altitude is the Scene's own camera. There is one face: no
|
|
22
|
+
* switch between a scene and the pages, and no record "drive-in" of the
|
|
23
|
+
* Scene's own. The page the person is reading is the one element that
|
|
24
|
+
* moves, continuously, every step drawn:
|
|
25
|
+
*
|
|
26
|
+
* - L0, THE PAGE: the routed page, the whole window; the city not seen.
|
|
27
|
+
* - L1, BESIDE THE CITY: the same page, its box narrowed to a column beside
|
|
28
|
+
* the city (a sheet from the foot on a phone), the camera pulled back to
|
|
29
|
+
* its place, and a Connected list grown into its foot — what the record
|
|
30
|
+
* is linked to, each row with a line to its building.
|
|
31
|
+
* - L2, THE CITY: every page and view of the app a board standing on its
|
|
32
|
+
* place — the home, each kind's list, each lens — and this page among
|
|
33
|
+
* them, shrunk into its own board. Choosing a board (a press, Enter, or
|
|
34
|
+
* the button that comes down) comes down to that page beside the city.
|
|
35
|
+
*
|
|
36
|
+
* One button at the window's bottom left rises and comes down a level and
|
|
37
|
+
* says which level this is; Alt and the arrows, and Escape for down, do the
|
|
38
|
+
* same from the keyboard; a pinch or ctrl and the wheel over the page beside
|
|
39
|
+
* the city scrub the camera, and the page with it, as far as the hand goes,
|
|
40
|
+
* settling to the nearest level when let go. Over the city, at Nearby and
|
|
41
|
+
* the City, a pinch zooms the camera and a drag pans it, and the level
|
|
42
|
+
* stays. The address is the page's
|
|
43
|
+
* route at every level, so Back and Forward work.
|
|
44
|
+
*
|
|
45
|
+
* The city's part (`one-place-city.tsx`) — the Scene, the camera, the
|
|
46
|
+
* lines, the boards' places — is fetched as the page first draws.
|
|
47
|
+
*/
|
|
48
|
+
const OnePlaceCity = lazyPart(retryingImport(() => import("./one-place-city.js").then((module) => ({ default: module.OnePlaceCity }))));
|
|
49
|
+
const lessMotion = () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
50
|
+
const windowSize = () => ({ width: document.documentElement.clientWidth || window.innerWidth, height: window.innerHeight });
|
|
51
|
+
/** What the page's address is in the city. */
|
|
52
|
+
function whereOf(schema, has, pathname, placeKinds) {
|
|
53
|
+
if (pathname === OVERVIEW_PATH)
|
|
54
|
+
return { type: "overview" };
|
|
55
|
+
const segments = pathname.split("/").filter(Boolean).map((one) => {
|
|
56
|
+
try {
|
|
57
|
+
return decodeURIComponent(one);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return one;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (segments.length === 0)
|
|
64
|
+
return { type: "home" };
|
|
65
|
+
if (segments[0] === "places" && segments.length === 2) {
|
|
66
|
+
const kinds = placeKinds(segments[1]);
|
|
67
|
+
return kinds.length > 0 ? { type: "place", as: segments[1], kinds } : { type: "home" };
|
|
68
|
+
}
|
|
69
|
+
const kind = kindOfSlug(schema, segments[0]);
|
|
70
|
+
if (kind && segments.length === 1)
|
|
71
|
+
return { type: "list", kind };
|
|
72
|
+
if (kind && segments.length === 2 && has(segments[1]) === kind)
|
|
73
|
+
return { type: "record", id: segments[1], kind };
|
|
74
|
+
return { type: "home" };
|
|
75
|
+
}
|
|
76
|
+
/** The first few names a view of these kinds lists, for its sign. */
|
|
77
|
+
function firstOf(store, kinds) {
|
|
78
|
+
const names = [];
|
|
79
|
+
for (const kind of kinds) {
|
|
80
|
+
for (const node of store.graph.nodesOfKind(kind)) {
|
|
81
|
+
if (names.length >= 3)
|
|
82
|
+
return names;
|
|
83
|
+
names.push(labelOf(store.schema.tryDefinition(kind), node));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return names;
|
|
87
|
+
}
|
|
88
|
+
/** Which board a place is. */
|
|
89
|
+
const boardKeyOf = (where, boards) => {
|
|
90
|
+
if (where.type === "record")
|
|
91
|
+
return `record:${where.id}`;
|
|
92
|
+
const found = boards.find((board) => where.type === "home" || where.type === "overview"
|
|
93
|
+
? board.where.type === "home"
|
|
94
|
+
: where.type === "list"
|
|
95
|
+
? board.where.type === "list" && board.where.kind === where.kind
|
|
96
|
+
: board.where.type === "place" && board.where.as === where.as);
|
|
97
|
+
return found?.key ?? HOME_KEY;
|
|
98
|
+
};
|
|
99
|
+
/*
|
|
100
|
+
* THE CONTROL'S TOOLTIPS, ON INTENT. A pointer passing over shows nothing:
|
|
101
|
+
* a tooltip comes after the pointer has rested on a part for TIP_DELAY_MS,
|
|
102
|
+
* and goes TIP_HIDE_MS after it leaves. Once one has shown, the next part
|
|
103
|
+
* the pointer rests on shows its own at once, for TIP_WARM_MS after the last
|
|
104
|
+
* went (the way along the stops). The keyboard's focus shows it at once; a
|
|
105
|
+
* finger, only a long press.
|
|
106
|
+
*/
|
|
107
|
+
const TIP_DELAY_MS = 600;
|
|
108
|
+
const TIP_HIDE_MS = 100;
|
|
109
|
+
const TIP_WARM_MS = 300;
|
|
110
|
+
const TIP_PRESS_MS = 500;
|
|
111
|
+
/** When a tooltip of the control was last put away, for the warm window. */
|
|
112
|
+
let tipHiddenAt = -Infinity;
|
|
113
|
+
/** Until when a focus this face put on the control itself (a page with nothing else to take it) shows no tooltip. */
|
|
114
|
+
let quietFocusUntil = -Infinity;
|
|
115
|
+
/** When a pointer last went down: a focus that follows a press is the pointer's, and shows no tooltip. */
|
|
116
|
+
let pressedAt = -Infinity;
|
|
117
|
+
if (typeof document !== "undefined")
|
|
118
|
+
document.addEventListener("pointerdown", () => (pressedAt = performance.now()), { capture: true, passive: true });
|
|
119
|
+
function useIntentTip() {
|
|
120
|
+
const [shown, setShown] = useState(null);
|
|
121
|
+
const showing = useRef(false);
|
|
122
|
+
const timer = useRef(undefined);
|
|
123
|
+
const clear = () => window.clearTimeout(timer.current);
|
|
124
|
+
useEffect(() => clear, []);
|
|
125
|
+
const show = (el, text) => {
|
|
126
|
+
clear();
|
|
127
|
+
const host = el.closest("[data-graview-tip-host]");
|
|
128
|
+
const left = host ? Math.max(0, el.getBoundingClientRect().left - host.getBoundingClientRect().left) : 0;
|
|
129
|
+
showing.current = true;
|
|
130
|
+
setShown({ text, left });
|
|
131
|
+
};
|
|
132
|
+
const hide = (after) => {
|
|
133
|
+
clear();
|
|
134
|
+
const go = () => {
|
|
135
|
+
if (showing.current)
|
|
136
|
+
tipHiddenAt = performance.now();
|
|
137
|
+
showing.current = false;
|
|
138
|
+
setShown(null);
|
|
139
|
+
};
|
|
140
|
+
if (after > 0)
|
|
141
|
+
timer.current = window.setTimeout(go, after);
|
|
142
|
+
else
|
|
143
|
+
go();
|
|
144
|
+
};
|
|
145
|
+
const on = (text) => ({
|
|
146
|
+
onPointerEnter: (event) => {
|
|
147
|
+
if (event.pointerType === "touch")
|
|
148
|
+
return;
|
|
149
|
+
const el = event.currentTarget;
|
|
150
|
+
clear();
|
|
151
|
+
if (showing.current || performance.now() - tipHiddenAt < TIP_WARM_MS)
|
|
152
|
+
show(el, text);
|
|
153
|
+
else
|
|
154
|
+
timer.current = window.setTimeout(() => show(el, text), TIP_DELAY_MS);
|
|
155
|
+
},
|
|
156
|
+
onPointerLeave: (event) => {
|
|
157
|
+
if (event.pointerType !== "touch")
|
|
158
|
+
hide(TIP_HIDE_MS);
|
|
159
|
+
},
|
|
160
|
+
onPointerDown: (event) => {
|
|
161
|
+
if (event.pointerType !== "touch")
|
|
162
|
+
return;
|
|
163
|
+
const el = event.currentTarget;
|
|
164
|
+
clear();
|
|
165
|
+
timer.current = window.setTimeout(() => show(el, text), TIP_PRESS_MS);
|
|
166
|
+
},
|
|
167
|
+
onPointerUp: (event) => {
|
|
168
|
+
// A finger lifted: what a long press showed stays a moment to be read; a tap showed nothing.
|
|
169
|
+
if (event.pointerType === "touch")
|
|
170
|
+
hide(showing.current ? 1500 : 0);
|
|
171
|
+
},
|
|
172
|
+
onPointerCancel: () => hide(0),
|
|
173
|
+
onFocus: (event) => {
|
|
174
|
+
// The keyboard's focus (or one moved there for it), not a press's.
|
|
175
|
+
if (performance.now() < quietFocusUntil)
|
|
176
|
+
return;
|
|
177
|
+
if (event.currentTarget.matches(":focus-visible") || performance.now() - pressedAt > 400)
|
|
178
|
+
show(event.currentTarget, text);
|
|
179
|
+
},
|
|
180
|
+
onBlur: () => hide(0),
|
|
181
|
+
});
|
|
182
|
+
return { shown, on };
|
|
183
|
+
}
|
|
184
|
+
/** The tooltip itself: one for the control, over the part it is about. */
|
|
185
|
+
function Tip({ id, tip, said }) {
|
|
186
|
+
// The level's own tooltip is the description the stop and the slider are given, and says only that; another part's words are shown in one of their own.
|
|
187
|
+
const own = !tip.shown || tip.shown.text === said;
|
|
188
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { id: id, role: "tooltip", "data-graview-one-face-tip": "", "data-graview-shown": tip.shown && own ? "" : undefined, style: { left: tip.shown?.left ?? 0 }, children: said }), _jsx("span", { "aria-hidden": "true", "data-graview-one-face-tip": "", "data-graview-shown": tip.shown && !own ? "" : undefined, style: { left: tip.shown?.left ?? 0 }, children: own ? "" : tip.shown.text })] }));
|
|
189
|
+
}
|
|
190
|
+
/** Where this browser keeps whether the legend is shown beside the city. */
|
|
191
|
+
const LEGEND_KEY = "graview.one-face.legend";
|
|
192
|
+
/** Where this browser keeps whether the control is the three levels or a slider. */
|
|
193
|
+
const CONTROL_KEY = "graview.one-face.control";
|
|
194
|
+
/** The keys that go straight to each level, Page, Nearby and City. */
|
|
195
|
+
const LEVEL_KEYS = ["1", "2", "3"];
|
|
196
|
+
/** Where this browser keeps whether the level's single keys are on (WCAG 2.1.4: they can be turned off). */
|
|
197
|
+
const KEYS_KEY = "graview.one-face.keys";
|
|
198
|
+
const keysOn = () => {
|
|
199
|
+
try {
|
|
200
|
+
return window.localStorage.getItem(KEYS_KEY) !== "off";
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
/** Typing somewhere: the keys are the field's, not the altitude's. */
|
|
207
|
+
const typingIn = (target) => target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement || (target instanceof HTMLElement && target.isContentEditable);
|
|
208
|
+
export function OnePlace({ context, page, onFace, children, }) {
|
|
209
|
+
const { views } = useGraview();
|
|
210
|
+
const store = context.store;
|
|
211
|
+
const schema = store.schema;
|
|
212
|
+
// The views' signs say what their records are now: drawn again as the store changes.
|
|
213
|
+
const tick = useStoreTick(store);
|
|
214
|
+
const location = useLocation();
|
|
215
|
+
const navigate = useNavigate();
|
|
216
|
+
const base = useHref("/").replace(/\/$/, "");
|
|
217
|
+
const address = `${location.pathname}${location.search}`;
|
|
218
|
+
const has = useCallback((id) => store.graph.getNode(id)?.kind, [store]);
|
|
219
|
+
const placeKinds = useCallback((as) => [...new Set(views.places().filter((place) => place.as === as).flatMap((place) => (place.kind ? [place.kind] : [])))], [views]);
|
|
220
|
+
const where = useMemo(() => whereOf(schema, has, location.pathname, placeKinds), [schema, has, location.pathname, placeKinds]);
|
|
221
|
+
const [size, setView] = useState(() => (typeof window === "undefined" ? { width: 1280, height: 800 } : windowSize()));
|
|
222
|
+
/* The app's bar, fixed at the window's top at every level: its slot, and how tall it stands. */
|
|
223
|
+
const [bar, setBar] = useState(null);
|
|
224
|
+
const [barHeight, setBarHeight] = useState(0);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (!bar || typeof ResizeObserver === "undefined")
|
|
227
|
+
return;
|
|
228
|
+
const measure = () => setBarHeight(Math.ceil(bar.getBoundingClientRect().height));
|
|
229
|
+
measure();
|
|
230
|
+
const watch = new ResizeObserver(measure);
|
|
231
|
+
watch.observe(bar);
|
|
232
|
+
return () => watch.disconnect();
|
|
233
|
+
}, [bar]);
|
|
234
|
+
/* A host that draws the bar itself (an embed's) is handed the slot, and draws its bar there. */
|
|
235
|
+
const toldSlot = context.onBarSlot;
|
|
236
|
+
useLayoutEffect(() => {
|
|
237
|
+
if (!toldSlot)
|
|
238
|
+
return;
|
|
239
|
+
toldSlot(bar);
|
|
240
|
+
return () => toldSlot(null);
|
|
241
|
+
}, [bar, toldSlot]);
|
|
242
|
+
/*
|
|
243
|
+
* THE PANEL AS THE PERSON SIZED IT: dragged by its inner edge, or stepped
|
|
244
|
+
* by the arrow keys there — a desk's panel's width, a phone's sheet's
|
|
245
|
+
* height (the share of the window above it). Kept in this browser for
|
|
246
|
+
* this app (its address and its name: two apps on one host keep their
|
|
247
|
+
* own), for the moves between levels to start and end from, and over the
|
|
248
|
+
* width the panel opens at (`context.panel`, 55% of a desk's window).
|
|
249
|
+
*/
|
|
250
|
+
const phoneNow = size.width <= PHONE;
|
|
251
|
+
const appKey = `${base || "/"}|${context.app?.name ?? context.brand?.name ?? schema.kinds.join(",")}`;
|
|
252
|
+
const panelKey = panelStoreKey(appKey, phoneNow);
|
|
253
|
+
const [panelSize, setPanelSize] = useState(() => {
|
|
254
|
+
try {
|
|
255
|
+
const kept = typeof window === "undefined" ? null : window.localStorage.getItem(panelStoreKey(appKey, windowSize().width <= PHONE));
|
|
256
|
+
return kept === null ? undefined : Number(kept) || undefined;
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
// Across the phone's width the size is the other device's: read again for it.
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
try {
|
|
265
|
+
const kept = window.localStorage.getItem(panelKey);
|
|
266
|
+
setPanelSize(kept === null ? undefined : Number(kept) || undefined);
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
setPanelSize(undefined);
|
|
270
|
+
}
|
|
271
|
+
}, [panelKey]);
|
|
272
|
+
/** The size, now; kept in this browser once the hand lets go (`keepPanel`), not on every move. */
|
|
273
|
+
const sizePanel = useCallback((to) => setPanelSize(to), []);
|
|
274
|
+
const panelHeld = useRef(panelSize);
|
|
275
|
+
panelHeld.current = panelSize;
|
|
276
|
+
const keepPanel = useCallback(() => {
|
|
277
|
+
try {
|
|
278
|
+
const to = panelHeld.current;
|
|
279
|
+
if (to === undefined)
|
|
280
|
+
window.localStorage.removeItem(panelKey);
|
|
281
|
+
else
|
|
282
|
+
window.localStorage.setItem(panelKey, String(Math.round(to * 1000) / 1000));
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// A browser that keeps nothing keeps the size for this visit.
|
|
286
|
+
}
|
|
287
|
+
}, [panelKey]);
|
|
288
|
+
const share = context.panel;
|
|
289
|
+
const view = useMemo(() => ({ ...size, top: barHeight, ...(panelSize !== undefined ? { panel: panelSize } : {}), ...(share !== undefined ? { share } : {}) }), [size, barHeight, panelSize, share]);
|
|
290
|
+
const motion = useRef({ level: where.type === "overview" ? CITY : null, scrub: 0, scrubbing: false, held: false, resizing: false });
|
|
291
|
+
// What the camera says: the level rested at or headed for, and whether the page is out of the window.
|
|
292
|
+
const [now, setNow] = useState({ level: PAGE, away: where.type === "overview", moving: false });
|
|
293
|
+
const sheet = useRef(null);
|
|
294
|
+
const connected = useRef(null);
|
|
295
|
+
const fab = useRef(null);
|
|
296
|
+
const boardLayer = useRef(null);
|
|
297
|
+
const boardEls = useRef(new Map());
|
|
298
|
+
/** The board last given the keyboard at the city: the button that comes down goes into it. */
|
|
299
|
+
const chosen = useRef(null);
|
|
300
|
+
/** Put down at the city by a press on the ground or Escape: the keyboard is not put back on a view until a level is moved. */
|
|
301
|
+
const deselected = useRef(false);
|
|
302
|
+
const kept = useRef(null);
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
const resized = () => setView(windowSize());
|
|
305
|
+
window.addEventListener("resize", resized);
|
|
306
|
+
return () => window.removeEventListener("resize", resized);
|
|
307
|
+
}, []);
|
|
308
|
+
/*
|
|
309
|
+
* THE BOARDS: every page and view the app offers — its home, each kind's
|
|
310
|
+
* list, each lens, as the bar's places list them, lists and lenses alike
|
|
311
|
+
* — and, on a record's page, that record's own.
|
|
312
|
+
*/
|
|
313
|
+
const boards = useMemo(() => {
|
|
314
|
+
const places = barPlaces({ store: store, principal: context.principal, views: context.views }).filter((place) => !place.hidden);
|
|
315
|
+
/*
|
|
316
|
+
* WHAT EACH BOARD SAYS IT IS. A view's board listed the first records of
|
|
317
|
+
* its kind, as its kind's list did: ten views on a rich app drew alike,
|
|
318
|
+
* and none looked like itself. A list's board says how many it holds
|
|
319
|
+
* and its first; a view's says whose view it is, over its own
|
|
320
|
+
* title; the home's and the connections' say what they are.
|
|
321
|
+
*/
|
|
322
|
+
const out = places.map((place) => {
|
|
323
|
+
const where = whereOf(schema, has, place.path.split("?")[0], placeKinds);
|
|
324
|
+
const list = where.type === "list";
|
|
325
|
+
const kind = place.kind;
|
|
326
|
+
const count = kind ? store.graph.count(kind) : 0;
|
|
327
|
+
const says = place.group === "home"
|
|
328
|
+
? "Front page"
|
|
329
|
+
: place.key === "connections"
|
|
330
|
+
? "The kinds, linked"
|
|
331
|
+
: list && kind
|
|
332
|
+
? count === 0
|
|
333
|
+
? `No ${pluralOf(store, kind).toLowerCase()} yet`
|
|
334
|
+
: counted(store.schema, kind, count)
|
|
335
|
+
: kind
|
|
336
|
+
? `View · ${pluralOf(store, kind).toLowerCase()}`
|
|
337
|
+
: "A view";
|
|
338
|
+
return {
|
|
339
|
+
key: place.key,
|
|
340
|
+
label: place.label,
|
|
341
|
+
path: place.path,
|
|
342
|
+
eyebrow: place.group === "home" ? "home" : place.group === "lists" ? "list" : "view",
|
|
343
|
+
says,
|
|
344
|
+
lines: list && kind ? firstOf(store, [kind]).slice(0, 1) : [],
|
|
345
|
+
kind: place.kind,
|
|
346
|
+
where,
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
if (where.type === "record") {
|
|
350
|
+
const node = store.graph.getNode(where.id);
|
|
351
|
+
out.push({ key: `record:${where.id}`, label: node ? labelOf(store.schema.tryDefinition(node.kind), node) : where.id, path: recordPath(schema, where.kind, where.id), eyebrow: "page", says: "", lines: [], kind: where.kind, where });
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
355
|
+
}, [store, context.principal, context.views, schema, has, placeKinds, where, tick]);
|
|
356
|
+
const current = boardKeyOf(where, boards);
|
|
357
|
+
/* While the history is played, a view that comes into being rises out of the city, and one that goes sinks back into it. */
|
|
358
|
+
const rising = Boolean(usePlayback()?.open) && !lessMotion();
|
|
359
|
+
const leaving = useLeavingBoards(boards, rising);
|
|
360
|
+
const standing = useMemo(() => (leaving.length > 0 ? [...boards, ...leaving] : boards), [boards, leaving]);
|
|
361
|
+
/** Out of the window: where the page was scrolled, for the page as it moves and for the way back in. */
|
|
362
|
+
const keep = () => {
|
|
363
|
+
if (!now.away && !kept.current)
|
|
364
|
+
kept.current = { scrollY: window.scrollY, address };
|
|
365
|
+
};
|
|
366
|
+
const goLevel = useCallback((level) => {
|
|
367
|
+
const to = Math.max(PAGE, Math.min(CITY, level));
|
|
368
|
+
if (to > PAGE)
|
|
369
|
+
keep();
|
|
370
|
+
motion.current.level = to;
|
|
371
|
+
// The page leaves the window in this commit, so the first frame of the move draws it where it was.
|
|
372
|
+
if (to > PAGE)
|
|
373
|
+
setNow((was) => (was.away ? was : { ...was, away: true }));
|
|
374
|
+
},
|
|
375
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
376
|
+
[now.away, address]);
|
|
377
|
+
/* Out of the window, the page keeps its own scroll; in again, the window takes it back. */
|
|
378
|
+
useLayoutEffect(() => {
|
|
379
|
+
const plane = sheet.current;
|
|
380
|
+
if (!plane)
|
|
381
|
+
return;
|
|
382
|
+
if (now.away) {
|
|
383
|
+
if (kept.current)
|
|
384
|
+
plane.scrollTop = kept.current.address === address ? kept.current.scrollY : 0;
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const was = kept.current;
|
|
388
|
+
kept.current = null;
|
|
389
|
+
if (was)
|
|
390
|
+
window.scrollTo({ left: 0, top: was.address === address ? was.scrollY : 0, behavior: "instant" });
|
|
391
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
392
|
+
}, [now.away]);
|
|
393
|
+
/* The overview's own address is the city, standing over the home: the address the home's. */
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
if (where.type !== "overview")
|
|
396
|
+
return;
|
|
397
|
+
motion.current.level = CITY;
|
|
398
|
+
setNow((was) => ({ ...was, away: true }));
|
|
399
|
+
navigate(`/${location.search}`, { replace: true });
|
|
400
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
401
|
+
}, [where.type]);
|
|
402
|
+
/** Another place, at a level: its address, and the camera asked to that level there. */
|
|
403
|
+
/*
|
|
404
|
+
* THE PAGE CHOSEN IS DRAWN FIRST, THEN IT MOVES. Asked for at the same
|
|
405
|
+
* moment as the address, the level began to move the page that was being
|
|
406
|
+
* left while the chosen one's route was still drawing — on a slow machine
|
|
407
|
+
* one long task, which landed inside the move as a leap. The level is
|
|
408
|
+
* asked once the new address has drawn and been painted.
|
|
409
|
+
*/
|
|
410
|
+
const pendingLevel = useRef(null);
|
|
411
|
+
useEffect(() => {
|
|
412
|
+
const pending = pendingLevel.current;
|
|
413
|
+
if (!pending || pending.path !== location.pathname)
|
|
414
|
+
return;
|
|
415
|
+
pendingLevel.current = null;
|
|
416
|
+
const frame = requestAnimationFrame(() => {
|
|
417
|
+
motion.current.level = pending.level;
|
|
418
|
+
});
|
|
419
|
+
return () => cancelAnimationFrame(frame);
|
|
420
|
+
}, [location.pathname]);
|
|
421
|
+
const openAt = useCallback((path, level) => {
|
|
422
|
+
// The page this is (asked by its path alone, or narrowed as it is): only the level moves. Narrowed otherwise (`/problems?kind=…` from `/problems`), it is gone to.
|
|
423
|
+
if (path.includes("?") ? path === `${location.pathname}${location.search}` : path === location.pathname)
|
|
424
|
+
return goLevel(level);
|
|
425
|
+
if (level > PAGE)
|
|
426
|
+
keep();
|
|
427
|
+
kept.current = level > PAGE ? { scrollY: 0, address: path } : null;
|
|
428
|
+
pendingLevel.current = { path: path.split("?")[0], level };
|
|
429
|
+
if (level > PAGE)
|
|
430
|
+
setNow((was) => (was.away ? was : { ...was, away: true }));
|
|
431
|
+
navigate(path);
|
|
432
|
+
},
|
|
433
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
434
|
+
[location.pathname, goLevel, navigate]);
|
|
435
|
+
const openRecord = useCallback((id, level) => {
|
|
436
|
+
const kind = has(id);
|
|
437
|
+
if (kind)
|
|
438
|
+
openAt(recordPath(schema, kind, id), level);
|
|
439
|
+
}, [has, schema, openAt]);
|
|
440
|
+
const openKind = useCallback((kind, level) => {
|
|
441
|
+
// A place that shows this kind is already its page.
|
|
442
|
+
if (where.type === "place" && where.kinds.includes(kind))
|
|
443
|
+
return goLevel(level);
|
|
444
|
+
openAt(`/${pluralSlug(schema, kind)}`, level);
|
|
445
|
+
}, [schema, where, goLevel, openAt]);
|
|
446
|
+
const resolve = useCallback((pathname) => {
|
|
447
|
+
const path = base && pathname.startsWith(base) ? pathname.slice(base.length) || "/" : pathname;
|
|
448
|
+
const found = whereOf(schema, has, path, placeKinds);
|
|
449
|
+
return found.type === "record" || found.type === "list" ? found : null;
|
|
450
|
+
}, [base, schema, has, placeKinds]);
|
|
451
|
+
/** Into a board, beside the city: this page's own, or another's. */
|
|
452
|
+
const intoBoard = useCallback((key) => {
|
|
453
|
+
const board = boards.find((one) => one.key === key);
|
|
454
|
+
if (!board || key === current)
|
|
455
|
+
return goLevel(PANEL);
|
|
456
|
+
openAt(board.path, PANEL);
|
|
457
|
+
}, [boards, current, goLevel, openAt]);
|
|
458
|
+
/** To a level from here: from the city down, into the board the keyboard chose, if it chose another. */
|
|
459
|
+
const goTo = useCallback((level) => {
|
|
460
|
+
const to = Math.max(PAGE, Math.min(CITY, level));
|
|
461
|
+
if (now.level === CITY && to < CITY && chosen.current && chosen.current !== current) {
|
|
462
|
+
const board = boards.find((one) => one.key === chosen.current);
|
|
463
|
+
if (board)
|
|
464
|
+
return openAt(board.path, to);
|
|
465
|
+
}
|
|
466
|
+
goLevel(to);
|
|
467
|
+
}, [now.level, current, boards, goLevel, openAt]);
|
|
468
|
+
const rise = useCallback(() => goTo(now.level + 1), [goTo, now.level]);
|
|
469
|
+
const descend = useCallback(() => goTo(now.level - 1), [goTo, now.level]);
|
|
470
|
+
/*
|
|
471
|
+
* A PINCH, OR CTRL AND THE WHEEL, SCRUBS THE ALTITUDE: on the page and on
|
|
472
|
+
* the panel this face moves the camera itself, as far as the hand goes;
|
|
473
|
+
* over the city the Scene's own hand zooms it, and the level stays.
|
|
474
|
+
* Nothing snaps: let go, it settles to the nearest level.
|
|
475
|
+
* Alt and the up arrow rise a level, Alt and the down arrow (or Escape)
|
|
476
|
+
* come down one — never while the keys are writing in a field.
|
|
477
|
+
*/
|
|
478
|
+
/**
|
|
479
|
+
* NO VIEW CHOSEN: the keyboard off every view, onto the views' own group,
|
|
480
|
+
* and the city as it is. A press on bare ground at the city does it, and
|
|
481
|
+
* Escape there.
|
|
482
|
+
*/
|
|
483
|
+
const deselect = useCallback(() => {
|
|
484
|
+
chosen.current = null;
|
|
485
|
+
deselected.current = true;
|
|
486
|
+
boardLayer.current?.focus({ preventScroll: true });
|
|
487
|
+
}, []);
|
|
488
|
+
/** Out of the window's flow, ready for a hand to move the camera. */
|
|
489
|
+
const beginAway = useCallback(() => {
|
|
490
|
+
if (latest.current.now.away)
|
|
491
|
+
return;
|
|
492
|
+
latest.current.keep();
|
|
493
|
+
setNow((was) => (was.away ? was : { ...was, away: true }));
|
|
494
|
+
}, []);
|
|
495
|
+
const onGround = useCallback(() => {
|
|
496
|
+
if (latest.current.now.level === CITY && !latest.current.now.moving)
|
|
497
|
+
latest.current.deselect();
|
|
498
|
+
}, []);
|
|
499
|
+
const latest = useRef({ now, rise, descend, deselect, keep, goTo });
|
|
500
|
+
latest.current = { now, rise, descend, deselect, keep, goTo };
|
|
501
|
+
useEffect(() => {
|
|
502
|
+
const onPage = (target) => target instanceof Node && sheet.current?.contains(target) === true;
|
|
503
|
+
const begin = () => {
|
|
504
|
+
if (!latest.current.now.away) {
|
|
505
|
+
latest.current.keep();
|
|
506
|
+
setNow((was) => (was.away ? was : { ...was, away: true }));
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
let pinch = null;
|
|
510
|
+
const apart = (touches) => Math.hypot(touches[0].clientX - touches[1].clientX, touches[0].clientY - touches[1].clientY);
|
|
511
|
+
const touchStart = (event) => {
|
|
512
|
+
motion.current.held = event.touches.length > 0;
|
|
513
|
+
/*
|
|
514
|
+
* A PINCH IS THE BROWSER'S OWN ON THE PAGE: there it zooms the page's
|
|
515
|
+
* words for whoever needs them larger, and a level is moved by the
|
|
516
|
+
* control, its keys, or Alt and the arrows. Ctrl and the wheel, a
|
|
517
|
+
* trackpad's pinch, are the browser's own over the page too. Beside the
|
|
518
|
+
* city two fingers on the page scrub the altitude; over the city, and
|
|
519
|
+
* at the City, the Scene's own hand zooms the camera.
|
|
520
|
+
*/
|
|
521
|
+
const nearby = latest.current.now.level === PANEL && latest.current.now.away && !latest.current.now.moving;
|
|
522
|
+
const mine = nearby && onPage(event.touches[0]?.target ?? null) && onPage(event.touches[1]?.target ?? null);
|
|
523
|
+
pinch = event.touches.length === 2 && mine ? apart(event.touches) : null;
|
|
524
|
+
};
|
|
525
|
+
const touchMove = (event) => {
|
|
526
|
+
if (pinch === null || event.touches.length !== 2)
|
|
527
|
+
return;
|
|
528
|
+
event.preventDefault();
|
|
529
|
+
begin();
|
|
530
|
+
const distance = apart(event.touches);
|
|
531
|
+
// Fingers together is out: the altitude rises as far as they have closed.
|
|
532
|
+
motion.current.scrub += Math.log(pinch / distance) * 1.6;
|
|
533
|
+
pinch = distance;
|
|
534
|
+
};
|
|
535
|
+
const touchEnd = (event) => {
|
|
536
|
+
motion.current.held = event.touches.length > 0;
|
|
537
|
+
if (event.touches.length < 2)
|
|
538
|
+
pinch = null;
|
|
539
|
+
};
|
|
540
|
+
/*
|
|
541
|
+
* A TRACKPAD'S PINCH OVER THE PANEL (ctrl and the wheel, as the browser
|
|
542
|
+
* says one) steps the level, as two fingers on a phone's sheet do: it
|
|
543
|
+
* scrubs the altitude, Page↔Nearby↔City, settling to the nearest when let
|
|
544
|
+
* go. Over the city beside it the same pinch is the city's own and only
|
|
545
|
+
* zooms the camera (`one-place-city.tsx`); a plain scroll over the panel
|
|
546
|
+
* scrolls the page. At Page the pinch is the browser's own.
|
|
547
|
+
*/
|
|
548
|
+
/*
|
|
549
|
+
* SAFARI'S TRACKPAD PINCH is a GestureEvent, its `scale` how far the
|
|
550
|
+
* fingers have gone since they began: over the panel it scrubs the
|
|
551
|
+
* altitude as a pinch on a phone's sheet does (and the page is not
|
|
552
|
+
* zoomed by the browser while it is out of the window). Two fingers on
|
|
553
|
+
* glass are the touches' (above), never read twice.
|
|
554
|
+
*/
|
|
555
|
+
let gestureFrom = null;
|
|
556
|
+
const gestureStart = (event) => {
|
|
557
|
+
const now = latest.current.now;
|
|
558
|
+
if (!onPage(event.target) || !now.away || pinch !== null)
|
|
559
|
+
return;
|
|
560
|
+
event.preventDefault();
|
|
561
|
+
gestureFrom = now.level === PANEL && !now.moving ? 1 : null;
|
|
562
|
+
};
|
|
563
|
+
const gestureChange = (event) => {
|
|
564
|
+
if (!onPage(event.target) || !latest.current.now.away || pinch !== null)
|
|
565
|
+
return;
|
|
566
|
+
event.preventDefault();
|
|
567
|
+
if (gestureFrom === null)
|
|
568
|
+
return;
|
|
569
|
+
const scale = event.scale ?? 1;
|
|
570
|
+
if (!(scale > 0))
|
|
571
|
+
return;
|
|
572
|
+
begin();
|
|
573
|
+
motion.current.held = true;
|
|
574
|
+
// Fingers together is out: the altitude rises as far as they have closed.
|
|
575
|
+
motion.current.scrub += Math.log(gestureFrom / scale) * 1.6;
|
|
576
|
+
gestureFrom = scale;
|
|
577
|
+
};
|
|
578
|
+
const gestureEnd = () => {
|
|
579
|
+
if (gestureFrom !== null)
|
|
580
|
+
motion.current.held = false;
|
|
581
|
+
gestureFrom = null;
|
|
582
|
+
};
|
|
583
|
+
const wheel = (event) => {
|
|
584
|
+
if (!(event.ctrlKey || event.metaKey) || !onPage(event.target))
|
|
585
|
+
return;
|
|
586
|
+
// Safari says a pinch as a gesture as well: read once, from the gesture.
|
|
587
|
+
if (gestureFrom !== null) {
|
|
588
|
+
event.preventDefault();
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
const now = latest.current.now;
|
|
592
|
+
if (!now.away)
|
|
593
|
+
return;
|
|
594
|
+
// Out of the window, the browser never zooms the page under the hand: the pinch is the face's.
|
|
595
|
+
event.preventDefault();
|
|
596
|
+
if (!motion.current.scrubbing && (now.level !== PANEL || now.moving))
|
|
597
|
+
return;
|
|
598
|
+
const unit = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? 400 : 1;
|
|
599
|
+
begin();
|
|
600
|
+
// Fingers together (the wheel's down) is out: the altitude rises as far as the camera's zoom would fall.
|
|
601
|
+
motion.current.scrub += event.deltaY * unit * 0.016;
|
|
602
|
+
};
|
|
603
|
+
const key = (event) => {
|
|
604
|
+
// Never with the browser's own chords (its zoom is Cmd or Ctrl and plus, minus, 0), never while the keys are writing, never into a view's frame.
|
|
605
|
+
const target = (event.composedPath()[0] ?? event.target);
|
|
606
|
+
if (event.defaultPrevented || event.repeat || event.isComposing || event.metaKey || event.ctrlKey || event.shiftKey || typingIn(target))
|
|
607
|
+
return;
|
|
608
|
+
// Where the keys mean something of their own — a menu, a list to type into, a grid — they are theirs.
|
|
609
|
+
if (target instanceof Element && target.closest('[role="menu"], [role="listbox"], [role="combobox"], [role="grid"], [role="textbox"], [role="spinbutton"], [role="tree"]'))
|
|
610
|
+
return;
|
|
611
|
+
if (document.querySelector("[data-graview-overlay]:not([hidden])"))
|
|
612
|
+
return;
|
|
613
|
+
const level = latest.current.now.level;
|
|
614
|
+
// 1, 2 and 3: Page, Nearby and City. [ and ]: down and up a level — unless the keys were turned off in the legend.
|
|
615
|
+
if (!event.altKey && !keysOn()) {
|
|
616
|
+
if (LEVEL_KEYS.includes(event.key) || event.key === "[" || event.key === "]")
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const stop = !event.altKey ? LEVEL_KEYS.indexOf(event.key) : -1;
|
|
620
|
+
if (stop >= 0) {
|
|
621
|
+
event.preventDefault();
|
|
622
|
+
// The level's own key, at Nearby or the City, brings the camera back to that level's framing after a hand moved it.
|
|
623
|
+
if (stop !== level || level > PAGE)
|
|
624
|
+
latest.current.goTo(stop);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const up = (event.altKey && event.key === "ArrowUp") || (!event.altKey && event.key === "]");
|
|
628
|
+
// Escape at the city puts down the view the keyboard chose, and stays at the city; below it, it comes down a level.
|
|
629
|
+
if (!event.altKey && event.key === "Escape" && level === CITY) {
|
|
630
|
+
if (boardLayer.current?.contains(document.activeElement)) {
|
|
631
|
+
event.preventDefault();
|
|
632
|
+
latest.current.deselect();
|
|
633
|
+
}
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const down = (event.altKey && event.key === "ArrowDown") || (!event.altKey && (event.key === "Escape" || event.key === "["));
|
|
637
|
+
if (up && level < CITY) {
|
|
638
|
+
event.preventDefault();
|
|
639
|
+
latest.current.rise();
|
|
640
|
+
}
|
|
641
|
+
else if (down && level > PAGE) {
|
|
642
|
+
event.preventDefault();
|
|
643
|
+
latest.current.descend();
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
window.addEventListener("touchstart", touchStart, { passive: true, capture: true });
|
|
647
|
+
window.addEventListener("touchmove", touchMove, { passive: false, capture: true });
|
|
648
|
+
window.addEventListener("touchend", touchEnd, { capture: true });
|
|
649
|
+
window.addEventListener("touchcancel", touchEnd, { capture: true });
|
|
650
|
+
window.addEventListener("wheel", wheel, { passive: false, capture: true });
|
|
651
|
+
window.addEventListener("gesturestart", gestureStart, { passive: false, capture: true });
|
|
652
|
+
window.addEventListener("gesturechange", gestureChange, { passive: false, capture: true });
|
|
653
|
+
window.addEventListener("gestureend", gestureEnd, { capture: true });
|
|
654
|
+
document.addEventListener("keydown", key);
|
|
655
|
+
return () => {
|
|
656
|
+
window.removeEventListener("touchstart", touchStart, { capture: true });
|
|
657
|
+
window.removeEventListener("touchmove", touchMove, { capture: true });
|
|
658
|
+
window.removeEventListener("touchend", touchEnd, { capture: true });
|
|
659
|
+
window.removeEventListener("touchcancel", touchEnd, { capture: true });
|
|
660
|
+
window.removeEventListener("wheel", wheel, { capture: true });
|
|
661
|
+
window.removeEventListener("gesturestart", gestureStart, { capture: true });
|
|
662
|
+
window.removeEventListener("gesturechange", gestureChange, { capture: true });
|
|
663
|
+
window.removeEventListener("gestureend", gestureEnd, { capture: true });
|
|
664
|
+
document.removeEventListener("keydown", key);
|
|
665
|
+
};
|
|
666
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
667
|
+
}, []);
|
|
668
|
+
const onAltitude = useCallback((told) => {
|
|
669
|
+
setNow((was) => (was.level === told.level && was.away === told.away && was.moving === told.moving ? was : told));
|
|
670
|
+
}, []);
|
|
671
|
+
/*
|
|
672
|
+
* WHERE THE KEYBOARD WAITS. At the city the page takes none: it waits on
|
|
673
|
+
* this page's own board, laid over it, unless it is already on a board or
|
|
674
|
+
* the button. Headed back down, a keyboard left on a board (going out of
|
|
675
|
+
* reach) goes to the page's title.
|
|
676
|
+
*/
|
|
677
|
+
const cameFrom = useRef(now.level);
|
|
678
|
+
useLayoutEffect(() => {
|
|
679
|
+
const active = document.activeElement;
|
|
680
|
+
const onBoards = boardLayer.current?.contains(active) === true;
|
|
681
|
+
// Only a move between levels places the keyboard: a page that opens at Page leaves it where the routed face puts it, as the derived pages do.
|
|
682
|
+
const moved = cameFrom.current !== now.level;
|
|
683
|
+
cameFrom.current = now.level;
|
|
684
|
+
if (now.level === CITY) {
|
|
685
|
+
if (now.moving || onBoards || fab.current?.contains(active) || deselected.current || bar?.contains(active))
|
|
686
|
+
return;
|
|
687
|
+
boardEls.current.get(current)?.focus({ preventScroll: true });
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
chosen.current = null;
|
|
691
|
+
deselected.current = false;
|
|
692
|
+
if (!onBoards && (active !== document.body || !moved))
|
|
693
|
+
return;
|
|
694
|
+
const title = sheet.current?.querySelector("main h1, h1:not([data-graview-app-bar] h1)");
|
|
695
|
+
/*
|
|
696
|
+
* A page with no title of its own (a view drawn in place of a record's
|
|
697
|
+
* page) takes the keyboard on its main part; only a page with none of
|
|
698
|
+
* that either puts it on the control — on the level it is at, its
|
|
699
|
+
* tooltip quiet: the first stop lit by a focus ring, "Page (1)" up, read
|
|
700
|
+
* as a second level chosen.
|
|
701
|
+
*/
|
|
702
|
+
const landing = title ?? sheet.current?.querySelector("main, [role=main]") ?? null;
|
|
703
|
+
if (landing) {
|
|
704
|
+
if (!landing.hasAttribute("tabindex")) {
|
|
705
|
+
landing.setAttribute("tabindex", "-1");
|
|
706
|
+
if (landing !== title)
|
|
707
|
+
landing.setAttribute("data-graview-focus-landing", "");
|
|
708
|
+
}
|
|
709
|
+
landing.focus({ preventScroll: true });
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
quietFocusUntil = performance.now() + 400;
|
|
713
|
+
(fab.current?.querySelector('button[aria-pressed="true"]') ?? fab.current?.querySelector("button"))?.focus({ preventScroll: true });
|
|
714
|
+
}
|
|
715
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
716
|
+
}, [now.level, now.moving, current, bar]);
|
|
717
|
+
const face = useMemo(() => ({ level: now.level, goLevel, openRecord, openPath: openAt, bar }), [now.level, goLevel, openRecord, openAt, bar]);
|
|
718
|
+
// The page drawn where it was first drawn reads the face from there: told it as it changes, before the frame is painted.
|
|
719
|
+
useLayoutEffect(() => {
|
|
720
|
+
onFace?.(face);
|
|
721
|
+
}, [face, onFace]);
|
|
722
|
+
useLayoutEffect(() => () => onFace?.(null), [onFace]);
|
|
723
|
+
const away = now.away;
|
|
724
|
+
/*
|
|
725
|
+
* IN THE PANEL: out of the window and at Nearby or above (headed there,
|
|
726
|
+
* or resting) — the page as a column beside the city, not a full page. The
|
|
727
|
+
* page says so (`data-graview-in-panel`, which each worker view's root
|
|
728
|
+
* takes too), and its gutter and its room above and below are a panel's.
|
|
729
|
+
*/
|
|
730
|
+
const inPanel = away && now.level >= PANEL;
|
|
731
|
+
// The page as one element: in the page's own flow while it is read, the window's box and then the panel's once it moves (`one-place-city.tsx` sets its box each frame).
|
|
732
|
+
const sheetStyle = away
|
|
733
|
+
? {
|
|
734
|
+
position: "fixed",
|
|
735
|
+
left: 0,
|
|
736
|
+
top: view.top,
|
|
737
|
+
width: view.width,
|
|
738
|
+
height: view.height - view.top,
|
|
739
|
+
overflowY: "auto",
|
|
740
|
+
overflowX: "hidden",
|
|
741
|
+
zIndex: ONE_FACE_LAYERS.page,
|
|
742
|
+
background: "var(--graview-ground, Canvas)",
|
|
743
|
+
boxShadow: "0 18px 50px rgba(0,0,0,0.20)",
|
|
744
|
+
outline: "1px solid var(--graview-edge)",
|
|
745
|
+
// At the city it takes no pointer: its board, laid over it, does.
|
|
746
|
+
pointerEvents: now.level >= CITY || now.moving ? "none" : "auto",
|
|
747
|
+
willChange: "transform, left, top, width, height",
|
|
748
|
+
// Its own sizes for its words: it is a narrower page as a panel.
|
|
749
|
+
containerType: "inline-size",
|
|
750
|
+
// Out of the window's flow the page is under the bar already: the room it kept for it is none.
|
|
751
|
+
["--graview-one-face-bar"]: "0px",
|
|
752
|
+
// Its gutter and its room above and below: set each frame by the city part, from the altitude (`frameSpacingAt`), so they move with the page's box.
|
|
753
|
+
}
|
|
754
|
+
: { display: "contents", ["--graview-one-face-bar"]: `${barHeight}px`, ...frameSpacing(false) };
|
|
755
|
+
const subject = where.type === "record" ? where.id : null;
|
|
756
|
+
const whole = useWholeView(sheet, `${where.type}:${subject ?? ""}`);
|
|
757
|
+
/* The arrow keys among the boards: the nearest that way. */
|
|
758
|
+
const boardKeys = (event) => {
|
|
759
|
+
const ways = { ArrowLeft: "left", ArrowRight: "right", ArrowUp: "up", ArrowDown: "down" };
|
|
760
|
+
const way = ways[event.key];
|
|
761
|
+
if (!way || event.altKey || event.metaKey || event.ctrlKey)
|
|
762
|
+
return;
|
|
763
|
+
const at = event.target.closest("[data-graview-board]");
|
|
764
|
+
if (!at)
|
|
765
|
+
return;
|
|
766
|
+
const boxOf = (el) => {
|
|
767
|
+
const r = el.getBoundingClientRect();
|
|
768
|
+
return { x: r.left, y: r.top, width: r.width, height: r.height };
|
|
769
|
+
};
|
|
770
|
+
const others = [...boardEls.current.entries()].filter(([, el]) => el !== at && Number(el.style.opacity || 0) > 0.5 && el.getBoundingClientRect().width > 0).map(([key, el]) => ({ key, box: boxOf(el) }));
|
|
771
|
+
const next = nearestThatWay(boxOf(at), others, way);
|
|
772
|
+
event.preventDefault();
|
|
773
|
+
if (next)
|
|
774
|
+
boardEls.current.get(next)?.focus({ preventScroll: true });
|
|
775
|
+
};
|
|
776
|
+
return (_jsxs(OneFaceContext.Provider, { value: face, children: [_jsx("div", { ref: setBar, "data-testid": "one-place-bar", "data-graview-one-face-bar": "", style: { position: "fixed", left: 0, right: 0, top: 0, zIndex: ONE_FACE_LAYERS.bar, background: "var(--graview-ground, Canvas)" } }), _jsx(Suspense, { fallback: null, children: _jsx(OnePlaceCity, { where: where, out: now.away, sheet: sheet, connected: connected, boards: standing, current: current, boardEls: boardEls, boardLayer: boardLayer, fab: fab, view: view, lessMotion: lessMotion(), resolve: resolve, openRecord: openRecord, openKind: openKind, onGround: onGround, motion: motion, onAltitude: onAltitude }) }), _jsx("div", { ref: sheet, "data-graview-one-place": now.level, ...(inPanel ? { "data-graview-in-panel": "" } : {}), "data-graview-standing-on": where.type === "record" ? where.id : where.type === "list" ? `kind:${where.kind}` : where.type, style: sheetStyle, children: _jsxs("div", { ...(now.level >= CITY ? { inert: true } : {}), style: away ? { minHeight: "100%", display: "flex", flexDirection: "column" } : { display: "contents" }, children: [context.embedded ? _jsx("div", { "aria-hidden": "true", "data-graview-bar-room": "", style: { height: "var(--graview-one-face-bar, 0px)", flex: "0 0 auto" } }) : null, away && subject && whole ? _jsx(Connected, { store: store, id: subject, box: connected, sheet: sheet, openRecord: openRecord, whole: true }) : null, page ? _jsx(HeldHere, { host: page }) : children, away && subject && !whole ? _jsx(Connected, { store: store, id: subject, box: connected, sheet: sheet, openRecord: openRecord, whole: false }) : null, away ? null : _jsx(FootRoom, { fab: fab, sheet: sheet })] }) }), _jsx("div", { ref: boardLayer, role: "group", "aria-label": "The app's views", "data-testid": "one-place-boards", tabIndex: -1, onKeyDown: boardKeys, hidden: now.level < PANEL && !now.moving, style: { position: "fixed", left: 0, top: 0, width: 0, height: 0, zIndex: ONE_FACE_LAYERS.page }, children: standing.map((board) => (_jsx("button", { ref: (el) => {
|
|
777
|
+
if (el)
|
|
778
|
+
boardEls.current.set(board.key, el);
|
|
779
|
+
else
|
|
780
|
+
boardEls.current.delete(board.key);
|
|
781
|
+
}, type: "button", "data-graview-board": board.key, ...(rising ? { "data-graview-rising": "" } : {}), ...(leaving.includes(board) ? { "data-graview-leaving": "", tabIndex: -1, "aria-hidden": true } : {}), "data-graview-board-path": board.path, ...(board.key === current ? { "aria-current": "page" } : {}), "aria-label": `${board.label}, ${board.eyebrow}${board.key === current ? ", the one you were on" : ""}`, title: board.label, onClick: () => intoBoard(board.key), onFocus: () => {
|
|
782
|
+
chosen.current = board.key;
|
|
783
|
+
}, className: "graview-one-place-board",
|
|
784
|
+
// In the layer's own box, not each a layer of its own: every board's post is drawn under every board (`LOCAL_LAYERS.beneath`), so a post that has to cross another board runs behind its words, never over them.
|
|
785
|
+
style: { position: "absolute", left: 0, top: 0, width: 0, height: 0, padding: 0, margin: 0, border: "none", background: "none", cursor: "pointer", overflow: "visible", display: "block", opacity: 0, color: "inherit", font: "inherit", textAlign: "start" }, children: board.key === current ? null : _jsx(BoardFace, { board: board, width: boardFaceWidth(view), height: boardFaceWidth(view) / BOARD_ASPECT, small: smallWindow(view) }) }, board.key))) }), now.level === PANEL && !now.moving ? _jsx(PanelEdge, { view: view, size: sizePanel, keep: keepPanel, motion: motion }) : null, _jsx(Altitude, { box: fab, level: now.level, moving: now.moving, goTo: goTo, where: where, chosen: chosen, boards: boards, current: current, store: store, motion: motion, begin: beginAway }), _jsx("style", { children: ONE_PLACE_CSS })] }));
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* A BOARD'S FACE: the top of its page as the page draws it — what it is,
|
|
789
|
+
* its title — at the page's own size, scaled by the city part
|
|
790
|
+
* with the camera, so a board and the page that becomes one read alike.
|
|
791
|
+
* A title too long for it is cut whole, with an ellipsis; the board's own
|
|
792
|
+
* name (`title`, and what a screen reader is told) is the whole of it.
|
|
793
|
+
*/
|
|
794
|
+
function BoardFace({ board, width, height, small }) {
|
|
795
|
+
// A small window's face is narrower and its words fewer to a line: its title on two lines, broken where a word must be, fits the card whole.
|
|
796
|
+
const sizes = small ? { pad: "16px 16px 0", says: "2.125rem", title: "2.25rem" } : { pad: "22px 34px 0", says: "2.25rem", title: "3.5rem" };
|
|
797
|
+
const hue = board.kind ? `hsl(${Math.round(hueFor(board.kind))} 55% 52%)` : "var(--graview-accent)";
|
|
798
|
+
const view = board.eyebrow === "view";
|
|
799
|
+
return (_jsx("div", { "data-graview-board-face": "", "aria-hidden": "true", style: { position: "absolute", left: 0, top: 0, width, height, transformOrigin: "0 0", background: "var(--graview-ground, Canvas)", border: "3px solid var(--graview-edge)", borderTop: `10px solid ${hue}`, borderRadius: 18, overflow: "hidden", boxShadow: "0 18px 40px rgba(0,0,0,0.28)", pointerEvents: "none" }, children: _jsxs("div", { lang: "en", style: { padding: sizes.pad, ...(view ? { background: `linear-gradient(color-mix(in srgb, ${hue} 16%, transparent), transparent 85%)`, height: "100%", boxSizing: "border-box" } : {}) }, children: [_jsx("div", { "data-graview-board-says": "", style: { fontSize: sizes.says, lineHeight: 1.2, fontWeight: 600, letterSpacing: "0.06em", textTransform: "uppercase", color: view ? hue : "var(--graview-ink-muted)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }, children: board.says }), _jsx("div", { "data-graview-board-title": "", style: { marginTop: 6, fontSize: sizes.title, lineHeight: 1.15, fontWeight: 650, color: "var(--graview-ink)", display: "-webkit-box", WebkitLineClamp: 2, WebkitBoxOrient: "vertical", overflow: "hidden", overflowWrap: "break-word", hyphens: "auto" }, children: board.label }), _jsx("div", { style: { marginTop: 16, display: "grid", gap: 12 }, children: (small ? [] : board.lines).map((line, index) => (_jsxs("div", { style: { display: "flex", alignItems: "center", gap: 16, padding: "10px 16px", borderRadius: 12, border: "2px solid var(--graview-edge)", fontSize: "2.125rem", color: "var(--graview-ink-muted)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }, children: [_jsx("span", { style: { flex: "0 0 auto", width: 18, height: 18, borderRadius: 9, border: `3px solid ${hue}` } }), _jsx("span", { style: { minWidth: 0, overflow: "hidden", textOverflow: "ellipsis" }, children: line })] }, index))) })] }) }));
|
|
800
|
+
}
|
|
801
|
+
/** How long a board takes to rise out of the city or sink into it, as a building does while the history plays. */
|
|
802
|
+
const RISE_MS = 420;
|
|
803
|
+
/**
|
|
804
|
+
* The views going while the history is played: kept as they were for as
|
|
805
|
+
* long as they take to sink, unless they come back first. Worked out as
|
|
806
|
+
* the list changes, in the render that changes it (state set from the
|
|
807
|
+
* last render's list, as React has it), so a view going keeps its element.
|
|
808
|
+
*/
|
|
809
|
+
function useLeavingBoards(boards, rising) {
|
|
810
|
+
const key = boards.map((board) => board.key).join("\n");
|
|
811
|
+
const [seen, setSeen] = useState({ key, boards });
|
|
812
|
+
const [gone, setGone] = useState(new Map());
|
|
813
|
+
if (seen.key !== key) {
|
|
814
|
+
setSeen({ key, boards });
|
|
815
|
+
const here = new Set(boards.map((board) => board.key));
|
|
816
|
+
const next = new Map([...gone].filter(([one]) => !here.has(one)));
|
|
817
|
+
if (rising)
|
|
818
|
+
for (const board of seen.boards)
|
|
819
|
+
if (!here.has(board.key) && board.where.type !== "record" && !next.has(board.key))
|
|
820
|
+
next.set(board.key, { board, until: performance.now() + RISE_MS });
|
|
821
|
+
setGone(next);
|
|
822
|
+
}
|
|
823
|
+
useEffect(() => {
|
|
824
|
+
if (!rising && gone.size > 0)
|
|
825
|
+
return setGone(new Map());
|
|
826
|
+
if (gone.size === 0)
|
|
827
|
+
return;
|
|
828
|
+
const next = Math.min(...[...gone.values()].map((one) => one.until));
|
|
829
|
+
const timer = window.setTimeout(() => setGone((was) => new Map([...was].filter(([, one]) => one.until > performance.now() + 4))), Math.max(0, next - performance.now()) + 8);
|
|
830
|
+
return () => window.clearTimeout(timer);
|
|
831
|
+
}, [gone, rising]);
|
|
832
|
+
const kept = useMemo(() => [...gone.values()].map((one) => one.board), [gone]);
|
|
833
|
+
return rising ? kept : [];
|
|
834
|
+
}
|
|
835
|
+
const ONE_PLACE_CSS = `
|
|
836
|
+
.graview-one-place-edge::after { content: ""; position: absolute; border-radius: 3px; background: color-mix(in srgb, var(--graview-ink) 28%, transparent); transition: background 120ms; }
|
|
837
|
+
.graview-one-place-edge[aria-orientation="vertical"]::after { left: 5px; top: 50%; width: 4px; height: 44px; margin-top: -22px; }
|
|
838
|
+
.graview-one-place-edge[aria-orientation="horizontal"]::after { top: 11px; left: 50%; height: 5px; width: 40px; margin-left: -20px; }
|
|
839
|
+
.graview-one-place-edge:hover::after, .graview-one-place-edge:focus-visible::after { background: var(--graview-accent); }
|
|
840
|
+
.graview-one-place-edge:focus-visible { outline: none; }
|
|
841
|
+
.graview-one-place-board { touch-action: none; }
|
|
842
|
+
.graview-one-place-board::after { content: ""; position: absolute; z-index: ${LOCAL_LAYERS.beneath}; left: 50%; top: 100%; width: 2px; height: var(--graview-sign-post, 10px); margin-left: -1px; background: color-mix(in srgb, var(--graview-ink) 35%, transparent); }
|
|
843
|
+
.graview-one-place-board::before { content: ""; position: absolute; z-index: ${LOCAL_LAYERS.beneath}; left: 50%; top: calc(100% + var(--graview-sign-post, 10px)); width: 18px; height: 6px; margin: -3px 0 0 -9px; border-radius: 50%; background: rgba(0,0,0,0.28); }
|
|
844
|
+
.graview-one-place-board[data-graview-rising] { transform-origin: 50% 100%; transform: scaleY(1); transition: transform ${RISE_MS}ms cubic-bezier(.33,0,.2,1); }
|
|
845
|
+
@starting-style { .graview-one-place-board[data-graview-rising] { transform: scaleY(0); } }
|
|
846
|
+
.graview-one-place-board[data-graview-rising][data-graview-leaving] { transform: scaleY(0); pointer-events: none; }
|
|
847
|
+
.graview-one-place-board[aria-current] { outline: 2px solid color-mix(in srgb, var(--graview-accent) 60%, transparent); outline-offset: 3px; border-radius: 4px; }
|
|
848
|
+
[data-graview-past-slot] > * { pointer-events: auto; margin: 0 !important; }
|
|
849
|
+
[data-graview-focus-landing]:focus { outline: none; }
|
|
850
|
+
.graview-one-place-board:focus-visible { outline: 3px solid var(--graview-accent); outline-offset: 4px; border-radius: 6px; }
|
|
851
|
+
.graview-one-place-board:hover [data-graview-board-face] { border-color: var(--graview-accent); }
|
|
852
|
+
[data-graview-one-face-stops] { display: inline-flex; align-items: stretch; height: 32px; padding: 2px; gap: 2px; border-radius: 8px; border: 1px solid var(--graview-edge); background: var(--graview-panel, Canvas); box-shadow: 0 1px 2px rgba(0,0,0,0.12); box-sizing: border-box; }
|
|
853
|
+
[data-graview-one-face-stops] button { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 52px; padding: 0 10px; border: none; border-radius: 6px; background: none; color: var(--graview-ink-muted); font: inherit; font-size: 0.8125rem; font-weight: 500; cursor: pointer; white-space: nowrap; }
|
|
854
|
+
[data-graview-one-face-stops] button:hover { color: var(--graview-ink); background: color-mix(in srgb, var(--graview-ink) 7%, transparent); }
|
|
855
|
+
[data-graview-one-face-stops] button[aria-pressed="true"] { color: var(--graview-ink); font-weight: 600; background: color-mix(in srgb, var(--graview-accent) 18%, transparent); cursor: default; }
|
|
856
|
+
[data-graview-one-face-stops] button[data-graview-key-stop] { min-width: 30px; padding: 0 8px; margin-left: 2px; box-shadow: -1px 0 0 0 var(--graview-edge); border-radius: 0 6px 6px 0; }
|
|
857
|
+
[data-graview-one-face-stops] button:focus-visible, [data-graview-one-face-slider]:focus-visible { outline: 2px solid var(--graview-accent); outline-offset: 1px; }
|
|
858
|
+
[data-graview-one-face-tip] { position: absolute; left: 0; bottom: calc(100% + 6px); padding: 4px 8px; border-radius: 6px; border: 1px solid var(--graview-edge); background: var(--graview-panel, Canvas); color: var(--graview-ink); font-size: 0.75rem; white-space: nowrap; pointer-events: none; opacity: 0; }
|
|
859
|
+
[data-graview-one-face-tip][data-graview-shown] { opacity: 1; }
|
|
860
|
+
[data-graview-one-face-mini]:has([aria-expanded="true"]) > [data-graview-one-face-tip], [data-graview-one-face-stops]:has([data-testid="altitude-key"][aria-expanded="true"]) > [data-graview-one-face-tip] { opacity: 0; }
|
|
861
|
+
/* Put away, the same control made shorter: one row, the stops' height, border and type — the level's name, the track, and the way back to all three. */
|
|
862
|
+
[data-graview-one-face-mini] { display: inline-flex; align-items: stretch; height: 32px; padding: 2px; gap: 2px; border-radius: 8px; border: 1px solid var(--graview-edge); background: var(--graview-panel, Canvas); box-shadow: 0 1px 2px rgba(0,0,0,0.12); box-sizing: border-box; }
|
|
863
|
+
[data-graview-mini-word] { display: inline-flex; align-items: center; justify-content: center; min-width: 54px; padding: 0 4px; border: none; border-radius: 6px; background: color-mix(in srgb, var(--graview-accent) 18%, transparent); color: var(--graview-ink); font: inherit; font-size: 0.8125rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
|
|
864
|
+
[data-graview-mini-word]:hover { background: color-mix(in srgb, var(--graview-accent) 26%, transparent); }
|
|
865
|
+
[data-graview-mini-word]:focus-visible { outline: 2px solid var(--graview-accent); outline-offset: 1px; }
|
|
866
|
+
/* The chevron: a small glyph in a 24-pixel target (a thumb's 44 on a phone), reaching over the row's own padding. */
|
|
867
|
+
[data-graview-mini-tool] { position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; width: 24px; height: 26px; margin: 0 -2px 0 -4px; padding: 0; border: none; border-radius: 6px; background: none; color: var(--graview-ink-muted); cursor: pointer; }
|
|
868
|
+
[data-graview-mini-tool]:hover { color: var(--graview-ink); }
|
|
869
|
+
[data-graview-mini-tool]:focus-visible { outline: 2px solid var(--graview-accent); outline-offset: -2px; }
|
|
870
|
+
@media (max-width: 600px), (pointer: coarse) {
|
|
871
|
+
[data-graview-one-face-stops] { height: 48px; } [data-graview-one-face-stops] button { min-width: 64px; min-height: 44px; } [data-graview-one-face-stops] button[data-graview-key-stop] { min-width: 44px; }
|
|
872
|
+
[data-graview-one-face-mini] { height: 48px; }
|
|
873
|
+
[data-graview-mini-word] { min-width: 60px; min-height: 44px; }
|
|
874
|
+
[data-graview-mini-tool] { width: 44px; height: 44px; margin: 0; }
|
|
875
|
+
[data-testid="altitude-key-pane"] { padding-right: 48px !important; }
|
|
876
|
+
[data-testid="altitude-key-pane"] [data-testid="altitude-key-hide"] { width: 44px !important; height: 44px !important; top: 0 !important; right: 0 !important; }
|
|
877
|
+
[data-testid="altitude-keys-turn"] { min-height: 44px !important; min-width: 44px !important; }
|
|
878
|
+
}
|
|
879
|
+
`;
|
|
880
|
+
/**
|
|
881
|
+
* WHERE YOU ARE, AND THE WAY UP AND DOWN: one slim control at the window's
|
|
882
|
+
* bottom left, the bar's own size and manner — three stops, named, Page ·
|
|
883
|
+
* Nearby · City, the one you are at lit, and a press on another going
|
|
884
|
+
* there, every step drawn. Up and down are the stops either side; Alt and
|
|
885
|
+
* the arrows (and Escape, down) move one from the keyboard. Where the city
|
|
886
|
+
* is in sight, its Key is the control's last stop, opening above it. The
|
|
887
|
+
* level is said aloud as it changes.
|
|
888
|
+
*/
|
|
889
|
+
function Altitude({ box, level, moving, goTo, where, chosen, boards, current, store, motion, begin, }) {
|
|
890
|
+
/*
|
|
891
|
+
* ALL THREE LEVELS, OR ONE SLIM SLIDER. Shown whole the first time — a
|
|
892
|
+
* person learns there are three levels by reading their names — and put
|
|
893
|
+
* away into a slider naming only the level you are at whenever that is
|
|
894
|
+
* asked for, kept in this browser.
|
|
895
|
+
*/
|
|
896
|
+
const [small, setSmall] = useState(() => {
|
|
897
|
+
try {
|
|
898
|
+
return window.localStorage.getItem(CONTROL_KEY) === "slider";
|
|
899
|
+
}
|
|
900
|
+
catch {
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
const keepSmall = (to) => {
|
|
905
|
+
setSmall(to);
|
|
906
|
+
try {
|
|
907
|
+
window.localStorage.setItem(CONTROL_KEY, to ? "slider" : "levels");
|
|
908
|
+
}
|
|
909
|
+
catch {
|
|
910
|
+
// A browser that keeps nothing keeps the choice for this visit.
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
useEffect(() => {
|
|
914
|
+
// A notice placed above what stands at the foot places itself again: this has changed its width.
|
|
915
|
+
if (!moving)
|
|
916
|
+
window.dispatchEvent(new Event("graview:foot-moved"));
|
|
917
|
+
}, [level, moving]);
|
|
918
|
+
const kind = where.type === "record" || where.type === "list" ? where.kind : null;
|
|
919
|
+
const into = boards.find((board) => board.key === (chosen.current ?? current));
|
|
920
|
+
/** What a press on each stop does, said. */
|
|
921
|
+
const saying = (stop) => {
|
|
922
|
+
if (stop === level)
|
|
923
|
+
return `${LEVEL_NAMES[stop]}: you are here`;
|
|
924
|
+
if (stop === PAGE)
|
|
925
|
+
return level === CITY && into && into.key !== current ? `Page: “${into.label}”, alone` : "Page: this page alone";
|
|
926
|
+
if (stop === PANEL)
|
|
927
|
+
return level === CITY ? `Nearby: ${into ? `“${into.label}”` : "this page"} beside its place in the city` : `Nearby: this page beside ${kind ? `the ${pluralOf(store, kind).toLowerCase()} district` : "the city"}`;
|
|
928
|
+
return "City: every page and view of the app";
|
|
929
|
+
};
|
|
930
|
+
/*
|
|
931
|
+
* THE LEGEND IS A BUTTON. It starts put away — the Key, the control's
|
|
932
|
+
* last stop, opens it — beside the city and on the page alike: open by
|
|
933
|
+
* default it stood over a quarter of a desk's window at the City on the
|
|
934
|
+
* first visit, over the districts it was there to explain. Opened beside
|
|
935
|
+
* the city, it is kept open in this browser until it is put away, and
|
|
936
|
+
* kept put away after; read from this browser as the control mounts, so
|
|
937
|
+
* the swap of the pages' plain routes for this face keeps it.
|
|
938
|
+
*/
|
|
939
|
+
const [legendCity, setLegendCity] = useState(() => {
|
|
940
|
+
try {
|
|
941
|
+
return window.localStorage.getItem(LEGEND_KEY) === "shown";
|
|
942
|
+
}
|
|
943
|
+
catch {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
const [legendPage, setLegendPage] = useState(false);
|
|
948
|
+
const keyOpen = level === PAGE ? legendPage : legendCity;
|
|
949
|
+
const setKeyOpen = (to) => {
|
|
950
|
+
const next = typeof to === "function" ? to(keyOpen) : to;
|
|
951
|
+
if (level === PAGE)
|
|
952
|
+
return setLegendPage(next);
|
|
953
|
+
setLegendCity(next);
|
|
954
|
+
try {
|
|
955
|
+
window.localStorage.setItem(LEGEND_KEY, next ? "shown" : "hidden");
|
|
956
|
+
}
|
|
957
|
+
catch {
|
|
958
|
+
// Kept for this visit.
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
const tipId = useId();
|
|
962
|
+
const tip = `${LEVEL_NAMES[level]} (${LEVEL_KEYS[level]}) · [ and ] to move`;
|
|
963
|
+
const intent = useIntentTip();
|
|
964
|
+
const stopTips = [PAGE, PANEL, CITY].map((stop) => intent.on(stop === level ? tip : `${LEVEL_NAMES[stop]} (${LEVEL_KEYS[stop]})`));
|
|
965
|
+
const keys = (stop) => [LEVEL_KEYS[stop], stop === level + 1 ? "] Alt+ArrowUp" : stop === level - 1 ? "[ Alt+ArrowDown Escape" : ""].filter(Boolean).join(" ");
|
|
966
|
+
return (_jsxs("div", { ref: box, role: "region", "aria-label": "Where you are", "data-testid": "altitude", "data-graview-one-face-level": level, "data-graview-foot": "", style: { position: "fixed", left: 16, right: 16, bottom: 16, zIndex: ONE_FACE_LAYERS.control, display: "flex", flexWrap: "wrap-reverse", alignItems: "flex-end", gap: 8, pointerEvents: "none" }, children: [_jsxs("div", { "data-graview-one-face-dock": "", style: { display: "flex", flexDirection: "column", alignItems: "flex-start", gap: keyOpen && !small ? 30 : 8, pointerEvents: "none" }, children: [keyOpen ? _jsx(CityKey, { close: () => setKeyOpen(false) }) : null, small ? (_jsxs("div", { role: "group", "aria-label": "Level", "data-graview-one-face-mini": "", "data-graview-tip-host": "", style: { pointerEvents: "auto", position: "relative" }, children: [_jsx("button", { type: "button", "data-testid": "altitude-key", "data-graview-mini-word": "", "aria-expanded": keyOpen, "aria-label": `${LEVEL_NAMES[level]}: show the legend, what the city's marks mean and the keys`, ...intent.on("Legend"), onClick: () => setKeyOpen((open) => !open), onKeyDown: (event) => {
|
|
967
|
+
if (event.key !== "Escape" || !keyOpen)
|
|
968
|
+
return;
|
|
969
|
+
event.preventDefault();
|
|
970
|
+
event.stopPropagation();
|
|
971
|
+
setKeyOpen(false);
|
|
972
|
+
}, children: _jsx("span", { "data-testid": "altitude-mini-word", children: LEVEL_NAMES[level] }) }), _jsx(LevelSlider, { level: level, goTo: goTo, motion: motion, begin: begin, describedBy: tipId, tip: intent.on(tip) }), _jsx("button", { type: "button", "data-testid": "altitude-size", "aria-expanded": false, "aria-label": "Show all three levels", ...intent.on("Show all three levels"), onClick: () => keepSmall(false), "data-graview-mini-tool": "", children: _jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", "aria-hidden": "true", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M4 3l3 3-3 3" }) }) }), _jsx(Tip, { id: tipId, tip: intent, said: tip })] })) : (_jsxs("div", { role: "group", "aria-label": `Altitude: ${LEVEL_NAMES[level].toLowerCase()}, ${level + 1} of 3`, "data-graview-one-face-stops": "", "data-graview-tip-host": "", style: { pointerEvents: "auto", position: "relative" }, children: [[PAGE, PANEL, CITY].map((stop) => (_jsxs("button", { type: "button", "data-testid": `altitude-stop-${stop}`, ...(stop === level + 1 ? { "data-graview-rise": "" } : stop === level - 1 ? { "data-graview-descend": "" } : {}), "aria-pressed": stop === level, "aria-label": saying(stop), "aria-keyshortcuts": keys(stop), ...(stop === level ? { "aria-describedby": tipId } : {}), ...stopTips[stop],
|
|
973
|
+
// The board the keyboard chose keeps it: a press here goes into it.
|
|
974
|
+
onPointerDown: (event) => {
|
|
975
|
+
event.preventDefault();
|
|
976
|
+
stopTips[stop].onPointerDown(event);
|
|
977
|
+
},
|
|
978
|
+
// The level it is at, pressed at Nearby or the City, brings the camera back to that level's framing.
|
|
979
|
+
onClick: () => (stop === level && level === PAGE ? undefined : goTo(stop)), children: [LEVEL_NAMES[stop], keyOpen ? (_jsx("kbd", { "data-testid": `altitude-keycap-${stop}`, "aria-hidden": "true", style: { position: "absolute", top: -22, left: "50%", transform: "translateX(-50%)", minWidth: 18, padding: "1px 5px", borderRadius: 4, border: "1px solid var(--graview-edge)", background: "var(--graview-panel, Canvas)", color: "var(--graview-ink)", font: "inherit", fontSize: "0.75rem", lineHeight: 1.4, textAlign: "center" }, children: LEVEL_KEYS[stop] })) : null] }, stop))), _jsx("button", { type: "button", "data-testid": "altitude-key", "data-graview-key-stop": "", "aria-expanded": keyOpen, "aria-label": "Key: what the city's marks mean", ...intent.on("Key: what the city's marks mean"), onClick: () => setKeyOpen((open) => !open), onKeyDown: (event) => {
|
|
980
|
+
// The Key's Escape is the Key's: it puts the Key away, and nothing moves a level.
|
|
981
|
+
if (event.key !== "Escape" || !keyOpen)
|
|
982
|
+
return;
|
|
983
|
+
event.preventDefault();
|
|
984
|
+
event.stopPropagation();
|
|
985
|
+
setKeyOpen(false);
|
|
986
|
+
}, children: _jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", "aria-hidden": "true", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", children: [_jsx("circle", { cx: "7", cy: "7", r: "5.6" }), _jsx("path", { d: "M7 6.4v3.4" }), _jsx("circle", { cx: "7", cy: "4.3", r: "0.4", fill: "currentColor" })] }) }), _jsx(Tip, { id: tipId, tip: intent, said: tip }), _jsx("button", { type: "button", "data-testid": "altitude-size", "data-graview-key-stop": "", "aria-expanded": true, "aria-label": "Put the levels away into a slider", ...intent.on("Put the levels away into a slider"), onClick: () => keepSmall(true), children: _jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", "aria-hidden": "true", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M8 3L5 6l3 3" }) }) })] }))] }), _jsx("div", { "data-graview-past-slot": "", style: { flex: "1 1 300px", minWidth: 0, maxWidth: 720, pointerEvents: "none" }, children: _jsx(PastBar, { face: "pages" }) }), _jsx("span", { role: "status", style: { position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap" }, children: moving ? "" : LEVEL_NAMES[level] })] }));
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* THE LEVELS AS A SLIDER: a short track with a stop for each level and a
|
|
990
|
+
* thumb at the one you are at, its name beside it. Dragged, the camera
|
|
991
|
+
* follows the thumb the whole way and settles at the nearest stop when it
|
|
992
|
+
* is let go, as a pinch does; pressed on the track, or moved by the arrows,
|
|
993
|
+
* Home and End, or 1, 2 and 3, it goes to a stop.
|
|
994
|
+
*/
|
|
995
|
+
/** The collapsed control's track, and its thumb. */
|
|
996
|
+
const TRACK = 64;
|
|
997
|
+
const THUMB = 14;
|
|
998
|
+
function LevelSlider({ level, goTo, motion, begin, describedBy, tip }) {
|
|
999
|
+
const track = useRef(null);
|
|
1000
|
+
const moved = useRef(false);
|
|
1001
|
+
const [dragging, setDragging] = useState(null);
|
|
1002
|
+
const altitudeNow = () => Number(document.querySelector('[data-testid="one-place-city"]')?.getAttribute("data-graview-altitude-now") ?? level) || 0;
|
|
1003
|
+
const atPointer = (clientX) => {
|
|
1004
|
+
const box = track.current?.getBoundingClientRect();
|
|
1005
|
+
if (!box || box.width === 0)
|
|
1006
|
+
return level;
|
|
1007
|
+
// The stops stand inside the track, half a thumb in from each end.
|
|
1008
|
+
return Math.max(0, Math.min(CITY, ((clientX - box.left - THUMB / 2) / Math.max(1, box.width - THUMB)) * CITY));
|
|
1009
|
+
};
|
|
1010
|
+
const shown = dragging ?? level;
|
|
1011
|
+
const named = LEVEL_NAMES[Math.round(shown)];
|
|
1012
|
+
return (_jsxs("div", { role: "slider", tabIndex: 0, "data-testid": "altitude-slider", "aria-label": "Level", "aria-valuemin": PAGE, "aria-valuemax": CITY, "aria-valuenow": level, "aria-valuetext": LEVEL_NAMES[level], "aria-keyshortcuts": "1 2 3 [ ]", "aria-describedby": describedBy, onPointerEnter: tip.onPointerEnter, onPointerLeave: tip.onPointerLeave, onFocus: tip.onFocus, onBlur: tip.onBlur, onKeyDown: (event) => {
|
|
1013
|
+
const to = event.key === "ArrowLeft" || event.key === "ArrowDown" ? level - 1 : event.key === "ArrowRight" || event.key === "ArrowUp" ? level + 1 : event.key === "Home" ? PAGE : event.key === "End" ? CITY : null;
|
|
1014
|
+
if (to === null || event.altKey)
|
|
1015
|
+
return;
|
|
1016
|
+
event.preventDefault();
|
|
1017
|
+
event.stopPropagation();
|
|
1018
|
+
goTo(Math.max(PAGE, Math.min(CITY, to)));
|
|
1019
|
+
}, onPointerDown: (event) => {
|
|
1020
|
+
if (event.button !== 0 || !event.isPrimary)
|
|
1021
|
+
return;
|
|
1022
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1023
|
+
motion.current.held = true;
|
|
1024
|
+
// Out of the page's flow and a hand on the camera from the first touch: the frame does not put the page back before the thumb moves.
|
|
1025
|
+
motion.current.scrubbing = true;
|
|
1026
|
+
moved.current = false;
|
|
1027
|
+
begin();
|
|
1028
|
+
setDragging(atPointer(event.clientX));
|
|
1029
|
+
}, onPointerMove: (event) => {
|
|
1030
|
+
if (dragging === null)
|
|
1031
|
+
return;
|
|
1032
|
+
const to = atPointer(event.clientX);
|
|
1033
|
+
if (Math.abs(to - (dragging ?? to)) > 0.02)
|
|
1034
|
+
moved.current = true;
|
|
1035
|
+
setDragging(to);
|
|
1036
|
+
// The camera follows the thumb: as far as it has gone since the last frame, as a pinch scrubs it.
|
|
1037
|
+
motion.current.scrub = to - altitudeNow();
|
|
1038
|
+
}, onPointerUp: (event) => {
|
|
1039
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
1040
|
+
const to = dragging;
|
|
1041
|
+
setDragging(null);
|
|
1042
|
+
motion.current.held = false;
|
|
1043
|
+
// A press without a drag goes to the stop pressed; a drag settles where the camera lets it go, at the nearest.
|
|
1044
|
+
if (!moved.current) {
|
|
1045
|
+
motion.current.scrubbing = false;
|
|
1046
|
+
motion.current.scrub = 0;
|
|
1047
|
+
if (to !== null)
|
|
1048
|
+
goTo(Math.round(to));
|
|
1049
|
+
}
|
|
1050
|
+
}, onPointerCancel: () => {
|
|
1051
|
+
setDragging(null);
|
|
1052
|
+
motion.current.held = false;
|
|
1053
|
+
motion.current.scrub = 0;
|
|
1054
|
+
}, "data-graview-one-face-slider": "", style: { position: "relative", flex: "none", display: "inline-flex", alignItems: "center", width: TRACK, padding: 0, cursor: "pointer", touchAction: "none", outline: "none", borderRadius: 6 }, children: [_jsxs("div", { ref: track, "aria-hidden": "true", style: { position: "relative", width: "100%", height: 2, borderRadius: 1, background: "var(--graview-edge)" }, children: [[PAGE, PANEL, CITY].map((stop) => (_jsx("span", { style: { position: "absolute", left: `calc(${THUMB / 2}px + ${stop / CITY} * (100% - ${THUMB}px))`, top: "50%", width: 2, height: 8, marginLeft: -1, marginTop: -4, borderRadius: 1, background: "var(--graview-ink-muted)" } }, stop))), _jsx("span", { "data-testid": "altitude-thumb", style: { position: "absolute", left: `calc(${THUMB / 2}px + ${shown / CITY} * (100% - ${THUMB}px))`, top: "50%", width: THUMB, height: THUMB, marginLeft: -THUMB / 2, marginTop: -THUMB / 2, borderRadius: THUMB / 2, background: "var(--graview-accent)", boxShadow: "0 1px 3px rgba(0,0,0,0.3)", transition: dragging === null ? "left 200ms ease" : "none" } })] }), _jsx("span", { "data-testid": "altitude-word", "aria-hidden": "true", style: { position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)" }, children: named })] }));
|
|
1055
|
+
}
|
|
1056
|
+
/** What on a page a person reads or presses: a part that would be covered if the control stood over it. */
|
|
1057
|
+
const CONTENT = "a[href], button, input, select, textarea, img, svg, video, canvas, [role=button], [role=link]";
|
|
1058
|
+
/**
|
|
1059
|
+
* THE ROOM THE PAGE KEEPS AT ITS FOOT FOR THE CONTROL — only as much as
|
|
1060
|
+
* keeps the control off the page's content when it is scrolled to its end.
|
|
1061
|
+
* Every part with words or a control whose column the control stands in
|
|
1062
|
+
* (the control's width, and a little air) is measured where it would be at
|
|
1063
|
+
* the scroll's end: the room is what lifts the lowest of them clear of the
|
|
1064
|
+
* control's top. A footer whose words stand at its right, the control at
|
|
1065
|
+
* its empty left, keeps no room at all.
|
|
1066
|
+
*/
|
|
1067
|
+
function FootRoom({ fab, sheet }) {
|
|
1068
|
+
const room = useRef(null);
|
|
1069
|
+
const [height, setHeight] = useState(0);
|
|
1070
|
+
useEffect(() => {
|
|
1071
|
+
let frame = 0;
|
|
1072
|
+
const measure = () => {
|
|
1073
|
+
frame = 0;
|
|
1074
|
+
const plane = sheet.current;
|
|
1075
|
+
const holder = fab.current;
|
|
1076
|
+
const spacer = room.current;
|
|
1077
|
+
if (!plane || !holder || !spacer)
|
|
1078
|
+
return;
|
|
1079
|
+
const parts = [holder.querySelector("[data-graview-one-face-dock]"), holder.querySelector("[data-graview-past-slot] > *")].flatMap((el) => {
|
|
1080
|
+
const r = el?.getBoundingClientRect();
|
|
1081
|
+
return r && r.width > 0 && r.height > 0 ? [r] : [];
|
|
1082
|
+
});
|
|
1083
|
+
if (parts.length === 0)
|
|
1084
|
+
return setHeight(0);
|
|
1085
|
+
const scrollY = window.scrollY;
|
|
1086
|
+
const whole = document.documentElement.scrollHeight - spacer.offsetHeight;
|
|
1087
|
+
const end = Math.max(0, whole - window.innerHeight);
|
|
1088
|
+
let lowest = -Infinity;
|
|
1089
|
+
for (const el of plane.querySelectorAll("*")) {
|
|
1090
|
+
if (el === spacer || spacer.contains(el))
|
|
1091
|
+
continue;
|
|
1092
|
+
// A leaf with words, or a control or a picture: what a person reads or presses.
|
|
1093
|
+
const said = el.matches(CONTENT) || (el.childElementCount === 0 && (el.textContent ?? "").trim().length > 0);
|
|
1094
|
+
if (!said)
|
|
1095
|
+
continue;
|
|
1096
|
+
const r = el.getBoundingClientRect();
|
|
1097
|
+
if (r.width === 0 || r.height === 0)
|
|
1098
|
+
continue;
|
|
1099
|
+
if (r.bottom + scrollY < end + window.innerHeight - 400)
|
|
1100
|
+
continue;
|
|
1101
|
+
if (!parts.some((part) => r.right > part.left - 8 && r.left < part.right + 8))
|
|
1102
|
+
continue;
|
|
1103
|
+
// Fixed to the window (a notice, a dialog): it does not scroll to the page's end.
|
|
1104
|
+
if (el.offsetParent === null && getComputedStyle(el).position === "fixed")
|
|
1105
|
+
continue;
|
|
1106
|
+
// Inside a box that scrolls or clips: where that box shows it, not where its content runs on below.
|
|
1107
|
+
let seen = r.bottom;
|
|
1108
|
+
for (let at = el.parentElement; at && at !== plane; at = at.parentElement) {
|
|
1109
|
+
const style = getComputedStyle(at);
|
|
1110
|
+
if (style.position === "fixed") {
|
|
1111
|
+
seen = -Infinity;
|
|
1112
|
+
break;
|
|
1113
|
+
}
|
|
1114
|
+
if (style.overflowY !== "visible")
|
|
1115
|
+
seen = Math.min(seen, at.getBoundingClientRect().bottom);
|
|
1116
|
+
}
|
|
1117
|
+
if (seen === -Infinity)
|
|
1118
|
+
continue;
|
|
1119
|
+
lowest = Math.max(lowest, seen + scrollY);
|
|
1120
|
+
}
|
|
1121
|
+
if (lowest === -Infinity)
|
|
1122
|
+
return setHeight(0);
|
|
1123
|
+
// The control's top where it rests, and air above it: the lowest such part ends there at the scroll's end.
|
|
1124
|
+
const top = Math.min(...parts.map((part) => part.top)) - 8;
|
|
1125
|
+
const need = Math.ceil(lowest - top + window.innerHeight - whole);
|
|
1126
|
+
setHeight((was) => (Math.abs(was - Math.max(0, need)) < 1 ? was : Math.max(0, need)));
|
|
1127
|
+
};
|
|
1128
|
+
const soon = () => {
|
|
1129
|
+
if (!frame)
|
|
1130
|
+
frame = requestAnimationFrame(measure);
|
|
1131
|
+
};
|
|
1132
|
+
soon();
|
|
1133
|
+
const sized = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(soon);
|
|
1134
|
+
// The page is in the window's flow here (its box is the document's): the body's size is the page's.
|
|
1135
|
+
sized?.observe(document.body);
|
|
1136
|
+
if (fab.current)
|
|
1137
|
+
sized?.observe(fab.current);
|
|
1138
|
+
const changed = typeof MutationObserver === "undefined" ? null : new MutationObserver(soon);
|
|
1139
|
+
if (sheet.current)
|
|
1140
|
+
changed?.observe(sheet.current, { childList: true, subtree: true, characterData: true });
|
|
1141
|
+
window.addEventListener("resize", soon);
|
|
1142
|
+
return () => {
|
|
1143
|
+
cancelAnimationFrame(frame);
|
|
1144
|
+
sized?.disconnect();
|
|
1145
|
+
changed?.disconnect();
|
|
1146
|
+
window.removeEventListener("resize", soon);
|
|
1147
|
+
};
|
|
1148
|
+
}, [fab, sheet]);
|
|
1149
|
+
return _jsx("div", { ref: room, "aria-hidden": "true", "data-graview-altitude-room": "", style: { height } });
|
|
1150
|
+
}
|
|
1151
|
+
/** The level's keys, said as they are now, with the one button that turns them off or back on (WCAG 2.1.4). A bare checkbox read as "off" while the keys worked; the line itself says which it is. */
|
|
1152
|
+
function KeysLine() {
|
|
1153
|
+
const [on, setOn] = useState(keysOn);
|
|
1154
|
+
const turn = () => {
|
|
1155
|
+
const next = !on;
|
|
1156
|
+
setOn(next);
|
|
1157
|
+
try {
|
|
1158
|
+
window.localStorage.setItem(KEYS_KEY, next ? "on" : "off");
|
|
1159
|
+
}
|
|
1160
|
+
catch {
|
|
1161
|
+
// Kept for this visit only.
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
const button = (_jsx("button", { type: "button", "data-testid": "altitude-keys-turn", "aria-pressed": on, "aria-label": on ? "Level keys are on: turn them off" : "Level keys are off: turn them on", onClick: turn, style: { display: "inline-flex", alignItems: "center", minHeight: 24, minWidth: 24, marginLeft: 6, padding: "0 4px", verticalAlign: "middle", border: "none", background: "none", color: "var(--graview-accent)", font: "inherit", textDecoration: "underline", textUnderlineOffset: 2, cursor: "pointer" }, children: on ? "Turn off" : "Turn on" }));
|
|
1165
|
+
return (_jsxs("p", { "data-testid": "altitude-key-keys", "data-graview-keys": on ? "on" : "off", style: { margin: "0 0 6px", color: "var(--graview-ink-muted)" }, children: [_jsx("strong", { style: { fontWeight: 600, color: "var(--graview-ink)" }, children: "Keys" }), on ? ": 1 Page · 2 Nearby · 3 City · [ down · ] up" : " are off: Alt ↑ up · Alt ↓ down", button] }));
|
|
1166
|
+
}
|
|
1167
|
+
/** What the city's marks mean, as this face draws them: nothing it does not draw. */
|
|
1168
|
+
function CityKey({ close }) {
|
|
1169
|
+
const swatch = (inner) => _jsx("span", { "aria-hidden": "true", style: { display: "inline-flex", width: 18, height: 14, alignItems: "center", justifyContent: "center" }, children: inner });
|
|
1170
|
+
const rows = [
|
|
1171
|
+
[swatch(_jsx("span", { style: { width: 14, height: 10, borderRadius: 2, border: "1.5px solid var(--graview-edge)", borderTopWidth: 3, borderTopColor: "var(--graview-accent)", background: "var(--graview-ground)" } })), "View", "a page of the app. Click to open it."],
|
|
1172
|
+
[swatch(_jsx("svg", { width: "18", height: "12", viewBox: "0 0 18 12", children: _jsx("path", { d: "M9 1 17 6 9 11 1 6Z", fill: "none", stroke: "var(--graview-edge)", strokeWidth: "1.4" }) })), "District", "all the records of one kind."],
|
|
1173
|
+
[swatch(_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", children: [_jsx("path", { d: "M7 1 13 4 7 7 1 4Z", fill: "color-mix(in srgb, var(--graview-ink) 30%, var(--graview-panel))" }), _jsx("path", { d: "M1 4v6l6 3V7Z", fill: "color-mix(in srgb, var(--graview-ink) 18%, var(--graview-panel))" }), _jsx("path", { d: "M13 4v6l-6 3V7Z", fill: "color-mix(in srgb, var(--graview-ink) 24%, var(--graview-panel))" })] })), "Building", "one record."],
|
|
1174
|
+
[swatch(_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", children: [_jsx("path", { d: "M7 1 13 4 7 7 1 4Z", fill: "var(--graview-warn)" }), _jsx("path", { d: "M1 4v6l6 3V7Z", fill: "color-mix(in srgb, var(--graview-warn) 70%, black)" }), _jsx("path", { d: "M13 4v6l-6 3V7Z", fill: "color-mix(in srgb, var(--graview-warn) 85%, black)" })] })), "Orange roof", "needs your attention."],
|
|
1175
|
+
[swatch(_jsx("svg", { width: "18", height: "12", viewBox: "0 0 18 12", children: _jsx("path", { d: "M1 11 Q9 1 17 6", fill: "none", stroke: "var(--graview-accent)", strokeWidth: "1.5" }) })), "Line", "links something on the page to its record."],
|
|
1176
|
+
[swatch(_jsx("span", { style: { width: 18, height: 3, borderRadius: 2, background: "var(--graview-edge)" } })), "Road", "these kinds are linked."],
|
|
1177
|
+
];
|
|
1178
|
+
return (_jsxs("div", { role: "region", "aria-label": "What the city's marks mean", "data-testid": "altitude-key-pane", onKeyDown: (event) => {
|
|
1179
|
+
if (event.key !== "Escape")
|
|
1180
|
+
return;
|
|
1181
|
+
event.preventDefault();
|
|
1182
|
+
event.stopPropagation();
|
|
1183
|
+
close();
|
|
1184
|
+
}, style: { pointerEvents: "auto", position: "relative", width: "max-content", maxWidth: "calc(100vw - 32px)", padding: "8px 28px 8px 10px", borderRadius: 8, border: "1px solid var(--graview-edge)", background: "var(--graview-panel, Canvas)", color: "var(--graview-ink)", boxShadow: "0 1px 2px rgba(0,0,0,0.12)", fontSize: "0.75rem", lineHeight: 1.35 }, children: [_jsx("button", { type: "button", "data-testid": "altitude-key-hide", "aria-label": "Put the legend away", onClick: close, style: { position: "absolute", top: 2, right: 2, width: 24, height: 24, padding: 0, border: "none", borderRadius: 4, background: "none", color: "var(--graview-ink-muted)", font: "inherit", cursor: "pointer" }, children: "\u00D7" }), _jsx(KeysLine, {}), _jsx("ul", { style: { listStyle: "none", margin: 0, padding: 0, display: "grid", gap: 3 }, children: rows.map(([mark, term, words]) => (_jsxs("li", { style: { display: "grid", gridTemplateColumns: "18px 1fr", gap: 10, alignItems: "start", lineHeight: "18px" }, children: [_jsx("span", { style: { display: "flex", height: 18, alignItems: "center" }, children: mark }), _jsxs("span", { children: [_jsx("strong", { style: { fontWeight: 600 }, children: term }), ": ", words] })] }, term))) })] }));
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* CONNECTED: what the record is linked to that its page does not already
|
|
1188
|
+
* show — a relation the page draws as a section of its own is not said
|
|
1189
|
+
* again — at the page's foot, in its flow, never over its words. Grown in
|
|
1190
|
+
* as the page becomes the panel (its box's height is set each frame); each
|
|
1191
|
+
* row is the record it names, and a line leaves the page's edge level with
|
|
1192
|
+
* it for that record's building. Nothing at all when the page shows every
|
|
1193
|
+
* one. What the Scene's own record view said under the record ("why this is
|
|
1194
|
+
* here", "the list it is on") is here when the page does not say it.
|
|
1195
|
+
*
|
|
1196
|
+
* A PAGE THAT IS A VIEW'S WHOLE (Graview HQ brief
|
|
1197
|
+
* b-cloud-2026-11-13-connected-under-a-view): a tall view can put what the
|
|
1198
|
+
* record is connected to far below the first window, or under nothing that
|
|
1199
|
+
* says it is there. Then Connected stands at the page's top, every record
|
|
1200
|
+
* it is linked to said there at once, small, under how many there are; a
|
|
1201
|
+
* line leaves from the view's own part for a record where that part is in
|
|
1202
|
+
* sight, and from here where it is not.
|
|
1203
|
+
*/
|
|
1204
|
+
/** Whether the page the sheet holds is a view's whole (`data-graview-whole-view`), as it is drawn now. */
|
|
1205
|
+
function useWholeView(sheet, at) {
|
|
1206
|
+
const [whole, setWhole] = useState(false);
|
|
1207
|
+
useLayoutEffect(() => {
|
|
1208
|
+
const plane = sheet.current;
|
|
1209
|
+
if (!plane)
|
|
1210
|
+
return;
|
|
1211
|
+
const read = () => setWhole(plane.querySelector("[data-graview-whole-view]") !== null);
|
|
1212
|
+
read();
|
|
1213
|
+
const watch = typeof MutationObserver === "undefined" ? null : new MutationObserver(read);
|
|
1214
|
+
watch?.observe(plane, { childList: true, subtree: true });
|
|
1215
|
+
return () => watch?.disconnect();
|
|
1216
|
+
}, [sheet, at]);
|
|
1217
|
+
return whole;
|
|
1218
|
+
}
|
|
1219
|
+
function Connected({ store, id, box, sheet, openRecord, whole }) {
|
|
1220
|
+
const tick = useStoreTick(store);
|
|
1221
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1222
|
+
const facts = useMemo(() => recordFacts(store, id), [store, id, tick]);
|
|
1223
|
+
/* What the page shows already: every record a part of it marks, outside this list. */
|
|
1224
|
+
const [onPage, setOnPage] = useState(null);
|
|
1225
|
+
useLayoutEffect(() => {
|
|
1226
|
+
const plane = sheet.current;
|
|
1227
|
+
if (!plane)
|
|
1228
|
+
return;
|
|
1229
|
+
const read = () => {
|
|
1230
|
+
const shown = new Set();
|
|
1231
|
+
for (const part of plane.querySelectorAll(`[data-graview-pick], [data-graview-record], [data-record], a[href], [${RECORD_BOXES_ATTRIBUTE}]`)) {
|
|
1232
|
+
if (box.current?.contains(part))
|
|
1233
|
+
continue;
|
|
1234
|
+
/* A view drawn where the page cannot read (a worker view, a frame): the records its host says it shows, in sight or not. */
|
|
1235
|
+
const drawn = recordBoxesOf(part);
|
|
1236
|
+
if (drawn) {
|
|
1237
|
+
for (const one of drawn.shows())
|
|
1238
|
+
shown.add(one);
|
|
1239
|
+
continue;
|
|
1240
|
+
}
|
|
1241
|
+
const marked = part.getAttribute("data-graview-pick") ?? part.getAttribute("data-graview-record") ?? part.getAttribute("data-record");
|
|
1242
|
+
if (marked)
|
|
1243
|
+
shown.add(marked);
|
|
1244
|
+
else if (part instanceof HTMLAnchorElement) {
|
|
1245
|
+
if (part.origin !== window.location.origin)
|
|
1246
|
+
continue;
|
|
1247
|
+
try {
|
|
1248
|
+
const last = decodeURIComponent(part.pathname.split("/").filter(Boolean).at(-1) ?? "");
|
|
1249
|
+
if (last)
|
|
1250
|
+
shown.add(last);
|
|
1251
|
+
}
|
|
1252
|
+
catch {
|
|
1253
|
+
// An address that is no record's.
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
setOnPage((was) => (was && was.size === shown.size && [...shown].every((one) => was.has(one)) ? was : shown));
|
|
1258
|
+
};
|
|
1259
|
+
read();
|
|
1260
|
+
const watch = typeof MutationObserver === "undefined" ? null : new MutationObserver(read);
|
|
1261
|
+
watch?.observe(plane, { childList: true, subtree: true });
|
|
1262
|
+
plane.addEventListener(RECORD_BOXES_MOVED, read);
|
|
1263
|
+
return () => {
|
|
1264
|
+
watch?.disconnect();
|
|
1265
|
+
plane.removeEventListener(RECORD_BOXES_MOVED, read);
|
|
1266
|
+
};
|
|
1267
|
+
}, [sheet, box, id, tick]);
|
|
1268
|
+
const groups = (facts?.links ?? []).map((group) => ({ ...group, targets: whole ? group.targets : group.targets.filter((target) => !onPage?.has(target.id)) })).filter((group) => group.targets.length > 0);
|
|
1269
|
+
const total = groups.reduce((sum, group) => sum + group.targets.length, 0);
|
|
1270
|
+
if (onPage === null || total === 0)
|
|
1271
|
+
return _jsx("div", { ref: box, "data-graview-connected-box": "", hidden: true });
|
|
1272
|
+
if (whole) {
|
|
1273
|
+
return (_jsx("div", { ref: box, "data-graview-connected-box": "", "data-graview-connected-at": "top", style: { height: 0, opacity: 0, overflow: "hidden", background: "var(--graview-panel, Canvas)", borderBottom: "1px solid var(--graview-edge)", flex: "0 0 auto" }, children: _jsxs("section", { "data-graview-connected": total, "aria-label": "Connected", style: { padding: "8px 18px 10px" }, children: [_jsxs("h2", { style: { margin: "0 0 6px", fontSize: "0.95rem" }, children: ["Connected ", _jsxs("span", { style: { fontWeight: 400, color: "var(--graview-ink-faint)" }, children: ["\u00B7 ", total] })] }), groups.map((group) => (_jsxs("div", { style: { marginTop: 4 }, children: [_jsx("div", { style: { fontSize: "0.75rem", color: "var(--graview-ink-muted)" }, children: group.description ?? group.edgeKind }), _jsx("ul", { style: { listStyle: "none", margin: "2px 0 0", padding: 0, display: "flex", flexWrap: "wrap", gap: 4 }, children: group.targets.map((target) => (_jsx("li", { children: _jsx("button", { type: "button", "data-graview-record": target.id, onClick: () => openRecord(target.id, PANEL), style: { display: "inline-flex", alignItems: "center", minHeight: 26, padding: "2px 8px", border: "1px solid var(--graview-edge)", borderRadius: 999, background: "none", color: "var(--graview-ink)", font: "inherit", fontSize: "0.8125rem", cursor: "pointer" }, children: target.label }) }, target.id))) })] }, `${group.edgeKind}|${group.direction}`)))] }) }));
|
|
1274
|
+
}
|
|
1275
|
+
return (_jsx("div", { ref: box, "data-graview-connected-box": "", style: { height: 0, opacity: 0, overflow: "hidden", background: "var(--graview-panel, Canvas)", borderTop: "1px solid var(--graview-edge)", flex: "0 0 auto" }, children: _jsxs("section", { "data-graview-connected": total, "aria-label": "Also connected", style: { padding: "10px 18px 12px" }, children: [_jsxs("h2", { style: { margin: "0 0 6px", fontSize: "0.95rem" }, children: ["Also connected ", _jsxs("span", { style: { fontWeight: 400, color: "var(--graview-ink-faint)" }, children: ["\u00B7 ", total] })] }), groups.map((group) => (_jsxs("div", { style: { marginTop: 6 }, children: [_jsx("div", { style: { fontSize: "0.75rem", color: "var(--graview-ink-muted)" }, children: group.description ?? group.edgeKind }), _jsx("ul", { style: { listStyle: "none", margin: 0, padding: 0 }, children: group.targets.map((target) => (_jsx("li", { children: _jsx("button", { type: "button", "data-graview-record": target.id, onClick: () => openRecord(target.id, PANEL), style: { display: "block", width: "100%", textAlign: "start", padding: "4px 0", border: "none", background: "none", color: "var(--graview-ink)", font: "inherit", fontSize: "0.9rem", cursor: "pointer", minHeight: 32 }, children: target.label }) }, target.id))) })] }, `${group.edgeKind}|${group.direction}`)))] }) }));
|
|
1276
|
+
}
|
|
1277
|
+
export { PHONE };
|
|
1278
|
+
/**
|
|
1279
|
+
* THE PANEL'S INNER EDGE, TO DRAG: a desk's panel wider or narrower by its
|
|
1280
|
+
* left edge, a phone's sheet higher or lower by its top. A separator the
|
|
1281
|
+
* keyboard reaches: the arrows step it, Home and End go to its least and
|
|
1282
|
+
* most, a double press puts it back. The city beside it follows on the one
|
|
1283
|
+
* camera as it moves (`one-place-city.tsx`).
|
|
1284
|
+
*/
|
|
1285
|
+
function PanelEdge({ view, size, keep, motion }) {
|
|
1286
|
+
const phone = view.width <= PHONE;
|
|
1287
|
+
const range = panelRange(view);
|
|
1288
|
+
const panel = panelBox(view);
|
|
1289
|
+
const now = view.panel ?? range.default;
|
|
1290
|
+
const clamp = (value) => Math.max(range.min, Math.min(range.max, value));
|
|
1291
|
+
const bar = view.top ?? 0;
|
|
1292
|
+
const fromPointer = (event) => (phone ? (event.clientY - bar) / Math.max(1, view.height - bar) : view.width - 12 - event.clientX);
|
|
1293
|
+
const step = phone ? 0.04 : 24;
|
|
1294
|
+
const said = phone ? `${Math.round((1 - now) * 100)}% of the window` : `${Math.round(now)} pixels wide`;
|
|
1295
|
+
return (_jsx("div", { role: "separator", "aria-orientation": phone ? "horizontal" : "vertical", "aria-label": phone ? "The sheet's height" : "The panel's width", "aria-valuenow": Math.round(phone ? (1 - now) * 100 : now), "aria-valuemin": Math.round(phone ? (1 - range.max) * 100 : range.min), "aria-valuemax": Math.round(phone ? (1 - range.min) * 100 : range.max), "aria-valuetext": said, tabIndex: 0, "data-testid": "one-place-panel-edge", title: "Drag to size the panel; double-click to put it back", onPointerDown: (event) => {
|
|
1296
|
+
event.preventDefault();
|
|
1297
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1298
|
+
motion.current.resizing = true;
|
|
1299
|
+
}, onPointerMove: (event) => {
|
|
1300
|
+
if (!motion.current.resizing)
|
|
1301
|
+
return;
|
|
1302
|
+
size(clamp(fromPointer(event)));
|
|
1303
|
+
}, onPointerUp: (event) => {
|
|
1304
|
+
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
|
1305
|
+
motion.current.resizing = false;
|
|
1306
|
+
keep();
|
|
1307
|
+
}, onPointerCancel: () => {
|
|
1308
|
+
motion.current.resizing = false;
|
|
1309
|
+
}, onDoubleClick: () => {
|
|
1310
|
+
size(undefined);
|
|
1311
|
+
requestAnimationFrame(keep);
|
|
1312
|
+
}, onKeyDown: (event) => {
|
|
1313
|
+
// A phone's sheet grows as its top goes up: the share above it shrinks.
|
|
1314
|
+
const grow = phone ? -step : step;
|
|
1315
|
+
const to = event.key === "Home" ? (phone ? range.max : range.min) : event.key === "End" ? (phone ? range.min : range.max) : event.key === (phone ? "ArrowUp" : "ArrowLeft") ? now + grow : event.key === (phone ? "ArrowDown" : "ArrowRight") ? now - grow : null;
|
|
1316
|
+
if (to === null)
|
|
1317
|
+
return;
|
|
1318
|
+
event.preventDefault();
|
|
1319
|
+
size(clamp(to));
|
|
1320
|
+
requestAnimationFrame(keep);
|
|
1321
|
+
}, className: "graview-one-place-edge", style: phone
|
|
1322
|
+
? { position: "fixed", left: panel.x + panel.width / 2 - 32, top: panel.y - 14, width: 64, height: 28, zIndex: ONE_FACE_LAYERS.edge, cursor: "row-resize", touchAction: "none" }
|
|
1323
|
+
: { position: "fixed", left: panel.x - 8, top: panel.y + 16, width: 14, height: panel.height - 32, zIndex: ONE_FACE_LAYERS.edge, cursor: "col-resize", touchAction: "none" } }));
|
|
1324
|
+
}
|
|
1325
|
+
//# sourceMappingURL=one-place.js.map
|